Skip to content

Commit

Permalink
implementing API
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Mar 12, 2018
1 parent 2ae0e36 commit d226abb
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
22 changes: 22 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
""" Tests API
:Author: Jonathan Karr <jonrkarr@gmail.com>
:Date: 2018-03-12
:Copyright: 2018, Karr Lab
:License: MIT
"""

import wc_lang
import types
import unittest


class ApiTestCase(unittest.TestCase):
def test(self):
self.assertIsInstance(wc_lang, types.ModuleType)
self.assertIsInstance(wc_lang.Model, type)
self.assertIsInstance(wc_lang.io, types.ModuleType)
self.assertIsInstance(wc_lang.config, types.ModuleType)
self.assertIsInstance(wc_lang.config.get_config, types.FunctionType)
self.assertIsInstance(wc_lang.sbml, types.ModuleType)
self.assertIsInstance(wc_lang.sbml.io, types.ModuleType)
16 changes: 16 additions & 0 deletions wc_lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@
with open(pkg_resources.resource_filename('wc_lang', 'VERSION'), 'r') as file:
__version__ = file.read().strip()
# :obj:`str`: version

# API
from .core import (TaxonRank, SubmodelAlgorithm, SpeciesTypeType, RateLawDirection, ReferenceType,
Model, Taxon, Submodel, ObjectiveFunction, Compartment,
SpeciesType, Species, Concentration,
Reaction, ReactionParticipant, RateLaw, RateLawEquation,
BiomassComponent, BiomassReaction, Parameter, Reference,
DatabaseReference)
from . import config
from . import io
from . import model_gen
from . import prepare
from . import rate_law_utils
from . import sbml
from . import transform
from . import util
2 changes: 1 addition & 1 deletion wc_lang/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.2'
from .core import get_config, get_debug_logs_config
7 changes: 5 additions & 2 deletions wc_lang/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from math import ceil, floor, exp, log, log10, isnan
from natsort import natsorted, ns
from six import with_metaclass, string_types
import pkg_resources
import re
import sys
from obj_model.core import (Model as BaseModel,
Expand All @@ -53,7 +54,9 @@
from wc_lang.sbml.util import (wrap_libsbml, str_to_xmlstr, LibSBMLError,
init_sbml_model, create_sbml_parameter, add_sbml_unit, UNIT_KIND_DIMENSIONLESS)
from wc_lang.rate_law_utils import RateLawUtils
import wc_lang

with open(pkg_resources.resource_filename('wc_lang', 'VERSION'), 'r') as file:
wc_lang_version = file.read().strip()

# wc_lang generates obj_model SchemaWarning warnings because some Models lack primary attributes.
# These models include RateLaw, ReactionParticipant, RateLawEquation, and Species.
Expand Down Expand Up @@ -471,7 +474,7 @@ class Model(BaseModel):
name = StringAttribute()
version = RegexAttribute(min_length=1, pattern='^[0-9]+\.[0-9+]\.[0-9]+', flags=re.I)
wc_lang_version = RegexAttribute(min_length=1, pattern='^[0-9]+\.[0-9+]\.[0-9]+', flags=re.I,
default=wc_lang.__version__, verbose_name='wc_lang version')
default=wc_lang_version, verbose_name='wc_lang version')
comments = LongStringAttribute()

class Meta(BaseModel.Meta):
Expand Down
2 changes: 2 additions & 0 deletions wc_lang/sbml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import io
from . import util
17 changes: 11 additions & 6 deletions wc_lang/sbml/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
from six import iteritems

from obj_model.core import Validator
from wc_lang.core import (Model, Taxon, Submodel, ObjectiveFunction, Compartment, SpeciesType,
Species, Concentration, Reaction, ReactionParticipant, RateLaw, RateLawEquation,
BiomassComponent, BiomassReaction, Parameter, Reference, DatabaseReference, SubmodelAlgorithm)
from wc_lang.sbml.util import (init_sbml_model, SBML_LEVEL, SBML_VERSION, create_sbml_doc_w_fbc)
import wc_lang.core

'''
wc_lang to SBML mapping to support FBA modeling
Expand Down Expand Up @@ -106,7 +104,7 @@ def run(model, algorithms=None, path=None):
otherwise a list of SBML file(s) created
"""
if algorithms is None:
algorithms = [SubmodelAlgorithm.dfba]
algorithms = [wc_lang.core.SubmodelAlgorithm.dfba]
sbml_documents = {}
for submodel in model.get_submodels():
if submodel.algorithm in algorithms:
Expand Down Expand Up @@ -188,8 +186,15 @@ def write(objects):
# Reaction must precede ObjectiveFunction
# BiomassReaction must precede ObjectiveFunction
# This partial order is satisfied by this sequence:
model_order = [Submodel, Compartment, Parameter, Species,
Reaction, BiomassReaction, ObjectiveFunction]
model_order = [
wc_lang.core.Submodel,
wc_lang.core.Compartment,
wc_lang.core.Parameter,
wc_lang.core.Species,
wc_lang.core.Reaction,
wc_lang.core.BiomassReaction,
wc_lang.core.ObjectiveFunction,
]

# add objects into libsbml.SBMLDocument
for model in model_order:
Expand Down

0 comments on commit d226abb

Please sign in to comment.