Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 2.7 python中的多线程在大型multifasta上运行_Python 2.7_Alignment_Python Multithreading_Dna Sequence - Fatal编程技术网

Python 2.7 python中的多线程在大型multifasta上运行

Python 2.7 python中的多线程在大型multifasta上运行,python-2.7,alignment,python-multithreading,dna-sequence,Python 2.7,Alignment,Python Multithreading,Dna Sequence,我的问题很简单,但我不知道如何解决它。 我有一个大约一百万个序列的列表,每个序列都需要与一个序列适配器对齐。我正在考虑使用Biopython的pairwise2工具在python中进行对齐。我想使用这个工具,因为我需要收集所有对齐分数,做一些数学运算,并根据数学选择序列。如果我运行下面的代码,它会工作,但速度很慢,因为每次只运行一个对齐 def align_call(record, adapter): score = pairwise2.align.localms(record.seq, ada

我的问题很简单,但我不知道如何解决它。 我有一个大约一百万个序列的列表,每个序列都需要与一个序列适配器对齐。我正在考虑使用Biopython的pairwise2工具在python中进行对齐。我想使用这个工具,因为我需要收集所有对齐分数,做一些数学运算,并根据数学选择序列。如果我运行下面的代码,它会工作,但速度很慢,因为每次只运行一个对齐

def align_call(record, adapter):
score = pairwise2.align.localms(record.seq, adapter.seq, 1, -3, -1, -0.99, one_alignment_only=1, score_only=1)
print  record.id  + " "  +  record.seq  + " "  + adapter.id + " "  + str(score)
#results.append(line)
return

if __name__ == '__main__':    
fastaSeq = argv[1]
threads = argv[2]
fastaAdapt = argv[3]
listSeq = []
adpt = list(SeqIO.parse(fastaAdapt, "fasta"))
for record in SeqIO.parse(fastaSeq, "fasta"):
    align_call(record, adpt[0])
因此,我想改变代码,使用多线程或多进程来加速进程,根据计算机的线程数发送n个并行作业。所以我想出了这样的办法:

results = []

def align_call(record, adapter):
score = pairwise2.align.localms(record.seq, adapter.seq, 1, -3, -1, -0.99, one_alignment_only=1, score_only=1)
line = record.id  + " "  +  record.seq  + " "  + adapter.id + " "  + str(score)
results.append(line)
return results

if __name__ == '__main__':    
fastaSeq = argv[1]
threads = argv[2]
fastaAdapt = argv[3]

listSeq = []
adpt = list(SeqIO.parse(fastaAdapt, "fasta"))
for record in SeqIO.parse(fastaSeq, "fasta"):
    pool = Pool(processes=1)
    result = pool.apply_async(align_call, args= (record, adpt[0]))
    print result.get()
该脚本可以工作,但我无法调整每次需要发送多少序列,当我得到很多序列时,我的内核和内存就用完了

你知道我该怎么做吗?建议? 我尝试实现队列,但没有成功

谢谢
Luigi

您可能需要查看vsearch(或usearch) 它相当快!并且支持多线程

--id是允许的与目标序列的最大%差异(在本例中为80%)

--iddef 0是评分方法0=基于最短序列的标识,2=带端子间隙…)

然后,您可以读取这个outputfile.txt并获取对齐分数/匹配项/间距/对齐长度查询名称。。。 对于每个序列。 收集所需的查询名称后,可以使用这些名称从原始fasta文件中提取相关序列

如果您只希望大于x%的序列与适配器匹配,可以使用--matched而不是--uc,这将为您提供一个fasta文件,其中包含匹配超过--id阈值的序列

或者,-samout将为您提供一个sam文件,其中包含序列名称、对齐长度、对齐的雪茄代码以及查询序列


拥有全套输出选项和命令

我认为应该在SeqIO循环之前创建池。您需要使用锁或回调来确保输出的顺序正确

vsearch --usearch_global big.fasta -db adapter_seq.fasta --uc outputfile.txt --id 0.8 --iddef 0 --threads 6