Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Suggests:
dplyr,
GenomicRanges,
IRanges,
BSgenome.Hsapiens.UCSC.hg19
BSgenome.Hsapiens.UCSC.hg19,
BSgenome.Hsapiens.UCSC.hg38
Config/testthat/edition: 3
LinkingTo:
Rcpp
Expand Down
31 changes: 18 additions & 13 deletions R/track_plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,16 @@ plot_browser_track <- function(
NULL
}
}
exons <- if (!is.null(exon_anno) && nrow(exon_anno) > 0) {
.merged_exons_per_gene(exon_anno)
} else {
genes[0, c("gene_name", "chr", "start", "end", "strand")]
if (is.null(exon_anno) || nrow(exon_anno) == 0) {
rlang::warn(c(
"No exon annotations found; the gene track will draw genes without exons.",
i = "Run: set_gene_annotations(proj, annotation_type = 'exons', name = 'exons')"
))
}
track_list$gene <- .trackplot_gene_level(
genes = genes, exons = exons, region = region,
genes = genes,
exons = exon_anno %||% genes[0, c("gene_name", "chr", "start", "end", "strand")],
region = region,
base_size = base_size
)
} else {
Expand Down Expand Up @@ -569,6 +572,12 @@ plot_browser_track <- function(
strand = character(0), stringsAsFactors = FALSE
))
}
if (!requireNamespace("IRanges", quietly = TRUE)) {
rlang::abort(c(
"Package 'IRanges' is required to draw exons on the gene track.",
i = 'Install: BiocManager::install("IRanges")'
))
}
by_gene <- split(seq_len(nrow(exons)), exons$gene_name)
merged_list <- lapply(names(by_gene), function(gn) {
idx <- by_gene[[gn]]
Expand Down Expand Up @@ -654,14 +663,10 @@ plot_browser_track <- function(
genes$chr == r$chr & genes$end >= r$start & genes$start <= r$end,
, drop = FALSE
]
exons_sub <- if (nrow(exons) > 0) {
exons[
exons$chr == r$chr & exons$end >= r$start & exons$start <= r$end,
, drop = FALSE
]
} else {
exons
}
exons_sub <- .merged_exons_per_gene(exons[
exons$chr == r$chr & exons$end >= r$start & exons$start <= r$end,
, drop = FALSE
])

# Pack overlapping gene bodies onto distinct y-levels.
slop <- region_width * 0.10
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-track-plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ test_that(".trackplot_gene_level filters genes to the plotted region", {
expect_equal(unique(gene_layer_data$gene_name), "KEEP")
})

test_that(".trackplot_gene_level merges only exons inside the plotted region", {
# Same gene_name on chrX and chrY (pseudoautosomal), overlapping coordinates.
genes <- data.frame(
gene_name = "PAR", chr = c("chrX", "chrY"),
start = 100, end = 900, strand = "+",
stringsAsFactors = FALSE
)
exons <- data.frame(
gene_name = "PAR", feature = "exon", chr = c("chrX", "chrX", "chrY"),
start = c(100, 150, 600), end = c(200, 250, 800), strand = "+",
stringsAsFactors = FALSE
)
gg <- MarchR:::.trackplot_gene_level(
genes, exons, region = "chrX:0-1000", base_size = 10, label_genes = FALSE
)
exon_layer_data <- gg$layers[[2]]$data
expect_equal(exon_layer_data$chr, "chrX")
expect_equal(exon_layer_data$start, 100)
expect_equal(exon_layer_data$end, 250)
})

test_that(".trackplot_gene_level handles a region with no overlapping genes", {
genes <- data.frame(
gene_name = "FAR", chr = "chr1",
Expand Down
15 changes: 13 additions & 2 deletions vignettes/marchr_hematopoiesis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ proj
## Genome Annotations

The ArchR tutorial fragments are aligned to hg19.
**Note that the built-in GENCODE hg19 annotation set differs from the one used in ArchR and does not include exons.**
Transcripts are used for TSS enrichment QC, genes for gene scores, and exons for the gene track
in genome browser plots.

```{r}
proj <- set_gene_annotations(
Expand All @@ -168,6 +169,15 @@ proj <- set_gene_annotations(
release = "19",
annotation_set = "comprehensive"
)
proj <- set_gene_annotations(
proj,
annotation_type = "exons",
name = "exons",
dir_name = ref_dir,
release = "19",
transcript_choice = "all",
annotation_set = "comprehensive"
)
proj <- set_blacklist(proj, genome = "hg19", dir_name = ref_dir)
proj <- set_chrom_sizes(proj, genome = "hg19", dir_name = ref_dir)
proj <- set_genome_sequence(proj, genome = "hg19")
Expand Down Expand Up @@ -351,7 +361,8 @@ plot_gene_scores(

## Genome Browser Tracks

We can use the `plot_browser_track()` to browse the local chromatin accessibility at these marker genes (e.g. CD14) on a per cluster basis.
We can use the `plot_browser_track()` to browse the local chromatin accessibility at these marker genes (e.g. CD14) on a per cluster basis.
The gene track draws each gene body as a line, with its merged exons from the `exons` annotation as thicker blocks.

```{r fig.width=8, fig.height=6}
region <- gene_region(
Expand Down
Loading
Loading