本文整理汇总了Python中libtbx.containers.OrderedDict.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.iteritems方法的具体用法?Python OrderedDict.iteritems怎么用?Python OrderedDict.iteritems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libtbx.containers.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.iteritems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cif
# 需要导入模块: from libtbx.containers import OrderedDict [as 别名]
# 或者: from libtbx.containers.OrderedDict import iteritems [as 别名]
class cif(DictMixin):
def __init__(self, blocks=None):
if blocks is not None:
self.blocks = OrderedDict(blocks)
else:
self.blocks = OrderedDict()
self.keys_lower = dict([(key.lower(), key) for key in self.blocks.keys()])
def __setitem__(self, key, value):
assert isinstance(value, block)
if not re.match(tag_re, '_'+key):
raise Sorry("%s is not a valid data block name" %key)
self.blocks[key] = value
self.keys_lower[key.lower()] = key
def get(self, key, default=None):
key_lower = self.keys_lower.get(key.lower())
if (key_lower is None):
return default
return self.blocks.get(key_lower, default)
def __getitem__(self, key):
result = self.get(key)
if (result is None):
raise KeyError('Unknown CIF data block name: "%s"' % key)
return result
def __delitem__(self, key):
del self.blocks[self.keys_lower[key.lower()]]
del self.keys_lower[key.lower()]
def keys(self):
return self.blocks.keys()
def __repr__(self):
return repr(OrderedDict(self.iteritems()))
def __copy__(self):
return cif(self.blocks.copy())
copy = __copy__
def __deepcopy__(self, memo):
return cif(copy.deepcopy(self.blocks, memo))
def deepcopy(self):
return copy.deepcopy(self)
def show(self, out=None, indent=" ", indent_row=None,
data_name_field_width=34,
loop_format_strings=None):
if out is None:
out = sys.stdout
for name, block in self.items():
print >> out, "data_%s" %name
block.show(
out=out, indent=indent, indent_row=indent_row,
data_name_field_width=data_name_field_width,
loop_format_strings=loop_format_strings)
def __str__(self):
s = StringIO()
self.show(out=s)
return s.getvalue()
def validate(self, dictionary, show_warnings=True, error_handler=None, out=None):
if out is None: out = sys.stdout
from iotbx.cif import validation
errors = {}
if error_handler is None:
error_handler = validation.ErrorHandler()
for key, block in self.blocks.iteritems():
error_handler = error_handler.__class__()
dictionary.set_error_handler(error_handler)
block.validate(dictionary)
errors.setdefault(key, error_handler)
if error_handler.error_count or error_handler.warning_count:
error_handler.show(show_warnings=show_warnings, out=out)
return error_handler
def sort(self, recursive=False, key=None, reverse=False):
self.blocks = OrderedDict(sorted(self.blocks.items(), key=key, reverse=reverse))
if recursive:
for b in self.blocks.values():
b.sort(recursive=recursive, reverse=reverse)
示例2: __init__
# 需要导入模块: from libtbx.containers import OrderedDict [as 别名]
# 或者: from libtbx.containers.OrderedDict import iteritems [as 别名]
#.........这里部分代码省略.........
entity_id += 1
sequence_to_entity_id[sequence] = entity_id
sequence_counts.setdefault(sequence, 0)
sequence_counts[sequence] += 1
sequence_to_chain_ids.setdefault(sequence, [])
sequence_to_chain_ids[sequence].append(chain.chain_id)
sequence_to_chains.setdefault(sequence, [])
sequence_to_chains[sequence].append(chain)
chain_id_to_entity_id[chain.chain_id] = sequence_to_entity_id[sequence]
aligned_pdb_chains.add(chain.residue_groups[0].parent())
unaligned_pdb_chains = OrderedSet(pdb_hierarchy.chains()) - aligned_pdb_chains
assert len(chain.residue_groups) + chain.n_missing_start + chain.n_missing_end == len(sequence)
residue_groups = [None] * chain.n_missing_start + chain.residue_groups + [None] * chain.n_missing_end
i = chain.n_missing_start
seq_num = 0
for i, residue_group in enumerate(residue_groups):
if residue_group is None and chain.alignment.b[i] == '-':
# a deletion
continue
seq_num += 1
if residue_group is not None:
residue_group_to_seq_num_mapping[
residue_group] = seq_num
for pdb_chain in unaligned_pdb_chains:
for residue_group in pdb_chain.residue_groups():
for resname in residue_group.unique_resnames():
if resname not in non_polymer_resname_to_entity_id:
entity_id += 1
non_polymer_resname_to_entity_id[resname] = entity_id
non_polymer_counts[resname] += 1
for sequence, count in sequence_counts.iteritems():
entity_poly_seq_num = 0
entity_id = sequence_to_entity_id[sequence]
entity_loop.add_row((
entity_id,
'polymer', #polymer/non-polymer/macrolide/water
#'?', #src_method
#'?', # pdbx_description
'?', # formula_weight
len(sequence_to_chains[sequence]), # pdbx_number_of_molecules
#'?', # details
#'?', # pdbx_mutation
#'?', # pdbx_fragment
#'?' # pdbx_ec
))
# The definition of the cif item _entity_poly.pdbx_seq_one_letter_code
# says that modifications and non-standard amino acids should be encoded
# as 'X', however in practice the PDB seem to encode them as the three-letter
# code in parentheses.
pdbx_seq_one_letter_code = []
pdbx_seq_one_letter_code_can = []
chains = sequence_to_chains[sequence]
from iotbx.pdb import amino_acid_codes
chain = chains[0]
matches = chain.alignment.matches()
for i, one_letter_code in enumerate(sequence):