def parse_json_file(file): # returns a tuple: (species,reactions,compartments) # species: { 'id' : Species(...) } # reactions: { 'id' : Reaction(...) } # compartments { 'id' : ('name','outside') } model = util.parse_json_file(file) compartments = {} for compartment in model['compartments']: compartments[compartment['id']] = (compartment['name'],compartment['outside']) species = {} for sp in model['species']: species[sp['id']] = Species(sp['id'],name=sp['name'],compartment=sp['compartment']) reactions = {} for reaction in model['reactions']: reactants = [copy.deepcopy(species[s]) for s in reaction['reactants']] products = [copy.deepcopy(species[s]) for s in reaction['products']] reactions[reaction['id']] = Reaction(reaction['id'], reactants=reactants, products=products, reversible=reaction['reversible'], subsystem=reaction['subsystem']) return species,reactions,compartments
def parse_json_file(file): # returns a tuple: (species,reactions,compartments) # species: { 'id' : Species(...) } # reactions: { 'id' : Reaction(...) } # compartments { 'id' : ('name','outside') } model = util.parse_json_file(file) compartments = {} for compartment in model['compartments']: compartments[compartment['id']] = (compartment['name'], compartment['outside']) species = {} for sp in model['species']: species[sp['id']] = Species(sp['id'], name=sp['name'], compartment=sp['compartment']) reactions = {} for reaction in model['reactions']: reactants = [copy.deepcopy(species[s]) for s in reaction['reactants']] products = [copy.deepcopy(species[s]) for s in reaction['products']] reactions[reaction['id']] = Reaction(reaction['id'], reactants=reactants, products=products, reversible=reaction['reversible'], subsystem=reaction['subsystem']) return species, reactions, compartments
def read_json_config_file(filename): defaults.clear() defaults.update(util.parse_json_file(filename)) def to_fn(key): # convert a string to a lambda expression in defaults if key in defaults: defaults[key] = eval(defaults[key]) # these two parameters are stored as strings in JSON, but should really be lambdas to_fn("METABOLITE_LABEL_TRANSFORM") to_fn("REACTION_LABEL_TRANSFORM")
def read_met_file(filename): minors = [] json = filename.endswith('.json') if json: for minor in util.parse_json_file(filename)['minor_counts']: if minor['minor']: minors.append(minor['name']) else: with open(filename) as infile: for line in iter(infile): _, _, name = line.partition("\t") if name[0] == '*': minors.append(name.rstrip()[1:]) return minors
def read_met_file(filename): minors = [] json = filename.endswith('.json') if json: for minor in util.parse_json_file(filename)['minor_counts']: if minor['minor']: minors.append(minor['name']) else: with open(filename) as infile: for line in iter(infile): _,_,name = line.partition("\t") if name[0] == '*': minors.append(name.rstrip()[1:]) return minors