所以我一直在尝试使用Biopython,而且我还很新。我的代码:
fasta_string = open("C:\\Users\\saeed\\Desktop\\dna2.fasta").read()
print('1')
result_handle = NCBIWWW.qblast("blastn", "nt", fasta_string)
print('2')
blast_record = NCBIXML.read(result_handle)
len(blast_record.alignments)
E_VALUE_THRESH = 0.01
for alignment in blast_record.alignments:
for hsp in alignment.hsps:
if hsp.expect < E_VALUE_THRESH:
print('*Alignment*')
print('sequence', alignment.title)
print('length', alignment.length)
print(' e value', hsp.expect)
print(hsp.query)
print(hsp.match)
print(hsp.sbjct)
每当我运行此代码时,它会打印1并停止。不会像在退出时那样停止,而是继续运行并且不会打印任何其他内容。我尝试用&#34; myseq.fa&#34;替换dna2.fasta文件,但这似乎也没有用。它只是说文件不存在。我想知道我做错了什么,以及如何解决它。有什么帮助吗?
答案 0 :(得分:0)
这是我通过BioPython对序列进行qblast所必须做的事情:
import ssl # monkey patch for BioPython 1.68 & 1.69
ssl._create_default_https_context = ssl._create_unverified_context
from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML
from Bio import SeqIO
E_VALUE_THRESH = 0.01
input_file_name = "C:\\Users\\saeed\\Desktop\\dna2.fasta"
fasta_object = SeqIO.read(input_file_name, format='fasta')
result_handle = NCBIWWW.qblast("blastn", "nt", fasta_object.seq)
blast_record = NCBIXML.read(result_handle)
for alignment in blast_record.alignments:
for hsp in alignment.hsps:
if hsp.expect < E_VALUE_THRESH:
print('*Alignment*')
print('sequence', alignment.title)
print('length', alignment.length)
print('e value', hsp.expect)
print(hsp.query)
print(hsp.match)
print(hsp.sbjct)
我有兴趣了解是否有更好的方法来处理SSL /证书问题。
答案 1 :(得分:0)
以下是我在一个请求中包含多个查询的示例。
import timeit # Not necessary; just for timing the blast request.
from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML
fasta_string = open("dna2.fasta").read()
# In "dna2.fasta":
# >test1
# CGCTCATGCTAAAACCACGGAGGAATGTTTGGCCTATTTTGGGGTGAGTG
# >test2
# GCCAAGTCTGCAGGAAGCTTTGAGTTCTGACATCCTTAATGACATGGAGT
#
# Or you can make a string for this simple example.
# fasta_string = ">test1\nCGCTCATGCTAAAACCACGGAGGAATGTTTGGCCTATTTTGGGGTGAGTG\n>test2\nGCCAAGTCTGCAGGAAGCTTTGAGTTCTGACATCCTTAATGACATGGAGT\n"
print(fasta_string)
a = timeit.default_timer() # Not necessary; just for timing the blast request.
result_handle = NCBIWWW.qblast("blastn", "nt", fasta_string)
print(timeit.default_timer() - a) # Not necessary; just for timing the blast request.
# This takes me ~ 40 sec in one test.
# Use "parse" instead of "read" because you have lots of results (i.e., multiple query sequences)
blast_records = NCBIXML.parse(result_handle)
for blast_record in blast_records:
print(blast_record.alignments[0].hsps[0])
&#34; cdlane&#34;是对的。您可能还想使用Bio.SeqIO
模块读取FASTA文件。我确定您已阅读过,但为了以防万一,相关文档在此处:http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc87