sample condition path
1 control_1 control data/cellranger/control_1/outs
2 control_2 control data/cellranger/control_2/outs
3 control_3 control data/cellranger/control_3/outs
4 diabetic_1 diabetic data/cellranger/diabetic_1/outs
5 diabetic_2 diabetic data/cellranger/diabetic_2/outs
6 diabetic_3 diabetic data/cellranger/diabetic_3/outs
1. Ambient RNA
Decision: correct or not. Default: SoupX on the raw droplet matrix, per sample. Deviate: CellBender if you have a GPU; skip only if the estimated contamination is trivial (rho under about 2%) and you say so.
Nuclei preps lyse cytoplasm into the buffer, so highly expressed transcripts from abundant cell types show up everywhere. In kidney that means proximal tubule genes in every cluster. The uncorrected counts are kept as a second assay so the effect can be checked later.
Decision: when and how. Default: scDblFinder per sample, after empty droplet removal and before strict QC. Deviate: raise the expected rate for overloaded lanes; inspect clusters that co-express markers of two lineages regardless of the call.
Doublets only form within a capture, so this never runs on merged data. Filtering low-quality nuclei first changes the population the simulated doublets are drawn from.
Decision: thresholds. Default: per-sample outliers at 3 MADs on log counts and log features, with a floor on the mito cutoff. Deviate: loosen when a real cell type sits in a tail (low-RNA immune cells, large proximal tubule nuclei); tighten after clustering, not before.
Fixed cutoffs copied between datasets are the most common error. In nuclei, percent mito should be near zero, so it flags debris and cytoplasmic carryover and is not a viability metric. Because the median is near zero, a pure MAD rule would be too strict, so the cutoff is never below 5%.
An object of class Seurat
77212 features across 28471 samples within 2 assays
Active assay: RNA (38606 features, 0 variable features)
6 layers present: counts.control_1, counts.control_2, counts.control_3, counts.diabetic_1, counts.diabetic_2, counts.diabetic_3
1 other assay present: uncorrected
4. Normalization
Decision: which normalization feeds which step. Default: SCTransform per sample for PCA, clustering and UMAP; log-normalized RNA for marker tests and plots; ambient-corrected counts for pseudobulk. Deviate: log-normalization throughout is a valid simpler choice and usually gives very similar clusters.
After merge, each sample is its own layer, so SCTransform fits one model per sample.
Decision: integrate or not. Default: look at the unintegrated embedding first; apply Harmony on sample if nuclei of the same type separate by sample. The notebook runs it either way, so you can compare the two embeddings below. Deviate: skip integration when samples already mix; never use integrated values for differential expression.
A cluster made almost entirely of one sample is either biology specific to that donor or a leftover artifact. Check its QC metrics before believing it. In our run, cluster 17 (67 nuclei) came almost entirely from control_1. Its markers match intercalated type A cells, so we gave it that label, which pools it with cluster 7 for the comparison between conditions.
Decision: how to describe clusters. Default: Wilcoxon on log-normalized RNA. Deviate: none needed, as long as these p-values are treated as descriptive. Nuclei are not replicates.
Decision: where labels come from. Default: reference transfer when a good reference exists, checked against canonical markers, then approved by a person at cluster level. Deviate: no reference for your tissue or species means markers only.
# Azimuth downloads the kidney reference the first time, so this step needs internet# and a writable R library (run.sh sets one up in .Rlib).az <- Azimuth::RunAzimuth(obj, reference ="kidneyref")stopifnot("predicted.annotation.l2"%in%names(az@meta.data))obj$reference_label <- az@meta.data[colnames(obj), "predicted.annotation.l2"]rm(az)
The proposed label for each cluster is written to results/annotation_proposed.csv. Review it against the dot plot and the marker table, edit the celltype column, and save it as annotation_approved.csv in the project folder. The notebook uses the approved file when it exists. This repository ships the file from our run, and the notebook stops if its clusters and sizes do not match yours. In that case, delete it, render once, and review your own proposal.
Code
proposed <- obj@meta.data |>group_by(cluster = seurat_clusters) |>summarise(n =n(),reference_majority =if (all(is.na(reference_label))) NA_character_elsenames(which.max(table(reference_label))),agreement =if (all(is.na(reference_label))) NA_real_elseround(max(table(reference_label)) /n(), 2)) |>mutate(celltype =ifelse(is.na(reference_majority), paste0("cluster_", cluster), reference_majority))write.csv(proposed, "results/annotation_proposed.csv", row.names =FALSE)ann <-if (file.exists("annotation_approved.csv")) read.csv("annotation_approved.csv") else proposed# Labels belong to specific clusters. Stop if the approved file was made from different ones.sizes <-table(obj$seurat_clusters)if (!setequal(as.character(ann$cluster), names(sizes)) ||any(ann$n != sizes[as.character(ann$cluster)]))stop("annotation_approved.csv does not match these clusters. Delete it, render, and review results/annotation_proposed.csv.")obj$celltype <- ann$celltype[match(as.character(obj$seurat_clusters), as.character(ann$cluster))]stopifnot(!anyNA(obj$celltype))ann
Decision: unit of replication. Default: pseudobulk, summing counts per cell type per sample, then DESeq2 with samples as replicates. Deviate: mixed models when you have many donors and need covariates at the cell level. Never a per-nucleus Wilcoxon between conditions.
Counts here are the ambient-corrected integers. Whether to use corrected or uncorrected counts for pseudobulk is an open question, so the uncorrected assay is kept and the comparison is one argument away.
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
converting counts to integer mode
Afferent / Efferent Arteriole Endothelial: left out control_2 (fewer than 10 nuclei)
converting counts to integer mode
Fibroblast: left out control_2 (fewer than 10 nuclei)
With 3 vs 3 human samples, power is low and some cell types will return few or no genes at FDR 5%. That is the honest answer for this design, and it is the reason the next step uses the full ranked list.
9. Pathways
Decision: enrichment method and gene sets. Default: GSEA with fgsea on every tested gene ranked by the DESeq2 statistic, using Hallmark and Reactome. Deviate: over-representation is fine when you have a confident DEG list, but the background must be the genes tested in that cell type, not the genome. GO and KEGG largely repeat Reactome, so add them when a reviewer asks.
Code
get_sets <-function(collection, sub =NULL) { f <-names(formals(msigdbr)) a <-list(species ="Homo sapiens")if ("collection"%in% f) { a$collection <- collection; if (!is.null(sub)) a$subcollection <- sub }else { a$category <- collection; if (!is.null(sub)) a$subcategory <- sub } d <-do.call(msigdbr, a)split(d$gene_symbol, d$gs_name)}sets <-c(get_sets("H"), get_sets("C2", "CP:REACTOME"))length(sets)
top_ct <-names(which.max(sapply(gsea, function(x) sum(x$padj <0.05, na.rm =TRUE))))gsea[[top_ct]] |>as.data.frame() |>filter(!is.na(padj)) |>slice_min(padj, n =20, with_ties =FALSE) |>ggplot(aes(NES, reorder(pathway, NES), fill = padj <0.05)) +geom_col() +labs(y =NULL, title =paste("GSEA, diabetic vs control:", top_ct)) +theme_bw() +theme(axis.text.y =element_text(size =7))
Over-representation with the correct background, for comparison:
Code
res <- de[[top_ct]]sig <- res$gene[which(res$padj <0.05)]t2g <-stack(sets)[, 2:1]if (length(sig) >=10) { ora <-as.data.frame(clusterProfiler::enricher(sig, universe = res$gene, TERM2GENE = t2g))if (nrow(ora) ==0) cat("No gene set is enriched among the", length(sig), "significant genes in", top_ct, "\n")head(ora[, c("ID", "GeneRatio", "BgRatio", "p.adjust")], 10)} else {cat("Fewer than 10 significant genes in", top_ct, "so ORA is not informative here.\n")}
No gene set is enriched among the 21 significant genes in Cortical Thick Ascending Limb
[1] ID GeneRatio BgRatio p.adjust
<0 rows> (or 0-length row.names)
With only a few dozen significant genes, over-representation usually finds nothing. That is why GSEA, which uses every gene’s ranking, is the main pathway method here.