Skip to content

Commit 2600b2e

Browse files
committed
support single tissue download
1 parent a23416d commit 2600b2e

2 files changed

Lines changed: 47 additions & 14 deletions

File tree

splicemap/main.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,37 @@ def complete_url(tissue, psi):
7070
]
7171
}
7272

73+
def check_tissue_in_url(url, tissues):
74+
in_url = False
75+
for tissue in tissues:
76+
if tissue in url:
77+
in_url = True
78+
return in_url
79+
80+
def _download(url, splicemap_dir):
81+
r = requests.get(url)
82+
fname = Path(splicemap_dir)
83+
fname.mkdir(exist_ok=True)
84+
fname = fname / \
85+
unquote(Path(url).name).replace('?download=1', '')
86+
print(fname)
87+
with open(fname, 'wb') as fd:
88+
fd.write(r.content)
89+
7390
@click.command()
7491
@click.option('--version', help='SpliceMap version (currently SpliceMaps from gtex_v8 (hg38) supported)')
7592
@click.option('--splicemap_dir', help='Path to download SpliceMaps')
76-
def splicemap_download(version, splicemap_dir):
93+
@click.option('--tissues', multiple=True, help='List of tissue names to download')
94+
def splicemap_download(version, splicemap_dir, tissues=None):
7795

7896
if version not in splicemap_url:
7997
raise(f'Version {version} is not supported.')
8098

8199
print('Downloading SpliceMaps...')
82100

83101
for url in tqdm(splicemap_url[version]):
84-
r = requests.get(url)
85-
fname = Path(splicemap_dir)
86-
fname.mkdir(exist_ok = True)
87-
fname = fname / unquote(Path(url).name).replace('?download=1', '')
88-
89-
with open(fname, 'wb') as fd:
90-
fd.write(r.content)
102+
if tissues:
103+
if check_tissue_in_url(url, tissues):
104+
_download(url, splicemap_dir)
105+
else:
106+
_download(url, splicemap_dir)

tests/test_download.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
from click.testing import CliRunner
22
from splicemap.splice_map import SpliceMap
3-
from splicemap.main import splicemap_download
4-
3+
from splicemap.main import splicemap_download, gtex_v8_tissues
4+
import os
55

66
def tests_download_splicemap(tmp_path):
77
runner = CliRunner()
88

9-
result = runner.invoke(splicemap_download, f'--version _test --splicemap_dir {str(tmp_path)}')
9+
result = runner.invoke(splicemap_download, f'--version gtex_v8 --splicemap_dir {str(tmp_path)}')
1010
assert result.exit_code == 0
11-
12-
sm = SpliceMap.read_csv(str(tmp_path))
13-
assert sm.df.shape[0] > 0
1411

12+
for tissue in gtex_v8_tissues:
13+
for psi in ['psi5', 'psi3']:
14+
sm = SpliceMap.read_csv(os.path.join(
15+
tmp_path,
16+
f'{tissue}_splicemap_{psi}_method=kn_event_filter=median_cutoff.csv.gz'))
17+
assert sm.df.shape[0] > 0
18+
19+
def tests_download_splicemap_single_tissue(tmp_path):
20+
runner = CliRunner()
21+
22+
result = runner.invoke(
23+
splicemap_download, f'--version gtex_v8 --splicemap_dir {str(tmp_path)} --tissues Whole_Blood --tissues Lung')
24+
assert result.exit_code == 0
25+
26+
for tissue in ['Whole_Blood', 'Lung']:
27+
for psi in ['psi5', 'psi3']:
28+
sm = SpliceMap.read_csv(os.path.join(
29+
tmp_path,
30+
f'{tissue}_splicemap_{psi}_method=kn_event_filter=median_cutoff.csv.gz'))
31+
assert sm.df.shape[0] > 0

0 commit comments

Comments
 (0)