Pseudoalignment of scRNA-seq Reads with kb-python
This tutorial provides a brief introduction to kb-python. For a more in-depth guide, see the official documentation and reference the papers for kb-python, bustools, and kallisto.
kb-python is a lightweight, command-line toolkit for processing single-cell RNA sequencing (scRNA-seq) data. It provides an efficient and transparent way to convert raw sequencing reads into gene count matrices ready for downstream analysis.
The tool integrates two powerful components:
kallisto - performs fast and accurate transcript quantification using pseudoalignment
bustools - manages barcode and UMI information in the BUS (Barcode, UMI, Set) file format.
Together, these tools enable a streamlined and modular workflow that supports flexible experimental designs and efficient large-scale processing.
A typical kb-python workflow includes:
Building a reference index with
kb refProcessing FASTQ files into the BUS format with
kb countGenerating a count matrix summarizing gene expression per cell
In order to install kb-python, follow our installation instructions here.
Workflows
kb-python provides three workflows tailored to different experimental setups and analysis goals. The two most commonly used are:
NAC workflow – quantifies nascent (unspliced) transcripts. This workflow is typically used for single-nucleus RNA-seq experiments, where a substantial portion of captured mRNA remains unspliced.
Standard workflow – quantifies mature (fully spliced) transcripts. This workflow is suitable when you are interested only in processed mRNA.
Step 1: Generate a Reference Index
The first step of any RNA-seq analysis is aligning your reads to a reference genome. To do this, kb-python requires a reference index representing the set of target transcripts to which your reads will be mapped.
Using a Default Index
kb-python conveniently has a precompiled set of indices for the following species:
- human
- mouse
- dog
- monkey
- zebrafish
For the standard workflow, you can load the human index as follows:
kb ref -d human -i index.idx -g t2g.txtwhich will create the files index.idx and t2g.txt.
and for the nascent workflow,
kb ref --workflow=nac -d human -i index.idx \
-g t2g.txt -c1 cdna.txt -c2 nascent.txtwhich will additionally generate the files cdna.txt and nascent.txt.
See how the precompiled indices were generated here.
Generating a Custom Index
In order to make a custom index, you must specify a genome FASTA reference file and a GTF annotation file from which to extract the transcript sequences. You can obtain these files from ENSEMBL. We recommend using the primary assembly FASTA file (ends .dna.primary_assembly.fa.gz).
Then, to generate an index for the standard workflow, run:
kb ref -i index.idx -g t2g.txt -f1 cdna.fasta genome.fasta genome.gtfand for the nac workflow, run:
kb ref --workflow=nac -i index.idx -g t2g.txt -c1 cdna.txt -c2 nascent.txt \
-f1 cdna.fasta -f2 nascent.fasta genome.fasta genome.gtfStep 2: Align to Reference Genome
The next step is to generate a count matrix by pseudoaligning the reads to your reference index using the kb count command. For example, suppose you have two paired-end FASTQ files (read1.fastq and read2.fastq) from a 10x Chromium Next GEM v3 library.
Note that this section is only applicable to single cell data. Applying kb count to bulk data looks slightly different. If you would like to learn how to use kb count to pseudoalign bulk RNA-seq reads, refer to our Bulk RNA-seq tutorial.
For the standard workflow, you can perform pseudoalignment with:
kb count -i index_file.idx -g t2g_file.txt -x 10XV3 \
-o output_dir read1.fastq read2.fastqand for the nascent workflow,
kb count --workflow=nac -i index_file.idx -g t2g_file.txt -c1 cdna.txt \
-c2 nascent.txt -x 10XV3 -o output_dir read1.fastq read2.fastqwhere output_dir is the folder where you wish the results of kb_count to be stored.
FASTQ files are the standard format for storing raw sequencing reads from next-generation sequencing instruments. Each read in a FASTQ file is represented by four lines:
@SEQ_ID
GATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT
+
!''*((((***+))%%%++)(%%%%).1***-+*''))**55CCF>>>>>>CCCCCCC65Line 1 – Read identifier (begins with @)
Line 2 – Nucleotide sequence
Line 3 – Separator line (usually just +)
Line 4 – Quality scores for each base (encoded as ASCII characters)
kb count accepts both raw and gzipped FASTQ files. If your reads are stored in another file format, you will have to convert to FASTQ before pseudoalignment with kb-python.
Change -x 10XV3 according to the specific technology you used to generate your library.
- 10X Chromium GEM-X V4:
-x 10XV4 - Parse Evercode WT v2:
-x SPLIT-SEQ
To see a complete list of technologies and their corresponding technology strings, type kb --list into your terminal.
Batch Pseudoalignment
In most scRNA-seq experiments, you will have multiple samples, each with its own pair of FASTQ files. Instead of running kb count separately on every sample, kb-python allows you to process many samples in a single command using the --batch-barcodes flag.
To perform a batch pseudoalignment, run:
kb count ... --batch-barcodes batch.txtfilling in the command with the parameters specific to your experiment. The batch.txt file must be a space-separated file, with one row per sample. Each row should contain:
sample_name read1.fastq.gz read2.fastq.gz— that is, the name of the sample followed by the paths to its Read 1 and Read 2 FASTQ files.
kb-python will automatically process each sample independently and prepend a unique, artificially generated sample-specific barcode to the beginning of every cell barcode. This ensures that cell barcodes from different samples remain distinguishable in the combined output without altering the underlying cellular barcodes themselves.
A list of these sample-specific barcode prefixes is saved in counts_unfiltered/cells_x_genes.barcodes.prefix.txt, which maps each cell barcode to its corresponding sample barcode.
Parse Evercode WT v3: Using a Custom Specification
Currently, kb-python does not include a built-in specification for the Parse Evercode WT v3 chemistry. To pseudoalign Parse v3 data, you must manually specify the assay configuration by providing:
v3_onlist.txt — a list of valid cell barcodes
a technology string defining barcode positions within the read:
-x "1,10,18,1,30,38,1,50,58:1,0,10:0,0,0"the orientation of the first read (R1) relative to your library specification:
--strand=forwardthe read parity (
pairedif both paired-end reads contain the biological sequence andsingleotherwise):--parity=single
Then, run:
kb count --h5ad --strand=forward --parity=single \
-w v3_onlist.txt -x "1,10,18,1,30,38,1,50,58:1,0,10:0,0,0" \
-g t2g.txt -i index.idx R1.fastq.gz R2.fastq.gzParse Evercode WT: Substituting Barcodes with the -r Argument
The Parse Evercode WT chemistry is unique in that each cell has two cell-specific barcodes rather than one. Since kb-python expects a single barcode per cell, you must collapse barcode pairs before pseudoalignment. This is done using the -r argument in kb count, for example:
kb count -r <replace_file> ...where <replace_file> is a TSV file with two columns:
Column 1: barcodes to be replaced
Column 2: corresponding replacement barcodes
You can download:
When using -r to specify a replacement list in kb count, two count matrices will be produced: one with the original barcodes (stored in the output file counts_unfiltered) and one with the replacement barcodes (stored in the output file counts_unfiltered_modified).
Validating Pseudoalignment with the run_info.json file
When you run kallisto through kb-python, it generates a file called run_info.json. This file summarizes essential metrics from the pseudoalignment step and helps you verify that your reads were successfully mapped to the reference transcriptome. Although it is a small file, it contains several important fields that give a quick indication of alignment quality and potential issues with your input data, reference files, or library chemistry.
Key Metrics to Evaluate
n_processedThis value reports the total number of reads (or read pairs) that kallisto attempted to pseudoalign. It should match your expectation based on the number of reads in your FASTQ files. A much smaller number than expected usually indicates truncated FASTQ files, incorrect file paths, corrupted input, or an early pipeline failure.
p_pseudoalignedThis is the fraction of reads that successfully pseudoaligned (
n_pseudoaligned/n_processed). It is the most important single metric. Typical expectations:- Bulk RNA-seq: often >80–90%
- scRNA-seq (10x): usually 60–90%
- Multiome or non-standard assays: more variable
Very low values (e.g., <30%) almost always indicate a mismatch between your reference and your reads rather than a biological issue.
p_uniqueThis value reports the fraction of reads that pseudoaligned uniquely to a single transcript rather than mapping to multiple possible targets. For most scRNA-seq datasets, a value above 20% is expected, though this depends heavily on the organism, assay, and read length; in some cases, values as low as 10% can still be normal.
A low
p_uniquecan occur when:- many transcripts share highly similar sequences (e.g., paralogs, pseudogenes),
- the reference is incomplete or poorly annotated,
- reads are too short or low-quality,
- adapters or barcodes were not properly trimmed,
- a high percentage of the reads originate from ribosomal RNA.
While
p_pseudoalignedtells you how many reads mapped at all,p_uniquetells you how confidently kallisto could assign those reads.Runtime informationFields like
start_time,end_time, and sometimes call help you confirm that kallisto completed successfully and show exactly what command was executed.
Next Steps
After generating your count matrix, you can import it into analysis tools such as Scanpy, Seurat, or Bioconductor for downstream processing, clustering, and visualization.