1212from collections import Counter
1313from collections import defaultdict
1414import math as pymath
15- from bionetgen .atomizer .utils .util import logMess , TranslationException
15+ from bionetgen .atomizer .utils .util import logMess , TranslationException , get_size , get_item
1616import libsbml
1717from bionetgen .atomizer .bngModel import bngModel
1818
@@ -220,7 +220,7 @@ def extractModelAnnotation(self):
220220 annotation = self .model .getAnnotation ()
221221 lista = libsbml .CVTermList ()
222222 libsbml .RDFAnnotationParser .parseRDFAnnotation (annotation , lista )
223- for idx in range (lista . getSize ( )):
223+ for idx in range (get_size ( lista )):
224224 # biol,qual = lista.get(idx).getBiologicalQualifierType(), lista.get(idx).getModelQualifierType()
225225 qualifierType = lista .get (idx ).getQualifierType ()
226226 qualifierDescription = (
@@ -230,8 +230,8 @@ def extractModelAnnotation(self):
230230 )
231231 if qualifierDescription not in metaInformation :
232232 metaInformation [qualifierDescription ] = set ([])
233- for idx2 in range (0 , lista . get ( idx ).getResources (). getLength ( )):
234- resource = lista . get ( idx ).getResources ().getValue (idx2 )
233+ for idx2 in range (0 , get_size ( get_item ( lista , idx ).getResources ())):
234+ resource = get_item ( lista , idx ).getResources ().getValue (idx2 )
235235 metaInformation [qualifierDescription ].add (resource )
236236 return metaInformation
237237
@@ -338,7 +338,7 @@ def getRawSpecies(self, species, parameters=[], logEntries=True):
338338 # by compartment
339339 if logEntries and standardizedName != "0" :
340340 if standardizedName in self .speciesMemory :
341- if len ( list ( self .model .getListOfCompartments () )) == 1 :
341+ if get_size ( self .model .getListOfCompartments ()) == 1 :
342342 standardizedName += "_" + species .getId ()
343343 else :
344344 # we can differentiate by compartment tag, no need to attach it to the name
@@ -649,23 +649,9 @@ def find_all_symbols(self, math, reactionID):
649649 )
650650 l = math .getListOfNodes ()
651651 replace_dict = {}
652-
653- # libSBML versions differ in how list-like objects expose size/length
654- if hasattr (l , "getSize" ):
655- size = l .getSize ()
656- elif hasattr (l , "size" ):
657- size = l .size ()
658- else :
659- try :
660- size = len (l )
661- except Exception :
662- size = 0
663-
652+ size = get_size (l )
664653 for inode in range (size ):
665- if hasattr (l , "get" ):
666- node = l .get (inode )
667- else :
668- node = l [inode ]
654+ node = get_item (l , inode )
669655 # Sympy doesn't like "def" in our string
670656 name = node .getName ()
671657 if name == "def" :
@@ -1293,9 +1279,9 @@ def __getRawRules(
12931279 for compartment in (self.model.getListOfCompartments()):
12941280 if compartment.getId() not in compartmentList:
12951281 if len(rReactant) != 2:
1296- rateL = '{0} * {1}'.format(rateL,compartment.getSize( ))
1282+ rateL = '{0} * {1}'.format(rateL, get_size(compartment ))
12971283 if len(rProduct) != 2:
1298- rateR = '{0} * {1}'.format(rateR,compartment.getSize( ))
1284+ rateR = '{0} * {1}'.format(rateR,get_size(compartment ))
12991285 """
13001286 return {
13011287 "reactants" : reactant ,
@@ -1621,7 +1607,7 @@ def __getRawCompartments(self, compartment):
16211607 """
16221608 idid = compartment .getId ()
16231609 name = compartment .getName ()
1624- size = compartment . getSize ( )
1610+ size = get_size ( compartment )
16251611 # volume messes up the reactions
16261612 # size = 1.0
16271613 dimensions = compartment .getSpatialDimensions ()
@@ -2871,7 +2857,7 @@ def check_noCompartment(self, parameters=[]):
28712857 self .bngModel .noCompartment = True
28722858 return
28732859 for compartment in self .model .getListOfCompartments ():
2874- self .compartmentDict [compartment .getId ()] = compartment . getSize ( )
2860+ self .compartmentDict [compartment .getId ()] = get_size ( compartment )
28752861 self .noCompartment = False
28762862 self .bngModel .noCompartment = False
28772863 # Get all rawSpecies
@@ -2945,7 +2931,7 @@ def default_to_regular(d):
29452931 speciesAnnotationInfo = default_to_regular (self .getFullAnnotation ())
29462932 annotationInfo = {"moleculeTypes" : {}, "species" : {}}
29472933 for compartment in self .model .getListOfCompartments ():
2948- compartmentDict [compartment .getId ()] = compartment . getSize ( )
2934+ compartmentDict [compartment .getId ()] = get_size ( compartment )
29492935 unitFlag = True
29502936 for species in self .model .getListOfSpecies ():
29512937 # making molecule and seed species objs for
@@ -2971,7 +2957,7 @@ def default_to_regular(d):
29712957 if rawSpecies ["returnID" ] in rawSpeciesName :
29722958 rawSpeciesName .remove (rawSpecies ["returnID" ])
29732959 if (
2974- translator [rawSpecies ["returnID" ]]. getSize ( ) == 1
2960+ get_size ( translator [rawSpecies ["returnID" ]]) == 1
29752961 and translator [rawSpecies ["returnID" ]].molecules [0 ].name
29762962 not in names
29772963 and translator [rawSpecies ["returnID" ]].molecules [0 ].name
@@ -3086,9 +3072,9 @@ def default_to_regular(d):
30863072 if self .noCompartment :
30873073 compartmentSize = 1.0
30883074 else :
3089- compartmentSize = self . model . getCompartment (
3090- rawSpecies ["compartment" ]
3091- ). getSize ()
3075+ compartmentSize = get_size (
3076+ self . model . getCompartment ( rawSpecies ["compartment" ])
3077+ )
30923078 newParameter = compartmentSize * newParameter
30933079 # temp testing AS
30943080 spec_obj .val = newParameter
@@ -3261,7 +3247,7 @@ def default_to_regular(d):
32613247 sorted (rawSpeciesName , key = len )
32623248 for species in rawSpeciesName :
32633249 if (
3264- translator [species ]. getSize ( ) == 1
3250+ get_size ( translator [species ]) == 1
32653251 and translator [species ].molecules [0 ].name not in names
32663252 ):
32673253 names .append (translator [species ].molecules [0 ].name )
@@ -3401,10 +3387,10 @@ def getSpeciesAnnotation(self):
34013387 annotationXML = species .getAnnotation ()
34023388 lista = libsbml .CVTermList ()
34033389 libsbml .RDFAnnotationParser .parseRDFAnnotation (annotationXML , lista )
3404- if lista . getSize ( ) == 0 :
3390+ if get_size ( lista ) == 0 :
34053391 self .speciesAnnotation [rawSpecies ["returnID" ]] = []
34063392 else :
3407- for idx in range (lista . getSize ( )):
3393+ for idx in range (get_size ( lista )):
34083394 self .speciesAnnotation [rawSpecies ["returnID" ]].append (
34093395 lista .get (idx ).getResources ()
34103396 )
@@ -3421,11 +3407,11 @@ def getFullAnnotation(self):
34213407 annotationXML = species .getAnnotation ()
34223408 lista = libsbml .CVTermList ()
34233409 libsbml .RDFAnnotationParser .parseRDFAnnotation (annotationXML , lista )
3424- if lista . getSize ( ) == 0 :
3410+ if get_size ( lista ) == 0 :
34253411 continue
34263412 else :
3427- for idx in range (lista . getSize ( )):
3428- for idx2 in range (0 , lista . get ( idx ).getResources (). getLength ( )):
3413+ for idx in range (get_size ( lista )):
3414+ for idx2 in range (0 , get_size ( get_item ( lista , idx ).getResources ())):
34293415 resource = lista .get (idx ).getResources ().getValue (idx2 )
34303416 qualifierType = lista .get (idx ).getQualifierType ()
34313417 qualifierDescription = (
@@ -3444,7 +3430,7 @@ def getModelAnnotation(self):
34443430 annotationXML = self .model .getAnnotation ()
34453431 lista = libsbml .CVTermList ()
34463432 libsbml .RDFAnnotationParser .parseRDFAnnotation (annotationXML , lista )
3447- if lista . getSize ( ) == 0 :
3433+ if get_size ( lista ) == 0 :
34483434 modelAnnotations = []
34493435 else :
34503436 tempDict = {}
0 commit comments