Hi,
The gene ids are stored in the names of the GRangesList object:
ex_by_gene <- exonsBy(TxDb.Hsapiens.UCSC.hg19.knownGene,
by="gene")
names(ex_by_gene)[1:3]
# [1] "1" "10" "100"
Unlisting doesn't loose them:
exons <- unlist(ex_by_gene)
names(exons)[1:29]
# [1] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
# [13] "1" "1" "1" "10" "10" "100" "100" "100" "100" "100" "100" "100"
# [25] "100" "100" "100" "100" "100"
To put them in a metadata column:
mcols(exons)$gene_id <- names(exons)
exons
# GRanges object with 272776 ranges and 3 metadata columns:
# seqnames ranges strand | exon_id exon_name gene_id
# <Rle> <IRanges> <Rle> | <integer> <character> <character>
# 1 chr19 [58858172, 58858395] - | 250809 <NA> 1
# 1 chr19 [58858719, 58859006] - | 250810 <NA> 1
# 1 chr19 [58859832, 58860494] - | 250811 <NA> 1
# 1 chr19 [58860934, 58862017] - | 250812 <NA> 1
# 1 chr19 [58861736, 58862017] - | 250813 <NA> 1
# ... ... ... ... . ... ... ...
# 9997 chr22 [50961997, 50962853] - | 266958 <NA> 9997
# 9997 chr22 [50963871, 50964033] - | 266960 <NA> 9997
# 9997 chr22 [50963901, 50964034] - | 266961 <NA> 9997
# 9997 chr22 [50964430, 50964570] - | 266963 <NA> 9997
# 9997 chr22 [50964675, 50964905] - | 266965 <NA> 9997
# -------
# seqinfo: 93 sequences (1 circular) from hg19 genome
Hope this helps,
H.
Thanks! How can I miss this function?!
If it is a list (not GRangesList) object,
I would do
stack is very useful!