0001 classdef OpenBis
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 properties
0021 pybis
0022 end
0023
0024
0025 methods
0026
0027
0028 function obj = OpenBis(varargin)
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 if nargin > 0
0040 url = varargin{1};
0041 user = varargin{2};
0042 pw = varargin{3};
0043 else
0044 [url, user, pw] = user_url_pw_inputdlg;
0045 end
0046
0047 o = py.pybis.Openbis(url, pyargs('verify_certificates', 0));
0048 o.login(user, pw, pyargs('save_token', 1));
0049 obj.pybis = o;
0050 end
0051
0052 function logout(obj)
0053
0054
0055
0056
0057
0058
0059
0060 obj.pybis.logout();
0061 end
0062
0063 function tf= is_session_active(obj)
0064
0065
0066
0067
0068
0069 tf = obj.pybis.is_session_active();
0070 end
0071
0072 function token = token(obj)
0073
0074
0075
0076
0077
0078 token = char(obj.pybis.token);
0079 end
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 function experiment_types = get_experiment_types(obj)
0091
0092
0093
0094
0095
0096 experiment_types = obj.pybis.get_experiment_types();
0097 experiment_types = df_to_table(experiment_types.df);
0098 end
0099
0100 function sample_types = get_sample_types(obj)
0101
0102
0103
0104
0105
0106 sample_types = obj.pybis.get_sample_types();
0107 sample_types = df_to_table(sample_types.df);
0108 end
0109
0110 function material_types = get_material_types(obj)
0111
0112
0113
0114
0115
0116 material_types = obj.pybis.get_material_types();
0117 material_types = df_to_table(material_types.df);
0118 end
0119
0120 function dataset_types = get_dataset_types(obj)
0121
0122
0123
0124
0125
0126 dataset_types = obj.pybis.get_dataset_types();
0127 dataset_types = df_to_table(dataset_types.df);
0128 end
0129
0130 function terms = get_terms(obj)
0131
0132
0133
0134
0135
0136 terms = obj.pybis.get_terms();
0137 terms = df_to_table(terms.df);
0138 end
0139
0140 function tags = get_tags(obj)
0141
0142
0143
0144
0145
0146 tags = obj.pybis.get_tags();
0147 tags = df_to_table(tags.df);
0148 end
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 function spaces = get_spaces(obj)
0159
0160
0161
0162
0163
0164 spaces = obj.pybis.get_spaces();
0165 spaces = df_to_table(spaces.df);
0166 end
0167
0168 function space = get_space(obj, code)
0169
0170
0171
0172
0173
0174
0175
0176
0177 space = obj.pybis.get_space(code);
0178 end
0179
0180 function space = new_space(obj, code, description)
0181
0182
0183
0184
0185
0186
0187
0188
0189 space = obj.pybis.new_space(pyargs('code', code, ...
0190 'description', description));
0191 space.save;
0192 end
0193
0194 function delete_space(obj, code, reason)
0195
0196
0197
0198
0199
0200
0201
0202
0203 space = obj.pybis.get_space(code);
0204 space.delete(reason);
0205 end
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215 function projects = get_projects(obj, space, code)
0216
0217
0218
0219
0220
0221
0222
0223
0224 projects = obj.pybis.get_projects(pyargs('space', space, 'code', code));
0225 projects = df_to_table(projects.df);
0226 end
0227
0228 function project = get_project(obj, id)
0229
0230
0231
0232
0233
0234
0235
0236
0237 project = obj.pybis.get_project(id);
0238 end
0239
0240 function project = new_project(obj, space, code, description)
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 space = obj.pybis.get_space(space);
0252 project = space.new_project(pyargs('code', code, 'description', description));
0253 project.save();
0254 end
0255
0256 function delete_project(obj, code, reason)
0257
0258
0259
0260
0261
0262
0263
0264
0265 project = obj.pybis.get_project(code);
0266 project.delete(reason);
0267 end
0268
0269
0270
0271
0272
0273
0274
0275
0276 function experiments = get_experiments(obj, varargin)
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288 space = '';
0289 type = '';
0290 project = '';
0291
0292 p = inputParser;
0293 addRequired(p, 'obj');
0294 addParameter(p, 'space', space, @ischar);
0295 addParameter(p, 'type', type, @ischar);
0296 addParameter(p, 'project', project, @ischar);
0297 parse(p, obj, varargin{:});
0298 a = p.Results;
0299
0300 experiments = obj.pybis.get_experiments(pyargs('space', a.space, 'type', a.type, 'project', a.project));
0301 experiments = df_to_table(experiments.df);
0302 end
0303
0304 function experiment = get_experiment(obj, id)
0305
0306
0307
0308
0309
0310
0311
0312 experiment = obj.pybis.get_experiment(id);
0313 end
0314
0315 function exp = new_experiment(obj, type, code, project)
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326 t = obj.pybis.get_experiment_type(type);
0327
0328
0329 p = obj.get_project(project);
0330
0331
0332 exp = py.pybis.pybis.Experiment(obj.pybis, pyargs('type', t, 'code', code, 'project', p));
0333
0334
0335 exp.save();
0336 end
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346 function objects = get_objects(obj, varargin)
0347
0348
0349
0350
0351
0352
0353
0354
0355 defaultId = '';
0356
0357 p = inputParser;
0358 addRequired(p, 'obj');
0359 addParameter(p, 'id', defaultId, @ischar);
0360 parse(p, obj, varargin{:});
0361 a = p.Results;
0362
0363 objects = obj.pybis.get_objects(a.id);
0364 objects = df_to_table(objects.df);
0365 end
0366
0367 function object = get_object(obj, id)
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377 object = obj.pybis.get_object(id);
0378 end
0379
0380 function object = new_object(obj, type, space, code)
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391 object = obj.pybis.new_object(pyargs('type', type, 'space', space, 'code', code));
0392 object.save();
0393 end
0394
0395 function object = delete_object(obj, object, reason)
0396
0397
0398
0399
0400
0401
0402
0403
0404 object.delete(reason)
0405 end
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417 function datasets = get_datasets(obj, varargin)
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431 defaultCode = '';
0432 defaultType = '';
0433 defaultExp = '';
0434 defaultProj = '';
0435 defaultTags = '';
0436
0437 p = inputParser;
0438 addRequired(p, 'obj');
0439 addParameter(p, 'code', defaultCode, @ischar);
0440 addParameter(p, 'type', defaultType, @ischar);
0441 addParameter(p, 'experiment', defaultExp, @ischar);
0442 addParameter(p, 'project', defaultProj, @ischar);
0443 addParameter(p, 'tags', defaultTags, @ischar);
0444 parse(p, obj, varargin{:});
0445 a = p.Results;
0446
0447 datasets = obj.pybis.get_datasets(pyargs('code', a.code, 'type', a.type, 'experiment', a.experiment, ...
0448 'project', a.project, 'tags', a.tags));
0449 datasets = df_to_table(datasets.df);
0450 end
0451
0452 function dataset = get_dataset(obj, permid, varargin)
0453
0454
0455
0456
0457
0458
0459
0460 only_data = false;
0461
0462 p = inputParser;
0463 addRequired(p, 'obj');
0464 addRequired(p, 'permid', @ischar);
0465 addOptional(p, 'only_data', only_data, @islogical);
0466 parse(p, obj, permid, varargin{:});
0467 a = p.Results;
0468
0469
0470 dataset = obj.pybis.get_dataset(a.permid);
0471 end
0472
0473
0474 function files = get_dataset_files(obj, dataset, varargin)
0475
0476
0477
0478
0479
0480
0481
0482
0483 start_folder = '/';
0484
0485 p = inputParser;
0486 addRequired(p, 'obj');
0487 addRequired(p, 'dataset');
0488 addOptional(p, 'start_folder', start_folder, @ischar);
0489 parse(p, obj, dataset, varargin{:});
0490 a = p.Results;
0491
0492 files = dataset.get_files(pyargs('start_folder', a.start_folder));
0493 files = df_to_table(files);
0494 end
0495
0496 function path_to_file = dataset_download(obj, dataset, files, varargin)
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 destination = 'data';
0508 wait_until_finished = true;
0509 workers = 10;
0510
0511 p = inputParser;
0512 addRequired(p, 'obj');
0513 addRequired(p, 'dataset');
0514 addRequired(p, 'files', @iscellstr);
0515 addParameter(p, 'destination', destination, @ischar);
0516 addParameter(p, 'wait_until_finished', wait_until_finished, @islogical);
0517 addParameter(p, 'workers', workers, @isscalar);
0518
0519 parse(p, obj, dataset, files, varargin{:});
0520 a = p.Results;
0521
0522 dataset.download(pyargs('files', a.files, 'destination', a.destination, 'wait_until_finished', a.wait_until_finished, 'workers', int16(a.workers)));
0523
0524 path_to_file = fullfile(a.destination, dataset.char, a.files);
0525
0526 end
0527
0528 function dataset = new_dataset(obj, type, object, file_list, varargin)
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538 properties = struct;
0539
0540 p = inputParser;
0541 addRequired(p, 'obj');
0542 addRequired(p, 'type', @ischar);
0543 addRequired(p, 'object', @ischar);
0544 addRequired(p, 'file_list', @iscellstr);
0545 addParameter(p, 'properties', properties, @isstruct);
0546
0547 parse(p, obj, type, object, file_list, varargin{:});
0548 a = p.Results;
0549
0550 dataset = obj.pybis.new_dataset(pyargs('type', a.type, 'experiment', a.object, ...
0551 'files', a.file_list, 'props', a.properties));
0552 dataset.save();
0553
0554 end
0555
0556 function dataset = new_dataset_container(obj, type, experiment, object)
0557
0558
0559
0560
0561
0562
0563
0564
0565 p = inputParser;
0566 addRequired(p, 'obj');
0567 addRequired(p, 'type', @ischar);
0568 addRequired(p, 'experiment', @ischar);
0569 addRequired(p, 'object', @ischar);
0570
0571 parse(p, obj, type, experiment, object, file_list);
0572 a = p.Results;
0573
0574 dataset = obj.pybis.new_dataset(pyargs('type', a.type, 'experiment', a.experiment, 'sample', a.object, 'kind', 'CONTAINER'));
0575 dataset.save();
0576
0577 end
0578
0579
0580 end
0581
0582 end
0583
0584