guts-base 1.0.6__tar.gz → 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of guts-base might be problematic. Click here for more details.

Files changed (36) hide show
  1. {guts_base-1.0.6 → guts_base-1.0.7}/PKG-INFO +1 -1
  2. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/__init__.py +1 -1
  3. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/openguts.py +2 -0
  4. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/time_of_death.py +35 -11
  5. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/base.py +26 -16
  6. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base.egg-info/PKG-INFO +1 -1
  7. {guts_base-1.0.6 → guts_base-1.0.7}/pyproject.toml +2 -2
  8. {guts_base-1.0.6 → guts_base-1.0.7}/LICENSE +0 -0
  9. {guts_base-1.0.6 → guts_base-1.0.7}/README.md +0 -0
  10. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/__init__.py +0 -0
  11. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/expydb.py +0 -0
  12. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/generator.py +0 -0
  13. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/preprocessing.py +0 -0
  14. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/survival.py +0 -0
  15. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/data/utils.py +0 -0
  16. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/mod.py +0 -0
  17. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/plot.py +0 -0
  18. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/prob.py +0 -0
  19. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/__init__.py +0 -0
  20. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/constructors.py +0 -0
  21. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/ecx.py +0 -0
  22. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/mempy.py +0 -0
  23. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/report.py +0 -0
  24. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base/sim/utils.py +0 -0
  25. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base.egg-info/SOURCES.txt +0 -0
  26. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base.egg-info/dependency_links.txt +0 -0
  27. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base.egg-info/entry_points.txt +0 -0
  28. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base.egg-info/requires.txt +0 -0
  29. {guts_base-1.0.6 → guts_base-1.0.7}/guts_base.egg-info/top_level.txt +0 -0
  30. {guts_base-1.0.6 → guts_base-1.0.7}/setup.cfg +0 -0
  31. {guts_base-1.0.6 → guts_base-1.0.7}/tests/test_data_import.py +0 -0
  32. {guts_base-1.0.6 → guts_base-1.0.7}/tests/test_ecx.py +0 -0
  33. {guts_base-1.0.6 → guts_base-1.0.7}/tests/test_from_pymob.py +0 -0
  34. {guts_base-1.0.6 → guts_base-1.0.7}/tests/test_scripted_simulations.py +0 -0
  35. {guts_base-1.0.6 → guts_base-1.0.7}/tests/test_simulations.py +0 -0
  36. {guts_base-1.0.6 → guts_base-1.0.7}/tests/test_symbolic_solve.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: guts_base
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Basic GUTS model implementation in pymob
5
5
  Author-email: Florian Schunck <fluncki@protonmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -4,7 +4,7 @@ from . import data
4
4
  from . import prob
5
5
  from . import plot
6
6
 
7
- __version__ = "1.0.6"
7
+ __version__ = "1.0.7"
8
8
 
9
9
  from .sim import (
10
10
  GutsBase,
@@ -251,6 +251,8 @@ def import_data_to_database(path, database, preprocessing: Optional[Callable] =
251
251
 
252
252
  experiment.to_database(database=database)
253
253
 
254
+ print("Import to database successful.")
255
+
254
256
 
255
257
  def create_database_and_import_data_main(datasets_path, database_path, preprocessing=None, preprocessing_out=None):
256
258
  print("\n")
@@ -225,7 +225,7 @@ def make_openguts_observation_table(
225
225
  experiment_start = get_unique_value(df["time_start_experiment"])
226
226
  experiment_end = get_unique_value(df["time_end_experiment"])
227
227
 
228
- time = pd.date_range(experiment_start, experiment_end, freq=observation_schedule)
228
+ times_nominal = pd.date_range(experiment_start, experiment_end, freq=observation_schedule)
229
229
  timecol_name = f"time [{observation_schedule.lower()}]"
230
230
 
231
231
 
@@ -234,13 +234,17 @@ def make_openguts_observation_table(
234
234
  # calculate survival time
235
235
  df[timecol_name] = df["time_death"] - df["time_start_experiment"]
236
236
 
237
- time_remainder = df[timecol_name] % pd.Timedelta(1, observation_schedule)
238
- if (time_remainder > pd.Timedelta(0)).any():
239
- raise ValueError(
240
- "Observations should be entered at the same time as the experiment start "+
241
- "df['time_death] - df['time_experiment_start'] should be a multiple of "+
242
- f"the time resolution of the observation schedule. Here: 1{observation_schedule}"
243
- )
237
+ # this seems to have been necessary, because reindexing removed times smaller than
238
+ # the observation_schedule interval. This is now resolved by concatenating true
239
+ # times and nominal times
240
+ # TODO: remove this commented block when there appear no more errors
241
+ # time_remainder = df[timecol_name] % pd.Timedelta(1, observation_schedule)
242
+ # if (time_remainder > pd.Timedelta(0)).any():
243
+ # raise ValueError(
244
+ # "Observations should be entered at the same time as the experiment start "+
245
+ # "df['time_death] - df['time_experiment_start'] should be a multiple of "+
246
+ # f"the time resolution of the observation schedule. Here: 1{observation_schedule}"
247
+ # )
244
248
 
245
249
  if observation == "censored":
246
250
  # sum IDs that were marked as censored at time t
@@ -258,8 +262,12 @@ def make_openguts_observation_table(
258
262
  # df to wide frame
259
263
  df_wide = long_to_wide(df_long.reset_index(), id_columns, timecol_name, observation)
260
264
 
265
+ # get a time vector that contains all nominal observation times and also actually
266
+ # occurred days
267
+ observation_times = np.unique(np.concatenate([df_wide.index, times_nominal-experiment_start]))
268
+
261
269
  # reindex wide dataframe on time
262
- df_wide = df_wide.reindex(index=time-experiment_start, method=None)
270
+ df_wide = df_wide.reindex(index=observation_times, method=None)
263
271
  df_wide.index = df_wide.index.set_names(timecol_name)
264
272
  df_wide = df_wide.fillna(0)
265
273
 
@@ -299,8 +307,10 @@ class TimeOfDeathIO:
299
307
  self.data = self.from_file()
300
308
 
301
309
  def main(file: str, sheet: str, out:str, intervention_columns: List[str],
310
+ extra_observation_columns: List[str] = [],
302
311
  observation_schedule="d", rect_interpolate=False):
303
312
  intervention_columns = clean_column_names(list(intervention_columns))
313
+ extra_observation_columns = clean_column_names(list(extra_observation_columns))
304
314
  processed_file = f"{out}/openguts_{os.path.basename(file)}"
305
315
 
306
316
  print("\n")
@@ -454,6 +464,17 @@ def main(file: str, sheet: str, out:str, intervention_columns: List[str],
454
464
  observation_schedule=observation_schedule,
455
465
  )
456
466
 
467
+ _extra_observations = []
468
+ for eob in extra_observation_columns:
469
+ ob_wide = make_openguts_observation_table(
470
+ data,
471
+ observation=eob,
472
+ observation_schedule=observation_schedule
473
+ )
474
+ _extra_observations.append(ob_wide)
475
+ excel_writer(ob_wide, file=processed_file, sheet=eob)
476
+
477
+
457
478
  deaths = lethality - censored
458
479
 
459
480
  # excel export
@@ -537,6 +558,7 @@ def main(file: str, sheet: str, out:str, intervention_columns: List[str],
537
558
  else:
538
559
  warnings.warn("No metadata found in sheets 'meta' or 'Info'.")
539
560
 
561
+ return processed_file
540
562
 
541
563
  @click.command()
542
564
  @click.option("--file", "-f", help="Path to the xlsx file")
@@ -544,12 +566,14 @@ def main(file: str, sheet: str, out:str, intervention_columns: List[str],
544
566
  @click.option("--out", "-o", help="Output directory", default="processed_data")
545
567
  @click.option("--observation_schedule", help="Schedule of the observations: d - daily, h - hourly", default="d")
546
568
  @click.option("--intervention_columns", "-c", multiple=True, type=str, help="Names of the columns that carry the exposure information")
547
- def time_of_death_to_openguts(file, sheet, out, observation_schedule, intervention_columns):
548
- main(
569
+ @click.option("--extra_observation_columns", "-e", multiple=True, type=str, default=[], help="Names of the columns that carry additional observations beside time-of-death and censoring")
570
+ def time_of_death_to_openguts(file, sheet, out, observation_schedule, intervention_columns, extra_observation_columns):
571
+ _ = main(
549
572
  file=file,
550
573
  sheet=sheet,
551
574
  out=out,
552
575
  intervention_columns=intervention_columns,
576
+ extra_observation_columns=extra_observation_columns,
553
577
  observation_schedule=observation_schedule
554
578
  )
555
579
 
@@ -49,6 +49,10 @@ class GutsBase(SimulationBase):
49
49
  results_interpolation: Tuple[float,float,int] = (np.nan, np.nan, 100)
50
50
  _skip_data_processing: bool = False
51
51
  ecx_mode: Literal["mean", "draws"] = "mean"
52
+ exposure_scenarios = {
53
+ "acute_1day": {"start": 0.0, "end": 1.0},
54
+ "chronic": {"start": 0.0, "end": None},
55
+ }
52
56
 
53
57
  def initialize(self, input: Optional[Dict] = None):
54
58
  """Initiaization goes through a couple of steps:
@@ -254,8 +258,9 @@ class GutsBase(SimulationBase):
254
258
  observations=self.observations
255
259
  )
256
260
 
257
- if "exposure" in self.observations:
258
- self.config.data_structure.exposure.observed=False
261
+ if "exposure" not in self.observations:
262
+ self.observations["exposure"] = self.observations[self.config.simulation.substance]
263
+ self.config.data_structure.exposure.observed=False
259
264
 
260
265
  def _convert_exposure_units(self):
261
266
  """
@@ -485,21 +490,26 @@ class GutsBase(SimulationBase):
485
490
  for coord in exposure_coordinates:
486
491
  concentrations = np.where(coord == exposure_coordinates, 1.0, 0.0)
487
492
 
488
- exposure_dict = {
489
- coord: ExposureDataDict(start=0, end=1, concentration=conc)
490
- for coord, conc in zip(exposure_coordinates, concentrations)
491
- }
492
-
493
- scenario = design_exposure_scenario(
494
- exposures=exposure_dict,
495
- t_max=time_max,
496
- dt=1/24,
497
- exposure_dimension=exposure_dimension
498
- )
493
+ for _name, _expo_scenario in self.exposure_scenarios.items():
494
+ exposure_dict = {
495
+ coord: ExposureDataDict(
496
+ start=_expo_scenario["start"],
497
+ end=_expo_scenario["end"],
498
+ concentration=conc
499
+ )
500
+ for coord, conc in zip(exposure_coordinates, concentrations)
501
+ }
502
+
503
+ scenario = design_exposure_scenario(
504
+ exposures=exposure_dict,
505
+ t_max=time_max,
506
+ dt=1/24,
507
+ exposure_dimension=exposure_dimension
508
+ )
499
509
 
500
- scenarios.update({
501
- f"1day_exposure_{coord}": scenario
502
- })
510
+ scenarios.update({
511
+ f"1day_exposure_{coord}": scenario
512
+ })
503
513
 
504
514
  return scenarios
505
515
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: guts_base
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Basic GUTS model implementation in pymob
5
5
  Author-email: Florian Schunck <fluncki@protonmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "guts_base"
7
- version = "1.0.6"
7
+ version = "1.0.7"
8
8
  authors = [
9
9
  { name="Florian Schunck", email="fluncki@protonmail.com" },
10
10
  ]
@@ -49,7 +49,7 @@ import-openguts = "guts_base.data.openguts:create_database_and_import_data"
49
49
  convert-time-of-death-to-openguts = "guts_base.data.time_of_death:time_of_death_to_openguts"
50
50
 
51
51
  [tool.bumpver]
52
- current_version = "1.0.6"
52
+ current_version = "1.0.7"
53
53
  version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
54
54
  commit_message = "bump version {old_version} -> {new_version}"
55
55
  tag_message = "{new_version}"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes