forked from GilbertLabUCSF/CanDI
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor DepMapData.DataNamespace into reusable CancerDataNamespace, add custom dataset injection, and exclude non-core datasets from built-in defaults
#4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cecbe61
Refactor DataNamespace and add custom dataset support
Copilot b4e1768
Run post-change validation checks
Copilot e56d190
Remove generated wheel artifact
Copilot 3edc028
Exclude OmicsProteinAbundance and CRISPRScreenMap from defaults
Copilot 118157b
Extract reusable CancerDataNamespace base class
Copilot 69d9dbd
Rename cancer_database.py to _database.py
abearab d0a83e5
Fix import statement formatting in __init__.py
abearab efbf226
Change import path for CancerDataNamespace
abearab 137df33
Apply suggestions from code review
abearab 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| from .depmap import DepMapAPI, DepMapData | ||
| from .depmap import DepMapAPI, DepMapData |
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,55 @@ | ||
| from typing import Any | ||
|
|
||
|
|
||
| class CancerDataNamespace: | ||
| """Reusable namespace for attribute-style dataset access under `.data`.""" | ||
|
|
||
| __slots__ = ("_parent",) | ||
|
|
||
| def __init__(self, parent: Any) -> None: | ||
| object.__setattr__(self, "_parent", parent) | ||
|
|
||
| def __getattr__(self, name: str) -> Any: | ||
| if name in self._parent._datasets: | ||
| return self._parent._datasets[name] | ||
| if name in self._parent._paths: | ||
| raise AttributeError( | ||
| f"Dataset '{name}' is available but not loaded. Call `.load('{name}')` first." | ||
| ) | ||
| raise AttributeError(f"No dataset named '{name}' defined.") | ||
|
|
||
| def __setattr__(self, name: str, value: Any) -> None: | ||
| if name == "_parent": | ||
| object.__setattr__(self, name, value) | ||
| return | ||
| self.add(name=name, dataset=value) | ||
|
|
||
| def __dir__(self): | ||
| return sorted( | ||
| set(super().__dir__()) | ||
| | set(self._parent._paths) | ||
| | set(self._parent._datasets) | ||
| ) | ||
|
|
||
| def add(self, name: str, dataset: Any, overwrite: bool = False) -> None: | ||
| """Add a dataset to this namespace.""" | ||
| if not name or not isinstance(name, str): | ||
| raise ValueError("Dataset name must be a non-empty string.") | ||
| if not name.isidentifier(): | ||
| raise ValueError( | ||
| f"Dataset name '{name}' is not a valid Python identifier for attribute access." | ||
| ) | ||
| if name in object.__dir__(self): | ||
| raise ValueError( | ||
| f"Dataset name '{name}' conflicts with an existing namespace attribute." | ||
| ) | ||
| if name in self._parent._datasets and not overwrite: | ||
| raise ValueError( | ||
| f"Dataset '{name}' is already loaded. Pass overwrite=True to replace it." | ||
| ) | ||
|
abearab marked this conversation as resolved.
|
||
| if name in self._parent._paths and not overwrite: | ||
| raise ValueError( | ||
| f"Dataset '{name}' is already defined as an available built-in dataset. " | ||
| f"Pass overwrite=True to replace it." | ||
| ) | ||
| self._parent._datasets[name] = dataset | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.