Upload tasks/amplicon-microbiome/scripts/05_report.R with huggingface_hub
Browse files
tasks/amplicon-microbiome/scripts/05_report.R
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Compile final report from all pipeline outputs
|
| 2 |
+
|
| 3 |
+
# Read DADA2 summary
|
| 4 |
+
dada2_summary <- readLines("outputs/dada2/summary.txt")
|
| 5 |
+
parse_val <- function(lines, key) {
|
| 6 |
+
line <- grep(paste0("^", key, ":"), lines, value=TRUE)
|
| 7 |
+
trimws(sub(paste0("^", key, ": *"), "", line))
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
total_input <- parse_val(dada2_summary, "total_input_reads")
|
| 11 |
+
total_filtered <- parse_val(dada2_summary, "total_filtered_reads")
|
| 12 |
+
total_asvs <- parse_val(dada2_summary, "total_asvs")
|
| 13 |
+
total_chimeras <- parse_val(dada2_summary, "total_chimeras")
|
| 14 |
+
|
| 15 |
+
# Taxonomy
|
| 16 |
+
tax <- read.table("outputs/taxonomy/taxonomy.tsv", header=TRUE, sep="\t", fill=TRUE)
|
| 17 |
+
classified <- sum(!is.na(tax$Phylum))
|
| 18 |
+
phylum_tab <- table(tax$Phylum, useNA="no")
|
| 19 |
+
top_phylum <- names(sort(phylum_tab, decreasing=TRUE))[1]
|
| 20 |
+
top_phylum_pct <- round(100 * max(phylum_tab) / sum(phylum_tab), 1)
|
| 21 |
+
|
| 22 |
+
# Diversity
|
| 23 |
+
div <- read.table("outputs/diversity/diversity_metrics.tsv", header=TRUE, sep="\t")
|
| 24 |
+
mean_shannon <- div$value[div$metric == "mean_shannon"]
|
| 25 |
+
mean_simpson <- div$value[div$metric == "mean_simpson"]
|
| 26 |
+
mean_observed <- div$value[div$metric == "mean_observed_richness"]
|
| 27 |
+
mean_pd <- div$value[div$metric == "mean_faith_pd"]
|
| 28 |
+
|
| 29 |
+
# DA results
|
| 30 |
+
da <- read.table("outputs/diversity/da_results.tsv", header=TRUE, sep="\t")
|
| 31 |
+
da_features <- sum(da$padj < 0.05, na.rm=TRUE)
|
| 32 |
+
|
| 33 |
+
# PICRUSt2 pathways
|
| 34 |
+
pw_count <- 0
|
| 35 |
+
pw_files <- c(
|
| 36 |
+
"outputs/picrust2/out/pathways_out/path_abun_unstrat.tsv.gz",
|
| 37 |
+
"outputs/picrust2/out/pathways_out/path_abun_unstrat.tsv"
|
| 38 |
+
)
|
| 39 |
+
for (pf in pw_files) {
|
| 40 |
+
if (file.exists(pf)) {
|
| 41 |
+
if (grepl("\\.gz$", pf)) {
|
| 42 |
+
pw <- read.table(gzfile(pf), header=TRUE, sep="\t", check.names=FALSE)
|
| 43 |
+
} else {
|
| 44 |
+
pw <- read.table(pf, header=TRUE, sep="\t", check.names=FALSE)
|
| 45 |
+
}
|
| 46 |
+
pw_count <- nrow(pw)
|
| 47 |
+
break
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Write report
|
| 52 |
+
report <- data.frame(
|
| 53 |
+
metric = c("total_samples", "total_input_reads", "total_filtered_reads",
|
| 54 |
+
"total_sequence_variants", "chimeras_removed",
|
| 55 |
+
"classified_variants", "top_phylum", "top_phylum_pct",
|
| 56 |
+
"mean_shannon", "mean_simpson", "mean_observed_richness",
|
| 57 |
+
"mean_phylogenetic_diversity", "predicted_pathways",
|
| 58 |
+
"differentially_abundant_features"),
|
| 59 |
+
value = c(4, total_input, total_filtered, total_asvs, total_chimeras,
|
| 60 |
+
classified, top_phylum, top_phylum_pct,
|
| 61 |
+
mean_shannon, mean_simpson, mean_observed, mean_pd,
|
| 62 |
+
pw_count, da_features)
|
| 63 |
+
)
|
| 64 |
+
write.csv(report, "results/report.csv", row.names=FALSE, quote=FALSE)
|
| 65 |
+
cat("=== Final Report ===\n")
|
| 66 |
+
for (i in seq_len(nrow(report))) {
|
| 67 |
+
cat(sprintf(" %s = %s\n", report$metric[i], report$value[i]))
|
| 68 |
+
}
|