Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取限制位点附近300个碱基的序列读数_Python_R_Perl - Fatal编程技术网

Python 获取限制位点附近300个碱基的序列读数

Python 获取限制位点附近300个碱基的序列读数,python,r,perl,Python,R,Perl,我有许多sam文件,其中包含序列读取,我希望在两个方向上都获得限制序列附近至少300个碱基的读取。 包含限制点位置的第一个文件,有两列。 chr01 4957 chr01 6605 chr02 19968 chr02 21055 chr02 208555 chr03 243398 以SAM文件格式读取的第二个文件。(近2.6米线路) id1995 147 chr03 119509969 42 85M id1999 83 chr10 131560619 26 81M id1999 163 chr1

我有许多sam文件,其中包含序列读取,我希望在两个方向上都获得限制序列附近至少300个碱基的读取。
包含限制点位置的第一个文件,有两列。
chr01 4957
chr01 6605
chr02 19968
chr02 21055
chr02 208555
chr03 243398

以SAM文件格式读取的第二个文件。(近2.6米线路)

id1995 147 chr03 119509969 42 85M
id1999 83 chr10 131560619 26 81M
id1999 163 chr10 131560429 26 85M
id2099 73 chr10 60627850 42 81M

现在我想比较sam文件的第3列和位置文件的第1列,以及sam文件的第4列和位置文件的第2列。 我试着用R语言来做,但是因为数据量很大,所以要花很多时间。 如果您可以通过实现最佳算法来改进R脚本以更快地完成工作。 R代码:

pos=read.csv(file=“sites.csv”,header=F,sep=“\t”)
fastq=read.csv(file=“reads.sam”,header=F,sep=“\t”)
newFastq=data.frame(fastq)
newFastq=NULL
修剪-300){
newFastq=rbind(newFastq,fastq[i,]))
}
}
}  
}
#将数据写入文件
write.table(newFastq,file=“sitesFound.csv”,row.names=FALSE,na=“”,quote=FALSE,col.names=FALSE,sep=“\t”)

或者您可以通过用perl编写来改进此代码。

一个总体策略是使用
asBam()
indexBam()
创建索引bam文件。将第一个文件读入data.frame并构造一个
GRanges()
对象。最后,使用
readGAlignments()
读取bam文件,使用
GRanges()
作为
ScanBamParam()
的which=参数。如果您决定走这条路线,Bioconductor支持网站更适合回答Bioconductor问题

看起来您想要的读数在GRanges对象的+/-300个碱基对内。调整田庄的大小

library(GenomicRanges)
## create gr = GRanges(...)
gr = resize(gr, width = 600, fix="center")
将其用作
ScanBamParam()
中的
,并读取BAM文件

library(GenomicAlignments)
param = ScanBamParam(which = gr)
reads = readGAlignments("your.bam", param = param)
使用
what=
控制从BAM文件读取的字段,例如

param = ScanBamParam(which = gr, what = "seq")

如果能够比较两个文件之间的位置比我写的代码快,那么使用bioconductor解决这个问题看起来是相关的;您的最终解决方案中不会有R级迭代(对于
循环,没有
)。您能否提供可能的脚本,我可以通过该脚本使用Rsamtools和GRanges()比较这两个文件?您是否从SAM文件创建了BAM文件,并从“sites.csv”文件创建了GRanges对象?是的,我创建了BAM文件和GRanges对象。请下一个过程脚本。
param = ScanBamParam(which = gr, what = "seq")