Last updated: 2026-07-05

Checks: 6 1

Knit directory: immgenT-GP-analysis/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.7.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(1) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 6d1c6c0. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .claude/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    analysis/assets/.DS_Store
    Ignored:    code/.DS_Store
    Ignored:    data
    Ignored:    figures/final-selected/.DS_Store
    Ignored:    figures/final-selected/bits/.DS_Store
    Ignored:    figures/final-selected/bits/Figure 1/.DS_Store
    Ignored:    figures/final-selected/bits/Figure 2/.DS_Store
    Ignored:    figures/final-selected/bits/Figure 3/.DS_Store
    Ignored:    figures/final-selected/bits/Figure 4/.DS_Store
    Ignored:    figures/final-selected/bits/Figure 6/.DS_Store
    Ignored:    figures/final-selected/bits/Figure 7/.DS_Store
    Ignored:    figures/final-selected/bits/Figure S1/.DS_Store
    Ignored:    figures/final-selected/bits/Figure S2/.DS_Store
    Ignored:    figures/final-selected/bits/Figure S3/.DS_Store
    Ignored:    figures/final-selected/bits/Figure S6/.DS_Store
    Ignored:    figures/final-selected/bits/Figure S7/.DS_Store
    Ignored:    figures/generated/.DS_Store
    Ignored:    figures/generated/Figure 5/
    Ignored:    figures/generated/Figure 7/
    Ignored:    figures/generated/Figure 8/
    Ignored:    figures/generated/Figure 9/

Untracked files:
    Untracked:  analysis/ExtendedDataTable1.Rmd
    Untracked:  analysis/ExtendedDataTable2.Rmd
    Untracked:  analysis/ExtendedDataTable3.Rmd
    Untracked:  analysis/ExtendedDataTable4.Rmd
    Untracked:  analysis/ExtendedDataTable5.Rmd
    Untracked:  analysis/ExtendedDataTable6.Rmd
    Untracked:  analysis/ExtendedDataTable7.Rmd
    Untracked:  figures/generated/ExtendedDataTable1_GP_summary.csv
    Untracked:  figures/generated/ExtendedDataTable2_GP_AUC_lineage.csv
    Untracked:  figures/generated/ExtendedDataTable3_GP_AUC_tissue.csv
    Untracked:  figures/generated/ExtendedDataTable4_GP_AUC_cluster.csv
    Untracked:  figures/generated/ExtendedDataTable5_GP_during_activation.csv
    Untracked:  figures/generated/ExtendedDataTable6_protein_factor_matrix.csv
    Untracked:  figures/generated/ExtendedDataTable7_protein_gating.csv
    Untracked:  script/ExtendedDataTable1_GP_summary.R
    Untracked:  script/ExtendedDataTable2_GP_AUC_lineage.R
    Untracked:  script/ExtendedDataTable3_GP_AUC_tissue.R
    Untracked:  script/ExtendedDataTable4_GP_AUC_cluster.R
    Untracked:  script/ExtendedDataTable5_GP_during_activation.R
    Untracked:  script/ExtendedDataTable6_protein_factor_matrix.R
    Untracked:  script/ExtendedDataTable7_protein_gating.R
    Untracked:  tables/

Unstaged changes:
    Deleted:    analysis/TableS1.Rmd
    Modified:   analysis/index.Rmd
    Modified:   code/R/gated_protein_helpers.R
    Modified:   code/R/roc_auc.R
    Modified:   code/README.md
    Modified:   code/pipeline/02_compute_auc.R
    Deleted:    figures/generated/Supplementary_Table1_GP_summary.csv
    Modified:   script/README.md
    Deleted:    script/TableS1.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Produced by script/ExtendedDataTable1_GP_summary.R:

# Extended Data Table 1: summary of GP characteristics and annotations.
#
# One row per GP (GP1..GP200) with:
#   - Lineage / Cluster / Tissue: the categories each GP *positively* predicts
#     well -- one-vs-rest AUC > 0.8 AND the optimal decision threshold at or
#     above the GP's median loading, so high loading (not low) drives the
#     prediction. Categories are annotation_level1 (lineage), annotation_level2
#     (cluster) and organ_simplified (tissue), all from the healthy
#     non-thymocyte AUC family (*_no_thymocytes_healthy, same population as
#     Figure 2/Figure 4); the median loading is likewise computed on the healthy
#     non-thymocyte cells so the threshold comparison is on the same population.
#   - Signature genes / proteins: the top 5 up- and top 5 down-regulated genes
#     and proteins by factor score, among those with |score| > 0.1 on the
#     max|.|=1-per-GP-scaled gene (F_pm_filtered) and protein (Figure 6's
#     Protein_F_pm) factor matrices.
#
# Reworks the retired Table S1 (script/TableS1.R): drops its Condition column,
# switches the annotations from the non-thymocyte healthy+diseased AUC to the
# healthy non-thymocyte AUC, adds protein signatures, and loosens the gene
# signature cutoff from 0.25 to 0.1.

data_path <- "data/"
output_path <- "figures/generated/"

# ---- Protein factor matrix (Figure 6's Protein_F_pm: filtered + max|.|=1 per
# GP column). Load, extract, and drop the heavy fit before loading L. ----
Protein_flash_result <- readRDS(paste0(data_path, "protein_flash_selected_summary_lognorm_backfit200.rds"))
Protein_F_pm_raw <- Protein_flash_result$F_pm
rm(Protein_flash_result); gc()

isotype_proteins <- grep("^Isotype", rownames(Protein_F_pm_raw), value = TRUE)
proteins_quality <- read.csv(paste0(data_path, "TableS4_citeseq_qc_20250513.csv"), header = TRUE, stringsAsFactors = FALSE, skip = 1)
good_proteins <- c(proteins_quality$protein[proteins_quality$classification == "good"], "IL2RA.CD25", "ITB7", "CD69")
exclude_proteins <- c("CD19", "CD34", "CD45.1", "CD45.2", "CD138", "TCRVA2", "TER119")
thy11_proteins <- grep("THY1.1", rownames(Protein_F_pm_raw), value = TRUE)

Protein_F_pm <- Protein_F_pm_raw[!rownames(Protein_F_pm_raw) %in% isotype_proteins, ]
Protein_F_pm <- Protein_F_pm[rownames(Protein_F_pm) %in% good_proteins, ]
Protein_F_pm <- Protein_F_pm[!rownames(Protein_F_pm) %in% exclude_proteins, ]
Protein_F_pm <- Protein_F_pm[!rownames(Protein_F_pm) %in% thy11_proteins, ]
D_lognorm <- diag(1 / apply(Protein_F_pm, 2, function(x) max(abs(x))))
Protein_F_pm <- Protein_F_pm %*% D_lognorm
Protein_F_pm[is.na(Protein_F_pm)] <- 0

# ---- Loadings, gene factor matrix, healthy non-thymocyte AUC ----
# L_pm_filtered / F_pm_filtered and the cached AUC matrices all share the raw
# "K1","K2",... column names (from the flashier fit); keep them for matching and
# relabel to "GP1","GP2",... only for output.
L_pm_filtered <- readRDS(paste0(data_path, "L_pm_filtered.rds"))
F_pm_filtered <- readRDS(paste0(data_path, "F_pm_filtered.rds"))
level_1_AUC_list <- readRDS(paste0(data_path, "level_1_AUC_list_figure_no_thymocytes_healthy.rds"))
level_2_AUC_list <- readRDS(paste0(data_path, "level_2_AUC_list_figure_no_thymocytes_healthy.rds"))
organ_AUC_list   <- readRDS(paste0(data_path, "organ_simplified_AUC_list_figure_no_thymocytes_healthy.rds"))

# Use L_pm_filtered's "K1".."K200" names as the canonical GP key: the AUC
# matrices carry these same names, whereas F_pm_filtered's raw columns are
# "F1".."F200" and the protein factor columns are unnamed -- but all three are
# in the same factor order as L (same flashier fit / fixed-loading projection),
# so relabeling them to L's K-names aligns every signature/annotation lookup.
gps <- colnames(L_pm_filtered)          # "K1".."K200"
gp_labels <- paste0("GP", seq_along(gps))
colnames(Protein_F_pm) <- gps

# Normalize the gene factor matrix so each GP column has max|score| = 1.
F_pm_filtered <- apply(F_pm_filtered, 2, function(x) x / max(abs(x)))
colnames(F_pm_filtered) <- gps

# ---- Median loading on the healthy non-thymocyte cell subset ----
seurat_meta <- readRDS(paste0(data_path, "igt1_96_withtotalvi20260206_clean_ADTonly.Rds"))@meta.data
seurat_meta_filtered <- seurat_meta[rownames(L_pm_filtered), ]
rm(seurat_meta); gc()
# which() drops any cells whose condition/lineage metadata is NA (so they don't
# leak in as NA rows and turn every median into NA). seurat_meta_filtered is row-
# aligned to L_pm_filtered, so the integer index selects the matching L rows.
healthy_nonthy_idx <- which(
  seurat_meta_filtered$condition_broad == "healthy" &
    seurat_meta_filtered$annotation_level1 != "thymocyte"
)
L_healthy_nonthy <- L_pm_filtered[healthy_nonthy_idx, , drop = FALSE]

# ---- Positively-predicted categories: AUC > 0.8 and threshold >= median
# loading (so high loading drives the prediction) ----
get_passing_categories <- function(auc_list, gps, L_mat, threshold = 0.8) {
  auc_mat <- auc_list$auc
  thr_mat <- auc_list$threshold
  gp_median_loading <- apply(L_mat, 2, median)
  lapply(gps, function(gp) {
    if (!gp %in% colnames(auc_mat)) return("")
    auc_vals <- auc_mat[, gp]
    thr_vals <- thr_mat[, gp]
    med_load <- gp_median_loading[gp]
    pass <- !is.na(auc_vals) & !is.na(thr_vals) &
      auc_vals > threshold & thr_vals >= med_load
    cats <- rownames(auc_mat)[pass]
    paste(cats, collapse = "; ")
  })
}

lineage_cats <- get_passing_categories(level_1_AUC_list, gps, L_healthy_nonthy)
cluster_cats <- get_passing_categories(level_2_AUC_list, gps, L_healthy_nonthy)
tissue_cats  <- get_passing_categories(organ_AUC_list, gps, L_healthy_nonthy)

# ---- Top 5 up / down signature genes and proteins (|score| > 0.1) ----
top_signatures <- function(score_mat, gps, cutoff = 0.1, n = 5) {
  pos <- lapply(gps, function(gp) {
    vals <- score_mat[, gp]
    cand <- names(vals)[vals > cutoff]
    top <- head(cand[order(vals[cand], decreasing = TRUE)], n)
    paste(top, collapse = "; ")
  })
  neg <- lapply(gps, function(gp) {
    vals <- score_mat[, gp]
    cand <- names(vals)[vals < -cutoff]
    top <- head(cand[order(abs(vals[cand]), decreasing = TRUE)], n)
    paste(top, collapse = "; ")
  })
  list(pos = unlist(pos), neg = unlist(neg))
}

gene_sig <- top_signatures(F_pm_filtered, gps)
prot_sig <- top_signatures(Protein_F_pm, gps)

supp_table <- data.frame(
  GP = gp_labels,
  Lineage = unlist(lineage_cats),
  Cluster = unlist(cluster_cats),
  Tissue = unlist(tissue_cats),
  Signature_Genes_Pos = gene_sig$pos,
  Signature_Genes_Neg = gene_sig$neg,
  Signature_Proteins_Pos = prot_sig$pos,
  Signature_Proteins_Neg = prot_sig$neg,
  stringsAsFactors = FALSE
)

write.csv(
  supp_table,
  file = paste0(output_path, "ExtendedDataTable1_GP_summary.csv"),
  row.names = FALSE
)

Table

Showing the first 20 rows (of 200); download the full table at figures/generated/ExtendedDataTable1_GP_summary.csv.

GP Lineage Cluster Tissue Signature_Genes_Pos Signature_Genes_Neg Signature_Proteins_Pos Signature_Proteins_Neg
GP1 CD8.K; CD4.X; CD4.Y; CD4.P; Treg.P; gdT.B; gdT.C; gdT.D; gdT.P; CD8aa.C; CD8aa.D; CD8aa.E; CD8aa.P; DN.P; DP.wY; DP.wP CT010467.1; Tmsb4x; Actb; Tmsb10; Eef1a1 THY1.2; CD45RB; CD5; CD2; CD55.DAF
GP2 CD8.wM; CD4.wM; Treg.wM; gdT.E; gdT.wM; CD8aa.wM; Tz.wM; DN.wM; DP.wC; DP.wM Arhgap15; Dock2; Mbnl1; Inpp4b; Foxp1 Tmsb10; Tmsb4x; Fau; Pfn1; Ppia CD45RB; THY1.2; CD44; CD24; CD27 CD4; ICOS.CD278
GP3 gdT.A; gdT.B; gdT.C; gdT.D; gdT.E; gdT.F; gdT.Z; gdT.P; CD8aa.C; CD8aa.D; CD8aa.E; DP.wY small intestine epi Gzma; Cd7; Ccl5; Fcer1g; Tyrobp Tmsb10; Tpt1; CT010467.1; Actb; Tmsb4x CD38; CD8A; ITB7; CD39; CD73.5NTD THY1.2; CD5; CD2; CD11A; CD44
GP4 CD4.wN Tmsb10; Fau; CT010467.1; Pfn1; Ppia Dock2; Rack1; Arhgap15; Myh9; Ptprc CD5; CD45RB; CD55.DAF; CD4; CD31
GP5 CD8.K; CD8.P; CD4.P; Treg.P; gdT.P; CD8aa.P; Tz.P; DN.P; DP.wP H2ac8; H1f5; H1f4; H4c4; Hist1h2ap Igfbp4; Cnn2; Limd2; Ccr7; Cd52 CD8A; CD8B; CD73.5NTD; CD38; CD103 CD4; CD62L
GP6 CD8.K; CD4.T; CD4.U; CD4.X; CD4.Y; CD4.P; Treg.D; Treg.E; Treg.P; gdT.Q; gdT.R; gdT.S; gdT.T; gdT.U; gdT.V; gdT.X; gdT.Z; Tz.D skin S100a6; Gzmb; Lgals1; Vim; Crip1 Tmsb10; CT010467.1; Eef1a1; Cmss1; Cdk8 ITAM.CD11B; CD86; CD39; GR1-LY6G-LY6C1-LY6C2; GITR.CD357 THY1.2; ICOS.CD278; KLRG1; CD5; CD31
GP7 gdT.Z; DP.wG CT010467.1; Ccl5; Cmss1; Cdk8; Crip1 Igfbp4; Ccr7; Limd2; Ifi27l2a; Cd52 THY1.2; CD45RB; CD24; CD29; CD73.5NTD CD4; CD62L
GP8 gdT.X; gdT.Z skin; CNS Fth1; S100a6; Thy1; Ctla2a; Gem Ccl5; Gzma; Gzmb; AW112010; Tyrobp TCRVG3; CD2; CD4; CD44; TCRGD CD73.5NTD; CD38; CD8A; CD45RB; CD8B
GP9 CD8.wU; CD8.wV; DP.wC; DP.wE Cdk8; Cmss1; CT010467.1; Eef2; Myh9 Tmsb10; Fau; Tmsb4x; Cd52; Eif1 CD45RB; CD4; CD5; CD62L; CD55.DAF
GP10 CD8.H; CD8.I; CD8.K; CD8.wY; CD4.S; DN.F Ccl5; Gzma; Lgals1; Nkg7; Ly6c2 Ly6e; Ltb; Tcf7; Eef1b2; Eef1a1 KLRG1; CD8B; CD8A; ITAX.CD11C; ICAM1 CD4; CD62L; CD5; CD31; CD55.DAF
GP11 CD4.X lung; placenta; kidney Vps37b; Gramd3; Dusp10; Junb; Ccr7 Cd52; Ltb; Ptprcap; Mir142hg; Pfn1 CD45RB; CD5; CD2; CD31; CD55.DAF CD27; CD44; CD80
GP12 CD8.C; CD8.wX; CD4.E; CD4.G; CD4.H; CD4.I; Treg.B; Tz.C; DN.A; DN.G Izumo1r; Cdk8; Tox; Tbc1d4; Pdcd1 Crip1; Ccl5; Satb1; Igfbp4; Selplg FR4; CD73.5NTD; ICOS.CD278; CD38; NEUROPILIN1.CD304 CD62L; CD45RB; CD8A; CD55.DAF; CD8B
GP13 CD4.Y; gdT.Q; gdT.R; gdT.S; gdT.T; gdT.U; gdT.V; Tz.D Tmem176b; Tmem176a; Il7r; CT010467.1; Cd163l1 Ms4a4b; Inpp4b; Ctla4; Ifi27l2a; Cd2 CD44; TCRGD; CD73.5NTD; NEUROPILIN1.CD304; THY1.2 CD4; CD62L; CD86; SCA1; CD2
GP14 DP.wF; DP.wG Cd8b1; Cd8a; Satb1; Rag1; Themis H2-K1; Crip1; H2-D1; B2m; Eef1a1 CD8B; CD8A; CD155.PVR; CD4; SLAM.CD150 ITB7; SCA1; CD44; CD73.5NTD; CD55.DAF
GP15 CD8.D; CD8.F; CD4.F; Treg.C; gdT.X; DN.G; DN.H; DP.wH Eif5a; Npm1; Hsp90ab1; Ncl; Mif Malat1; Tmsb4x; Itm2b; Cd52; Ypel3 CD8B; IL2RA.CD25; CD8A; ICAM1; CD69 CD4; CD62L; SCA1; CD5; CD31
GP16 CD8.F; CD8.wY; CD4.D; DN.I; DN.J Ifi27l2a; Isg15; Ly6a; Bst2; Stat1 Thy1 SCA1; ICOS.CD278; CD4; CD11A; CD5 CD38; CD8A
GP17 CNS Ifi27l2a; Atp5e; Tmsb4x; Ripor2; Lef1 Actg1; Ubb; Hspa8; Eef1a1; Il31ra CD24; SCA1; ITAM.CD11B; CD38; GR1-LY6G-LY6C1-LY6C2 CD44; THY1.2; KLRG1; CD103; ITB7
GP18 Cpa3; CT010467.1; Crip1; Ccl5; Tmsb10 Ifi27l2a; Ccr7; Ly6d; Rgcc; Limd2 ITB7; CD27; THY1.2; CD62L; CD103 IL2RA.CD25; CD4; FR4; CD55.DAF
GP19 Prl8a9; Tpbpa; Psg21; Prl3b1; Creg1 Cts6; Ccr10; Cts3; Hsd17b2; Plekhh3 CD86; CD8B; CD4; GITR.CD357; LY49A CD62L; THY1.2; FR4; CD55.DAF; SCA1
GP20 CD8.K Cenpa; Ube2c; Cdc20; Cenpf; Arl6ip1 H2ac8; H1f5; H1f4; Hist1h2ap; H1f3 CD8B; CD8A; CD45RB; CD55.DAF; ITB7

Extended Data Table 1. One row per GP. Lineage, Cluster and Tissue list the categories (annotation_level1, annotation_level2, organ_simplified) that the GP positively predicts well – one-vs-rest AUC > 0.8 and the optimal decision threshold at or above the GP’s median loading, so high (not low) loading drives the prediction – computed on healthy non-thymocyte cells (the same population as Figure 2 / Figure 4), with the median loading taken on that same population. Signature genes / proteins give the top 5 up- and top 5 down-regulated genes and proteins by factor score, among those with |score| > 0.1 on the max|.|=1-per-GP-scaled gene and protein factor matrices.


sessionInfo()
R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.6.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_CA/en_CA/en_CA/C/en_CA/en_CA

time zone: Asia/Tokyo
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] vctrs_0.7.3     cli_3.6.6       knitr_1.50      rlang_1.2.0    
 [5] xfun_0.55       stringi_1.8.7   otel_0.2.0      promises_1.5.0 
 [9] jsonlite_2.0.0  workflowr_1.7.2 glue_1.8.1      rprojroot_2.1.1
[13] git2r_0.36.2    htmltools_0.5.9 httpuv_1.6.16   sass_0.4.10    
[17] rmarkdown_2.30  evaluate_1.0.5  jquerylib_0.1.4 tibble_3.3.0   
[21] fastmap_1.2.0   yaml_2.3.12     lifecycle_1.0.5 stringr_1.6.0  
[25] compiler_4.5.1  fs_1.6.6        Rcpp_1.1.1-1.1  pkgconfig_2.0.3
[29] later_1.4.4     digest_0.6.39   R6_2.6.1        pillar_1.11.1  
[33] magrittr_2.0.5  bslib_0.9.0     tools_4.5.1     cachem_1.1.0