Skip to content

Commit c3ea65d

Browse files
Merge branch 'master' of github.com:guillaumecharbonnier/mw-lib
2 parents a0504f5 + 572cf21 commit c3ea65d

3 files changed

Lines changed: 61 additions & 27 deletions

File tree

src/r/scripts/fishpond_tximeta.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,22 @@ gse <- summarizeToGene(se)
6666

6767
saveRDS(gse, file.path(outdir, "genes.rds"))
6868
message("Saved: ", file.path(outdir, "genes.rds"))
69+
70+
# Export count matrices as CSV.gz (row metadata + counts, one row per feature)
71+
se_rd <- tryCatch({
72+
rd <- as.data.frame(rowData(se))
73+
rd[, sapply(rd, is.atomic), drop = FALSE]
74+
}, error = function(e) data.frame(row.names = rownames(se)))
75+
76+
se_counts <- cbind(se_rd, as.data.frame(assay(se, "counts")))
77+
fwrite(se_counts, file.path(outdir, "transcripts_counts.csv.gz"))
78+
message("Saved: ", file.path(outdir, "transcripts_counts.csv.gz"))
79+
80+
gse_rd <- tryCatch({
81+
rd <- as.data.frame(rowData(gse))
82+
rd[, sapply(rd, is.atomic), drop = FALSE]
83+
}, error = function(e) data.frame(row.names = rownames(gse)))
84+
85+
gse_counts <- cbind(gse_rd, as.data.frame(assay(gse, "counts")))
86+
fwrite(gse_counts, file.path(outdir, "genes_counts.csv.gz"))
87+
message("Saved: ", file.path(outdir, "genes_counts.csv.gz"))

src/snakemake/envs/r_fishpond.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
name:
22
r_fishpond
33
channels:
4-
- bioconda
54
- conda-forge
5+
- bioconda
66
- nodefaults
77
dependencies:
8-
- bioconductor-tximeta
9-
- bioconductor-fishpond
8+
- bioconductor-fishpond =2.8.0
9+
- bioconductor-tximeta =1.20.1
1010
- bioconductor-org.hs.eg.db
11-
- bioconductor-org.mm.eg.db
1211
- bioconductor-summarizedexperiment
13-
- r-openxlsx
1412
- r-data.table
15-
- r-readr
16-
- r-biocmanager
1713

src/snakemake/rules/fishpond_tximeta.smk

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,37 @@ Aim:
66
- gene-level SummarizedExperiment (genes.rds)
77
88
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
9+
mapper.py populates mwconf['ids'][coldata_id] with a list of
10+
"sample_name\\tquant_sf_path" strings for each RNA exp group (GRCh38).
11+
The rules below write the coldata TSV and run the R script.
1312
14-
Then request:
13+
Alternatively, register a list of "name\\tfile" strings manually in
14+
mwconf['ids'] under a chosen <coldata_id> key and request:
1515
out/fishpond/tximeta_GRCh38_ensembl/<coldata_id>/transcripts.rds
1616
out/fishpond/tximeta_GRCh38_ensembl/<coldata_id>/genes.rds
1717
"""
1818

1919

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]
20+
rule fishpond_coldata_from_ids:
21+
"""
22+
Created:
23+
2026-02-22
24+
Aim:
25+
Write a coldata TSV (columns: name, file) from the list of
26+
"name\\tfile" strings stored in mwconf['ids'][coldata_id].
27+
Populated automatically by mapper.py for each RNA exp group.
28+
"""
29+
output:
30+
"out/fishpond/coldata/{coldata_id}.tsv"
31+
wildcard_constraints:
32+
coldata_id = r"[-a-zA-Z0-9_]+"
33+
run:
34+
import os
35+
os.makedirs(os.path.dirname(output[0]), exist_ok=True)
36+
with open(output[0], 'w') as fh:
37+
fh.write("name\tfile\n")
38+
for entry in mwconf['ids'][wildcards.coldata_id]:
39+
fh.write(entry + "\n")
2640

2741

2842
rule fishpond_tximeta_GRCh38_ensembl:
@@ -33,19 +47,24 @@ rule fishpond_tximeta_GRCh38_ensembl:
3347
Import salmon quant.sf files (human GRCh38, Ensembl release detected
3448
automatically from salmon index metadata) with tximeta, add SYMBOL IDs,
3549
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.
50+
coldata_id:
51+
Key in mwconf['ids'] whose value is a list of "name\\tfile" strings.
52+
Populated automatically by mapper.py for RNA exp groups.
3853
Test:
39-
out/fishpond/tximeta_GRCh38_ensembl/my_coldata_id/transcripts.rds
40-
out/fishpond/tximeta_GRCh38_ensembl/my_coldata_id/genes.rds
54+
out/fishpond/tximeta_GRCh38_ensembl/coldata-GRCh38-myexp/transcripts.rds
55+
out/fishpond/tximeta_GRCh38_ensembl/coldata-GRCh38-myexp/genes.rds
56+
out/fishpond/tximeta_GRCh38_ensembl/coldata-GRCh38-myexp/transcripts_counts.csv.gz
57+
out/fishpond/tximeta_GRCh38_ensembl/coldata-GRCh38-myexp/genes_counts.csv.gz
4158
"""
4259
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"
60+
coldata = "out/fishpond/coldata/{coldata_id}.tsv",
61+
quant_sf = lambda wildcards: [e.split('\t')[1] for e in mwconf['ids'][wildcards.coldata_id]],
62+
script = "../mw-lib/src/r/scripts/fishpond_tximeta.R"
4663
output:
47-
transcripts = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/transcripts.rds",
48-
genes = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/genes.rds"
64+
transcripts = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/transcripts.rds",
65+
genes = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/genes.rds",
66+
transcripts_counts = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/transcripts_counts.csv.gz",
67+
genes_counts = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}/genes_counts.csv.gz"
4968
params:
5069
outdir = "out/fishpond/tximeta_GRCh38_ensembl/{coldata_id}",
5170
bfc_path = "out/TximetaBFC"

0 commit comments

Comments
 (0)