RRNA-seqWES与WGS分析

[R]bioconductor之GenomicFeatures学

2020-10-26  本文已影响0人  小贝学生信

GenomicFeatures包主要提供了TxDb对象结构。基于此对象的操作,we can easily download the genomic locations of the transcripts, exons and cds of a given organism s from the UCSC Genome Bioinformatics and BioMart2 data resources.
官方教程:https://www.bioconductor.org/packages/release/bioc/html/GenomicFeatures.html
https://www.bioconductor.org/packages/release/bioc/vignettes/GenomicFeatures/inst/doc/GenomicFeatures.pdf

一、TxDb对象构建

常用的方法:加载对应R包

一般常用的物种基因注释信息都已经有人构建好TxDb对象,以R包的形式上传到Bioconductor里。我们使用时直接加载、赋值即可。


TxDb 包
BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene")
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
class(txdb)
txdb
txdb

如官网所说,由于TxDb对象基于SQL支持,因此可use the loadDb method to load the object directly from an appropriate .sqlite database file. 不过多学习了。
此外GenomicFeatures还支持自己手动从指定数据库中构建TxDb对象,例如从 UCSC提取构建的makeTxDbFromUCSC()函数;从BioMart提取构建的makeTxDbFromBiomart()函数等方法可以用作替补方案(没有对应TXDB的R包时)

二、子集筛选

1、指定染色体

head(seqlevels(txdb))
#只保留chr1
seqlevels(txdb) <- "chr1"
seqlevels(txdb)

#恢复初始设置
seqlevels(txdb) <- seqlevels0(txdb)
head(seqlevels(txdb))
seqlevels

2、key-column select模式

keytypes(txdb)
#[1] "CDSID"    "CDSNAME"  "EXONID"   "EXONNAME" "GENEID"   "TXID"     "TXNAME" 
#查看所有的column
columns(txdb)
columns(txdb)
keys <- c("100033416", "100033417", "100033420")
select(txdb, keys = keys, keytype="GENEID", columns="TXNAME")
select
cols <- c("TXNAME", "TXSTRAND", "TXCHROM")
select(txdb, keys=keys, keytype="GENEID", columns=cols)
select2

3、提取transcripts, exons, cds, genes, promoters GRanges

GR.tr <- transcripts(txdb)
GR.tr
GR.tr
#配合filter参数,筛选指定信息
GR.ex.sub <- exons(txdb, filter=list(tx_chrom = "chr15", tx_strand = "-"))
GR.ex.sub
GR.ex.sub

关于 promoters启动子,由于其定义为transcription start site(TSS)位点上下游范围的一段序列,具体上下游的长度可自己定义,promoters()函数默认设置为upstream=2000, downstream=200

head(promoters(txdb)) #2000+200,即2200的长度
promoters

4、Grouped Features & GRangesList

##group transcripts by genes:
length(GR.tr);length(GR.ge)
#[1] 82960
#[1] 23056
GRList.tr2ge <- transcriptsBy(txdb, by = "gene")
class(GRList.tr2ge)
length(GRList.tr2ge)
#[1] 23459
head(GRList.tr2ge,2)
head(GRList.tr2ge,2)
length(GR.ex);length(GR.tr)
#[1] 289969
#[1] 82960
GRList.ex2tx <- exonsBy(txdb, by = "tx") 
length(GRList.ex2tx)
#[1] 82960

此外GenomicFeatures包还提供了三种prespecified form function:intronsByTranscript,fiveUTRsByTranscript, threeUTRsByTranscript,可通过名字直接了解包含关系,方便使用。

5、获取对应的序列信息

#BiocManager::install("BSgenome.Hsapiens.UCSC.hg19")
library(BSgenome.Hsapiens.UCSC.hg19)
BSgenome = BSgenome.Hsapiens.UCSC.hg19
test <- head(GR.ex)
tmp <- getSeq(BSgenome,test)
tmp
class(tmp)
#[1] "DNAStringSet"
#attr(,"package")
#[1] "Biostrings"
tmp
nchar(as.character(tmp[[1]]))
translate(tmp)

tx_seqs1 <- extractTranscriptSeqs(Hsapiens, TxDb.Hsapiens.UCSC.hg19.knownGene,
                                  use.names=TRUE)
suppressWarnings(translate(tx_seqs1))
translate
上一篇 下一篇

猜你喜欢

热点阅读