Beispiel #1
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)
Beispiel #2
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)
    system_types_settings_names = sh.config_to_database(filename)

    system_type, settings_name = system_types_settings_names[0]

    #View the database
    #Get all system_types as a list
    lst = sh.list_settings()

    #Optional: Export a copy of the entire database as a DataFrame
    #Note that changes to the DataFrame do not affect the database.
    #Refer to the Pandas documentation for DataFrame operations.
    df = sh.to_df()
    r = df[df['system_type'] == system_type]

    #Retrieve param ensemble
    search_result1 = sh.quick_search(system_type=system_type,
                                     settings_name=settings_name)

    #Print search result
    for key in search_result1:
        print(key)
        print(search_result1[key])
        print()

    #Create a template
    sh.make_settings_template(system_types_settings_names,
                              filename='settings_template.ini')

    #Deactivate a settings and remove it from searches.
    sh.delete(system_type=system_type, settings_name=settings_name)

    #Check if it is still visible in the list view and search results
Beispiel #4
0
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)
model_2.addSpecies('Pep2', 0)