Exemplo n.º 1
0
def subset_petab_problem(
    petab_problem: petab.Problem,
    timecourse_id: str,
) -> Sequence[petab.Problem]:
    petab_problem = deepcopy(petab_problem)
    petab_problem.observable_df.loc[DUMMY_OBSERVABLE_ID] = \
        {
            OBSERVABLE_FORMULA: DUMMY_MEASUREMENT,
            NOISE_FORMULA: DUMMY_NOISE,
        }
    # TODO allow no specification of timecourse if only one timecourse in
    # problem. TODO raise error if multiple timecourses but no timecourse ID
    # specified
    petab_problem.measurement_df = petab_problem.measurement_df[
        petab_problem.measurement_df[SIMULATION_CONDITION_ID] == timecourse_id]
    timecourse = parse_timecourse_string(
        petab_problem.timecourse_df.loc[timecourse_id][TIMECOURSE], )
    # FIXME timepoints not necessarily float
    timecourse = [(float(_t), _id) for _t, _id in timecourse]
    petab_problems = []
    for index, (timepoint, condition_id) in enumerate(timecourse):
        petab_problems.append(deepcopy(petab_problem))
        petab_problems[-1].condition_df.loc[timecourse_id] = \
            petab_problems[-1].condition_df.loc[condition_id]
        # Drop other conditions
        # FIXME test how this affects other conditions or how to combine normal conditions + timecourses...
        #       or only allow timecourses?
        petab_problems[-1].condition_df = (
            petab_problems[-1].condition_df.loc[[timecourse_id]])
        petab_problems[-1].measurement_df = \
            petab_problems[-1].measurement_df[
                petab_problems[-1].measurement_df[TIME].astype(float)
                >= timepoint
            ]
        if index < len(timecourse) - 1:
            next_timepoint = timecourse[index + 1][0]
            petab_problems[-1].measurement_df = \
                petab_problems[-1].measurement_df[
                    petab_problems[-1].measurement_df[TIME].astype(float)
                    <= next_timepoint
                ]
            # Add dummy data to ensure endpoint is outputted.
            petab_problems[-1].measurement_df = \
                petab_problems[-1].measurement_df.append(
                    {
                        OBSERVABLE_ID: DUMMY_OBSERVABLE_ID,
                        SIMULATION_CONDITION_ID: timecourse_id,
                        TIME: next_timepoint,
                        MEASUREMENT: DUMMY_MEASUREMENT,
                    },
                    ignore_index=True,
                )
        # Remove condition parameters from the parameters table.
        condition_components = [
            c for c in petab_problems[-1].condition_df.loc[timecourse_id].index
            if c not in NON_COMPONENT_CONDITION_LABELS
        ]
        petab_problems[-1].parameter_df.drop(
            condition_components,
            inplace=True,
            errors='ignore',  # only parameters that are in the table are dropped
        )

        #for t in [timepoint, next_timepoint]:
        #    if not any(
        #            t == petab_problems[-1].measurement_df[TIME].astype(float)
        #    ):
        #        # FIXME add dummy data
        #        print(t)
        #        breakpoint()
        #        pass
    return petab_problems
Exemplo n.º 2
0
def filter_observables(petab_problem: petab.Problem):
    petab_problem.measurement_df = petab_problem.measurement_df.loc[
        petab_problem.measurement_df[petab.OBSERVABLE_ID].apply(
            lambda x: x in petab_problem.observable_df.index
        ), :
    ]