### Install Development Dependencies Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md Clones the pertpy repository and installs the package in editable mode with development, testing, and documentation dependencies. This setup is crucial for contributing to the project. ```bash git clone https://github.com/scverse/pertpy.git cd pertpy pip install -e ".[dev,test,doc]" ``` -------------------------------- ### Install pertpy via PyPI (pip) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs the most recent stable release of pertpy using pip. This is the recommended method for most users. Ensure pip is installed; refer to the Python installation guide if needed. ```shell pip install pertpy ``` -------------------------------- ### Clone pertpy from GitHub (git) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Clones the pertpy source code repository from GitHub. This method is useful for developers or for installing directly from the latest development version. ```shell $ git clone git://github.com/scverse/pertpy ``` -------------------------------- ### Install pertpy milo (de solver) dependencies (pip) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs pertpy with the 'de' extra, which is required for the 'pydeseq2' solver used with the milo functionality. ```shell pip install 'pertpy[de]' ``` -------------------------------- ### Install pertpy via conda-forge Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs pertpy from the conda-forge channel. This is an alternative installation method for users who prefer using conda for package management. ```shell conda install -c conda-forge pertpy ``` -------------------------------- ### Guide Assignment Example Source: https://github.com/scverse/pertpy/blob/main/docs/api/preprocessing_index.md Demonstrates how to use pertpy.pp.GuideAssignment to assign guides to cells based on thresholds. It loads data, preprocesses it, performs assignment, and plots a heatmap of the results. ```python import pertpy as pt import scanpy as sc mdata = pt.dt.papalexi_2021() gdo = mdata.mod["gdo"] gdo.layers["counts"] = gdo.X.copy() sc.pp.log1p(gdo) ga = pt.pp.GuideAssignment() ga.assign_by_threshold(gdo, 5, layer="counts", output_layer="assigned_guides") ga.plot_heatmap(gdo, layer="assigned_guides") ``` -------------------------------- ### Download pertpy tarball (curl) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Downloads the pertpy source code as a tarball from the master branch on GitHub. This is an alternative method for obtaining the source code. ```shell $ curl -OJL https://github.com/scverse/pertpy/tarball/master ``` -------------------------------- ### Install pertpy tascCODA dependencies (pip) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs pertpy with the 'tcoda' extra, which includes additional dependencies like ete4, pyqt6, and toytree required for the tascCODA functionality. ```shell pip install pertpy[tcoda] ``` -------------------------------- ### Install pertpy DGE dependencies (pip) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs additional dependencies required for the differential gene expression (DGE) interface of pertpy. This command installs the 'de' extra group. ```shell pip install pertpy[de] ``` -------------------------------- ### Install rpy2 dependency (pip) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs the rpy2 Python package, which is required for interfacing with R, specifically for the 'edger' solver in pertpy. ```shell pip install rpy2 ``` -------------------------------- ### Core Installation Source: https://github.com/scverse/pertpy/blob/main/README.md Install the core pertpy package using pip or conda. This provides the fundamental functionality for perturbation analysis. ```console pip install pertpy ``` ```console conda install -c conda-forge pertpy ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md Commands to build the project's documentation locally using Sphinx. This involves navigating to the docs directory and executing the make html command. ```bash cd docs make html open _build/html/index.html ``` -------------------------------- ### Install R dependencies for edgeR (R) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs the edgeR package from Bioconductor, which is a dependency for the 'edger' solver used with pertpy's DGE interface. Requires R and BiocManager. ```r BiocManager::install("edgeR") ``` -------------------------------- ### Install R dependencies for statmod (R) Source: https://github.com/scverse/pertpy/blob/main/docs/installation.md Installs the statmod package from Bioconductor, a dependency for the 'edger' solver used with milo in pertpy. Requires R and BiocManager. ```r BiocManager::install("statmod") ``` -------------------------------- ### Access Pertpy Tool Example Source: https://github.com/scverse/pertpy/blob/main/docs/api.md Shows an example of how to call a hypothetical tool within the pertpy library's toolkit module. This illustrates accessing submodules and their functions. ```python pt.tl.cool_fancy_tool() ``` -------------------------------- ### Enable Local Pre-commit Hooks Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md Installs pre-commit locally to automatically check and fix code styles on every commit. This ensures consistent code formatting across the project. ```bash pre-commit install ``` -------------------------------- ### Build Package Distributions Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md Builds the source archive and wheel distribution for the Python package using the 'build' tool. These distributions are required for publishing to PyPI. ```bash python -m build ``` -------------------------------- ### Publish Git Tags for Release Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md After updating the version number according to Semantic Versioning, push all created tags to GitHub to mark the release. ```bash git push --tags ``` -------------------------------- ### Check and Upload Package to PyPI Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md Validates the built distribution files using 'twine check' and then uploads them to the Python Package Index (PyPI) for distribution. ```bash twine check dist/* twine upload dist/* ``` -------------------------------- ### Optional Installation (Extras) Source: https://github.com/scverse/pertpy/blob/main/README.md Install pertpy with optional extras for specific functionalities. Use 'de' for differential gene expression analysis and 'tcoda' for tascCODA integration. ```console pip install 'pertpy[de]' ``` ```console pip install 'pertpy[tcoda]' ``` -------------------------------- ### Milo Dependencies Installation Source: https://github.com/scverse/pertpy/blob/main/README.md Install dependencies required for the milo functionality, which includes R packages for statistical analysis and the rpy2 Python package for interoperability. ```R BiocManager::install("edgeR") BiocManager::install("statmod") ``` ```console pip install rpy2 ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md Executes all automated tests using the pytest framework from the root of the repository. This is essential for verifying code changes before submission. ```bash pytest ``` -------------------------------- ### Rebase After Pre-commit.ci Changes Source: https://github.com/scverse/pertpy/blob/main/docs/contributing.md If pre-commit.ci automatically commits fixes to your pull request branch, use this command to rebase your local branch and integrate those changes. ```bash git pull --rebase ``` -------------------------------- ### scCODA/tascCODA Analysis with pertpy Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Demonstrates how to perform compositional data analysis using scCODA and tascCODA with pertpy. This involves loading single-cell data, preparing it for analysis by specifying cell type and sample identifiers, and running Bayesian inference. The example includes filtering data for specific conditions and visualizing results. ```Python import pertpy as pt haber_cells = pt.dt.haber_2017_regions() sccoda = pt.tl.Sccoda() sccoda_data = sccoda.load( haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", sample_identifier="batch", covariate_obs=["condition"], ) sccoda_data.mod["coda_salm"] = sccoda_data["coda"].obs["condition"].isin(["Control", "Salmonella"]) sccoda_data = sccoda.prepare( sccoda_data, modality_key="coda_salm", formula="condition", reference_cell_type="Goblet", ) sccoda.run_nuts(sccoda_data, modality_key="coda_salm") sccoda.summary(sccoda_data, modality_key="coda_salm") sccoda.plot_effects_barplot( sccoda_data, modality_key="coda_salm", parameter="Final Parameter" ) ``` -------------------------------- ### Compute Perturbation Space using PseudobulkSpace Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Calculates a perturbation space based on summary statistics, organizing cells into cohesive ensembles to understand collective perturbation impacts. This example uses PseudobulkSpace with RNA data and specifies target and group columns for computation. ```python import pertpy as pt mdata = pt.dt.papalexi_2021() ps = pt.tl.PseudobulkSpace() ps_adata = ps.compute( mdata["rna"], target_col="gene_target", groups_col="gene_target", mode="mean", ) ``` -------------------------------- ### Import Pertpy API Source: https://github.com/scverse/pertpy/blob/main/docs/api.md Demonstrates the standard way to import the pertpy library for use in Python projects. This is the initial step before accessing any of its functionalities. ```python import pertpy as pt ``` -------------------------------- ### Pairwise Distances and Permutation Tests with pertpy Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Illustrates calculating pairwise distances and performing permutation tests on perturbation data using pertpy. It covers initializing Distance and PermutationTest objects, calculating pairwise distances, and applying the E-test for statistical significance. ```python import pertpy as pt adata = pt.dt.distance_example() # Pairwise distances distance = pt.tl.Distance(metric="edistance", obsm_key="X_pca") pairwise_edistance = distance.pairwise(adata, groupby="perturbation") # E-test (Permutation test using E-distance) etest = pt.tl.PermutationTest( metric="edistance", obsm_key="X_pca", correction="holm-sidak" ) tab = etest(adata, groupby="perturbation", contrast="control") ``` -------------------------------- ### Response Prediction with Augur using pertpy Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Shows how to use the Augur module in pertpy for ranking cell types by their response to experimental perturbations. This involves loading data, initializing the Augur estimator, and predicting responses to quantify perturbation effects. ```python import pertpy as pt adata = pt.dt.sc_sim_augur() ag = pt.tl.Augur(estimator="random_forest_classifier") adata = ag.load(adata) adata, results = ag.predict(adata) # metrics for each cell type results["summary_metrics"] ``` -------------------------------- ### Pertpy Citation Source: https://github.com/scverse/pertpy/blob/main/README.md BibTeX entry for citing the pertpy framework in academic publications. It includes author information, title, publication venue, and DOI. ```bibtex @article {Heumos2024.08.04.606516, author = {Heumos, Lukas and Ji, Yuge and May, Lilly and Green, Tessa and Zhang, Xinyue and Wu, Xichen and Ostner, Johannes and Peidli, Stefan and Schumacher, Antonia and Hrovatin, Karin and Müller, Michaela and Chong, Faye and Sturm, Gregor and Tejada, Alejandro and Dann, Emma and Dong, Mingze and Bahrami, Mojtaba and Gold, Ilan and Rybakov, Sergei and Namsaraeva, Altana and Moinfar, Amir and Zheng, Zihe and Roellin, Eljas and Mekki, Isra and Sander, Chris and Lotfollahi, Mohammad and Schiller, Herbert B. and Theis, Fabian J.}, title = {Pertpy: an end-to-end framework for perturbation analysis}, elocation-id = {2024.08.04.606516}, year = {2024}, doi = {10.1101/2024.08.04.606516}, publisher = {Cold Spring Harbor Laboratory}, URL = {https://www.biorxiv.org/content/early/2024/08/07/2024.08.04.606516}, eprint = {https://www.biorxiv.org/content/early/2024/08/07/2024.08.04.606516.full.pdf}, journal = {bioRxiv} } ``` -------------------------------- ### Gene Expression Prediction with scGen using pertpy Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Demonstrates gene expression prediction for cell-type-specific responses to perturbations using scGen within pertpy. This includes setting up AnnData, training the scGen model, and predicting outcomes for specific cell types. ```python import pertpy as pt train = pt.dt.kang_2018() train_new = train[ ~((train.obs["cell_type"] == "CD4T") & (train.obs["condition"] == "stimulated")) ] train_new = train_new.copy() pt.tl.Scgen.setup_anndata(train_new, batch_key="condition", labels_key="cell_type") scgen = pt.tl.Scgen(train_new) scgen.train(max_epochs=100, batch_size=32) pred, delta = scgen.predict( ctrl_key="control", stim_key="stimulated", celltype_to_predict="CD4T" ) pred.obs["condition"] = "pred" ``` -------------------------------- ### Multicellular Program Discovery with DIALOGUE Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Illustrates the use of the DIALOGUE method in pertpy for discovering latent multicellular programs from single-cell or spatial transcriptomics data. The process involves calculating multi-factor PMD (Proportion of Mutual Dependence) and performing multilevel modeling to identify genes associated with these programs, considering confounders. ```Python import pertpy as pt import scanpy as sc adata = pt.dt.dialogue_example() sc.pp.pca(adata) sc.pp.neighbors(adata) sc.tl.umap(adata) dl = pt.tl.Dialogue( sample_id="clinical.status", celltype_key="cell.subtypes", n_counts_key="nCount_RNA", n_mpcs=3, ) adata, mcps, ws, ct_subs = dl.calculate_multifactor_PMD(adata, normalize=True) all_results, new_mcps = dl.multilevel_modeling( ct_subs=ct_subs, mcp_scores=mcps, ws_dict=ws, confounder="gender", ) ``` -------------------------------- ### Milo Differential Abundance Testing Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Enables exploration of differential abundance of cell types across biological conditions using Milo. It employs a neighborhood-testing approach to statistically assess variations in cell type compositions, providing insights into microenvironmental heterogeneity. ```python import pertpy as pt import scanpy as sc adata = pt.dt.stephenson_2021_subsampled() adata.obs["COVID_severity"] = adata.obs["Status_on_day_collection_summary"].copy() adata.obs[["patient_id", "COVID_severity"]].drop_duplicates() adata = adata[adata.obs["Status"] != "LPS"].copy() milo = pt.tl.Milo() mdata = milo.load(adata) sc.pp.neighbors(mdata["rna"], use_rep="X_scVI", n_neighbors=150, n_pcs=10) milo.make_nhoods(mdata["rna"], prop=0.1) mdata = milo.count_nhoods(mdata, sample_col="patient_id") mdata["rna"].obs["Status"] = ( mdata["rna"].obs["Status"].cat.reorder_categories(["Healthy", "Covid"]) ) milo.da_nhoods(mdata, design="~Status") ``` -------------------------------- ### Enrichment Analysis with pertpy Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Demonstrates how to perform enrichment tests on single-cell data using the pertpy library. It involves initializing an Enrichment object and scoring the AnnData object to identify overrepresented pathways or gene sets. ```python import pertpy as pt import scanpy as sc adata = sc.datasets.pbmc3k_processed() pt_enricher = pt.tl.Enrichment() pt_enricher.score(adata) ``` -------------------------------- ### Analyze Causal Effects with CINEMA-OT Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Performs causal perturbation analysis using CINEMA-OT to identify individual treatment effects and synergy. It requires an AnnData object and specifies perturbation keys, control conditions, and solver parameters for calculating causal effects. ```python import pertpy as pt adata = pt.dt.cinemaot_example() model = pt.tl.Cinemaot() de = model.causaleffect( adata, pert_key="perturbation", control="No stimulation", return_matching=True, thres=0.5, smoothness=1e-5, eps=1e-3, solver="Sinkhorn", preweight_label="cell_type0528", ) ``` -------------------------------- ### Mixscape Perturbation Signature and Analysis Source: https://github.com/scverse/pertpy/blob/main/docs/api/tools_index.md Implements the Mixscape pipeline to identify and remove unsuccessfully perturbed cells from CRISPR screens. It calculates a perturbation signature, determines affected cells using mixture models, and visualizes similarities across perturbations. ```python import pertpy as pt mdata = pt.dt.papalexi_2021() ms = pt.tl.Mixscape() ms.perturbation_signature(mdata["rna"], "perturbation", "NT", "replicate") ms.mixscape(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert") ms.lda(adata=mdata["rna"], labels="gene_target", layer="X_pert", control="NT") ms.plot_lda(adata=mdata["rna"], control="NT") ``` -------------------------------- ### Pertpy BibTeX Citation Source: https://github.com/scverse/pertpy/blob/main/docs/about/cite.md The BibTeX entry for the pertpy framework, suitable for inclusion in LaTeX documents for academic citations. ```bibtex @article {Heumos2024.08.04.606516, author = {Heumos, Lukas and Ji, Yuge and May, Lilly and Green, Tessa and Zhang, Xinyue and Wu, Xichen and Ostner, Johannes and Peidli, Stefan and Schumacher, Antonia and Hrovatin, Karin and Müller, Michaela and Chong, Faye and Sturm, Gregor and Tejada, Alejandro and Dann, Emma and Dong, Mingze and Bahrami, Mojtaba and Gold, Ilan and Rybakov, Sergei and Namsaraeva, Altana and Moinfar, Amir and Zheng, Zihe and Roellin, Eljas and Mekki, Isra and Sander, Chris and Lotfollahi, Mohammad and Schiller, Herbert B. and Theis, Fabian J.}, title = {Pertpy: an end-to-end framework for perturbation analysis}, elocation-id = {2024.08.04.606516}, year = {2024}, doi = {10.1101/2024.08.04.606516}, publisher = {Cold Spring Harbor Laboratory}, URL = {https://www.biorxiv.org/content/early/2024/08/07/2024.08.04.606516}, eprint = {https://www.biorxiv.org/content/early/2024/08/07/2024.08.04.606516.full.pdf}, journal = {bioRxiv} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.