Skip to content

Commit

Permalink
fix timepoint specific mapping check (#44)
Browse files Browse the repository at this point in the history
* update using AMICI implementation

* Update petab/lint.py

Co-authored-by: Daniel Weindl <[email protected]>

Co-authored-by: Daniel Weindl <[email protected]>
  • Loading branch information
FFroehlich and dweindl authored Mar 19, 2021
1 parent a1d3d80 commit 88f570a
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions petab/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import numbers
import re
from typing import Optional, Iterable
from typing import Optional, Iterable, Union
from collections import Counter

import libsbml
Expand Down Expand Up @@ -542,12 +542,29 @@ def measurement_table_has_timepoint_specific_mappings(
# since we edit it, copy it first
measurement_df = copy.deepcopy(measurement_df)

if NOISE_PARAMETERS not in measurement_df:
measurement_df[NOISE_PARAMETERS] = np.nan

measurement_df.loc[
measurement_df.noiseParameters.apply(isinstance, args=(
numbers.Number,)), NOISE_PARAMETERS] = np.nan
def is_numeric(x: Union[str, numbers.Number]) -> bool:
"""
Checks whether x can be transformed into a (list of) float(s)
:param x:
number or string containing numbers seperated by ;
:return:
True if conversion is possible for all values
"""
if isinstance(x, numbers.Number):
return True
if not isinstance(x, str):
return False
try:
[float(y) for y in x.split(';')]
return True
except (ValueError, TypeError):
return False

# mask numeric values
for col in [OBSERVABLE_PARAMETERS, NOISE_PARAMETERS]:
if col not in measurement_df:
continue
measurement_df.loc[measurement_df[col].apply(is_numeric), col] = np.nan

grouping_cols = core.get_notnull_columns(
measurement_df,
Expand All @@ -557,8 +574,8 @@ def measurement_table_has_timepoint_specific_mappings(
OBSERVABLE_PARAMETERS,
NOISE_PARAMETERS,
])
grouped_df = measurement_df.fillna('').groupby(grouping_cols).size()\
.reset_index()
grouped_df = measurement_df.groupby(grouping_cols,
dropna=False).size().reset_index()

grouping_cols = core.get_notnull_columns(
grouped_df,
Expand All @@ -567,11 +584,10 @@ def measurement_table_has_timepoint_specific_mappings(
PREEQUILIBRATION_CONDITION_ID])
grouped_df2 = grouped_df.groupby(grouping_cols).size().reset_index()

if len(grouped_df.index) != len(grouped_df2.index):
logger.warning("Measurement table has timepoint-specific "
f"mappings:\n{grouped_df}")
return True
return False
# data frame has timepoint specific overrides if grouping by noise
# parameters and observable parameters in addition to observable,
# condition and preeq id yields more groups
return len(grouped_df.index) != len(grouped_df2.index)


def measurement_table_has_observable_parameter_numeric_overrides(
Expand Down

0 comments on commit 88f570a

Please sign in to comment.