[e5f1db]: / docs / usage / usage.md

Download this file

433 lines (329 with data), 8.3 kB

API

Import the ehrapy API as follows:

import ehrapy as ep

You can then access the respective modules like:

ep.pl.cool_fancy_plot()
.. currentmodule:: ehrapy

Reading and writing

.. module:: ehrapy
.. autosummary::
    :toctree: io
    :nosignatures:

    io.read_csv
    io.read_h5ad
    io.read_fhir
    io.write

Data

.. autosummary::
    :toctree: data
    :nosignatures:

    data.mimic_2
    data.mimic_2_preprocessed
    data.mimic_3_demo
    data.diabetes_130_raw
    data.diabetes_130_fairlearn
    data.heart_failure
    data.chronic_kidney_disease
    data.breast_tissue
    data.cervical_cancer_risk_factors
    data.dermatology
    data.echocardiogram
    data.heart_disease
    data.hepatitis
    data.statlog_heart
    data.thyroid
    data.breast_cancer_coimbra
    data.parkinson_dataset_with_replicated_acoustic_features
    data.parkinsons
    data.parkinsons_disease_classification
    data.parkinsons_telemonitoring

Preprocessing

Any transformation of the data matrix that is not a tool.
Other than tools, preprocessing steps usually don’t return an easily interpretable annotation, but perform a basic transformation on the data matrix.

Basic preprocessing

.. autosummary::
    :toctree: preprocessing
    :nosignatures:

    preprocessing.encode
    preprocessing.pca
    preprocessing.regress_out
    preprocessing.subsample
    preprocessing.balanced_sample
    preprocessing.highly_variable_features
    preprocessing.winsorize
    preprocessing.clip_quantile
    preprocessing.summarize_measurements

Quality control

.. autosummary::
    :toctree: preprocessing
    :nosignatures:

    preprocessing.qc_metrics
    preprocessing.qc_lab_measurements
    preprocessing.mcar_test
    preprocessing.detect_bias

Imputation

.. autosummary::
    :toctree: preprocessing
    :nosignatures:

    preprocessing.explicit_impute
    preprocessing.simple_impute
    preprocessing.knn_impute
    preprocessing.miss_forest_impute
    preprocessing.mice_forest_impute

Normalization

.. autosummary::
    :toctree: preprocessing
    :nosignatures:

    preprocessing.log_norm
    preprocessing.maxabs_norm
    preprocessing.minmax_norm
    preprocessing.power_norm
    preprocessing.quantile_norm
    preprocessing.robust_scale_norm
    preprocessing.scale_norm
    preprocessing.offset_negative_values

Dataset Shift Correction

Partially overlaps with dataset integration. Note that a simple batch correction method is available via pp.regress_out().

.. autosummary::
    :toctree: preprocessing
    :nosignatures:

    preprocessing.combat

Neighbors

.. autosummary::
    :toctree: preprocessing
    :nosignatures:

    preprocessing.neighbors

Tools

Any transformation of the data matrix that is not preprocessing.
In contrast to a preprocessing function, a tool usually adds an easily interpretable annotation to the data matrix, which can then be visualized with a corresponding plotting function.

Embeddings

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.tsne
    tools.umap
    tools.draw_graph
    tools.diffmap
    tools.embedding_density

Clustering and trajectory inference

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.leiden
    tools.dendrogram
    tools.dpt
    tools.paga

Feature Ranking

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.rank_features_groups
    tools.filter_rank_features_groups
    tools.rank_features_supervised

Dataset integration

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.ingest

Natural language processing

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.annotate_text
    tools.get_medcat_annotation_overview
    tools.add_medcat_annotation_to_obs

Survival Analysis

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.ols
    tools.glm
    tools.kaplan_meier
    tools.test_kmf_logrank
    tools.test_nested_f_statistic
    tools.cox_ph
    tools.weibull_aft
    tools.log_logistic_aft
    tools.nelson_aalen
    tools.weibull

Causal Inference

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.causal_inference

Cohort Tracking

.. autosummary::
    :toctree: tools
    :nosignatures:

    tools.CohortTracker

Plotting

The plotting module ehrapy.pl.\* largely parallels the tl.\* and a few of the pp.\* functions.
For most tools and for some preprocessing functions, you will find a plotting function with the same name.

Generic

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.scatter
    plot.heatmap
    plot.dotplot
    plot.tracksplot
    plot.violin
    plot.stacked_violin
    plot.matrixplot
    plot.clustermap
    plot.ranking
    plot.dendrogram
    plot.catplot

Quality Control and missing values

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.missing_values_matrix
    plot.missing_values_barplot
    plot.missing_values_heatmap
    plot.missing_values_dendrogram

Classes

Please refer to Scanpy's plotting classes documentation.

Tools

Methods that extract and visualize tool-specific annotation in an AnnData object. For any method in module tl, there is a method with the same name in pl.

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.pca
    plot.pca_loadings
    plot.pca_variance_ratio
    plot.pca_overview

Embeddings

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.tsne
    plot.umap
    plot.diffmap
    plot.draw_graph
    plot.embedding
    plot.embedding_density

Branching trajectories and pseudotime

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.dpt_groups_pseudotime
    plot.dpt_timeseries
    plot.paga
    plot.paga_path
    plot.paga_compare

Feature Ranking

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.rank_features_groups
    plot.rank_features_groups_violin
    plot.rank_features_groups_stacked_violin
    plot.rank_features_groups_heatmap
    plot.rank_features_groups_dotplot
    plot.rank_features_groups_matrixplot
    plot.rank_features_groups_tracksplot
    plot.rank_features_supervised

Survival Analysis

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.ols
    plot.kaplan_meier
    plot.cox_ph_forestplot

Causal Inference

.. autosummary::
    :toctree: plot
    :nosignatures:

    plot.causal_effect

AnnData utilities

.. autosummary::
    :toctree: anndata
    :nosignatures:

    anndata.infer_feature_types
    anndata.feature_type_overview
    anndata.replace_feature_types
    anndata.df_to_anndata
    anndata.anndata_to_df
    anndata.move_to_obs
    anndata.delete_from_obs
    anndata.move_to_x
    anndata.get_obs_df
    anndata.get_var_df
    anndata.get_rank_features_df

Settings

A convenience object for setting some default {obj}matplotlib.rcParams and a
high-resolution jupyter display backend useful for use in notebooks.

An instance of the {class}~scanpy._settings.ScanpyConfig is available as ehrapy.settings and allows configuring ehrapy.

import ehrapy as ep

ep.settings.set_figure_params(dpi=150)

Please refer to the Scanpy settings documentation
for configuration options. ehrapy will adapt these in the future and update the documentation.

Dependency Versions

ehrapy is complex software with many dependencies. To ensure a consistent runtime environment you should save all
versions that were used for an analysis. This comes in handy when trying to diagnose issues and to reproduce results.

Call the function via:

import ehrapy as ep

ep.print_versions()