-
Notifications
You must be signed in to change notification settings - Fork 1
Update downloads module #80
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
axiomcura
wants to merge
5
commits into
WayScience:main
Choose a base branch
from
axiomcura:update-download-module
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5044203
updated docs and removed functions that were no longer used
axiomcura ec78b56
download module update
axiomcura 5940d0e
doc updates
axiomcura 9f2f9f2
fixed execution call
axiomcura cb44173
updated module by adding cell type
axiomcura 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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||
| "source": [ | ||||||
| "# Downloading Single-Cell Profiles\n", | ||||||
| "\n", | ||||||
| "This notebook focuses on downloading metadata and single-cell profiles from three key datasets:\n", | ||||||
| "This notebook downloading metadata and single-cell profiles from three key datasets:\n", | ||||||
| "\n", | ||||||
| "1. **CPJUMP1 Pilot Dataset** ([link](https://github.com/jump-cellpainting/2024_Chandrasekaran_NatureMethods_CPJUMP1)): Metadata is downloaded and processed to identify and organize plates containing wells treated with compound perturbations for downstream analysis.\n", | ||||||
| "2. **MitoCheck Dataset**: Normalized and feature-selected single-cell profiles are downloaded for further analysis.\n", | ||||||
|
|
@@ -74,7 +74,7 @@ | |||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "# setting config path\n", | ||||||
| "config_path = pathlib.Path(\"../nb-configs.yaml\").resolve(strict=True)\n", | ||||||
| "config_path = pathlib.Path(\"dl-configs.yaml\").resolve(strict=True)\n", | ||||||
| "\n", | ||||||
| "# setting results setting a data directory\n", | ||||||
| "data_dir = pathlib.Path(\"./data\").resolve()\n", | ||||||
|
|
@@ -114,7 +114,7 @@ | |||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "execution_count": 4, | ||||||
| "id": "5b8bfe5f", | ||||||
| "metadata": {}, | ||||||
| "outputs": [ | ||||||
|
|
@@ -126,15 +126,15 @@ | |||||
| "Series: 'Assay_Plate_Barcode' [str]\n", | ||||||
| "[\n", | ||||||
| "\t\"BR00117054\"\n", | ||||||
| "\t\"BR00117012\"\n", | ||||||
| "\t\"BR00117008\"\n", | ||||||
| "\t\"BR00117016\"\n", | ||||||
| "\t\"BR00117055\"\n", | ||||||
| "\t…\n", | ||||||
| "\t\"BR00117010\"\n", | ||||||
| "\t\"BR00117009\"\n", | ||||||
| "\t\"BR00117011\"\n", | ||||||
| "\t…\n", | ||||||
| "\t\"BR00117013\"\n", | ||||||
| "\t\"BR00117010\"\n", | ||||||
| "\t\"BR00117017\"\n", | ||||||
| "\t\"BR00117008\"\n", | ||||||
| "\t\"BR00117012\"\n", | ||||||
| "\t\"BR00117015\"\n", | ||||||
| "\t\"BR00117019\"\n", | ||||||
| "]\n", | ||||||
| "shape: (12, 13)\n" | ||||||
|
|
@@ -241,6 +241,80 @@ | |||||
| "exp_metadata" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "id": "a4665c17", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "\n", | ||||||
| "In this section, we download:\n", | ||||||
| "\n", | ||||||
| "1. **Compound metadata** from the CPJUMP1 repository \n", | ||||||
| "2. **Mechanism of action (MOA) metadata** from the Broad Repurposing Hub\n", | ||||||
| "\n", | ||||||
| "We then merge both datasets into a single compound metadata table.\n", | ||||||
| "\n", | ||||||
| "If a compound has missing MOA information, the value in `Metadata_moa` is replaced with `\"unknown\"`. This indicates that no MOA annotation is currently available for that compound." | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": 5, | ||||||
| "id": "22e417e3", | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "# downloading compound metadata from cpjump1 repo\n", | ||||||
| "CPJUMP_compound_metadata = pl.read_csv(\n", | ||||||
| " nb_configs[\"links\"][\"CPJUMP1-compound-metadata-source\"],\n", | ||||||
| " separator=\"\\t\",\n", | ||||||
| " has_header=True,\n", | ||||||
| " encoding=\"utf-8\",\n", | ||||||
| ")\n", | ||||||
| "\n", | ||||||
| "# downloading compound moa metadata from broad institute drug repurposing hub\n", | ||||||
| "broad_compound_moa_metadata = pl.read_csv(\n", | ||||||
| " nb_configs[\"links\"][\"Broad-compounds-moa-source\"],\n", | ||||||
| " separator=\"\\t\",\n", | ||||||
| " skip_rows=9,\n", | ||||||
| " encoding=\"utf8-lossy\",\n", | ||||||
| ")\n", | ||||||
| "\n", | ||||||
| "# for both dataframes make sure that all columns have \"Metadata_\" in the column name\n", | ||||||
| "CPJUMP_compound_metadata = CPJUMP_compound_metadata.rename(\n", | ||||||
| " {col: f\"Metadata_{col}\" for col in CPJUMP_compound_metadata.columns}\n", | ||||||
| ")\n", | ||||||
| "broad_compound_moa_metadata = broad_compound_moa_metadata.rename(\n", | ||||||
| " {col: f\"Metadata_{col}\" for col in broad_compound_moa_metadata.columns}\n", | ||||||
| ")\n", | ||||||
| "\n", | ||||||
| "# replace null values in the boroad compound moa to \"unknown\"\n", | ||||||
|
||||||
| "# replace null values in the boroad compound moa to \"unknown\"\n", | |
| "# replace null values in the broad compound moa to \"unknown\"\n", |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,13 +31,12 @@ | |||||
| "import sys\n", | ||||||
| "import json\n", | ||||||
| "import pathlib\n", | ||||||
| "from typing import Optional\n", | ||||||
| "\n", | ||||||
| "import polars as pl\n", | ||||||
| "\n", | ||||||
| "sys.path.append(\"../../\")\n", | ||||||
| "from utils.data_utils import split_meta_and_features, add_cell_id_hash\n", | ||||||
| "from utils.io_utils import load_profiles" | ||||||
| "from utils.io_utils import load_and_concat_profiles" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
|
|
@@ -57,64 +56,6 @@ | |||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "def load_and_concat_profiles(\n", | ||||||
| " profile_dir: str | pathlib.Path,\n", | ||||||
| " shared_features: Optional[list[str]] = None,\n", | ||||||
| " specific_plates: Optional[list[pathlib.Path]] = None,\n", | ||||||
| ") -> pl.DataFrame:\n", | ||||||
| " \"\"\"\n", | ||||||
| " Load all profile files from a directory and concatenate them into a single Polars DataFrame.\n", | ||||||
| "\n", | ||||||
| " Parameters\n", | ||||||
| " ----------\n", | ||||||
| " profile_dir : str or pathlib.Path\n", | ||||||
| " Directory containing the profile files (.parquet).\n", | ||||||
| " shared_features : Optional[list[str]], optional\n", | ||||||
| " List of shared feature names to filter the profiles. If None, all features are loaded.\n", | ||||||
| " specific_plates : Optional[list[pathlib.Path]], optional\n", | ||||||
| " List of specific plate file paths to load. If None, all profiles in the directory are loaded.\n", | ||||||
| "\n", | ||||||
| " Returns\n", | ||||||
| " -------\n", | ||||||
| " pl.DataFrame\n", | ||||||
| " Concatenated Polars DataFrame containing all loaded profiles.\n", | ||||||
| " \"\"\"\n", | ||||||
| " # Ensure profile_dir is a pathlib.Path\n", | ||||||
| " if isinstance(profile_dir, str):\n", | ||||||
| " profile_dir = pathlib.Path(profile_dir)\n", | ||||||
| " elif not isinstance(profile_dir, pathlib.Path):\n", | ||||||
| " raise TypeError(\"profile_dir must be a string or a pathlib.Path object\")\n", | ||||||
| "\n", | ||||||
| " # Validate specific_plates\n", | ||||||
| " if specific_plates is not None:\n", | ||||||
| " if not isinstance(specific_plates, list):\n", | ||||||
| " raise TypeError(\"specific_plates must be a list of pathlib.Path objects\")\n", | ||||||
| " if not all(isinstance(path, pathlib.Path) for path in specific_plates):\n", | ||||||
| " raise TypeError(\n", | ||||||
| " \"All elements in specific_plates must be pathlib.Path objects\"\n", | ||||||
| " )\n", | ||||||
| "\n", | ||||||
| " # Use specific_plates if provided, otherwise gather all .parquet files\n", | ||||||
| " if specific_plates is not None:\n", | ||||||
| " # Validate that all specific plate files exist\n", | ||||||
| " for plate_path in specific_plates:\n", | ||||||
| " if not plate_path.exists():\n", | ||||||
| " raise FileNotFoundError(f\"Profile file not found: {plate_path}\")\n", | ||||||
| " files_to_load = specific_plates\n", | ||||||
| " else:\n", | ||||||
| " files_to_load = list(profile_dir.glob(\"*.parquet\"))\n", | ||||||
| " if not files_to_load:\n", | ||||||
| " raise FileNotFoundError(f\"No profile files found in {profile_dir}\")\n", | ||||||
| "\n", | ||||||
| " # Load and concatenate profiles\n", | ||||||
| " loaded_profiles = [\n", | ||||||
| " load_profiles(f, shared_features=shared_features) for f in files_to_load\n", | ||||||
| " ]\n", | ||||||
| "\n", | ||||||
| " # Concatenate all loaded profiles\n", | ||||||
| " return pl.concat(loaded_profiles, rechunk=True)\n", | ||||||
| "\n", | ||||||
| "\n", | ||||||
| "def split_data(\n", | ||||||
| " pycytominer_output: pl.DataFrame, dataset: str = \"CP_and_DP\"\n", | ||||||
| ") -> pl.DataFrame:\n", | ||||||
|
|
@@ -199,16 +140,17 @@ | |||||
| "# Setting profiles directory\n", | ||||||
| "profiles_dir = (data_dir / \"sc-profiles\").resolve(strict=True)\n", | ||||||
| "\n", | ||||||
| "# setting connectivity map drug repurposing config\n", | ||||||
| "drug_repurposing_config_path = (data_dir / \"repurposing_drugs_20180907.txt\").resolve(\n", | ||||||
| " strict=True\n", | ||||||
| ")\n", | ||||||
| "\n", | ||||||
| "# Experimental metadata\n", | ||||||
| "exp_metadata_path = (\n", | ||||||
| " profiles_dir / \"cpjump1\" / \"cpjump1_compound_experimental-metadata.csv\"\n", | ||||||
| ").resolve(strict=True)\n", | ||||||
| "\n", | ||||||
| "# cpjump1 compound metadta\n", | ||||||
|
||||||
| "# cpjump1 compound metadta\n", | |
| "# cpjump1 compound metadata\n", |
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,8 @@ | ||
| links: | ||
| MitoCheck-profiles-source: https://zenodo.org/records/7967386/files/3.normalize_data__normalized_data.zip?download=1 | ||
| CFReT-profiles-source: https://github.com/WayScience/cellpainting_predicts_cardiac_fibrosis/raw/refs/heads/main/3.process_cfret_features/data/single_cell_profiles/localhost230405150001_sc_feature_selected.parquet?download= | ||
| CPJUMP1-experimental-metadata-source: https://github.com/carpenter-singh-lab/2024_Chandrasekaran_NatureMethods/raw/refs/heads/main/benchmark/output/experiment-metadata.tsv | ||
| CPJUMP1-compound-metadata-source: https://raw.githubusercontent.com/carpenter-singh-lab/2024_Chandrasekaran_NatureMethods/main/metadata/external_metadata/JUMP-Target-1_compound_metadata_targets.tsv | ||
| Broad-compounds-moa-source: https://s3.amazonaws.com/data.clue.io/repurposing/downloads/repurposing_drugs_20180907.txt | ||
| CPJUMP-plate-maps-source: https://raw.githubusercontent.com/jump-cellpainting/2024_Chandrasekaran_NatureMethods_CPJUMP1/refs/heads/main/metadata/platemaps/2020_11_04_CPJUMP1/platemap/JUMP-Target-1_crispr_platemap.txt | ||
| CPJUMP1-profiles-source: https://cellpainting-gallery.s3.amazonaws.com/cpg0000-jump-pilot/source_4/workspace/profiles |
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.
Grammar issue in notebook intro: "This notebook downloading ..." is missing a verb (e.g., "This notebook downloads ..." / "This notebook focuses on downloading ...").