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.23. Desktop beta builds for Linux and
macOS are on the releases page;
the Windows build waits on code signing.
Reads pooled per single-cell cluster (pseudobulking) and placed on the genome 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, and open RNA marker genes side by side
- add one row per cell under the pooled RNA rows, from a Zarr store, and embed both tracks in a web page under the UMAP of the same cells
- read the ATAC rows at a T-cell and a B-cell marker, then load AlphaGenome 2's predicted ATAC for the same cell types under them
- load a plain list of BigWigs as one track, without names, colors or groups
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. 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/ |
Load the GRCh38 assembly
The RNA reads and the ATAC fragments were both aligned to GRCh38, and the
BigWigs use its chr1-style chromosome names, so the tracks go on an hg38
assembly that spells them the same way. JBrowse draws a BigWig empty when its
names differ from the assembly's, such as Ensembl's 1 against chr1, unless
the assembly has a name-alias table.
genomes.jbrowse.org hosts hg38, and this page's hg38 tracks attach to it by that name. The other tabs build the same assembly from its files.
- In JBrowse Desktop, click hg38 on the start screen, or launch
jbrowse-desktop --genome hg38. - On the web, open hg38 on genomes.jbrowse.org.
- In your own JBrowse Web,
jbrowse add-assembly --genome hg38adds it to theconfig.jsonin the current folder.
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.
Pool reads into one BigWig per cell type
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. A larger bin gives a smaller file at a lower resolution, and the bin 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 dictWith too many n_jobs workers, the writer runs out of memory and fails 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
Load the RNA rows
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: JBrowse draws the subadapters 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
Marker genes, one per cell type, open side by side: 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. Type each gene's 3' end into the location box:
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,610Add one row per cell 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:
Set two things for the per-cell rows:
- 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
Show both tracks under the UMAP in a web page
A web page of your own can mount the view under the UMAP of the same cells. Open
the
single-cell UMAP example,
which mounts @jbrowse/react-linear-genome-view2 at MS4A1 with the pooled and
per-cell RNA tracks open:
The page draws the UMAP itself, on a canvas, from two files hosted beside the BigWigs:
cells.jsonlists each cell's UMAP position and cell type, each cell type's name, group and color, and the genes the UMAP can be colored by with their locationsexpr.binholds each cell's expression of those genes, scaled to each gene's maximum
Click clusters or legend swatches to narrow the pooled track to those cell types, and click one again to drop it. The per-cell rows stay as they are. The page hands the clicked names to the pooled track's display:
function pickCellType(name: string) {
const next = selected.includes(name)
? selected.filter(t => t !== name)
: [...selected, name]
setSelected(next)
const display = view.getTrack(TRACK_ID)?.activeDisplay as
| WiggleDisplayModel
| undefined
display?.setRowFocus(next.length ? next : undefined)
}Clicking a gene in the view that cells.json lists, or choosing one in the
page's select, colors the cells by its expression. The select also moves the
view to the gene. The whole page is
one file.
Load the ATAC rows
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"
}
]
}
}Type both into the location box to open CD8A and MS4A1 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.
Load predicted ATAC under the measured rows
AlphaGenome 2 predicts scATAC from sequence for blood cell types that match each of the ATAC labels, so its predictions load as a second track with the same rows. The build script on AlphaGenome 2 predictions by cell type writes one BigWig per cell type over the PBMC marker loci, and maps each label to the blood condition of the same cell type that AlphaGenome 2 has measured scATAC for. The predicted track takes the measured track's names, colors and groups:
Goes in the tracks array of config.json. See Tracks.
{
"type": "MultiQuantitativeTrack",
"trackId": "ag2_pbmc_scatac_predicted",
"name": "AlphaGenome 2 predicted scATAC, PBMC cell types (marker loci)",
"category": ["Single cell", "Chromatin accessibility"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#d62728",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#aec7e8",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/Naive_B.bw"
}
]
},
"displayDefaults": { "mark": "bar", "height": 300 }
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "MultiQuantitativeTrack",
"trackId": "ag2_pbmc_scatac_predicted",
"name": "AlphaGenome 2 predicted scATAC, PBMC cell types (marker loci)",
"category": ["Single cell", "Chromatin accessibility"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#d62728",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#aec7e8",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/Naive_B.bw"
}
]
},
"displayDefaults": { "mark": "bar", "height": 300 }
}'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": "ag2_pbmc_scatac_predicted",
"name": "AlphaGenome 2 predicted scATAC, PBMC cell types (marker loci)",
"category": ["Single cell", "Chromatin accessibility"],
"assemblyNames": ["hg38"],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#d62728",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#aec7e8",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/Naive_B.bw"
}
]
},
"displayDefaults": { "mark": "bar", "height": 300 }
}Open this track in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fucsc%2Fhg38%2Fconfig.json&session=spec-%7B%22sessionTracks%22%3A%5B%7B%22type%22%3A%22MultiQuantitativeTrack%22%2C%22trackId%22%3A%22ag2_pbmc_scatac_predicted%22%2C%22name%22%3A%22AlphaGenome+2+predicted+scATAC%2C+PBMC+cell+types+%28marker+loci%29%22%2C%22category%22%3A%5B%22Single+cell%22%2C%22Chromatin+accessibility%22%5D%2C%22assemblyNames%22%3A%5B%22hg38%22%5D%2C%22adapter%22%3A%7B%22type%22%3A%22MultiWiggleAdapter%22%2C%22subadapters%22%3A%5B%7B%22type%22%3A%22BigWigAdapter%22%2C%22name%22%3A%22CD8+Naive%22%2C%22group%22%3A%22T+cell%22%2C%22color%22%3A%22%23d62728%22%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Falphagenome2_singlecell%2Fpbmc%2FCD8_Naive.bw%22%7D%2C%7B%22type%22%3A%22BigWigAdapter%22%2C%22name%22%3A%22CD8+Memory%22%2C%22group%22%3A%22T+cell%22%2C%22color%22%3A%22%23279e68%22%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Falphagenome2_singlecell%2Fpbmc%2FCD8_Memory.bw%22%7D%2C%7B%22type%22%3A%22BigWigAdapter%22%2C%22name%22%3A%22Naive+B%22%2C%22group%22%3A%22B+cell%22%2C%22color%22%3A%22%23aec7e8%22%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Falphagenome2_singlecell%2Fpbmc%2FNaive_B.bw%22%7D%5D%7D%2C%22displayDefaults%22%3A%7B%22mark%22%3A%22bar%22%2C%22height%22%3A300%7D%7D%5D%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg38%22%2C%22loc%22%3A%22chr2%3A86%2C780%2C000..86%2C820%2C000%22%2C%22tracks%22%3A%5B%22ag2_pbmc_scatac_predicted%22%5D%7D%5D%7D&sessionName=JBrowse+docs%3A+AlphaGenome+2+predicted+scATAC%2C+PBMC+cell+types+%28marker+loci%29This view in a notebook, with jbrowse-anywidget. Swap a track's uri for your file.
from jbrowse_anywidget import JBrowseApp, fetch_hub
config = fetch_hub("https://jbrowse.org/ucsc/hg38/config.json")
app = JBrowseApp(
assemblies=config["assemblies"],
tracks=config.get("tracks", []) + [
{
"type": "MultiQuantitativeTrack",
"trackId": "ag2_pbmc_scatac_predicted",
"name": "AlphaGenome 2 predicted scATAC, PBMC cell types (marker loci)",
"category": [
"Single cell",
"Chromatin accessibility"
],
"assemblyNames": [
"hg38"
],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#d62728",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#aec7e8",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/Naive_B.bw"
}
]
},
"displayDefaults": {
"mark": "bar",
"height": 300
}
}
],
views=[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr2:86,780,000..86,820,000",
"tracks": [
"ag2_pbmc_scatac_predicted"
]
}
],
)
app # display the widgetThis view in your React 19 app, with @jbrowse/react-app2 and @jbrowse/core. Add your own files to tracks.
import { use } from 'react'
import { JBrowse } from '@jbrowse/react-app2'
import '@jbrowse/react-app2/styles.css'
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
const configUrl = "https://jbrowse.org/ucsc/hg38/config.json"
const configPromise = fetch(configUrl)
.then(res => res.json())
.then(config => {
addRelativeUris(config, new URL(configUrl))
return config
})
export default function Figure() {
const config = use(configPromise)
return (
<JBrowse
assemblies={config.assemblies}
tracks={[...(config.tracks ?? []), ...[
{
"type": "MultiQuantitativeTrack",
"trackId": "ag2_pbmc_scatac_predicted",
"name": "AlphaGenome 2 predicted scATAC, PBMC cell types (marker loci)",
"category": [
"Single cell",
"Chromatin accessibility"
],
"assemblyNames": [
"hg38"
],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#d62728",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#aec7e8",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/Naive_B.bw"
}
]
},
"displayDefaults": {
"mark": "bar",
"height": 300
}
}
]]}
aggregateTextSearchAdapters={config.aggregateTextSearchAdapters}
configuration={config.configuration}
views={[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr2:86,780,000..86,820,000",
"tracks": [
"ag2_pbmc_scatac_predicted"
]
}
]}
/>
)
}jbrowse-img draws this view as an SVG, no browser needed. Swap --config or a track for your own.
cat > tracks.json <<'JSON'
[
{
"type": "MultiQuantitativeTrack",
"trackId": "ag2_pbmc_scatac_predicted",
"name": "AlphaGenome 2 predicted scATAC, PBMC cell types (marker loci)",
"category": [
"Single cell",
"Chromatin accessibility"
],
"assemblyNames": [
"hg38"
],
"adapter": {
"type": "MultiWiggleAdapter",
"subadapters": [
{
"type": "BigWigAdapter",
"name": "CD8 Naive",
"group": "T cell",
"color": "#d62728",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Naive.bw"
},
{
"type": "BigWigAdapter",
"name": "CD8 Memory",
"group": "T cell",
"color": "#279e68",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/CD8_Memory.bw"
},
{
"type": "BigWigAdapter",
"name": "Naive B",
"group": "B cell",
"color": "#aec7e8",
"uri": "https://jbrowse.org/demos/alphagenome2_singlecell/pbmc/Naive_B.bw"
}
]
},
"displayDefaults": {
"mark": "bar",
"height": 300
}
}
]
JSON
npx @jbrowse/img --config https://jbrowse.org/ucsc/hg38/config.json \
--trackConfigs tracks.json \
--assembly hg38 --loc chr2:86,780,000..86,820,000 \
--track ag2_pbmc_scatac_predicted \
--out figure.svgFor a PNG, --out figure.png (needs rsvg-convert: apt install librsvg2-bin, brew install librsvg).
The hosted config, https://jbrowse.org/demos/alphagenome2_singlecell/config.json, has all the rows beside the measured track. The BigWigs cover only the marker loci, so the rows are empty elsewhere. Open CD8A and MS4A1 again, under that config's NCBI RefSeq - RefSeq Curated genes:
chr2:86,780,000-86,820,000 chr11:60,450,000-60,490,000Load a plain list of BigWigs as one track
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.
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 scanpy
- 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 in the label order stored in the object the rows of one lineage are 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
- Tutorial: AlphaGenome 2 predictions by cell type
- 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.