Skip to content

Commit 87fecb4

Browse files
committed
making a function
1 parent 555b961 commit 87fecb4

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

scripts/qiita-load-qebil-downloads

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ from glob import glob
1212
from os.path import isdir, basename, join
1313
from shutil import copyfile
1414

15-
from qiita_db.user import User
1615
from qiita_db.study import Study
1716
from qiita_db.artifact import Artifact
1817
from qiita_db.commands import (
@@ -21,25 +20,11 @@ from qiita_db.commands import (
2120
from qiita_db.util import get_data_types, get_mountpoint, create_nested_path
2221

2322

24-
SLEEP_TIME = 10
25-
EBIDIR = '/panfs/panfs1.ucsd.edu/panscratch/qiita/qebil/vertebrates/'
26-
data_types = set([x.replace(' ', '_') for x in get_data_types()])
23+
def load_qebil_study(folder, shared_with):
24+
data_types = set([x.replace(' ', '_') for x in get_data_types()])
2725

28-
folders = glob(f'{EBIDIR}/*')
29-
shared_with_emails = ['sjsong@eng.ucsd.edu']
30-
shared_with = [User(x) for x in shared_with_emails]
31-
32-
for folder in folders:
3326
warnings = []
3427
extra_notes = dict()
35-
if not isdir(folder):
36-
print(f'Ignoring: {folder}')
37-
continue
38-
print(f'\n\n\n+++> Processing {folder}, you have {SLEEP_TIME} '
39-
'seconds to ctrl-c')
40-
# Note: this sleep is not necessary but nice for debugging so we have time
41-
# to ctrl-c
42-
sleep(10)
4328

4429
files = glob(f'{folder}/*')
4530
files_used = []
@@ -48,7 +33,7 @@ for folder in folders:
4833
qebil_status = fp.readlines()[0]
4934
if 'complete' not in qebil_status:
5035
print(f'Skipping {qebil_status_fp}, not ready: {qebil_status}')
51-
continue
36+
return
5237
files_used.append(qebil_status_fp)
5338

5439
title_fp = [f for f in files if f.endswith('_study_title.txt')][0]
@@ -63,11 +48,18 @@ for folder in folders:
6348

6449
if Study.exists(title):
6550
print(f'======> {folder}: {title} already loaded')
66-
continue
51+
return
6752

6853
with open(config_fp, 'r') as fp:
6954
study = load_study_from_cmd('qiita.help@gmail.com', title, fp)
7055

56+
print('===================')
57+
print('===================')
58+
print('===================')
59+
print(f'study {study.id} created')
60+
print('===================')
61+
print('===================')
62+
7163
study.autoloaded = True
7264
study.ebi_study_accession = study.info['study_alias'].split(';')[0]
7365
sample_info = load_sample_template_from_cmd(sample_fp, study.id)
@@ -201,6 +193,11 @@ for folder in folders:
201193

202194
artifact = Artifact.create(filepaths, 'per_sample_FASTQ',
203195
prep_template=pt, move_files=False)
196+
print(" ")
197+
print(" ")
198+
print(f" artifact {artifact.id} was created for {pt.id}")
199+
print(" ")
200+
print(" ")
204201
notes = ''
205202
if warnings:
206203
notes = '<b>Warnings</b>:<ol>%s</ol>\n' % ''.join(
@@ -225,3 +222,23 @@ for folder in folders:
225222

226223
for x in shared_with:
227224
study.share(x)
225+
226+
227+
# data is a list [str, [list of Users]]
228+
data = [
229+
# ["folder filepath", [list of Users to add as shared_with]]
230+
]
231+
232+
for folder, shared_with in data:
233+
SLEEP_TIME = 10
234+
235+
if not isdir(folder):
236+
print(f'Ignoring: {folder}')
237+
continue
238+
print(f'\n\n\n+++> Processing {folder}, you have {SLEEP_TIME} '
239+
'seconds to ctrl-c')
240+
# Note: this sleep is not necessary but nice for debugging so we have time
241+
# to ctrl-c
242+
sleep(10)
243+
244+
load_qebil_study(folder, shared_with)

0 commit comments

Comments
 (0)