def main(rdir, eqnfn, molfn, outfn):

    print ("Loading molecule names... ")
    # dictionary where keys are mol ids (C00001) and
    # items are names from second column of kegg-compounds file
    mol2name = common.parse_molecule_names(molfn)
    print "Loading reconstruction: %s/%s" % (rdir, common.NETWORK_REACTION_FILE)
    f = open("%s/%s" % (rdir, common.NETWORK_REACTION_FILE))
    bf = open(eqnfn)
    reco = common.read_reconstruction(f)
    eqns = read_balanced_reactions(bf)
    print "%d reactions" % (len(reco))
    write_matrix(reco, eqns, mol2name, outfn)
def main(rdir, eqnfn, molfn, outfn):
    mol2name = {}
    f = open(molfn)
    for s in f:
        molid, name, name2 = s.strip().split("\t")
        mol2name[molid] = name
    print "Loading reconstruction: %s/%s" % (rdir, common.NETWORK_REACTION_FILE)
    f = open("%s/%s" % (rdir, common.NETWORK_REACTION_FILE))
    bf = open(eqnfn)
    reco = common.read_reconstruction(f)
    eqns = read_balanced_reactions(bf)
    print "%d reactions" % (len(reco))
    write_matrix(reco, eqns, mol2name, outfn)
def main(rdir, eqnfn, molfn, taxon, modelid, modelname, species, outfn):
    mol2name = {}
    f = open(molfn)
    for s in f:
        molid, name, name2 = s.strip().split("\t")
        mol2name[molid] = name
    print "Loading reconstruction: %s/%s" % (rdir, common.NETWORK_REACTION_FILE)
    f = open("%s/%s" % (rdir, common.NETWORK_REACTION_FILE))
    bf = open(eqnfn)
    reco = common.read_reconstruction(f)
    eqns = read_balanced_reactions(bf)
    print "%d reactions" % (len(reco))
    sbml = convert_to_SBML(reco, eqns, mol2name, taxon, modelid, modelname, species)
    libsbml.writeSBMLToFile(sbml, outfn)
def main():
    if len(sys.argv) == 3:
        ddir = sys.argv[1]  # reconstruction result directory
        ofn = sys.argv[2]   # output
        reco = common.read_reconstruction(open("%s/%s" % (ddir, common.NETWORK_REACTION_FILE)))
        convert(reco, open(ofn, "w"))
    elif len(sys.argv) == 2:
        pdir = sys.argv[1]  # project dir, reconstruction dirs as subdirs
        convert_multiple_dirs(pdir)
    else:
        print """Usage:
%s reco-dir output 
%s project-dir
""" % (sys.argv[0], sys.argv[0])
Example #5
0
def main(rdir, eqnfn, molfn, outfn):
    mol2name = {}
    f = open(molfn)
    for s in f:
        molid, name, name2 = s.strip().split("\t")
        mol2name[molid] = name
    print "Loading reconstruction: %s/%s" % (rdir,
                                             common.NETWORK_REACTION_FILE)
    f = open("%s/%s" % (rdir, common.NETWORK_REACTION_FILE))
    bf = open(eqnfn)
    reco = common.read_reconstruction(f)
    eqns = read_balanced_reactions(bf)
    print "%d reactions" % (len(reco))
    write_matrix(reco, eqns, mol2name, outfn)
Example #6
0
def main():
    if len(sys.argv) == 3:
        ddir = sys.argv[1]  # reconstruction result directory
        ofn = sys.argv[2]  # output
        reco = common.read_reconstruction(
            open("%s/%s" % (ddir, common.NETWORK_REACTION_FILE)))
        convert(reco, open(ofn, "w"))
    elif len(sys.argv) == 2:
        pdir = sys.argv[1]  # project dir, reconstruction dirs as subdirs
        convert_multiple_dirs(pdir)
    else:
        print """Usage:
%s reco-dir output 
%s project-dir
""" % (sys.argv[0], sys.argv[0])
Example #7
0
def main(rdir, eqnfn, molfn, taxon, modelid, modelname, species, outfn):
    mol2name = {}
    f = open(molfn)
    for s in f:
        molid, name, name2 = s.strip().split("\t")
        mol2name[molid] = name
    print "Loading reconstruction: %s/%s" % (rdir,
                                             common.NETWORK_REACTION_FILE)
    f = open("%s/%s" % (rdir, common.NETWORK_REACTION_FILE))
    bf = open(eqnfn)
    reco = common.read_reconstruction(f)
    eqns = read_balanced_reactions(bf)
    print "%d reactions" % (len(reco))
    sbml = convert_to_SBML(reco, eqns, mol2name, taxon, modelid, modelname,
                           species)
    libsbml.writeSBMLToFile(sbml, outfn)
def main(rdir, eqnfn, molfn, taxon, modelid, modelname, species, outfn, sbmlversion, boundsfile,  rxnnamefile=None, pathwayfile=None):
    print("Loading molecule names... ")
    # dictionary where keys are mol ids (C00001) and
    # items are names from second column of kegg-compounds file
    mol2name = common.parse_molecule_names(molfn)
    print "Loading reconstruction: %s/%s" % (rdir, common.NETWORK_REACTION_FILE)
    f = open("%s/%s" % (rdir, common.NETWORK_REACTION_FILE))
    bf = open(eqnfn)
    reco = common.read_reconstruction(f)
    eqns = read_balanced_reactions(bf)
    if pathwayfile is not None:
        fp = open(pathwayfile)
        pathways={};
        pathwayasnames={};
        for s in fp: 
            #print s
            sisalto = s.strip().split("\t") 
            #print len(sisalto)
            if len(sisalto)>1:
                pathways[sisalto[0]]=sisalto[1]
            if len(sisalto)>2:
                pathwayasnames[sisalto[0]]=sisalto[2]
        if len(pathwayasnames) == 0:
            pathwayasnames = None
    else:
        pathways = None
    if rxnnamefile is not None:
        fp = open(rxnnamefile)
        rxnnames={};
        for s in fp: 
            sisalto = s.strip().split("\t") 
            if len(sisalto)>1:
                rxnnames[sisalto[0]]=sisalto[1]
                #print ("rxnnames[%s] = %s" % (sisalto[0],sisalto[1]))                
    else:
        rxnnames = None
        
    bounds={};
    if boundsfile is not None:
        fp = open(boundsfile)        
        for s in fp: 
            sisalto = s.strip().split("\t") 
            if len(sisalto)>1:
                bounds[sisalto[0].strip()]=sisalto[3] +","+ sisalto[4]
  #  print "%d reactions" % (len(reco))
    sbml = convert_to_SBML(reco, eqns, mol2name, taxon, modelid, modelname, species, sbmlversion, bounds,  rxnnames, pathways, pathwayasnames)
    libsbml.writeSBMLToFile(sbml, outfn)
def main(inputdir, ecfile):

    ec2r, r2ec = common.read_ec_list(open(ecfile))

    reactions = common.read_stoichiometry(open(STOICHIOMETRY)).reactions
    reco = common.read_reconstruction(open("%s/%s" % (inputdir, common.NETWORK_REACTION_FILE)))
    cofactors = common.read_set(open(COFACTORS))
    o = open("%s/%s" % (inputdir, common.FILE_EC_GRAPH), "w")

    R = set()
    for r in reco:
        baser = r.split("_")[0].replace("#","_")
        #baser = r.split("_")[0]
        R.add(baser)

    E = {}
    for r in R:
        if r in reactions:
            re = reactions[r]
            if r not in E:
                E[r] = {}
            for m in re.substrates:
                if m not in E:
                    E[m] = {}
                E[m][r] = 1
                E[r][m] = 1
            for m in re.products:
                if m not in E:
                    E[m] = {}
                E[r][m] = 1
                E[m][r] = 1
   
    ecg = {}
    for r in E:
        if r not in r2ec:
            continue
        ec1 = r2ec[r]
        for m in E[r]:
            if m in E:
                for r2 in E[m]:
                    if r == r2:
                        continue
                    if r2 not in r2ec:
                        continue
                    ec2 = r2ec[r2]
                    for e1 in ec1:
                        if e1 not in ecg:
                            ecg[e1] = {}
                        for e2 in ec2:
                            if e2 not in ecg[e1]:
                                ecg[e1][e2] = set()
                            ecg[e1][e2].add(m)

    o.write("#Output of \"%s\" on %s\n" % (" ".join(sys.argv), datetime.datetime.now()))
    cofs = list(cofactors)
    cofs.sort()
    o.write("#Cofactors: %s\n" % (",".join(cofs)))
    o.write("#EC1 EC2 SharedMetabolites AllCofactors\n")
    k1 = ecg.keys()
    k1.sort()
    for ec1 in k1:
        k2 = ecg[ec1].keys()
        k2.sort()
        for ec2 in k2:
            cofactor = 1
            for m in ecg[ec1][ec2]:
                if m not in cofactors:
                    cofactor = 0
            if cofactor and REMOVE_COFACTORS:
                continue
            o.write("%s\t%s\t%s\t%s\n" % (ec1, ec2, ",".join(ecg[ec1][ec2]), cofactor))
def convert_dir(ddir):
    reco = common.read_reconstruction(open("%s/%s" % (ddir, common.NETWORK_REACTION_FILE)))
    convert(reco, open("%s/%s" % (ddir, common.NETWORK_ECLIST_FILE), "w"))
Example #11
0
def main(inputdir):
    ec2r, r2ec = common.read_ec_list(open(common.FILE_EC_MAP))
    reactions = common.read_stoichiometry(open(STOICHIOMETRY)).reactions
    reco = common.read_reconstruction(open("%s/%s" % (inputdir, common.NETWORK_REACTION_FILE)))
    cofactors = common.read_set(open(COFACTORS))
    o = open("%s/%s" % (inputdir, common.FILE_EC_GRAPH), "w")

    R = set()
    for r in reco:
        baser = r.split("_")[0]
        R.add(baser)

    E = {}
    for r in R:
        if r in reactions:
            re = reactions[r]
            if r not in E:
                E[r] = {}
            for m in re.substrates:
                if m not in E:
                    E[m] = {}
                E[m][r] = 1
                E[r][m] = 1
            for m in re.products:
                if m not in E:
                    E[m] = {}
                E[r][m] = 1
                E[m][r] = 1
   
    ecg = {}
    for r in E:
        if r not in r2ec:
            continue
        ec1 = r2ec[r]
        for m in E[r]:
            if m in E:
                for r2 in E[m]:
                    if r == r2:
                        continue
                    if r2 not in r2ec:
                        continue
                    ec2 = r2ec[r2]
                    for e1 in ec1:
                        if e1 not in ecg:
                            ecg[e1] = {}
                        for e2 in ec2:
                            if e2 not in ecg[e1]:
                                ecg[e1][e2] = set()
                            ecg[e1][e2].add(m)

    o.write("#Output of \"%s\" on %s\n" % (" ".join(sys.argv), datetime.datetime.now()))
    cofs = list(cofactors)
    cofs.sort()
    o.write("#Cofactors: %s\n" % (",".join(cofs)))
    o.write("#EC1 EC2 SharedMetabolites AllCofactors\n")
    k1 = ecg.keys()
    k1.sort()
    for ec1 in k1:
        k2 = ecg[ec1].keys()
        k2.sort()
        for ec2 in k2:
            cofactor = 1
            for m in ecg[ec1][ec2]:
                if m not in cofactors:
                    cofactor = 0
            if cofactor and REMOVE_COFACTORS:
                continue
            o.write("%s\t%s\t%s\t%s\n" % (ec1, ec2, ",".join(ecg[ec1][ec2]), cofactor))
Example #12
0
def convert_dir(ddir):
    reco = common.read_reconstruction(
        open("%s/%s" % (ddir, common.NETWORK_REACTION_FILE)))
    convert(reco, open("%s/%s" % (ddir, common.NETWORK_ECLIST_FILE), "w"))