本文介绍了如何使用 R 从 FASTA 文件中为 BED 文件中定义的每个间隔提取序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 R 从 FASTA 文件中为 BED 文件中定义的每个间隔提取序列?使用的参考基因组是Gallus gallus",可以通过以下方式获得:

How can I extract sequences from a FASTA file for each of the intervals defined in a BED file using R?The reference genome used is "Gallus gallus" that can be obtained by:

source("http://bioconductor.org/biocLite.R")
biocLite("BSgenome.Ggallus.UCSC.galGal4")
    library(BSgenome.Ggallus.UCSC.galGal4)

我的数据文件是 gRanges 包的结果

My data file is a result of gRanges package

library("GenomicRanges")

> olaps
GRanges object with 2141 ranges and 0 metadata columns:
         seqnames               ranges strand
            <Rle>            <IRanges>  <Rle>
     [1]    chr14 [ 1665929,  1673673]      *
     [2]    chr14 [ 2587465,  2595209]      *
     [3]    chr14 [ 8143785,  8151529]      *
     [4]    chr14 [ 9779705,  9787449]      *
     [5]    chr14 [10281129, 10288873]      *
     ...      ...                  ...    ...
  [2137]    chr24   [3280553, 3288297]      *
  [2138]    chr24   [3330889, 3338633]      *
  [2139]    chr24   [3005641, 3015321]      *
  [2140]    chr24   [3319273, 3327017]      *
  [2141]    chr24   [5549545, 5557289]      *
  -------
  seqinfo: 31 sequences from an unspecified genome; no seqlengths

我可以在 data.table 中进行转换

That I can transform in data.table

olaps<- as.data.table(olaps)

使用示例:

olaps<-"seqnames    start      end width strand
chr1  1665929  1673673  7745      *
chr1  2587465  2595209  7745      *
chr1  8143785  8151529  7745      *
chr2  9779705  9787449  7745      *
chr2 10281129 10288873  7745      *"
olaps<-read.table(text=olaps,header=T)

预期结果:像这样(fasta 格式):

Expected outcome:something like this (fasta format):

>SEQUENCE_1
ACTGACTAGCATCGCAT...
>SEQUENCE_2
ACGTAGAGAGGGACATA...
>SEQUENCE_3...

我尝试使用这个包直到现在都没有成功:

I have tried to use this package unsuccessful until now:

source("http://bioconductor.org/biocLite.R")
biocLite("rtracklayer")

推荐答案

这个,应该可以解决你的问题:

This, should solve your trick:

首先:

seq = BSgenome::getSeq(BSgenome.Ggallus.UCSC.galGal4, olaps)

为序列添加名称:

names(seq) = paste0("SEQUENCE_", seq_along(seq))

从您的序列生成.fasta":

To generate a ".fasta" from your sequences:

Biostrings::writeXStringSet(seq, "my.fasta")

之前提供了更多详细信息:

More details were provided before:

https://support.bioconductor.org/p/77913/#77986

这篇关于如何使用 R 从 FASTA 文件中为 BED 文件中定义的每个间隔提取序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:31