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


Python HashSet.add方法代碼示例

本文整理匯總了Python中Bio.Pathway.Rep.HashSet.add方法的典型用法代碼示例。如果您正苦於以下問題:Python HashSet.add方法的具體用法?Python HashSet.add怎麽用?Python HashSet.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bio.Pathway.Rep.HashSet的用法示例。


在下文中一共展示了HashSet.add方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testLen

# 需要導入模塊: from Bio.Pathway.Rep import HashSet [as 別名]
# 或者: from Bio.Pathway.Rep.HashSet import add [as 別名]
 def testLen(self):
     a = HashSet()
     self.assertEqual(len(a), 0, "incorrect default size")
     a.add('a')
     a.add('b')
     self.assertEqual(len(a), 2, "incorrect size")
     a.remove('b')
     self.assertEqual(len(a), 1, "incorrect size after removal")
     a.add('a')
     self.assertEqual(len(a), 1, "incorrect size after duplicate add")
開發者ID:,項目名稱:,代碼行數:12,代碼來源:

示例2: testLen

# 需要導入模塊: from Bio.Pathway.Rep import HashSet [as 別名]
# 或者: from Bio.Pathway.Rep.HashSet import add [as 別名]
 def testLen(self):
     a = HashSet()
     self.failUnless(len(a) == 0, "incorrect default size")
     a.add('a')
     a.add('b')
     self.failUnless(len(a) == 2, "incorrect size")
     a.remove('b')
     self.failUnless(len(a) == 1, "incorrect size after removal")
     a.add('a')
     self.failUnless(len(a) == 1, "incorrect size after duplicate add")
開發者ID:andyoberlin,項目名稱:biopython,代碼行數:12,代碼來源:test_Pathway.py

示例3: __init__

# 需要導入模塊: from Bio.Pathway.Rep import HashSet [as 別名]
# 或者: from Bio.Pathway.Rep.HashSet import add [as 別名]
class System:
    """Abstraction for a collection of reactions.

    This class is used in the Bio.Pathway framework to represent an arbitrary
    collection of reactions without explicitly defined links.

    Attributes:

    None    
    """
    
    def __init__(self, reactions = []):
        """Initializes a new System object."""
        self.__reactions = HashSet(reactions)

    def __repr__(self):
        """Returns a debugging string representation of self."""
        return "System(" + ",".join(map(repr,self.__reactions.list())) + ")"
    
    def __str__(self):
        """Returns a string representation of self."""
        return "System of " + str(len(self.__reactions)) + \
               " reactions involving " + str(len(self.species())) + \
               " species"

    def add_reaction(self, reaction):
        """Adds reaction to self."""
        self.__reactions.add(reaction)

    def remove_reaction(self, reaction):
        """Removes reaction from self."""
        self.__reactions.remove(reaction)

    def reactions(self):
        """Returns a list of the reactions in this system."""
        return self.__reactions.list()

    def species(self):
        """Returns a list of the species in this system."""
        s = HashSet(reduce(lambda s,x: s + x,
                           [x.species() for x in self.reactions()], []))
        return s.list()

    def stochiometry(self):
        """Computes the stoichiometry matrix for self.

        Returns (species, reactions, stoch) where

            species    = ordered list of species in this system
            reactions  = ordered list of reactions in this system
            stoch      = 2D array where stoch[i][j] is coef of the
                         jth species in the ith reaction, as defined
                         by species and reactions above
        """
        # Note: This an inefficient and ugly temporary implementation.
        #       To be practical, stochiometric matrices should probably
        #       be implemented by sparse matrices, which would require
        #       NumPy dependencies.
        #
        # PS: We should implement automatic checking for NumPy here.
        species = self.species()
        reactions = self.reactions()
        stoch = [] * len(reactions)
        for i in range(len(reactions)):
            stoch[i] = 0 * len(species)
            for s in reactions[i].species():
                stoch[species.index(s)] = reactions[i].reactants[s]
        return (species, reactions, stoch)
開發者ID:BlogomaticProject,項目名稱:Blogomatic,代碼行數:70,代碼來源:__init__.py


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