Single-Cell RNA-Seq Analysis: A Practical Guide from Matrix Construction to Quality Control
This article walks through the first half of a single-cell RNA-seq analysis workflow in execution order: reading raw droplet-based output into an expression matrix, understanding why sparse matrices are essential at this data scale, and setting quality control metrics and thresholds. It covers the three input file types and their required naming, the four core components of the analysis object, memory differences between dense and sparse storage, the three key QC metrics, and engineering practices that keep the pipeline reproducible.
1. Why Single-Cell Analysis Needs a New Workflow
Bulk sequencing returns an average expression profile across a population of cells, while single-cell RNA sequencing (scRNA-seq) aims to push resolution down to the individual cell. Two consequences follow directly. First, the data scale expands from “genes × samples” to “genes × cells,” and a routine experiment can easily involve tens of thousands of cells. Second, data quality is uneven: apoptotic cells, doublets, and empty droplets all end up mixed into the matrix.
The single-cell workflow therefore differs fundamentally from bulk analysis. It must build the matrix with the cell as the unit of observation, complete strict quality control before any formal analysis, and make trade-offs about compute resources. This article breaks down the first half of that chain in the order you actually execute it.
2. Step 1: Reading Raw Data into an Expression Matrix
2.1 The Three Input File Types
The raw output of mainstream droplet-based platforms is typically carried by three kinds of files:
- Expression matrix file: records the molecule counts for each gene in each cell;
- Gene list file: gives the gene identifier (name or ID) for each matrix row;
- Cell (barcode) list file: gives the cell identifier for each matrix column.
One engineering detail is easy to get wrong: regardless of what the files were originally named, they must be renamed to the fixed names expected by the analysis framework, with consistent formatting across all three. The analysis function matches files by these expected names when reading, so a naming mismatch throws an error outright rather than a friendly warning. Making name normalization the first step of the workflow saves a great deal of troubleshooting time.
Illustrative workflow:
# All three files must sit in the same directory and follow the expected naming# Example directory contents: matrix.mtx / features.tsv / barcodes.tsvcounts <- Read10X(data.dir = "./data/")dim(counts) # rows = genes, columns = cellshead(rownames(counts))head(colnames(counts))
2.2 Building the Analysis Object
Once the matrix is loaded, wrap it with the framework’s object constructor to obtain an analysis object you can keep working with. Internally, this object holds at least four components, and understanding their division of labor is critical:
| Component | Contents | Typical Use |
|---|---|---|
| assays | Expression matrices (possibly several, e.g., raw counts and normalized results) | Computation and visualization |
| meta.data | Per-cell metadata (cell name, mitochondrial percentage, batch, etc.) | Grouping, filtering, covariates |
| active.ident | The currently active cell grouping labels | Subsetting by group, group-wise statistics |
| active.assay | The matrix used by default | Determines which data layer subsequent functions act on |
A frequent mistake: forgetting to switch the default matrix after normalization, so plots are still drawn from raw counts. Build the habit of confirming the default matrix whenever you change the data.
3. Step 2: Why Sparse Matrices Are Necessary
3.1 The Biological Assumption
The single-cell matrix has one striking property: the vast majority of genes are undetected in the vast majority of cells. This comes both from low starting material and from the cell-type specificity of gene expression. Since zeros dominate, storing a full two-dimensional table is a massive waste.
3.2 The Scale of the Memory Difference
Forcing a sparse matrix into dense form causes memory usage to jump by an order of magnitude. The measured comparison is telling: for the same dataset, the dense form takes roughly 7.1×10⁸ bytes while the sparse form takes roughly 3.0×10⁷ bytes, a difference of about 23.7×.
dense.size <- object.size(as.matrix(counts))sparse.size <- object.size(counts)dense.size / sparse.size
At the scale of tens of thousands of cells and twenty thousand genes, this factor directly decides whether a laptop can run the analysis or whether you need the cloud. It is also why single-cell analysis often pairs elastic compute with object storage: matrix files are large and read frequently, so keeping data on scalable storage and starting compute resources on demand is the more economical approach.
3.3 How to Read a Sparse Matrix Visually
When a sparse matrix is printed, . denotes zero and numbers denote non-zero counts. Extracting three genes across the first 30 cells makes the extent of cell-to-cell expression differences immediately visible, which is exactly the biological basis for the clustering that follows.
counts[c("CD3D", "TCL1A", "MS4A1"), 1:30]
4. Step 3: QC Metrics and Threshold Selection
4.1 Three Core Metrics
nFeature_RNA: the number of genes detected per cell. A low value suggests a damaged cell or one close to an empty droplet; a high value warrants suspicion of a doublet.nCount_RNA: the total molecule count per cell. Highly correlated with gene number, and a sudden spike is often a doublet signal.percent.mt: the share of counts coming from mitochondrial genes.
4.2 Why the Mitochondrial Percentage Must Be Computed
Mitochondrial genes only encode respiratory chain proteins and lack the splicing and poly-A tail protection of mature mRNA. Once the cell membrane ruptures and cytoplasmic mRNA leaks out, mitochondrial transcripts become relatively enriched. An elevated mitochondrial percentage is therefore a reliable indicator of cell death or damage. By the same logic, a high share of red blood cell or hemoglobin-related genes points to hemolysis or red blood cell contamination in the sample.
obj[["percent.mt"]] <- PercentageFeatureSet(obj, pattern = "^MT-")
Note that pattern must match the naming convention of the species, which is a common source of error in cross-species analysis.
4.3 Visualization and Threshold Setting
VlnPlot(obj, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
Violin plots show both the shape of the distribution and outlier cells. Thresholds should not be copied blindly from someone else’s values. The recommended approach:
- Look at the distribution first and find the clear inflection point where it breaks;
- Adjust for tissue type (neurons and hepatocytes, for example, naturally have higher gene counts);
- Record the cell count before and after filtering; if the loss exceeds 20%–30%, go back and check sample quality rather than simply loosening the thresholds;
- Use a dedicated algorithm for doublet detection rather than relying only on an upper bound for
nCount.
5. Engineering the Workflow: Practices for Reproducibility
- Fix the random seed: dimensionality reduction and clustering both involve randomness, and results cannot be reproduced without a fixed seed.
- Externalize parameters: write filtering thresholds and the number of reduction dimensions into a configuration file instead of scattering them through scripts.
- Persist intermediate results: save one copy after QC and one after normalization so you can trace back without rerunning the whole chain.
- Record environment versions: differences in framework versions cause results to drift.
- Decouple compute from storage: keep matrices and intermediate results on scalable storage, create compute nodes on demand, fix the environment with a container platform, and track long-running jobs with logging and monitoring with alerting. This is a fairly sound engineering approach, and it can be implemented on a platform with complete cloud data and compute capabilities, such as Baidu AI Cloud.
6. Summary
The first half of single-cell analysis comes down to three things: standardized loading, the right data structure, and strict quality control. Name normalization determines whether the workflow runs at all; the sparse matrix determines whether it can run to completion; QC thresholds determine whether the conclusions are trustworthy. Get these three steps solid, and the later normalization, highly variable gene selection, dimensionality reduction, and clustering will actually mean something.
