NBISweden / aMeta

Ancient microbiome snakemake workflow
MIT License
19 stars 15 forks source link

mapdamage rule fails when no pathogen present #104

Closed LeandroRitter closed 1 year ago

LeandroRitter commented 1 year ago

If no pathogenic microbes are listed in results/KRAKENUNIQ/{sample}/taxID.pathogens the MapDamage rule fails. Perhaps just a simple if-statement would help to skip this rule entirely in case the results/KRAKENUNIQ/{sample}/taxID.pathogens is empty? Like this:

shell:
    "mkdir {output.dir}; "
    "if [ -s {input.pathogen_tax_id} ]; then "
    'cat {input.pathogen_tax_id} | parallel -j {threads} "grep -w {{}} {params.pathogenome_path}/seqid2taxid.pathogen.map | cut -f1 > {output.dir}/{{}}.seq_ids" ; '
    "for i in $(cat {input.pathogen_tax_id}); do xargs --arg-file={output.dir}/${{i}}.seq_ids samtools view -bh {input.bam} --write-index -@ {threads} -o {output.dir}/${{i}}.tax.bam; done >> {log} 2>&1; "
    "find {output.dir} -name '*.tax.bam' | parallel -j {threads} \"mapDamage {params.options} -i {{}} -r {params.PATHO_DB} --merge-reference-sequences -d {output.dir}/mapDamage_{{}}\" >> {log} 2>&1 || true; "
    "for filename in {output.dir}/*.tax.bam; do newname=`echo $filename | sed 's/tax\.//g'`; mv $filename $newname; done >> {log} 2>&1; "
    "mv {output.dir}/mapDamage_{output.dir}/* {output.dir} >> {log} 2>&1; "
    "rm -r {output.dir}/mapDamage_results >> {log} 2>&1; "
    "else echo NO MICROBES TO AUTHENTICATE > {output.dir}/README.txt; fi"
LeandroRitter commented 1 year ago

Solved with the latest PR