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 stings or dictionaries in the same format). The function build_pipe_from_yaml will accept the file name for a yaml. This pipe object example below will collect initial obesity diagnosis where there is a sleep apnea diagnosis in one year window before or after. Each task is given as a absolute import import such as phenopipe.tasks.get_data.phenotype.FirstSleepApneaPt or commonly used modules can be described using modules keyword and relative import can be given such as modules.phenotype.FirstObesityPt 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:
  first_obesity:
    task_name: modules.phenotype.FirstObesityPt
    cache_type: std
  first_sleep_apnea:
    task_name: phenopipe.tasks.get_data.phenotype.FirstSleepApneaPt
    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.4.0a1.tar.gz (51.4 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.4.0a1-py3-none-any.whl (86.7 kB view details)

Uploaded Python 3

File details

Details for the file phenopipe-0.4.0a1.tar.gz.

File metadata

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

File hashes

Hashes for phenopipe-0.4.0a1.tar.gz
Algorithm Hash digest
SHA256 e6fa4e0da2c45816b1a9696e47f420a3ed42b4022193083e2fdfd91e88d850e2
MD5 cec905eed0ee7e5718e99fa0afda41fd
BLAKE2b-256 308788e83d491e2448355d352de22cccb3125b2cbf4f12d5774dd4de0a8cd82a

See more details on using hashes here.

Provenance

The following attestation bundles were made for phenopipe-0.4.0a1.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.4.0a1-py3-none-any.whl.

File metadata

  • Download URL: phenopipe-0.4.0a1-py3-none-any.whl
  • Upload date:
  • Size: 86.7 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.4.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 eaddcdb177352d202d245164c4b102c24eed8224213d6d09e9a01d0861de91ec
MD5 748bf830ec4d82b2b8fb3c0720532c6f
BLAKE2b-256 c36520bad504b3e9b2b242095f1f47680f4a24520cbaef2056674fd234d29dc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for phenopipe-0.4.0a1-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