Get internal exons using GenomicFeatures
1
1
Entering edit mode
Last seen 5.9 years ago

Hi

I'm trying to make a Granges objet with all the internal exons of the genes annotated in a GTF file. I using this code:

txdb <- makeTxDbFromGFF("./gencode.vM9.chr_patch_hapl_scaff.annotation.gtf.sed", format="gtf")
exons <- exonsBy(txdb, by="tx")
internal_exons <- lapply(exons,
function(x) if (length(x)>=3){x[3:length(x)-1] })

But it running really slow, is there any way to make it more efficient?

genomicfeatures granges • 726 views
3
Entering edit mode
@michael-lawrence-3846
Last seen 13 months ago
United States

The more important problem is that internal_exons is not a convenient data structure. It will contain NULL values where the condition failed, instead of an empty set of ranges, and the list is semantically poor. Also, the looping obscures the code.

This is faster and cleaner:

internal_exons <- phead(ptail(exons, -2L), -1L)

0
Entering edit mode

You are totally right! I was having problems to use internal_exons as a list. Thanks a lot.