Skip to content

Commit 63fffc0

Browse files
Add draft fihspond rule
1 parent 5ae22e9 commit 63fffc0

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

src/r/scripts/fishpond_tximeta.R

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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"))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Aim:
3+
Rules to import salmon quant.sf files with tximeta (human GRCh38 / Ensembl)
4+
and run fishpond preprocessing, producing:
5+
- transcript-level SummarizedExperiment (transcripts.rds)
6+
- gene-level SummarizedExperiment (genes.rds)
7+
8+
Usage:
9+
Register a coldata TSV in mwconf['ids'] under a chosen <coldata_id> key.
10+
The TSV must have two tab-separated columns:
11+
name sample label (used as column name in the SE)
12+
file path to the corresponding salmon quant.sf
13+
14+
Then request:
15+
out/fishpond/tximeta_GRCh38_ensembl/<coldata_id>/transcripts.rds
16+
out/fishpond/tximeta_GRCh38_ensembl/<coldata_id>/genes.rds
17+
"""
18+
19+
20+
def _fishpond_tximeta_quant_files(wildcards):
21+
"""Return the list of quant.sf paths declared in the coldata TSV."""
22+
coldata_path = mwconf['ids'][wildcards.coldata_id]
23+
with open(coldata_path) as fh:
24+
reader = csv.DictReader(fh, delimiter='\t')
25+
return [row['file'] for row in reader]
26+
27+
28+
rule fishpond_tximeta_GRCh38_ensembl:
29+
"""
30+
Created:
31+
2026-02-22
32+
Aim:
33+
Import salmon quant.sf files (human GRCh38, Ensembl release detected
34+
automatically from salmon index metadata) with tximeta, add SYMBOL IDs,
35+
scale inferential replicates, and summarise to gene level.
36+
Input coldata_id:
37+
Key in mwconf['ids'] that points to a TSV with 'name' and 'file' columns.
38+
Test:
39+
out/fishpond/tximeta_GRCh38_ensembl/my_coldata_id/transcripts.rds
40+
out/fishpond/tximeta_GRCh38_ensembl/my_coldata_id/genes.rds
41+
"""
42+
input:
43+
coldata = lambda wildcards: mwconf['ids'][wildcards.coldata_id],
44+
quant_sf = _fishpond_tximeta_quant_files,
45+
script = "src/r/scripts/fishpond_tximeta.R"
46+
output:
47+
transcripts = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/transcripts.rds",
48+
genes = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/genes.rds"
49+
params:
50+
outdir = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}",
51+
bfc_path = "out/TximetaBFC"
52+
wildcard_constraints:
53+
coldata_id = r"[-a-zA-Z0-9_]+"
54+
conda:
55+
"../envs/r_fishpond.yaml"
56+
shell:
57+
"Rscript {input.script} {input.coldata} {params.outdir} {params.bfc_path}"

0 commit comments

Comments
 (0)