From b3b662f3cf8d86f37690c80f63cff9c1816ff3c5 Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Tue, 17 Oct 2023 09:46:43 -0400 Subject: [PATCH 1/2] Adding support for Snakemake Adding some comments to test file --- Unix/t/00_C.t | 5 +++ cloc | 13 ++++++++ tests/inputs/Snakefile | 63 ++++++++++++++++++++++++++++++++++++ tests/outputs/Snakefile.yaml | 19 +++++++++++ 4 files changed, 100 insertions(+) create mode 100644 tests/inputs/Snakefile create mode 100644 tests/outputs/Snakefile.yaml diff --git a/Unix/t/00_C.t b/Unix/t/00_C.t index ba7b11d2..0411444f 100755 --- a/Unix/t/00_C.t +++ b/Unix/t/00_C.t @@ -1006,6 +1006,11 @@ my @Tests = ( 'ref' => '../tests/outputs/captcha.cs.yaml', 'args' => '../tests/inputs/captcha.cs', }, + { + 'name' => 'Snakemake', + 'ref' => '../tests/outputs/Snakefile.yaml', + 'args' => '../tests/inputs/Snakefile', + }, { 'name' => 'Smarty', 'ref' => '../tests/outputs/guestbook.tpl.yaml', diff --git a/cloc b/cloc index 4f191af2..45503bf1 100755 --- a/cloc +++ b/cloc @@ -8806,6 +8806,8 @@ sub set_constants { # {{{1 'data.sql' => 'SQL Data' , 'sss' => 'SugarSS' , 'st' => 'Smalltalk' , + 'rules' => 'Snakemake' , + 'smk' => 'Snakemake' , 'styl' => 'Stylus' , 'i' => 'SWIG' , 'svelte' => 'Svelte' , @@ -9111,6 +9113,7 @@ sub set_constants { # {{{1 'pom.xml' => 'Maven/XML' , 'Rakefile' => 'Ruby' , 'rakefile' => 'Ruby' , + 'Snakefile' => 'Snakemake' , 'Dockerfile' => 'Dockerfile' , 'Dockerfile.m4' => 'Dockerfile' , 'Dockerfile.cmake' => 'Dockerfile' , @@ -10338,6 +10341,14 @@ sub set_constants { # {{{1 [ 'smarty_to_C' ], [ 'call_regexp_common' , 'C' ], ], + 'Snakemake' => [ + [ 'remove_matches' , '/\*' ], + [ 'remove_matches' , '\*/' ], + [ 'remove_matches' , '^\s*#' ], + [ 'docstring_to_C' ], + [ 'call_regexp_common' , 'C' ], + [ 'remove_inline' , '#.*$' ], + ], 'Standard ML' => [ [ 'remove_between_general', '(*', '*)' ], ], @@ -10762,6 +10773,7 @@ sub set_constants { # {{{1 'kvlang' => '\\\\$' , 'Kermit' => '\\\\$' , 'Korn Shell' => '\\\\$' , + 'Snakemake' => '\\\\$' , 'Starlark' => '\\\\$' , 'Solidity' => '\\\\$' , 'Stata' => '///$' , @@ -11263,6 +11275,7 @@ sub set_constants { # {{{1 'PHP' => 3.50, 'Jupyter Notebook' => 4.20, 'Python' => 4.20, + 'Snakemake' => 4.20, # This is a guess. Copied from Python, because Snakemake supports Python syntax 'RapydScript' => 4.20, 'Starlark' => 4.20, 'BizTalk Pipeline' => 1.00, diff --git a/tests/inputs/Snakefile b/tests/inputs/Snakefile new file mode 100644 index 00000000..502b1d01 --- /dev/null +++ b/tests/inputs/Snakefile @@ -0,0 +1,63 @@ +""" +A sample Snakefile for testing line counting +""" + +SAMPLES = ["A", "B"] + + +# This is a +# multiline +# comment +rule all: + input: + "plots/quals.svg" + + +rule bwa_map: + input: + "data/genome.fa", # Inline comments are also supported + "data/samples/{sample}.fastq" + output: + "mapped_reads/{sample}.bam" + shell: + "bwa mem {input} | samtools view -Sb - > {output}" + + +rule samtools_sort: + input: + "mapped_reads/{sample}.bam" + output: + "sorted_reads/{sample}.bam" + shell: + "samtools sort -T sorted_reads/{wildcards.sample} " + "-O bam {input} > {output}" + + +rule samtools_index: + input: + "sorted_reads/{sample}.bam" + output: + "sorted_reads/{sample}.bam.bai" + shell: + "samtools index {input}" + + +rule bcftools_call: + input: + fa="data/genome.fa", + bam=expand("sorted_reads/{sample}.bam", sample=SAMPLES), + bai=expand("sorted_reads/{sample}.bam.bai", sample=SAMPLES) + output: + "calls/all.vcf" + shell: + "bcftools mpileup -f {input.fa} {input.bam} | " + "bcftools call -mv - > {output}" + + +rule plot_quals: + input: + "calls/all.vcf" + output: + "plots/quals.svg" + script: + "scripts/plot-quals.py" diff --git a/tests/outputs/Snakefile.yaml b/tests/outputs/Snakefile.yaml new file mode 100644 index 00000000..f674bd9a --- /dev/null +++ b/tests/outputs/Snakefile.yaml @@ -0,0 +1,19 @@ +# github.com/AlDanial/cloc +header : + cloc_url : github.com/AlDanial/cloc + cloc_version : 1.99 + elapsed_seconds : 0.039093017578125 + n_files : 1 + n_lines : 63 + files_per_second : 25.5800156128025 + lines_per_second : 1611.54098360656 +'Snakemake' : + nFiles: 1 + blank: 13 + comment: 6 + code: 44 +SUM: + blank: 13 + comment: 6 + code: 44 + nFiles: 1 From 523f733f26fc3ea3cf9d8026e7154dbaa731288d Mon Sep 17 00:00:00 2001 From: Dan F-M Date: Thu, 19 Oct 2023 08:56:13 -0400 Subject: [PATCH 2/2] Responding to comments from @AlDanial --- cloc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cloc b/cloc index 45503bf1..64aaeaf1 100755 --- a/cloc +++ b/cloc @@ -10342,8 +10342,6 @@ sub set_constants { # {{{1 [ 'call_regexp_common' , 'C' ], ], 'Snakemake' => [ - [ 'remove_matches' , '/\*' ], - [ 'remove_matches' , '\*/' ], [ 'remove_matches' , '^\s*#' ], [ 'docstring_to_C' ], [ 'call_regexp_common' , 'C' ], @@ -11275,7 +11273,7 @@ sub set_constants { # {{{1 'PHP' => 3.50, 'Jupyter Notebook' => 4.20, 'Python' => 4.20, - 'Snakemake' => 4.20, # This is a guess. Copied from Python, because Snakemake supports Python syntax + 'Snakemake' => 4.20, 'RapydScript' => 4.20, 'Starlark' => 4.20, 'BizTalk Pipeline' => 1.00,