-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIBdb.m
2665 lines (1803 loc) · 91.5 KB
/
IBdb.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef IBdb < handle
%IBdb API request handler for insectbrainDB.org
% For details, see README.md
%
%
% obj = IBdb();
% obj = IBdb(tokenAuthString);
% obj = IBdb(credentialsFilename);
%
%
%
%
%
% Author:
% Frederick Zittrell (2021)
properties
% File name pointing to the local file with the database user credentials.
credentialsFilename (1,1) string
% Stores the authentication token string.
tokenAuth (1,1) string
% Stores the authentication token time stamp. This is possibly relevant because
% tokens have an expiration time (currently 24 h).
tokenTimeStamp (1,1) datetime
default_experimenter (1,1) string
default_reconstructionCreator (1,1) string
default_groupHead (1,1) string
default_species {IBdb.mustBeEmpytOrScalarInteger}
% WEBOPTIONS used for WEBWRITE and WEBREAD calls. Defines request parameters such
% as request method and headers, incl. authentication.
webopts (1,1) weboptions
end
properties (SetAccess = immutable)
% Indicating whether there is a Python installation that can be used to state
% requests
hasPy = false
end
properties (Constant)
api = "https://insectbraindb.org/api/v2/"
%% Enumeration-like strings for URLs
% These are parts of endpoints and are supposed to be used to compose the URL for
% requests. Use composeUrl() for this.
TOKEN = "token"
NEURON = "neuron"
FUNCTION = "function"
FUNCTIONS = "functions"
NEURON_RECONSTRUCTION = "neuron-reconstruction"
CONFOCAL_STACKS = "confocal_stacks"
CONFOCAL_STACK = "confocal_stack"
BRAIN_STRUCTURE = "brain-structure"
SPECIES_RECONSTRUCTION = "species-reconstruction"
SPECIES = "species"
EXPERIMENT = "experiment"
CATEGORY = "category"
FILE = "file"
FILES = "files"
MORPHOLOGY = "morphology"
GROUP = "group"
PUBLICATION = "publication"
ARBORIZATION_REGION = "arborization_region"
ARBORIZATION_REGIONS = "arborization_regions"
SUPERTYPE = "supertype"
FAMILY = "family"
CLASS = "class"
%% Enumeration-like strings that correspond to database enumerations
% Properties named validate*Enums are supposed to be used in validation functions
% for the respective enumerations.
SEX_MALE = "MALE"
SEX_FEMALE = "FEMALE"
SEX_UNKNOWN = "UNKNOWN"
validEnums_SEX = [
IBdb.SEX_UNKNOWN
IBdb.SEX_FEMALE
IBdb.SEX_MALE
]
HEMISPHERE_LEFT = "LEFT"
HEMISPHERE_RIGHT = "RIGHT"
HEMISPHERE_UNPAIRED = "UNPAIRED"
validEnums_HEMISPHERE = [
IBdb.HEMISPHERE_LEFT
IBdb.HEMISPHERE_RIGHT
IBdb.HEMISPHERE_UNPAIRED
]
STAINING_INTRACELLULARFILL = "Intracellular Fill"
STAINING_EXTRACELLULARFILL = "Extracellular Fill"
STAINING_GOLGI = "Golgi Stain"
STAINING_GENETICALLYLABELED = "Genetically Labeled Neuron"
STAINING_IMMUNOSTAINED = "Immunostained Neuron"
validEnums_STAINING = [
IBdb.STAINING_INTRACELLULARFILL
IBdb.STAINING_EXTRACELLULARFILL
IBdb.STAINING_GOLGI
IBdb.STAINING_GENETICALLYLABELED
IBdb.STAINING_IMMUNOSTAINED
]
FUNCTION_RESPONSE_CLASS_SENSORY = "SENSORY"
FUNCTION_RESPONSE_CLASS_MOTOR = "MOTOR"
FUNCTION_RESPONSE_CLASS_UNKNOWN = "UNKNOWN"
validEnums_FUNCTION_RESPONSE_CLASS = [
IBdb.FUNCTION_RESPONSE_CLASS_SENSORY
IBdb.FUNCTION_RESPONSE_CLASS_MOTOR
IBdb.FUNCTION_RESPONSE_CLASS_UNKNOWN
]
FUNCTION_MODALITY_UNKNOWN = "UNKNOWN"
FUNCTION_MODALITY_NONE = "NONE"
FUNCTION_MODALITY_VISUAL = "VISUAL"
FUNCTION_MODALITY_MECHANOSENSORY = "MECHANOSENSORY"
FUNCTION_MODALITY_OLFACTORY = "OLFACTORY"
FUNCTION_MODALITY_CHEMOSENSORY = "CHEMOSENSORY"
FUNCTION_MODALITY_AUDITORY = "AUDITORY"
FUNCTION_MODALITY_MULTIMODAL = "MULTIMODAL"
validEnums_FUNCTION_MODALITY = [
IBdb.FUNCTION_MODALITY_NONE
IBdb.FUNCTION_MODALITY_UNKNOWN
IBdb.FUNCTION_MODALITY_VISUAL
IBdb.FUNCTION_MODALITY_OLFACTORY
IBdb.FUNCTION_MODALITY_MECHANOSENSORY
IBdb.FUNCTION_MODALITY_CHEMOSENSORY
IBdb.FUNCTION_MODALITY_AUDITORY
IBdb.FUNCTION_MODALITY_MULTIMODAL
]
FUNCTION_ROLE_UNKNOWN = "UNKNOWN"
FUNCTION_ROLE_INHIBITORY = "INHIBITORY"
FUNCTION_ROLE_EXCITATORY = "EXCITATORY"
validEnums_FUNCTION_ROLE = [
IBdb.FUNCTION_ROLE_UNKNOWN
IBdb.FUNCTION_ROLE_INHIBITORY
IBdb.FUNCTION_ROLE_EXCITATORY
]
ARBORIZATION_FIELDSIZE_UNKNOWN = "UNKNOWN";
ARBORIZATION_FIELDSIZE_SMALL = "SMALL";
ARBORIZATION_FIELDSIZE_WIDE = "WIDE";
validEnums_ARBORIZATION_FIELDSIZE = [
IBdb.ARBORIZATION_FIELDSIZE_UNKNOWN
IBdb.ARBORIZATION_FIELDSIZE_SMALL
IBdb.ARBORIZATION_FIELDSIZE_WIDE
]
ARBORIZATION_DIRECTION_NOT_DEFINED = "NOT_DEFINED";
ARBORIZATION_DIRECTION_MIXED = "MIXED";
ARBORIZATION_DIRECTION_INPUT = "INPUT";
ARBORIZATION_DIRECTION_OUTPUT = "OUTPUT";
validEnums_ARBORIZATION_DIRECTION = [
IBdb.ARBORIZATION_DIRECTION_NOT_DEFINED
IBdb.ARBORIZATION_DIRECTION_MIXED
IBdb.ARBORIZATION_DIRECTION_INPUT
IBdb.ARBORIZATION_DIRECTION_OUTPUT
]
BRAINSTRUCTURE_TYPE_SUBREGION = "subregion"
BRAINSTRUCTURE_TYPE_SUPERCATEGORY = "supercategory"
BRAINSTRUCTURE_TYPE_NEUROPIL = "neuropil"
validEnums_BRAINSTRUCTURE_TYPE = [
IBdb.BRAINSTRUCTURE_TYPE_SUBREGION
IBdb.BRAINSTRUCTURE_TYPE_SUPERCATEGORY
IBdb.BRAINSTRUCTURE_TYPE_NEUROPIL
]
%%
% Date format for date specifications.
dateFormatSpec = "yyyy-MM-dd" % 2020-01-30
end
properties (GetAccess = protected)
dbUsername % Login credentials: user name
dbPassword % Login credentials: password
end
methods
%% Constructor
function self = IBdb(tokenAuthStr_or_filename)
arguments
tokenAuthStr_or_filename (1,1) string = ""
end
self.hasPy = IBdb.checkForPython();
if nargin > 0 && ~isempty(tokenAuthStr_or_filename)
if isfile(tokenAuthStr_or_filename)
self.credentialsFilename = tokenAuthStr_or_filename;
self.token_create;
else
self.tokenAuth = tokenAuthStr_or_filename;
end
else
self.token_create();
end
end
%% api communication wrappers for http requests
function [resp, respPy] = request(self, method, url, key, value)
%request State an HTTP request.
% This is an abstract wrapper for different request functions. Which one is
% used depends on whether Python is available and the METHOD. Developer's
% note: Use this function in specific request functions.
%
% [resp, respPy] = obj.request(method, url, key1, value1, keyN, valueN);
%
% Input:
%
% method -- Request method; one out of ["post","get","put","patch","delete"]
% Scalar string
%
% url -- Request URL
% Scalar string
% This URL is appended to the API's URL
%
% key, value -- Request parameter key/value pairs
%
%
% Output:
%
% resp -- Server response
% struct
% May be empty if the server's response is empty.
%
% respPy -- Server response as retrieved from Python's REQUESTS package
% struct
% May be empty if the server's response is empty. Is always empty if Python is
% not installed. This is useful for debugging.
%
arguments
self
method (1,1) string ...
{mustBeMember(method, ["post","get","put","patch","delete"])}
url (1,1) string
end
arguments (Repeating)
key
value
end
% Compose parameters
query = [key; value];
query = query(:);
if self.hasPy
[resp, respPy] = self.pyRequest(method, url, query{:});
else
respPy = [];
if method == "get"
resp = self.webreadApi(url, self.webopts, query{:});
else
opts = self.webopts;
opts.RequestMethod = method;
resp = self.webwriteApi(url, opts, query{:});
end
end
end
function resp = webreadApi(self, url, options, key, value)
%webreadApi Wrapper for WEBREAD
%
%
% resp = obj.webreadApi(url, options, key, value)
arguments
self
url (1,1) string
options (1,1) weboptions = self.webopts
end
arguments (Repeating)
key
value
end
% Pack into array (cell) with alternating name and value input.
query = [key; value];
query = query(:);
resp = webread(composeUrl(self.api, url), query{:}, options);
end
function resp = webwriteApi(self, url, options, key, value)
%webwriteApi Wrapper for WEBWRITE
%
%
% resp = obj.webwriteApi(url, options, key, value)
arguments
self
url (1,1) string
options (1,1) weboptions = self.webopts
end
arguments (Repeating)
key
value
end
query = [key; value];
query = query(:);
resp = webwrite(composeUrl(self.api, url), query{:}, options);
end
function [resp, respPy] = pyRequest(self, method, url, key, value)
%pyRequest Uses Python's REQUESTS package to send API requests.
% This is advantageous compared to WEBREAD and WEBWRITE because the server
% response is more detailed and the requests are easier to debug. The
% tokenAuth string is taken from the WEBOPTS property for authentication.
% "file" and "files" are special keys whose values are expected to be a file
% name (incl. path). If provided, the specified file is uploaded.
%
% resp = obj.pyRequest(method, url, key1, value1, keyN, valueN)
%
% Example:
%
% resp = obj.pyRequest('get', 'neuron/123');
arguments
self
method (1,1) string ...
{mustBeMember(method, ["post","get","put","patch","delete"])}
url (1,1) string
end
arguments (Repeating)
key (1,1) string
value
end
url = append(self.api, url);
% Make doubles that represent integers actual integers. Else, the request may
% fail because 42.0 instead of 42 is passed by Python. This is rather
% UNPLEASANT. Doing the integer check like this is advised by MATLAB (doc
% isinteger).
for iV = 1:numel(value)
v = value{iV};
if isnumeric(v) && all(round(v) == v)
value{iV} = int64(v);
end
end
% Catch file upload parameter
uploadFileKeyTFMat = lower(string(key)) == ["file"; "files"];
% -> returns a logical matrix where the rows are the upload parameter words
% that are matched and the columns are the keys. Thus, if there is a 1, the
% key with this column index is the "file"/"files" key.
uploadFileKeyTF = any(uploadFileKeyTFMat, 1);
assert(nnz(uploadFileKeyTF) <= 1, "IBDB:pyRequest:MultipleFileKeysProvided", ...
"For file upload, specify either ""file"" or ""files"", not both.");
uploadFileTF = any(uploadFileKeyTF);
if uploadFileTF
fullFileName = string(value(uploadFileKeyTF));
% Remove from query
key(uploadFileKeyTF) = [];
value(uploadFileKeyTF) = [];
assert(isscalar(fullFileName), "Upload of multiple files not implemented.");
% Probably just implement a loop for the py.dict?
[~, fn, ext] = fileparts(fullFileName);
fnExt = append(fn, ext);
files = py.dict(...
pyargs('file', {fnExt, py.open(fullFileName, 'rb')} ));
else
files = "";
end
% Compose query parameters
query = [key; value];
query = query(:);
if ~isempty(query)
payload = py.dict(pyargs(query{:}));
else
payload = "";
end
% Get authentication token from WEBOPTS header
if ~isempty(self.webopts.HeaderFields)
headers = py.dict(pyargs(self.webopts.HeaderFields{:}));
else
headers = "";
end
switch method
case "get"
payloadArgname = 'params'; % For queries
otherwise
payloadArgname = 'data';
end
respPy = py.requests.request(method, url, ...
pyargs('headers', headers, payloadArgname, payload, 'files', files));
% Throw exception if the request was unsuccesful
try
respPy.raise_for_status;
catch ME
% Add details from the response
causeME = MException(...
"IBDB:pyRequest:HTTPError", ...
string(respPy.text));
ME = addCause(ME, causeME);
ME.rethrow;
end
if py.len(respPy.content) > 0
% Convert response data
jsonTxt = string(respPy.text);
resp = jsondecode(jsonTxt);
else
resp = [];
end
end
%%
function [n, p] = getLoginCredentials(self)
%getLoginCredentials Handles getting data base login credentials.
% First asks for a file that stores the credentials. If none provided, the
% user is asked to type in the credentials. If aborted, no login is attempted.
% remember directory
persistent lastDir
if isempty(lastDir)
lastDir = '*.*'; end
if isfile(self.credentialsFilename)
[n,p] = IBdb.readCredentialsFile(self.credentialsFilename);
else
disp("Choose a text file containing user credentials in the form " + ...
"'username,password' (without quotes, single line).");
[fn,fp] = uigetfile(lastDir, 'MultiSelect', 'off');
if ischar(fn)
self.credentialsFilename = fullfile(fp, fn);
[n,p] = IBdb.readCredentialsFile(self.credentialsFilename);
lastDir = fullfile(p, '*.*');
else % aborted
[n,p] = IBdb.readCredentialsUserInput;
end
end
end
function token_create(self)
%token_create Retrieves the tokenAuth string using the data base login
%credentials.
[n,p] = self.getLoginCredentials;
if n == ""
warning("IBDB:token_create:NoCredentialsProvided", ...
"No token was requested from the database because no user " + ...
"credentials were provided.");
else
response = webwrite(...
composeUrl(self.api, self.TOKEN), ...
"username", n, ...
"password", p);
self.tokenAuth = response.token;
self.tokenTimeStamp = datetime(response.created, ...
'InputFormat', 'yyyy-MM-dd''T''HH:mm:ss.S''Z');
end
end
function set.tokenAuth(self, token)
if ~startsWith(token, "Token")
warning('IBDB:setTokenAuth:MissingPrefix', ...
"The tokenAuth string should be starting with ""Token"".")
end
self.tokenAuth = token;
% Pack token in the header of the WEBOPTIONS that is used for requests
self.webopts.HeaderFields = ['Authorization', self.tokenAuth];
end
%% Request functions
function [resp, respPy] = neuron_get(self, id)
id = IBdb.validate_id(id);
[resp, respPy] = self.request('get', composeUrl(self.NEURON, id));
end
function [resp, respPy] = neuron_delete(self, neuron_id)
neuron_id = IBdb.validate_id(neuron_id);
[resp, respPy] = self.request('delete', ...
composeUrl(IBdb.NEURON, neuron_id));
end
function [resp, respPy] = neuron_post(self, NameValue)
arguments
self
NameValue.name (1,1) string
NameValue.short_name (1,1) string
NameValue.public {IBdb.mustBeEmptyOrLogical}
NameValue.species {IBdb.mustBeEmpytOrScalarInteger} = self.default_species
NameValue.archived {IBdb.mustBeEmptyOrLogical}
NameValue.archived_notes string {IBdb.mustBeEmptyOrScalarText}
NameValue.hemisphere string {IBdb.mustBeEmptyOrScalarText}
NameValue.reconstruction_creator string {IBdb.mustBeEmptyOrScalarText} = ...
self.default_reconstructionCreator
NameValue.sex string {IBdb.mustBeEmptyOrScalarText} = IBdb.SEX_UNKNOWN
NameValue.group_head string {IBdb.mustBeEmptyOrScalarText} ...
= self.default_groupHead
NameValue.experimenter string {IBdb.mustBeEmptyOrScalarText}...
= self.default_experimenter
NameValue.super_type {IBdb.mustBeEmpytOrScalarInteger}
NameValue.neuron_family {IBdb.mustBeEmpytOrScalarInteger}
NameValue.neuron_class {IBdb.mustBeEmpytOrScalarInteger}
end
NameValue.sex = IBdb.validate_SEX(NameValue.sex);
if isfield(NameValue, 'hemisphere')
NameValue.hemisphere = IBdb.validate_HEMISPHERE(NameValue.hemisphere);
end
query = namedargs2cell(NameValue);
[resp, respPy] = self.request("post", composeUrl(IBdb.NEURON), query{:});
end
function [resp, respPy] = neuron_patch(self, neuron_id, NameValue)
arguments
self
neuron_id
NameValue.name string {IBdb.mustBeEmptyOrScalarText}
NameValue.short_name string {IBdb.mustBeEmptyOrScalarText}
NameValue.sex string {IBdb.mustBeEmptyOrScalarText}
NameValue.reconstruction_creator string {IBdb.mustBeEmptyOrScalarText}
NameValue.group_head string {IBdb.mustBeEmptyOrScalarText}
NameValue.experimenter string {IBdb.mustBeEmptyOrScalarText}
NameValue.public {IBdb.mustBeEmptyOrLogical}
NameValue.hemisphere string {IBdb.mustBeEmptyOrScalarText}
NameValue.species {IBdb.mustBeEmpytOrScalarInteger}
NameValue.super_type {IBdb.mustBeEmpytOrScalarInteger}
NameValue.neuron_family {IBdb.mustBeEmpytOrScalarInteger}
NameValue.neuron_class {IBdb.mustBeEmpytOrScalarInteger}
end
neuron_id = IBdb.validate_id(neuron_id);
if isfield(NameValue, 'sex')
NameValue.sex = IBdb.validate_SEX(NameValue.sex);
end
if isfield(NameValue, 'hemisphere')
NameValue.hemisphere = IBdb.validate_HEMISPHERE(NameValue.hemisphere);
end
query = namedargs2cell(NameValue);
[resp, respPy] = self.request('patch', ...
composeUrl(IBdb.NEURON, neuron_id), query{:});
end
function [resp, respPy] = experiment_post(self, neuron_id, NameValue)
arguments
self
neuron_id
NameValue.description string {IBdb.mustBeEmptyOrScalarText}
NameValue.experimenter ...
string {IBdb.mustBeEmptyOrScalarText} = self.default_experimenter
NameValue.date string {IBdb.mustBeEmptyOrScalarText}
NameValue.comments string {IBdb.mustBeEmptyOrScalarText}
NameValue.category {IBdb.mustBeEmpytOrScalarInteger}
NameValue.user_defined_id string {IBdb.mustBeEmptyOrScalarText}
end
neuron_id = self.validate_id(neuron_id);
if isfield(NameValue, 'category')
NameValue.category = ...
IBdb.validate_experimentCategory(NameValue.category);
end
postArgs = namedargs2cell(NameValue);
[resp, respPy] = self.request("post", ...
composeUrl(IBdb.EXPERIMENT, IBdb.NEURON, neuron_id), ...
postArgs{:});
end
function [resp, respPy] = neuron_classification_get(self, classification_type)
%neuron_classification_get List all entries in the data base of the specified
%classification type.
%
arguments
self
classification_type (1,1) string ...
{mustBeMember(classification_type, ["class","family","supertype"])}
end
[resp, respPy] = self.request('get', ...
composeUrl(IBdb.NEURON, classification_type));
end
function [resp, respPy] = neuron_classification_post(self, classification_type, value)
arguments
self
classification_type (1,1) string ...
{mustBeMember(classification_type, ["class","family","supertype"])}
value (1,1) string
end
[resp, respPy] = self.request('post', ...
composeUrl(IBdb.NEURON, classification_type), ...
"value", value);
end
function [resp, respPy] = neuron_classification_delete(self, classification_type, id)
arguments
self
classification_type (1,1) string ...
{mustBeMember(classification_type, ["class","family","supertype"])}
id
end
id = IBdb.validate_id(id);
[resp, respPy] = self.request('delete', ...
composeUrl(IBdb.NEURON, classification_type, id));
end
function id = neuron_classification_get_id(self, classification_type, value, createIfMissing)
%neuron_classification_get_id Returns the ID of a specific classification
%type. The entry is matched case insensitively with the specified value.
%
% id = obj.neuron_classification_get_id(classification_type, value)
% id = obj.neuron_classification_get_id(classification_type, value, createIfMissing)
%
% Input:
% classification_type -- One of ["class","family","supertype"]
% Scalar string
%
% value -- The value of the entry
% Scalar string
%
% createIfMissing (optional) -- Add entry with this name if not found
% false (default) | true
% If the specified entry is not found in the database, and this parameter
% is set to TRUE, the entry is created and the new entry's ID is returned.
%
% Output:
% id -- Entry ID
% Scalar double
% If no entry with the specified value is found and createIfMissing is FALSE,
% ID is empty.
%
% Example:
% id = obj.neuron_classification_get_id("supertype", "delta7")
%
arguments
self
classification_type (1,1) string ...
{mustBeMember(classification_type, ["class","family","supertype"])}
value (1,1) string
createIfMissing (1,1) logical = false
end
entries = self.request('get', ...
composeUrl(IBdb.NEURON, classification_type));
matchTF = strcmpi(string({entries.value}), value);
if any(matchTF)
id = entries(matchTF).id;
elseif createIfMissing
resp = self.neuron_classification_post(...
classification_type, value);
id = resp.id;
logMsg("New neuron %s created: %s (ID %i)", ...
classification_type, value, id);
else
id = [];
end
end
function [resp, respPy] = publication_post(self, type, id, doi)
%publication_post Add a publication (via DOI) to an experiment or neuron.
arguments
self
type (1,1) string {mustBeMember(type, ["experiment", "neuron"])}
id
doi (1,1) string
end
id = self.validate_id(id);
[resp, respPy] = self.request("post", ...
composeUrl(type, id, IBdb.PUBLICATION), ...
'doi', doi);
end
function [resp, respPy] = publication_delete(self, type, type_id, publication_id)
%publication_delete Remove a publication entry of an experiment or neuron. The
%publication is identified by it's ID, which can be retrieved from the
%experiment's/neuron's metadata.
%
% [resp, respPy] = publication_delete(self, type, doi_id)
arguments
self
type (1,1) string {mustBeMember(type, ["experiment", "neuron"])}
type_id
publication_id (1,1) {mustBeInteger}
end
type_id = self.validate_id(type_id);
[resp, respPy] = self.request("delete", ...
composeUrl(type, type_id, IBdb.PUBLICATION, publication_id) );
end
function [resp, respPy] = experiment_publication_post(self, experiment_id, doi)
[resp, respPy] = self.publication_post('experiment', experiment_id, doi);
end
function [resp, respPy] = experiment_publication_delete(self, experiment_id, doi_id)
[resp, respPy] = self.publication_delete('experiment', experiment_id, doi_id);
end
function [resp, respPy] = neuron_publication_post(self, neuron_id, doi)
[resp, respPy] = self.publication_post('neuron', neuron_id, doi);
end
function [resp, respPy] = neuron_publication_delete(self, neuron_id, doi_id)
[resp, respPy] = self.publication_delete('neuron', neuron_id, doi_id);
end
function [resp, respPy] = neuron_arborization_region_get(self, neuron_id)
neuron_id = IBdb.validate_id(neuron_id);
[resp, respPy] = self.request('get', ...
composeUrl(IBdb.NEURON, neuron_id, IBdb.ARBORIZATION_REGIONS));
end
function [resp, respPy] = neuron_morphology_get(self, id)
id = IBdb.validate_id(id);
[resp, respPy] = self.request('get', ...
composeUrl(IBdb.NEURON, IBdb.MORPHOLOGY, id) );
end
function [resp, respPy] = neuron_morphology_post(self, neuron_id, NameValue)
arguments
self
neuron_id
NameValue.soma_location string {IBdb.mustBeEmptyOrScalarText}
NameValue.fiber_bundles double {mustBeInteger}
NameValue.description string {IBdb.mustBeEmptyOrScalarText}
end
neuron_id = self.validate_id(neuron_id);
NameValue.neuron = neuron_id;
query = namedargs2cell(NameValue);
[resp, respPy] = self.request('post', ...
composeUrl(IBdb.NEURON, IBdb.MORPHOLOGY), ...
query{:});
end
function [resp, respPy] = neuron_morphology_patch(self, neuron_id, NameValue)
arguments
self