basepair 1.5__0-py3.8.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +27 -0
- EGG-INFO/SOURCES.txt +38 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/requires.txt +5 -0
- EGG-INFO/scripts/basepair +637 -0
- EGG-INFO/top_level.txt +1 -0
- EGG-INFO/zip-safe +1 -0
- basepair/__init__.py +32 -0
- basepair/__pycache__/__init__.cpython-38.pyc +0 -0
- basepair/__pycache__/api.cpython-38.pyc +0 -0
- basepair/api.py +1353 -0
- basepair/helpers/__init__.py +3 -0
- basepair/helpers/__pycache__/__init__.cpython-38.pyc +0 -0
- basepair/helpers/__pycache__/eprint.cpython-38.pyc +0 -0
- basepair/helpers/__pycache__/nice_print.cpython-38.pyc +0 -0
- basepair/helpers/__pycache__/set_filter.cpython-38.pyc +0 -0
- basepair/helpers/eprint.py +8 -0
- basepair/helpers/nice_print.py +170 -0
- basepair/helpers/set_filter.py +18 -0
- basepair/infra/__init__.py +0 -0
- basepair/infra/__pycache__/__init__.cpython-38.pyc +0 -0
- basepair/infra/configuration/__init__.py +1 -0
- basepair/infra/configuration/__pycache__/__init__.cpython-38.pyc +0 -0
- basepair/infra/configuration/__pycache__/parser.cpython-38.pyc +0 -0
- basepair/infra/configuration/parser.py +67 -0
- basepair/infra/webapp/__init__.py +12 -0
- basepair/infra/webapp/__pycache__/__init__.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/abstract.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/analysis.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/file.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/gene.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/genome.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/genome_file.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/host.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/module.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/pipeline.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/project.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/sample.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/upload.cpython-38.pyc +0 -0
- basepair/infra/webapp/__pycache__/user.cpython-38.pyc +0 -0
- basepair/infra/webapp/abstract.py +128 -0
- basepair/infra/webapp/analysis.py +10 -0
- basepair/infra/webapp/file.py +10 -0
- basepair/infra/webapp/gene.py +10 -0
- basepair/infra/webapp/genome.py +10 -0
- basepair/infra/webapp/genome_file.py +10 -0
- basepair/infra/webapp/host.py +10 -0
- basepair/infra/webapp/module.py +10 -0
- basepair/infra/webapp/pipeline.py +10 -0
- basepair/infra/webapp/project.py +10 -0
- basepair/infra/webapp/sample.py +10 -0
- basepair/infra/webapp/upload.py +10 -0
- basepair/infra/webapp/user.py +48 -0
- basepair/utils/__init__.py +0 -0
- basepair/utils/__pycache__/__init__.cpython-38.pyc +0 -0
- basepair/utils/__pycache__/colors.cpython-38.pyc +0 -0
- basepair/utils/__pycache__/monitor.cpython-38.pyc +0 -0
- basepair/utils/__pycache__/s3.cpython-38.pyc +0 -0
- basepair/utils/__pycache__/sqs.cpython-38.pyc +0 -0
- basepair/utils/__pycache__/swf.cpython-38.pyc +0 -0
- basepair/utils/colors.py +43 -0
- basepair/utils/monitor.py +38 -0
- basepair/utils/s3.py +77 -0
- basepair/utils/sqs.py +147 -0
- basepair/utils/swf.py +129 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
'''
|
|
3
|
+
Basepair CLI, wraps the Python API
|
|
4
|
+
|
|
5
|
+
[2015] - [2019] Basepair INC
|
|
6
|
+
All Rights Reserved.
|
|
7
|
+
|
|
8
|
+
NOTICE: All information contained herein is, and remains
|
|
9
|
+
the property of Basepair INC and its suppliers,
|
|
10
|
+
if any. The intellectual and technical concepts contained
|
|
11
|
+
herein are proprietary to Basepair INC
|
|
12
|
+
and its suppliers and may be covered by U.S. and Foreign Patents,
|
|
13
|
+
patents in process, and are protected by trade secret or copyright law.
|
|
14
|
+
Dissemination of this information or reproduction of this material
|
|
15
|
+
is strictly forbidden unless prior written permission is obtained
|
|
16
|
+
from Basepair INC.
|
|
17
|
+
'''
|
|
18
|
+
|
|
19
|
+
from __future__ import print_function
|
|
20
|
+
|
|
21
|
+
import argparse
|
|
22
|
+
import json
|
|
23
|
+
import sys
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
sys.path.insert(0, '/home/ec2-user/basepair')
|
|
27
|
+
import basepair
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def yes_or_no(question, default='no'):
|
|
31
|
+
"""Ask a yes/no question via raw_input() and return their answer.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
question - str
|
|
36
|
+
Is a string that is presented to the user.
|
|
37
|
+
|
|
38
|
+
default - str
|
|
39
|
+
is the presumed answer if the user just hits <Enter>.
|
|
40
|
+
It must be "yes" (the default), "no" or None (meaning
|
|
41
|
+
an answer is required of the user).
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
valid = {"yes": True, "y": True, "ye": True,
|
|
45
|
+
"no": False, "n": False}
|
|
46
|
+
|
|
47
|
+
prompt = " [y/n] "
|
|
48
|
+
|
|
49
|
+
while True:
|
|
50
|
+
|
|
51
|
+
# get input function for py 2 and 3
|
|
52
|
+
get_input = input
|
|
53
|
+
|
|
54
|
+
if sys.version_info[:2] <= (2, 7):
|
|
55
|
+
get_input = raw_input
|
|
56
|
+
|
|
57
|
+
# get input from user
|
|
58
|
+
|
|
59
|
+
sys.stdout.write(question + prompt)
|
|
60
|
+
choice = get_input().lower()
|
|
61
|
+
|
|
62
|
+
# check answer
|
|
63
|
+
if choice in valid:
|
|
64
|
+
return valid[choice]
|
|
65
|
+
else:
|
|
66
|
+
sys.stdout.write("Please respond with 'yes' or 'no' "
|
|
67
|
+
"(or 'y' or 'n').\n")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main():
|
|
71
|
+
args = read_args()
|
|
72
|
+
|
|
73
|
+
if args.config:
|
|
74
|
+
conf = json.load(open(args.config))
|
|
75
|
+
else:
|
|
76
|
+
conf = None
|
|
77
|
+
|
|
78
|
+
# will override default and use these as owner for all actions
|
|
79
|
+
# if args.username:
|
|
80
|
+
# conf['api']['username'] = args.username
|
|
81
|
+
# if args.api_key:
|
|
82
|
+
# conf['api']['api_key'] = args.api_key
|
|
83
|
+
|
|
84
|
+
bp = basepair.connect(
|
|
85
|
+
conf=conf,
|
|
86
|
+
scratch=args.scratch,
|
|
87
|
+
use_cache=args.use_cache,
|
|
88
|
+
user_cache_for_host_conf=args.keep_cloud_service_conf,
|
|
89
|
+
verbose=args.verbose
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if hasattr(args, 'datatype'):
|
|
93
|
+
if args.datatype and args.datatype not in bp.DATATYPES:
|
|
94
|
+
raise argparse.ArgumentTypeError(
|
|
95
|
+
'datatype has to be among:' + ', '.join(bp.DATATYPES))
|
|
96
|
+
|
|
97
|
+
if args.action == 'create':
|
|
98
|
+
if args.create_type == 'project':
|
|
99
|
+
create_project(bp, args)
|
|
100
|
+
|
|
101
|
+
if args.create_type == 'sample':
|
|
102
|
+
|
|
103
|
+
# if payload username or api key specified, make sure both
|
|
104
|
+
# are present
|
|
105
|
+
|
|
106
|
+
if args.payload_username is not None \
|
|
107
|
+
and args.payload_api_key is None:
|
|
108
|
+
print('specify both --payload-username and --payload-api-key!')
|
|
109
|
+
sys.exit(1)
|
|
110
|
+
elif args.payload_api_key is not None \
|
|
111
|
+
and args.payload_username is None:
|
|
112
|
+
print('specify both --payload-username and --payload-api-key!')
|
|
113
|
+
sys.exit(1)
|
|
114
|
+
elif args.payload_username is not None \
|
|
115
|
+
and args.payload_username is not None:
|
|
116
|
+
bp.payload = {
|
|
117
|
+
'username': args.payload_username,
|
|
118
|
+
'api_key': args.payload_api_key}
|
|
119
|
+
|
|
120
|
+
create_sample(bp, args)
|
|
121
|
+
if args.create_type == 'analysis':
|
|
122
|
+
create_analysis(bp, args)
|
|
123
|
+
elif args.action == 'updateProject':
|
|
124
|
+
update_project(bp, args)
|
|
125
|
+
elif args.action == 'updateSample':
|
|
126
|
+
update_sample(bp, args.sample[0], args.key, args.val)
|
|
127
|
+
elif args.action == 'updateAnalysis':
|
|
128
|
+
update_analysis(bp, args.analysis, args.key, args.val)
|
|
129
|
+
elif args.action == 'download':
|
|
130
|
+
|
|
131
|
+
if args.download_type == 'analysis':
|
|
132
|
+
# download a file form an analysis by tags
|
|
133
|
+
|
|
134
|
+
for uid in args.uid:
|
|
135
|
+
bp.download_analysis(uid, args.tags, args.tagkind,
|
|
136
|
+
args.outdir)
|
|
137
|
+
elif args.download_type == 'file':
|
|
138
|
+
# download a file by uid
|
|
139
|
+
|
|
140
|
+
for uid in args.uid:
|
|
141
|
+
file_i = bp.get_file(uid)
|
|
142
|
+
bp.download_file(file_i['path'], dirname=args.outdir)
|
|
143
|
+
|
|
144
|
+
elif args.download_type == 'log':
|
|
145
|
+
|
|
146
|
+
for uid in args.uid:
|
|
147
|
+
|
|
148
|
+
# check analysis id is valid
|
|
149
|
+
info, res = bp.get_analysis(uid)
|
|
150
|
+
if info is None:
|
|
151
|
+
print("{} is not a valid analysis id!".format(uid))
|
|
152
|
+
continue
|
|
153
|
+
|
|
154
|
+
if args.outdir:
|
|
155
|
+
bp.get_log(uid, args.outdir)
|
|
156
|
+
else:
|
|
157
|
+
bp.get_log(uid)
|
|
158
|
+
|
|
159
|
+
elif args.download_type == 'sample':
|
|
160
|
+
for uid in args.uid:
|
|
161
|
+
|
|
162
|
+
sample = bp.get_sample(uid, add_analysis=True)
|
|
163
|
+
|
|
164
|
+
if sample is None:
|
|
165
|
+
print("{} is not a valid sample id!".format(uid))
|
|
166
|
+
continue
|
|
167
|
+
|
|
168
|
+
# if tags provided, download file by tags
|
|
169
|
+
if args.tags:
|
|
170
|
+
bp.get_file_by_tags(sample, tags=args.tags,
|
|
171
|
+
kind=args.tagkind, dirname=args.outdir)
|
|
172
|
+
else:
|
|
173
|
+
bp.download_raw_files(sample, args.outdir)
|
|
174
|
+
|
|
175
|
+
elif args.action == 'delete':
|
|
176
|
+
delete(bp, args.type[0], args.uid)
|
|
177
|
+
elif args.action == 'list':
|
|
178
|
+
|
|
179
|
+
if args.list_type == 'analysis':
|
|
180
|
+
for uid in args.uid:
|
|
181
|
+
bp.print_data(data_type='analysis', uid=uid,
|
|
182
|
+
is_json=args.json)
|
|
183
|
+
if args.list_type == 'analyses':
|
|
184
|
+
bp.print_data(data_type='analyses', is_json=args.json)
|
|
185
|
+
elif args.list_type == 'genomes':
|
|
186
|
+
bp.print_data(data_type='genomes', is_json=args.json)
|
|
187
|
+
elif args.list_type == 'sample':
|
|
188
|
+
for uid in args.uid:
|
|
189
|
+
bp.print_data(data_type='sample', uid=uid,
|
|
190
|
+
is_json=args.json)
|
|
191
|
+
elif args.list_type == 'samples':
|
|
192
|
+
bp.print_data(data_type='samples', is_json=args.json)
|
|
193
|
+
elif args.list_type == 'workflows':
|
|
194
|
+
bp.print_data(data_type='workflows', is_json=args.json)
|
|
195
|
+
elif args.list_type == 'genome':
|
|
196
|
+
for uid in args.uid:
|
|
197
|
+
bp.print_data(data_type='genome', uid=uid,
|
|
198
|
+
is_json=args.json)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def create_project(bp, args):
|
|
202
|
+
data = {
|
|
203
|
+
'name': args.name,
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
# if args.key and args.val:
|
|
207
|
+
# for key, val in zip(args.key, args.val):
|
|
208
|
+
# data[key] = val
|
|
209
|
+
|
|
210
|
+
project_id = bp.create_project(data=data)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def create_sample(bp, args):
|
|
214
|
+
data = {
|
|
215
|
+
'name': args.name,
|
|
216
|
+
'genome': args.genome,
|
|
217
|
+
'datatype': args.datatype,
|
|
218
|
+
'filepaths1': args.file1,
|
|
219
|
+
'filepaths2': args.file2,
|
|
220
|
+
'platform': args.platform,
|
|
221
|
+
'default_workflow': int(args.workflow) if args.workflow else None,
|
|
222
|
+
'projects': int(args.project) if args.project else None,
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if args.key and args.val:
|
|
226
|
+
for key, val in zip(args.key, args.val):
|
|
227
|
+
data[key] = val
|
|
228
|
+
|
|
229
|
+
bp.create_sample(data, upload=True, source='cli')
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def create_analysis(bp, args):
|
|
233
|
+
"""Create and submit an analysis"""
|
|
234
|
+
|
|
235
|
+
params = {'node': {}}
|
|
236
|
+
|
|
237
|
+
if args.params is not None:
|
|
238
|
+
|
|
239
|
+
for param in args.params:
|
|
240
|
+
node_id, arg, val = param.split(':')
|
|
241
|
+
|
|
242
|
+
if node_id not in params['node']:
|
|
243
|
+
params['node'][node_id] = {}
|
|
244
|
+
|
|
245
|
+
params['node'][node_id][arg] = val
|
|
246
|
+
|
|
247
|
+
else:
|
|
248
|
+
print('You specified no parameters, submitting with default ones...',
|
|
249
|
+
file=sys.stderr)
|
|
250
|
+
|
|
251
|
+
bp.create_analysis(
|
|
252
|
+
workflow_id=args.workflow, sample_ids=args.sample, control_ids=args.control,
|
|
253
|
+
project_id=args.project, params=params, ignore_validation_warnings=args.ignore_warning)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def update_info(bp, kind, uid, keys, vals):
|
|
257
|
+
data = {}
|
|
258
|
+
if keys and vals:
|
|
259
|
+
for key, val in zip(keys, vals):
|
|
260
|
+
data[key] = val
|
|
261
|
+
|
|
262
|
+
if kind == 'sample':
|
|
263
|
+
res = bp.update_sample(uid, data)
|
|
264
|
+
elif kind == 'analysis':
|
|
265
|
+
res = bp.update_analysis(uid, data)
|
|
266
|
+
if res.status_code != 204:
|
|
267
|
+
print('error {}: {}'.format(
|
|
268
|
+
res.status_code, res.reason), file=sys.stderr)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def update_project(bp, args):
|
|
272
|
+
perm = args.perm if args.perm else 'read'
|
|
273
|
+
params = {
|
|
274
|
+
'permission_data': {
|
|
275
|
+
'emails': args.emails,
|
|
276
|
+
'perm': perm,
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for project_id in args.project:
|
|
280
|
+
res = bp.update_project(project_id, data=None, params=params)
|
|
281
|
+
if res.status_code != 204:
|
|
282
|
+
print('error {}: {}'.format(
|
|
283
|
+
res.status_code, res.reason), file=sys.stderr)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def update_sample(bp, sample_id, keys, vals):
|
|
287
|
+
update_info(bp, 'sample', sample_id, keys, vals)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def update_analysis(bp, analysis_id, keys, vals):
|
|
291
|
+
update_info(bp, 'analysis', analysis_id, keys, vals)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def delete(bp, data_type, uid):
|
|
295
|
+
|
|
296
|
+
if not uid:
|
|
297
|
+
print('Please add one or more uid', file=sys.stderr)
|
|
298
|
+
return
|
|
299
|
+
|
|
300
|
+
if data_type not in ['sample', 'analysis']:
|
|
301
|
+
print(
|
|
302
|
+
('\'--type {}\' is invalid, choose from: ' +
|
|
303
|
+
'sample or analysis').format(data_type))
|
|
304
|
+
return
|
|
305
|
+
|
|
306
|
+
for uid in uid:
|
|
307
|
+
answer = yes_or_no('Are you sure you want to delete {}?'.format(uid))
|
|
308
|
+
if answer:
|
|
309
|
+
if data_type == 'sample':
|
|
310
|
+
bp.delete_sample(uid)
|
|
311
|
+
elif data_type == 'analysis':
|
|
312
|
+
bp.delete_analysis(uid)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def add_common_args(parser):
|
|
316
|
+
|
|
317
|
+
parser.add_argument('-c', '--config', help='API config info')
|
|
318
|
+
parser.add_argument('--quiet', action='store_true')
|
|
319
|
+
parser.add_argument('--keep-cloud-service-conf', action='store_true')
|
|
320
|
+
parser.add_argument('--use-cache', action='store_true')
|
|
321
|
+
parser.add_argument('--scratch', help='Scratch dir for files')
|
|
322
|
+
parser.add_argument('--verbose', action='store_true')
|
|
323
|
+
parser.set_defaults(scratch='.')
|
|
324
|
+
|
|
325
|
+
return parser
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def add_payload_args(parser):
|
|
329
|
+
|
|
330
|
+
parser.add_argument(
|
|
331
|
+
'--payload-username',
|
|
332
|
+
help='Replace payload api key. Must also specify --payload-api-key')
|
|
333
|
+
parser.add_argument(
|
|
334
|
+
'--payload-api-key',
|
|
335
|
+
help='Replace payload api key. Must also specify --payload-username')
|
|
336
|
+
|
|
337
|
+
return parser
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def add_uid_parser(parser):
|
|
341
|
+
|
|
342
|
+
parser.add_argument(
|
|
343
|
+
'-u',
|
|
344
|
+
'--uid',
|
|
345
|
+
nargs='+',
|
|
346
|
+
default=None,
|
|
347
|
+
help='The unique analysis id(s) to download')
|
|
348
|
+
return parser
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def add_json_parser(parser):
|
|
352
|
+
|
|
353
|
+
parser.add_argument(
|
|
354
|
+
'--json',
|
|
355
|
+
action='store_true',
|
|
356
|
+
help='(Optional) Print the data in JSON format ' +
|
|
357
|
+
'(this shows all data associated with each item).')
|
|
358
|
+
return parser
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def add_outdir_parser(parser):
|
|
362
|
+
parser.add_argument(
|
|
363
|
+
'-o',
|
|
364
|
+
'--outdir',
|
|
365
|
+
required=False,
|
|
366
|
+
default='.',
|
|
367
|
+
help='Base directory to save files to (default \'.\').')
|
|
368
|
+
return parser
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def add_tags_parser(parser):
|
|
372
|
+
parser.add_argument(
|
|
373
|
+
'--tags',
|
|
374
|
+
nargs='+',
|
|
375
|
+
action='append',
|
|
376
|
+
default=None)
|
|
377
|
+
parser.add_argument(
|
|
378
|
+
'--tagkind',
|
|
379
|
+
default='exact',
|
|
380
|
+
help='''
|
|
381
|
+
Tag filtering strategy. Options:\n
|
|
382
|
+
(1) exact (default): only get files with exactly these tags.
|
|
383
|
+
(2) diff: exclude files with this tag.
|
|
384
|
+
(3) subset: any files with one or more of these tags.
|
|
385
|
+
''')
|
|
386
|
+
|
|
387
|
+
return parser
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def read_args():
|
|
391
|
+
|
|
392
|
+
parser = argparse.ArgumentParser(
|
|
393
|
+
description='Basepair CLI, API version ' + basepair.__version__,
|
|
394
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
395
|
+
|
|
396
|
+
actions_p = parser.add_subparsers(
|
|
397
|
+
help='Basepair actions.',
|
|
398
|
+
dest='action')
|
|
399
|
+
actions_p.required = True
|
|
400
|
+
|
|
401
|
+
# create parser
|
|
402
|
+
|
|
403
|
+
create_p = actions_p.add_parser(
|
|
404
|
+
'create',
|
|
405
|
+
help='Create samples, analyses, etc.')
|
|
406
|
+
create_sp = create_p.add_subparsers(
|
|
407
|
+
help='Type of item to download',
|
|
408
|
+
dest='create_type')
|
|
409
|
+
|
|
410
|
+
# create project parser
|
|
411
|
+
|
|
412
|
+
create_project_p = create_sp.add_parser(
|
|
413
|
+
'project',
|
|
414
|
+
help='Add a project to your account on Basepair.')
|
|
415
|
+
create_project_p = add_common_args(create_project_p)
|
|
416
|
+
create_project_p.add_argument('--name')
|
|
417
|
+
create_project_p = add_payload_args(create_project_p)
|
|
418
|
+
|
|
419
|
+
# create sample parser
|
|
420
|
+
|
|
421
|
+
create_sample_p = create_sp.add_parser(
|
|
422
|
+
'sample',
|
|
423
|
+
help='Add a sample to your account on Basepair.')
|
|
424
|
+
create_sample_p = add_common_args(create_sample_p)
|
|
425
|
+
create_sample_p.add_argument('--name')
|
|
426
|
+
create_sample_p.add_argument('--genome')
|
|
427
|
+
create_sample_p.add_argument('--platform')
|
|
428
|
+
create_sample_p.add_argument('--datatype')
|
|
429
|
+
create_sample_p.add_argument('--file1', nargs='+')
|
|
430
|
+
create_sample_p.add_argument('--file2', nargs='+')
|
|
431
|
+
create_sample_p.add_argument('-w', '--workflow', help='Workflow id')
|
|
432
|
+
create_sample_p.add_argument('-p', '--project', help='Project id')
|
|
433
|
+
create_sample_p.add_argument('--key', action='append')
|
|
434
|
+
create_sample_p.add_argument('--val', action='append')
|
|
435
|
+
create_sample_p = add_payload_args(create_sample_p)
|
|
436
|
+
|
|
437
|
+
# create analysis parser
|
|
438
|
+
|
|
439
|
+
create_analysis_p = create_sp.add_parser(
|
|
440
|
+
'analysis',
|
|
441
|
+
help='Create and run an analysis.')
|
|
442
|
+
create_analysis_p = add_common_args(create_analysis_p)
|
|
443
|
+
create_analysis_p.add_argument('-p', '--project', help='Project id')
|
|
444
|
+
create_analysis_p.add_argument(
|
|
445
|
+
'-w', '--workflow', help='Workflow id')
|
|
446
|
+
create_analysis_p.add_argument(
|
|
447
|
+
'--sample', nargs='+', help='Sample id')
|
|
448
|
+
create_analysis_p.add_argument(
|
|
449
|
+
'--control', nargs='+', help='Control id')
|
|
450
|
+
create_analysis_p.add_argument('--params', nargs='+')
|
|
451
|
+
create_analysis_p.add_argument(
|
|
452
|
+
'-i', '--ignore_warning', default=False, action='store_true',
|
|
453
|
+
help='Ignore validation warnings')
|
|
454
|
+
|
|
455
|
+
# update project parser
|
|
456
|
+
|
|
457
|
+
update_project_parser = actions_p.add_parser(
|
|
458
|
+
'updateProject',
|
|
459
|
+
help='Update information associated with a project.'
|
|
460
|
+
)
|
|
461
|
+
update_project_parser = add_common_args(update_project_parser)
|
|
462
|
+
update_project_parser.add_argument(
|
|
463
|
+
'-p', '--project', nargs='+', help='project id')
|
|
464
|
+
update_project_parser.add_argument('--emails', nargs='+')
|
|
465
|
+
update_project_parser.add_argument('--perm')
|
|
466
|
+
update_project_parser.add_argument('--key', action='append')
|
|
467
|
+
update_project_parser.add_argument('--val', action='append')
|
|
468
|
+
|
|
469
|
+
# update sample parser
|
|
470
|
+
|
|
471
|
+
update_sample_parser = actions_p.add_parser(
|
|
472
|
+
'updateSample',
|
|
473
|
+
help='Update information associated with a sample.'
|
|
474
|
+
)
|
|
475
|
+
update_sample_parser = add_common_args(update_sample_parser)
|
|
476
|
+
update_sample_parser.add_argument(
|
|
477
|
+
'-s', '--sample', nargs='+', help='Sample id')
|
|
478
|
+
update_sample_parser.add_argument('--key', action='append')
|
|
479
|
+
update_sample_parser.add_argument('--val', action='append')
|
|
480
|
+
|
|
481
|
+
# update analysis parser
|
|
482
|
+
|
|
483
|
+
update_analysis_parser = actions_p.add_parser(
|
|
484
|
+
'updateAnalysis',
|
|
485
|
+
help='Update information associated with an analysis.'
|
|
486
|
+
)
|
|
487
|
+
update_analysis_parser = add_common_args(update_analysis_parser)
|
|
488
|
+
update_analysis_parser.add_argument('-a', '--analysis', help='Analysis id')
|
|
489
|
+
update_analysis_parser.add_argument('--key', action='append')
|
|
490
|
+
update_analysis_parser.add_argument('--val', action='append')
|
|
491
|
+
|
|
492
|
+
# download parsers
|
|
493
|
+
|
|
494
|
+
download_p = actions_p.add_parser('download', help='Download items.')
|
|
495
|
+
|
|
496
|
+
download_sp = download_p.add_subparsers(
|
|
497
|
+
help='Type of item to download',
|
|
498
|
+
dest='download_type')
|
|
499
|
+
|
|
500
|
+
download_analysis_p = download_sp.add_parser(
|
|
501
|
+
'analysis',
|
|
502
|
+
help='Download files for one or more analyses. ' +
|
|
503
|
+
'Can filter by file tags.')
|
|
504
|
+
download_analysis_p = add_uid_parser(download_analysis_p)
|
|
505
|
+
download_analysis_p = add_tags_parser(download_analysis_p)
|
|
506
|
+
download_analysis_p = add_outdir_parser(download_analysis_p)
|
|
507
|
+
download_analysis_p = add_common_args(download_analysis_p)
|
|
508
|
+
|
|
509
|
+
download_file_p = download_sp.add_parser(
|
|
510
|
+
'file',
|
|
511
|
+
help='Download one or more files by uid.')
|
|
512
|
+
download_file_p = add_uid_parser(download_file_p)
|
|
513
|
+
download_file_p = add_outdir_parser(download_file_p)
|
|
514
|
+
download_file_p = add_common_args(download_file_p)
|
|
515
|
+
|
|
516
|
+
download_log_p = download_sp.add_parser(
|
|
517
|
+
'log',
|
|
518
|
+
help='Download analysis logs from one or more analyses.')
|
|
519
|
+
download_log_p = add_uid_parser(download_log_p)
|
|
520
|
+
download_log_p = add_outdir_parser(download_log_p)
|
|
521
|
+
download_log_p = add_common_args(download_log_p)
|
|
522
|
+
|
|
523
|
+
download_sample_p = download_sp.add_parser(
|
|
524
|
+
'sample',
|
|
525
|
+
help='Download raw data or analysis files by tags from ' +
|
|
526
|
+
'one or more samples.')
|
|
527
|
+
download_sample_p = add_uid_parser(download_sample_p)
|
|
528
|
+
download_sample_p = add_tags_parser(download_sample_p)
|
|
529
|
+
download_sample_p = add_outdir_parser(download_sample_p)
|
|
530
|
+
download_sample_p = add_common_args(download_sample_p)
|
|
531
|
+
|
|
532
|
+
# delete parser
|
|
533
|
+
|
|
534
|
+
delete_parser = actions_p.add_parser(
|
|
535
|
+
'delete',
|
|
536
|
+
help='Delete a sample or analysis from your Basepair account.'
|
|
537
|
+
)
|
|
538
|
+
delete_parser = add_common_args(delete_parser)
|
|
539
|
+
delete_parser.add_argument(
|
|
540
|
+
'-t',
|
|
541
|
+
'--type',
|
|
542
|
+
required=True,
|
|
543
|
+
help='Type of data to delete. Options: sample, analysis')
|
|
544
|
+
delete_parser.add_argument(
|
|
545
|
+
'-u',
|
|
546
|
+
'--uid',
|
|
547
|
+
default=None,
|
|
548
|
+
nargs='+',
|
|
549
|
+
help=' The unique sample or analysis id(s)')
|
|
550
|
+
|
|
551
|
+
# list parser
|
|
552
|
+
|
|
553
|
+
list_p = actions_p.add_parser('list', help='List of items.')
|
|
554
|
+
|
|
555
|
+
list_sp = list_p.add_subparsers(
|
|
556
|
+
help='Type of item to list',
|
|
557
|
+
dest='list_type')
|
|
558
|
+
|
|
559
|
+
list_analysis_p = list_sp.add_parser(
|
|
560
|
+
'analysis',
|
|
561
|
+
help='List files and other info for one or more analyses.')
|
|
562
|
+
list_analysis_p = add_common_args(list_analysis_p)
|
|
563
|
+
list_analysis_p = add_uid_parser(list_analysis_p)
|
|
564
|
+
list_analysis_p = add_json_parser(list_analysis_p)
|
|
565
|
+
|
|
566
|
+
list_analyses_p = list_sp.add_parser(
|
|
567
|
+
'analyses',
|
|
568
|
+
help='List basic info about your analyses')
|
|
569
|
+
list_analyses_p = add_common_args(list_analyses_p)
|
|
570
|
+
list_analyses_p = add_json_parser(list_analyses_p)
|
|
571
|
+
|
|
572
|
+
list_samples_p = list_sp.add_parser(
|
|
573
|
+
'samples',
|
|
574
|
+
help='List basic info about all your samples.')
|
|
575
|
+
list_samples_p = add_common_args(list_samples_p)
|
|
576
|
+
list_samples_p = add_json_parser(list_samples_p)
|
|
577
|
+
|
|
578
|
+
list_sample_p = list_sp.add_parser(
|
|
579
|
+
'sample',
|
|
580
|
+
help='List detail info about one or more samples.')
|
|
581
|
+
list_sample_p = add_common_args(list_sample_p)
|
|
582
|
+
list_sample_p = add_uid_parser(list_sample_p)
|
|
583
|
+
list_sample_p = add_json_parser(list_sample_p)
|
|
584
|
+
|
|
585
|
+
list_genomes_p = list_sp.add_parser(
|
|
586
|
+
'genomes',
|
|
587
|
+
help='List available genomes.')
|
|
588
|
+
list_genomes_p = add_common_args(list_genomes_p)
|
|
589
|
+
list_genomes_p = add_json_parser(list_genomes_p)
|
|
590
|
+
|
|
591
|
+
list_genome_p = list_sp.add_parser(
|
|
592
|
+
'genome',
|
|
593
|
+
help='List detail info about one or more genomes.')
|
|
594
|
+
list_genome_p = add_common_args(list_genome_p)
|
|
595
|
+
list_genome_p = add_uid_parser(list_genome_p)
|
|
596
|
+
list_genome_p = add_json_parser(list_genome_p)
|
|
597
|
+
|
|
598
|
+
list_workflows_p = list_sp.add_parser(
|
|
599
|
+
'workflows',
|
|
600
|
+
help='List available workflows.')
|
|
601
|
+
list_workflows_p = add_common_args(list_workflows_p)
|
|
602
|
+
list_workflows_p = add_json_parser(list_workflows_p)
|
|
603
|
+
|
|
604
|
+
parser.set_defaults(
|
|
605
|
+
params=[],
|
|
606
|
+
)
|
|
607
|
+
args = parser.parse_args()
|
|
608
|
+
|
|
609
|
+
if not args.config:
|
|
610
|
+
if 'BP_CONFIG_FILE' not in os.environ:
|
|
611
|
+
print('Please either use the -c or --config param or set '
|
|
612
|
+
'the environment variable BP_CONFIG_FILE!', file=sys.stderr)
|
|
613
|
+
sys.exit(1)
|
|
614
|
+
else:
|
|
615
|
+
print('Using config file ' + os.environ['BP_CONFIG_FILE'],
|
|
616
|
+
file=sys.stderr)
|
|
617
|
+
else:
|
|
618
|
+
print('Using config file', args.config, file=sys.stderr)
|
|
619
|
+
|
|
620
|
+
# if neither set, be verbose
|
|
621
|
+
if not args.verbose and not args.quiet:
|
|
622
|
+
args.verbose = True
|
|
623
|
+
|
|
624
|
+
if hasattr(args, 'key') and hasattr(args, 'val'):
|
|
625
|
+
if args.key and not args.val:
|
|
626
|
+
raise argparse.ArgumentTypeError('val required for key')
|
|
627
|
+
elif not args.key and args.val:
|
|
628
|
+
raise argparse.ArgumentTypeError('key required for val')
|
|
629
|
+
elif args.key and args.val and len(args.key) != len(args.val):
|
|
630
|
+
raise argparse.ArgumentTypeError(
|
|
631
|
+
'number of key and val are not equal')
|
|
632
|
+
|
|
633
|
+
return args
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
if __name__ == '__main__':
|
|
637
|
+
main()
|
EGG-INFO/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
basepair
|
EGG-INFO/zip-safe
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
basepair/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'''set up basepair package'''
|
|
2
|
+
from __future__ import print_function
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
from .utils import colors
|
|
8
|
+
# from .api import basepair
|
|
9
|
+
|
|
10
|
+
__title__ = 'basepair'
|
|
11
|
+
__version__ = '1.5.0'
|
|
12
|
+
__copyright__ = 'Copyright [2017] - [2020] Basepair INC'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
JSON_URL = 'https://pypi.python.org/pypi/{}/json'.format(__title__)
|
|
16
|
+
try:
|
|
17
|
+
resp = requests.get(JSON_URL, timeout=1)
|
|
18
|
+
if resp.status_code == 200:
|
|
19
|
+
latest_version = resp.json()['info']['version']
|
|
20
|
+
if latest_version != __version__:
|
|
21
|
+
print(colors.color.warning(
|
|
22
|
+
'WARNING: The latest version of basepair package is {}. '
|
|
23
|
+
'Please upgrade to avail the latest features and bug-fixes'
|
|
24
|
+
''.format(latest_version)), file=sys.stderr)
|
|
25
|
+
except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
|
|
26
|
+
print('warning: no internet', file=sys.stderr)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def connect(*args, **kwargs):
|
|
30
|
+
'''return basepair package'''
|
|
31
|
+
from basepair.api import BpApi
|
|
32
|
+
return BpApi(*args, **kwargs)
|
|
Binary file
|
|
Binary file
|