本文整理汇总了Python中Bio.SearchIO.index方法的典型用法代码示例。如果您正苦于以下问题:Python SearchIO.index方法的具体用法?Python SearchIO.index怎么用?Python SearchIO.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.SearchIO
的用法示例。
在下文中一共展示了SearchIO.index方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_raw
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
def check_raw(self, filename, id, raw, **kwargs):
"""Index filename using keyword arguments, check get_raw(id)==raw."""
idx = SearchIO.index(filename, self.fmt, **kwargs)
raw = _as_bytes(raw)
# Anticipate cases where the raw string and/or file uses different
# newline characters ~ we set everything to \n.
new = idx.get_raw(id)
self.assertTrue(isinstance(new, bytes),
"Didn't get bytes from %s get_raw" % self.fmt)
self.assertEqual(raw.replace(b'\r\n', b'\n'),
new.replace(b'\r\n', b'\n'))
idx.close()
# Now again, but using SQLite backend
if sqlite3:
idx = SearchIO.index_db(":memory:", filename, self.fmt, **kwargs)
new = idx.get_raw(id)
self.assertTrue(isinstance(new, bytes),
"Didn't get bytes from %s get_raw" % self.fmt)
self.assertEqual(raw.replace(b'\r\n', b'\n'),
new.replace(b'\r\n', b'\n'))
idx.close()
if os.path.isfile(filename + ".bgz"):
# Do the tests again with the BGZF compressed file
print("[BONUS %s.bgz]" % filename)
self.check_raw(filename + ".bgz", id, raw, **kwargs)
示例2: check_index
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
def check_index(self, filename, format, **kwargs):
# check if Python3 installation has sqlite3
try:
import sqlite3
except ImportError:
sqlite3 = None
parsed = list(SearchIO.parse(filename, format, **kwargs))
# compare values by index
indexed = SearchIO.index(filename, format, **kwargs)
self.assertEqual(len(parsed), len(indexed.keys()))
# compare values by index_db, only if sqlite3 is present
if sqlite3 is not None:
db_indexed = SearchIO.index_db(':memory:', [filename], format, **kwargs)
self.assertEqual(len(parsed), len(db_indexed.keys()))
for qres in parsed:
idx_qres = indexed[qres.id]
# parsed and indexed qresult are different objects!
self.assertNotEqual(id(qres), id(idx_qres))
# but they should have the same attribute values
self.assertTrue(compare_search_obj(qres, idx_qres))
# sqlite3 comparison, only if it's present
if sqlite3 is not None:
dbidx_qres = db_indexed[qres.id]
self.assertNotEqual(id(qres), id(dbidx_qres))
self.assertTrue(compare_search_obj(qres, dbidx_qres))
indexed._proxy._handle.close() # TODO - Better solution
if sqlite3 is not None:
db_indexed.close()
db_indexed._con.close()
示例3: check_index
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
def check_index(self, filename, format, **kwargs):
# check if Python3 installation has sqlite3
try:
import sqlite3
except ImportError:
sqlite3 = None
if filename.endswith(".bgz"):
handle = gzip.open(filename)
parsed = list(SearchIO.parse(handle, format, **kwargs))
handle.close()
else:
parsed = list(SearchIO.parse(filename, format, **kwargs))
# compare values by index
indexed = SearchIO.index(filename, format, **kwargs)
self.assertEqual(len(parsed), len(indexed),
"Should be %i records in %s, index says %i"
% (len(parsed), filename, len(indexed)))
# compare values by index_db, only if sqlite3 is present
if sqlite3 is not None:
db_indexed = SearchIO.index_db(':memory:', [filename], format, **kwargs)
self.assertEqual(len(parsed), len(db_indexed),
"Should be %i records in %s, index_db says %i"
% (len(parsed), filename, len(db_indexed)))
for qres in parsed:
idx_qres = indexed[qres.id]
# parsed and indexed qresult are different objects!
self.assertNotEqual(id(qres), id(idx_qres))
# but they should have the same attribute values
self.assertTrue(compare_search_obj(qres, idx_qres))
# sqlite3 comparison, only if it's present
if sqlite3 is not None:
dbidx_qres = db_indexed[qres.id]
self.assertNotEqual(id(qres), id(dbidx_qres))
self.assertTrue(compare_search_obj(qres, dbidx_qres))
indexed.close()
if sqlite3 is not None:
db_indexed.close()
db_indexed._con.close()
if os.path.isfile(filename + ".bgz"):
# Do the tests again with the BGZF compressed file
print("[BONUS %s.bgz]" % filename)
self.check_index(filename + ".bgz", format, **kwargs)
示例4: check_raw
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
def check_raw(self, filename, id, raw, **kwargs):
"""Index filename using **kwargs, check get_raw(id)==raw."""
idx = SearchIO.index(filename, self.fmt, **kwargs)
raw = _as_bytes(raw)
self.assertEqual(raw, idx.get_raw(id))
idx.close()
#Now again, but using SQLite backend
if sqlite3:
idx = SearchIO.index_db(":memory:", filename, self.fmt, **kwargs)
self.assertEqual(raw, idx.get_raw(id))
idx.close()
if os.path.isfile(filename + ".bgz"):
#Do the tests again with the BGZF compressed file
print "[BONUS %s.bgz]" % filename
self.check_raw(filename + ".bgz", id, raw, **kwargs)
示例5: not
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
if not (os.path.isfile(db_fasta + ".nhr") and \
os.path.isfile(db_fasta + ".nin") and \
os.path.isfile(db_fasta + ".nsq")):
stop_err("Missing BLAST database for %s" % db_fasta)
cmd = NcbiblastnCommandline(query=query_fasta, db=db_fasta,
out=blast_file, outfmt=6,
evalue=1e-5)
print cmd
stdout, stderr = cmd()
return
if not os.path.isfile(blast_file):
do_blast(assembly_fasta, reference_fasta, blast_file)
contigs = SeqIO.index(assembly_fasta, "fasta")
blast_results = SearchIO.index(blast_file, "blast-tab")
reference_parser = SeqIO.parse(reference_fasta, "fasta")
fasta_handle = open(output_fasta, "w")
fasta_saved_count = 0
fasta_short_dropped = 0
offset = 0
ref_offsets = dict()
for record in reference_parser:
ref_offsets[hack_ncbi_fasta_name(record.id)] = offset
offset += len(record)
def reverse_complement_hsp_fragment(frag, query_length):
rev = SearchIO.HSPFragment(hit_id=frag.hit_id, query_id=frag.query_id)
示例6: open
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
filename = "substrates.txt"
with open(filename) as src:
p = [line.split('\r') for line in src][0]
legdict = {}
for line in p:
pp = line.split()
lid = pp[0].lower(),
alias = pp[1]
legdict[lid[0]] = {
"lid": lid[0],
"alias": alias}
from Bio import SearchIO
result_handle = open("results/blastp_resultAD.txt")
# comments=True)
idx = SearchIO.index('results/blastp_resultAD.txt', 'blast-tab')
idss = (idx.keys())
homs = {}
rec_list_all = []
for ids in idss:
rec_list = []
for rec in idx[ids].hsps:
rec_list.append((rec.hit_id, rec.evalue, rec.ident_pct))
rec_list_all.append(
(rec.query_id, rec.hit_id, rec.evalue, rec.ident_pct))
homs[ids] = {ids: rec_list}
leg_uniq = []
ids = []
for p in sorted(rec_list_all, key=lambda x: x[0][1]):
if p[2] < 10E-3:
示例7: open
# 需要导入模块: from Bio import SearchIO [as 别名]
# 或者: from Bio.SearchIO import index [as 别名]
from Bio import SearchIO
result_handle = open("results/blastp_resultAD.txt")
idx = SearchIO.index('results/blastp_resultAD.txt', 'blast-tab')# comments=True)
idss = (idx.keys())
homs = {}
rec_list_all = []
for ids in idss:
rec_list = []
for rec in idx[ids].hsps:
rec_list.append((rec.hit_id, rec.evalue, rec.ident_pct))
rec_list_all.append((rec.query_id, rec.hit_id, rec.evalue, rec.ident_pct))
homs[ids] = {ids: rec_list}
leg_uniq = []
ids = []
for p in sorted(rec_list_all, key=lambda x: x[0][1]):
if p[2] < 10E-3 and p[1] not in p[0]:
if p[1] not in ids:
ids.append(p[1])
leg_uniq.append(p)
output = open('results/leg_blastp_hits.txt', 'w')
output.write('id'+'\t'+'blastp_hit'+ '\t' + 'e-value' + '\t' + 'ident_pct' + '\n')
for p in leg_uniq:
qid = '%s' % p[0]
hit = '%s' % p[1]
ev = '%s' % p[2]
per = '%s' % p[3]
output.write(qid + "\t" + hit + "\t" + ev + '\t' + per + "\n")
output.close()