Example #1
0
def pe_sampled_ple_analysis(model_name,
                            filename,
                            parameter,
                            plots_dir,
                            fileout_param_estim_summary,
                            logspace=True,
                            scientific_notation=True):
    """
    Run the profile likelihood estimation analysis.

    :param model_name: the model name without extension
    :param filename: the filename containing the fits sequence
    :param parameter: the parameter to compute the PLE analysis
    :param plots_dir: the directory to save the generated plots
    :param fileout_param_estim_summary: the name of the file containing the summary for the parameter estimation
    :param logspace: true if parameters should be plotted in logspace
    :param scientific_notation: true if the axis labels should be plotted in scientific notation
    """

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); sampled_ple_analysis(\"' + model_name + \
              '\", \"' + filename + \
              '\", \"' + parameter + \
              '\", \"' + plots_dir + \
              '\", \"' + fileout_param_estim_summary + \
              '\", ' + str(logspace).upper() + \
              ', ' + str(scientific_notation).upper()
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += ')\''
    # print(command)
    run_cmd(command)
Example #2
0
def ps1_analyse_plot_homogen(model_name, inputdir, outputdir, repeat,
                             xaxis_label, yaxis_label):
    """
    Plot model single parameter scan time courses using homogeneous lines (Python wrapper).

    :param model_name: the model name without extension
    :param inputdir: the input directory containing the simulated data
    :param outputdir: the output directory that will contain the simulated plots
    :param repeat: the simulation number
    :param xaxis_label: the label for the x axis (e.g. Time [min])
    :param yaxis_label: the label for the y axis (e.g. Level [a.u.])
    """
    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); plot_single_param_scan_data_homogen(\"' + model_name + \
              '\", \"' + inputdir + \
              '\", \"' + outputdir + \
              '\", \"' + repeat
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\", \"' + xaxis_label + \
               '\", \"' + yaxis_label + \
               '\")\''
    # print(command)
    run_cmd(command)
Example #3
0
def run_copasi_model(infile):
    """
    Run a Copasi model

    :param infile: the input file
    """
    command = which("CopasiSE") + " " + infile
    run_cmd(command)
Example #4
0
def run_generic_model(infile):
    """
    Run a generic model

    :param infile: the input file
    """
    command = which("python") + " " + infile + \
              " " + os.path.basename(infile)[:-4] + ".csv"
    run_cmd(command)
Example #5
0
def pe_combine_param_ple_stats(plots_dir, fileout_param_estim_details):
    """
    Combine the statistics for the parameter estimation details

    :param plots_dir: the directory to save the generated plots
    :param fileout_param_estim_details: the name of the file containing the detailed statistics for the estimated parameters
    """

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); combine_param_ple_stats(\"' + plots_dir + \
              '\", \"' + fileout_param_estim_details
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\")\''
    # print(command)
    run_cmd(command)
Example #6
0
def sim_analyse_gen_stats_table(inputfile, outputfile, variable):
    """
    Plot model simulation time courses (Python wrapper).

    :param inputfile: the file containing the repeats
    :param outputfile: the output file containing the statistics
    :param variable: the model variable to analyse
    """

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); gen_stats_table(\"' + inputfile + \
              '\", \"' + outputfile
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\", \"' + variable + \
               '\")\''
    # print(command)
    run_cmd(command)
Example #7
0
def pe_objval_vs_iters_analysis(model_name, filename, plots_dir):
    """
    Analysis of the Objective values vs Iterations.

    :param model_name: the model name without extension
    :param filename: the filename containing the fits sequence
    :param plots_dir: the directory for storing the plots
    """

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); objval_vs_iters_analysis(\"' + model_name + \
              '\", \"' + filename + \
              '\", \"' + plots_dir
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\")\''
    # print(command)
    run_cmd(command)
Example #8
0
def pe_sampled_2d_ple_analysis(model_name,
                               filename,
                               parameter1,
                               parameter2,
                               plots_dir,
                               thres="BestFits",
                               best_fits_percent=100,
                               fileout_param_estim_summary="",
                               logspace=True,
                               scientific_notation=True):
    """
    2D profile likelihood estimation analysis.

    :param model_name: the model name without extension
    :param filename: the filename containing the fits sequence
    :param parameter1: the name of the first parameter
    :param parameter2: the name of the second parameter
    :param plots_dir: the directory for storing the plots
    :param thres: the threshold used to filter the dataset. Values: "BestFits", "CL66", "CL95", "CL99", "All".
    :param best_fits_percent: the percent of best fits to analyse. Only used if thres="BestFits".
    :param fileout_param_estim_summary: the name of the file containing the summary for the parameter estimation. Only used if thres!="BestFits".
    :param logspace: true if the parameters should be plotted in logspace
    :param scientific_notation: true if the axis labels should be plotted in scientific notation
    """

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); sampled_2d_ple_analysis(\"' + model_name + \
              '\", \"' + filename + \
              '\", \"' + parameter1 + \
              '\", \"' + parameter2 + \
              '\", \"' + plots_dir + \
              '\", \"' + thres + \
              '\", ' + str(best_fits_percent) + \
              ', \"' + fileout_param_estim_summary + \
              '\", ' + str(logspace).upper() + \
              ', ' + str(scientific_notation).upper()
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += ')\''
    # print(command)
    run_cmd(command)
Example #9
0
def pe_ds_preproc(filename,
                  param_names,
                  logspace=True,
                  all_fits=False,
                  data_point_num=0,
                  fileout_param_estim_summary="param_estim_summary.csv"):
    """
    Parameter estimation pre-processing. It renames the data set columns, and applies
    a log10 transformation if logspace is TRUE. If all.fits is true, it also computes
    the confidence levels.

    :param filename: the dataset filename containing the fits sequence
    :param param_names: the list of estimated parameter names
    :param logspace: true if the data set shoud be log10-transformed.
    :param all_fits: true if filename contains all fits, false otherwise
    :param data_point_num: the number of data points used for parameterise the model. Ignored if all.fits is false
    :param fileout_param_estim_summary: the name of the file containing the summary for the parameter estimation. Ignored if all.fits is false
    """

    # convert param_names into an R vector
    param_names_r = "c("
    for i in param_names:
        param_names_r += "\"" + i + "\","
    if len(param_names) > 0:
        param_names_r = param_names_r[:-1]
    param_names_r = param_names_r + ")"

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); pe_ds_preproc(\"' + filename + \
              '\", ' + param_names_r + \
              ', ' + str(logspace).upper() + \
              ', ' + str(all_fits).upper() + \
              ', ' + str(data_point_num) + \
              ', \"' + fileout_param_estim_summary
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\")\''
    # print(command)
    run_cmd(command)
Example #10
0
def sim_analyse_plot_sep_sims(inputdir, outputdir, model, exp_dataset,
                              plot_exp_dataset, exp_dataset_alpha, xaxis_label,
                              yaxis_label, variable):
    """
    Plot model simulation time courses (Python wrapper).

    :param inputdir: the directory containing the data to analyse
    :param outputdir: the output directory containing the results
    :param model: the model name
    :param exp_dataset: the full path of the experimental data set
    :param plot_exp_dataset: True if the experimental data set should also be plotted
    :param exp_dataset_alpha: the alpha level for the data set
    :param xaxis_label: the label for the x axis (e.g. Time [min])
    :param yaxis_label: the label for the y axis (e.g. Level [a.u.])
    :param variable: the model variable to analyse
    """

    if float(exp_dataset_alpha) > 1.0 or float(exp_dataset_alpha) < 0.0:
        print(
            "variable exp_dataset_alpha must be in [0,1]. Please, check your configuration file."
        )
        exp_dataset_alpha = 1.0

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); plot_sep_sims(\"' + inputdir + \
              '\", \"' + outputdir + \
              '\", \"' + model + \
              '\", \"' + exp_dataset + \
              '\", ' + str(plot_exp_dataset).upper() + \
              ', \"' + str(exp_dataset_alpha)
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\", \"' + xaxis_label + \
               '\", \"' + yaxis_label + \
               '\", \"' + variable + \
               '\")\''
    # print(command)
    run_cmd(command)
Example #11
0
def ps1_analyse_plot(model_name, inhibition_only, inputdir, outputdir, repeat,
                     percent_levels, min_level, max_level, levels_number,
                     xaxis_label, yaxis_label):
    """
    Plot model single parameter scan time courses (Python wrapper).

    :param model_name: the model name without extension
    :param inhibition_only: true if the scanning only decreases the variable amount (inhibition only)
    :param inputdir: the input directory containing the simulated data
    :param outputdir: the output directory that will contain the simulated plots
    :param repeat: the simulation number
    :param percent_levels: true if scanning levels are in percent
    :param min_level: the minimum level
    :param max_level: the maximum level
    :param levels_number: the number of levels
    :param homogeneous_lines: true if lines should be plotted homogeneously
    :param xaxis_label: the label for the x axis (e.g. Time [min])
    :param yaxis_label: the label for the y axis (e.g. Level [a.u.])
    """
    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); plot_single_param_scan_data(\"' + model_name + \
              '\", \"' + str(inhibition_only).upper() + \
              '\", \"' + inputdir + \
              '\", \"' + outputdir + \
              '\", \"' + repeat + \
              '\", \"' + str(percent_levels).upper() + \
              '\", \"' + str(min_level) + \
              '\", \"' + str(max_level) + \
              '\", \"' + str(levels_number)
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\", \"' + xaxis_label + \
               '\", \"' + yaxis_label + \
               '\")\''
    # print(command)
    run_cmd(command)
Example #12
0
def ps2_analyse_plot(model, scanned_par1, scanned_par2, inputdir, outputdir,
                     id):
    """
    Plot model double parameter scan time courses (Python wrapper).

    :param model: the model name without extension
    :param scanned_par1: the 1st scanned parameter
    :param scanned_par2: the 2nd scanned parameter
    :param inputdir: the input directory
    :param outputdir: the output directory
    :param run: the simulation number
    """
    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); plot_double_param_scan_data(\"' + model + \
              '\", \"' + scanned_par1 + '\", \"' + scanned_par2 + \
              '\", \"' + inputdir + \
              '\", \"' + outputdir + \
              '\", \"' + str(id)
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += '\")\''
    # print(command)
    run_cmd(command)
Example #13
0
def pe_parameter_pca_analysis(model_name,
                              filename,
                              plots_dir,
                              best_fits_percent=100):
    """
    PCA for the best fits of the estimated parameters.

    :param model_name: the model name without extension
    :param filename: the filename containing the fits sequence
    :param plots_dir: the directory for storing the plots
    :param best_fits_percent: the percent of best fits to analyse. Only used if thres="BestFits".
    """

    # requires devtools::install_github("pdp10/sbpiper")
    command = 'R --quiet -e \'library(sbpiper); parameter_pca_analysis(\"' + model_name + \
              '\", \"' + filename + \
              '\", \"' + plots_dir + \
              '\", ' + str(best_fits_percent)
    # we replace \\ with / otherwise subprocess complains on windows systems.
    command = command.replace('\\', '\\\\')
    # We do this to make sure that characters like [ or ] don't cause troubles.
    command += ')\''
    # print(command)
    run_cmd(command)
Example #14
0
def sbpipe(create_project='',
           simulate='',
           parameter_scan1='',
           parameter_scan2='',
           parameter_estimation='',
           version=False,
           logo=False,
           license=False,
           nocolor=False,
           log_level='',
           quiet=False,
           verbose=False):
    """
    SBpipe function.

    :param create_project: create a project with the name as argument
    :param simulate: model simulation using a configuration file as argument
    :param parameter_scan1: model one parameter scan using a configuration file as argument
    :param parameter_scan2: model two parameters scan using a configuration file as argument
    :param parameter_estimation: model parameter estimation using a configuration file as argument
    :param version: True to print the version
    :param logo: True to print the logo
    :param license: True to print the license
    :param nocolor: True to print logging messages without colors
    :param log_level: Set the logging level
    :param quiet: True if quiet (CRITICAL+)
    :param verbose: True if verbose (DEBUG+)
    :return: 0 if OK, 1  if trouble (e.g. a pipeline did not execute correctly).
    """

    exit_status = 0

    # setup the logger
    if log_level:
        set_logger(log_level, nocolor=nocolor)
    elif quiet:
        set_logger('CRITICAL', nocolor=nocolor)
    elif verbose:
        set_logger('DEBUG', nocolor=nocolor)
    else:
        set_logger()

    logger = logging.getLogger('sbpipe')

    # add platform information
    #logger.debug(platform.machine())
    logger.debug(platform.version())
    logger.debug(platform.platform())
    logger.debug('Python ' + platform.python_version())
    # retrieve the first line from the command output message
    logger.debug(run_cmd('R --version')[0].decode('utf-8').splitlines()[0])
    logger.debug('SBpipe ' + sbpipe_version())

    if version:
        print(sbpipe_version())
    elif logo:
        print(sbpipe_logo())
    elif license:
        print(sbpipe_license())
    elif create_project:
        from sbpipe.pl.create.newproj import NewProj
        s = NewProj()
        exit_status = 0 if s.run(create_project) else 1
    elif simulate:
        from sbpipe.pl.sim.sim import Sim
        s = Sim()
        exit_status = 0 if s.run(simulate) else 1
    elif parameter_scan1:
        from sbpipe.pl.ps1.parscan1 import ParScan1
        s = ParScan1()
        exit_status = 0 if s.run(parameter_scan1) else 1
    elif parameter_scan2:
        from sbpipe.pl.ps2.parscan2 import ParScan2
        s = ParScan2()
        exit_status = 0 if s.run(parameter_scan2) else 1
    elif parameter_estimation:
        from sbpipe.pl.pe.parest import ParEst
        s = ParEst()
        exit_status = 0 if s.run(parameter_estimation) else 1

    logging.shutdown()

    return exit_status