Commit 34cd517e authored by Elad Noor's avatar Elad Noor

style changes to command line scripts

parent 35a2f16f
Pipeline #49958966 failed with stage
in 19 minutes and 39 seconds
......@@ -33,33 +33,34 @@ import sys
import numpy as np
import pandas as pd
from equilibrator_api import Q_, ComponentContribution, Reaction
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Calculate potentials for a number of reactions.')
parser.add_argument('infile', type=argparse.FileType('r'),
help='path to input file containing reactions')
help='path to input file containing reactions (TXT format)')
parser.add_argument('outfile', type=argparse.FileType('w'),
help='path to output file')
help='path to output file (CSV format)')
parser.add_argument('--plaintext', action='store_true',
help="'indicate that reactions are given in plain text"
help="indicate that reactions are given in plain text"
" (not accessions)")
parser.add_argument('--ph', type=str,
help='pH level',
default="7.0")
parser.add_argument('--i', type=str,
help='ionic strength',
help='ionic strength (in molar, default 0.25 M)',
default="0.25M")
parser.add_argument('--t', type=str,
help='ionic strength',
help='temperature (in kalvin, default 298.15 K)',
default="298.15K")
logging.getLogger().setLevel(logging.WARNING)
args = parser.parse_args()
from equilibrator_api import Q_, ComponentContribution, Reaction, ureg
ureg.default_format = ".2f"
p_h = Q_(args.ph)
assert p_h.check(None)
......@@ -75,9 +76,9 @@ if __name__ == '__main__':
else:
assert temperature.check("[temperature]")
sys.stderr.write('pH = %s\n' % p_h)
sys.stderr.write('I = %s\n' % ionic_strength)
sys.stderr.write('T = %s\n' % temperature)
sys.stderr.write(f"pH = {p_h}\n")
sys.stderr.write(f"I = {ionic_strength}\n")
sys.stderr.write(f"T = {temperature}\n")
sys.stderr.flush()
infile_lines = list(filter(None, map(str.strip, args.infile.readlines())))
......@@ -112,3 +113,4 @@ if __name__ == '__main__':
result_df.to_csv(args.outfile)
args.outfile.flush()
......@@ -34,26 +34,24 @@ import argparse
import logging
import sys
from equilibrator_api import Q_, ComponentContribution, Reaction
def MakeParser():
"""Parser for equilibrator_cmd."""
parser = argparse.ArgumentParser(
description=('Estimate the Gibbs energy of a reaction. For example,'
'the following calculates dGr0 for ATP hydrolysis '
'at pH 6: equlibrator_cmd.py --ph 6 "KEGG:C00002 + '
'KEGG:C00001 = KEGG:C00008 + KEGG:C00009"'))
'at pH 6: equlibrator_cmd.py --ph 6 "kegg:C00002 + '
'kegg:C00001 = kegg:C00008 + kegg:C00009"'))
parser.add_argument('--ph', type=str,
help='pH level',
default="7.0")
parser.add_argument('--i', type=str,
help='ionic strength',
help='ionic strength (in molar, default 0.25 M)',
default="0.25M")
parser.add_argument('--t', type=str,
help='ionic strength',
help='temperature (in kalvin, default 298.15 K)',
default="298.15K")
parser.add_argument('reaction', type=str, help='reaction in KEGG notation')
parser.add_argument('reaction', type=str, help='chemical formula using accessions')
return parser
......@@ -63,6 +61,9 @@ args = parser.parse_args()
logging.getLogger().setLevel(logging.WARNING)
from equilibrator_api import Q_, ComponentContribution, Reaction, ureg
ureg.default_format = ".2f"
p_h = Q_(args.ph)
assert p_h.check(None)
......@@ -79,7 +80,7 @@ else:
assert temperature.check("[temperature]")
sys.stderr.write(f"pH = {p_h}\n")
sys.stderr.write(f"I = {ionic_strength}\n")
sys.stderr.write(f"I = {ionic_strength:.2g}\n")
sys.stderr.write(f"T = {temperature}\n")
sys.stderr.flush()
......@@ -94,7 +95,13 @@ equilibrator = ComponentContribution(p_h=p_h, ionic_strength=ionic_strength)
n_e = reaction.check_half_reaction_balancing()
if n_e is None:
logging.error('reaction is not chemically balanced')
sys.stderr.write(f"This reaction is not chemically balanced:\n")
atom_bag = reaction._get_reaction_atom_bag()
for atom, count in atom_bag.items():
if count < 0:
sys.stderr.write(f"* {abs(count):g} extra '{atom}'s on the left-hand side\n")
else:
sys.stderr.write(f"* {abs(count):g} extra '{atom}'s on the right-hand side\n")
sys.exit(-1)
elif n_e == 0:
standard_dg_prime, dg_uncertainty = equilibrator.standard_dg_prime(reaction)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment