Skip to content

Commit

Permalink
Merge branch 'develop' into fix_111
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Dec 4, 2019
2 parents d4e51cf + 60d5e1f commit b375031
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 48 deletions.
37 changes: 19 additions & 18 deletions petab/core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
"""PEtab core functions"""

import pandas as pd
import numpy as np
import libsbml
import sympy as sp
import re
import itertools
import os
import logging
import numbers
import os
import re
import warnings
from collections import OrderedDict
import logging
from . import lint
from . import sbml
from . import parameter_mapping
from typing import Optional, List, Union, Iterable, Set
import warnings

import libsbml
import numpy as np
import pandas as pd
import sympy as sp

from . import lint
from . import parameter_mapping
from . import sbml

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -971,25 +972,25 @@ def flatten_timepoint_specific_output_overrides(
unique_noise = df["noiseParameters"].unique()

# Loop
for i in range(len(unique_noise)):
for j in range(len(unique_sc)):
# Find the position of all instances of unique_noise[i]
for i_noise, cur_noise in enumerate(unique_noise):
for i_sc, cur_sc in enumerate(unique_sc):
# Find the position of all instances of cur_noise
# and unique_sc[j] in their corresponding column
# (full-string matches are denoted by zero)
idxs = (
df["noiseParameters"].str.find(unique_noise[i]) +
df["observableParameters"].str.find(unique_sc[j])
df["noiseParameters"].str.find(cur_noise) +
df["observableParameters"].str.find(cur_sc)
)
tmp_ = df.loc[idxs == 0, "observableId"]
# Create replicate-specific observable name
tmp = tmp_ + "_" + str(i + j + 1)
tmp = tmp_ + "_" + str(i_noise + i_sc + 1)
# Check if replicate-specific observable name already exists
# in df. If true, rename replicate-specific observable
counter = 2
while (df["observableId"].str.find(
tmp.to_string()
) == 0).any():
tmp = tmp_ + counter*"_" + str(i + j + 1)
tmp = tmp_ + counter*"_" + str(i_noise + i_sc + 1)
counter += 1
df.loc[idxs == 0, "observableId"] = tmp
# Append the result in a new df
Expand Down
30 changes: 16 additions & 14 deletions petab/lint.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""Integrity checks and tests for specific features used"""

from . import core
from . import sbml
import numpy as np
import numbers
import re
import copy
import logging
import numbers
import re
from typing import Optional

import libsbml
import numpy as np
import pandas as pd
from typing import Optional

from . import core
from . import sbml

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -178,10 +180,10 @@ def assert_parameter_id_is_string(parameter_df):
are string and not empty.
"""

for parameterId in parameter_df:
if isinstance(parameterId, str):
if parameterId[0].isdigit():
raise AssertionError('parameterId ' + parameterId
for parameter_id in parameter_df:
if isinstance(parameter_id, str):
if parameter_id[0].isdigit():
raise AssertionError('parameterId ' + parameter_id
+ ' starts with integer')
else:
raise AssertionError('Empty parameterId found')
Expand All @@ -203,11 +205,11 @@ def assert_parameter_scale_is_valid(parameter_df):
logarithm.
"""

for parameterScale in parameter_df['parameterScale']:
if parameterScale not in ['lin', 'log', 'log10']:
for parameter_scale in parameter_df['parameterScale']:
if parameter_scale not in ['lin', 'log', 'log10']:
raise AssertionError(
'Expected "lin", "log" or "log10" but got "' +
parameterScale + '"')
parameter_scale + '"')


def assert_parameter_bounds_are_numeric(parameter_df):
Expand Down Expand Up @@ -239,7 +241,7 @@ def assert_parameter_estimate_is_boolean(parameter_df):
0 or 1.
"""
for estimate in parameter_df['estimate']:
if not int(estimate) in [True, False]:
if int(estimate) not in [True, False]:
raise AssertionError(
f"Expected 0 or 1 but got {estimate} in estimate column.")

Expand Down
5 changes: 3 additions & 2 deletions petab/petablint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"""Command line tool to check for correct format"""

import argparse
import logging
import os
import petab
import sys
import logging

import petab
from colorama import (init as init_colorama, Fore)

logger = logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions petab/sbml.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Functions for direct access of SBML models"""

import libsbml
import math
import logging
import math
import warnings
from typing import Dict, Any

import libsbml

logger = logging.getLogger(__name__)


Expand Down
5 changes: 3 additions & 2 deletions petab/visualize/data_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
Functions for creating an overview report of a PEtab problem
"""

import petab
import os
import pandas as pd
from shutil import copyfile

import pandas as pd
import petab


def create_report(problem: petab.Problem, model_name: str) -> None:
"""Create an HTML overview data / model overview report
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def read(fname):
}

# project metadata
# noinspection PyUnresolvedReferences
setup(name='petab',
version=__version__, # noqa: F821
description='Parameter estimation tabular data',
Expand Down
24 changes: 14 additions & 10 deletions tests/test_parameter_mapping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import pandas as pd
import petab
import numpy as np

from petab.sbml import add_global_parameter

# import fixtures
Expand All @@ -12,7 +11,8 @@

class TestGetSimulationToOptimizationParameterMapping(object):

def test_no_condition_specific(self, condition_df_2_conditions,
@staticmethod
def test_no_condition_specific(condition_df_2_conditions,
minimal_sbml_model):
# Trivial case - no condition-specific parameters

Expand All @@ -26,7 +26,7 @@ def test_no_condition_specific(self, condition_df_2_conditions,
'noiseParameters': ['', '']
})

sbml_doc, sbml_model = minimal_sbml_model
_, sbml_model = minimal_sbml_model
add_global_parameter(sbml_model, 'dynamicParameter1')
add_global_parameter(sbml_model, 'dynamicParameter2')
add_global_parameter(sbml_model, 'dynamicParameter3')
Expand All @@ -48,12 +48,13 @@ def test_no_condition_specific(self, condition_df_2_conditions,

assert actual == expected

def test_all_override(self, condition_df_2_conditions,
@staticmethod
def test_all_override(condition_df_2_conditions,
minimal_sbml_model):
# Condition-specific parameters overriding original parameters
condition_df = condition_df_2_conditions

sbml_doc, sbml_model = minimal_sbml_model
_, sbml_model = minimal_sbml_model
add_global_parameter(sbml_model, 'dynamicParameter1')
add_global_parameter(sbml_model, 'dynamicParameter2')
add_global_parameter(sbml_model, 'observableParameter1_obs1')
Expand Down Expand Up @@ -94,12 +95,13 @@ def test_all_override(self, condition_df_2_conditions,

assert actual == expected

def test_partial_override(self, condition_df_2_conditions,
@staticmethod
def test_partial_override(condition_df_2_conditions,
minimal_sbml_model):
# Condition-specific parameters, keeping original parameters
condition_df = condition_df_2_conditions

sbml_doc, sbml_model = minimal_sbml_model
_, sbml_model = minimal_sbml_model
add_global_parameter(sbml_model, 'dynamicParameter1')
add_global_parameter(sbml_model, 'observableParameter1_obs1')
add_global_parameter(sbml_model, 'observableParameter2_obs1')
Expand Down Expand Up @@ -138,7 +140,8 @@ def test_partial_override(self, condition_df_2_conditions,

assert actual == expected

def test_parameterized_condition_table(self, minimal_sbml_model):
@staticmethod
def test_parameterized_condition_table(minimal_sbml_model):
condition_df = pd.DataFrame(data={
'conditionId': ['condition1', 'condition2', 'condition3'],
'conditionName': ['', 'Condition 2', ''],
Expand Down Expand Up @@ -179,8 +182,9 @@ def test_parameterized_condition_table(self, minimal_sbml_model):

assert actual == expected

@staticmethod
def test_parameterized_condition_table_changed_scale(
self, minimal_sbml_model):
minimal_sbml_model):
"""Test overriding a dynamic parameter `overridee` with
- a log10 parameter to be estimated (condition 1)
- lin parameter not estimated (condition2)
Expand Down

0 comments on commit b375031

Please sign in to comment.