本文整理汇总了Python中more_itertools.locate方法的典型用法代码示例。如果您正苦于以下问题:Python more_itertools.locate方法的具体用法?Python more_itertools.locate怎么用?Python more_itertools.locate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类more_itertools
的用法示例。
在下文中一共展示了more_itertools.locate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_default_pred
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_default_pred(self):
iterable = [0, 1, 1, 0, 1, 0, 0]
actual = list(mi.locate(iterable))
expected = [1, 2, 4]
self.assertEqual(actual, expected)
示例2: test_no_matches
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_no_matches(self):
iterable = [0, 0, 0]
actual = list(mi.locate(iterable))
expected = []
self.assertEqual(actual, expected)
示例3: test_custom_pred
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_custom_pred(self):
iterable = ['0', 1, 1, '0', 1, '0', '0']
pred = lambda x: x == '0'
actual = list(mi.locate(iterable, pred))
expected = [0, 3, 5, 6]
self.assertEqual(actual, expected)
示例4: test_window_size
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_window_size(self):
iterable = ['0', 1, 1, '0', 1, '0', '0']
pred = lambda *args: args == ('0', 1)
actual = list(mi.locate(iterable, pred, window_size=2))
expected = [0, 3]
self.assertEqual(actual, expected)
示例5: test_window_size_large
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_window_size_large(self):
iterable = [1, 2, 3, 4]
pred = lambda a, b, c, d, e: True
actual = list(mi.locate(iterable, pred, window_size=5))
expected = [0]
self.assertEqual(actual, expected)
示例6: test_window_size_zero
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_window_size_zero(self):
iterable = [1, 2, 3, 4]
pred = lambda: True
for it in (iterable, iter(iterable)):
with self.assertRaises(ValueError):
list(mi.locate(iterable, pred, window_size=0))
示例7: test_window_size_zero
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def test_window_size_zero(self):
iterable = [1, 2, 3, 4]
pred = lambda: True
with self.assertRaises(ValueError):
list(mi.locate(iterable, pred, window_size=0))
示例8: get_subsequence_from_property
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def get_subsequence_from_property(self, property_key, property_value, condition, return_resnums=False,
copy_letter_annotations=True):
"""Get a subsequence as a new SeqProp object given a certain property you want to find in
this chain's letter_annotation
See documentation for :func:`ssbio.protein.sequence.seqprop.SeqProp.get_subsequence_from_property`
Args:
property_key (str): Property key in the ``letter_annotations`` attribute that you want to filter using
property_value (str): Property value that you want to filter by
condition (str): ``<``, ``=``, ``>``, ``>=``, or ``<=`` to filter the values by
return_resnums (bool): If resnums should be returned as well
Returns:
SeqProp: New SeqProp object that you can run computations on or just extract its properties
"""
if not self.seq_record:
raise ValueError('No chain sequence stored')
if property_key not in self.seq_record.letter_annotations:
log.error(KeyError('{}: {} not contained in the letter annotations'.format(self.seq_record.id, property_key)))
return
if condition == 'in':
subfeat_indices = list(locate(self.seq_record.letter_annotations[property_key],
lambda x: x in property_value))
else:
subfeat_indices = list(locate(self.seq_record.letter_annotations[property_key],
lambda x: ssbio.utils.check_condition(x, condition, property_value)))
subfeat_resnums = [x + 1 for x in subfeat_indices]
new_sp = self.get_subsequence(resnums=subfeat_resnums, new_id='{}_{}_{}_{}_extracted'.format(self.pdb_parent,
self.id,
property_key,
condition,
property_value),
copy_letter_annotations=copy_letter_annotations)
if return_resnums:
return new_sp, subfeat_resnums
else:
return new_sp
示例9: get_subsequence_from_property
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import locate [as 别名]
def get_subsequence_from_property(self, property_key, property_value, condition,
return_resnums=False, copy_letter_annotations=True):
"""Get a subsequence as a new SeqProp object given a certain property you want to find in the
original SeqProp's letter_annotation
This can be used to do something like extract the subsequence of exposed residues, so you can can run
calculations on that subsequence. Useful if you have questions like "are there any predicted surface exposed
cysteines in my protein sequence?"
Example:
>>> sp = SeqProp(id='tester', seq='MQSLE')
>>> sp.letter_annotations['a_key'] = [2, 2, 3, 1, 0]
>>> pk = 'a_key'
>>> pv = 2
>>> cond = '<'
>>> new_sp = sp.get_subsequence_from_property(pk, pv, cond)
>>> new_sp.letter_annotations[pk]
[1, 0]
>>> new_sp
SeqProp(seq=Seq('LE', ExtendedIUPACProtein()), id='tester_a_key_<_2_extracted', name='<unknown name>', description='<unknown description>', dbxrefs=[])
Args:
property_key (str): Property key in the ``letter_annotations`` attribute that you want to filter using
property_value (str): Property value that you want to filter by
condition (str): ``<``, ``=``, ``>``, ``>=``, or ``<=`` to filter the values by
Returns:
SeqProp: New SeqProp object that you can run computations on or just extract its properties
"""
if property_key not in self.letter_annotations:
log.error('{}: {} not contained in the letter annotations'.format(self.id, property_key))
return
if condition == 'in':
subfeat_indices = list(locate(self.letter_annotations[property_key],
lambda x: x in property_value))
else:
subfeat_indices = list(
locate(self.letter_annotations[property_key], lambda x: ssbio.utils.check_condition(x, condition, property_value)))
subfeat_resnums = [x+1 for x in subfeat_indices]
new_sp = self.get_subsequence(resnums=subfeat_resnums, new_id='{}_{}_{}_{}_extracted'.format(self.id,
property_key,
condition,
property_value),
copy_letter_annotations=copy_letter_annotations)
if return_resnums:
return new_sp, subfeat_resnums
else:
return new_sp