Python more_itertools.locate() Examples
The following are 26
code examples of more_itertools.locate().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
more_itertools
, or try the search function
.
Example #1
Source File: test_more.py From pipenv with MIT License | 5 votes |
def test_no_matches(self): iterable = [0, 0, 0] actual = list(mi.locate(iterable)) expected = [] self.assertEqual(actual, expected)
Example #2
Source File: test_more.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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))
Example #3
Source File: test_more.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: test_more.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: test_more.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: test_more.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def test_no_matches(self): iterable = [0, 0, 0] actual = list(mi.locate(iterable)) expected = [] self.assertEqual(actual, expected)
Example #7
Source File: test_more.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: test_more.py From pipenv with MIT License | 5 votes |
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))
Example #9
Source File: test_more.py From pipenv with MIT License | 5 votes |
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)
Example #10
Source File: test_more.py From pipenv with MIT License | 5 votes |
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)
Example #11
Source File: test_more.py From pipenv with MIT License | 5 votes |
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)
Example #12
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #13
Source File: test_more.py From pipenv with MIT License | 5 votes |
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)
Example #14
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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))
Example #15
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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))
Example #16
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #17
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #18
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
def test_no_matches(self): iterable = [0, 0, 0] actual = list(mi.locate(iterable)) expected = [] self.assertEqual(actual, expected)
Example #19
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #20
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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))
Example #21
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #22
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #23
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
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)
Example #24
Source File: test_more.py From python-netsurv with MIT License | 5 votes |
def test_no_matches(self): iterable = [0, 0, 0] actual = list(mi.locate(iterable)) expected = [] self.assertEqual(actual, expected)
Example #25
Source File: chainprop.py From ssbio with MIT License | 4 votes |
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
Example #26
Source File: seqprop.py From ssbio with MIT License | 4 votes |
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