Skip to content

Commit

Permalink
support single tissue download
Browse files Browse the repository at this point in the history
  • Loading branch information
WagnerNils committed Apr 25, 2022
1 parent a23416d commit 2600b2e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
32 changes: 24 additions & 8 deletions splicemap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,37 @@ def complete_url(tissue, psi):
]
}

def check_tissue_in_url(url, tissues):
in_url = False
for tissue in tissues:
if tissue in url:
in_url = True
return in_url

def _download(url, splicemap_dir):
r = requests.get(url)
fname = Path(splicemap_dir)
fname.mkdir(exist_ok=True)
fname = fname / \
unquote(Path(url).name).replace('?download=1', '')
print(fname)
with open(fname, 'wb') as fd:
fd.write(r.content)

@click.command()
@click.option('--version', help='SpliceMap version (currently SpliceMaps from gtex_v8 (hg38) supported)')
@click.option('--splicemap_dir', help='Path to download SpliceMaps')
def splicemap_download(version, splicemap_dir):
@click.option('--tissues', multiple=True, help='List of tissue names to download')
def splicemap_download(version, splicemap_dir, tissues=None):

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

print('Downloading SpliceMaps...')

for url in tqdm(splicemap_url[version]):
r = requests.get(url)
fname = Path(splicemap_dir)
fname.mkdir(exist_ok = True)
fname = fname / unquote(Path(url).name).replace('?download=1', '')

with open(fname, 'wb') as fd:
fd.write(r.content)
if tissues:
if check_tissue_in_url(url, tissues):
_download(url, splicemap_dir)
else:
_download(url, splicemap_dir)
29 changes: 23 additions & 6 deletions tests/test_download.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
from click.testing import CliRunner
from splicemap.splice_map import SpliceMap
from splicemap.main import splicemap_download

from splicemap.main import splicemap_download, gtex_v8_tissues
import os

def tests_download_splicemap(tmp_path):
runner = CliRunner()

result = runner.invoke(splicemap_download, f'--version _test --splicemap_dir {str(tmp_path)}')
result = runner.invoke(splicemap_download, f'--version gtex_v8 --splicemap_dir {str(tmp_path)}')
assert result.exit_code == 0

sm = SpliceMap.read_csv(str(tmp_path))
assert sm.df.shape[0] > 0

for tissue in gtex_v8_tissues:
for psi in ['psi5', 'psi3']:
sm = SpliceMap.read_csv(os.path.join(
tmp_path,
f'{tissue}_splicemap_{psi}_method=kn_event_filter=median_cutoff.csv.gz'))
assert sm.df.shape[0] > 0

def tests_download_splicemap_single_tissue(tmp_path):
runner = CliRunner()

result = runner.invoke(
splicemap_download, f'--version gtex_v8 --splicemap_dir {str(tmp_path)} --tissues Whole_Blood --tissues Lung')
assert result.exit_code == 0

for tissue in ['Whole_Blood', 'Lung']:
for psi in ['psi5', 'psi3']:
sm = SpliceMap.read_csv(os.path.join(
tmp_path,
f'{tissue}_splicemap_{psi}_method=kn_event_filter=median_cutoff.csv.gz'))
assert sm.df.shape[0] > 0

0 comments on commit 2600b2e

Please sign in to comment.