Entering edit mode
Is there a simple way to subset a GRangesList by its seqnames (for example, select only transcripts in chromosome 1)?
I tried this:
gr1 = GRanges(seqnames = "chr2",
ranges = IRanges(103, 106),
strand = "+",
score = 5L, GC = 0.45)
gr2 = GRanges(seqnames = c("chr1", "chr1"),
ranges = IRanges(c(107, 113), width = 3),
strand = c("+", "-"),
score = 3:4, GC = c(0.3, 0.5))
grl = GRangesList(txA = gr1, txB = gr2)
grl_chr1 = grl[seqnames(grl) == "chr1"]
But grl_chr1
is a GRangesList with the same length as grl
with its first element as a zero-length GRanges object. Is there a simple way to remove all zero-length elements from a GRangesList so that I can get a new GRangesList with only transcripts from chr1?
But do note that it won't work for any transcripts that are on multiple chromosomes.