-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add BreastInvasiveCarcinoma
dataset
#7905
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c7e7035
Added breast_cancer_graph_dataset
Favourj-bit 3051d4b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 02e7cff
Update CHANGELOG.md
Favourj-bit ebd7d86
editing files
Favourj-bit 64dc463
Merge pull request #1 from pyg-team/master
Favourj-bit 00649f5
editing comments
Favourj-bit 14593be
Merge branch 'master' of https://github.com/Favourj-bit/pytorch_geome…
Favourj-bit b8c8d8f
Merge branch 'master' into master
akihironitta bd1c052
Rename the class BrcaTcga
akihironitta 1ed7c24
Update comments
akihironitta 145ac71
Rename the class BrcaTcga
akihironitta bd1a7de
Update docstring
akihironitta a89db24
Pass pre_filter
akihironitta bb4c0ec
Remove unused kwarg
akihironitta 8c42767
Refactor
akihironitta ab2f485
editing docstring
Favourj-bit 204f26a
editing docstring
Favourj-bit 1e557bb
Merge branch 'master' into master
rusty1s 41ec8c5
update
rusty1s 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 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 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,107 @@ | ||
import os | ||
from typing import Callable, Optional, Tuple | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import torch | ||
|
||
from torch_geometric.data import ( | ||
Data, | ||
InMemoryDataset, | ||
download_url, | ||
extract_zip, | ||
) | ||
|
||
|
||
class BrcaTcga(InMemoryDataset): | ||
r"""The breast cancer (BRCA TCGA) dataset from `cBioPortal | ||
<https://www.cbioportal.org>`_ and the biological network for node | ||
connections from `Pathway Commons <https://www.pathwaycommons.org>`_. | ||
The dataset contains the gene features of each patient in graph_features | ||
and the overall survival time (in months) of each patient, | ||
which are the labels. | ||
|
||
Args: | ||
root (str): Root directory where the dataset should be saved. | ||
transform (callable, optional): A function/transform that takes in an | ||
:obj:`torch_geometric.data.Data` object and returns a transformed | ||
version. The data object will be transformed before every access. | ||
(default: :obj:`None`) | ||
pre_transform (callable, optional): A function/transform that takes in | ||
an :obj:`torch_geometric.data.Data` object and returns a | ||
transformed version. The data object will be transformed before | ||
being saved to disk. (default: :obj:`None`) | ||
|
||
**STATS:** | ||
|
||
.. list-table:: | ||
:widths: 10 10 10 10 | ||
:header-rows: 1 | ||
|
||
* - #graphs | ||
- #nodes | ||
- #edges | ||
- #features | ||
* - 1082 | ||
- 271771 | ||
- 1082 | ||
- 4 | ||
""" | ||
url = 'https://zenodo.org/record/8251328/files/brca_tcga.zip?download=1' | ||
|
||
def __init__( | ||
self, | ||
root: str, | ||
transform: Optional[Callable] = None, | ||
pre_transform: Optional[Callable] = None, | ||
): | ||
super().__init__(root, transform, pre_transform) | ||
self.data, self.slices = torch.load(self.processed_paths[0]) | ||
|
||
@property | ||
def raw_file_names(self): | ||
return ['graph_idx.csv', 'graph_labels.csv', 'edge_index.pt'] | ||
|
||
@property | ||
def processed_file_names(self): | ||
return 'breast_data.pt' | ||
|
||
def download(self): | ||
path = download_url(self.url, self.raw_dir) | ||
extract_zip(path, self.raw_dir) | ||
os.unlink(path) | ||
|
||
def process(self): | ||
graph_features = pd.read_csv( | ||
os.path.join(self.raw_dir, 'brca_tcga', 'graph_idx.csv'), | ||
index_col=0) | ||
graph_labels = np.loadtxt( | ||
os.path.join(self.raw_dir, 'brca_tcga', 'graph_labels.csv'), | ||
delimiter=',') | ||
edge_index = torch.load( | ||
os.path.join(self.raw_dir, 'brca_tcga', 'edge_index.pt')) | ||
|
||
graph_features = graph_features.values | ||
num_patients = graph_features.shape[0] | ||
|
||
data_list = [] | ||
for i in range(num_patients): | ||
node_features = graph_features[i] | ||
target = graph_labels[i] | ||
data_list.append( | ||
Data( | ||
x=torch.tensor(node_features.reshape(-1, 1)), | ||
edge_index=edge_index, | ||
y=torch.tensor(target), | ||
)) | ||
|
||
data, slices = self.collate(data_list) | ||
torch.save((data, slices), self.processed_paths[0]) | ||
|
||
def predefined_split( | ||
self, train_index, test_index, | ||
val_index) -> Tuple['BrcaTcga', 'BrcaTcga', 'BrcaTcga']: | ||
train_dataset = self.index_select(train_index) | ||
test_dataset = self.index_select(test_index) | ||
val_dataset = self.index_select(val_index) | ||
return train_dataset, test_dataset, val_dataset |
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.
Could you check the docstring change as I've just removed some redundant sentences? Also, it'd be ncie if you could describe what nodes and edges represent to help new users understand this dataset. (example: https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.datasets.KarateClub.html#torch_geometric.datasets.KarateClub)