Skip to content

Commit

Permalink
adding download function
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitjohnson committed Mar 20, 2024
1 parent 8bacbe3 commit 0b2b65a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 27 deletions.
78 changes: 53 additions & 25 deletions docs/tutorials/nbs/demo_data_scimap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,85 @@
"id": "19f306b3-25e3-4130-995e-382d59b74d2b",
"metadata": {},
"source": [
"A short guide to downloading our exemplar data for trying out the **scimap toolbox**.\n",
"\n",
"Navigate to the Harvard Dataverse website and download the exemplar data (see screenshot below!)\n",
"A short guide to downloading our demo data for trying out the **scimap toolbox**."
]
},
{
"cell_type": "markdown",
"id": "dfa7001e-ac43-4e2e-ab77-6c899dcee781",
"metadata": {},
"source": [
"**You can download the data in two methods:**\n",
"\n",
"Data: https://doi.org/10.7910/DVN/C45JWT"
"1. Utilize the built-in download function of scimap.\n",
"2. Visit the website through your browser and manually download the data."
]
},
{
"cell_type": "markdown",
"id": "cc076a7d-528f-4115-a907-e21fb9fb8d54",
"metadata": {},
"source": [
"### 1. Built in function"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d99d5348-fe28-4676-acd1-7c651f8c5fc1",
"metadata": {},
"outputs": [],
"source": [
"import scimap as sm"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "92580b41-d8b0-4472-b666-1863848d9e11",
"id": "eb92e132-674c-47f0-b4a0-65a75eb8058b",
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Provide a download directory\n",
"download_directory = ''\n",
"sm.hl.downloadDemoData (download_directory)"
]
},
{
"cell_type": "markdown",
"id": "13c8e569-21f0-4bfe-86db-33c4eb47651d",
"id": "7b01408a-6505-468e-b384-be5316afd352",
"metadata": {},
"source": [
"- Click on the \"Access Dataset\"\"Original Format ZIP\" button.\n",
"- Wait for the download to complete. The size of the file is approximately 40 MB.\n",
"- Unzip the downloaded file to access the data.\n",
" \n",
"To ensure that you can follow the tutorial correctly, please make sure that the following folder structure (screenshot below) is maintained:\n",
"\n"
"A zipped data folder will appear in the specified directory. Simply unzip it, and you'll be all set to start."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd533e27-b744-4ecb-9834-84527f5432a9",
"cell_type": "markdown",
"id": "83a9cf87-7904-46b1-9d52-45f4780cb30f",
"metadata": {},
"outputs": [],
"source": []
"source": [
"### 2. Download from Zonodo"
]
},
{
"cell_type": "markdown",
"id": "15b3e78f-7464-4bd8-9a95-e953a80f1b48",
"id": "17a4ece7-4a97-40a4-be25-4d247ebb1f8a",
"metadata": {},
"source": [
"If you have any questions or encounter any issues while following the tutorial, please don't hesitate to contact us for assistance."
"- Go to [Zonodo](https://zenodo.org/records/10845625)\n",
"- Click on the download button\n",
"- unzip the downloaded file\n",
"\n",
"DOI: [10.5281/zenodo.10845624](https://zenodo.org/records/10845625)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d74d7aeb-0bda-4448-9eb9-3d040cfb8ec6",
"cell_type": "markdown",
"id": "15b3e78f-7464-4bd8-9a95-e953a80f1b48",
"metadata": {},
"outputs": [],
"source": []
"source": [
"If you have any questions or encounter any issues while following the tutorial, please don't hesitate to contact us for assistance."
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "SCIMAP"
version = "1.3.14"
version = "1.3.15"
description = "Spatial Single-Cell Analysis Toolkit"

license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion scimap/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .rename import renamefrom .classify import classifyfrom .scimap_to_csv import scimap_to_csvfrom .addROI_omero import addROI_omerofrom .animate import animatefrom .dropFeatures import dropFeaturesfrom .merge_adata_obs import merge_adata_obs
from .rename import renamefrom .classify import classifyfrom .scimap_to_csv import scimap_to_csvfrom .addROI_omero import addROI_omerofrom .animate import animatefrom .dropFeatures import dropFeaturesfrom .merge_adata_obs import merge_adata_obsfrom .downloadDemoData import downloadDemoData
Expand Down
41 changes: 41 additions & 0 deletions scimap/helpers/downloadDemoData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 20 15:04:25 2024
@author: aj
"""

import requests
import os

def downloadDemoData(directory):

# Ensure the target directory exists
if not os.path.exists(directory):
os.makedirs(directory)
print(f"Created directory: {directory}")

# Get record details from Zenodo API
api_url = f"https://zenodo.org/api/records/10845625"
response = requests.get(api_url)
if response.status_code != 200:
print(f"Failed to retrieve record details. HTTP status code: {response.status_code}")
return

# Extract file links from the record information
record_data = response.json()
files = record_data.get('files', [])

# Download each file
for file_info in files:
file_url = file_info['links']['self']
filename = file_info['key']
save_path = os.path.join(directory, filename)

# Download the file
print(f"Downloading {filename}...")
with requests.get(file_url, stream=True) as file_response:
with open(save_path, 'wb') as file:
for chunk in file_response.iter_content(chunk_size=8192):
file.write(chunk)
print(f"Downloaded {filename} to {save_path}")

0 comments on commit 0b2b65a

Please sign in to comment.