Skip to content

Commit 04edee5

Browse files
committed
report now incorporates read-based reference analysis. some fixes needed for contig-based
1 parent 4d721de commit 04edee5

File tree

9 files changed

+117
-32
lines changed

9 files changed

+117
-32
lines changed

workflows/Nextflow/main.nf

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ workflow {
114114
}
115115

116116
//Reference-based analysis
117+
readsToRefReports = channel.empty()
118+
contigsToRefReports = channel.empty()
117119
if(params.modules.refBasedAnalysis) {
118120
REFERENCEBASEDANALYSIS(baseSettings.plus(params.refBased).plus(params.contigsToRef), platform, paired, unpaired, contigs.ifEmpty("${projectDir}/nf_assets/NO_FILE3"))
121+
readsToRefReports = REFERENCEBASEDANALYSIS.out.readsToRefReports
119122
}
120123

121124
//Reads-based taxonomic classification
@@ -164,16 +167,17 @@ workflow {
164167

165168
//report generation
166169
REPORT(
167-
baseSettings,
170+
baseSettings.plus(params.refBased),
168171
platform,
169-
counts.ifEmpty{file("DNE")},
170-
qcStats.ifEmpty{file("DNE1")},
171-
qcReport.ifEmpty{file("DNE2")},
172-
rtaReports.ifEmpty{file("DNE4")},
173-
ctaReport.ifEmpty{file("DNE5")},
174-
contigStatsReport.ifEmpty{file("DNE6")},
175-
contigPlots.ifEmpty{file("DNE7")},
176-
annStats.ifEmpty{file("DNE8")},
177-
alnStats.ifEmpty{file("DNE9")}
172+
counts.ifEmpty{file("${projectDir}/nf_assets/NO_FILE")},
173+
qcStats.ifEmpty{file("${projectDir}/nf_assets/NO_FILE2")},
174+
qcReport.ifEmpty{file("${projectDir}/nf_assets/NO_FILE3")},
175+
rtaReports.ifEmpty{file("${projectDir}/nf_assets/NO_FILE4")},
176+
ctaReport.ifEmpty{file("${projectDir}/nf_assets/NO_FILE5")},
177+
contigStatsReport.ifEmpty{file("${projectDir}/nf_assets/NO_FILE6")},
178+
contigPlots.ifEmpty{file("${projectDir}/nf_assets/NO_FILE7")},
179+
annStats.ifEmpty{file("${projectDir}/nf_assets/NO_FILE8")},
180+
alnStats.ifEmpty{file("${projectDir}/nf_assets/NO_FILE9")},
181+
readsToRefReports.ifEmpty{file("${projectDir}/nf_assets/NO_FILEa")}
178182
)
179183
}

workflows/Nextflow/modules/referenceBasedAnalysis/refBasedAnalysis.nf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ process referenceBasedPipeline {
1919
path paired
2020
path unpaired
2121

22+
2223
output:
2324
path "*"
25+
path "readsToRef{_plots.pdf,.alnstats.txt}", emit: readsToRefReports
2426
path "readsToRef.gaps", emit: gaps
2527
path "readsToRef.vcf", optional:true, emit: vcf
2628
path "*.sort.bam", emit: bam
@@ -312,11 +314,18 @@ workflow REFERENCEBASEDANALYSIS {
312314
reference = reference.concat(channel.fromPath(settings["referenceGenomes"], checkIfExists: true))
313315
}
314316

315-
referenceBasedPipeline(settings, reference.collect(), platform, paired, unpaired)
317+
alignmentBam = channel.empty()
318+
readsToRefReports = channel.empty()
319+
//run reads-based pipeline if any non-placeholder inputs were given for reads
320+
if(settings["inputFastq"].size() > 0 || settings["sra2fastq"].toBoolean()) {
321+
referenceBasedPipeline(settings, reference.collect(), platform, paired, unpaired)
322+
alignmentBam = referenceBasedPipeline.out.bam
323+
readsToRefReports = referenceBasedPipeline.out.readsToRefReports
324+
}
316325

317326
//retrieve unmapped READS if mapping or just extracting
318327
if((settings["r2gMapUnmapped"].toBoolean())|| (settings["r2gExtractUnmapped"].toBoolean())) {
319-
retrieveUnmappedReads(settings, reference, paired, referenceBasedPipeline.out.bam)
328+
retrieveUnmappedReads(settings, reference, paired, alignmentBam)
320329
if(settings["r2gMapUnmapped"]) {
321330
//map unmapped reads to RefSeq
322331
mapUnmapped(settings,
@@ -343,4 +352,10 @@ workflow REFERENCEBASEDANALYSIS {
343352
reference)
344353
}
345354

355+
356+
357+
emit:
358+
readsToRefReports
359+
//contigsToRefReports
360+
346361
}

workflows/Nextflow/modules/referenceBasedAnalysis/resources/usr/bin/nucmer_genome_coverage.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
}
5959
else
6060
{
61-
system ("nucmer --maxmatch -c $mincluster --prefix=$prefix $referenceFile $queryFile 2>/dev/null");
61+
print("nucmer --maxmatch -c $mincluster --prefix=$prefix $referenceFile $queryFile");
62+
system ("nucmer --maxmatch -c $mincluster --prefix=$prefix $referenceFile $queryFile");
6263
system ("show-coords -clTr $prefix.delta > $prefix.coords");
6364
system ("delta-filter -1 -i $identity_cutoff $prefix.delta > $prefix.filterforSNP");
6465
system ("show-snps -CT $prefix.filterforSNP > $prefix.snps");

workflows/Nextflow/modules/report/report.nf

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ process report {
3232
path contigPlots
3333
path annStats
3434
path alnstats
35+
path readsToRefReports
3536

3637
output:
3738
path "*"
@@ -49,26 +50,27 @@ process report {
4950
my \$ont_flag = ("${platform != null ? platform.trim(): ""}" =~ /NANOPORE/)? 1 : 0;
5051
my \$pacbio_flag = ("${platform != null ? platform.trim(): ""}" =~ /PACBIO/)? 1 : 0;
5152
my \$mergeFiles="\$InputLogPDF,";
52-
\$mergeFiles.="$qcReport"."," if ( -e "$qcReport");
53+
\$mergeFiles.="$qcReport"."," if ( -s "$qcReport");
5354
my \$imagesDir = "./HTML_Report/images";
5455
my \$final_pdf= "./final_report.pdf";
5556
5657
58+
59+
5760
my \$taxonomyPDFfiles="";
58-
\$taxonomyPDFfiles .= "$readsTaxonomyReports" if("$readsTaxonomyReports" ne "DNE4");
61+
\$taxonomyPDFfiles .= "$readsTaxonomyReports" if("$readsTaxonomyReports" ne "NO_FILE4");
5962
\$taxonomyPDFfiles =~ s/\\s/,/g;
60-
\$taxonomyPDFfiles .= "$contigTaxonomyReport"."," if( -e "$contigTaxonomyReport");
63+
\$taxonomyPDFfiles .= "$contigTaxonomyReport"."," if( -s "$contigTaxonomyReport");
6164
6265
6366
my \$qc_flag = (${settings['faqcs']})?"V":"";
6467
my \$assembly_flag = (${settings["runAssembly"]})?"V":"";
6568
my \$annotation_flag = (${settings["annotation"]})?"V":"";
6669
my \$taxonomy_flag = (${settings["readsTaxonomyAssignment"]})?"V":"";
6770
68-
my \$features_parameters = "qc<-c(\\"\$qc_flag\\",\\"QC\\")\\nhost<-c(\\"\$host_removal_flag\\",\\"Host Removal\\")\\n
71+
my \$features_parameters = "qc<-c(\\"\$qc_flag\\",\\"QC\\")\\n
6972
assembly<-c(\\"\$assembly_flag\\",\\"Assembly\\")\\nannotation<-c(\\"\$assembly_flag\\",\\"Annotation\\")\\n
70-
taxonomy<-c(\\"\$taxonomy_flag\\",\\"Taxonomy Classification\\")\\n
71-
primer<-c(\\"\$primer_flag\\",\\"Primer Design\\")\\n";
73+
taxonomy<-c(\\"\$taxonomy_flag\\",\\"Taxonomy Classification\\")\\n";
7274
7375
open (my \$Rfh, ">\$Rscript") or die "\$Rscript \$!";
7476
print \$Rfh <<Rscript;
@@ -85,10 +87,22 @@ process report {
8587
input_pos<-nextPos-0.28
8688
Rscript
8789
90+
91+
if(${settings['refBasedAnalysis']}){
92+
print \$Rfh <<Rscript;
93+
94+
text(0,nextPos,paste("Reference:",\"${settings["selectGenomes"].plus(settings["referenceGenomes"]).join(", ")}\"),adj=0,font=2)
95+
nextPos<-nextPos-0.08
96+
parameters_pos<-nextPos-0.12
97+
input_pos<-nextPos-0.26
98+
Rscript
99+
}
100+
101+
88102
print \$Rfh <<Rscript;
89103
text(0,nextPos,"Features:",adj=0,font=2)
90104
\$features_parameters
91-
parameters<-rbind(qc,host,assembly,annotation,taxonomy,primer)
105+
parameters<-rbind(qc,assembly,annotation,taxonomy)
92106
rownames(parameters)<-parameters[,2]
93107
parameters<-t(parameters)
94108
parameters[2,]<-\\"\\"
@@ -113,11 +127,41 @@ process report {
113127
Rscript
114128
}
115129
130+
if ((\$ont_flag or \$pacbio_flag)&& -s "$qcStats" ){
131+
print \$Rfh <<Rscript;
132+
def.par <- par(no.readonly = TRUE)
133+
pdf(file = \"$qcReport\",width=10,height=8)
134+
par(family="mono")
135+
SummaryStats<-readLines("$qcStats")
136+
plot(0:1,0:1,type=\'n\',xlab=\"\",ylab=\"\",xaxt=\'n\',yaxt=\'n\',bty=\'n\')
137+
adjust<-11
138+
abline(h=0.85,lty=2)
139+
for (i in 1:length(SummaryStats)){
140+
if (i>5 && i<adjust){
141+
text(0.45,1-0.035*(i-6),SummaryStats[i],adj=0,font=2,cex=0.9)
142+
}else if(i >=adjust){
143+
text(0.05,1-0.035*(i-6),SummaryStats[i],adj=0,font=2,cex=0.9)
144+
}else{
145+
text(0.05,1-0.035*(i-1),SummaryStats[i],adj=0,font=2,cex=0.9)
146+
}
147+
}
148+
149+
title("QC stats")
150+
par(def.par)#- reset to default
151+
tmp<-dev.off()
152+
Rscript
116153
117-
if (-e "$contigStatsReport"){
154+
#TODO: nanoplot plots
155+
156+
157+
}
158+
159+
160+
161+
if (-s "$contigStatsReport"){
118162
\$mergeFiles .= '$contigStatsReport'.",";
119163
}
120-
if ( -e "$alnstats"){
164+
if ( -s "$alnstats"){
121165
\$mergeFiles .= "alnstats.pdf".",".'$contigPlots'.",";
122166
print \$Rfh <<Rscript;
123167
pdf(file = "alnstats.pdf",width = 10, height = 8)
@@ -135,7 +179,26 @@ process report {
135179
136180
}
137181
138-
\$mergeFiles .= '$annStats'."," if ( -e '$annStats');
182+
\$mergeFiles .= '$annStats'."," if ( -s '$annStats');
183+
184+
if (${settings['refBasedAnalysis']}) {
185+
if ( -s "${readsToRefReports[0]}"){
186+
\$mergeFiles .= "${readsToRefReports[1]}".","."${readsToRefReports[0]}".",";
187+
print \$Rfh <<Rscript;
188+
pdf(file = "${readsToRefReports[1]}",width = 10, height = 8)
189+
190+
readsMappingToRefStats<-readLines("${readsToRefReports[0]}",n=11)
191+
readsMappingToRefStats<-gsub("-?nan","0",readsMappingToRefStats,ignore.case = TRUE)
192+
plot(0:1,0:1,type='n',xlab="",ylab="",xaxt='n',yaxt='n')
193+
for (i in 1:length(readsMappingToRefStats)){
194+
text(0,1-0.07*i,readsMappingToRefStats[i],adj=0,font=2)
195+
}
196+
title("Mapping Reads to Reference")
197+
tmp<-dev.off()
198+
Rscript
199+
}
200+
}
201+
139202
140203
\$mergeFiles .= \$taxonomyPDFfiles if (\$taxonomyPDFfiles);
141204
@@ -152,7 +215,7 @@ process report {
152215
153216
154217
my @conversions;
155-
if ( -e "$qcReport")
218+
if ( -s "$qcReport")
156219
{
157220
my \$page_count = `pdfPageCount.pl "$qcReport"`;
158221
chomp \$page_count;
@@ -165,19 +228,19 @@ process report {
165228
push @conversions, "convert -strip -density 120 -flatten $qcReport[\$qc_boxplot_page] ./QC_quality_boxplot.png";
166229
}
167230
168-
push @conversions, "convert -strip -density 120 -flatten $contigStatsReport[0] ./Assembly_length.png" if (-e "$contigStatsReport");
169-
push @conversions, "convert -strip -density 120 -flatten $contigStatsReport[1] ./Assembly_GC_content.png" if (-e "$contigStatsReport");
170-
push @conversions, "convert -strip -density 120 -flatten $contigPlots[0] ./Assembly_CovDepth_vs_Len.png" if (-e "$contigPlots");
171-
push @conversions, "convert -strip -density 120 -flatten $contigPlots[1] ./Assembly_Cov_vs_Len.png" if (-e "$contigPlots");
172-
push @conversions, "convert -strip -density 120 -flatten $contigPlots[2] ./Assembly_GC_vs_CovDepth.png" if (-e "$contigPlots");
173-
push @conversions, "convert -strip -density 120 -flatten $annStats ./annotation_stats_plots.png" if (-e "$annStats");
231+
push @conversions, "convert -strip -density 120 -flatten $contigStatsReport[0] ./Assembly_length.png" if (-s "$contigStatsReport");
232+
push @conversions, "convert -strip -density 120 -flatten $contigStatsReport[1] ./Assembly_GC_content.png" if (-s "$contigStatsReport");
233+
push @conversions, "convert -strip -density 120 -flatten $contigPlots[0] ./Assembly_CovDepth_vs_Len.png" if (-s "$contigPlots");
234+
push @conversions, "convert -strip -density 120 -flatten $contigPlots[1] ./Assembly_Cov_vs_Len.png" if (-s "$contigPlots");
235+
push @conversions, "convert -strip -density 120 -flatten $contigPlots[2] ./Assembly_GC_vs_CovDepth.png" if (-s "$contigPlots");
236+
push @conversions, "convert -strip -density 120 -flatten $annStats ./annotation_stats_plots.png" if (-s "$annStats");
174237
175238
foreach my \$file(split /,/, \$taxonomyPDFfiles)
176239
{
177240
next if (\$file eq "$contigTaxonomyReport");
178241
my (\$file_name, \$file_path, \$file_suffix)=fileparse("\$file", qr/\\.[^.]*/);
179242
my \$size_opt = (\$file_name =~ /tree/)? "-resize 240":"-density 120";
180-
push @conversions, "convert \$size_opt -colorspace RGB -flatten \$file ./\$file_name.png" if (-e \$file);
243+
push @conversions, "convert \$size_opt -colorspace RGB -flatten \$file ./\$file_name.png" if (-s \$file);
181244
}
182245
183246
eval {system(\$_)} foreach (@conversions);
@@ -199,6 +262,7 @@ workflow REPORT {
199262
contigPlots
200263
annStats
201264
alnStats
265+
readsToRefReports
202266

203267
main:
204268
report(settings,
@@ -211,6 +275,7 @@ workflow REPORT {
211275
contigStatsReport,
212276
contigPlots,
213277
annStats,
214-
alnStats)
278+
alnStats,
279+
readsToRefReports)
215280

216281
}

workflows/Nextflow/nf_assets/NO_FILE6

Whitespace-only changes.

workflows/Nextflow/nf_assets/NO_FILE7

Whitespace-only changes.

workflows/Nextflow/nf_assets/NO_FILE8

Whitespace-only changes.

workflows/Nextflow/nf_assets/NO_FILE9

Whitespace-only changes.

workflows/Nextflow/nf_assets/NO_FILEa

Whitespace-only changes.

0 commit comments

Comments
 (0)