Ejemplo n.º 1
0
def extract(system: str, kinetics: str):
    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": total_lipid_concentration,
        "Analysis": "Converting Old Parameters",
        "version": "3.0"
    }
    LOG.info(json.dumps(log_data, sort_keys=True))
    progress_counter = 0
    all_para = get_parameters()
    for para in all_para:
        initial_con = get_random_concentrations(total_lipid_concentration,
                                                system)
        sanity_counter = 0
        update_progress(progress_counter / len(all_para),
                        "Extracting Old Parameters")
        while sanity_counter < 10000:
            para[E_SOURCE].k = np.random.uniform(min_k, max_k)
            output = get_concentration_profile(system, initial_con, para,
                                               ode_end_time, ode_slices)
            e = calculate_wild_type_error(output[-1])
            if e < save_cutoff:
                save_para(para, e)
                break
            sanity_counter += 1
        progress_counter += 1
Ejemplo n.º 2
0
def do_sweep(system: str, kinetics: str,
             total_lipid=total_lipid_concentration):
    # Initial setup to start sweep
    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": total_lipid,
        "Analysis": "Nelder-Mead Simplex Sweep",
        "version": "3.0"}
    LOG.info(json.dumps(log_data, sort_keys=True))

    lowest_error = 1000000
    progress_counter = 0
    update_progress(progress_counter / outer_iterations,
                    "lowest_error : %s" % lowest_error)
    for i in range(outer_iterations):
        initial_condition = get_random_concentrations(total_lipid, system)
        best, good, worst = make_initial_set(initial_condition, system,
                                             kinetics, total_lipid)
        para_skip = 0
        while para_skip < para_skip_threshold:
            mid = mid_point(best, good)
            mid_out = get_concentration_profile(system, initial_condition, mid,
                                                ode_end_time, ode_slices)
            mid_error = Error(total_lipid, mid_out[-1], mid)
            reflection = get_reflection(mid_error, worst)
            reflection_out = get_concentration_profile(system,
                                                       initial_condition,
                                                       reflection,
                                                       ode_end_time,
                                                       ode_slices)
            reflection_error = Error(total_lipid, reflection_out[-1],
                                     reflection)

            analysis_list = [best, good, worst, mid_error, reflection_error]
            before_sort = best
            analysis_list.sort(key=lambda x: x.total_error)
            best, good, worst = analysis_list[0], analysis_list[1], \
                                analysis_list[2]

            if before_sort == best:
                para_skip += 1
            if best.total_error < lowest_error:
                lowest_error = best.total_error
                best.record()

        progress_counter += 1
        update_progress(progress_counter / outer_iterations,
                        "lowest_error : %s" % lowest_error)
Ejemplo n.º 3
0
def calculate(system: str, kinetics: str, mutant_factor):
    if system != S_OPEN_2 and kinetics != MASS_ACTION:
        raise Exception("This analysis is only for OPEN Cycle 2 Mass action "
                        "reactions")

    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": "N/A",
        "Analysis": "Mass Action Reverse Calculations",
        "version": "3.0"}
    LOG.info(json.dumps(log_data, sort_keys=True))

    lowest_error = 100000
    progress_counter = 0
    update_progress(progress_counter / outer_iterations,
                    "lowest_error : %s" % lowest_error)

    for i in range(outer_iterations):
        current_para = ParaSet()
        current_error = lowest_error

        for j in range(inner_iterations):
            wt = current_para.steady_state()
            current_para.mutate_dagk(mutant_factor)
            rdga = current_para.steady_state()
            current_para.restore_to_original()
            current_para.mutate_laza(mutant_factor)
            laza = current_para.steady_state()
            current_para.restore_to_original()

            e = calculate_total_error(wt, rdga, laza)

            if e < current_error:
                current_error = e
                current_para.replace_old()
                if current_error < 0.35:
                    save_parameters(current_para.get_all(), current_error)
            else:
                current_para.restore_to_original()
                current_para.randomize(3)

            if current_error < lowest_error:
                lowest_error = current_error

        progress_counter += 1
        update_progress(progress_counter / outer_iterations,
                        "lowest_error : %s" % lowest_error)
def do_sweep_with_penalty(system: str,
                          kinetics: str,
                          total_lipid=total_lipid_concentration):
    """
    This function add penalty for PMPI > ERPI
    """
    # Initial setup to start sweep
    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": total_lipid_concentration,
        "Analysis": "Parameter Sweep with PI penalty",
        "version": "3.0"
    }
    LOG.info(json.dumps(log_data, sort_keys=True))

    # Start sweep
    progress_counter = 0
    lowest_error = 10000000
    update_progress(progress_counter / outer_iterations,
                    "lowest_error : %s" % lowest_error)
    for i in range(outer_iterations):
        current_error = 10000000
        initial_conditions = get_random_concentrations(total_lipid, system)
        enzymes = get_random_enzymes(kinetics)
        para_skip = 0
        for j in range(inner_iterations):
            output = get_concentration_profile(system, initial_conditions,
                                               enzymes, 20000, 2000)
            error = Error(total_lipid, list(output[-1]), enzymes)
            if error.total_error_with_penalty < current_error:
                error.record()
                current_error = error.total_error_with_penalty
                update_enzymes(enzymes)
            else:
                para_skip += 1
                if para_skip > para_skip_threshold:
                    break
                else:
                    for e in enzymes.values():
                        e.reset()
                    randomize(enzymes)

        if current_error < lowest_error:
            lowest_error = current_error
        progress_counter += 1
        update_progress(progress_counter / outer_iterations,
                        "lowest_error : %s" % lowest_error)
def do_sweep(system: str, kinetics: str, population: int,
             mutation_rate: float):
    pop = create_population(population, kinetics)
    lowest_error = 100000
    progress_counter = 0
    update_progress(
        progress_counter / outer_iterations,
        "lowest_error: %s current_error : %s" % (lowest_error, lowest_error))
    for i in range(outer_iterations):
        pop, current_fitness = renew_population(system, pop, mutation_rate)
        if current_fitness < lowest_error:
            lowest_error = current_fitness

        progress_counter += 1
        update_progress(
            progress_counter / outer_iterations,
            "lowest_error: %s current_error : %s" %
            (lowest_error, current_fitness))
Ejemplo n.º 6
0
def calculate_mutant(filename: str, system: str, kinetics: str,
                     expression_levels: list) -> None:
    """
    :param filename: Name of file which contains parameter values
    :param system: System Name
    :param kinetics: Type of Kinetics
    :param expression_levels: Expression level w.r.t. Wild Type for mutant
    analysis
    """

    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": total_lipid_concentration,
        "Analysis": "Calculating Mutant",
        "ODEEndTime": ode_end_time,
        "version": "3.0"}
    LOG.info(json.dumps(log_data, sort_keys=True))

    all_para = get_parameter_set(filename)
    progress_counter = 0
    update_progress(progress_counter / len(all_para), "Calculating mutants")
    for para in all_para:
        enz = convert_to_enzyme(para)
        mutant_ratio = {}
        for expression in expression_levels:
            initial_con = get_random_concentrations(total_lipid_concentration,
                                                    system)
            wt_output = get_concentration_profile(system, initial_con, enz,
                                                  ode_end_time, ode_slices)
            enz[E_DAGK].mutate(expression)
            rdga_output = get_concentration_profile(system, initial_con, enz,
                                                    ode_end_time, ode_slices)
            enz[E_DAGK].mutate(1 / expression)
            enz[E_LAZA].mutate(expression)
            laza_output = get_concentration_profile(system, initial_con, enz,
                                                    ode_end_time, ode_slices)
            enz[E_LAZA].mutate(1 / expression)

            mutant_ratio[expression] = {
                "RDGA": {
                    "PA": round(get_pa_ratio(wt_output[-1], rdga_output[-1]),
                                4),
                    "DAG": round(get_dag_ratio(wt_output[-1], rdga_output[-1]),
                                 4)
                },
                "LAZA": {
                    "PA": round(get_pa_ratio(wt_output[-1], laza_output[-1]),
                                4),
                    "DAG": round(get_dag_ratio(wt_output[-1], laza_output[-1]),
                                 4)
                },
            }

        data = {}
        for value in enz.values():
            data[value.name] = {
                "v": round(value.v, 4),
                "k": round(value.k, 4),
                "kinetics": value.kinetics
            }
        save_values = {
            "Mutants": mutant_ratio,
            "Enzymes": data
        }
        OUTPUT.info(json.dumps(save_values, sort_keys=True))
        progress_counter += 1
        update_progress(progress_counter / len(all_para),
                        "Calculating mutants")
def improve(system: str,
            kinetics: str,
            filename: str,
            mutant_expression: float,
            total_lipid=total_lipid_concentration):
    # Initial setup to start sweep
    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": total_lipid_concentration,
        "Analysis": "Improve Parameter",
        "ExpressionLevel": mutant_expression,
        "version": "3.0"
    }
    LOG.info(json.dumps(log_data, sort_keys=True))

    # Start sweep
    progress_counter = 0
    lowest_error = 10000000
    update_progress(progress_counter / outer_iterations,
                    "lowest_error : %s" % lowest_error)

    time_end = ode_end_time
    if len(get_parameter_set(filename)) > 1:
        LOG.info("Multiple parameters found. Only first parameter will "
                 "be used")
    counter_error = 10000
    for i in range(outer_iterations):
        current_error = 10000000
        initial_conditions = get_random_concentrations(total_lipid, system)
        # enzymes = convert_to_enzyme(get_parameter_set(filename)[0])
        # enzymes = get_random_enzymes(kinetics)
        enzymes = get_open2(MASS_ACTION)
        para_skip = 0
        for j in range(inner_iterations):
            error = MutantError(system,
                                initial_conditions,
                                enzymes,
                                time_end,
                                mutant_level=mutant_expression,
                                cut_off=0.3)
            if error.total_error < current_error:
                error.record()
                current_error = error.total_error
                update_enzymes(enzymes)
            else:
                para_skip += 1
                if para_skip > para_skip_threshold:
                    break
                else:
                    for e in enzymes.values():
                        e.reset()
                    randomize(enzymes, 4)

        if current_error < lowest_error:
            lowest_error = current_error
        if current_error < counter_error:
            counter_error = current_error
        progress_counter += 1
        update_progress(progress_counter / outer_iterations,
                        "lowest_error : %s" % lowest_error)
Ejemplo n.º 8
0
def calculate(system: str, kinetics: str):
    if system != S_OPEN_2 and kinetics != MICHAELIS_MENTEN:
        raise Exception(
            "This analysis is only for OPEN Cycle 2 Michaelis-Menten "
            "reactions")

    log_data = {
        "UID": CURRENT_JOB,
        "System": system,
        "Kinetics": kinetics,
        "TotalLipid": "N/A",
        "Analysis": "Michealis-Menten Reverse Calculations",
        "version": "3.0"}
    LOG.info(json.dumps(log_data, sort_keys=True))

    smallest_error = 10000
    for i in range(outer_iterations):
        v_sink = np.random.uniform(min_v, max_k)
        k_sink = np.random.uniform(min_k, max_k)

        k_source = np.random.uniform(min_v, v_sink)

        dag = (k_sink * k_source) / (v_sink - k_source)

        pmpa, v_patp, k_patp, v_laza, k_laza, v_dagk, k_dagk = get_pmpa_related(
            dag)

        if pmpa > 0:
            m2 = v_patp * pmpa / (k_patp + pmpa)

            v_cds = np.random.uniform(m2, m2 + 10)
            k_cds = np.random.uniform(min_k, max_k)

            erpa = k_cds * m2 / (v_cds - m2)

            m = v_cds * erpa / (k_cds + erpa)

            k_pis, k_pitp, k_pi4k, k_pip5k, k_plc = np.random.uniform(min_k,
                                                                      max_k, 5)
            v_pis, v_pitp, v_pi4k, v_pip5k, v_plc = np.random.uniform(m,
                                                                      m + 10,
                                                                      5)

            cdpdag = k_pis * m / (v_pis - m)
            erpi = k_pitp * m / (v_pitp - m)
            pmpi = k_pi4k * m / (v_pi4k - m)
            pi4p = k_pip5k * m / (v_pip5k - m)
            pip2 = k_plc * m / (v_plc - m)

            e = calculate_wild_type_error(
                [pmpi, pi4p, pip2, dag, pmpa, erpa, cdpdag, erpi])

            if e < smallest_error:
                smallest_error = e
                if smallest_error < save_cutoff:
                    all_k = k_pitp, k_pi4k, k_pip5k, k_plc, k_dagk, k_sink, k_laza, k_patp, k_source, k_cds, k_pis
                    all_v = v_pitp, v_pi4k, v_pip5k, v_plc, v_dagk, v_sink, v_laza, v_patp, 1, v_cds, v_pis
                    save_parameters(all_k, all_v, smallest_error)

        update_progress(i / outer_iterations,
                        "lowest_error : %s" % smallest_error)