Skip to content

Commit 497f328

Browse files
committed
output abundances per sample in one file, optimise scatter plot
1 parent 88b6cc1 commit 497f328

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

bin/compare_performance.r

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,20 @@ if (length(SAMPLES) == 0) {
179179

180180
# (B) ANALYSE
181181

182-
# Initialize dataframe
182+
# Initialize dataframes
183183
df <- data.frame(
184184
sample=character(),
185185
type=character(),
186186
value=character(),
187187
stringsAsFactors=FALSE)
188+
abundances <- data.frame(
189+
sample=character(),
190+
ID=character(),
191+
query=character(),
192+
target=character(),
193+
observed_abund=numeric(),
194+
expected_abund=numeric(),
195+
stringsAsFactors=FALSE)
188196

189197
# for each sample
190198
for (sample in SAMPLES) {
@@ -238,10 +246,10 @@ for (sample in SAMPLES) {
238246
data$observed_abund <- data$observed_abund/sum(data$observed_abund,na.rm=TRUE)
239247
# Sort by expected abundance
240248
data <- data[order(data$expected_abund, decreasing = TRUE), ]
241-
# write table
242-
outfile <- paste0(sample,"_abundances.tsv")
243-
print(paste("write",outfile))
244-
write.table(data, file = outfile, row.names = FALSE, col.names = TRUE, quote = FALSE, na = '', sep="\t")
249+
# append sample data to table
250+
data$sample <- rep(sample, nrow(data))
251+
data <- data[, c("sample", "ID", "query", "target", "observed_abund", "expected_abund")]
252+
abundances <- rbind( abundances, data )
245253

246254
# (3) STATISTICS
247255

@@ -274,12 +282,13 @@ for (sample in SAMPLES) {
274282
invisible(dev.off())
275283

276284
# Scatter plot: Observed vs. Expected Abundance (log-log)
285+
data_matches <- data[data$observed_abund >0 & data$expected_abund >0,] # only on matched observed to expected
277286
outfile <- paste0(sample,"_scatter_loglog")
278287
print(paste("write",outfile))
279288
svg(paste0(outfile,".svg"), width = 8, height = 6)
280289
plot(
281-
log10(data$expected_abund),
282-
log10(data$observed_abund),
290+
log10(data_matches$expected_abund),
291+
log10(data_matches$observed_abund),
283292
xlab = "log10(Expected Abundance)",
284293
ylab = "log10(Observed Abundance)",
285294
main = "Scatter Plot: Observed vs. Expected Abundance (log-log)",
@@ -321,6 +330,12 @@ for (sample in SAMPLES) {
321330

322331
# (5) TABLES - metrics overall
323332

333+
# write table
334+
outfile <- "abundances_per-sample.tsv"
335+
abundances$tag <- rep(tag, nrow(abundances))
336+
print(paste("write",outfile))
337+
write.table(abundances, file = outfile, row.names = FALSE, col.names = TRUE, quote = FALSE, na = '', sep="\t")
338+
324339
# Write detailed output
325340
outfile <- "performance_per-sample.tsv"
326341
df$tag <- rep(tag, nrow(df))

conf/modules.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,12 @@ process {
12481248
[
12491249
path: { "${params.outdir}/comparison/${meta.id}" },
12501250
mode: params.publish_dir_mode,
1251-
pattern: "*{performance_summary.tsv,.log,performance_boxplot.svg,performance_boxplot.png,performance_per-sample.tsv}"
1251+
pattern: "*{performance_summary.tsv,.log,performance_boxplot.svg,performance_boxplot.png,performance_per-sample.tsv,abundances_per-sample.tsv}"
12521252
],
12531253
[
12541254
path: { "${params.outdir}/comparison/${meta.id}/per-sample" },
12551255
mode: params.publish_dir_mode,
1256-
pattern: "*{rank_abundance_curve.svg,_scatter_loglog.svg,_abundance_barplot.svg,_abundances.tsv}"
1256+
pattern: "*{rank_abundance_curve.svg,_scatter_loglog.svg,_abundance_barplot.svg}"
12571257
]
12581258
]
12591259
}

docs/output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,14 +721,14 @@ The following additional files will be produced:
721721
<summary>Output files</summary>
722722

723723
- `comparison/<parameter md5sum>_<pipeline version>`
724+
- `abundances_per-sample.tsv`: Tab-separated table with abundance of expected and observed sequences per sample, in long format.
724725
- `performance_summary.tsv`: Tab-separated table with aggregated performance metrics.
725726
- `performance_per-sample.tsv`: Tab-separated table with performance metrics per sample, in long format.
726727
- `performance.log`: Log file, complementary to `nucleotide-differences.log`.
727728
- `performance_boxplot.png`: Boxplot of number of aggregated performance metrics in png format.
728729
- `performance_boxplot.svg`: Boxplot of number of aggregated performance metrics in svg format.
729730
- `comparison/<parameter md5sum>_<pipeline version>/per-sample`
730731
- `<sample>_abundance_barplot.svg`: Side-by-Side bar plots in svg format.
731-
- `<sample>_abundances.tsv`: Tab-separated table with expected and observed abundances.
732732
- `<sample>_rank_abundance_curve.svg`: Rank Abundance Curves in svg format.
733733
- `<sample>_scatter_loglog.svg`: Scatter plot: Observed vs. Expected Abundance (log-log) in svg format.
734734

modules/local/compare_performance.nf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ process COMPARE_PERFORMANCE {
1717
path("*.png") , emit: png
1818
path("performance_summary.tsv") , emit: performance
1919
path("performance_per-sample.tsv") , emit: performance_per_sample
20-
path("*_abundances.tsv") , emit: abundance_table_per_sample
20+
path("abundances_per-sample.tsv") , emit: abundance_table_per_sample
2121
path("performance.log") , emit: log
2222
path("Warnings.txt") , emit: warnings
2323
path "versions.yml" , emit: versions, topic: versions

0 commit comments

Comments
 (0)