Skip to content

Commit

Permalink
Switch to seqkit for check_own and concat_contamination
Browse files Browse the repository at this point in the history
  • Loading branch information
matthuska committed Dec 11, 2023
1 parent 814e37b commit 5d87ac4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
2 changes: 2 additions & 0 deletions envs/seqkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ channels:
- conda-forge
dependencies:
- seqkit==2.6.1
- tabix==1.11
- samtools==1.18
31 changes: 6 additions & 25 deletions modules/prepare_contamination.nf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ process download_host {
}

process check_own {
label 'minimap2'
label 'seqkit'

input:
path fasta
Expand All @@ -59,15 +59,7 @@ process check_own {

script:
"""
# -L for following a symbolic link
if ! ( file -L $fasta | grep -q 'BGZF; gzip compatible\\|gzip compressed' ); then
sed -e '\$a\\' ${fasta} > ${fasta}.tmp
bgzip -@ ${task.cpus} < ${fasta}.tmp > ${fasta}.gz
# now $fasta'.gz'
else
mv ${fasta} ${fasta}.tmp
zcat ${fasta}.tmp | sed -e '\$a\\' | bgzip -@ ${task.cpus} -c > ${fasta}.gz
fi
seqkit seq ${fasta} -o ${fasta}.gz
"""
stub:
"""
Expand All @@ -76,7 +68,7 @@ process check_own {
}

process concat_contamination {
label 'minimap2'
label 'seqkit'

publishDir (
path: "${params.output}/intermediate",
Expand All @@ -101,21 +93,10 @@ process concat_contamination {
path 'db.fa.fai', emit: fai

script:
len = fastas.collect().size()
"""
if [[ ${len} -gt 1 ]]
then
for FASTA in ${fastas}
do
NAME="\${FASTA%%.*}"
zcat \$FASTA | awk -v n=\$NAME '/>/{sub(">","&"n"_")}1' | bgzip -@ ${task.cpus} -c >> db.fa.gz
done
else
mv ${fastas} db.fa.gz
fi
samtools faidx db.fa.gz
mv db.fa.gz.fai db.fa.fai
# Combine input files, rename duplicate sequences (by id) if found, and compress
seqkit seq ${fastas} | seqkit rename | bgzip -@ ${task.cpus} -c > db.fa.gz
samtools faidx db.fa.gz --gzi-idx db.fa.fai
"""
stub:
"""
Expand Down

0 comments on commit 5d87ac4

Please sign in to comment.