Skip to content

Commit d12dcc2

Browse files
Clare72claude
andcommitted
Saavedra 2023 stage 4: expression
CPM summary expression of the 14 loaded clusters from the two control libraries' GEO matrices (combine_matrices.py); the metadata's per-library barcode suffix mapped to GEO's, so all control nuclei are assigned; FBgn ids mapped to current FlyBase genes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 10651e0 commit d12dcc2

10 files changed

Lines changed: 16775 additions & 3 deletions

File tree

‎docs/DESIGN.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,4 +1858,14 @@ or FoxO, two technical replicates each. Replaces the old FlyBase/SCEA load FBlc0
18581858
ventral nervous system to *adult VNC neuron*, peripheral nervous system to *adult PNS
18591859
neuron*, salivary gland to *adult salivary gland epithelial cell*. 14 clusters mapped (12
18601860
terms), 3 held ("Unknown cluster").
1861+
- **Expression (stage 4).** From the GEO matrices of the two control libraries (Cell Ranger 7
1862+
filtered, raw UMI counts, FBgn ids), side by side (`combine_matrices.py`; nuclei
1863+
`<library>_<barcode>`), as CPM. The authors' metadata gives each library's barcodes an
1864+
aggregation suffix (wt1 `-1`, wt2 `-2`, ...); `build_clusters.py` maps them to GEO's
1865+
per-library `-1`, so all 14,170 control nuclei are assigned. Genes: 16,412 current, 80
1866+
secondary (3 merges); 1 split and 2 withdrawn dropped. 16,489 genes; 14 clusters, 3,163
1867+
rows (extent > 0.2; ~230 genes per cluster: single nuclei with ~400 UMIs); the 3 held
1868+
clusters (540 nuclei) left out. The most cluster-specific genes fit the author types
1869+
(muscle *sls*, *bt*, *Zasp52/66*; neurons *para*, *Snap25*; hemocytes *Hml*, *Ppn*;
1870+
adipose *apolpp*; salivary gland *CAH1*).
18611871

88.7 KB
Binary file not shown.

‎id_registry/registry.json‎

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"counter": 3202,
2+
"counter": 3216,
33
"entries": {
44
"Assay::E-MTAB-10519:FCA10_Male_head_adult_5dWT_Luo_sample4_S1": {
55
"accession": null,
@@ -18397,6 +18397,104 @@
1839718397
"label": "head_transmedullary neuron Tm9",
1839818398
"natural_key": "GSE218661:main:head_transmedullary neuron Tm9"
1839918399
},
18400+
"Cluster::GSE227038:main:0_Indirect flight muscle": {
18401+
"accession": null,
18402+
"entity_type": "Cluster",
18403+
"id": "VFBseq_00003203",
18404+
"label": "0_Indirect flight muscle",
18405+
"natural_key": "GSE227038:main:0_Indirect flight muscle"
18406+
},
18407+
"Cluster::GSE227038:main:10_Peripheral nervous system": {
18408+
"accession": null,
18409+
"entity_type": "Cluster",
18410+
"id": "VFBseq_00003212",
18411+
"label": "10_Peripheral nervous system",
18412+
"natural_key": "GSE227038:main:10_Peripheral nervous system"
18413+
},
18414+
"Cluster::GSE227038:main:12_Cell body glial cell": {
18415+
"accession": null,
18416+
"entity_type": "Cluster",
18417+
"id": "VFBseq_00003213",
18418+
"label": "12_Cell body glial cell",
18419+
"natural_key": "GSE227038:main:12_Cell body glial cell"
18420+
},
18421+
"Cluster::GSE227038:main:13_Perineurial glial sheath": {
18422+
"accession": null,
18423+
"entity_type": "Cluster",
18424+
"id": "VFBseq_00003214",
18425+
"label": "13_Perineurial glial sheath",
18426+
"natural_key": "GSE227038:main:13_Perineurial glial sheath"
18427+
},
18428+
"Cluster::GSE227038:main:14_Adult alary muscle": {
18429+
"accession": null,
18430+
"entity_type": "Cluster",
18431+
"id": "VFBseq_00003215",
18432+
"label": "14_Adult alary muscle",
18433+
"natural_key": "GSE227038:main:14_Adult alary muscle"
18434+
},
18435+
"Cluster::GSE227038:main:15_Adult salivary gland": {
18436+
"accession": null,
18437+
"entity_type": "Cluster",
18438+
"id": "VFBseq_00003216",
18439+
"label": "15_Adult salivary gland",
18440+
"natural_key": "GSE227038:main:15_Adult salivary gland"
18441+
},
18442+
"Cluster::GSE227038:main:1_Muscle cell": {
18443+
"accession": null,
18444+
"entity_type": "Cluster",
18445+
"id": "VFBseq_00003204",
18446+
"label": "1_Muscle cell",
18447+
"natural_key": "GSE227038:main:1_Muscle cell"
18448+
},
18449+
"Cluster::GSE227038:main:2_Ventral nervous system": {
18450+
"accession": null,
18451+
"entity_type": "Cluster",
18452+
"id": "VFBseq_00003205",
18453+
"label": "2_Ventral nervous system",
18454+
"natural_key": "GSE227038:main:2_Ventral nervous system"
18455+
},
18456+
"Cluster::GSE227038:main:3_Epithelial cell": {
18457+
"accession": null,
18458+
"entity_type": "Cluster",
18459+
"id": "VFBseq_00003206",
18460+
"label": "3_Epithelial cell",
18461+
"natural_key": "GSE227038:main:3_Epithelial cell"
18462+
},
18463+
"Cluster::GSE227038:main:4_Adipose tissue": {
18464+
"accession": null,
18465+
"entity_type": "Cluster",
18466+
"id": "VFBseq_00003207",
18467+
"label": "4_Adipose tissue",
18468+
"natural_key": "GSE227038:main:4_Adipose tissue"
18469+
},
18470+
"Cluster::GSE227038:main:5_Muscle cell": {
18471+
"accession": null,
18472+
"entity_type": "Cluster",
18473+
"id": "VFBseq_00003208",
18474+
"label": "5_Muscle cell",
18475+
"natural_key": "GSE227038:main:5_Muscle cell"
18476+
},
18477+
"Cluster::GSE227038:main:6_Tracheal": {
18478+
"accession": null,
18479+
"entity_type": "Cluster",
18480+
"id": "VFBseq_00003209",
18481+
"label": "6_Tracheal",
18482+
"natural_key": "GSE227038:main:6_Tracheal"
18483+
},
18484+
"Cluster::GSE227038:main:7_Epithelial cell": {
18485+
"accession": null,
18486+
"entity_type": "Cluster",
18487+
"id": "VFBseq_00003210",
18488+
"label": "7_Epithelial cell",
18489+
"natural_key": "GSE227038:main:7_Epithelial cell"
18490+
},
18491+
"Cluster::GSE227038:main:8_Hemocyte": {
18492+
"accession": null,
18493+
"entity_type": "Cluster",
18494+
"id": "VFBseq_00003211",
18495+
"label": "8_Hemocyte",
18496+
"natural_key": "GSE227038:main:8_Hemocyte"
18497+
},
1840018498
"Clustering::E-MTAB-10519:antenna": {
1840118499
"accession": null,
1840218500
"entity_type": "Clustering",

‎projects/saavedra_2023/build_clusters.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
all_genotypes_cell_number the cluster's nuclei in all six libraries
1616
1717
Also writes .cache/saavedra/memberships.tsv.gz (nucleus<TAB>cluster; nuclei named
18-
<library>_<barcode>) for the expression build.
18+
<library>_<barcode>-1, the metadata's aggregation suffix replaced by the per-library one,
19+
as in GEO's per-library barcodes) for the expression build.
1920
2021
Usage:
2122
uv run python projects/saavedra_2023/build_clusters.py
@@ -56,7 +57,9 @@ def main() -> None:
5657
n += 1
5758
total[r["Cluster"]] += 1
5859
if r["Sample"] in CONTROLS:
59-
cells[r["Cluster"]].append(f"{r['Sample']}_{r['Barcode']}")
60+
# the metadata's barcodes carry an aggregation suffix per library (wt1 -1, wt2 -2,
61+
# ...); GEO's per-library barcodes all end -1
62+
cells[r["Cluster"]].append(f"{r['Sample']}_{r['Barcode'].rsplit('-', 1)[0]}-1")
6063
if n != PAPER_NUCLEI or len(total) != 17 or set(cells) != set(total):
6164
raise SystemExit(f"expected the authors' 17 clusters / {PAPER_NUCLEI} nuclei: {len(total)} / {n}")
6265
anns = []
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
"""Saavedra 2023: one count matrix from the two control libraries (GEO).
3+
4+
GEO (GSE227038) has a Cell Ranger 7 filtered matrix per library (MatrixMarket, named
5+
.matrix.tsv.gz); each author cluster spans both control libraries (wt1, wt2), so the
6+
expression build reads one matrix with them side by side. Nuclei are named
7+
<library>_<barcode> (e.g. wt1_AAACCCAAGAGTCAGC-1), as in build_clusters.py's memberships.
8+
The libraries share one feature list (checked).
9+
10+
Reads .cache/saavedra/geo/<library>/{barcodes,features,matrix}.tsv.gz; writes
11+
.cache/saavedra/combined/{matrix.mtx.gz, features.tsv.gz, barcodes.tsv.gz}.
12+
13+
Usage:
14+
uv run python projects/saavedra_2023/combine_matrices.py
15+
"""
16+
17+
from __future__ import annotations
18+
19+
import gzip
20+
from pathlib import Path
21+
22+
CACHE = Path(__file__).resolve().parents[2] / ".cache" / "saavedra"
23+
LIBS = ("wt1", "wt2")
24+
25+
26+
def main() -> None:
27+
feats = {gzip.decompress((CACHE / "geo" / lib / "features.tsv.gz").read_bytes()) for lib in LIBS}
28+
assert len(feats) == 1, "libraries differ in their features"
29+
heads, bodies = {}, {}
30+
for lib in LIBS:
31+
with gzip.open(CACHE / "geo" / lib / "matrix.tsv.gz", "rt") as fh:
32+
banner = fh.readline()
33+
line = fh.readline()
34+
while line.startswith("%"):
35+
line = fh.readline()
36+
heads[lib] = (banner, *map(int, line.split()))
37+
n_genes = {h[1] for h in heads.values()}
38+
assert len(n_genes) == 1
39+
out = CACHE / "combined"
40+
out.mkdir(parents=True, exist_ok=True)
41+
(out / "features.tsv.gz").write_bytes(gzip.compress(feats.pop()))
42+
n_cells = sum(h[2] for h in heads.values())
43+
n_entries = sum(h[3] for h in heads.values())
44+
offset = 0
45+
with gzip.open(out / "matrix.mtx.gz", "wt") as mo, gzip.open(out / "barcodes.tsv.gz", "wt") as bo:
46+
mo.write(heads[LIBS[0]][0])
47+
mo.write(f"{n_genes.pop()} {n_cells} {n_entries}\n")
48+
for lib in LIBS:
49+
with gzip.open(CACHE / "geo" / lib / "barcodes.tsv.gz", "rt") as fh:
50+
bo.writelines(f"{lib}_{b.strip()}\n" for b in fh)
51+
with gzip.open(CACHE / "geo" / lib / "matrix.tsv.gz", "rt") as fh:
52+
line = fh.readline()
53+
while line.startswith("%"):
54+
line = fh.readline() # the size line follows the comments
55+
for line in fh:
56+
g, c, v = line.split()
57+
mo.write(f"{g} {int(c) + offset} {v}\n")
58+
offset += heads[lib][2]
59+
print(f"wrote {len(LIBS)} libraries: {n_cells} nuclei, {n_entries} entries -> {out}")
60+
61+
62+
if __name__ == "__main__":
63+
main()

‎projects/saavedra_2023/config.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ unidentified:
6060

6161
# FBbt mappings are made once per author type (type_mapping/, write_type_mappings.py) and
6262
# copied per cluster by scripts/expand_type_mappings.py.
63+
64+
# Summary expression (scripts/build_expression.py) from the GEO matrices of the two control
65+
# libraries (Cell Ranger 7 filtered, raw UMI counts, FBgn ids), side by side
66+
# (combine_matrices.py; nuclei <library>_<barcode>, as in build_clusters.py's memberships).
67+
expression:
68+
matrix_file: saavedra/combined/matrix.mtx.gz
69+
features_file: saavedra/combined/features.tsv.gz
70+
barcodes_file: saavedra/combined/barcodes.tsv.gz
71+
membership_file: saavedra/memberships.tsv.gz
72+
normalisation: CPM
73+
extent_cutoff: 0.2
74+
hide_in_terminfo: "true"
75+
gzip_tsv: true
76+
gene_id_map: gene_id_map.tsv
44.8 KB
Binary file not shown.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"dataset": {
3+
"total_gene_count": 12031,
4+
"filtered_gene_count": 1402
5+
},
6+
"clusters": {
7+
"0_Indirect flight muscle": {
8+
"total_gene_count": 10134,
9+
"filtered_gene_count": 207
10+
},
11+
"10_Peripheral nervous system": {
12+
"total_gene_count": 6383,
13+
"filtered_gene_count": 162
14+
},
15+
"12_Cell body glial cell": {
16+
"total_gene_count": 4635,
17+
"filtered_gene_count": 175
18+
},
19+
"13_Perineurial glial sheath": {
20+
"total_gene_count": 6702,
21+
"filtered_gene_count": 305
22+
},
23+
"14_Adult alary muscle": {
24+
"total_gene_count": 6809,
25+
"filtered_gene_count": 244
26+
},
27+
"15_Adult salivary gland": {
28+
"total_gene_count": 5187,
29+
"filtered_gene_count": 518
30+
},
31+
"1_Muscle cell": {
32+
"total_gene_count": 8288,
33+
"filtered_gene_count": 176
34+
},
35+
"2_Ventral nervous system": {
36+
"total_gene_count": 8076,
37+
"filtered_gene_count": 201
38+
},
39+
"3_Epithelial cell": {
40+
"total_gene_count": 6371,
41+
"filtered_gene_count": 108
42+
},
43+
"4_Adipose tissue": {
44+
"total_gene_count": 8323,
45+
"filtered_gene_count": 442
46+
},
47+
"5_Muscle cell": {
48+
"total_gene_count": 5973,
49+
"filtered_gene_count": 148
50+
},
51+
"6_Tracheal": {
52+
"total_gene_count": 5351,
53+
"filtered_gene_count": 157
54+
},
55+
"7_Epithelial cell": {
56+
"total_gene_count": 5127,
57+
"filtered_gene_count": 121
58+
},
59+
"8_Hemocyte": {
60+
"total_gene_count": 6093,
61+
"filtered_gene_count": 199
62+
}
63+
}
64+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Expression summary — GSE227038
2+
3+
- normalisation: **CPM**; extent filter: **> 0.2**
4+
- 16489 genes x 14170 cells; 14 clusters; 3,163 filtered rows
5+
- not loaded: 3 held clusters (no FBbt term), 540 cells
6+
- dataset-level: total_gene_count **12031**, filtered_gene_count **1402**
7+
8+
| cluster | cells | total_gene_count | filtered_gene_count |
9+
|---|---|---|---|
10+
| 0_Indirect flight muscle | 6611 | 10134 | 207 |
11+
| 10_Peripheral nervous system | 364 | 6383 | 162 |
12+
| 12_Cell body glial cell | 212 | 4635 | 175 |
13+
| 13_Perineurial glial sheath | 192 | 6702 | 305 |
14+
| 14_Adult alary muscle | 211 | 6809 | 244 |
15+
| 15_Adult salivary gland | 95 | 5187 | 518 |
16+
| 1_Muscle cell | 1930 | 8288 | 176 |
17+
| 2_Ventral nervous system | 1225 | 8076 | 201 |
18+
| 3_Epithelial cell | 530 | 6371 | 108 |
19+
| 4_Adipose tissue | 733 | 8323 | 442 |
20+
| 5_Muscle cell | 495 | 5973 | 148 |
21+
| 6_Tracheal | 327 | 5351 | 157 |
22+
| 7_Epithelial cell | 298 | 5127 | 121 |
23+
| 8_Hemocyte | 407 | 6093 | 199 |

0 commit comments

Comments
 (0)