{ "cells": [ { "cell_type": "markdown", "id": "2f333c50", "metadata": {}, "source": [ "# FBN1 Cohort Analysis: Correlation\n", "\n", "In this tutorial, we analyze a cohort of phenopackets associated with the gene **FBN1**. The example data is retrieved from the [phenopacket store](https://github.com/monarch-initiative/phenopacket-store).\n", "\n", "Using this dataset, we demonstrate a complete workflow with **phenocor**, including:\n", "\n", "- dataset construction\n", "- correlation analysis\n", "\n", "We recommend running this tutorial in a **Jupyter notebook** for interactive exploration and visualization, although it can also be executed as a standard Python script.\n", "\n", "\n", "## 1. Load phenopackets\n", "\n", "We start by loading phenopackets for the **FBN1** cohort:" ] }, { "cell_type": "markdown", "id": "b806eb63", "metadata": {}, "source": [ "### Requirements\n", "\n", "Install phenocor and the toolkit used to retrieve the example data:\n", "\n", "```bash\n", "pip install phenocor phenopacket-store-toolkit\n", "```\n", "\n", "The first data download requires an internet connection." ] }, { "cell_type": "code", "execution_count": 13, "id": "deec03c5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loaded 143 phenopackets\n" ] } ], "source": [ "from ppktstore.registry import configure_phenopacket_registry\n", "registry = configure_phenopacket_registry()\n", "with registry.open_phenopacket_store() as ps:\n", " phenopackets = [\n", " p for p in ps.iter_cohort_phenopackets(\"FBN1\")\n", " ]\n", "\n", "print(f\"Loaded {len(phenopackets)} phenopackets\")" ] }, { "cell_type": "markdown", "id": "3a47822d", "metadata": {}, "source": [ "The registry provides access to Phenopacket Store cohorts through iter_cohort_phenopackets().\n", "\n", "> **Note:** \n", "> You can also use your own phenopacket data. As long as your data follows the [GA4GH Phenopacket schema](https://phenopacket-schema.readthedocs.io/en/latest/index.html), it can be directly used in the workflow.\n", "\n", "## 2. Build the dataset\n", "\n", "Next, we convert phenopackets into a structured dataset suitable for downstream statistical analysis. " ] }, { "cell_type": "code", "execution_count": 14, "id": "01d4d77a", "metadata": {}, "outputs": [], "source": [ "from phenocor import PhenotypeDatasetBuilder\n", "\n", "dataset = PhenotypeDatasetBuilder(phenopackets).build()" ] }, { "cell_type": "markdown", "id": "f5029d84", "metadata": {}, "source": [ "The resulting `dataset` is now ready for correlation.\n", "\n", "\n", "## 3. Correlation analysis\n", "\n", "Next, we compute pairwise correlations between HPO features across individuals in the cohort." ] }, { "cell_type": "code", "execution_count": 15, "id": "69656de4", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Calculating pairwise correlations: 100%|██████████| 728/728 [00:01<00:00, 486.47it/s]\n" ] }, { "data": { "text/html": [ "
| \n", " | HPO_A | \n", "HPO_B | \n", "correlation | \n", "p_value | \n", "adj_p_value | \n", "n(A:E/B:E) | \n", "n(A:E/B:O) | \n", "n(A:O/B:E) | \n", "n(A:O/B:O) | \n", "n_individuals | \n", "HPO_A_label | \n", "HPO_B_label | \n", "n_pmids | \n", "pmids | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "HP:0004322 | \n", "HP:0004942 | \n", "-0.827131 | \n", "2.049015e-14 | \n", "9.773799e-12 | \n", "7 | \n", "34 | \n", "33 | \n", "0 | \n", "74 | \n", "Short stature | \n", "Aortic aneurysm | \n", "5 | \n", "10756346;11175294;12203992;20375004;21683322 | \n", "
| 1 | \n", "HP:0000098 | \n", "HP:0004942 | \n", "0.796637 | \n", "1.940118e-13 | \n", "4.627183e-11 | \n", "45 | \n", "7 | \n", "1 | \n", "26 | \n", "79 | \n", "Tall stature | \n", "Aortic aneurysm | \n", "13 | \n", "10756346;11175294;12203992;20375004;20979188;2... | \n", "
| 2 | \n", "HP:0000098 | \n", "HP:0004322 | \n", "-0.685681 | \n", "5.424742e-12 | \n", "8.625340e-10 | \n", "16 | \n", "33 | \n", "37 | \n", "0 | \n", "86 | \n", "Tall stature | \n", "Short stature | \n", "5 | \n", "10756346;11175294;12203992;20375004;21683322 | \n", "
| 3 | \n", "HP:0000098 | \n", "HP:0002616 | \n", "0.646903 | \n", "1.766457e-11 | \n", "2.106500e-09 | \n", "70 | \n", "7 | \n", "10 | \n", "26 | \n", "113 | \n", "Tall stature | \n", "Aortic root aneurysm | \n", "18 | \n", "10756346;11175294;12203992;20375004;20979188;2... | \n", "
| 4 | \n", "HP:0002616 | \n", "HP:0004322 | \n", "-0.634615 | \n", "2.474657e-10 | \n", "2.360823e-08 | \n", "19 | \n", "33 | \n", "33 | \n", "0 | \n", "85 | \n", "Aortic root aneurysm | \n", "Short stature | \n", "5 | \n", "10756346;11175294;12203992;20375004;21683322 | \n", "
To view the interactive plot, click the link below:
'\n", " f'{link_text}')" ] }, { "cell_type": "code", "execution_count": 17, "id": "66c2e84d", "metadata": {}, "outputs": [], "source": [ "fig1 = results.plot_correlation_heatmap_with_significance(\n", " title=\"Cohort FBN1\",\n", ")" ] }, { "cell_type": "code", "execution_count": 18, "id": "11a16cf9", "metadata": { "nbsphinx": { "hide-input": true }, "tags": [ "hide_input" ] }, "outputs": [ { "data": { "text/html": [ "To view the interactive plot, click the link below:
Click here to view interactive correlation heatmap" ], "text/plain": [ "