ehrapy: Electronic Health Record Analysis with Python

repository·main·Indexed 43 days ago

https://github.com/theislab/ehrapy

A modular open-source Python framework for the end-to-end exploratory analysis of heterogeneous epidemiological and Electronic Health Record (EHR) data. Version 0.15.0 provides a full pipeline covering data ingestion, quality control, and advanced analyses including clustering, survival analysis, trajectory inference, causal inference, and deep learning. It utilizes the EHRData structure based on the AnnData format for compatibility with the scverse ecosystem.

Tokens
6K
Snippets
28
Records
49
Agent score
56%

What's inside ehrapy

  1. Overview of ehrapy preprocessing modules

    main
    Preprocessing in ehrapy involves transformations applied to the data matrix, typically targeting the .X attribute or specific .layers of an AnnData object. The preprocessing module is organized into several functional categories: basic transformations, filtering, quality control, imputation, normalization, dataset shift correction, neighbor computation, and correlation analysis.
  2. Overview of ehrapy capabilities

    main

    ehrapy is a modular open-source Python framework designed for the exploratory analysis of heterogeneous epidemiological and Electronic Health Record (EHR) data. It provides a full pipeline including:

    • Data Ingestion & Quality Control
    • Advanced Analyses: Clustering, survival analysis, trajectory analysis, causal inference, and deep learning.
  3. Overview of the ehrapy plotting module

    main
    The plotting module ehrapy.pl.* is designed to visualize results from ehrapy tools and preprocessing functions. It largely follows the naming convention used in tl.* (tools) and some pp.* (preprocessing) functions. For most tool-based analyses, a corresponding plotting function exists in ehrapy.pl with the same name.
  4. Overview of the ehrapy analysis workflow

    main

    The ehrapy framework is designed with a modular workflow that allows users to customize their analysis pipelines. A typical workflow consists of three interconnected stages:

    1. Data loading and preprocessing: Importing data from various sources, mapping against ontologies, performing quality control, normalization, and imputation.
    2. Exploration and visualization: Generating lower-dimensional embeddings, performing clustering, and creating visualizations to understand patient landscapes.
    3. Knowledge inference: Conducting statistical analysis, patient stratification, survival analysis, causal inference, and trajectory inference.
  5. Access ehrapy submodules

    main

    The ehrapy API is organized into functional modules. You can access specific functionalities through these submodules. For example, tools are located under ep.tl.

    Available top-level modules include:

    • ep.io: Input/Output operations
    • ep.preprocessing: Preprocessing workflows
    • ep.tl: Tools (e.g., ep.tl.tool())
    • ep.pl: Plotting and visualization
    • ep.settings: Configuration and settings
    # Example of accessing a tool module
    ep.tl.tool()
  6. Understand the EHRData structure

    main

    ehrapy uses a standardized data structure called EHRData to handle the complexities of heterogeneous electronic health record (EHR) data. This structure organizes data into a consistent format where:

    • Rows represent observations (such as patients or visits).
    • Columns represent variables (such as measurements or clinical features).
    • Time can optionally be represented as a third dimension.

    EHRData is based on the AnnData format, ensuring compatibility with the scverse ecosystem and other scientific Python libraries used for machine learning and statistical analysis.

  7. What are ehrapy tools and how do they differ from preprocessing?

    main
    In ehrapy, tools are defined as any transformation of the data matrix that is not considered preprocessing. While preprocessing functions prepare the data, tools typically add easily interpretable annotations to the data matrix. These annotations are designed to be used with corresponding plotting functions for visualization.
  8. Using Jupyter notebooks as tutorials

    main

    Tutorials are rendered from .ipynb files located in the docs/notebooks directory using myst-nb.

    Key requirements for tutorials:

    • Only .ipynb format is supported.
    • Notebooks must include both input and output cells.
    • It is the contributor's responsibility to update and re-run notebooks to ensure they are current.

    Note on Submodules: The notebooks are sourced from the ehrapy-tutorials git submodule. When updating tutorials, you must submit pull requests to both the ehrapy-tutorials repository and the ehrapy repository (to update the submodule pointer) to keep them in sync.

  9. Causal Inference in ehrapy

    main

    ehrapy includes a lightweight set of causal inference estimators built on scikit-learn.

    Average Treatment Effect (ATE) Estimators (for binary treatments via IPTW, parametric g-computation, doubly-robust AIPW, or propensity score matching):

    • tools.iptw
    • tools.g_computation
    • tools.aipw
    • tools.propensity_score_matching

    Conditional Average Treatment Effect (CATE) Estimators (Meta-learners):

    • tools.t_learner
    • tools.s_learner
    • tools.x_learner

    Diagnostics:

    • tools.covariate_balance
    • tools.positivity_check
    • tools.CausalEstimate
  10. How documentation is structured in ehrapy

    main

    Ehrapy uses Sphinx as its documentation engine with several extensions to support modern documentation workflows:

    • Markdown/MyST: The myst extension allows writing documentation in Markdown or MyST.
    • Docstrings: Uses Numpy-style docstrings via the napoleon extension.
    • Type Hints: sphinx-autodoc-typehints is used to automatically reference annotated input and output types.
    • Citations: Citations (e.g., {cite:p}Virshup_2023) are supported via sphinxcontrib-bibtex`.
    • Tutorials: Jupyter notebooks are rendered as tutorials using myst-nb.

    For detailed guidance on writing docstrings, refer to the Numpy docstring format.

  11. Read and write datasets with EHRData

    main
    To perform input/output operations such as reading from or writing to files, use the methods provided by the EHRData class. Detailed documentation on specific file formats and the available I/O methods can be found in the ehrdata:api/io_index module.