Example #1
0
    def test_delete(self):
        global core_model_1

        system_type = core_model_1['system_type']
        lst = mh.list_models()
        assert core_model_1['system_type'] in lst
        mh.delete(system_type)

        #Check if in database
        lst = mh.list_models()
        assert system_type not in lst
Example #2
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)    
Example #3
0
 def test_autogenerate_sbml_from_folder(self):
     #Test if the function is correctly taking in Config files from folder 
     #and outputting to Tempdir
     inputpath = (Path.cwd()/'ConfigSBML')
     output_path_auto = os.path.join(output_path, 'ConfigSBML')
         
     files = [f for f in glob.glob(os.path.join(inputpath,"**/*.ini"), recursive=True)]
     
     for file in files:
         core_model_test = mh.from_config(file)
         system_type = core_model_test['system_type']
         settings_name = 'Setting_test1'
         mh.delete(system_type)
         sh.delete(system_type=system_type, settings_name=settings_name)
         assert system_type not in (mh.list_models()), 'Model was not deleted'
         assert system_type not in (sh.list_settings()), 'settings was not deleted'
         
     sbmlgen.autogenerate_sbml_from_folder(inputpath, output_path_auto)
     
     for outputfile in files:
         placeholder = outputfile.replace(str(inputpath), '')
         placeholder = placeholder.replace('.ini', '')
         placeholder = placeholder.replace('\\', '')
         filename = os.path.join(output_path_auto, 'DatabasetoSBML_' + placeholder +'.xml')
         print('This is the file name:', filename)
         print()
         assert os.path.exists(filename) == True, "File did not output properly" 
Example #4
0
    def test_restore(self):
        global core_model_1

        system_type = core_model_1['system_type']
        mh.restore(system_type)

        #Check if in database
        lst = mh.list_models()
        assert system_type in lst
Example #5
0
    def test_add_to_database(self):
        '''
        Note: add_to_database already makes calls to search/quick_search
        '''
        global core_model_1

        core_model = core_model_1

        mh.add_to_database(core_model, dialog=False)

        #Check if in database
        lst = mh.list_models()
        assert core_model['system_type'] in lst
Example #6
0
 def test_config_to_sbml(self):
     #Test if files are output correctly
     filelist = ['TestModel_LogicGate_ORgate_DelayActivation_DelayActivation.ini',
                 'TestModel_CellModel_CellularResources_ProteomeAllocation_RibosomeLimitation.ini']
     
     for file in filelist:
         core_model_test = mh.from_config(file)
         system_type = core_model_test['system_type']
         settings_name = 'Setting_test1'
         mh.delete(system_type)
         sh.delete(system_type=system_type, settings_name=settings_name)
         assert system_type not in (mh.list_models()), 'Model was not deleted'
         assert system_type not in (sh.list_settings()), 'settings was not deleted'
         
     sbmlgen.config_to_sbml(filelist, output_path)
         
     for outputfile in filelist:
         placeholder = outputfile.replace('.ini', '')
         filename = os.path.join(output_path, 'DatabasetoSBML_' + placeholder +'.xml')
         assert os.path.exists(filename) == True, "File did not output properly"
plt.close('all')

if __name__ == '__main__':

    outputpath = (Path.cwd())
    #Where the COMBINE file will be outputed to, working directory by default
    print(outputpath)
    '''
    Use the following section to add model to database from config file.
    '''
    filename = "TestModel_Repressilator_OMEX_example.ini"

    #Add model to database and view all the models in the database
    system_type = mh.config_to_database(filename)
    lst = mh.list_models()
    print(lst)

    #Add settings to database and view all the settings in the database
    system_types_settings_names = sh.config_to_database(filename)
    lst_setting = sh.list_settings()
    print(lst_setting)
    '''
    Use database_to_combine to create a COMBINE archive from an existing model in database.
    '''
    model_name = "Test_Model, OMEX, Repressilator, Example"  #Enter model name
    settings_name = "__default__"  #usually "__default__" by default
    Plot_Variable = [
        "X", "Y", "Z"
    ]  #, "rmq"] #Assign which variables you would like to plot
    KISAO_algorithm = "0"
Example #8
0
 def test_database_to_sbml_fail(self):
     #Test if model declared is in database
     system_type_fail = "TestModel_fail"
     assert system_type_fail in mh.list_models(), 'Model not in database'
     sbmlgen.database_to_sbml(system_type, settings_name, output_path)
- Add, edit and retrieve models.
- Delete and restore models.

'''

if __name__ == '__main__':
    #Fill in the filenames here
    filename = 'TestModel_Dummy.ini'

    #Add new core model/Replace existing core model
    #Note that this assigns a unique id to the core model that is then printed to the console.
    system_type = mh.config_to_database(filename)

    #View the database
    #Get all system_types as a list
    lst = mh.list_models()

    #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 = 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')