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.
- MEDS_extract/__init__.py +50 -0
- MEDS_extract/configs/__init__.py +0 -0
- MEDS_extract/configs/_extract.yaml +49 -0
- MEDS_extract/configs/stage_configs/__init__.py +0 -0
- MEDS_extract/configs/stage_configs/convert_to_sharded_events.yaml +2 -0
- MEDS_extract/configs/stage_configs/extract_code_metadata.yaml +3 -0
- MEDS_extract/configs/stage_configs/finalize_MEDS_data.yaml +2 -0
- MEDS_extract/configs/stage_configs/finalize_MEDS_metadata.yaml +3 -0
- MEDS_extract/configs/stage_configs/merge_to_MEDS_cohort.yaml +3 -0
- MEDS_extract/configs/stage_configs/shard_events.yaml +3 -0
- MEDS_extract/configs/stage_configs/split_and_shard_subjects.yaml +9 -0
- MEDS_extract/convert_to_sharded_events.py +907 -0
- MEDS_extract/extract_code_metadata.py +456 -0
- MEDS_extract/finalize_MEDS_data.py +138 -0
- MEDS_extract/finalize_MEDS_metadata.py +229 -0
- MEDS_extract/merge_to_MEDS_cohort.py +283 -0
- MEDS_extract/shard_events.py +426 -0
- MEDS_extract/split_and_shard_subjects.py +296 -0
- MEDS_extract/utils.py +133 -0
- meds_extract-0.1.dist-info/METADATA +315 -0
- meds_extract-0.1.dist-info/RECORD +25 -0
- meds_extract-0.1.dist-info/WHEEL +5 -0
- meds_extract-0.1.dist-info/entry_points.txt +8 -0
- meds_extract-0.1.dist-info/licenses/LICENSE +21 -0
- meds_extract-0.1.dist-info/top_level.txt +1 -0
MEDS_extract/__init__.py
ADDED
|
@@ -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
|