-
Notifications
You must be signed in to change notification settings - Fork 2
Network loader #55
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
Network loader #55
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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
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,3 +1,4 @@ | ||
| from .dataset_loader import DatasetLoader | ||
| from .network_loader import NetworkLoader | ||
|
|
||
| __all__ = ["DatasetLoader"] | ||
| __all__ = ["DatasetLoader", "NetworkLoader"] |
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,79 @@ | ||
| from pathlib import Path | ||
| import pandas as pd | ||
| from typing import List | ||
|
|
||
| class NetworkLoader: | ||
| """ | ||
| Class to load bundled networks from the networks folder. | ||
| Current options are: | ||
| - brca_smccnet_ae | ||
| - brca_smccnet_rf | ||
| - brca_smccnet_var | ||
|
|
||
| Networks must live in subfolders each containing: | ||
| - GlobalNetwork.csv | ||
| - size_<n>_net_<i>.csv | ||
| """ | ||
| def __init__(self): | ||
| self.base_dir = Path(__file__).parent / "networks" | ||
| if not self.base_dir.is_dir(): | ||
| raise FileNotFoundError(f"Bundled networks folder not found at: {self.base_dir}") | ||
|
|
||
| methods: List[str] = [] | ||
| for p in self.base_dir.iterdir(): | ||
| if p.is_dir(): | ||
| methods.append(p.name) | ||
|
|
||
| self.methods = methods | ||
|
|
||
| def available_methods(self) -> List[str]: | ||
| """Return list of bundled network-method names""" | ||
| return self.methods | ||
|
|
||
| def load_global_network(self, method: str) -> pd.DataFrame: | ||
| """ | ||
| Load the GlobalNetwork.csv for the given method. | ||
| """ | ||
|
|
||
| folder = self.base_dir / method | ||
| path = folder / "GlobalNetwork.csv" | ||
|
|
||
| if not path.is_file(): | ||
| raise FileNotFoundError(f"GlobalNetwork.csv not found for method {method}") | ||
|
|
||
| return pd.read_csv(path, index_col=0) | ||
|
|
||
| def load_clusters(self, method: str) -> List[pd.DataFrame]: | ||
| """ | ||
| Load all size_*_net_*.csv cluster files for the given method, | ||
| sorted by (size, index), and return them as DataFrames | ||
| """ | ||
| folder = self.base_dir / method | ||
| if not folder.is_dir(): | ||
| raise FileNotFoundError(f"Method folder '{method}' not found under {self.base_dir}") | ||
|
|
||
| raw = list(folder.glob("size_*_net_*.csv")) | ||
| sorted_paths: List[Path] = [] | ||
|
|
||
| for p in raw: | ||
| parts = p.stem.split("_") | ||
| size = int(parts[1]) | ||
| idx = int(parts[-1]) | ||
| inserted = False | ||
| for i, ex in enumerate(sorted_paths): | ||
| ex_parts = ex.stem.split("_") | ||
| ex_size = int(ex_parts[1]) | ||
| ex_idx = int(ex_parts[-1]) | ||
| if (size, idx) < (ex_size, ex_idx): | ||
| sorted_paths.insert(i, p) | ||
| inserted = True | ||
| break | ||
|
|
||
| if not inserted: | ||
| sorted_paths.append(p) | ||
|
|
||
| clusters: List[pd.DataFrame] = [] | ||
| for path in sorted_paths: | ||
| clusters.append(pd.read_csv(path, index_col=0)) | ||
|
|
||
| return clusters |
2,504 changes: 2,504 additions & 0 deletions
2,504
bioneuralnet/datasets/networks/brca_smccnet_ae/GlobalNetwork.csv
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
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.
Typo 'realease' should be corrected to 'release'.