Skip to content

Commit

Permalink
report adjustments and updates for stability
Browse files Browse the repository at this point in the history
  • Loading branch information
replikation committed Apr 21, 2021
1 parent 1bcfa06 commit 8f3df11
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
17 changes: 12 additions & 5 deletions workflows/create_summary_report.nf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include { summary_report } from './process/summary_report'
include { summary_report; summary_report_fasta; summary_report_default } from './process/summary_report'
include { plot_coverages } from '../modules/plot_coverages.nf'

workflow create_summary_report_wf {
Expand All @@ -9,22 +9,29 @@ workflow create_summary_report_wf {
kraken2
alignments
samples_list
main:
main:
version_ch = Channel.fromPath(workflow.projectDir + "/configs/container.config")

pangolin_results = pangolin.map {it -> it[1]}.collectFile(name: 'pangolin_results.csv', skip: 1, keepHeader: true)
president_results = president.map {it -> it[1]}.collectFile(name: 'president_results.tsv', skip: 1, keepHeader: true)
nextclade_results = nextclade.map {it -> it[1]}.collectFile(name: 'nextclade_results.tsv', skip: 1, keepHeader: true)
kraken2_results = kraken2.map {it -> it[2]}.collect()

alignment_files = alignments.map {it -> it[0]}.collect()
if (params.fasta || workflow.profile.contains('test_fasta')) {
coverage_plots = Channel.from( ['deactivated'] ).collect()

summary_report_fasta(version_ch, pangolin_results, president_results, nextclade_results)

} else {
kraken2_results = kraken2.map {it -> it[2]}.collect()
// sort by sample name, group in lists of 6, collect the grouped plots
coverage_plots = plot_coverages(alignments.map{it -> it[0]}.toSortedList({ a, b -> a.simpleName <=> b.simpleName }).flatten().collate(6), \
alignments.map{it -> it[1]}.toSortedList({ a, b -> a.simpleName <=> b.simpleName }).flatten().collate(6)).collect()

if (params.samples) { summary_report(version_ch, pangolin_results, president_results, nextclade_results, kraken2_results, coverage_plots, samples_list) }
else { summary_report_default(version_ch, pangolin_results, president_results, nextclade_results, kraken2_results, coverage_plots) }

}

summary_report(version_ch, pangolin_results, president_results, nextclade_results, kraken2_results, coverage_plots, samples_list)


}
1 change: 1 addition & 0 deletions workflows/process/nextclade.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ process nextclade {
tuple val(name), path(consensus)
output:
tuple val(name), path("${name}_clade.tsv")
script:
"""
nextclade --input-fasta ${consensus} --output-tsv tmp.tsv
cat tmp.tsv | tr -d "\r" > ${name}_clade.tsv
Expand Down
59 changes: 55 additions & 4 deletions workflows/process/summary_report.nf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,44 @@ process summary_report {
path("poreCov_summary_report_*.tsv")

shell:
if (params.fasta || workflow.profile.contains('test_fasta'))
'''
echo 'sample,num_unclassified,num_sarscov2,num_human' > kraken2_results.csv
for KF in !{kraken2_results}; do
NUNCLASS=$(awk -v ORS= '$5=="0" {print $3}' $KF)
NSARS=$(awk -v ORS= '$5=="2697049" {print $3}' $KF)
NHUM=$(awk '$5=="9606" {print $3}' $KF)
echo "${KF%.kreport},${NUNCLASS:-0},${NSARS:-0},${NHUM:-0}" >> kraken2_results.csv
done
summary_report.py \
-v !{version_config} \
--porecov_version !{workflow.revision}:!{workflow.commitId}:!{workflow.scriptId} \
--primer !{params.primerV} \
-p !{pangolin_results} \
-q !{president_results} \
-n !{nextclade_results} \
-k kraken2_results.csv \
-c $(echo !{coverage_plots} | tr ' ' ',') \
-s !{samples_list}
'''
else
}

process summary_report_default {
publishDir "${params.output}/", mode: 'copy'
label 'fastcov'
input:
path(version_config)
path(pangolin_results)
path(president_results)
path(nextclade_results)
path(kraken2_results)
path(coverage_plots)
output:
path("poreCov_summary_report_*.html")
path("poreCov_summary_report_*.xlsx")
path("poreCov_summary_report_*.tsv")

shell:
'''
echo 'sample,num_unclassified,num_sarscov2,num_human' > kraken2_results.csv
for KF in !{kraken2_results}; do
Expand All @@ -43,7 +70,31 @@ process summary_report {
-q !{president_results} \
-n !{nextclade_results} \
-k kraken2_results.csv \
-c $(echo !{coverage_plots} | tr ' ' ',') \
-s !{samples_list}
-c $(echo !{coverage_plots} | tr ' ' ',')
'''
}

process summary_report_fasta {
publishDir "${params.output}/", mode: 'copy'
label 'fastcov'
input:
path(version_config)
path(pangolin_results)
path(president_results)
path(nextclade_results)
output:
path("poreCov_summary_report_*.html")
path("poreCov_summary_report_*.xlsx")
path("poreCov_summary_report_*.tsv")

script:
"""
summary_report.py \
-v ${version_config} \
--porecov_version ${workflow.revision}:${workflow.commitId}:${workflow.scriptId} \
-p ${pangolin_results} \
-q ${president_results} \
-n ${nextclade_results} \
-s "deactivated"
"""
}

0 comments on commit 8f3df11

Please sign in to comment.