Skip to content

Commit 1157e00

Browse files
committed
fix errors and data links
1 parent b283531 commit 1157e00

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

cefcon/datasets.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tqdm.auto import tqdm
1313

1414

15-
def _download_from_url(file_url: str, save_path: str):
15+
def _download_from_url(file_url: str, save_path: Path):
1616
try:
1717
response = requests.get(file_url, stream=True)
1818
response.raise_for_status()
@@ -24,17 +24,20 @@ def _download_from_url(file_url: str, save_path: str):
2424
block_size = 8192
2525
progress_bar = tqdm(total=total_size, unit='B', unit_scale=True)
2626

27-
with open(save_path, 'wb') as file:
27+
download_file = save_path.parent / file_url.split('/')[-1]
28+
with open(download_file, 'wb') as file:
2829
for chunk in response.iter_content(chunk_size=block_size):
2930
if chunk:
3031
file.write(chunk)
3132
progress_bar.update(len(chunk))
3233

3334
progress_bar.close()
3435

35-
if save_path.endswith('.zip'):
36-
with zipfile.ZipFile(save_path, 'r') as zip_file:
36+
if str(download_file).endswith('.zip'):
37+
with zipfile.ZipFile(download_file, 'r') as zip_file:
3738
zip_file.extractall(os.path.dirname(save_path))
39+
zip_file.close()
40+
os.remove(download_file)
3841

3942
print(f'Ths data has been downloaded to `{save_path}`.')
4043

@@ -45,18 +48,18 @@ def load_human_prior_interaction_network(dataset: str = 'nichenet',
4548

4649
# The URL for every dataset. These datasets are stored at zenodo (https://doi.org/10.5281/zenodo.7564872).
4750
urls = {
48-
'nichenet': 'https://zenodo.org/record/7564872/files/NicheNet_human.zip',
49-
'pathwaycommons': 'https://zenodo.org/record/7564872/files/PathwayCommons12.All.hgnc.zip',
50-
'inbiomap': 'https://zenodo.org/record/7564872/files/InBioMap.zip',
51-
'harmonizome': 'https://zenodo.org/record/7564872/files/Harmonizome_nichenet.zip',
52-
'omnipath_interaction': 'https://zenodo.org/record/7564872/files/Omnipath_interaction.zip',
51+
'nichenet': 'https://zenodo.org/record/8013900/files/NicheNet_human.zip',
52+
'pathwaycommons': 'https://zenodo.org/record/8013900/files/PathwayCommons12.All.hgnc.zip',
53+
'inbiomap': 'https://zenodo.org/record/8013900/files/InBioMap.zip',
54+
'harmonizome': 'https://zenodo.org/record/8013900/files/Harmonizome_nichenet.zip',
55+
'omnipath_interactions': 'https://zenodo.org/record/8013900/files/Omnipath_interaction.zip',
5356
}
5457
filenames = {
5558
'nichenet': 'NicheNet_human.csv',
5659
'pathwaycommons': 'PathwayCommons12.All.hgnc.sif',
5760
'inbiomap': 'InBioMap.csv',
5861
'harmonizome': 'Harmonizome_nichenet.csv',
59-
'omnipath_interaction': 'Omnipath_interaction.csv',
62+
'omnipath_interactions': 'Omnipath_interaction.csv',
6063
}
6164

6265
# Download if the file does not exist
@@ -88,7 +91,7 @@ def load_human_prior_interaction_network(dataset: str = 'nichenet',
8891
prior_net = pd.read_csv(data_path, sep='\t')
8992
prior_net = prior_net.loc[:, ['from', 'to']]
9093

91-
elif dataset == 'omnipath_interaction': # 525,430
94+
elif dataset == 'omnipath_interactions': # 525,430
9295
prior_net = pd.read_csv(data_path)
9396
prior_net.rename(columns={'source_genesymbol': 'from', 'target_genesymbol': 'to'}, inplace=True)
9497
complex_idx = prior_net['source'].str.startswith('COMPLEX') | \
@@ -117,7 +120,7 @@ def load_human_prior_interaction_network(dataset: str = 'nichenet',
117120

118121
else:
119122
print(f"Value error. {dataset} is not available.")
120-
print("Available option: {'nichenet', 'pathwaycommons', 'inbiomap', 'harmonizome', 'omnipath_interaction'}")
123+
print("Available option: {'nichenet', 'pathwaycommons', 'inbiomap', 'harmonizome', 'omnipath_interactions'}")
121124

122125
if ('is_directed' in prior_net) and only_directed:
123126
prior_net = prior_net[prior_net['is_directed'] == 1]
@@ -240,16 +243,14 @@ def convert_human_to_mouse_network(net: pd.DataFrame):
240243
def mouse_hsc_nestorowa16(fpath: Optional[str] = './data_cache/mouse_hsc_nestorowa16_v0.h5ad', version: Optional[str] = 'v0'):
241244
if version=='v0':
242245
fpath = './data_cache/mouse_hsc_nestorowa16_v0.h5ad'
243-
url = 'https://zenodo.org/record/7564872/files/mouse_hsc_nestorowa16_v0.h5ad'
246+
url = 'https://zenodo.org/record/8013900/files/mouse_hsc_nestorowa16_v0.h5ad'
244247
print('Load mouse_hsc_nestorowa16_v0.h5ad')
245248
elif version=='v1':
246249
fpath = './data_cache/mouse_hsc_nestorowa16_v1.h5ad'
247-
url = 'https://zenodo.org/record/7564872/files/mouse_hsc_nestorowa16_v1.h5ad'
250+
url = 'https://zenodo.org/record/8013900/files/mouse_hsc_nestorowa16_v1.h5ad'
248251
print('Load mouse_hsc_nestorowa16_v1.h5ad')
249252
else:
250-
fpath = './data_cache/mouse_hsc_nestorowa16_v2.h5ad'
251-
url = 'https://zenodo.org/record/7564872/files/mouse_hsc_nestorowa16_v2.h5ad'
252-
print('Load mouse_hsc_nestorowa16_v2.h5ad')
253+
print('Wrong data!')
253254
adata = sc.read(fpath, backup_url=url, sparse=True, cache=True)
254255
adata.var_names_make_unique()
255256
return adata

0 commit comments

Comments
 (0)