Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1843,4 +1843,9 @@ or FoxO, two technical replicates each. Replaces the old FlyBase/SCEA load FBlc0
age; methods: about 1-2 weeks, 4-5 d at 18 C then 4 d at 29 C); *adult thorax*; male. The
control is a cross: `genotype_includes` Scer\GAL4[Mef2.PU] (FBal0288220, FlyBase's for
the paper) and Scer\GAL80[ts.alphaTub84B] (FBal0147425, unambiguous). One Clustering.
- **Clusters (stage 2):** `projects/saavedra_2023/build_clusters.py`: the authors' 17 clusters
from their GEO metadata (all 45,335 nuclei checked), restricted to the control libraries
(14,170 nuclei; every cluster has control nuclei); labelled as the authors give them
("0_Indirect flight muscle"), typed by the name. Held (`untyped`): the three "Unknown
cluster"s.

93 changes: 93 additions & 0 deletions projects/saavedra_2023/build_clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python
"""Saavedra et al. 2023: cell_type_annotations.json from the authors' clusters (controls).

The authors clustered all six libraries together (Seurat 4.3, Harmony, resolution 0.3: 17
clusters, annotated against the Fly Cell Atlas). Their per-nucleus clusters are on GEO
(GSE227038_2023-02-21_metadata_Pedro_thorax_10K_final.csv: barcode, "<n>_<name>", library),
for all 45,335 nuclei the paper reports. Curator 2026-10-20: control nuclei only (libraries
wt1 and wt2, one Sample).

label the authors' cluster as given (e.g. "0_Indirect flight muscle")
type the name (e.g. "Indirect flight muscle")
source_cluster_id the cluster number
unannotated "Unknown cluster" (held: untyped)
cells_by_library control nuclei per library (wt1, wt2)
all_genotypes_cell_number the cluster's nuclei in all six libraries

Also writes .cache/saavedra/memberships.tsv.gz (nucleus<TAB>cluster; nuclei named
<library>_<barcode>) for the expression build.

Usage:
uv run python projects/saavedra_2023/build_clusters.py
"""

from __future__ import annotations

import csv
import gzip
import json
import urllib.request
from collections import Counter, defaultdict
from pathlib import Path

import yaml

PROJ = Path(__file__).resolve().parent
CACHE = PROJ.parents[1] / ".cache" / "saavedra"
META = CACHE / "GSE227038_2023-02-21_metadata_Pedro_thorax_10K_final.csv.gz"
META_URL = ("https://ftp.ncbi.nlm.nih.gov/geo/series/GSE227nnn/GSE227038/suppl/"
"GSE227038_2023-02-21_metadata_Pedro_thorax_10K_final.csv.gz")
CONTROLS = ("wt1", "wt2")
PAPER_NUCLEI = 45335
HELD = "Unknown cluster"


def main() -> None:
cfg = yaml.safe_load((PROJ / "config.yaml").read_text())
(clustering,) = cfg["sample_build"]["clusterings"]
if not META.exists():
CACHE.mkdir(parents=True, exist_ok=True)
urllib.request.urlretrieve(META_URL, META)
cells: dict[str, list[str]] = defaultdict(list)
total: Counter = Counter()
n = 0
with gzip.open(META, "rt", newline="") as fh:
for r in csv.DictReader(fh):
n += 1
total[r["Cluster"]] += 1
if r["Sample"] in CONTROLS:
cells[r["Cluster"]].append(f"{r['Sample']}_{r['Barcode']}")
if n != PAPER_NUCLEI or len(total) != 17 or set(cells) != set(total):
raise SystemExit(f"expected the authors' 17 clusters / {PAPER_NUCLEI} nuclei: {len(total)} / {n}")
anns = []
for lab in sorted(cells, key=lambda x: int(x.split("_", 1)[0])):
num, name = lab.split("_", 1)
rec = {"label": lab, "type": name, "clustering": clustering["id"], "clustering_name": clustering["name"],
"source_cluster_id": num, "cell_number": len(cells[lab]),
"cells_by_library": dict(sorted(Counter(c.split("_", 1)[0] for c in cells[lab]).items())),
"all_genotypes_cell_number": total[lab]}
if name == HELD:
rec["unannotated"] = True
anns.append(rec)
with gzip.open(CACHE / "memberships.tsv.gz", "wt") as fh:
fh.write("barcode\tcluster\n")
for a in anns:
fh.writelines(f"{c}\t{a['label']}\n" for c in cells[a["label"]])
out = {
"source": {"doi": cfg["source"]["doi"], "title": cfg["source"]["title"]},
"dataset": {
"accession": cfg["dataset"]["accession"],
"label_source": "the authors' per-nucleus clusters in their GEO metadata file "
"(GSE227038_2023-02-21_metadata_Pedro_thorax_10K_final.csv), control libraries only",
"label_level": "author cluster (restricted to the control nuclei)",
"validate_against": "paper, Figure 3a",
},
"annotations": anns,
}
(PROJ / "cell_type_annotations.json").write_text(json.dumps(out, indent=2, ensure_ascii=False) + "\n")
print(f"wrote {len(anns)} clusters, {sum(a['cell_number'] for a in anns)} control nuclei of {n}; "
f"held {[a['label'] for a in anns if a.get('unannotated')]}")


if __name__ == "__main__":
main()
238 changes: 238 additions & 0 deletions projects/saavedra_2023/cell_type_annotations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
{
"source": {
"doi": "10.1038/s41467-023-40595-1",
"title": "REPTOR and CREBRF encode key regulators of muscle energy metabolism"
},
"dataset": {
"accession": "GSE227038",
"label_source": "the authors' per-nucleus clusters in their GEO metadata file (GSE227038_2023-02-21_metadata_Pedro_thorax_10K_final.csv), control libraries only",
"label_level": "author cluster (restricted to the control nuclei)",
"validate_against": "paper, Figure 3a"
},
"annotations": [
{
"label": "0_Indirect flight muscle",
"type": "Indirect flight muscle",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "0",
"cell_number": 6611,
"cells_by_library": {
"wt1": 3217,
"wt2": 3394
},
"all_genotypes_cell_number": 14616
},
{
"label": "1_Muscle cell",
"type": "Muscle cell",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "1",
"cell_number": 1930,
"cells_by_library": {
"wt1": 957,
"wt2": 973
},
"all_genotypes_cell_number": 8173
},
{
"label": "2_Ventral nervous system",
"type": "Ventral nervous system",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "2",
"cell_number": 1225,
"cells_by_library": {
"wt1": 578,
"wt2": 647
},
"all_genotypes_cell_number": 3905
},
{
"label": "3_Epithelial cell",
"type": "Epithelial cell",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "3",
"cell_number": 530,
"cells_by_library": {
"wt1": 279,
"wt2": 251
},
"all_genotypes_cell_number": 3872
},
{
"label": "4_Adipose tissue",
"type": "Adipose tissue",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "4",
"cell_number": 733,
"cells_by_library": {
"wt1": 329,
"wt2": 404
},
"all_genotypes_cell_number": 2214
},
{
"label": "5_Muscle cell",
"type": "Muscle cell",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "5",
"cell_number": 495,
"cells_by_library": {
"wt1": 232,
"wt2": 263
},
"all_genotypes_cell_number": 1742
},
{
"label": "6_Tracheal",
"type": "Tracheal",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "6",
"cell_number": 327,
"cells_by_library": {
"wt1": 157,
"wt2": 170
},
"all_genotypes_cell_number": 1489
},
{
"label": "7_Epithelial cell",
"type": "Epithelial cell",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "7",
"cell_number": 298,
"cells_by_library": {
"wt1": 148,
"wt2": 150
},
"all_genotypes_cell_number": 1457
},
{
"label": "8_Hemocyte",
"type": "Hemocyte",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "8",
"cell_number": 407,
"cells_by_library": {
"wt1": 206,
"wt2": 201
},
"all_genotypes_cell_number": 1426
},
{
"label": "9_Unknown cluster",
"type": "Unknown cluster",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "9",
"cell_number": 312,
"cells_by_library": {
"wt1": 155,
"wt2": 157
},
"all_genotypes_cell_number": 1407,
"unannotated": true
},
{
"label": "10_Peripheral nervous system",
"type": "Peripheral nervous system",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "10",
"cell_number": 364,
"cells_by_library": {
"wt1": 165,
"wt2": 199
},
"all_genotypes_cell_number": 1364
},
{
"label": "11_Unknown cluster",
"type": "Unknown cluster",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "11",
"cell_number": 208,
"cells_by_library": {
"wt1": 106,
"wt2": 102
},
"all_genotypes_cell_number": 998,
"unannotated": true
},
{
"label": "12_Cell body glial cell",
"type": "Cell body glial cell",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "12",
"cell_number": 212,
"cells_by_library": {
"wt1": 105,
"wt2": 107
},
"all_genotypes_cell_number": 861
},
{
"label": "13_Perineurial glial sheath",
"type": "Perineurial glial sheath",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "13",
"cell_number": 192,
"cells_by_library": {
"wt1": 93,
"wt2": 99
},
"all_genotypes_cell_number": 766
},
{
"label": "14_Adult alary muscle",
"type": "Adult alary muscle",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "14",
"cell_number": 211,
"cells_by_library": {
"wt1": 102,
"wt2": 109
},
"all_genotypes_cell_number": 712
},
{
"label": "15_Adult salivary gland",
"type": "Adult salivary gland",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "15",
"cell_number": 95,
"cells_by_library": {
"wt1": 44,
"wt2": 51
},
"all_genotypes_cell_number": 295
},
{
"label": "16_Unknown cluster",
"type": "Unknown cluster",
"clustering": "control",
"clustering_name": "Saavedra 2023 adult thorax clusters (controls)",
"source_cluster_id": "16",
"cell_number": 20,
"cells_by_library": {
"wt1": 12,
"wt2": 8
},
"all_genotypes_cell_number": 38,
"unannotated": true
}
]
}
8 changes: 8 additions & 0 deletions projects/saavedra_2023/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ sample_build:
genotype_includes: [FBal0288220, FBal0147425]
clusterings:
- { id: control, name: "Saavedra 2023 adult thorax clusters (controls)", sample_age: "adult (about 1-2 weeks)" }

# Clusters (projects/saavedra_2023/build_clusters.py): the authors' 17 clusters from their GEO
# metadata, restricted to the control nuclei. Held (untyped): the "Unknown cluster"s.
annotations:
review_columns: [clustering, source_cluster_id, type, all_genotypes_cell_number]

unidentified:
rule: none
18 changes: 18 additions & 0 deletions projects/saavedra_2023/mapping.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cluster_label clustering source_cluster_id all_genotypes_cell_number type class cell_number kind hold_reason fbbt_id fbbt_label match_type confidence new_term_needed verification_needed n_other_candidates justification manual_edit reviewed review_notes
0_Indirect flight muscle control 0 14616 Indirect flight muscle 6611 named pending 0
1_Muscle cell control 1 8173 Muscle cell 1930 named pending 0
2_Ventral nervous system control 2 3905 Ventral nervous system 1225 named pending 0
3_Epithelial cell control 3 3872 Epithelial cell 530 named pending 0
4_Adipose tissue control 4 2214 Adipose tissue 733 named pending 0
5_Muscle cell control 5 1742 Muscle cell 495 named pending 0
6_Tracheal control 6 1489 Tracheal 327 named pending 0
7_Epithelial cell control 7 1457 Epithelial cell 298 named pending 0
8_Hemocyte control 8 1426 Hemocyte 407 named pending 0
9_Unknown cluster control 9 1407 Unknown cluster 312 placeholder untyped pending 0
10_Peripheral nervous system control 10 1364 Peripheral nervous system 364 named pending 0
11_Unknown cluster control 11 998 Unknown cluster 208 placeholder untyped pending 0
12_Cell body glial cell control 12 861 Cell body glial cell 212 named pending 0
13_Perineurial glial sheath control 13 766 Perineurial glial sheath 192 named pending 0
14_Adult alary muscle control 14 712 Adult alary muscle 211 named pending 0
15_Adult salivary gland control 15 295 Adult salivary gland 95 named pending 0
16_Unknown cluster control 16 38 Unknown cluster 20 placeholder untyped pending 0
Loading