No project description provided
Project description
Phenopipe
Python Functions for Phenotyping and Analysis
Phenopipe is a Python library to automate phenotyping and downstream analysis. Its main development target is All of Us research platform. Phenopipe is heavily inspired by and borrowed query definitions from https://github.com/annisjs/aou.phenotyper2 and https://github.com/annisjs/aou.reader
Tasks
The basic building block in phenopipe library is a task which is a class from tasks module. A task represents a single step in phenotyping and analysis. Its inputs are polars dataframes and it has a single polars dataframe output. Therefore tasks' outputs can be passed to other tasks. This can be automated using input_tasks attribute in task class. Each task in input_tasks will be completed prior to task completion and those outputs will be added to inputs. Each task need to have a complete method which contains the logic of the data retrieval and/or analysis step and completion decorator automates common operations prior and after task is completed.
Data Queries
A common task type is getting the data from the database. These tasks are collected under get_data module in tasks module. These tasks contains additional attributes such as caching and lazy dataframe evaulation. Data queries are planned by tasks but it is run inside query connection objects which are provided in query_connections module. The goal is to allow running the same data tasks on different platform by simply changing the query connection in enviroment variables. This is partially achieved for other platforms designed around OMOP Data Model like AOU, however AOU specific data structures does not fully allow this. To track if a task is compatible (or tested) with a platform state attribute is used. This attribute holds a key value pair where keys are shared with query platform attribute of query connections and values indicate if task is compatible. Value can be one of the followings:
incompatible: Indicates the task is known to be incompatible with the platform. parsed: Indicates the task is parsed from another library and it is not yet tested. untested: Indicates the task in not tested on this platform. unverified: Indicates the resulting data is not yet verified. tested: Indicates the task is tested on this platform verified: Indicates the task is verified on this platform which means the resulting data is used in an analysis and didn't show any inconsistencies.
Environment Variables
env_vars attribute in task object holds variables that is shared between different tasks. It is also used to share common variables between tasks in a analysis. An example variable is query connection stored in env_vars to delegate communication with database.
Plan
A Pipe object holds a phenotyping and analysis plan as a dictionary of tasks and a env_vars attribute. Pipe object has a run method which will complete each task and merge each result on its anchor. Only tasks outputs without any anchor is saved in outputs dictionary.
Inputs
A task can accept other tasks or their outputs as inputs. Each task may have a minimal input schema which describes the minimal column names and data types in order to task to run succesfully. Similarly every task has a minimal output schema which describes the minimal column names and data types in the output dataframe so any task can determine if it accepts the task as input. All input schemas and output schema are validated during task completion.
Anchor Input
Anchor keyword in inputs dictionary is reserved for a data frame defining a selection criteria of the output. This can be described using anchor_date, anchor_range, anchor_pid attributes in the task object. Anchor range list of two literal which can be column names in anchor input dataframe or integers determining the time window for selection around anchor_date_col column in anchor dataframe. Anchor pid is the name of the column of person ids in the anchor dataframe to be used during subsetting.
Data Aggregate
Any task can indicate an aggregate function that will be run after or alongside the anchoring. This can be first, last, closest:nearest, closest:forward, closest:backward. For closest aggregate an anchor needs to be given. Ties are broken randomly but consistently.
Templating
Phenopipe provides a templating structure to define a Pipe object using yaml files (or strings or dictionaries in the same format). The function build_pipe_from_yaml will accept the file name for a yaml. The pipe object obtained using example below will collect initial hypertension diagnosis where there is a heart failure hospitalization in one year window before or after and return with the first heart failure hospitalization date in that window. Each task is given as a absolute import import such as phenopipe.tasks.get_data.hospitalization.FirstHfHospitalizationData or commonly used modules can be described using modules keyword and relative import can be given such as modules.phenotype.HypertensionPt for convenience. Query connection will be translated as the camelcase class of the underscored name given in the template. All parameters under the task id will be passed into task init method. The inputs of a task can be other tasks in the plan given by using the identifier.
target: examples
cache: false
lazy: false
env_vars:
query_conn: big_query_connection
modules:
phenotype: phenopipe.tasks.get_data.phenotype
tasks:
hypertension:
task_name: modules.phenotype.HypertensionPt
cache_type: std
first_hf_hospitalization:
task_name: phenopipe.tasks.get_data.hospitalization.FirstHfHospitalizationData
cache_type: std
inputs:
anchor: hypertension
anchor_range: [-365, 365]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phenopipe-0.6.0a1.tar.gz.
File metadata
- Download URL: phenopipe-0.6.0a1.tar.gz
- Upload date:
- Size: 74.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e44d0bcf42e19b123a1b390f7f881e452b4d01d0566dd70ebe7895eeeaf39d51
|
|
| MD5 |
284951ae037d7d71d20ce80024f40e09
|
|
| BLAKE2b-256 |
83b9999d2072eb52fa3e91f54e8123f32f71984db3809ccd8ad7d2243970f131
|
Provenance
The following attestation bundles were made for phenopipe-0.6.0a1.tar.gz:
Publisher:
python-publish.yml on cakarac/phenopipe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phenopipe-0.6.0a1.tar.gz -
Subject digest:
e44d0bcf42e19b123a1b390f7f881e452b4d01d0566dd70ebe7895eeeaf39d51 - Sigstore transparency entry: 434850304
- Sigstore integration time:
-
Permalink:
cakarac/phenopipe@09c9eb3e4f9c2e68d659ef218ea9c408ee467a8c -
Branch / Tag:
refs/tags/0.6.0a1 - Owner: https://github.com/cakarac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@09c9eb3e4f9c2e68d659ef218ea9c408ee467a8c -
Trigger Event:
push
-
Statement type:
File details
Details for the file phenopipe-0.6.0a1-py3-none-any.whl.
File metadata
- Download URL: phenopipe-0.6.0a1-py3-none-any.whl
- Upload date:
- Size: 193.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ca9960ab11d2178a0aa3a9c308fc242401d1f08decbbfa42f82e3de5e96c98d
|
|
| MD5 |
d18828e0907e0daa26e71efd41f785fd
|
|
| BLAKE2b-256 |
302e44d124f61342e6235267a3c254a83763d095e25c8d387bf530f3d55e3e12
|
Provenance
The following attestation bundles were made for phenopipe-0.6.0a1-py3-none-any.whl:
Publisher:
python-publish.yml on cakarac/phenopipe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phenopipe-0.6.0a1-py3-none-any.whl -
Subject digest:
0ca9960ab11d2178a0aa3a9c308fc242401d1f08decbbfa42f82e3de5e96c98d - Sigstore transparency entry: 434850366
- Sigstore integration time:
-
Permalink:
cakarac/phenopipe@09c9eb3e4f9c2e68d659ef218ea9c408ee467a8c -
Branch / Tag:
refs/tags/0.6.0a1 - Owner: https://github.com/cakarac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@09c9eb3e4f9c2e68d659ef218ea9c408ee467a8c -
Trigger Event:
push
-
Statement type: