11# Rules for generic read mapping using BBMap
2+ # TODO: Remove superfluous str conversions when Snakemake is pathlib compatible.
3+ from pathlib import Path
4+
25from snakemake .exceptions import WorkflowError
3- import os .path
46
57localrules :
68 bbmap_counts_table
79 bbmap_featureCounts
810
9- if not os .path .isdir (os .path .join (config ["bbmap" ]["db_path" ], "ref" )):
10- err_message = "BBMap index not found at: '{}'\n " .format (config ["bbmap" ]["db_path" ])
11+ db_path = Path (config ["bbmap" ]["db_path" ])
12+ if not Path (db_path / "ref" ).exists ():
13+ err_message = "BBMap index not found at: '{}'\n " .format (db_path )
1114 err_message += "Check path in config setting 'bbmap:db_path'.\n "
1215 err_message += "If you want to skip mapping with BBMap, set mappers:bbmap:False in config.yaml."
1316 raise WorkflowError (err_message )
1417
1518# Add final output files from this module to 'all_outputs' from the main
1619# Snakefile scope. SAMPLES is also from the main Snakefile scope.
17- bbmap_alignments = expand ("{outdir}/bbmap/{db_name}/{sample}.{output_type}" ,
18- outdir = config ["outdir" ],
20+ bbmap_alignments = expand (str (OUTDIR / "bbmap/{db_name}/{sample}.{output_type}" ),
1921 db_name = config ["bbmap" ]["db_name" ],
2022 sample = SAMPLES ,
2123 output_type = ("sam.gz" , "covstats.txt" , "rpkm.txt" ))
22- counts_table = expand ("{outdir}/bbmap/{db_name}/all_samples.counts_table.tab" ,
23- outdir = config ["outdir" ],
24+ counts_table = expand (str (OUTDIR / "bbmap/{db_name}/all_samples.counts_table.tab" ),
2425 db_name = config ["bbmap" ]["db_name" ],
2526 sample = SAMPLES )
26- featureCounts = expand ("{outdir}/bbmap/{db_name}/all_samples.featureCounts{output_type}" ,
27- outdir = config ["outdir" ],
27+ featureCounts = expand (str (OUTDIR / "bbmap/{db_name}/all_samples.featureCounts{output_type}" ),
2828 db_name = config ["bbmap" ]["db_name" ],
2929 sample = SAMPLES ,
3030 output_type = ["" , ".summary" , ".table.tsv" ])
3131all_outputs .extend (bbmap_alignments )
3232if config ["bbmap" ]["counts_table" ]["annotations" ]:
33- if not os . path . isfile (config ["bbmap" ]["counts_table" ]["annotations" ]):
33+ if not Path (config ["bbmap" ]["counts_table" ]["annotations" ]). exists ( ):
3434 err_message = "BBMap counts table annotations not found at: '{}'\n " .format (config ["bbmap" ]["counts_table" ]["annotations" ])
3535 err_message += "Check path in config setting 'bbmap:counts_table:annotations'.\n "
3636 err_message += "If you want to skip read counts summary for BBMap, set bbmap:counts_table:annotations to '' in config.yaml."
3737 raise WorkflowError (err_message )
3838 all_outputs .extend (counts_table )
3939if config ["bbmap" ]["featureCounts" ]["annotations" ]:
40- if not os . path . isfile (config ["bbmap" ]["featureCounts" ]["annotations" ]):
40+ if not Path (config ["bbmap" ]["featureCounts" ]["annotations" ]). exists ( ):
4141 err_message = "BBMap featureCounts annotations not found at: '{}'\n " .format (config ["bbmap" ]["featureCounts" ]["annotations" ])
4242 err_message += "Check path in config setting 'bbmap:featureCounts:annotations'.\n "
4343 err_message += "If you want to skip mapping with BBMap, set mappers:bbmap:False in config.yaml."
4444 raise WorkflowError (err_message )
4545 all_outputs .extend (featureCounts )
4646
4747bbmap_config = config ["bbmap" ]
48- bbmap_output_folder = config [ "outdir" ] + "/ bbmap/{db_name}/ " .format (db_name = bbmap_config ["db_name" ])
48+ bbmap_output_folder = OUTDIR / " bbmap/{db_name}" .format (db_name = bbmap_config ["db_name" ])
4949rule bbmap :
5050 """BBMap"""
5151 input :
52- read1 = config [ "outdir" ] + "/ filtered_human/{sample}_R1.filtered_human.fq.gz" ,
53- read2 = config [ "outdir" ] + "/ filtered_human/{sample}_R2.filtered_human.fq.gz" ,
52+ read1 = OUTDIR / " filtered_human/{sample}_R1.filtered_human.fq.gz" ,
53+ read2 = OUTDIR / " filtered_human/{sample}_R2.filtered_human.fq.gz" ,
5454 output :
55- sam = bbmap_output_folder + "{sample}.sam.gz" ,
56- covstats = bbmap_output_folder + "{sample}.covstats.txt" ,
57- rpkm = bbmap_output_folder + "{sample}.rpkm.txt" ,
55+ sam = bbmap_output_folder / "{sample}.sam.gz" ,
56+ covstats = bbmap_output_folder / "{sample}.covstats.txt" ,
57+ rpkm = bbmap_output_folder / "{sample}.rpkm.txt" ,
5858 log :
59- stdout = config [ "outdir" ] + "/logs/ bbmap/{sample}.bbmap.stdout.log" ,
60- stderr = config [ "outdir" ] + "/logs/ bbmap/{sample}.bbmap.statsfile.txt"
59+ stdout = str ( LOGDIR / " bbmap/{sample}.bbmap.stdout.log") ,
60+ stderr = str ( LOGDIR / " bbmap/{sample}.bbmap.statsfile.txt"),
6161 shadow :
6262 "shallow"
6363 conda :
@@ -87,13 +87,13 @@ rule bbmap:
8787
8888rule bbmap_counts_table :
8989 input :
90- rpkms = expand (config [ "outdir" ] + "/ bbmap/{dbname}/{sample}.rpkm.txt" ,
90+ rpkms = expand (str ( OUTDIR / " bbmap/{dbname}/{sample}.rpkm.txt") ,
9191 dbname = bbmap_config ["db_name" ],
9292 sample = SAMPLES )
9393 output :
94- counts = config [ "outdir" ] + "/ bbmap/{dbname}/all_samples.counts_table.tab" .format (dbname = bbmap_config ["db_name" ]),
94+ counts = OUTDIR / " bbmap/{dbname}/all_samples.counts_table.tab" .format (dbname = bbmap_config ["db_name" ]),
9595 log :
96- config [ "outdir" ] + "/logs/ bbmap/{dbname}/all_samples.counts_table.log" .format (dbname = bbmap_config ["db_name" ])
96+ str ( LOGDIR / " bbmap/{dbname}/all_samples.counts_table.log" .format (dbname = bbmap_config ["db_name" ]) )
9797 shadow :
9898 "shallow"
9999 conda :
@@ -115,15 +115,15 @@ rule bbmap_counts_table:
115115fc_config = bbmap_config ["featureCounts" ]
116116rule bbmap_featureCounts :
117117 input :
118- bams = expand (config [ "outdir" ] + "/ bbmap/{dbname}/{sample}.sam.gz" ,
118+ bams = expand (str ( OUTDIR / " bbmap/{dbname}/{sample}.sam.gz") ,
119119 dbname = bbmap_config ["db_name" ],
120120 sample = SAMPLES )
121121 output :
122- counts = config [ "outdir" ] + "/ bbmap/{dbname}/all_samples.featureCounts" .format (dbname = bbmap_config ["db_name" ]),
123- counts_table = config [ "outdir" ] + "/ bbmap/{dbname}/all_samples.featureCounts.table.tsv" .format (dbname = bbmap_config ["db_name" ]),
124- summary = config [ "outdir" ] + "/ bbmap/{dbname}/all_samples.featureCounts.summary" .format (dbname = bbmap_config ["db_name" ]),
122+ counts = OUTDIR / " bbmap/{dbname}/all_samples.featureCounts" .format (dbname = bbmap_config ["db_name" ]),
123+ counts_table = OUTDIR / " bbmap/{dbname}/all_samples.featureCounts.table.tsv" .format (dbname = bbmap_config ["db_name" ]),
124+ summary = OUTDIR / " bbmap/{dbname}/all_samples.featureCounts.summary" .format (dbname = bbmap_config ["db_name" ]),
125125 log :
126- config [ "outdir" ] + "/logs/ bbmap/{dbname}/all_samples.featureCounts.log" .format (dbname = bbmap_config ["db_name" ])
126+ str ( LOGDIR / " bbmap/{dbname}/all_samples.featureCounts.log" .format (dbname = bbmap_config ["db_name" ]) )
127127 shadow :
128128 "shallow"
129129 conda :
0 commit comments