Created
July 14, 2025 12:52
-
-
Save kaspermunch/527a8d2ea9a5f41357c530042e7e8f12 to your computer and use it in GitHub Desktop.
Download script for 4dnuleome database
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
| import os | |
| import requests | |
| from requests.auth import HTTPBasicAuth | |
| import json | |
| from tqdm.notebook import tqdm | |
| def download_4dn(identifier, dowload_dir=os.getcwd(), pgbar=False): | |
| def download_file(url, dowload_dir=dowload_dir: | |
| if not os.path.exists(dowload_dir): | |
| os.makedirs(dowload_dir) | |
| file_name = url.split('/')[-1] | |
| with requests.get(url, stream=True) as r: | |
| r.raise_for_status() | |
| with open(file_name, 'wb') as f: | |
| if pgbar: | |
| pbar = tqdm(total=int(r.headers['Content-Length'])) | |
| for chunk in r.iter_content(chunk_size=8192): | |
| if chunk: | |
| f.write(chunk) | |
| if pgbar: | |
| pbar.update(len(chunk)) | |
| url = f"https://data.4dnucleome.org/ga4gh/drs/v1/objects/{identifier}/access/https" | |
| response = requests.get(url, auth=HTTPBasicAuth(key, secret)) | |
| if not response.ok: | |
| assert 0 | |
| info = response.json() | |
| download_file(info["url"]) | |
| download_4dn('4DNFIA85JYD7') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment