Skip to content

real_multi_modality #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 497 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
497 commits
Select commit Hold shift + click to select a range
609db04
translate notes
xingzhongyu Dec 20, 2024
b26151f
add notes
xingzhongyu Dec 20, 2024
6878afa
add notes
xingzhongyu Dec 20, 2024
04ab7eb
add notes
xingzhongyu Dec 20, 2024
844d883
add notes
xingzhongyu Dec 20, 2024
1512c01
add notes
xingzhongyu Dec 20, 2024
7549f1d
minor
xingzhongyu Dec 20, 2024
f0b8db4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
3c3f527
minor
xingzhongyu Dec 20, 2024
bc037a7
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 20, 2024
93d96c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
e2bd540
minor
xingzhongyu Dec 20, 2024
312ab95
minor
xingzhongyu Dec 20, 2024
b5a6a22
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 20, 2024
5e51a66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
1a98457
minor
xingzhongyu Dec 20, 2024
4220db0
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 20, 2024
a19aa53
update data
xingzhongyu Dec 20, 2024
aa664c9
add data
xingzhongyu Dec 22, 2024
3c66081
minor
xingzhongyu Dec 22, 2024
c2e6aa9
update data
xingzhongyu Dec 23, 2024
fc3213f
add yamls
xingzhongyu Dec 23, 2024
3fc9e3d
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 23, 2024
b5d738c
add yamls
xingzhongyu Dec 23, 2024
d276716
merge
xingzhongyu Dec 23, 2024
629e065
minor
xingzhongyu Dec 23, 2024
60711e0
add yamls
xingzhongyu Dec 23, 2024
ca1f837
minor
xingzhongyu Dec 23, 2024
9df3dfe
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 23, 2024
5b03b8d
minor
xingzhongyu Dec 23, 2024
b308093
merge
xingzhongyu Dec 23, 2024
745d058
add yamls
xingzhongyu Dec 23, 2024
b32bf75
update data
xingzhongyu Dec 23, 2024
814f39e
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 23, 2024
ef30006
update get_result_web
xingzhongyu Dec 25, 2024
4543d1c
minor
xingzhongyu Dec 26, 2024
9345b19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 26, 2024
b27e312
update run config
xingzhongyu Dec 27, 2024
add42ca
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 27, 2024
2f6cf01
minor
xingzhongyu Dec 27, 2024
f1ea675
update config
xingzhongyu Dec 27, 2024
a3d0aa6
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 27, 2024
978ce1c
minor
xingzhongyu Dec 27, 2024
aae2315
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 27, 2024
ca00a8d
update result web
xingzhongyu Dec 27, 2024
6f6612f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 27, 2024
42a42c8
update data
xingzhongyu Dec 27, 2024
742ec97
update data
xingzhongyu Dec 27, 2024
7785022
update ans
xingzhongyu Dec 27, 2024
3c7b91d
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 27, 2024
3344477
update config
xingzhongyu Dec 28, 2024
b686b37
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 28, 2024
0f2b6a4
update ans
xingzhongyu Dec 28, 2024
3bc9f79
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 28, 2024
a7313ea
delete a file or dir
xingzhongyu Dec 28, 2024
933f1bc
update ans
xingzhongyu Dec 28, 2024
20adea2
update config
xingzhongyu Dec 28, 2024
3e61695
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 28, 2024
74394c8
update ans
xingzhongyu Dec 29, 2024
ebc1d80
update ans
xingzhongyu Dec 29, 2024
bd021c2
update ans
xingzhongyu Dec 29, 2024
88a1ed8
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 29, 2024
29611b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 29, 2024
b5c6af1
update ans
xingzhongyu Dec 29, 2024
9f3218a
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 29, 2024
a53558f
update ans
xingzhongyu Dec 29, 2024
6e2c17f
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 29, 2024
b011926
update ans
xingzhongyu Dec 29, 2024
64a4c7a
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 29, 2024
a2f9ac2
update ans
xingzhongyu Dec 29, 2024
60cf01a
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 29, 2024
ce36094
update ans
xingzhongyu Dec 29, 2024
13cc17f
update ans
xingzhongyu Dec 30, 2024
f20cdd0
update ans
xingzhongyu Dec 30, 2024
192621f
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Dec 30, 2024
95b1e97
update ans
xingzhongyu Dec 30, 2024
1150e12
update ans
xingzhongyu Dec 30, 2024
c69f3c1
update ans
xingzhongyu Dec 30, 2024
3dcdf78
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 30, 2024
39a3a71
update ans
xingzhongyu Dec 30, 2024
f31da9f
update ans
xingzhongyu Dec 30, 2024
ded0576
update ans
xingzhongyu Dec 30, 2024
610425f
update ans
xingzhongyu Dec 30, 2024
52480a7
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Dec 30, 2024
0f345ef
update ans
xingzhongyu Dec 30, 2024
95b241b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 30, 2024
10fda95
update ans
xingzhongyu Dec 30, 2024
50fd98d
update ans
xingzhongyu Dec 30, 2024
529de4c
update ans
xingzhongyu Dec 30, 2024
7bd4246
update ans
xingzhongyu Dec 30, 2024
dd7540c
update main
xingzhongyu Dec 31, 2024
eda1fff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 31, 2024
ed4a62b
update ans
xingzhongyu Dec 31, 2024
7cb693a
update ans
xingzhongyu Dec 31, 2024
36d6412
update ans
xingzhongyu Dec 31, 2024
bcf4492
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 31, 2024
66af9da
update ans
xingzhongyu Jan 1, 2025
ab917f0
update ans
xingzhongyu Jan 2, 2025
2b68b1b
update ans
xingzhongyu Jan 2, 2025
ff02cf7
minor
xingzhongyu Jan 2, 2025
3aa929d
Merge branch 'celltype_annotation_automl' of https://github.com/Omics…
xingzhongyu Jan 2, 2025
afa7fc8
update ans
xingzhongyu Jan 2, 2025
3ed6a96
update ans
xingzhongyu Jan 2, 2025
0edb02b
update ans
xingzhongyu Jan 3, 2025
f56e2fd
update ans
xingzhongyu Jan 3, 2025
66cfc67
update ans
xingzhongyu Jan 3, 2025
e6faa66
update ans
xingzhongyu Jan 3, 2025
b70e71f
update ans
xingzhongyu Jan 3, 2025
0812e66
update ans
xingzhongyu Jan 3, 2025
00380dc
update ans
xingzhongyu Jan 4, 2025
5a8a162
update ans
xingzhongyu Jan 4, 2025
9a291e7
update ans
xingzhongyu Jan 4, 2025
431edc1
update ans
xingzhongyu Jan 4, 2025
3d3516c
update ans
xingzhongyu Jan 4, 2025
60d4731
update ans
xingzhongyu Jan 4, 2025
a531ab9
update ans
xingzhongyu Jan 4, 2025
b11b5aa
update ans
xingzhongyu Jan 4, 2025
f7925c6
update ans
xingzhongyu Jan 4, 2025
1d7bb5b
update ans
xingzhongyu Jan 5, 2025
cc9a683
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 5, 2025
fd17d42
update ans
xingzhongyu Jan 5, 2025
159c4b7
update ans
xingzhongyu Jan 5, 2025
1f7f13f
update ans
xingzhongyu Jan 5, 2025
81a4982
update ans
xingzhongyu Jan 5, 2025
caf70c0
update ans
xingzhongyu Jan 5, 2025
e08eec4
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 5, 2025
fd3e9a3
update ans
xingzhongyu Jan 5, 2025
9e8fb85
update ans
xingzhongyu Jan 5, 2025
01f159c
update ans
xingzhongyu Jan 5, 2025
cdd9c50
update ans
xingzhongyu Jan 7, 2025
518d9ca
update ans
xingzhongyu Jan 7, 2025
087c40d
update ans
xingzhongyu Jan 7, 2025
c4c9889
update ans
xingzhongyu Jan 7, 2025
135136c
update ans
xingzhongyu Jan 7, 2025
e8d2817
update ans
xingzhongyu Jan 7, 2025
6b6f79b
update ans
xingzhongyu Jan 7, 2025
ee334bb
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 7, 2025
58d2b20
update ans
xingzhongyu Jan 7, 2025
5b99078
update ans
xingzhongyu Jan 7, 2025
2b82fd6
update ans
xingzhongyu Jan 7, 2025
f4e6965
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 7, 2025
561025f
update ans
xingzhongyu Jan 7, 2025
790e5d9
update ans
xingzhongyu Jan 8, 2025
0a9a2d3
update ans
xingzhongyu Jan 8, 2025
7e7d158
update ans
xingzhongyu Jan 9, 2025
7ab9272
update ans
xingzhongyu Jan 10, 2025
af633a2
update ans
xingzhongyu Jan 10, 2025
0ee8d40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2025
3e24fcd
update ans
xingzhongyu Jan 10, 2025
c611304
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 10, 2025
ffc84b2
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 10, 2025
3336d4c
update ans
xingzhongyu Jan 11, 2025
fadbea6
git merge
xingzhongyu Jan 11, 2025
d97a92f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 11, 2025
0a33784
update ans
xingzhongyu Jan 12, 2025
9846dee
update ans
xingzhongyu Jan 12, 2025
c8c4e2b
update ans
xingzhongyu Jan 12, 2025
6454d16
update ans
xingzhongyu Jan 12, 2025
5781123
update ans
xingzhongyu Jan 12, 2025
7cb9810
update ans
xingzhongyu Jan 12, 2025
2d18eae
update ans
xingzhongyu Jan 12, 2025
5d81ec7
update ans
xingzhongyu Jan 13, 2025
9ded6a2
update ans
xingzhongyu Jan 13, 2025
5ac5142
update ans
xingzhongyu Jan 13, 2025
47f2515
update ans
xingzhongyu Jan 13, 2025
25bf832
update ans
xingzhongyu Jan 13, 2025
9de47a1
update ans
xingzhongyu Jan 13, 2025
f23b1ca
update ans
xingzhongyu Jan 14, 2025
9c4b124
update ans
xingzhongyu Jan 15, 2025
0a580a3
update ans
xingzhongyu Jan 15, 2025
9db346a
update ans
xingzhongyu Jan 15, 2025
28cb5f6
update ans
xingzhongyu Jan 15, 2025
cf402bd
update ans
xingzhongyu Jan 15, 2025
6538dcb
update ans
xingzhongyu Jan 15, 2025
d093eff
update ans
xingzhongyu Jan 15, 2025
fd967ca
update ans
xingzhongyu Jan 15, 2025
04e1c4c
update ans
xingzhongyu Jan 15, 2025
9c02b28
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 15, 2025
4ed35ab
update ans
xingzhongyu Jan 15, 2025
0131d01
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Jan 15, 2025
d3296d7
add wandb to requirement
xingzhongyu Jan 15, 2025
c4be6a9
update ans
xingzhongyu Jan 18, 2025
4844b13
update ans
xingzhongyu Jan 18, 2025
dfaf304
update ans
xingzhongyu Jan 18, 2025
b0406bb
update ans
xingzhongyu Jan 18, 2025
2baf956
update ans
xingzhongyu Jan 18, 2025
8037b1c
update ans
xingzhongyu Jan 18, 2025
1f242f4
update test
xingzhongyu Jan 18, 2025
0c2b37d
update ans
xingzhongyu Jan 19, 2025
479d366
update ot
xingzhongyu Jan 28, 2025
3af7d79
update ot
xingzhongyu Jan 28, 2025
3be3608
update test
xingzhongyu Jan 28, 2025
36567d0
update comment
xingzhongyu Jan 30, 2025
e1c97df
update comment
xingzhongyu Jan 30, 2025
8a53ec0
update comment
xingzhongyu Jan 30, 2025
4274782
add readme
xingzhongyu Feb 2, 2025
89fcad3
translate
xingzhongyu Feb 3, 2025
6e046f8
add device argument
xingzhongyu Feb 3, 2025
2340eac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2025
7bc4a3c
translate
xingzhongyu Feb 3, 2025
a9ce1d6
translate
xingzhongyu Feb 3, 2025
56fcc36
add note
xingzhongyu Feb 3, 2025
34bcfac
update comment
xingzhongyu Feb 3, 2025
058c9a2
update comment
xingzhongyu Feb 3, 2025
966728a
minor
xingzhongyu Feb 3, 2025
7d9e44b
update comment
xingzhongyu Feb 3, 2025
113d8cd
update test
xingzhongyu Feb 3, 2025
2cca105
update comment
xingzhongyu Feb 3, 2025
0af5f2e
minor
xingzhongyu Feb 3, 2025
0d8b22d
minor
xingzhongyu Feb 3, 2025
622aea8
add comment
xingzhongyu Feb 4, 2025
315b532
update import
xingzhongyu Feb 5, 2025
50141ae
update user interface
xingzhongyu Feb 6, 2025
4b6838e
update user interface
xingzhongyu Feb 6, 2025
2c5e1da
minor
xingzhongyu Feb 11, 2025
9f724b3
add cell type annotation atlas
xingzhongyu Feb 15, 2025
6389413
add test data
xingzhongyu Feb 15, 2025
eb34bad
update file path
xingzhongyu Feb 15, 2025
9f8cc5e
ignore test atlas
xingzhongyu Feb 15, 2025
1f6bc42
add sensitive data test
xingzhongyu Feb 16, 2025
65b0f11
minor
xingzhongyu Feb 16, 2025
18306c8
remote data
xingzhongyu Feb 16, 2025
d91a511
minor
xingzhongyu Feb 16, 2025
c6f60df
update analysis
xingzhongyu Feb 21, 2025
204e50c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2025
84ae0ef
add tutorial
xingzhongyu Mar 24, 2025
e96511d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 24, 2025
bdf2993
delete proxy
xingzhongyu Mar 25, 2025
a8dff5a
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Mar 25, 2025
8e59677
init scheteronet
xingzhongyu Apr 13, 2025
4c78769
init stdgcn
xingzhongyu Apr 15, 2025
7f21e6a
update dataset
xingzhongyu Apr 16, 2025
3d3e35d
add dataset
xingzhongyu Apr 16, 2025
a822819
update PCA
xingzhongyu Apr 16, 2025
44431c6
change
xingzhongyu Apr 16, 2025
fd3df41
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 16, 2025
c5e3277
add dataset
xingzhongyu Apr 17, 2025
4235942
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Apr 17, 2025
ce9b5bc
add cluster
xingzhongyu Apr 20, 2025
e32cf06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 20, 2025
fc6e90f
add filter
xingzhongyu Apr 21, 2025
fe0b553
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Apr 21, 2025
4ce95b5
update imputation
xingzhongyu Apr 21, 2025
90c9d18
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 21, 2025
51adffb
update run_kwargs
xingzhongyu Apr 21, 2025
540b9f3
update run_kwargs
xingzhongyu Apr 21, 2025
55b8329
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 21, 2025
d7f0475
update filter
xingzhongyu Apr 21, 2025
8e5f642
Merge remote-tracking branch 'origin/celltype_annotation_automl' into…
xingzhongyu Apr 21, 2025
e863c61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ temp_data
*.egg*
__pycache__
build/
*.log

#ignore example result
examples/**/*.h5ad
examples/tuning/**/*.yaml
examples/tuning/**/*.csv
examples/tuning/**/*.sh
examples/tuning/**/*.h5
examples/tuning/**/*.tar.gz
examples/tuning/**/*.tif
examples/tuning/**/*.txt
examples/atlas/config/run_config.csv
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: ^docs/

# - repo: https://github.com/lyz-code/yamlfix # The tool that actually fixes
# rev: 1.16.0 # <---- UPDATE THIS to the latest stable version
# hooks:
# - id: yamlfix
# name: yamlfix (Auto-Fix) # Optional: Rename for clarity
# additional_dependencies:
# - maison==1.4.3 # <--- 例子:指定 maison 版本为 0.2.3
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args: [-c=.yamllint.yml]

- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py3-plus]

- repo: https://github.com/google/yapf
rev: v0.40.2
hooks:
- id: yapf
name: Format code
additional_dependencies: [toml]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: Sort imports
args: [--line-width, "120", --profile, black]

args: [--line-width, '120', --profile, black]
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
rev: eb1df34
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooks:
- id: docformatter
name: Format docstring
additional_dependencies: [tomli]
args: [--config, pyproject.toml]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
name: Format markdown
additional_dependencies:
- mdformat-gfm
- mdformat-tables
additional_dependencies: [mdformat-gfm, mdformat-tables]
64 changes: 32 additions & 32 deletions README.md

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions dance/atlas/data_dropbox_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import json
import os
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropbox Data Upload Utility

A module providing utility functions for uploading single-cell data to Dropbox and generating shareable links.

Core Features

  • upload_file_to_dropbox: Upload local files to Dropbox
  • file_upload: Handle large files using chunked upload
  • create_shared_link: Create or retrieve Dropbox shared links
  • get_link: Upload files and get downloadable shared links
  • get_ans: Generate dataset metadata dictionary

Technical Highlights

  • Supports chunked upload for large files
  • Handles authentication errors gracefully
  • Provides dataset metadata management
  • Optimized for single-cell data (AnnData format)

import pathlib

import dropbox
import numpy as np
import pandas as pd
import scanpy as sc
from dropbox.exceptions import ApiError, AuthError

from dance.utils import logger


def upload_file_to_dropbox(dropbox_path, access_token, local_path):
"""Upload a local file to Dropbox.

Parameters
----------
dropbox_path : str
Destination path in Dropbox
access_token : str
Dropbox API access token
local_path : str or pathlib.Path
Path to local file to upload

Returns
-------
None
Returns None if upload fails

"""
dbx = dropbox.Dropbox(access_token)

# Verify access token
try:
dbx.users_get_current_account()
except AuthError as err:
print("ERROR: Invalid access token; please check your access token.")
return None
try:
file_upload(dbx=dbx, local_path=local_path, remote_path=dropbox_path)
print("Upload successful.")
except ApiError as err:
print(f"API error: {err}")
return None


def file_upload(dbx: dropbox.Dropbox, local_path: pathlib.Path, remote_path: str):
"""Upload large files to Dropbox using chunked upload.

Parameters
----------
dbx : dropbox.Dropbox
Authenticated Dropbox client
local_path : pathlib.Path
Path to local file
remote_path : str
Destination path in Dropbox

"""
CHUNKSIZE = 100 * 1024 * 1024
upload_session_start_result = dbx.files_upload_session_start(b'')
cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id, offset=0)
with local_path.open("rb") as f:
while True:
data = f.read(CHUNKSIZE)
if data == b"":
break
logger.debug("Pushing %d bytes", len(data))
dbx.files_upload_session_append_v2(data, cursor)
cursor.offset += len(data)
commit = dropbox.files.CommitInfo(path=remote_path)
dbx.files_upload_session_finish(b'', cursor, commit)


def create_shared_link(dbx, dropbox_path):
"""Create or get existing shared link.

:param dbx: Dropbox object
:param dropbox_path: File path on Dropbox
:return: Shared link URL

"""
try:
links = dbx.sharing_list_shared_links(path=dropbox_path, direct_only=True).links
if links:
# If shared link already exists, return the first one
return links[0].url
else:
# Create a new shared link
link = dbx.sharing_create_shared_link_with_settings(dropbox_path)
return link.url
except ApiError as err:
print(f"Error creating shared link: {err}")
return None


def get_link(data_fname, local_path, ACCESS_TOKEN, DROPBOX_DEST_PATH):
DROPBOX_DEST_PATH = DROPBOX_DEST_PATH + "/" + data_fname

upload_file_to_dropbox(dropbox_path=DROPBOX_DEST_PATH, access_token=ACCESS_TOKEN, local_path=local_path)

# Create Dropbox object to get shared link
dbx = dropbox.Dropbox(ACCESS_TOKEN)
# Get shared link
shared_link = create_shared_link(dbx, DROPBOX_DEST_PATH)
if shared_link:
# Dropbox shared link defaults to `dl=0` at the end, which means preview in browser.
# change it to `dl=1`.
download_link = shared_link.replace('&dl=0', '&dl=1')
print(f"Download link: {download_link}")
return download_link
else:
print("Unable to get shared link.")


def get_ans(data: sc.AnnData, tissue: str, dataset_id: str, local_path, ACCESS_TOKEN, DROPBOX_DEST_PATH):
"""Generate metadata dictionary for dataset and upload to Dropbox.

Parameters
----------
data : sc.AnnData
Annotated data matrix
tissue : str
Tissue type
dataset_id : str
Unique identifier for dataset
local_path : str or pathlib.Path
Path to local data file
ACCESS_TOKEN : str
Dropbox API access token
DROPBOX_DEST_PATH : str
Base path in Dropbox for uploads

Returns
-------
dict
Metadata dictionary containing dataset information and Dropbox URLs

"""
# keys=["species","tissue","dataset","split","celltype_fname","celltype_url","data_fname","data_url"]
# Create metadata dictionary with dataset info
ans = {}
ans["species"] = "human"
ans["tissue"] = tissue.capitalize()
# Store number of observations (cells) in dataset
ans["dataset"] = data.n_obs
ans["split"] = "train"
ans["celltype_fname"] = ""
ans["celltype_url"] = ""
ans["data_fname"] = f"train_human_{tissue.capitalize()}{dataset_id}_data.h5ad"
ans["data_url"] = get_link(data_fname=ans["data_fname"].split("_", 1)[1], local_path=local_path,
ACCESS_TOKEN=ACCESS_TOKEN, DROPBOX_DEST_PATH=DROPBOX_DEST_PATH)
ans["is_ALL_Integer"] = np.all(np.equal(data.X.data, data.X.data.astype(int)))
return ans
Loading