Last active
April 25, 2022 06:55
-
-
Save Yu-AnChen/3842bc756824f69d1f9fe6115bde3446 to your computer and use it in GitHub Desktop.
Upload recursively to sage synapse using synapse python client
This file contains 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 synapseclient | |
import pathlib | |
from synapseclient import Folder, File | |
exclude_folders = ( | |
'.nextflow', | |
'probability-maps', | |
'qc', | |
'registration', | |
'segmentation' | |
) | |
include_folders = ('quantification', ) | |
def upload_to_parent(path, parent, syn): | |
p = pathlib.Path(path) | |
if not p.is_dir(): | |
if set(include_folders).intersection(p.parts) > 0: | |
# print(p) | |
top_f = File(str(p), parent=parent) | |
syn.store(top_f) | |
else: | |
for i in p.iterdir(): | |
if not i.is_dir(): | |
if len(set(include_folders).intersection(i.parts)) > 0: | |
# print(i) | |
l1_f = File(str(i), parent=parent) | |
syn.store(l1_f) | |
else: | |
if len(set(exclude_folders).intersection(i.parts)) == 0: | |
# print(i) | |
l1_p = Folder(i.name, parent=parent) | |
l1_p = syn.store(l1_p) | |
upload_to_parent(i, l1_p, syn) | |
syn = synapseclient.Synapse() | |
syn.login() | |
syn_f = syn.get('syn123') | |
upload_to_parent(r'path/to/local/dir', syn_f, syn) | |
syn.logout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment