v2: Allow applying multiple conditions simultaneously#373
v2: Allow applying multiple conditions simultaneously#373dweindl merged 4 commits intoPEtab-dev:developfrom
Conversation
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
bc56350 to
d1f692f
Compare
dilpath
left a comment
There was a problem hiding this comment.
Looks good! Nothing that needs to be changed.
| 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) | ||
| ] |
There was a problem hiding this comment.
Might need to add a dropna
| 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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| condition_targets = { | ||
| change.target_id | ||
| for cond in problem.condition_table.conditions | ||
| if cond.id == condition_id | ||
| for change in cond.changes | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
| missing_conditions = ( | ||
| set( | ||
| chain.from_iterable( | ||
| period.condition_ids for period in experiment.periods | ||
| ) | ||
| ) | ||
| - available_conditions | ||
| ) |
There was a problem hiding this comment.
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()There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
🤯
Didn't know an SBML test model could be specified so simply.
Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
Adapt to PEtab-dev/PEtab#616, which allows providing multiple conditions for the same experiment / timepoint.