Exemplo n.º 1
0
def database_to_combine(system_type, settings_name, Plot_Variable, outputpath, KISAO_algorithm):
    '''Select model stored in database and generate the SBML file. 
    :param system_type: system type of model in string format
    :param settings_name: settings name of model in string format
    :param Plot_Variable: Variables to be plotted in list format
    :param outputpath:  filepath to output OMEX file in OS path format
    :param KISAO_algorithm:  Kinetic Simulation Algorithm Ontology number in string format   
    '''
    
    combinefilelist=[]
    number_scenario = 0

    
    search_result_settings  = sh.search_database(system_type, settings_name)
    core_model              = mh.quick_search(system_type)
    settings                = search_result_settings[0]
    
    #-- Checkers --
    plotvariablechecker(Plot_Variable, core_model)
    KISAOchecker(KISAO_algorithm)
    if system_type not in mh.list_models():
        raise Exception("Model is not in database")
    
    combinefilename, number_scenario = Combinecreator(core_model, settings, Plot_Variable, outputpath, KISAO_algorithm)
    combinefilelist.append(combinefilename)
   
    
        
    print()
    print('Number of Scenarios in COMBINE File=', number_scenario)
    print('COMBINE files outputed: ', combinefilelist)    
Exemplo n.º 2
0
def database_to_sbml(system_type, settings_name, output_path):
    '''Select model stored in database and generate the SBML file. 
    :param system_type:  system_type of model to search in database in string format
    :param settings_name:  settings_name of model to search in database in string format
    '''
    sbmlfilelist = []
    number_scenario = 0

    search_result_settings = sh.search_database(system_type, settings_name)
    search_result_model = mh.quick_search(system_type)
    core_model = search_result_model
    settings = search_result_settings[0]
    addparam = settings['parameters']
    number_init = len(settings['init'])
    number_parameters = len(settings['parameters'])

    unit_model = unitlookup(settings)

    for j in range(number_init):  #Cycle through number of init
        for k in range(number_parameters):  #Cycle through number of parameters
            sbmlstr = SBMLcreation(core_model, settings, unit_model, addparam,
                                   j, k)
            number_scenario = number_scenario + 1
            sbmlfilename = os.path.join(
                output_path, 'DatabasetoSBML_' + str(number_scenario) + '.xml')
            f = open(sbmlfilename, 'w')
            f.write(sbmlstr)
            f.close()
            del sbmlstr
            sbmlfilelist.append(sbmlfilename)
    #Function that creates SBML file and returns the number of files outputed and the file list.

    print()
    print('Number of Scenarios in Model =', number_scenario)
    print('SBML files outputed: ', sbmlfilelist)
Exemplo n.º 3
0
def autogenerate_sbml_from_folder(folderpath):
    '''To automatically generate the corresponding SBML files from the given
    folder containing all the configuration files.
    
    :param folderpath: the path to the folder containing all the configuration files.
    :type folderpath: str
    '''

    files = [
        f for f in glob.glob(os.path.join(folderpath, "**/*.ini"),
                             recursive=True)
    ]

    for f in files:
        print('\n', f)

    sbmlfilelist = []
    number_scenario = 0

    for f in files:  #Add ini files to database
        system_type = mh.config_to_database(f)
        system_types_settings_names = sh.config_to_database(f)
        system_type, settings_name = system_types_settings_names[0]
        search_result_model = mh.quick_search(system_type)
        search_result_settings = sh.quick_search(system_type=system_type,
                                                 settings_name=settings_name)
        core_model = search_result_model
        settings = search_result_settings
        addparam = settings['parameters']
        number_init = len(settings['init'])
        number_parameters = len(settings['parameters'])
        unit_model = unitlookup(settings)

        for j in range(number_init):  #Cycle through number of init values
            for k in range(
                    number_parameters):  #Cycle through number of parameters
                sbmlstr = SBMLcreation(core_model, settings, unit_model,
                                       addparam, j, k)
                number_scenario = number_scenario + 1
                placeholder = os.path.splitext(os.path.basename(f))[0]
                sbmlfilename = os.path.join(
                    folderpath, 'DatabasetoSBML_' + placeholder + '.xml')
                f = open(
                    sbmlfilename,
                    'w')  #creates SBML file in same folder as python script
                f.write(sbmlstr)
                f.close()
                del sbmlstr
                sbmlfilelist.append(sbmlfilename)

        #Function that creates SBML file and returns the number of files outputed and the file list.

    print()
    print('Number of Files Printed =', number_scenario)
    print('SBML files outputed: ', sbmlfilelist)
Exemplo n.º 4
0
def config_to_sbml(inifileslist, output_path):
    '''Read in list of configuration files and generate the corresponding SBML
    files.
    
    :param inifileslist: a list of input configuration files in strings.
    :type inifileslist: list
    '''

    sbmlfilelist = []
    number_scenario = 0

    for f in inifileslist:
        print('\n', f)

    for f in inifileslist:  #Add ini files to database
        print('filename', f)
        system_type = mh.config_to_database(f)
        system_types_settings_names = sh.config_to_database(f)
        system_type, settings_name = system_types_settings_names[0]
        search_result_model = mh.quick_search(system_type)
        search_result_settings = sh.quick_search(system_type=system_type,
                                                 settings_name=settings_name)
        core_model = search_result_model
        settings = search_result_settings
        addparam = settings['parameters']
        number_init = len(settings['init'])
        number_parameters = len(settings['parameters'])
        unit_model = unitlookup(settings)

        for j in range(number_init):  #Cycle through number of init values
            for k in range(
                    number_parameters):  #Cycle through number of parameters
                sbmlstr = SBMLcreation(core_model, settings, unit_model,
                                       addparam, j, k)
                #Function that creates SBML file and returns the number of files outputed and the file list.
                number_scenario = number_scenario + 1
                placeholder = os.path.splitext(f)[0]
                sbmlfilename = os.path.join(
                    output_path, 'DatabasetoSBML_' + placeholder + '.xml')
                f = open(
                    sbmlfilename,
                    'w')  #creates SBML file in same folder as python script
                f.write(sbmlstr)
                f.close()
                del sbmlstr
                sbmlfilelist.append(sbmlfilename)

    print()
    print('Number of Files Printed =', number_scenario)
    print('SBML files outputed: ', sbmlfilelist)
    print('}')
    print()
    '''
    The core_model data structure can be updated as follows.
    
    ir.dump_sg_results(sg_results, variables, config_data, user_core_models={}, save=True)
    
    For models in the database, the results for that model will be added to the 
    database if save is set to True. If the model is not in the database or 
    has been supplied using user_core_models, the results for that model will 
    not be saved in the database regardless of the value of save.
    '''

    #This will not be saved into the database
    system_type = config_data[1]['system_type']
    core_model1 = mh.quick_search(system_type)

    print('Printing core_model1["ia"] before update')
    print(core_model1['ia'])
    print()

    user_core_models = {system_type: core_model1}

    ir.dump_sg_results(sg_results,
                       variables,
                       config_data,
                       user_core_models=user_core_models,
                       save=False)

    print('Printing core_model1["ia"] after update')
    print(core_model1['ia'])
Exemplo n.º 6
0
    return helper


if __name__ == '__main__':
    '''
    0. Setting Up This Example
    '''
    '''
    This step adds the second model in the file to the database so that this 
    example can run smoothly.
    
    '''

    try:
        mh.quick_search('Inducible, Double, DegradingInducer, LogisticGrowth')
    except:
        mh.config_to_database(
            'Inducible_Double_DegradingInducer_LogisticGrowth.ini')
    '''
    1. Create a Custom Model
    '''
    model_files = ['Inducible_Double_Uptake_LogisticGrowth.ini']

    user_core_models = [mh.from_config(filename) for filename in model_files]
    user_core_models = {
        core_model['system_type']: core_model
        for core_model in user_core_models
    }
    '''
    user_core_models is a dictionary containing core_model data structures.
Exemplo n.º 7
0
from pathlib import Path
import os
import glob

import add_BMSS_to_path as lab
import BMSS.standardfiles_generators.sbmlgen as sbmlgen
import BMSS.models.model_handler as mh
import BMSS.models.settings_handler as sh
import tempfile
import BMSS.standardfiles_generators.simplesbml as simplesbml
import pytest


system_type       = 'TestModel, BMSS, LogicGate, gate, DelayActivationInput2'
settings_name     = '__default__'
core_model_1 = mh.quick_search(system_type)
settings = sh.quick_search(system_type=system_type, settings_name=settings_name)
addparam          = settings['parameters']
number_init       = len(settings['init'])
number_parameters = len(settings['parameters'])
unit_model        = sbmlgen.unitlookup(settings)
init_scenario     = 0
param_scenario    = 0
output_path = tempfile.gettempdir()

model_2 = simplesbml.SbmlModel()
model_2.addSpecies('Inde', 0)
model_2.addSpecies('Indi', 0)
model_2.addSpecies('mRNA1', 0)
model_2.addSpecies('Pep1', 0)
model_2.addSpecies('mRNA2', 0)
    #Refer to the Pandas documentation for DataFrame operations.
    df = mh.to_df()
    r = df[df['system_type'] == system_type]

    #Search the database
    #This returns a list of core_models with system_types containing the keyword
    #Try searching using the core model's id
    search_result_1 = mh.search_database('TestModel',
                                         search_type='system_type')
    core_model_1 = search_result_1[0]
    model_id = core_model_1['id']
    search_result_2 = mh.search_database(model_id, search_type='id')

    #If you already know the exact system_type, use quick_search to directly return the core model.
    #This function is a wrapper for search_database tha returns the first result.
    search_result_3 = mh.quick_search(system_type)

    #Deactivate a core model and remove it from searches.
    #Change name to reactivate
    mh.delete(system_type)

    #Check if it is still visible in the list view and search results
    new_lst = mh.list_models()
    search_result_5 = mh.search_database(system_type)

    #Note that you can still see it when exporting the database as a DataFrame
    new_df = mh.to_df()

    # #Restore it and see if it is searchable
    mh.restore(system_type)
    search_result_6 = mh.search_database(system_type)
Exemplo n.º 9
0
import tempfile
import tellurium as te, os
import BMSS.standardfiles_generators.combinegen as combinegen
import BMSS.models.model_handler as mh
import BMSS.models.settings_handler as sh

outputpath = tempfile.gettempdir()
model_name = "TestModel, Dummy, CellModel, CellularResources, ProteomeAllocation, RibosomeLimitation"  #Enter model name
settings_name = "__default__"  #usually "__default__" by default
Plot_Variable = ["r", "a",
                 "p"]  #, "rmq"] #Assign which variables you would like to plot
KISAO_algorithm = "kisao.0000071"
#Define which KISAO algorithm to use for tspan, write "0" if to use default CVODE

search_result_settings = sh.search_database(model_name, settings_name)
search_result_model = mh.quick_search(model_name)
core_model = search_result_model
settings = search_result_settings[0]

combinegen.database_to_combine(model_name, settings_name, Plot_Variable,
                               outputpath, KISAO_algorithm)


class TestCombinecreator:
    def test_model_in_database(self):
        #Model needs to be in databases for COMBINE to be generated
        #Checker is called in beginning of database_to_combine
        test_model_name = "TestModel, Dummy, CellModel, CellularResources, ProteomeAllocation, RibosomeLimitation"
        combinegen.database_to_combine(test_model_name, settings_name,
                                       Plot_Variable, outputpath,
                                       KISAO_algorithm)