Example #1
0
    def FromFiles():
        feist = Feist()
        reaction_file = '../data/metabolic_models/iAF1260_reactions.csv'

        # Read compounds ids 2 Kegg cid's mapping file into a dict

        counters = {
            'kegg_error': 0,
            'translocation': 0,
            'exchange': 0,
            'sink': 0,
            'unbalanced': 0,
            'okay': 0
        }
        for row in csv.DictReader(open(reaction_file, 'r')):
            #if 'Transport' in row['subSystem']:
            #    counters['translocation'] += 1
            #    continue
            if row['abbreviation'][0:3] == 'EX_':
                counters['exchange'] += 1
                continue
            if row['abbreviation'][0:3] == 'DM_':
                counters['sink'] += 1
                continue

            sparse = Feist.parse_equation(row['equation'])
            kegg_sparse = {}
            for biggID, coeff in sparse.iteritems():
                keggID = feist.bigg2kegg[biggID]
                kegg_sparse[keggID] = kegg_sparse.get(keggID, 0) + coeff

            if 0 in kegg_sparse:
                logging.debug('Some compounds are missing KEGG IDs in %s: %s' %
                              (row['abbreviation'], row['equation']))
                counters['kegg_error'] += 1
                continue

            for keggID in [k for k, v in kegg_sparse.iteritems() if v == 0]:
                del kegg_sparse[keggID]

            directionality = row["directionality without uncertainty (pH 7.2)"]
            #directionaliry = row['reconstruction directionality']
            if directionality == 'reversible':
                direction = '<=>'
            elif directionality == 'forward only':
                direction = '=>'
            elif directionality == 'reverse only':
                direction = '<='
            else:
                raise ValueError('unknown directionality tag: ' +
                                 directionality)

            reaction = Reaction(row['abbreviation'],
                                kegg_sparse,
                                direction=direction)
            if row['delta G (pH 7)'] == 'Not calculated':
                dG0 = np.nan
            else:
                dG0 = float(row['delta G (pH 7)']) * J_per_cal

            try:
                reaction.Balance(balance_water=True,
                                 exception_if_unknown=False)
                counters['okay'] += 1
            except KeggReactionNotBalancedException as e:
                logging.debug(str(e) + ' - ' + str(reaction))
                counters['unbalanced'] += 1
                continue

            feist.reactions.append(reaction)
            feist.dG0s.append(dG0)

        logging.debug(" ; ".join(
            ["%s : %d" % (key, val) for (key, val) in counters.iteritems()]))
        return feist
Example #2
0
    #H.ToDatabase(db, 'hatzi_gc')
    #H.I = 0.25
    #H.T = 300;
    #sparse_reaction = {13:-1, 1:-1, 9:2}
    #sparse_reaction = {36:-1, 3981:1}
    #sparse_reaction = {6:-1, 143:-1, 234:1, 5:1}
    #sparse_reaction = {1:-1, 499:-1, 603:1, 86:1}
    #sparse_reaction = {1:-1, 6:-1, 311:-1, 288:1, 5:1, 80:2, 26:1}
    #sparse_reaction = {408:-1, 6:-1, 4092:1, 5:1}
    #sparse_reaction = {588:-1, 1:-1, 114:1, 9:1}
    #sparse_reaction = {1:-1, 3:-1, 149:-1, 288:1, 4:1, 80:2, 22:1}
    react = Reaction("reaction", {408: -1, 6: -1, 4092: 1, 5: 1})

    #sys.stdout.write("The dG0_r of PPi + H20 <=> 2 Pi: \n\n")

    react.Balance()
    print react.FullReactionString()

    sys.stdout.write("%5s | %5s | %6s | %6s\n" % ("pH", "I", "T", "dG0_r"))
    for pH in np.arange(5, 10.01, 0.25):
        H_withpka.pH = pH
        sys.stdout.write("%5.2f | %5.2f | %6.1f | %6.2f\n" %
                         (H_withpka.pH, H_withpka.I, H_withpka.T,
                          react.PredictReactionEnergy(H_withpka)))

    for cid in react.get_cids():
        print '-' * 50
        print "C%05d - %s:" % (cid, H_withpka.kegg.cid2name(cid))
        print H_withpka.kegg.cid2inchi(cid)
        print "Pseudoisomers:\n", H_withpka.cid2PseudoisomerMap(cid)
        print "dG0'_f = %.1f kJ/mol" % H_withpka.cid2PseudoisomerMap(