Skip to content

Commit

Permalink
way better samtools error fail save
Browse files Browse the repository at this point in the history
  • Loading branch information
replikation committed Aug 18, 2020
1 parent caa8540 commit d675d96
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions modules/samtools.nf
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
process samtools {
publishDir "${params.output}/${name}/phage_positive_contigs", mode: 'copy', pattern: "${name}_positive_contigs.fa"
label 'samtools'
publishDir "${params.output}/${name}/phage_positive_contigs", mode: 'copy', pattern: "${name}_positive_contigs.fa"
label 'samtools'
input:
tuple val(name), file(file), file(list)
tuple val(name), file(file), file(list)
output:
tuple val(name), file("${name}_positive_contigs.fa")
tuple val(name), file("${name}_positive_contigs.fa")
script:
"""
cat ${list} | sort | uniq > tmp_allctgs.txt
cat ${file} > all.fasta
xargs samtools faidx all.fasta < tmp_allctgs.txt > ${name}_positive_contigs.fa
"""
"""
cat ${list} | sort | uniq > tmp_allctgs.txt
cat ${file} > all.fasta
# get samtools but ignore "samtool fails"
while read fastaheader; do
if grep -qw ">\$fastaheader" all.fasta; then
samtools faidx all.fasta \$fastaheader >> ${name}_positive_contigs.fa
else
echo "\$fastaheader not found" >> error_code_samtools.txt
fi
done < tmp_allctgs.txt
# old command
# xargs samtools faidx all.fasta < tmp_allctgs.txt > ${name}_positive_contigs.fa
"""
}

process samtools_fastq {
publishDir "${params.output}/${name}/phage_positive_contigs", mode: 'copy', pattern: "${name}_positive_contigs.fa"
label 'samtools'
publishDir "${params.output}/${name}/phage_positive_contigs", mode: 'copy', pattern: "${name}_positive_contigs.fa"
label 'samtools'
input:
tuple val(name), file(file), file(list)
tuple val(name), file(file), file(list)
output:
tuple val(name), file("${name}_positive_contigs.fa")
tuple val(name), file("${name}_positive_contigs.fa")
script:
"""
cat ${list} | sort | uniq > tmp_allctgs.txt
cat ${file} > all.fasta
xargs samtools faidx all.fasta < tmp_allctgs.txt > ${name}_positive_contigs.fa
"""
cat ${list} | sort | uniq > tmp_allctgs.txt
cat ${file} > all.fasta
# get samtools but ignore "samtool fails"
while read fastaheader; do
if grep -qw ">\$fastaheader" all.fasta; then
samtools faidx all.fasta \$fastaheader >> ${name}_positive_contigs.fa
else
echo "\$fastaheader not found" >> error_code_samtools.txt
fi
done < tmp_allctgs.txt
# old command
# xargs samtools faidx all.fasta < tmp_allctgs.txt > ${name}_positive_contigs.fa
"""
}

0 comments on commit d675d96

Please sign in to comment.