本文整理汇总了Python中Bio.File.UndoHandle.peekline方法的典型用法代码示例。如果您正苦于以下问题:Python UndoHandle.peekline方法的具体用法?Python UndoHandle.peekline怎么用?Python UndoHandle.peekline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.File.UndoHandle
的用法示例。
在下文中一共展示了UndoHandle.peekline方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_sprot_raw
# 需要导入模块: from Bio.File import UndoHandle [as 别名]
# 或者: from Bio.File.UndoHandle import peekline [as 别名]
def test_get_sprot_raw(self):
"""Bio.ExPASy.get_sprot_raw("O23729")"""
identifier = "O23729"
# This is to catch an error page from our proxy:
handle = UndoHandle(ExPASy.get_sprot_raw(identifier))
if _as_string(handle.peekline()).startswith("<!DOCTYPE HTML"):
raise IOError
record = SeqIO.read(handle, "swiss")
handle.close()
self.assertEqual(record.id, identifier)
self.assertEqual(len(record), 394)
self.assertEqual(seguid(record.seq), "5Y08l+HJRDIlhLKzFEfkcKd1dkM")
示例2: test_get_sprot_raw
# 需要导入模块: from Bio.File import UndoHandle [as 别名]
# 或者: from Bio.File.UndoHandle import peekline [as 别名]
def test_get_sprot_raw(self):
"""Bio.ExPASy.get_sprot_raw("O23729")"""
identifier = "O23729"
try:
#This is to catch an error page from our proxy:
handle = UndoHandle(ExPASy.get_sprot_raw(identifier))
if _as_string(handle.peekline()).startswith("<!DOCTYPE HTML"):
raise IOError
record = SeqIO.read(handle, "swiss")
handle.close()
except IOError:
raise MissingExternalDependencyError(
"internet (or maybe just ExPASy) not available")
self.assertEqual(record.id, identifier)
self.assertEqual(len(record), 394)
self.assertEqual(seguid(record.seq), "5Y08l+HJRDIlhLKzFEfkcKd1dkM")
示例3: FastaM10Parser
# 需要导入模块: from Bio.File import UndoHandle [as 别名]
# 或者: from Bio.File.UndoHandle import peekline [as 别名]
#.........这里部分代码省略.........
# set values from preamble
for key, value in self._preamble.items():
setattr(qresult, key, value)
elif qres_state == state_QRES_CONTENT:
assert self.line[3:].startswith(qresult.id), self.line
for hit, strand in self._parse_hit(query_id):
# HACK: re-set desc, for hsp hit and query description
hit.description = hit.description
hit.query_description = qresult.description
# if hit is not in qresult, append it
if hit.id not in qresult:
qresult.append(hit)
# otherwise, it might be the same hit with a different strand
else:
# make sure strand is different and then append hsp to
# existing hit
for hsp in hit.hsps:
assert strand != hsp.query_strand
qresult[hit.id].append(hsp)
self.line = self.handle.readline()
def _parse_hit(self, query_id):
while True:
self.line = self.handle.readline()
if self.line.startswith('>>'):
break
state = _STATE_NONE
strand = None
hsp_list = []
while True:
peekline = self.handle.peekline()
# yield hit if we've reached the start of a new query or
# the end of the search
if peekline.strip() in [">>><<<", ">>>///"] or \
(not peekline.startswith('>>>') and '>>>' in peekline):
# append last parsed_hsp['hit']['seq'] line
if state == _STATE_HIT_BLOCK:
parsed_hsp['hit']['seq'] += self.line.strip()
elif state == _STATE_CONS_BLOCK:
hsp.aln_annotation['similarity'] += \
self.line.strip('\r\n')
# process HSP alignment and coordinates
_set_hsp_seqs(hsp, parsed_hsp, self._preamble['program'])
hit = Hit(hsp_list)
hit.description = hit_desc
hit.seq_len = seq_len
yield hit, strand
hsp_list = []
break
# yield hit and create a new one if we're still in the same query
elif self.line.startswith('>>'):
# try yielding, if we have hsps
if hsp_list:
_set_hsp_seqs(hsp, parsed_hsp, self._preamble['program'])
hit = Hit(hsp_list)
hit.description = hit_desc
hit.seq_len = seq_len
yield hit, strand
hsp_list = []
# try to get the hit id and desc, and handle cases without descs
try:
hit_id, hit_desc = self.line[2:].strip().split(' ', 1)
except ValueError:
示例4: PdbAtomIterator
# 需要导入模块: from Bio.File import UndoHandle [as 别名]
# 或者: from Bio.File.UndoHandle import peekline [as 别名]
def PdbAtomIterator(handle):
"""Returns SeqRecord objects for each chain in a PDB file
The sequences are derived from the 3D structure (ATOM records), not the
SEQRES lines in the PDB file header.
Unrecognised three letter amino acid codes (e.g. "CSD") from HETATM entries
are converted to "X" in the sequence.
In addition to information from the PDB header (which is the same for all
records), the following chain specific information is placed in the
annotation:
record.annotations["residues"] = List of residue ID strings
record.annotations["chain"] = Chain ID (typically A, B ,...)
record.annotations["model"] = Model ID (typically zero)
Where amino acids are missing from the structure, as indicated by residue
numbering, the sequence is filled in with 'X' characters to match the size
of the missing region, and None is included as the corresponding entry in
the list record.annotations["residues"].
This function uses the Bio.PDB module to do most of the hard work. The
annotation information could be improved but this extra parsing should be
done in parse_pdb_header, not this module.
"""
# Only import PDB when needed, to avoid/delay NumPy dependency in SeqIO
from Bio.PDB import PDBParser
from Bio.SeqUtils import seq1
from Bio.SCOP.three_to_one_dict import to_one_letter_code
def restype(residue):
"""Return a residue's type as a one-letter code.
Non-standard residues (e.g. CSD, ANP) are returned as 'X'.
"""
return seq1(residue.resname, custom_map=to_one_letter_code)
# Deduce the PDB ID from the PDB header
# ENH: or filename?
from Bio.File import UndoHandle
undo_handle = UndoHandle(handle)
firstline = undo_handle.peekline()
if firstline.startswith("HEADER"):
pdb_id = firstline[62:66]
else:
warnings.warn("First line is not a 'HEADER'; can't determine PDB ID")
pdb_id = '????'
struct = PDBParser().get_structure(pdb_id, undo_handle)
model = struct[0]
for chn_id, chain in sorted(model.child_dict.iteritems()):
# HETATM mod. res. policy: remove mod if in sequence, else discard
residues = [res for res in chain.get_unpacked_list()
if seq1(res.get_resname().upper(),
custom_map=to_one_letter_code) != "X"]
if not residues:
continue
# Identify missing residues in the structure
# (fill the sequence with 'X' residues in these regions)
gaps = []
rnumbers = [r.id[1] for r in residues]
for i, rnum in enumerate(rnumbers[:-1]):
if rnumbers[i+1] != rnum + 1:
# It's a gap!
gaps.append((i+1, rnum, rnumbers[i+1]))
if gaps:
res_out = []
prev_idx = 0
for i, pregap, postgap in gaps:
if postgap > pregap:
gapsize = postgap - pregap - 1
res_out.extend(map(restype, residues[prev_idx:i]))
prev_idx = i
res_out.append('X'*gapsize)
# Last segment
res_out.extend(map(restype, residues[prev_idx:]))
else:
warnings.warn("Ignoring out-of-order residues after a gap",
UserWarning)
# Keep the normal part, drop the out-of-order segment
# (presumably modified or hetatm residues, e.g. 3BEG)
res_out.extend(map(restype, residues[prev_idx:i]))
else:
# No gaps
res_out = map(restype, residues)
record_id = "%s:%s" % (pdb_id, chn_id)
# ENH - model number in SeqRecord id if multiple models?
# id = "Chain%s" % str(chain.id)
# if len(structure) > 1 :
# id = ("Model%s|" % str(model.id)) + id
record = SeqRecord(Seq(''.join(res_out), generic_protein),
id=record_id,
description=record_id,
)
# The PDB header was loaded as a dictionary, so let's reuse it all
record.annotations = struct.header.copy()
# Plus some chain specifics:
#.........这里部分代码省略.........
示例5: PdbAtomIterator
# 需要导入模块: from Bio.File import UndoHandle [as 别名]
# 或者: from Bio.File.UndoHandle import peekline [as 别名]
def PdbAtomIterator(handle):
"""Return SeqRecord objects for each chain in a PDB file.
The sequences are derived from the 3D structure (ATOM records), not the
SEQRES lines in the PDB file header.
Unrecognised three letter amino acid codes (e.g. "CSD") from HETATM entries
are converted to "X" in the sequence.
In addition to information from the PDB header (which is the same for all
records), the following chain specific information is placed in the
annotation:
record.annotations["residues"] = List of residue ID strings
record.annotations["chain"] = Chain ID (typically A, B ,...)
record.annotations["model"] = Model ID (typically zero)
Where amino acids are missing from the structure, as indicated by residue
numbering, the sequence is filled in with 'X' characters to match the size
of the missing region, and None is included as the corresponding entry in
the list record.annotations["residues"].
This function uses the Bio.PDB module to do most of the hard work. The
annotation information could be improved but this extra parsing should be
done in parse_pdb_header, not this module.
This gets called internally via Bio.SeqIO for the atom based interpretation
of the PDB file format:
>>> from Bio import SeqIO
>>> for record in SeqIO.parse("PDB/1A8O.pdb", "pdb-atom"):
... print("Record id %s, chain %s" % (record.id, record.annotations["chain"]))
...
Record id 1A8O:A, chain A
Equivalently,
>>> with open("PDB/1A8O.pdb") as handle:
... for record in PdbAtomIterator(handle):
... print("Record id %s, chain %s" % (record.id, record.annotations["chain"]))
...
Record id 1A8O:A, chain A
"""
# TODO - Add record.annotations to the doctest, esp the residues (not working?)
# Only import PDB when needed, to avoid/delay NumPy dependency in SeqIO
from Bio.PDB import PDBParser
# Deduce the PDB ID from the PDB header
# ENH: or filename?
from Bio.File import UndoHandle
undo_handle = UndoHandle(handle)
firstline = undo_handle.peekline()
# check if file is empty
if firstline == '':
raise ValueError("Empty file.")
if firstline.startswith("HEADER"):
pdb_id = firstline[62:66]
else:
warnings.warn("First line is not a 'HEADER'; can't determine PDB ID. "
"Line: %r" % firstline, BiopythonParserWarning)
pdb_id = '????'
struct = PDBParser().get_structure(pdb_id, undo_handle)
for record in AtomIterator(pdb_id, struct):
# The PDB header was loaded as a dictionary, so let's reuse it all
record.annotations.update(struct.header)
# ENH - add letter annotations -- per-residue info, e.g. numbers
yield record