Skip to content

Conversation

@dweindl
Copy link
Member

@dweindl dweindl commented Apr 3, 2025

Adapt to PEtab-dev/PEtab#616, which allows providing multiple conditions for the same experiment / timepoint.

@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 74.17%. Comparing base (b43f5b8) to head (ba1996f).

Files with missing lines Patch % Lines
petab/v2/lint.py 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #373      +/-   ##
===========================================
+ Coverage    74.08%   74.17%   +0.08%     
===========================================
  Files           58       58              
  Lines         6221     6234      +13     
  Branches      1078     1084       +6     
===========================================
+ Hits          4609     4624      +15     
+ Misses        1206     1204       -2     
  Partials       406      406              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dweindl dweindl self-assigned this Apr 3, 2025
@dweindl dweindl force-pushed the v2_combine_conditions branch from bc56350 to d1f692f Compare April 23, 2025 08:36
@dweindl dweindl marked this pull request as ready for review April 23, 2025 08:37
@dweindl dweindl requested a review from a team as a code owner April 23, 2025 08:37
Copy link
Member

@dilpath dilpath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Nothing that needs to be changed.

Comment on lines +551 to +558
for timepoint in cur_exp_df[C.TIME].unique():
condition_ids = [
cid
for cid in cur_exp_df.loc[
cur_exp_df[C.TIME] == timepoint, C.CONDITION_ID
]
if not pd.isna(cid)
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to add a dropna

Suggested change
for timepoint in cur_exp_df[C.TIME].unique():
condition_ids = [
cid
for cid in cur_exp_df.loc[
cur_exp_df[C.TIME] == timepoint, C.CONDITION_ID
]
if not pd.isna(cid)
]
for timepoint, cur_exp_time_df in cur_exp_df.groupby(C.TIME):
condition_ids = cur_exp_time_df[C.CONDITION_ID].unique()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid the overhead of the additional groupy / creating the additional dataframes. Usually there will only be a single condition ID.

I'd avoid the unique otherwise this will hide errors in case of duplicated conditions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating the additional dataframes

Ah, you're right, I thought it was some view instead

I'd avoid the unique

Yes, not sure why I did that...

No issue with your code but I find the groupby faster to understand.
Independently of this, again this might be something that tools want in a library function

Comment on lines +408 to +413
condition_targets = {
change.target_id
for cond in problem.condition_table.conditions
if cond.id == condition_id
for change in cond.changes
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this useful for tools? I guess tools might like some problem.condition_table.get_updates(condition_id) that provides a dictionary of updates to be applied. Then the keys can be used here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's already in a dict, the keys will be unique and we can't check for duplicates any. It works if we do the checking every time in such a function.
I think something like that will come when progressing with the importer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rather meant like this. It checks all conditions at once though, rather than one at a time, but there's no issue with identifying duplicates.

from collections import Counter
from itertools import chain

all_updates = [
    problem.condition_table.get_updates(condition_id)
    for condition_id in period.condition_ids
]
duplicates = {
    target_id
    for target_id, count in Counter(chain.from_iterable(all_updates)).items()
    if count > 1
}

Or a method that provides all_updates as a condition_id => updates dict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it simplifies the code here, just that it might be useful to tools. But fine to keep as is until a tool dev requests something...

Comment on lines +512 to +519
missing_conditions = (
set(
chain.from_iterable(
period.condition_ids for period in experiment.periods
)
)
- available_conditions
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing for here and below, is it useful to add this to the classes? Looks like a lot of additional interface though so fine as is

problem.experiment_table.get_condition_ids()
problem.experiment_table.get_experiment(experiment_id).get_condition_ids()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure yet. I think, usually one only needs the conditions for a single period, not for the full experiment at once.

"""Multiple conditions with overlapping targets cannot be applied
at the same time."""
problem = Problem()
problem.model = SbmlModel.from_antimony("p1 = 1; p2 = 2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

Didn't know an SBML test model could be specified so simply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
@dweindl dweindl merged commit 2a9142c into PEtab-dev:develop Apr 25, 2025
7 checks passed
@dweindl dweindl deleted the v2_combine_conditions branch April 25, 2025 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants