def parse( self, rxnfile ): rxnParser = ReactionParser() result = {} #currently reaction are parsed in an unordered form. self.startFile(rxnfile) d = self.getTagedLine() while d != None: if d != "": reaction = rxnParser.parseEquation(d["Equation"]) reaction.setId(d["Name"]) reaction.setName(d["OfficialName"]) reaction.setEquation(d["Equation"]) reaction.annotation = d.annotation result[d["Name"]] = reaction d = self.getTagedLine() self.closeFile() return result
def __init__( self, delimiter='\t', comment='#' ): FlatFileParser.__init__( self, delimiter, comment ) self.reactionParser = ReactionParser() requiredHeaders = { "Abbreviation":"name", "Equation":"equation", "Lower Bound":"lowerBound", "Upper Bound":"upperBound" } optionalHeaders = {"objective":"objective"} self.addRequiredHeaders( requiredHeaders ) self.addOptionalHeaders( optionalHeaders ) self.setObjectiveTag( "objective function" )
class FluxAnalysisFlatFileParser( FlatFileParser ): def __init__( self, delimiter='\t', comment='#' ): FlatFileParser.__init__( self, delimiter, comment ) self.reactionParser = ReactionParser() requiredHeaders = { "Abbreviation":"name", "Equation":"equation", "Lower Bound":"lowerBound", "Upper Bound":"upperBound" } optionalHeaders = {"objective":"objective"} self.addRequiredHeaders( requiredHeaders ) self.addOptionalHeaders( optionalHeaders ) self.setObjectiveTag( "objective function" ) def setObjectiveTag( self, objectiveTag ): self.objectiveTag = objectiveTag def parseReactionLine( self, line ): name = line["name"] equation = line["equation"] reaction = self.reactionParser.parse( name, "", "", equation ) return reaction def parseLimitLine( self, line ): lower = line["lowerBound"] upper = line["upperBound"] return ( lower, upper ) def parseObjectiveLine( self, line ): return -1 def parse( self, analysisFile ): lines = self.parseFile( analysisFile ) objective = Objective() limit = FluxLimit() reactions = {} for line in lines: name = line["name"] reaction = Reaction() reaction = self.parseReactionLine( line ) reactions[name] = reaction if line["objective"] == self.objectiveTag: objectiveValue = self.parseObjectiveLine( line ) objective[name] = objectiveValue else: limitValue = self.parseLimitLine( line ) if reaction.direction == 'IRREVERSIBLE-LEFT-TO-RIGHT': ( lower, upper ) = limitValue limitValue = ( 0.0, upper ) limit[name] = limitValue return ( reactions, objective, limit )