Datasets:
Upload folder using huggingface_hub
#1
by avantikalal - opened
Files changed (4)
- .gitattributes+1
- 1_data.ipynbAdded+624
- README.md+46-3
- data.csvAdded+3
56 unmodified lines5758596056 unmodified lines# Video files - compressed*.mp4 filter=lfs diff=lfs merge=lfs -text*.webm filter=lfs diff=lfs merge=lfs -textdata.csv filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624{ "cells": [ { "cell_type": "markdown", "id": "6b984a20-40eb-4c08-8494-ebb607e91b94", "metadata": {}, "source": [ "# Process data for chromHMM multiclass classification model" ] }, { "cell_type": "markdown", "id": "df5cf6ce-dd2c-445f-a5b3-a13e9fd07d17", "metadata": {}, "source": [ "## Set up wandb" ] }, { "cell_type": "code", "execution_count": 1, "id": "35c13d53-f8f7-45c9-a7f0-c0e92d7654c9", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: Using wandb-core as the SDK backend. Please refer to https://wandb.me/wandb-core for more information.\n", "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mavantikalal\u001b[0m (\u001b[33mgrelu\u001b[0m) to \u001b[32mhttps://api.wandb.ai\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n" ] } ], "source": [ "import wandb\n", "import anndata\n", "import pandas as pd\n", "import numpy as np\n", "import os\n", "\n", "wandb.login(host=\"https://api.wandb.ai\")\n", "project_name = 'human-chromhmm-fullstack'" ] }, { "cell_type": "code", "execution_count": 2, "id": "37ecd399-3fd9-4687-9d7d-95638f529dc1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "Tracking run with wandb version 0.19.7" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in <code>/code/github/gReLU-applications/chromhmm/wandb/run-20250306_045811-8fux0bft</code>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run <strong><a href='https://wandb.ai/grelu/human-chromhmm-fullstack/runs/8fux0bft' target=\"_blank\">prep</a></strong> to <a href='https://wandb.ai/grelu/human-chromhmm-fullstack' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/developer-guide' target=\"_blank\">docs</a>)<br>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at <a href='https://wandb.ai/grelu/human-chromhmm-fullstack' target=\"_blank\">https://wandb.ai/grelu/human-chromhmm-fullstack</a>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at <a href='https://wandb.ai/grelu/human-chromhmm-fullstack/runs/8fux0bft' target=\"_blank\">https://wandb.ai/grelu/human-chromhmm-fullstack/runs/8fux0bft</a>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "run = wandb.init(\n", " entity='grelu', project=project_name, job_type='preprocessing', name='prep',\n", " settings=wandb.Settings(\n", " program_relpath='1_data.ipynb',\n", " program_abspath='/code/github/gReLU-applications/chromhmm/1_data.ipynb')\n", ")" ] }, { "cell_type": "markdown", "id": "b4b88d95-a65a-4e75-a309-032faf846c03", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "code", "execution_count": 3, "id": "1527622f-94c0-4377-b125-407a0eef4bec", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>chrom</th>\n", " <th>start</th>\n", " <th>end</th>\n", " <th>state</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>chr1</td>\n", " <td>10000</td>\n", " <td>10400</td>\n", " <td>2_GapArtf2</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>chr1</td>\n", " <td>10400</td>\n", " <td>10600</td>\n", " <td>27_Acet1</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>chr1</td>\n", " <td>10600</td>\n", " <td>10800</td>\n", " <td>38_EnhWk4</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>chr1</td>\n", " <td>10800</td>\n", " <td>12800</td>\n", " <td>1_GapArtf1</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>chr1</td>\n", " <td>12800</td>\n", " <td>13000</td>\n", " <td>38_EnhWk4</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " chrom start end state\n", "0 chr1 10000 10400 2_GapArtf2\n", "1 chr1 10400 10600 27_Acet1\n", "2 chr1 10600 10800 38_EnhWk4\n", "3 chr1 10800 12800 1_GapArtf1\n", "4 chr1 12800 13000 38_EnhWk4" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chromhmm = pd.read_table('https://public.hoffman2.idre.ucla.edu/ernst/2K9RS//full_stack/full_stack_annotation_public_release/hg38/hg38_genome_100_segments.bed.gz', header=None)\n", "chromhmm.columns = ['chrom', 'start', 'end', 'state']\n", "chromhmm.head()" ] }, { "cell_type": "markdown", "id": "91bec5b4-201c-4c66-992f-6b54ba5bc71e", "metadata": {}, "source": [ "## Process data" ] }, { "cell_type": "code", "execution_count": 4, "id": "394d7f20-121f-4da7-886e-7b4184d2128d", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Keeping 5845850 intervals\n", "Keeping 5809104 intervals\n" ] } ], "source": [ "from grelu.data.preprocess import filter_chromosomes, filter_blacklist\n", "from grelu.sequence.utils import resize\n", "\n", "chromhmm = filter_chromosomes(chromhmm, include='autosomes')\n", "chromhmm = resize(chromhmm, 1024)\n", "chromhmm = filter_blacklist(chromhmm, 'hg38')" ] }, { "cell_type": "markdown", "id": "8a93565f-d819-44d4-911c-d8d1f5d7a052", "metadata": {}, "source": [ "## Get coarse-grained state labels" ] }, { "cell_type": "code", "execution_count": 5, "id": "44474b8b-7f33-4608-95cb-b77e87fb4840", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "state\n", "Quies 1485576\n", "Acet 639669\n", "EnhA 613794\n", "ReprPC 610147\n", "Tx 561526\n", "EnhWk 543113\n", "HET 521161\n", "TxWk 254518\n", "TxEnh 190465\n", "TxEx 121833\n", "PromF 88429\n", "GapArtf 51474\n", "BivProm 48242\n", "znf 34146\n", "TSS 24402\n", "DNase 20609\n", "Name: count, dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chromhmm['state'] = [\n", " x.split('_')[1][:-1] for x in chromhmm.state\n", "]\n", "chromhmm.loc[chromhmm.state.isin(['EnhA1', 'EnhA2']), 'state'] = 'EnhA'\n", "\n", "chromhmm['state'] = chromhmm['state'].astype('category')\n", "chromhmm.state.value_counts() " ] }, { "cell_type": "markdown", "id": "3eb00f57-972a-4b07-badd-d8edf20e9d9e", "metadata": {}, "source": [ "## Load Enformer splits" ] }, { "cell_type": "code", "execution_count": 6, "id": "89717895-524f-4ea5-bacc-4914e8893096", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: 1 of 1 files downloaded. \n" ] }, { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>chrom</th>\n", " <th>start</th>\n", " <th>end</th>\n", " <th>split</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>chr18</td>\n", " <td>895618</td>\n", " <td>1092226</td>\n", " <td>train</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>chr4</td>\n", " <td>113598179</td>\n", " <td>113794787</td>\n", " <td>train</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>chr11</td>\n", " <td>18394952</td>\n", " <td>18591560</td>\n", " <td>train</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " chrom start end split\n", "0 chr18 895618 1092226 train\n", "1 chr4 113598179 113794787 train\n", "2 chr11 18394952 18591560 train" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "artifact = run.use_artifact('enformer/human_intervals:latest')\n", "dir = artifact.download()\n", "enformer_intervals = pd.read_table(os.path.join(dir, \"data.tsv\"))\n", "enformer_intervals.head(3)" ] }, { "cell_type": "markdown", "id": "e19fd34a-5797-49f3-a838-c3e2d0342be0", "metadata": {}, "source": [ "## Split regions based on their overlap with Enformer split" ] }, { "cell_type": "code", "execution_count": 7, "id": "86d33170-ccb8-4245-9e7e-c12f1ca9fb2f", "metadata": {}, "outputs": [], "source": [ "chromhmm = chromhmm.reset_index(drop=True)\n", "chromhmm['interval_idx'] = range(len(chromhmm))" ] }, { "cell_type": "code", "execution_count": 8, "id": "6d7628c5-3e70-4835-8c04-b6d193490419", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "split_\n", "train 4963283\n", "test 402392\n", "valid 363619\n", "None 76215\n", "testtrain 1606\n", "trainvalid 1221\n", "testvalid 768\n", "Name: count, dtype: int64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import bioframe as bf\n", "overlaps = bf.overlap(chromhmm, enformer_intervals, how='left')\n", "overlaps.split_ = overlaps.split_.fillna('None')\n", "\n", "overlaps = overlaps.groupby('interval_idx').split_.apply(lambda x: ''.join(list(np.unique(x))))\n", "overlaps.value_counts()" ] }, { "cell_type": "code", "execution_count": 9, "id": "562e9b6e-aaf3-4c11-82fb-41f8b69d94cf", "metadata": {}, "outputs": [], "source": [ "assert np.all(overlaps.index == chromhmm.interval_idx)" ] }, { "cell_type": "code", "execution_count": 10, "id": "a43a1227-154f-47f7-90fd-a7fd5f59ce3b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "train 5042325\n", "test 402392\n", "valid 364387\n", "Name: count, dtype: int64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_splits = np.array(['train'] * len(overlaps))\n", "new_splits[[(('valid' in x) and ('train' not in x)) for x in overlaps]] = 'valid'\n", "new_splits[[(('test' in x) and ('train' not in x) and ('valid' not in x)) for x in overlaps]] = 'test'\n", "pd.Series(new_splits).value_counts()" ] }, { "cell_type": "code", "execution_count": 11, "id": "04c0bede-0f36-4d07-bd81-7988ca856c09", "metadata": {}, "outputs": [], "source": [ "chromhmm['enformer_split'] = overlaps\n", "chromhmm['split'] = new_splits" ] }, { "cell_type": "markdown", "id": "7dbf9d8a-aa8f-45b0-a572-e7e3a6abb607", "metadata": {}, "source": [ "## Save dataset" ] }, { "cell_type": "code", "execution_count": 12, "id": "801efe31-dfbc-4052-81bf-9b1de399c8f3", "metadata": {}, "outputs": [], "source": [ "chromhmm.to_csv('chromhmm.csv.gz', index=False) " ] }, { "cell_type": "code", "execution_count": 13, "id": "be914f0c-da00-4b1a-820b-8d61d6725b70", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<Artifact dataset>" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "artifact = wandb.Artifact('dataset', type='dataset')\n", "artifact.add_file(local_path='chromhmm.csv.gz', name='data.csv.gz')\n", "run.log_artifact(artifact)" ] }, { "cell_type": "code", "execution_count": 14, "id": "7afe340f-d1cd-43d1-a6ce-0db10c2e2e63", "metadata": {}, "outputs": [ { "data": { "text/html": [], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run <strong style=\"color:#cdcd00\">prep</strong> at: <a href='https://wandb.ai/grelu/human-chromhmm-fullstack/runs/8fux0bft' target=\"_blank\">https://wandb.ai/grelu/human-chromhmm-fullstack/runs/8fux0bft</a><br> View project at: <a href='https://wandb.ai/grelu/human-chromhmm-fullstack' target=\"_blank\">https://wandb.ai/grelu/human-chromhmm-fullstack</a><br>Synced 6 W&B file(s), 0 media file(s), 2 artifact file(s) and 0 other file(s)" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Find logs at: <code>./wandb/run-20250306_045811-8fux0bft/logs</code>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "run.finish()" ] }, { "cell_type": "code", "execution_count": null, "id": "46094f9a-324c-45ef-acf1-051c7d7ebe3d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 5}12312345678910111213141516171819202122232425262728293031323334353637383940414243444546---
license: mit
------license: mittask_categories:- tabular-classificationtags:- biology- genomicspretty_name: "ChromHMM fullstack annotation of the human genome"size_categories:- 1M<n<10M---
# human-chromhmm-fullstack
## Dataset SummaryThis dataset provides a multi-class annotation of genomic regions across the hg38 genome. It is derived from the ChromHMM fullstack annotation (Vu & Ernst, 2022; https://doi.org/10.1186/s13059-021-02572-z). Genomic regions are classified into 16 states. The data is derived from https://public.hoffman2.idre.ucla.edu/ernst/2K9RS//full_stack/full_stack_annotation_public_release/hg38/hg38_genome_100_segments.bed.gz.
## Repository Content1. `data.csv`: The main dataset stored in comma-separated tabular format.2. `1_data.ipynb`: Jupyter notebook containing the preprocessing steps used to generate the `.csv` file.
## Dataset Structure
| Column | Type | Description || :--- | :--- | :--- || chrom | string | Chromosome name (e.g., chr1) || start | int | Start coordinate of the genomic interval || end | int | End coordinate of the genomic interval || state | string | Chromatin state annotation (e.g., EnhWk, Quies) || interval_idx | int | Unique numerical index for the specific genomic interval || enformer_split | string | Overlap with the data splits used for training the Enformer model || split | string |Splits used for downstream modeling (training/validation/test) |
## Usage
```pythonimport pandas as pdfrom huggingface_hub import hf_hub_download
file_path = hf_hub_download( repo_id="Genentech/human-chromhmm-fullstack-data", filename="data.csv")
df = pd.read_csv(file_path)```123version https://git-lfs.github.com/spec/v1oid sha256:7a827f9fa2d26e924fa134ae16edeb4cccd65bb5e93e5e6c636ed489da3b5ad1size 284326235.gitattributes+1
1_data.ipynbAdded+624
README.md+46-3
data.csvAdded+3