Skip to main content

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

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.

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: all_newborn_delivery
    anchor_range: [-365, 365]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phenopipe-0.5.0.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phenopipe-0.5.0-py3-none-any.whl (89.8 kB view details)

Uploaded Python 3

File details

Details for the file phenopipe-0.5.0.tar.gz.

File metadata

  • Download URL: phenopipe-0.5.0.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for phenopipe-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d24266d5a20992184877c9932ec504f015edebc9b5954dd48a1e01d117a4ab14
MD5 3934697af17b728891287fc55eb5c9f7
BLAKE2b-256 95a805beeccd5ec36b8825a99ba54686bc67d451dc1df492545f32de486544ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for phenopipe-0.5.0.tar.gz:

Publisher: python-publish.yml on cakarac/phenopipe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file phenopipe-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: phenopipe-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 89.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for phenopipe-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9987f8cf7c98148bff6905a25655ce31b256bd6a17d093fc94adef34fc4a788
MD5 b2dca34643622b0f68cb7a6a6dee773d
BLAKE2b-256 799d7b110cdc6e8db28cd58aa5c08c876622b73a5aa69176cffe6f897059fe5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for phenopipe-0.5.0-py3-none-any.whl:

Publisher: python-publish.yml on cakarac/phenopipe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page