Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Aligning Reads and Assigning Them to Genes

Single-Cell Technologies and Count Data · Tutorial 6 of 700

Aligning Reads and Assigning Them to Genes

See how reference alignment and gene assignment turn barcoded sequencing reads into gene-associated evidence for individual cells, and how to recognize ambiguous or failed assignments.

Beginner 10 min read

What You'll Learn

  • Distinguish read alignment from assignment to an annotated gene.
  • Understand how reference choice, annotation and library design affect assignment.
  • Compare unique, ambiguous, fractional and discarded read assignments.
  • Calculate cell-specific gene-associated read counts without treating reads as molecules.
  • Use alignment and assignment summaries to identify possible processing problems.

From a Sequenced Read to a Gene Assignment

A sequenced read is a string of bases produced from a library fragment. To use it as evidence about gene expression, an analysis must determine where its sequence is compatible with a reference and, when possible, which annotated gene it supports. These are related but distinct steps: alignment locates a read relative to a reference, while gene assignment connects an acceptable alignment to a gene feature defined by an annotation.

In a single-cell library, a read or its associated record may also carry a cell barcode and a UMI, as introduced in the earlier material on cell barcodes, UMIs, and gene identifiers. Those labels must remain associated with the read through alignment and assignment. At this stage, however, an assigned read is still read-level evidence. It is not automatically a distinct captured molecule: several reads can arise from the same molecule, and their handling depends on later processing.

Definition: A reference is the genome or transcript sequence collection against which reads are compared. An alignment is a proposed placement of a read on that reference, including the correspondence between read bases and reference positions. A gene assignment is a decision to associate an accepted alignment with a gene specified in an annotation. An alignment can exist without yielding a gene assignment.

What Determines an Alignment and Assignment?

An alignment program searches for placements that are sufficiently compatible with a read, allowing features such as sequencing errors, mismatches, or gaps according to the program's scoring and filtering rules. For RNA sequencing, reads may cross a splice junction: an aligner designed for this data can represent a read as matching separated regions of the genome. An alternative is to compare reads with transcript sequences. These approaches rely on a chosen reference and do not guarantee that every read has one clearly identifiable location.

A read may have no acceptable alignment, one plausible alignment, or several plausible alignments. Several alignments can arise when a sequence is shared by related genes or repeated in the reference. A read with one reported placement is not necessarily biologically unique if the search or reference was incomplete; uniqueness is always relative to the reference and the aligner's settings.

Gene assignment then uses an annotation: a collection of genomic or transcript coordinates and gene identifiers. In general, a pipeline asks whether the accepted alignment is compatible with a feature assigned to a gene under its specified rules. Those rules may depend on the assay's library design and strand information, as well as which feature types are included. A read can align well but fail assignment if it does not match an eligible annotated feature. The exact treatment of reads near feature boundaries depends on the assignment procedure.

Key distinction: A high-quality alignment answers, “Where does this read plausibly match the reference?” A gene assignment answers, “Which annotated gene, if any, will receive this read as evidence?” Neither answer alone establishes that the read represents a distinct RNA molecule.

The steps rely on several practical assumptions. The reference should be appropriate for the sample and analysis, and the annotation should describe the genes intended for measurement. The library preparation and read orientation should be represented correctly in the analysis settings. Finally, the alignment and assignment rules should be applied consistently across samples being compared. Violating these conditions can produce missing assignments or systematic differences that look like biological variation.

Worked Example: A Read With One Accepted Gene Assignment

Suppose a hypothetical read has cell barcode C07 and aligns to one location with an illustrative mapping quality of 42. Under the chosen reference, annotation, and assignment rules, that location supports gene G1. Assume the barcode has already been accepted by the pipeline, the alignment passes its stated filters, and the library orientation is consistent with the assignment.

The read contributes one unit of read-level evidence for G1 in cell C07. If \(R_{C07,G1}\) denotes the number of reads assigned to that cell and gene under this policy, its contribution is

$$ R_{C07,G1} \leftarrow R_{C07,G1} + 1. $$

The mapping-quality value is not itself a gene count. Mapping quality is commonly based on a Phred-scaled estimate of the chance that a reported placement is wrong, but its precise calculation and interpretation depend on the aligner. In particular, the illustrative value 42 does not prove the placement is correct. The conclusion is limited to this: given the stated filters and assignment rules, this read is assigned to G1 for C07. It does not establish that the read is a separate molecule.

How Read Assignments Contribute to Cell-Specific Counts

Once each retained read has a cell label and a gene assignment, the number of assigned reads for a cell–gene pair can be defined by adding one for each qualifying read. For read records \(i=1,\ldots,n\), let \(c_i\) be the cell label and \(g_i\) the assigned gene, when one is available. Under a policy that assigns each retained read to at most one gene, the read-level count is

$$ R_{cg} = \sum_{i=1}^{n} I(c_i=c,\ g_i=g), $$

where \(I(\cdot)\) equals 1 when the condition is true and 0 otherwise. This definition makes explicit how assignment decisions affect counts: a read that is discarded or left unassigned contributes zero, while a read assigned to gene \(g\) in cell \(c\) contributes one. The formula describes read counts, not deduplicated molecule counts.

The indicator formulation also clarifies what happens when a read has multiple plausible genes. A pipeline must define how such reads are handled. It might discard them, assign them to one gene under a rule, or allocate their contribution across candidates. These choices change the meaning and often the numerical values of the resulting counts; they should not be mixed silently.

Worked Example: Ambiguous Reads Under Two Policies

In a hypothetical cell C12, four reads have clear assignments to gene A and two have clear assignments to gene B. In addition, six reads align equally plausibly to A or B. Assume all ten? No: there are twelve reads in total, all carrying the accepted barcode C12; the four and two clear reads are distinct from the six ambiguous reads. Compare discarding ambiguous reads with allocating each ambiguous read equally between the two genes.

Discard policy. The six ambiguous reads contribute nothing. The assigned read counts are \(R_{C12,A}=4\) and \(R_{C12,B}=2\), for a total of \(4+2=6\) assigned reads.

Equal fractional allocation. Each ambiguous read contributes \(1/2\) to each candidate gene. The ambiguous reads contribute \(6(1/2)=3\) to A and 3 to B. Thus,

$$ R_{C12,A}=4+3=7,\qquad R_{C12,B}=2+3=5. $$

The fractional policy accounts for all twelve reads while preserving a total contribution of one per read: \(7+5=12\). The discard policy retains six assigned read contributions. Neither result is a deduplicated molecule count. Fractional values also mean that the output is no longer an integer count of assigned read records, so the assignment policy must be known when interpreting or analyzing it.

A Short Justification for Fractional Assignment

Fractional allocation can be understood as an expected contribution under a simple uncertainty model. Suppose a read has exactly two candidate genes, A and B, and the procedure assigns it to A with probability \(q\) and to B with probability \(1-q\). Let \(Z_A\) equal 1 if the read is assigned to A and 0 otherwise. Then \(E(Z_A)=q\), because \(Z_A\) is a 0–1 indicator with probability \(q\) of being 1. If the evidence provides no reason to favor either candidate, choosing \(q=1/2\) gives an expected contribution of \(1/2\) to each gene.

For six such reads, linearity of expectation gives an expected contribution of \(6(1/2)=3\) to each gene. This calculation does not show that the reads truly came equally from the two genes. It justifies fractional allocation as an accounting of expected contributions under the stated equal-probability assumption. If that assumption is inappropriate, the fractional counts can misrepresent the evidence.

Worked Example: Summarizing Assignment Outcomes

A hypothetical processing run contains 12 read records. Ten have at least one alignment passing the alignment filter. Of those ten, seven are assigned to a gene under the chosen rules, two have multiple plausible gene assignments and are left unassigned, and one aligns but does not match an eligible annotated feature. The other two reads have no accepted alignment. Assume the seven assigned records include four assigned to gene G1 in cell C01 and three assigned to gene G2 in cell C02.

The fraction with at least one accepted alignment is \(10/12=0.8333\), or 83.33%. The fraction assigned to a gene, using all read records as the denominator, is \(7/12=0.5833\), or 58.33%. Among reads with an accepted alignment, the gene-assignment fraction is \(7/10=0.7000\), or 70.00%.

The assigned read-level totals are four for G1 in C01 and three for G2 in C02. The remaining five records have different outcomes: two have no accepted alignment, two are ambiguous under this policy, and one has no eligible gene assignment. They should not be described as five reads that failed alignment, because three of the five did align. These summaries are useful precisely because they separate alignment from gene assignment.

Diagnostics, Alternatives, and Limitations

A useful review begins with assignment outcomes, not just a final count total. Examine the fractions of reads that are unmapped, uniquely placed, multiply placed, assigned to genes, or aligned without an eligible assignment. Compare these summaries across samples and check that the same reference, annotation, library-orientation settings, and assignment policy were used. A sharp sample-specific drop in assigned reads can indicate a technical difference, a reference or annotation mismatch, or an incorrect setting; by itself, it does not identify which explanation is correct.

  • Unexpectedly many unmapped reads: check read quality, reference compatibility, and whether the correct reference was used.
  • Many multiple alignments: consider whether repetitive or shared sequences are common in the library and whether the policy for ambiguous reads is appropriate.
  • Many aligned reads without gene assignments: verify the annotation and feature-selection settings, and check that strand settings match the library.
  • Different assignment rates across samples: confirm that settings and references were consistent before interpreting the difference as biological.

The main alternatives for ambiguous reads are to discard them, choose one candidate using an explicit rule, or allocate their contributions across candidates. Discarding is straightforward but loses ambiguous evidence. Choosing a single candidate preserves integer read counts but can create arbitrary or rule-dependent assignments. Fractional allocation retains total read contribution but relies on a model for how evidence should be shared. No policy can resolve information that the read sequence does not contain.

Alignment and assignment also depend on the reference and annotation being sufficiently accurate for the intended question. A read may be placed incorrectly, a gene may be absent or inaccurately represented, or an assignment rule may omit relevant evidence. Counts therefore summarize the output of a specified computational procedure, not error-free observations of gene expression. Most importantly, a count of reads assigned to a cell and gene must not be interpreted as the number of distinct RNA molecules without the appropriate additional processing.

Common pitfall: “Every aligned read belongs to exactly one gene, so the aligned-read total is the gene-count total.” This is incorrect: reads can align to multiple locations or to no eligible annotated feature. The correction is to report alignment and assignment separately and state how ambiguous reads were treated.
1
Check the reference and annotation.
Confirm that the chosen sequences and gene definitions are suitable for the library and are used consistently.
2
Assess alignments.
Apply the stated alignment filters and distinguish no accepted placement from multiple plausible placements.
3
Apply assignment rules.
Use the annotation and library settings to assign, fractionally allocate, or leave reads unassigned according to a documented policy.
4
Summarize read-level evidence.
Retain the cell label and report assigned reads with units and the assignment policy; do not equate these directly with distinct molecules.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. How does alignment differ from gene assignment?
  2. A read has two equally plausible gene candidates. Under a discard policy, how much does it contribute to each gene? Under equal fractional allocation?
  3. Of 20 reads, 15 have accepted alignments and 9 are assigned to genes. What are the accepted-alignment fraction and the gene-assignment fraction using all reads as the denominator?
  4. Why is an assigned read count not necessarily a count of distinct RNA molecules?

Solutions. (1) Alignment proposes a location on the reference; gene assignment associates an accepted placement with an annotated gene under specified rules. (2) Discarding contributes zero to both genes. Equal fractional allocation contributes \(1/2\) to each, for a total contribution of one read. (3) The accepted-alignment fraction is \(15/20=0.75\), or 75%; the gene-assignment fraction is \(9/20=0.45\), or 45%. (4) Multiple reads can arise from the same captured molecule, so counting assigned reads alone does not identify distinct molecules.

Clinical Biostats