Commit e6517a1d authored by Elad Noor's avatar Elad Noor

adding option to initialize Pathway with SBtab from a stream

parent f759a9d5
......@@ -50,8 +50,8 @@ Import the API and create an instance. Creating the EquilibratorAPI class
instance reads all the data that is used to calculate thermodynamic potentials of reactions.
```python
from equilibrator_api import ComponentContribution, Reaction, ureg
eq_api = ComponentContribution(p_h=ureg("6.5"), ionic_strength=ureg('200 mM')) # set pH and I
from equilibrator_api import ComponentContribution, Reaction, Q_
eq_api = ComponentContribution(p_h=Q_("6.5"), ionic_strength=Q_('200 mM')) # set pH and I
```
You can parse a reaction from a KEGG-style reaction string. The example given
......@@ -79,14 +79,14 @@ calculate the standard change in Gibbs potential due to this reaction.
# You control the pH and ionic strength!
# ionic strength is in Molar units.
standard_dg_prime, uncertainty = eq_api.standard_dg_prime(rxn)
print("dG0' = %s \u00B1 %sl\n" % (standard_dg_prime, uncertainty))
print("dG0' = %s \u00B1 %s\n" % (standard_dg_prime, uncertainty))
```
You can also calculate the [reversibility index](https://doi.org/10.1093/bioinformatics/bts317) for this reaction.
```python
ln_RI = eq_api.ln_reversibility_index(rxn)
print('ln(Reversibility Index) = %.1f\n' % ln_RI)
print('ln(Reversibility Index) = %s\n' % ln_RI)
```
The reversibility index is a measure of the degree of the reversibility of the
......@@ -96,15 +96,12 @@ reactions are much "easier" to reverse than reactions with 1:1 or 2:2 reactions.
You can see the paper linked above for more information.
### Example of pathway analysis using Max-min Driving Force:
First, download an example configuration file (in SBtab format):
```
curl https://gitlab.com/elad.noor/equilibrator-api/raw/develop/tests/test_unit/pathway_ethanol_SBtab.tsv > example.tsv
```
Then inside the python3 shell:
Download an example pathway, run Max-min Driving Force analysis and generate two result figures
```python
from equilibrator_api import Pathway
pp = Pathway.from_sbtab('example.tsv')
from urllib.request import urlopen
url = "https://gitlab.com/elad.noor/equilibrator-api/raw/develop/tests/test_unit/pathway_ethanol_SBtab.tsv"
pp = Pathway.from_sbtab(urlopen(url))
mdf_res = pp.calc_mdf()
print('MDF = %s' % mdf_res.mdf)
mdf_res.reaction_plot.show()
......@@ -113,8 +110,8 @@ mdf_res.compound_plot.show()
## Dependencies:
- python >= 3.6
- equilibrator-cache
- component-contribution
- equilibrator-cache (latest)
- component-contribution (latest)
- sbtab
- numpy
- scipy
......
......@@ -26,6 +26,7 @@
import csv
from io import IOBase
import logging
from typing import Callable, Iterable, List, TextIO, Tuple
......@@ -223,13 +224,18 @@ class Pathway(object):
return PhasedReaction(sparse)
@classmethod
def from_sbtab(self, file_name: str) -> object:
def from_sbtab(self, sbtab) -> object:
"""
read the sbtab file (can be a filename or file handel)
and use it to initialize the Pathway
"""
sbtabdoc = SBtab.read_csv(file_name, 'pathway')
if type(sbtab) == str:
sbtabdoc = SBtab.read_csv(sbtab, "pathway")
elif isinstance(sbtab, IOBase):
sbtab_contents = sbtab.read()
if type(sbtab_contents) == bytes:
sbtab_contents = sbtab_contents.decode('utf-8')
sbtabdoc = SBtab.SBtabDocument("pathway", sbtab_contents, "unnamed_sbtab.tsv")
table_ids = ['ConcentrationConstraint', 'Reaction', 'RelativeFlux',
'Parameter']
dfs = []
......
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