R 中的 Bioconductor 入门
Paula Andrea Martinez, PhD.
Data Scientist
library(GenomicRanges)
(myGR <- GRanges("chr1:200-300"))
GRanges 对象:1 个区间,0 个元数据列:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 [200, 300] *
-----
seqinfo: 未指定基因组的 1 条序列;无序列长度
chr1:200-300seqnames 与 seqinfo# df 类 data.frame 的结构
seqnames start end strand score GC
1 chrX 50 120 + 1 0.25
2 chrX 130 140 + 2 0.25
3 chrX 153 154 + 3 0.25
4 chrY 30 40 * 4 0.25
5 chrY 50 55 - 5 0.25
(myGR <- as(df, "GRanges")) # 将 df 转为 GRanges
GRanges 对象:5 个区间,2 个元数据列:
seqnames ranges strand | score GC
<Rle> <IRanges> <Rle> | <integer> <numeric>
[1] chrX [ 50, 120] + | 1 0.25
[2] chrX [130, 140] + | 2 0.25
[3] chrX [153, 154] + | 3 0.25
[4] chrY [ 30, 40] * | 4 0.25
[5] chrY [ 50, 55] - | 5 0.25
-----
seqinfo: 未指定基因组的 2 条序列;无序列长度
methods(class = "GRanges") # 查看可用的访问器# 染色体名称 seqnames(gr)# 返回区间的 IRanges 对象 ranges(gr)# 元数据列 mcols(gr)# 序列信息(通用函数) seqinfo(gr)# 基因组名称 genome(gr)

library(TxDb.Hsapiens.UCSC.hg38.knownGene)
hg <- TxDb.Hsapiens.UCSC.hg38.knownGene
从X染色体选择基因
hg_chrXg <- genes(hg, filter = list(tx_chrom = c("chrX")))
GRanges 对象:1192 个区间,1 个元数据列:
seqnames ranges strand | gene_id
<Rle> <IRanges> <Rle> | <character>
100008586 chrX 49551278-49568218 + | 100008586
10009 chrX 120250752-120258398 + | 10009
100093698 chrX 13310652-13319933 + | 100093698
... ... ... ... . ...
-------
seqinfo: 来自 hg38 基因组的 640 条序列(1 条环状)
R 中的 Bioconductor 入门