Single-cell RNA and ATAC pseudobulk
The tutorials target the JBrowse v5 beta, and the v4.3.0 release
on the download page lacks some of what they show. To install the
beta of JBrowse Web, run npm install -g @jbrowse/cli@next, then
jbrowse create jbrowse2 --branch v5.0.0-beta.21. Desktop beta builds for Linux and
macOS are on the releases page;
the Windows build waits on code signing.
Pooled per single-cell cluster (pseudobulking) and placed on the genome, the reads show which cell types express a marker gene and where in the gene the reads fall. Single-cell ATAC fragments pooled the same way give one chromatin accessibility profile per cell type. With two separate 10x releases of peripheral blood cells (PBMC), one RNA and one ATAC, we:
- pool RNA reads or ATAC fragments into one coverage BigWig per cell type, outside JBrowse
- load each set as one multi-wiggle track with a row per cell type
- open nine RNA marker genes side by side
- add one row per cell under the pooled RNA rows, from a Zarr store
- read the ATAC rows at a T-cell and a B-cell marker
Prerequisites
- for RNA, cells already clustered and labeled, plus the barcoded BAM the counts
came from (Cell Ranger's
possorted_genome_bam.bam, or any BAM with a corrected cell-barcode tag) - for ATAC, cells already clustered and labeled, as a fragments file or a
barcoded BAM plus a barcode-to-label table, or as the project object your
analysis tool already holds, an
AnnDatain SnapATAC2 (Python), anArchRProjectin ArchR, or a Seurat/Signac object in R - the pooling tool that matches what you have:
bedGraphToBigWigfrom the UCSC utilities,pip install deeptools sintoplussamtoolsfor the split-the-BAM route, orpip install snapatac2(ArchR and Signac install from R). The RNA reproduce script bins the reads itself, so it needsbedGraphToBigWigbut neither deepTools nor sinto - a JBrowse instance to load the finished BigWigs into (see the web quickstart or the desktop quickstart)
- the zarr plugin, for the Zarr store. In your own JBrowse, load it by the URL that section gives
# Debian/Ubuntu
sudo apt install nodejs
# or conda, which has every tool above
conda install -c bioconda -c conda-forge ucsc-bedgraphtobigwig nodejs
# or Linux x86_64 binaries for the tools apt lacks
wget -P ~/.local/bin \
https://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/bedGraphToBigWig
chmod +x ~/.local/bin/bedGraphToBigWigThe data
10x Genomics' 5k PBMC v3 RNA experiment, which the RNA build script streams and pools by cell type without writing the BAM to disk, and SnapATAC2's annotated release of 10x's 5k PBMC scATAC experiment, already clustered and cell-type-labeled.
You don't need these files to follow the page: every track reads a hosted copy of what the commands below write, and the per-cell track's config points at the Zarr store the RNA build script makes, with the hosted copy's URL beside it. The build scripts fetch everything themselves; the ATAC one downloads the dataset through SnapATAC2 (about 800 MB, ten minutes). To generate per-cell-type BigWigs, supply your own barcoded BAM or fragments file and barcode table.
| What it is | File |
|---|---|
| The barcoded RNA alignments, streamed and never downloaded | 5k_pbmc_v3_possorted_genome_bam.bam |
| The filtered feature-barcode matrix the RNA clustering runs on | 5k_pbmc_v3_filtered_feature_bc_matrix.h5 |
The annotated ATAC AnnData that snap.datasets.pbmc5k(type="annotated_h5ad") downloads and caches |
snapatac2.datasets.pbmc5k.html |
Read by URL (no download needed)
| What it is | File |
|---|---|
| CATlas' published hg38 per-cell-type accessibility BigWigs | bw/ |
Loading GRCh38
The RNA reads and the ATAC fragments were both aligned to GRCh38, and the
BigWigs inherit its chr1-style chromosome names, so the tracks go on an hg38
assembly that spells them the same way. A BigWig whose names differ from the
assembly's, such as Ensembl's 1 against chr1, draws empty unless the
assembly has a name-alias table.
Goes in the assemblies array of config.json. See Assemblies.
{
"name": "hg38",
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz",
"refNameAliases": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt"
},
"cytobands": "https://jbrowse.org/genomes/GRCh38/cytoBand.txt"
}Edits config.json in the current folder, creating it if there is none. See JBrowse CLI with Desktop.
jbrowse add-assembly https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz \
--name hg38 \
--refNameAliases https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt \
--config '{"cytobands":"https://jbrowse.org/genomes/GRCh38/cytoBand.txt"}'hg38 is one of the genomes JBrowse Desktop hosts, with gene tracks already set up: on the start screen click Browse hosted genomes and pick it. To load the files of this config instead:
In JBrowse Desktop, Open your own genome on the start screen (or File → Open genome... in a session), then Open from a URL and paste, one per line:
https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz
https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.fai
https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.gziJBrowse reads the format off the file name. Then fill in:
- Genome name:
hg38 - refName aliases (under More options):
https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt - cytobands (under More options):
https://jbrowse.org/genomes/GRCh38/cytoBand.txt
The RNA figures show NCBI's RefSeq genes as a track:
Goes in the tracks array of config.json. See Tracks.
{
"trackId": "ncbi_refseq_hg38",
"name": "NCBI RefSeq genes",
"type": "FeatureTrack",
"assemblyNames": ["hg38"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/ucsc/hg38/ncbiRefSeq.gff.gz",
"csi": true
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"trackId": "ncbi_refseq_hg38",
"name": "NCBI RefSeq genes",
"type": "FeatureTrack",
"assemblyNames": ["hg38"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/ucsc/hg38/ncbiRefSeq.gff.gz",
"csi": true
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"trackId": "ncbi_refseq_hg38",
"name": "NCBI RefSeq genes",
"type": "FeatureTrack",
"assemblyNames": ["hg38"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/ucsc/hg38/ncbiRefSeq.gff.gz",
"csi": true
}
}The ATAC figure reads the same genes from NCBI's own RefSeq GFF3:
Goes in the tracks array of config.json. See Tracks.
{
"trackId": "ncbi_refseq_109_hg38_latest",
"name": "NCBI RefSeq (GFF3Tabix)",
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz",
"assemblyNames": ["hg38"]
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz \
--trackId ncbi_refseq_109_hg38_latest \
--name "NCBI RefSeq (GFF3Tabix)" \
--assemblyNames hg38In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track... and, in Add a track from file or URL, enter:
- Main file:
https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz
JBrowse reads the adapter and track type off the file name. Then fill in:
- Track name:
NCBI RefSeq (GFF3Tabix) - Assembly:
hg38
Click Add.
Generating per-cell-type BigWigs
Clustering and labeling happen upstream, in Seurat, scanpy, Cell Ranger ATAC,
ArchR, Signac or SnapATAC2. Each route below starts from a barcode-to-label
table or a labeled object and ends at one .bw per cell type, which JBrowse
stacks as rows of one track.1
From a barcoded RNA BAM
Three decisions determine whether the rows can be compared:
- Duplicates and multimappers. Cell Ranger flags PCR duplicates of the same
UMI (unique molecular identifier) with
0x400; filter them out so a row's height tracks expression. Restricting to uniquely mapped reads (MAPQ255, what STAR emits inside Cell Ranger) keeps multimappers off paralogs - Normalization. Cell types differ in cell count and depth, so each pooled track needs scaling (CPM is usual) before rows can be compared by height
- Splice-aware coverage. A read spanning an intron has an
Nin its CIGAR, and counting that as covered fills in introns no read touched
One route splits the BAM by label with
sinto filterbarcodes and
runs
bamCoverage
on each output:
# barcodes.tsv is two columns: cell barcode, cell-type label
sinto filterbarcodes -b possorted_genome_bam.bam -c barcodes.tsv -p 8
for bam in *.bam; do
samtools index "$bam"
# --samFlagExclude 1024 drops PCR duplicates; --minMappingQuality 255 keeps
# only unique alignments; --normalizeUsing CPM scales so one cell type's
# row compares with another's
bamCoverage -b "$bam" -o "${bam%.bam}.bw" \
--samFlagExclude 1024 --minMappingQuality 255 --normalizeUsing CPM
doneThe sinto route writes a second copy of the BAM to disk, split N ways;
build_scrna_pseudobulk.sh
instead reads the BAM by region over HTTPS, accumulating each cell type's
coverage in one pass with no download, split or scratch space. Either route
applies the normalization in its last step:
# CPM: scale by 1e6 / this cell type's own read total, so a row from 200 cells
# compares with one from 2,000
awk -v total="$reads" -v OFS='\t' \
'{print $1, $2, $3, $4 * 1e6 / total}' celltype.bg > celltype.cpm.bg
# chromosomes in chrom.sizes order, which for UCSC names is lexicographic
# (chr1, chr10, ... chr2) and not the order reads stream in
bedGraphToBigWig celltype.cpm.bg hg38.chrom.sizes celltype.bwThe script fills one row per cell type in one pass over each chromosome:
# of_barcode maps a corrected cell barcode to its cell type's row index
bam = pysam.AlignmentFile(BAM, "rb", index_filename=bai)
length = bam.get_reference_length(chrom)
cov = np.zeros((len(types), length // BIN + 1), dtype=np.uint32)
for read in bam.fetch(chrom):
# 0x400 is the duplicate flag, 0x100 secondary and 0x800 supplementary. The
# first is the duplicate decision; the other two stop one read landing in
# several places at once. STAR emits MAPQ 255 for a unique alignment, the
# only kind CellRanger writes.
if read.flag & SKIP_FLAGS or read.mapping_quality < MIN_MAPQ:
continue
try:
t = of_barcode[read.get_tag("CB")]
except KeyError:
continue # a cell the labeling dropped, or an uncorrected barcode
# get_blocks splits the read at every N in its CIGAR, so an intron the read
# spans stays a gap instead of filling in
for start, end in read.get_blocks():
cov[t][start // BIN : (end - 1) // BIN + 1] += 1The last step converts each row's bedGraph:
bedGraphToBigWig CD8_T.all.bg hg38.chrom.sizes bw/CD8_T.bwFrom ATAC fragments
One ATAC cell contributes a few thousand fragments, so a single cell's coverage is almost entirely zero, and pooling a cluster's cells gives a profile with peaks. Normalization matters as it does for RNA, since groups differ in cell count and total fragments. The bin size trades resolution against file size and has to stay well inside one peak.
SnapATAC2's export_coverage splits cells by a metadata column and writes one
normalized BigWig per group in a single call:
import snapatac2 as snap
# adata: an AnnData with fragments imported and a cell-type/cluster label in obs
snap.ex.export_coverage(
adata,
groupby="cell_type", # column in adata.obs to split on
bin_size=25, # bp per bin
normalization="RPKM", # comparable across groups
out_dir="bw",
suffix=".bw",
n_jobs=2, # each worker holds a genome-wide coverage vector
# blacklist= takes an ENCODE blacklist BED and drops those intervals from
# every group. The build script does not pass it, so the figures below are
# unmasked coverage.
)
# writes bw/<cell_type>.bw, one per group, keyed by group in the returned dictToo many n_jobs workers exhaust memory and fail the writer partway through the
groups. groupby="leiden" gives one BigWig per cluster instead.
The other ATAC tools write the same files:
- An
ArchRProject:getGroupBW(groupBy = "CellType", tileSize = 25)writes one BigWig per group.normMethod = "ReadsInTSS"normalizes by signal-in-TSS;"nCells"and"nFrags"are the alternatives - A barcoded ATAC BAM (Cell Ranger ATAC, or a Signac workflow's input):
split it with
sinto filterbarcodesas for RNA, then runbamCoverageon each with--binSize 25 --normalizeUsing CPM --extendReads.RPGCalso needs--effectiveGenomeSize - A
fragments.tsv.gzalone: filter it to each cluster's barcodes, thenbedtools genomecov -bgandbedGraphToBigWigper group. This route is unnormalized, so scale each group yourself (1e6 / total fragments for CPM) before the conversion
Loading the per-cell-type BigWigs as one track
One MultiQuantitativeTrack holds the set, one BigWigAdapter subadapter per
cell type with its name, color, and group. The fence lists the first RNA
rows in the figure below; the build script writes all of them, and the hosted
config, https://jbrowse.org/code/jb2/main/test_data/scrna_pbmc5k/config.json,
has them as pbmc5k_scrna_pseudobulk_hg38. Swap each uri for a BigWig your
pooling step wrote:
Goes in the tracks array of config.json. See Tracks.
{
"type": "MultiQuantitativeTrack",
"trackId": "pbmc5k_scrna_pseudobulk",
"name": "scRNA pseudobulk by cell type (10x 5k PBMC)",
"category": ["Single cell", "Expression"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD4 T",
"group": "T cell",
"color": "#1f77b4",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD4_T.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 T",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD8_T.bw"
},
{
"type": "BigWigAdapter",
"name": "CD14 Mono",
"group": "Monocyte",
"color": "#8c564b",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD14_Mono.bw"
}
]
},
"displayDefaults": {
"mark": "bar",
"encoding": {
"y": {
"scale": { "type": "log", "domainMin": 1 },
"axis": { "title": "CPM" }
}
},
"height": 330
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "MultiQuantitativeTrack",
"trackId": "pbmc5k_scrna_pseudobulk",
"name": "scRNA pseudobulk by cell type (10x 5k PBMC)",
"category": ["Single cell", "Expression"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD4 T",
"group": "T cell",
"color": "#1f77b4",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD4_T.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 T",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD8_T.bw"
},
{
"type": "BigWigAdapter",
"name": "CD14 Mono",
"group": "Monocyte",
"color": "#8c564b",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD14_Mono.bw"
}
]
},
"displayDefaults": {
"mark": "bar",
"encoding": {
"y": {
"scale": { "type": "log", "domainMin": 1 },
"axis": { "title": "CPM" }
}
},
"height": 330
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "MultiQuantitativeTrack",
"trackId": "pbmc5k_scrna_pseudobulk",
"name": "scRNA pseudobulk by cell type (10x 5k PBMC)",
"category": ["Single cell", "Expression"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD4 T",
"group": "T cell",
"color": "#1f77b4",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD4_T.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 T",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD8_T.bw"
},
{
"type": "BigWigAdapter",
"name": "CD14 Mono",
"group": "Monocyte",
"color": "#8c564b",
"uri": "https://jbrowse.org/demos/scrna_pbmc5k/CD14_Mono.bw"
}
]
},
"displayDefaults": {
"mark": "bar",
"encoding": {
"y": {
"scale": { "type": "log", "domainMin": 1 },
"axis": { "title": "CPM" }
}
},
"height": 330
}
}In grammar-of-graphics terms, a
mark is the shape drawn and
encoding.y is the y scale. bar compares peak shape, and rect, which the
track menu switches to, maps score to color and fits more rows. The rows share
one axis, and its log type, floored at 1 CPM by domainMin, keeps a dim row
readable beside a bright one such as LYZ in monocytes.
Set three things in the subadapters list from the single-cell object:
- the order: subadapters draw in the order given, so group them by lineage
color: copy the cluster color from your analysis, so a cell type matches its UMAP colorgroup: the sidebar tree branches on it, and Clustering rows clusters rows within each group
Building the track from a list of BigWigs
Without per-row names, colors or groups, the bigWigs shorthand takes a plain
array of URLs and labels each row from its filename:
Goes in the tracks array of config.json. See Tracks.
{
"type": "MultiQuantitativeTrack",
"trackId": "scrna_pseudobulk_simple",
"name": "scRNA pseudobulk",
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"bigWigs": [
"https://jbrowse.org/demos/scrna_pbmc5k/CD4_T.bw",
"https://jbrowse.org/demos/scrna_pbmc5k/CD8_T.bw",
"https://jbrowse.org/demos/scrna_pbmc5k/CD14_Mono.bw"
]
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "MultiQuantitativeTrack",
"trackId": "scrna_pseudobulk_simple",
"name": "scRNA pseudobulk",
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"bigWigs": [
"https://jbrowse.org/demos/scrna_pbmc5k/CD4_T.bw",
"https://jbrowse.org/demos/scrna_pbmc5k/CD8_T.bw",
"https://jbrowse.org/demos/scrna_pbmc5k/CD14_Mono.bw"
]
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "MultiQuantitativeTrack",
"trackId": "scrna_pseudobulk_simple",
"name": "scRNA pseudobulk",
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"bigWigs": [
"https://jbrowse.org/demos/scrna_pbmc5k/CD4_T.bw",
"https://jbrowse.org/demos/scrna_pbmc5k/CD8_T.bw",
"https://jbrowse.org/demos/scrna_pbmc5k/CD14_Mono.bw"
]
}
}Two workflows write the list from a set of files:
- Add multi-row track, in the Add track workflow, takes BigWig URLs one
per line, or a JSON array of subadapter objects. On JBrowse Desktop it reads
local
.bwfiles directly, and the same form stacks BED or BigBed files, one row of features per file. Exporting the session gets the JSON config back out jbrowse add-track --multiwigtakes the whole set of BigWigs in place of the single positional file, labeling rows from the filenames, as in the command below
jbrowse add-track --multiwig "$(find bw -name '*.bw' | sort | paste -sd,)" \
--name "Pseudobulk by cell type" --assemblyNames hg38 \
--load copy --subDir bw --out /var/www/html/jbrowse2--load copy --subDir bw copies local files in beside config.json; leave both
off for BigWigs already served over HTTP. For per-row names, colors and groups,
pass a .json file of subadapter objects instead of the comma list.
RNA marker genes side by side
We named the RNA clusters by scoring them against marker panels, so those markers have signal in the rows of their cell types by construction. To test the labels, we open nine markers the panels leave out, one per cell type: CD40LG, LINC02446, SPON2, CD22, S100A12, HES4, ENHO, LRRC26 and GNG11. 10x 3' kits sequence the 3' end of each transcript, so coverage is a spike near the polyadenylation site. Paste each gene's 3' end into the location box to open them side by side:
chrX:136,658,390-136,662,390 chr12:10,556,794-10,560,794 chr4:1,164,931-1,168,931 chr19:35,345,361-35,349,361 chr1:153,371,710-153,375,710 chr1:996,963-1,000,963 chr9:34,519,042-34,523,042 chr9:137,166,757-137,170,757 chr7:93,926,610-93,930,610Per-cell coverage rows from a Zarr store
A pseudobulk RNA row sums thousands of cells. A Zarr store holding a cells-by-bins coverage matrix adds the cells themselves, one row each, under the pooled rows.
The MultiWiggleZarrAdapter from
jbrowse-plugin-zarr reads
the store, the same adapter CNV across a population (1000 Genomes) uses for the 1000
Genomes panel. The build step writes the cell list, bin size and row colors as
attributes of the store. Install Zarr from the
plugin store, or name it in config.json:
{
"plugins": [{ "storePlugin": "Zarr" }]
}With the plugin loaded, the store is one track. The figure reads the hosted
store, https://jbrowse.org/demos/scrna_pbmc5k/percell.zarr, a directory of
chunks that 404s at its root but loads as a uri. For your own cells, uri
points at a store with the same layout, built by the reproduce script below:
Goes in the tracks array of config.json. See Tracks.
{
"type": "MultiQuantitativeTrack",
"trackId": "pbmc5k_scrna_percell_hg38",
"name": "Per-cell coverage (marker loci)",
"category": ["Single cell"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleZarrAdapter",
"uri": "percell.zarr"
},
"displayDefaults": {
"mark": "rect",
"encoding": { "y": { "scale": { "domainMin": 0, "domainMax": 2 } } },
"height": 420
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "MultiQuantitativeTrack",
"trackId": "pbmc5k_scrna_percell_hg38",
"name": "Per-cell coverage (marker loci)",
"category": ["Single cell"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleZarrAdapter",
"uri": "percell.zarr"
},
"displayDefaults": {
"mark": "rect",
"encoding": { "y": { "scale": { "domainMin": 0, "domainMax": 2 } } },
"height": 420
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "MultiQuantitativeTrack",
"trackId": "pbmc5k_scrna_percell_hg38",
"name": "Per-cell coverage (marker loci)",
"category": ["Single cell"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleZarrAdapter",
"uri": "percell.zarr"
},
"displayDefaults": {
"mark": "rect",
"encoding": { "y": { "scale": { "domainMin": 0, "domainMax": 2 } } },
"height": 420
}
}percell.zarr is relative to a config.json. Replace it with its URL or its path on this computer.
A relative uri resolves against the config that holds it, so the store is
served as static files beside config.json.
The store covers the marker windows, where the cells have reads, which keeps it small. The lookup is by chromosome name, so the build script picks one marker per chromosome.
Type chr12:69,353,000-69,354,500 into the location box, the 3' end of LYZ,
where the 3' kit's reads land:
Per cell, many lymphocytes have a single UMI of a monocyte gene, ambient RNA that was free in the droplet.
Two settings decide whether those single-UMI cells are visible:
- Order the rows by cell type. Thousands of rows in a few hundred pixels is
under a pixel each, so a block is visible only if its cells are adjacent. The
groupeach cell has in the store's attributes sets that order and the sidebar tree - Pin the score axis. A low
domainMaxputs one UMI a visible fraction up the color ramp, whereas autoscale takes its maximum from the tallest single cell in view
ATAC accessibility at a T-cell and a B-cell marker
The ATAC BigWigs written under From ATAC fragments load the same way, as a
second track. The fence lists some of the cell types the figure draws; the
ATAC build script writes the whole list, and the
hosted demo config,
https://jbrowse.org/code/jb2/main/test_data/config_demo.json, has it as
pbmc5k_scatac_pseudobulk_hg38:
Goes in the tracks array of config.json. See Tracks.
{
"type": "MultiQuantitativeTrack",
"trackId": "scatac_pseudobulk",
"name": "scATAC by cell type",
"category": ["Single cell", "Chromatin accessibility"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#4363d8",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#3cb44b",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#f58231",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/Naive_B.bw"
}
]
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "MultiQuantitativeTrack",
"trackId": "scatac_pseudobulk",
"name": "scATAC by cell type",
"category": ["Single cell", "Chromatin accessibility"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#4363d8",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#3cb44b",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#f58231",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/Naive_B.bw"
}
]
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "MultiQuantitativeTrack",
"trackId": "scatac_pseudobulk",
"name": "scATAC by cell type",
"category": ["Single cell", "Chromatin accessibility"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#4363d8",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#3cb44b",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#f58231",
"uri": "https://jbrowse.org/demos/scatac_pbmc5k/Naive_B.bw"
}
]
}
}At CD8A the CD8 T, MAIT and NK rows carry the peaks and the B rows stay near flat, and at MS4A1 the B rows carry them and the T rows stay near flat. Paste both into the location box to open them side by side:
chr2:86,780,000-86,820,000 chr11:60,450,000-60,490,000CATlas serves hg38 per-cell-type accessibility, one
file per cell type, from
https://decoder-genetics.wustl.edu/catlasv1/humanenhancer/data/bw/; its URLs
go into the subadapters list like the PBMC files. Percent-encode the + in a
cell-type name (T_lymphocyte_2_CD4%2B.bw); left unencoded, the URL breaks and
the row loads with no data.
Reproduce it end to end
build_scrna_pseudobulk.sh
starts from 10x's filtered RNA count matrix and the BAM. It:
- clusters the cells with the standard scanpy pipeline: quality filtering, normalization, PCA, a neighbor graph, the UMAP and Leiden clusters
- names each cluster after the canonical PBMC marker panel it scores highest on, and prints the whole score matrix so each call can be checked. A cluster that scores weakly against every panel stays unassigned
- pools each cell type's reads into one row, with the filters and CPM scaling above
- writes the per-cell store over the marker windows, the UMAP's data files, and a JBrowse instance with the pooled track
curl -fO https://raw.githubusercontent.com/GMOD/jbrowse-components/main/scripts/build_scrna_pseudobulk.sh
bash build_scrna_pseudobulk.sh # builds ./scrna_pseudobulk_build
npx --yes serve scrna_pseudobulk_build/jbrowse2build_scatac_pseudobulk.sh
starts from SnapATAC2's annotated release of the 10x 5k PBMC ATAC dataset, whose
standard pipeline and
cell-type annotation
tutorials leave every cell filtered, clustered and labeled, with its fragments
beside its cell_type. The script:
- pools each cell type's fragments into one BigWig, in 25 bp bins and RPKM, as above
- orders the rows by lineage (T cells, NK, B cells, then myeloid) from a map written into the script, because the label order stored in the object puts the rows of one lineage far apart. To run it on your own experiment, replace that map
- gives each row its cluster's color from the same object, so a cell type matches its UMAP
- loads the set as one track over hg38 and RefSeq genes
curl -fO https://raw.githubusercontent.com/GMOD/jbrowse-components/main/scripts/build_scatac_pseudobulk.sh
bash build_scatac_pseudobulk.sh # builds ./scatac_pseudobulk_build
npx --yes serve scatac_pseudobulk_build/jbrowse2Rows that stay open everywhere usually mean the normalization step was skipped, since an unnormalized group's height tracks its cell count.
See also
- Tutorial: RNA-seq visualization
- Tutorial: ChromHMM chromatin states
- User guide: Clustering rows
- Config guide: Quantitative track
- Reference: MultiWiggleAdapter
- Reference: LinearWiggleDisplay
External links
- 10x Genomics 5k PBMC v3, the RNA dataset this page pseudobulks
- SnapATAC2's 5k PBMC scATAC dataset, the 10x Genomics ATAC experiment this page pseudobulks, in its clustered and cell-type-annotated form
- scanpy's clustering tutorial, the pipeline the RNA build script follows
- SnapATAC2
export_coverage - ArchR: exporting pseudobulk BigWigs (
getGroupBW) - sinto
filterbarcodesand deepToolsbamCoveragefor the split-the-BAM route, and deepTools' normalization methods
Citations
- Zhang et al. (2021). A single-cell atlas of chromatin accessibility in the human genome, and its resource portal, the published atlas a track reads without building anything
Notes
-
The BigWigs can also be viewed inline from the clustering environment through the Python anywidget interface or JBrowseR. ↩
Feedback on this tutorial is welcome: contact us.