From b04bfa4eca9fabfc3f85ee362f62e3ad7c432449 Mon Sep 17 00:00:00 2001 From: hoelzer Date: Tue, 20 Feb 2024 10:15:05 +0100 Subject: [PATCH] fix virsorter filtering when there are no class 1,2,3,4 detections --- workflows/process/sourmash/sourmash.nf | 1 + workflows/process/virsorter/filter_virsorter.nf | 14 +++++++++----- .../virsorter_virome/filter_virsorter_virome.nf | 14 +++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/workflows/process/sourmash/sourmash.nf b/workflows/process/sourmash/sourmash.nf index 0266624..005df01 100644 --- a/workflows/process/sourmash/sourmash.nf +++ b/workflows/process/sourmash/sourmash.nf @@ -23,6 +23,7 @@ process sourmash { filename=\$(basename \${tempfile} .fa.sig.temporary) prediction_value=\$(grep -v "similarity,md5,filename,name,query_filename,query_name,query_md5,ani" \${tempfile} |sort -r -k1 | awk 'NR == 1' | cut -d "," -f1 ) + touch ${name}_\${PWD##*/}.list if [ \$value -gt 0 ] then echo "\$filename,\$prediction_value" >> ${name}_\${PWD##*/}.list fi diff --git a/workflows/process/virsorter/filter_virsorter.nf b/workflows/process/virsorter/filter_virsorter.nf index 06bda84..a014c6f 100644 --- a/workflows/process/virsorter/filter_virsorter.nf +++ b/workflows/process/virsorter/filter_virsorter.nf @@ -26,10 +26,14 @@ process filter_virsorter { echo "\$line,0" >> pro_phage_virsorter.tsv fi done < virsorter_categorized_contigs_*.list - grep ">" virsorter_phage.tsv | \\ - sed -e s/\\>VIRSorter_//g | \\ - sed -e s/\\-cat_[1-3]//g | \\ - awk -F, '{print \$1, \$2}' OFS="\\t" > virsorter_\${PWD##*/}.tsv - rm virsorter_phage.tsv + if [ -s virsorter_phage.tsv ]; then + grep ">" virsorter_phage.tsv | \\ + sed -e s/\\>VIRSorter_//g | \\ + sed -e s/\\-cat_[1-3]//g | \\ + awk -F, '{print \$1, \$2}' OFS="\\t" > virsorter_\${PWD##*/}.tsv + rm virsorter_phage.tsv + else + touch virsorter_\${PWD##*/}.tsv + fi """ } \ No newline at end of file diff --git a/workflows/process/virsorter_virome/filter_virsorter_virome.nf b/workflows/process/virsorter_virome/filter_virsorter_virome.nf index 98380a8..03e7d16 100644 --- a/workflows/process/virsorter_virome/filter_virsorter_virome.nf +++ b/workflows/process/virsorter_virome/filter_virsorter_virome.nf @@ -27,10 +27,14 @@ process filter_virsorter_virome { fi done < virsorter_categorized_contigs_*.list - grep ">" virsorter_phage.tsv | \\ - sed -e s/\\>VIRSorter_//g | \\ - sed -e s/\\-cat_[1-3]//g | \\ - awk -F, '{print \$1, \$2}' OFS="\\t" > virsorter-virome_\${PWD##*/}.tsv - rm virsorter_phage.tsv + if [ -s virsorter_phage.tsv ]; then + grep ">" virsorter_phage.tsv | \\ + sed -e s/\\>VIRSorter_//g | \\ + sed -e s/\\-cat_[1-3]//g | \\ + awk -F, '{print \$1, \$2}' OFS="\\t" > virsorter-virome_\${PWD##*/}.tsv + rm virsorter_phage.tsv + else + touch virsorter-virome_\${PWD##*/}.tsv + fi """ }