MEDS-extract 0.1__py3-none-any.whl

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.
@@ -0,0 +1,50 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+ from importlib.resources import files
3
+
4
+ import polars as pl
5
+ from meds import code_field, subject_id_field, time_field
6
+
7
+ __package_name__ = "MEDS_extract"
8
+ try:
9
+ __version__ = version(__package_name__)
10
+ except PackageNotFoundError: # pragma: no cover
11
+ __version__ = "unknown"
12
+
13
+ CONFIG_YAML = files(__package_name__).joinpath("configs/_extract.yaml")
14
+
15
+ MANDATORY_COLUMNS = [subject_id_field, time_field, code_field, "numeric_value"]
16
+
17
+ MANDATORY_TYPES = {
18
+ subject_id_field: pl.Int64,
19
+ time_field: pl.Datetime("us"),
20
+ code_field: pl.String,
21
+ "numeric_value": pl.Float32,
22
+ "categorical_value": pl.String,
23
+ "text_value": pl.String,
24
+ }
25
+
26
+ DEPRECATED_NAMES = {
27
+ "numerical_value": "numeric_value",
28
+ "categoric_value": "categoric_value",
29
+ "category_value": "categoric_value",
30
+ "textual_value": "text_value",
31
+ "timestamp": "time",
32
+ "patient_id": subject_id_field,
33
+ }
34
+
35
+ INFERRED_STAGE_KEYS = {
36
+ "is_metadata",
37
+ "data_input_dir",
38
+ "metadata_input_dir",
39
+ "output_dir",
40
+ "reducer_output_dir",
41
+ }
42
+
43
+ # TODO(mmd): This should really somehow be pulled from MEDS.
44
+ MEDS_METADATA_MANDATORY_TYPES = {
45
+ "code": pl.String,
46
+ "description": pl.String,
47
+ "parent_codes": pl.List(pl.String),
48
+ }
49
+
50
+ MEDS_DATA_MANDATORY_TYPES = {c: MANDATORY_TYPES[c] for c in MANDATORY_COLUMNS}
File without changes
@@ -0,0 +1,49 @@
1
+ defaults:
2
+ - _pipeline
3
+ - stage_configs:
4
+ - shard_events
5
+ - split_and_shard_subjects
6
+ - convert_to_sharded_events
7
+ - merge_to_MEDS_cohort
8
+ - extract_code_metadata
9
+ - finalize_MEDS_metadata
10
+ - finalize_MEDS_data
11
+ # There is no configuration beyond the global "event_conversion_config_fp" for the
12
+ # convert_to_sharded_events stage, so it doesn't have a stage config block here or below.
13
+ - _self_
14
+
15
+ etl_metadata.pipeline_name: "extract"
16
+
17
+ description: |-
18
+ This pipeline extracts raw MEDS events in longitudinal, sparse form from an input dataset meeting select
19
+ criteria and converts them to the flattened, MEDS format. It can be run in its entirety, with controllable
20
+ levels of parallelism, or in stages. Arguments:
21
+ - `event_conversion_config_fp`: The path to the event conversion configuration file. This file defines
22
+ the events to extract from the various rows of the various input files encountered in the global input
23
+ directory.
24
+ - `input_dir`: The path to the directory containing the raw input files.
25
+ - `cohort_dir`: The path to the directory where the output cohort will be written. It will be written in
26
+ various subfolders of this dir depending on the stage, as intermediate stages cache their output during
27
+ computation for efficiency of re-running and distributing.
28
+
29
+ # The event conversion configuration file is used throughout the pipeline to define the events to extract.
30
+ event_conversion_config_fp: ???
31
+ # The shards mapping is stored in the root of the final output directory.
32
+ shards_map_fp: "${cohort_dir}/metadata/.shards.json"
33
+
34
+ stages:
35
+ - shard_events
36
+ - split_and_shard_subjects
37
+ - convert_to_sharded_events
38
+ - merge_to_MEDS_cohort
39
+ - extract_code_metadata
40
+ - finalize_MEDS_metadata
41
+ - finalize_MEDS_data
42
+
43
+ stage_configs:
44
+ shard_events:
45
+ data_input_dir: "${input_dir}"
46
+
47
+ hydra:
48
+ searchpath:
49
+ - pkg://MEDS_transforms.configs
File without changes
@@ -0,0 +1,2 @@
1
+ convert_to_sharded_events:
2
+ do_dedup_text_and_numeric: True
@@ -0,0 +1,3 @@
1
+ extract_code_metadata:
2
+ is_metadata: true
3
+ description_separator: "\n"
@@ -0,0 +1,2 @@
1
+ finalize_MEDS_data:
2
+ do_retype: true
@@ -0,0 +1,3 @@
1
+ finalize_MEDS_metadata:
2
+ is_metadata: True
3
+ do_retype: True
@@ -0,0 +1,3 @@
1
+ merge_to_MEDS_cohort:
2
+ unique_by: "*"
3
+ additional_sort_by: null
@@ -0,0 +1,3 @@
1
+ shard_events:
2
+ row_chunksize: 200000000
3
+ infer_schema_length: 10000
@@ -0,0 +1,9 @@
1
+ split_and_shard_subjects:
2
+ is_metadata: True
3
+ output_dir: ${cohort_dir}/metadata
4
+ n_subjects_per_shard: 50000
5
+ external_splits_json_fp: null
6
+ split_fracs:
7
+ train: 0.8
8
+ tuning: 0.1
9
+ held_out: 0.1