當前位置: 首頁>>代碼示例>>Python>>正文


Python more_itertools.locate方法代碼示例

本文整理匯總了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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:7,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:7,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:8,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:8,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:8,代碼來源:test_more.py

示例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)) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:8,代碼來源:test_more.py

示例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)) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:7,代碼來源:test_more.py

示例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 
開發者ID:SBRG,項目名稱:ssbio,代碼行數:45,代碼來源:chainprop.py

示例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 
開發者ID:SBRG,項目名稱:ssbio,代碼行數:55,代碼來源:seqprop.py


注:本文中的more_itertools.locate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。