|
| 1 | +# fishpond_tximeta.R |
| 2 | +# Usage: Rscript fishpond_tximeta.R <coldata_tsv> <outdir> [bfc_path] |
| 3 | +# |
| 4 | +# coldata_tsv : TSV file with columns 'name' (sample label) and 'file' |
| 5 | +# (path to quant.sf produced by salmon with Gibbs samples) |
| 6 | +# outdir : output directory; receives transcripts.rds and genes.rds |
| 7 | +# bfc_path : (optional) BiocFileCache directory for tximeta reference |
| 8 | +# downloads; default: out/TximetaBFC |
| 9 | + |
| 10 | +suppressPackageStartupMessages({ |
| 11 | + library(tximeta) |
| 12 | + library(fishpond) |
| 13 | + library(org.Hs.eg.db) |
| 14 | + library(SummarizedExperiment) |
| 15 | + library(data.table) |
| 16 | +}) |
| 17 | + |
| 18 | +args <- commandArgs(trailingOnly = TRUE) |
| 19 | +if (length(args) < 2) { |
| 20 | + stop("Usage: Rscript fishpond_tximeta.R <coldata_tsv> <outdir> [bfc_path]") |
| 21 | +} |
| 22 | + |
| 23 | +coldata_tsv <- args[1] |
| 24 | +outdir <- args[2] |
| 25 | +bfc_path <- if (length(args) >= 3) args[3] else "out/TximetaBFC" |
| 26 | + |
| 27 | +dir.create(outdir, showWarnings = FALSE, recursive = TRUE) |
| 28 | +dir.create(bfc_path, showWarnings = FALSE, recursive = TRUE) |
| 29 | + |
| 30 | +setTximetaBFC(bfc_path) |
| 31 | + |
| 32 | +coldata <- as.data.frame(fread(coldata_tsv, sep = "\t")) |
| 33 | + |
| 34 | +if (!all(c("name", "file") %in% names(coldata))) { |
| 35 | + stop("coldata TSV must contain 'name' and 'file' columns") |
| 36 | +} |
| 37 | + |
| 38 | +# tximeta expects 'names' and 'files' columns |
| 39 | +coldata$names <- coldata$name |
| 40 | +coldata$files <- coldata$file |
| 41 | + |
| 42 | +missing <- !file.exists(coldata$files) |
| 43 | +if (any(missing)) { |
| 44 | + warning( |
| 45 | + sum(missing), " quant.sf file(s) not found and will be skipped:\n", |
| 46 | + paste(coldata$files[missing], collapse = "\n") |
| 47 | + ) |
| 48 | + coldata <- coldata[!missing, ] |
| 49 | +} |
| 50 | + |
| 51 | +# Transcript-level SummarizedExperiment (GRCh38 Ensembl; release detected |
| 52 | +# automatically from the salmon index metadata embedded in quant.sf) |
| 53 | +se <- tximeta(coldata) |
| 54 | + |
| 55 | +# Add gene-level SYMBOL annotations |
| 56 | +se <- addIds(se, "SYMBOL", gene = TRUE) |
| 57 | + |
| 58 | +# Scale inferential replicates (Gibbs samples) prior to downstream testing |
| 59 | +se <- scaleInfReps(se) |
| 60 | + |
| 61 | +saveRDS(se, file.path(outdir, "transcripts.rds")) |
| 62 | +message("Saved: ", file.path(outdir, "transcripts.rds")) |
| 63 | + |
| 64 | +# Gene-level summary |
| 65 | +gse <- summarizeToGene(se) |
| 66 | + |
| 67 | +saveRDS(gse, file.path(outdir, "genes.rds")) |
| 68 | +message("Saved: ", file.path(outdir, "genes.rds")) |
0 commit comments