-
Notifications
You must be signed in to change notification settings - Fork 7
Webapp #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MikeLippincott
wants to merge
26
commits into
WayScience:main
Choose a base branch
from
MikeLippincott:webapp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Webapp #78
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8f86c6f
progress capture
MikeLippincott ac290a9
progress capture
MikeLippincott d1c3ee2
add new webapp
MikeLippincott fa10bfa
add new webapp
MikeLippincott 602836d
add limitors
MikeLippincott df7e22e
track file
MikeLippincott 1742338
adding new
MikeLippincott 4a32650
add new site
MikeLippincott 8c8cf60
fix crashing by adding caching
MikeLippincott 905b43d
fix app startup crash caused by loading large data at import time
gwaybio c06f75e
adding webapp page fixes
MikeLippincott 77d41bf
resolve merge conflict in app.py
gwaybio bc1b511
remove large data files from LFS, gitignore CRISPR files
gwaybio 4688235
revert 0.data-download changes; clean up webapp dead code
gwaybio d20ef8a
remove stale download_data.sh from 0.data-download
gwaybio c01664f
webapp gardening: clean deps, lint, update README, remove Justfile
gwaybio 670f0e1
make webapp self-contained and HF Spaces ready
gwaybio f9ffaa8
add .hfignore and update README frontmatter for HF Spaces Docker/Stre…
gwaybio 9830a3c
add HF Spaces update instructions to README
gwaybio c28a170
Add Dockerfile and README for HF Spaces Docker deployment
gwaybio a7d63b9
Add HF Spaces badge to root README
gwaybio d148713
Add GitHub Action to auto-deploy webapp to HF Spaces on main
gwaybio b84b9f4
Update READMEs to document auto-deploy via GitHub Actions
gwaybio df8ddd4
minor tweaks
gwaybio bae50c0
Remove requirements.txt — pyproject.toml + uv.lock are authoritative
gwaybio 3562730
Move preprocessing.ipynb to 5.drug-dependency as notebook 9
gwaybio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: Deploy to HF Spaces | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - "9.webapp/**" | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| lfs: true | ||
|
|
||
| - name: Install huggingface_hub | ||
| run: pip install huggingface_hub | ||
|
|
||
| - name: Push to HF Spaces | ||
| env: | ||
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
| run: | | ||
| cd 9.webapp | ||
| hf upload WayScience/gene-dependency-explorer . . \ | ||
| --repo-type space \ | ||
| --exclude ".venv/**" \ | ||
| --exclude "**/__pycache__/**" \ | ||
| --exclude "**/*.pyc" \ | ||
| --exclude "**/*.egg-info/**" \ | ||
| --exclude "data/CRISPRGeneEffect.parquet" \ | ||
| --exclude "data/CRISPR_gene_dictionary.parquet" \ | ||
| --commit-message "deploy from ${{ github.sha }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| repos: | ||
| - repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update | ||
| rev: v0.9.0 # Insert the latest tag here | ||
|
|
||
| hooks: | ||
| - id: pre-commit-update | ||
| args: [--exclude, black, --keep, isort] | ||
| # Formats import order | ||
| - repo: https://github.com/pycqa/isort | ||
| rev: 5.12.0 | ||
| hooks: | ||
| - id: isort | ||
| name: isort (python) | ||
| args: ["--profile", "black", "--filter-files"] | ||
|
|
||
| #Code formatter for both python files and jupyter notebooks | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| # Ruff version. | ||
| rev: v0.15.17 | ||
| hooks: | ||
| # Run the formatter. | ||
| - id: ruff-format | ||
|
|
||
| - repo: https://github.com/nbQA-dev/nbQA | ||
| rev: 1.9.1 | ||
| hooks: | ||
| - id: nbqa-isort | ||
| additional_dependencies: [isort==5.6.4] | ||
| args: [--profile=black] | ||
|
|
||
| - repo: https://github.com/pre-commit/mirrors-prettier | ||
| rev: "v3.1.0" | ||
| hooks: | ||
| - id: prettier | ||
| types_or: [markdown, yaml, json, html, css, python, r] | ||
|
|
||
| - repo: https://github.com/hadialqattan/pycln | ||
| rev: v2.6.0 | ||
| hooks: | ||
| - id: pycln | ||
| args: [--config=pyproject.toml] | ||
| exclude: | | ||
| (?x)^( | ||
| 2\.segment_images/scripts/.*\.py$| | ||
| 3\.cellprofiling/scripts/.*\.py$ | ||
| )$ | ||
| # additional hooks found with in the pre-commit lib | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v6.0.0 | ||
| hooks: | ||
| - id: trailing-whitespace # removes trailing white spaces | ||
| - id: mixed-line-ending # removes mixed end of line | ||
| args: | ||
| - --fix=lf | ||
|
|
||
| - repo: local | ||
| hooks: | ||
| - id: shellcheck | ||
| name: shellcheck | ||
| description: Test shell scripts with shellcheck | ||
| entry: shellcheck | ||
| language: python | ||
| types: [shell] | ||
| require_serial: true # shellcheck can detect sourcing this way | ||
238 changes: 238 additions & 0 deletions
238
5.drug-dependency/9.precompute_webapp_pca_embeddings.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "notice-cell", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Precompute PCA Embeddings for Webapp\n", | ||
| "\n", | ||
| "> **Note:** This notebook was a one-time preprocessing step run to generate the pre-computed PCA\n", | ||
| "> parquet files bundled with the `9.webapp/` Streamlit app. It is **not intended to be re-run**\n", | ||
| "> without modification.\n", | ||
| ">\n", | ||
| "> The helper functions below (`load_model_data`, `single_load_data`, `latent_load_data`) were\n", | ||
| "> originally defined in `9.webapp/app_utils.py` but were removed from the app once the pre-computed\n", | ||
| "> parquets replaced runtime PCA computation. They are reproduced here for provenance.\n", | ||
| ">\n", | ||
| "> **Dependencies that are no longer in the webapp environment:**\n", | ||
| "> - `CRISPRGeneEffect.parquet` and `CRISPR_gene_dictionary.parquet` (large gitignored DepMap files\n", | ||
| "> — download via `0.data-download/` first)\n", | ||
| "> - `sklearn` (`scikit-learn`) — not in `9.webapp/pyproject.toml`\n", | ||
| ">\n", | ||
| "> **Outputs** (written to `9.webapp/data/`):\n", | ||
| "> - `pca_embeddings_single_dependencies.parquet`\n", | ||
| "> - `pca_embeddings_latent_reactome.parquet`\n", | ||
| "> - `pca_embeddings_latent_corum.parquet`\n", | ||
| "> - `pca_embeddings_latent_drug.parquet`" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "6c08a8f0", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import pathlib\n", | ||
| "\n", | ||
| "import pandas as pd\n", | ||
| "from sklearn.decomposition import PCA" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "paths-cell", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Paths — run from repo root or adjust accordingly\n", | ||
| "REPO_ROOT = pathlib.Path().resolve().parent # goes up from 5.drug-dependency/ to repo root\n", | ||
| "WEBAPP_DIR = REPO_ROOT / \"9.webapp\"\n", | ||
| "DATA_DIR = WEBAPP_DIR / \"data\"\n", | ||
| "RESULTS_DIR = REPO_ROOT / \"5.drug-dependency\" / \"results\"\n", | ||
| "\n", | ||
| "print(f\"Repo root: {REPO_ROOT}\")\n", | ||
| "print(f\"Webapp data: {DATA_DIR}\")\n", | ||
| "print(f\"Results dir: {RESULTS_DIR}\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "helpers-header", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Helper functions\n", | ||
| "\n", | ||
| "Originally from `9.webapp/app_utils.py`, reproduced here for provenance." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "load-model-data-cell", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "def load_model_data(dependency_file, gene_dict_file):\n", | ||
| " \"\"\"Load and preprocess gene dependency data and gene dictionary.\"\"\"\n", | ||
| " dependency_df = pd.read_parquet(dependency_file)\n", | ||
| " print(dependency_df.shape)\n", | ||
| "\n", | ||
| " gene_dict_df = (\n", | ||
| " pd.read_parquet(gene_dict_file).query(\"qc_pass\").reset_index(drop=True)\n", | ||
| " )\n", | ||
| " gene_dict_df.entrez_id = gene_dict_df.entrez_id.astype(str)\n", | ||
| "\n", | ||
| " entrez_genes = [\n", | ||
| " x[1].strip(\")\").strip()\n", | ||
| " for x in dependency_df.iloc[:, 1:].columns.str.split(\"(\")\n", | ||
| " ]\n", | ||
| " entrez_intersection = list(\n", | ||
| " set(gene_dict_df.entrez_id).intersection(set(entrez_genes))\n", | ||
| " )\n", | ||
| " gene_dict_df = gene_dict_df.set_index(\"entrez_id\").reindex(entrez_intersection)\n", | ||
| "\n", | ||
| " dependency_df.columns = [\"ModelID\"] + entrez_genes\n", | ||
| " dependency_df = dependency_df.loc[:, [\"ModelID\"] + gene_dict_df.index.tolist()]\n", | ||
| " dependency_df.columns = [\"ModelID\"] + gene_dict_df.symbol_id.tolist()\n", | ||
| " dependency_df = dependency_df.dropna(axis=\"columns\")\n", | ||
| " return dependency_df, gene_dict_df" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "single-load-cell", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "def single_load_data():\n", | ||
| " \"\"\"Load CRISPR gene dependency scores merged with cell line metadata.\"\"\"\n", | ||
| " dependency_file = DATA_DIR / \"CRISPRGeneEffect.parquet\"\n", | ||
| " gene_dict_file = DATA_DIR / \"CRISPR_gene_dictionary.parquet\"\n", | ||
| " cancer_type_input_file = DATA_DIR / \"Model.parquet\"\n", | ||
| "\n", | ||
| " dependency_df, _ = load_model_data(dependency_file, gene_dict_file)\n", | ||
| " dependency_df = dependency_df.set_index(\"ModelID\")\n", | ||
| " cancer_type_df = pd.read_parquet(cancer_type_input_file)\n", | ||
| " combined_df = dependency_df.merge(\n", | ||
| " cancer_type_df[[\"ModelID\", \"OncotreePrimaryDisease\"]], on=\"ModelID\", how=\"left\"\n", | ||
| " )\n", | ||
| " return combined_df" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "latent-load-cell", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "def latent_load_data():\n", | ||
| " \"\"\"Load latent score parquets and pivot to wide format for PCA.\"\"\"\n", | ||
| " reactome_df = pd.read_parquet(RESULTS_DIR / \"all_reactome_results.parquet\")\n", | ||
| " corum_df = pd.read_parquet(RESULTS_DIR / \"all_corum_results.parquet\")\n", | ||
| " drug_df = pd.read_parquet(RESULTS_DIR / \"all_drug_results.parquet\")\n", | ||
| "\n", | ||
| " reactome_df[\"feature\"] = reactome_df[\"reactome_pathway\"]\n", | ||
| " reactome_df = reactome_df.drop(\n", | ||
| " columns=[\"model\", \"latent_dim_total\", \"init\", \"seed\", \"z\", \"reactome_pathway\"]\n", | ||
| " )\n", | ||
| " corum_df[\"feature\"] = corum_df[\"reactome_pathway\"]\n", | ||
| " corum_df = corum_df.drop(\n", | ||
| " columns=[\"model\", \"latent_dim_total\", \"init\", \"seed\", \"z\", \"reactome_pathway\"]\n", | ||
| " )\n", | ||
| " drug_df[\"feature\"] = drug_df[\"name\"]\n", | ||
| " drug_df = drug_df.drop(\n", | ||
| " columns=[\"model\", \"latent_dim_total\", \"init\", \"seed\", \"z\", \"name\"]\n", | ||
| " )\n", | ||
| "\n", | ||
| " meta_cols = [\"ModelID\", \"OncotreePrimaryDisease\"]\n", | ||
| " reactome_meta = reactome_df[meta_cols].drop_duplicates()\n", | ||
| " corum_meta = corum_df[meta_cols].drop_duplicates()\n", | ||
| " drug_meta = drug_df[meta_cols].drop_duplicates()\n", | ||
| "\n", | ||
| " reactome_matrix = reactome_df.pivot(\n", | ||
| " index=\"ModelID\", columns=\"feature\", values=\"latent_score\"\n", | ||
| " ).merge(reactome_meta, on=\"ModelID\", how=\"left\")\n", | ||
| " corum_matrix = corum_df.pivot(\n", | ||
| " index=\"ModelID\", columns=\"feature\", values=\"latent_score\"\n", | ||
| " ).merge(corum_meta, on=\"ModelID\", how=\"left\")\n", | ||
| " drug_matrix = drug_df.pivot(\n", | ||
| " index=\"ModelID\", columns=\"feature\", values=\"latent_score\"\n", | ||
| " ).merge(drug_meta, on=\"ModelID\", how=\"left\")\n", | ||
| "\n", | ||
| " return reactome_matrix, corum_matrix, drug_matrix" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "pca-header", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Compute and save PCA embeddings" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "6cdc8f80", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "def compute_pca(df, metadata_columns) -> pd.DataFrame:\n", | ||
| " print(df.shape[0], \"rows before dropping NA\")\n", | ||
| " df = df.dropna()\n", | ||
| " print(df.shape[0], \"rows after dropping NA\")\n", | ||
| " metadata_df = df[metadata_columns].copy()\n", | ||
| " feat_cols = df.columns.drop(metadata_columns)\n", | ||
| " if \"source\" in feat_cols:\n", | ||
| " feat_cols = feat_cols.drop(\"source\")\n", | ||
| " pca_input = df[feat_cols].apply(pd.to_numeric, errors=\"coerce\")\n", | ||
| " pca = PCA(n_components=2, random_state=0)\n", | ||
| " pca_embedding = pca.fit_transform(pca_input)\n", | ||
| " metadata_df[\"PCA1\"] = pca_embedding[:, 0]\n", | ||
| " metadata_df[\"PCA2\"] = pca_embedding[:, 1]\n", | ||
| " return metadata_df" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "run-pca-cell", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "combined_df = single_load_data()\n", | ||
| "reactome_matrix, corum_matrix, drug_matrix = latent_load_data()\n", | ||
| "\n", | ||
| "pca_single_df = compute_pca(combined_df, [\"ModelID\", \"OncotreePrimaryDisease\"])\n", | ||
| "pca_latent_reactome_df = compute_pca(reactome_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n", | ||
| "pca_latent_corum_df = compute_pca(corum_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n", | ||
| "pca_latent_drug_df = compute_pca(drug_matrix, [\"OncotreePrimaryDisease\", \"ModelID\"])\n", | ||
| "\n", | ||
| "pca_single_df.to_parquet(DATA_DIR / \"pca_embeddings_single_dependencies.parquet\")\n", | ||
| "pca_latent_reactome_df.to_parquet(DATA_DIR / \"pca_embeddings_latent_reactome.parquet\")\n", | ||
| "pca_latent_corum_df.to_parquet(DATA_DIR / \"pca_embeddings_latent_corum.parquet\")\n", | ||
| "pca_latent_drug_df.to_parquet(DATA_DIR / \"pca_embeddings_latent_drug.parquet\")\n", | ||
| "\n", | ||
| "print(\"Done — parquets written to\", DATA_DIR)" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "name": "python", | ||
| "version": "3.12.0" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we going to run into conflicts when I merge my PR?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe! if the files are the same, then there should be no issue |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .venv/ | ||
| __pycache__/ | ||
| *.pyc | ||
| *.egg-info/ | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [server] | ||
| fileWatcherType = "none" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| FROM python:3.12-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv | ||
|
|
||
| COPY pyproject.toml uv.lock ./ | ||
| RUN uv sync --frozen --no-dev | ||
|
|
||
| COPY . . | ||
|
|
||
| EXPOSE 7860 | ||
|
|
||
| CMD ["uv", "run", "streamlit", "run", "app.py", \ | ||
| "--server.address", "0.0.0.0", \ | ||
| "--server.port", "7860", \ | ||
| "--server.headless", "true", \ | ||
| "--server.fileWatcherType", "none"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider running precommit on this file (and all other files in this repo) as well