Merge pull request #3972 from solgenomics/topic/nirs_brapi_setup
[sgn.git] / lib / SGN / Controller / AJAX / BrAPI.pm
blob0fd27cc8886bef1218e11a12a109b24a59649cd7
2 package SGN::Controller::AJAX::BrAPI;
4 use Moose;
5 use JSON::Any;
6 use Data::Dumper;
8 use POSIX;
9 use CXGN::BreedersToolbox::Projects;
10 use CXGN::Trial;
11 use CXGN::Trial::TrialLayout;
12 use CXGN::Stock;
13 use CXGN::Login;
14 use CXGN::Trial::TrialCreate;
15 use CXGN::Trial::Search;
16 use CXGN::Location::LocationLookup;
17 use JSON;
18 use JSON qw( decode_json );
19 use Data::Dumper;
20 use Digest::MD5;
21 use Try::Tiny;
22 use File::Slurp qw | read_file |;
23 use Spreadsheet::WriteExcel;
24 use Time::Piece;
26 use CXGN::BrAPI;
28 BEGIN { extends 'Catalyst::Controller::REST' };
30 __PACKAGE__->config(
31 # Leaving default Content-Type to not break everything. If data is passed that is not parsable as json, and the
32 # data type is not handled in the map below, we get a catalyst error with a 200 response which is not ideal.
33 default => 'application/json',
34 stash_key => 'rest',
35 map => { 'application/json' => 'JSON',
36 # would be nice if we could do image/* instead of explicitly listing each type
37 # also should see if a single list of image types can be used for this and for _get_extension in Images.pm
38 'image/_*' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
39 'image/jpeg' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
40 'image/png' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
41 'image/gif' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
42 'image/svg+xml' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
43 'application/pdf' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
44 'application/postscript' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
48 has 'brapi_module' => (
49 isa => 'CXGN::BrAPI',
50 is => 'rw',
53 has 'bcs_schema' => (
54 isa => 'Bio::Chado::Schema',
55 is => 'rw',
58 my $DEFAULT_PAGE_SIZE=10;
60 # don't do anything, let catalyst handle putting body into a temp file
61 sub deserialize_image {
62 my ( $self, $data, $c ) = @_;
63 # want $c->request->data to be undefined so that parsing in brapi sub skips it
64 return undef;
67 # have to serialize the json because using the callbacks in the config map
68 sub serialize_image {
69 my ( $self, $data, $c ) = @_;
70 my $json = JSON->new->allow_nonref;
71 $json->allow_tags;
72 $json->allow_blessed;
73 $json->convert_blessed;
74 my $json_text = $json->encode( $c->stash->{rest} );
76 $c->response->content_type('application/json');
77 return $json_text;
80 sub brapi : Chained('/') PathPart('brapi') CaptureArgs(1) {
81 my $self = shift;
82 my $c = shift;
83 my $version = shift;
84 my @status;
86 my $page = $c->req->param("page") || 0;
87 my $page_size = $c->req->param("pageSize") || $DEFAULT_PAGE_SIZE;
88 my $authorization_token = $c->req->headers->header("Authorization");
89 my $bearer_token = undef;
91 if (defined $authorization_token) {
92 my @bearer = split(/\s/, $authorization_token);
93 if (scalar @bearer == 2) {
94 if ($bearer[0] eq "Bearer") {
95 $bearer_token = $bearer[1];
100 my $session_token = $c->req->headers->header("access_token") || $bearer_token;
102 if (defined $c->request->data){
103 my $data_type = ref $c->request->data;
104 my $current_page = $c->request->data->{"page"} if ($data_type ne 'ARRAY');
105 my $current_page_size = $c->request->data->{"pageSize"} if ($data_type ne 'ARRAY');
106 my $current_sesion_token = $c->request->data->{"access_token"} if ($data_type ne 'ARRAY');
107 $page = $current_page || $page || 0;
108 $page_size = $current_page_size || $page_size || $DEFAULT_PAGE_SIZE;
109 $session_token = $current_sesion_token|| $session_token;
111 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
112 my $metadata_schema = $c->dbic_schema("CXGN::Metadata::Schema");
113 my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema");
114 my $people_schema = $c->dbic_schema("CXGN::People::Schema");
115 push @status, { 'INFO' => "BrAPI base call found with page=$page, pageSize=$page_size" };
117 my $brapi = CXGN::BrAPI->new({
118 version => $version,
119 brapi_module_inst => {
120 context => $c,
121 bcs_schema => $bcs_schema,
122 metadata_schema => $metadata_schema,
123 phenome_schema => $phenome_schema,
124 people_schema => $people_schema,
125 page_size => $page_size,
126 page => $page,
127 status => \@status
130 $self->brapi_module($brapi);
131 $self->bcs_schema($bcs_schema);
133 $c->response->headers->header( "Access-Control-Allow-Origin" => '*' );
134 $c->response->headers->header( "Access-Control-Allow-Methods" => "POST, GET, PUT, DELETE" );
135 $c->response->headers->header( 'Access-Control-Allow-Headers' => 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization');
136 $c->stash->{session_token} = $session_token;
138 if (defined $c->request->data){
139 # All POST requests accept for search methods require a json array body
140 if ($c->request->method eq "POST" && index($c->request->env->{REQUEST_URI}, "search") == -1){
141 if (ref $c->request->data ne 'ARRAY') {
142 my $response = CXGN::BrAPI::JSONResponse->return_error($c->stash->{status}, 'JSON array body required', 400);
143 _standard_response_construction($c, $response);
145 $c->stash->{clean_inputs} = _clean_inputs($c->req->params,$c->request->data);
146 } elsif ($c->request->method eq "PUT") {
147 if (ref $c->request->data eq 'ARRAY') {
148 my $response = CXGN::BrAPI::JSONResponse->return_error($c->stash->{status}, 'JSON hash body required', 400);
149 _standard_response_construction($c, $response);
151 $c->stash->{clean_inputs} = $c->request->data;
152 } else {
153 $c->stash->{clean_inputs} = $c->request->data;
156 else {
157 $c->stash->{clean_inputs} = _clean_inputs($c->req->params);
161 #useful because javascript can pass 'undef' as an empty value, and also standardizes all inputs as arrayrefs
162 sub _clean_inputs {
163 no warnings 'uninitialized';
164 my $params = shift;
165 my $alldata = shift;
167 if($alldata){
168 my %data = ref $alldata eq 'ARRAY' ? map { $_ => $_} @{$alldata} : %{$alldata};
169 %$params = $params ? (%data, %$params) : %data;
172 foreach (keys %$params){
173 my $values = $params->{$_};
174 my $ret_val;
175 if (ref \$values eq 'SCALAR' || ref $values eq 'ARRAY'){
177 if (ref \$values eq 'SCALAR') {
178 push @$ret_val, $values;
179 } elsif (ref $values eq 'ARRAY'){
180 $ret_val = $values;
183 @$ret_val = grep {$_ ne undef} @$ret_val;
184 @$ret_val = grep {$_ ne ''} @$ret_val;
185 $_ =~ s/\[\]$//; #ajax POST with arrays adds [] to the end of the name e.g. germplasmName[]. since all inputs are arrays now we can remove the [].
186 $params->{$_} = $ret_val;
188 elsif (ref $values eq 'HASH') {
189 $params->{$_} = $values;
191 else {
192 die "Input $_ is not a scalar, arrayref, or a single level hash\n";
196 return $params;
199 sub _validate_request {
200 my $c = shift;
201 my $data_type = shift;
202 my $data = shift;
203 my $required_fields = shift;
204 my $required_field_prefix = shift;
206 if ($required_fields) {
207 # Validate each array element
208 if ($data_type eq 'ARRAY') {
209 foreach my $object (values %{$data}) {
210 # Ignore the query params if they were passed in. Their included in the body
211 if (ref($object) eq 'HASH') {
212 _validate_request($c, 'HASH', $object, $required_fields);
217 # Check all of our fields
218 foreach my $required_field (@{$required_fields}) {
219 # Check if the required field has another level or not
220 if (ref($required_field) eq 'HASH') {
221 # Check the field keys and recurse
222 foreach my $sub_req_field (keys %{$required_field}) {
223 if ($data_type eq 'HASH') {
224 if (!$data->{$sub_req_field}) {
225 _missing_field_response($c, $sub_req_field, $required_field_prefix);
226 } else {
227 my $sub_data = $data->{$sub_req_field};
228 _validate_request($c, 'HASH', $sub_data, $required_field->{$sub_req_field},
229 $required_field_prefix ? sprintf("%s.%s", $required_field_prefix, $sub_req_field): $sub_req_field);
233 next;
236 if ($data_type eq 'HASH') {
237 if (!$data->{$required_field}) {
238 _missing_field_response($c, $required_field, $required_field_prefix);
245 sub _missing_field_response {
246 my $c = shift;
247 my $field_name = shift;
248 my $prefix = shift;
249 my $response = CXGN::BrAPI::JSONResponse->return_error($c->stash->{status}, $prefix ? sprintf("%s.%s required", $prefix, $field_name) : sprintf("%s required", $field_name), 400);
250 _standard_response_construction($c, $response);
253 sub _authenticate_user {
254 my $c = shift;
255 my $force_authenticate = shift;
256 my $status = $c->stash->{status};
257 my $user_id;
258 my $user_type;
259 my $user_pref;
260 my $expired;
261 my $wildcard = 'any';
263 my %server_permission;
264 my $rc = eval{
265 my $server_permission = $c->config->{"brapi_" . $c->request->method};
266 my @server_permission = split ',', $server_permission;
267 %server_permission = map { $_ => 1 } @server_permission;
268 1; };
270 if(!$rc && !%server_permission){
271 $server_permission{$wildcard} = 1;
274 # If our brapi config is set to authenticate or the controller calling this asks for forcing of
275 # authentication or serverinfo call method request auth, we authenticate.
276 if ($c->config->{brapi_require_login} == 1 || $force_authenticate || !exists($server_permission{$wildcard})){
277 ($user_id, $user_type, $user_pref, $expired) = CXGN::Login->new($c->dbc->dbh)->query_from_cookie($c->stash->{session_token});
278 #print STDERR $user_id." : ".$user_type." : ".$expired;
280 if (!$user_id || $expired || !$user_type || (!exists($server_permission{$user_type}) && !exists($server_permission{$wildcard}))) {
281 my $brapi_package_result = CXGN::BrAPI::JSONResponse->return_error($status, 'You must login and have permission to access this BrAPI call.');
283 _standard_response_construction($c, $brapi_package_result, 401);
287 return (1, $user_id, $user_type, $user_pref, $expired);
290 sub _standard_response_construction {
291 my $c = shift;
292 my $brapi_package_result = shift;
293 my $return_status = shift;
294 my $status = $brapi_package_result->{status};
295 my $pagination = $brapi_package_result->{pagination};
296 my $result = $brapi_package_result->{result};
297 my $datafiles = $brapi_package_result->{datafiles};
299 # some older brapi stuff uses parameter, could refactor at some point
300 if (!$return_status) { $return_status = $brapi_package_result->{http_code} };
302 my %metadata = (pagination=>$pagination, status=>$status, datafiles=>$datafiles);
303 my %response = (metadata=>\%metadata, result=>$result);
304 $c->stash->{rest} = \%response;
305 $c->response->status((!$return_status) ? 200 : $return_status);
306 $c->detach;
309 =head2 /brapi/v1/token
311 Usage: For logging a user in and loggin a user out through the API
312 Desc:
314 For Logging In
315 POST Request:
317 "grant_type" : "password", //(optional, text, `password`) ... The grant type, only allowed value is password, but can be ignored
318 "username" : "user38", // (required, text, `thepoweruser`) ... The username
319 "password" : "secretpw", // (optional, text, `mylittlesecret`) ... The password
320 "client_id" : "blabla" // (optional, text, `blabla`) ... The client id, currently ignored.
323 POST Response:
325 "metadata": {
326 "pagination": {},
327 "status": {},
328 "datafiles": []
330 "userDisplayName": "John Smith",
331 "access_token": "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4",
332 "expires_in": "The lifetime in seconds of the access token"
335 For Logging out
336 DELETE Request:
339 "access_token" : "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4" // (optional, text, `R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4`) ... The user access token. Default: current user token.
342 DELETE Response:
344 "metadata": {
345 "pagination" : {},
346 "status" : { "message" : "User has been logged out successfully."},
347 "datafiles": []
349 "result" : {}
352 =cut
354 sub authenticate_token : Chained('brapi') PathPart('token') Args(0) : ActionClass('REST') { }
356 sub authenticate_token_DELETE {
357 my $self = shift;
358 my $c = shift;
359 my $brapi = $self->brapi_module;
360 my $brapi_module = $brapi->brapi_wrapper('Authentication');
361 my $brapi_package_result = $brapi_module->logout();
362 _standard_response_construction($c, $brapi_package_result);
365 sub authenticate_token_GET {
366 my $self = shift;
367 my $c = shift;
368 process_authenticate_token($self,$c);
371 sub authenticate_token_POST {
372 my $self = shift;
373 my $c = shift;
374 process_authenticate_token($self,$c);
377 sub process_authenticate_token {
378 my $self = shift;
379 my $c = shift;
380 my $clean_inputs = $c->stash->{clean_inputs};
381 my $brapi = $self->brapi_module;
382 my $brapi_module = $brapi->brapi_wrapper('Authentication');
383 my $brapi_package_result = $brapi_module->login(
384 $clean_inputs->{grant_type}->[0],
385 $clean_inputs->{password}->[0],
386 $clean_inputs->{username}->[0],
387 $clean_inputs->{client_id}->[0],
390 my $status = $brapi_package_result->{status};
391 my $pagination = $brapi_package_result->{pagination};
392 my $result = $brapi_package_result->{result};
393 my $datafiles = $brapi_package_result->{datafiles};
395 my %metadata = (pagination=>$pagination, status=>$status, datafiles=>$datafiles);
396 my %response = (metadata=>\%metadata, access_token=>$result->{access_token}, userDisplayName=>$result->{userDisplayName}, expires_in=>$CXGN::Login::LOGIN_TIMEOUT);
397 $c->stash->{rest} = \%response;
398 $c->detach();
401 =head2 /brapi/v1/calls
403 Usage: For determining which calls have been implemented and with which datafile types and methods
404 Desc:
406 GET Request:
408 GET Response:
410 "metadata": {
411 "pagination": {
412 "pageSize": 3,
413 "currentPage": 0,
414 "totalCount": 3,
415 "totalPages": 1
417 "status": {},
418 "datafiles": []
420 "result": {
421 "data": [
423 "call": "allelematrix",
424 "datatypes": [
425 "json",
426 "tsv"
428 "methods": [
429 "GET",
430 "POST"
434 "call": "germplasm/id/mcpd",
435 "datatypes": [
436 "json"
438 "methods": [
439 "GET"
443 "call": "doesntexistyet",
444 "datatypes": [
445 "png",
446 "jpg"
448 "methods": [
449 "GET"
456 =cut
458 sub calls : Chained('brapi') PathPart('calls') Args(0) : ActionClass('REST') { }
460 sub calls_GET {
461 my $self = shift;
462 my $c = shift;
463 my ($auth) = _authenticate_user($c);
464 my $clean_inputs = $c->stash->{clean_inputs};
465 my $brapi = $self->brapi_module;
466 my $brapi_module = $brapi->brapi_wrapper('Calls');
467 my $brapi_package_result = $brapi_module->search(
468 $clean_inputs
470 _standard_response_construction($c, $brapi_package_result);
473 =head2 /brapi/v2/serverinfo
475 Usage: For determining which endpoints have been implemented and with which datafile types and methods
476 Desc:
478 GET Request:
480 GET Response:
482 "metadata": {
483 "pagination": {
484 "pageSize": 3,
485 "currentPage": 0,
486 "totalCount": 3,
487 "totalPages": 1
489 "status": {},
490 "datafiles": []
492 "result": {
493 "data": [
495 "call": "allelematrix",
496 "datatypes": [
497 "json",
498 "tsv"
500 "methods": [
501 "GET",
502 "POST"
506 "call": "germplasm/id/mcpd",
507 "datatypes": [
508 "json"
510 "methods": [
511 "GET"
515 "call": "doesntexistyet",
516 "datatypes": [
517 "png",
518 "jpg"
520 "methods": [
521 "GET"
528 =cut
530 sub serverinfo : Chained('brapi') PathPart('serverinfo') Args(0) : ActionClass('REST') { }
532 sub serverinfo_GET {
533 my $self = shift;
534 my $c = shift;
535 my ($auth) = _authenticate_user($c);
536 my $clean_inputs = $c->stash->{clean_inputs};
537 my $brapi = $self->brapi_module;
538 my $brapi_module = $brapi->brapi_wrapper('ServerInfo');
539 my $brapi_package_result = $brapi_module->search($c,$clean_inputs);
540 _standard_response_construction($c, $brapi_package_result);
543 sub crops : Chained('brapi') PathPart('crops') Args(0) : ActionClass('REST') { }
545 sub crops_GET {
546 my $self = shift;
547 my $c = shift;
548 my $supported_crop = $c->config->{'supportedCrop'};
549 my $brapi = $self->brapi_module;
550 my $brapi_module = $brapi->brapi_wrapper('Crops');
551 my $brapi_package_result = $brapi_module->crops($supported_crop);
552 _standard_response_construction($c, $brapi_package_result);
555 sub commoncropnames : Chained('brapi') PathPart('commoncropnames') Args(0) : ActionClass('REST') { }
557 sub commoncropnames_GET {
558 my $self = shift;
559 my $c = shift;
560 my $supported_crop = $c->config->{'supportedCrop'};
561 my $brapi = $self->brapi_module;
562 my $brapi_module = $brapi->brapi_wrapper('CommonCropNames');
563 my $brapi_package_result = $brapi_module->crops($supported_crop);
564 _standard_response_construction($c, $brapi_package_result);
567 sub observation_levels : Chained('brapi') PathPart('observationlevels') Args(0) : ActionClass('REST') { }
569 sub observation_levels_GET {
570 my $self = shift;
571 my $c = shift;
572 my $brapi = $self->brapi_module;
573 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
574 my $brapi_package_result = $brapi_module->observation_levels();
575 _standard_response_construction($c, $brapi_package_result);
578 sub seasons : Chained('brapi') PathPart('seasons') Args(0) : ActionClass('REST') { }
580 sub seasons_POST {
581 my $self = shift;
582 my $c = shift;
583 seasons_process($self, $c);
586 sub seasons_GET {
587 my $self = shift;
588 my $c = shift;
589 seasons_process($self, $c);
592 sub seasons_process {
593 my $self = shift;
594 my $c = shift;
595 my ($auth) = _authenticate_user($c);
596 my $clean_inputs = $c->stash->{clean_inputs};
597 my $brapi = $self->brapi_module;
598 my $brapi_module = $brapi->brapi_wrapper('Studies');
599 my $brapi_package_result = $brapi_module->seasons(
600 $clean_inputs->{year}->[0],
602 _standard_response_construction($c, $brapi_package_result);
605 sub season_single : Chained('brapi') PathPart('seasons') CaptureArgs(1) {
606 my $self = shift;
607 my $c = shift;
608 my $id = shift;
609 $c->stash->{seasonDbId} = $id;
612 sub season_fetch : Chained('season_single') PathPart('') Args(0) : ActionClass('REST') { }
615 sub season_fetch_GET {
616 my $self = shift;
617 my $c = shift;
618 my ($auth) = _authenticate_user($c);
619 my $clean_inputs = $c->stash->{clean_inputs};
620 my $brapi = $self->brapi_module;
621 my $brapi_module = $brapi->brapi_wrapper('Seasons');
622 my $brapi_package_result = $brapi_module->detail($c->stash->{seasonDbId});
623 _standard_response_construction($c, $brapi_package_result);
626 sub season_search : Chained('brapi') PathPart('search/seasons') Args(0) : ActionClass('REST') { }
628 sub season_search_POST {
629 my $self = shift;
630 my $c = shift;
631 save_results($self,$c,$c->stash->{clean_inputs},'Seasons');
634 sub season_search_retrieve : Chained('brapi') PathPart('search/seasons') Args(1) {
635 my $self = shift;
636 my $c = shift;
637 my $search_id = shift;
638 retrieve_results($self, $c, $search_id, 'Seasons');
642 =head2 brapi/v1/studyTypes
644 Usage: To retrieve a list of programs being worked onthe various study types
645 Desc:
646 Return JSON example:
648 "metadata" : {
649 "pagination": {
650 "pageSize": 10,
651 "currentPage": 1,
652 "totalCount": 10,
653 "totalPages": 1
655 "status": []
657 "result" : {
658 "data" : [
660 "name": "Nursery",
661 "description": "Description for Nursery study type"
664 "name": "Trial",
665 "description": "Description for Nursery study type"
670 Args:
671 Side Effects:
673 =cut
675 sub study_types : Chained('brapi') PathPart('studytypes') Args(0) : ActionClass('REST') { }
677 sub study_types_POST {
678 my $self = shift;
679 my $c = shift;
680 study_types_process($self, $c);
683 sub study_types_GET {
684 my $self = shift;
685 my $c = shift;
686 study_types_process($self, $c);
689 sub study_types_process {
690 my $self = shift;
691 my $c = shift;
692 my ($auth) = _authenticate_user($c);
693 my $brapi = $self->brapi_module;
694 my $brapi_module = $brapi->brapi_wrapper('Studies');
695 my $brapi_package_result = $brapi_module->study_types();
696 _standard_response_construction($c, $brapi_package_result);
702 =head2 /brapi/v1/germplasm-search?germplasmName=&germplasmGenus=&germplasmSubTaxa=&germplasmDbId&germplasmPUI=http://data.inra.fr/accession/234Col342&germplasmSpecies=Triticum&panel=diversitypanel1&collection=none&pageSize=pageSize&page=page
704 Usage: For searching a germplasm by name. Allows for exact and wildcard match methods. http://docs.brapi.apiary.io/#germplasm
705 Desc:
707 POST Request:
710 "germplasmPUI" : "http://...", // (optional, text, `http://data.inra.fr/accession/234Col342`) ... The name or synonym of external genebank accession identifier
711 "germplasmDbId" : 986, // (optional, text, `986`) ... The name or synonym of external genebank accession identifier
712 "germplasmSpecies" : "tomato", // (optional, text, `aestivum`) ... The name or synonym of genus or species ( merge with below ?)
713 "germplasmGenus" : "Solanum lycopersicum", //(optional, text, `Triticum, Hordeum`) ... The name or synonym of genus or species
714 "germplasmName" : "XYZ1", // (optional, text, `Triticum, Hordeum`) ... The name or synonym of the accession
715 "accessionNumber" : "ITC1234" // optional
716 "pageSize" : 100, // (optional, integer, `1000`) ... The size of the pages to be returned. Default is `1000`.
717 "page": 1 (optional, integer, `10`) ... Which result page is requested
721 POST Response:
723 "metadata": {
724 "status": {},
725 "datafiles": [],
726 "pagination": {
727 "pageSize": 10,
728 "currentPage": 1,
729 "totalCount": 2,
730 "totalPages": 1
733 "result": {
734 "data":[
736 "germplasmDbId": "01BEL084609",
737 "defaultDisplayName": "Pahang",
738 "accessionNumber": "ITC0609",
739 "germplasmName": "Pahang",
740 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
741 "pedigree": "TOBA97/SW90.1057",
742 "germplasmSeedSource": "Female GID:4/Male GID:4",
743 "synonyms": [ ],
744 "commonCropName": "banana",
745 "instituteCode": "01BEL084",
746 "instituteName": "ITC",
747 "biologicalStatusOfAccessionCode": 412,
748 "countryOfOriginCode": "UNK",
749 "typeOfGermplasmStorageCode": 10,
750 "genus": "Musa",
751 "species": "acuminata",
752 "speciesAuthority": "",
753 "subtaxa": "sp malaccensis var pahang",
754 "subtaxaAuthority": "",
755 "donors":
758 "donorAccessionNumber": "",
759 "donorInstituteCode": "",
760 "germplasmPUI": ""
763 "acquisitionDate": "19470131"
769 =cut
771 sub germplasm_search_old : Chained('brapi') PathPart('germplasm-search') Args(0) : ActionClass('REST') { }
773 sub germplasm_search_old_GET {
774 my $self = shift;
775 my $c = shift;
776 my ($auth) = _authenticate_user($c);
777 my $clean_inputs = $c->stash->{clean_inputs};
778 my $brapi = $self->brapi_module;
779 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
780 my $brapi_package_result = $brapi_module->search({
781 germplasmName => $clean_inputs->{germplasmName},
782 accessionNumber => $clean_inputs->{accessionNumber},
783 germplasmGenus => $clean_inputs->{germplasmGenus},
784 germplasmSubTaxa => $clean_inputs->{germplasmSubTaxa},
785 germplasmSpecies => $clean_inputs->{germplasmSpecies},
786 germplasmDbId => $clean_inputs->{germplasmDbId},
787 germplasmPUI => $clean_inputs->{germplasmPUI},
788 matchMethod => $clean_inputs->{matchMethod},
790 _standard_response_construction($c, $brapi_package_result);
793 sub germplasm_search_old_POST {
794 my $self = shift;
795 my $c = shift;
796 # my ($auth) = _authenticate_user($c);
797 my $clean_inputs = $c->stash->{clean_inputs};
798 my $brapi = $self->brapi_module;
799 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
800 my $brapi_package_result = $brapi_module->search({
801 germplasmName => $clean_inputs->{germplasmNames},
802 accessionNumber => $clean_inputs->{accessionNumbers},
803 germplasmGenus => $clean_inputs->{germplasmGenus},
804 germplasmSubTaxa => $clean_inputs->{germplasmSubTaxa},
805 germplasmSpecies => $clean_inputs->{germplasmSpecies},
806 germplasmDbId => $clean_inputs->{germplasmDbIds},
807 germplasmPUI => $clean_inputs->{germplasmPUIs},
808 matchMethod => $clean_inputs->{matchMethod},
810 _standard_response_construction($c, $brapi_package_result);
813 sub germplasm : Chained('brapi') PathPart('germplasm') Args(0) : ActionClass('REST') { }
815 sub germplasm_GET {
816 my $self = shift;
817 my $c = shift;
818 my $auth = _authenticate_user($c);
819 my $clean_inputs = $c->stash->{clean_inputs};
820 my $brapi = $self->brapi_module;
821 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
822 my $brapi_package_result = $brapi_module->search($clean_inputs);
824 _standard_response_construction($c, $brapi_package_result);
827 sub germplasm_POST {
828 my $self = shift;
829 my $c = shift;
830 my ($auth,$user_id) = _authenticate_user($c);
831 my $clean_inputs = $c->stash->{clean_inputs};
832 my $data = $clean_inputs;
833 my @all_germplasm;
834 foreach my $germplasm (values %{$data}) {
835 push @all_germplasm, $germplasm;
837 my $brapi = $self->brapi_module;
838 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
839 my $brapi_package_result = $brapi_module->store(\@all_germplasm,$user_id,$c);
841 _standard_response_construction($c, $brapi_package_result);
844 sub germplasm_search_save : Chained('brapi') PathPart('search/germplasm') Args(0) : ActionClass('REST') { }
846 sub germplasm_search_save_POST {
847 my $self = shift;
848 my $c = shift;
849 save_results($self,$c,$c->stash->{clean_inputs},'Germplasm');
852 sub germplasm_search_retrieve : Chained('brapi') PathPart('search/germplasm') Args(1) {
853 my $self = shift;
854 my $c = shift;
855 my $search_id = shift;
856 retrieve_results($self, $c, $search_id, 'Germplasm');
859 =head2 brapi/v1/germplasm/{id}
861 Usage: To retrieve details for a single germplasm
862 Desc:
863 Return JSON example:
865 "metadata": {
866 "status": [],
867 "pagination": {}
869 "result": {
870 "germplasmDbId": "01BEL084609",
871 "defaultDisplayName": "Pahang",
872 "germplasmName": "Pahang",
873 "accessionNumber": "ITC0609",
874 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
875 "pedigree": "TOBA97/SW90.1057",
876 "seedSource": "Female GID:4/Male GID:4",
877 "synonyms": ["Pahanga","Pahange"],
880 Args:
881 Side Effects:
883 =cut
885 sub germplasm_single : Chained('brapi') PathPart('germplasm') CaptureArgs(1) {
886 my $self = shift;
887 my $c = shift;
888 my $stock_id = shift;
890 $c->stash->{stock_id} = $stock_id;
894 sub germplasm_detail : Chained('germplasm_single') PathPart('') Args(0) : ActionClass('REST') { }
896 sub germplasm_detail_GET {
897 my $self = shift;
898 my $c = shift;
899 my ($auth) = _authenticate_user($c);
900 my $clean_inputs = $c->stash->{clean_inputs};
901 my $brapi = $self->brapi_module;
902 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
903 my $brapi_package_result = $brapi_module->germplasm_detail(
904 $c->stash->{stock_id}
906 _standard_response_construction($c, $brapi_package_result);
909 sub germplasm_detail_PUT {
910 my $self = shift;
911 my $c = shift;
912 my ($auth,$user_id) = _authenticate_user($c);
913 my $clean_inputs = $c->stash->{clean_inputs};
914 my $data = $clean_inputs;
915 my @all_germplasm;
916 push @all_germplasm, $data;
917 my $brapi = $self->brapi_module;
918 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
919 my $brapi_package_result = $brapi_module->update($c->stash->{stock_id},\@all_germplasm,$user_id,$c);
921 _standard_response_construction($c, $brapi_package_result);
924 =head2 brapi/v1/germplasm/{id}/MCPD
926 MCPD CALL NO LONGER IN BRAPI SPEC
928 Usage: To retrieve multi crop passport descriptor for a single germplasm
929 Desc:
930 Return JSON example:
932 "metadata": {
933 "status": [],
934 "pagination": {}
936 "result": {
937 "germplasmDbId": "01BEL084609",
938 "defaultDisplayName": "Pahang",
939 "accessionNumber": "ITC0609",
940 "germplasmName": "Pahang",
941 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
942 "pedigree": "TOBA97/SW90.1057",
943 "germplasmSeedSource": "Female GID:4/Male GID:4",
944 "synonyms": [ ],
945 "commonCropName": "banana",
946 "instituteCode": "01BEL084",
947 "instituteName": "ITC",
948 "biologicalStatusOfAccessionCode": 412,
949 "countryOfOriginCode": "UNK",
950 "typeOfGermplasmStorageCode": 10,
951 "genus": "Musa",
952 "species": "acuminata",
953 "speciesAuthority": "",
954 "subtaxa": "sp malaccensis var pahang",
955 "subtaxaAuthority": "",
956 "donors":
959 "donorAccessionNumber": "",
960 "donorInstituteCode": "",
961 "germplasmPUI": ""
964 "acquisitionDate": "19470131"
966 Args:
967 Side Effects:
969 =cut
971 sub germplasm_mcpd : Chained('germplasm_single') PathPart('mcpd') Args(0) : ActionClass('REST') { }
973 sub germplasm_mcpd_GET {
974 my $self = shift;
975 my $c = shift;
976 my ($auth) = _authenticate_user($c);
977 my $clean_inputs = $c->stash->{clean_inputs};
978 my $brapi = $self->brapi_module;
979 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
980 my $brapi_package_result = $brapi_module->germplasm_mcpd(
981 $c->stash->{stock_id}
983 _standard_response_construction($c, $brapi_package_result);
987 #BrAPI Trials are modeled as Folders
988 sub trials_list : Chained('brapi') PathPart('trials') Args(0) : ActionClass('REST') { }
990 sub trials_list_GET {
991 my $self = shift;
992 my $c = shift;
993 trials_search_process($self, $c);
996 sub trials_list_POST {
997 my $self = shift;
998 my $c = shift;
999 my ($auth,$user_id) = _authenticate_user($c);
1000 my $clean_inputs = $c->stash->{clean_inputs};
1001 my $data = $clean_inputs;
1002 my @all_trials;
1003 foreach my $trials (values %{$data}) {
1004 push @all_trials, $trials;
1006 my $brapi = $self->brapi_module;
1007 my $brapi_module = $brapi->brapi_wrapper('Trials');
1008 my $brapi_package_result = $brapi_module->store(\@all_trials,$user_id);
1009 _standard_response_construction($c, $brapi_package_result);
1012 sub trials_search_process {
1013 my $self = shift;
1014 my $c = shift;
1015 my ($auth) = _authenticate_user($c);
1016 my $clean_inputs = $c->stash->{clean_inputs};
1017 my $brapi = $self->brapi_module;
1018 my $brapi_module = $brapi->brapi_wrapper('Trials');
1019 my $brapi_package_result = $brapi_module->search({
1020 crop => $c->config->{supportedCrop},
1021 contactDbIds => $clean_inputs->{contactDbId},
1022 searchDateRangeStart => $clean_inputs->{searchDateRangeStart},
1023 searchDateRangeEnd => $clean_inputs->{searchDateRangeEnd},
1024 trialPUIs => $clean_inputs->{trialPUI},
1025 externalReferenceIDs => $clean_inputs->{externalReferenceID},
1026 externalReferenceSources => $clean_inputs->{externalReferenceSource},
1027 active => $clean_inputs->{active},
1028 commonCropNames => $clean_inputs->{commonCropName},
1029 programDbIds => $clean_inputs->{programDbId},
1030 locationDbIds => $clean_inputs->{locationDbId},
1031 studyDbIds => $clean_inputs->{studyDbId},
1032 trialDbIds => $clean_inputs->{trialDbId},
1033 trialNames => $clean_inputs->{trialName},
1036 _standard_response_construction($c, $brapi_package_result);
1040 sub trials_single : Chained('brapi') PathPart('trials') CaptureArgs(1) {
1041 my $self = shift;
1042 my $c = shift;
1043 my $folder_id = shift;
1045 $c->stash->{trial_id} = $folder_id;
1049 sub trials_detail : Chained('trials_single') PathPart('') Args(0) : ActionClass('REST') { }
1051 sub trials_detail_PUT {
1052 my $self = shift;
1053 my $c = shift;
1054 my ($auth,$user_id) = _authenticate_user($c);
1055 my $clean_inputs = $c->stash->{clean_inputs};
1056 my $data = $clean_inputs;
1057 $data->{trialDbId} = $c->stash->{trial_id};
1058 my $brapi = $self->brapi_module;
1059 my $brapi_module = $brapi->brapi_wrapper('Trials');
1060 my $brapi_package_result = $brapi_module->update($data,$user_id,$c->config->{supportedCrop});
1061 _standard_response_construction($c, $brapi_package_result);
1064 sub trials_detail_GET {
1065 my $self = shift;
1066 my $c = shift;
1067 my ($auth) = _authenticate_user($c);
1068 my $clean_inputs = $c->stash->{clean_inputs};
1069 my $brapi = $self->brapi_module;
1070 my $brapi_module = $brapi->brapi_wrapper('Trials');
1071 my $brapi_package_result = $brapi_module->details(
1072 $c->stash->{trial_id},
1073 $c->config->{supportedCrop}
1075 _standard_response_construction($c, $brapi_package_result);
1078 sub trials_search_save : Chained('brapi') PathPart('search/trials') Args(0) : ActionClass('REST') { }
1080 sub trials_search_save_POST {
1081 my $self = shift;
1082 my $c = shift;
1083 save_results($self,$c,$c->stash->{clean_inputs},'Trials');
1086 sub trials_search_retrieve : Chained('brapi') PathPart('search/trials') Args(1) {
1087 my $self = shift;
1088 my $c = shift;
1089 my $search_id = shift;
1090 retrieve_results($self, $c, $search_id, 'Trials');
1094 =head2 brapi/v1/germplasm/{id}/pedigree?notation=purdy
1096 Usage: To retrieve pedigree information for a single germplasm
1097 Desc:
1098 Return JSON example:
1100 "metadata": {
1101 "status": [],
1102 "pagination": {}
1104 "result": {
1105 "germplasmDbId": "382",
1106 "pedigree": "TOBA97/SW90.1057",
1107 "parent1Id": "23",
1108 "parent2Id": "55"
1111 Args:
1112 Side Effects:
1114 =cut
1116 sub germplasm_pedigree : Chained('germplasm_single') PathPart('pedigree') Args(0) : ActionClass('REST') { }
1118 sub germplasm_pedigree_POST {
1119 my $self = shift;
1120 my $c = shift;
1121 #my $auth = _authenticate_user($c);
1124 sub germplasm_pedigree_GET {
1125 my $self = shift;
1126 my $c = shift;
1127 my ($auth) = _authenticate_user($c);
1128 my $clean_inputs = $c->stash->{clean_inputs};
1129 my $brapi = $self->brapi_module;
1130 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1131 my $brapi_package_result = $brapi_module->germplasm_pedigree({
1132 stock_id => $c->stash->{stock_id},
1133 notation => $clean_inputs->{notation}->[0]
1135 _standard_response_construction($c, $brapi_package_result);
1139 =head2 brapi/v1/germplasm/{id}/progeny?notation=purdy
1141 Usage: To retrieve progeny (direct descendant) information for a single germplasm
1142 Desc:
1143 Return JSON example:
1145 "metadata" : {
1146 "pagination": {},
1147 "status": [],
1148 "datafiles": []
1150 "result" : {
1151 "germplasmDbId": "382",
1152 "defaultDisplayName": "Pahang",
1153 "data" : [{
1154 "progenyGermplasmDbId": "403",
1155 "parentType": "FEMALE"
1156 }, {
1157 "progenyGermplasmDbId": "402",
1158 "parentType": "MALE"
1159 }, {
1160 "progenyGermplasmDbId": "405",
1161 "parentType": "SELF"
1165 Args:
1166 Side Effects:
1168 =cut
1170 sub germplasm_progeny : Chained('germplasm_single') PathPart('progeny') Args(0) : ActionClass('REST') { }
1172 sub germplasm_progeny_POST {
1173 my $self = shift;
1174 my $c = shift;
1177 sub germplasm_progeny_GET {
1178 my $self = shift;
1179 my $c = shift;
1180 my ($auth) = _authenticate_user($c);
1181 my $clean_inputs = $c->stash->{clean_inputs};
1182 my $brapi = $self->brapi_module;
1183 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1184 my $brapi_package_result = $brapi_module->germplasm_progeny({
1185 stock_id => $c->stash->{stock_id}
1187 _standard_response_construction($c, $brapi_package_result);
1190 sub germplasm_attributes_detail : Chained('germplasm_single') PathPart('attributes') Args(0) : ActionClass('REST') { }
1192 sub germplasm_attributes_detail_GET {
1193 my $self = shift;
1194 my $c = shift;
1195 my ($auth) = _authenticate_user($c);
1196 my $clean_inputs = $c->stash->{clean_inputs};
1197 my $brapi = $self->brapi_module;
1198 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1199 my $brapi_package_result = $brapi_module->germplasm_attributes_germplasm_detail({
1200 stock_id => $c->stash->{stock_id},
1201 attribute_dbids => $clean_inputs->{attributeDbId}
1203 _standard_response_construction($c, $brapi_package_result);
1206 =head2 brapi/v1/germplasm/{id}/markerprofiles
1208 Usage: To retrieve markerprofile ids for a single germplasm
1209 Desc:
1210 Return JSON example:
1212 "metadata": {
1213 "status": [],
1214 "pagination": {}
1216 "result": {
1217 "germplasmDbId": "382",
1218 "markerProfiles": [
1219 "123",
1220 "456"
1224 Args:
1225 Side Effects:
1227 =cut
1229 sub germplasm_markerprofile : Chained('germplasm_single') PathPart('markerprofiles') Args(0) : ActionClass('REST') { }
1231 sub germplasm_markerprofile_POST {
1232 my $self = shift;
1233 my $c = shift;
1234 #my $auth = _authenticate_user($c);
1237 sub germplasm_markerprofile_GET {
1238 my $self = shift;
1239 my $c = shift;
1240 my ($auth) = _authenticate_user($c);
1241 my $clean_inputs = $c->stash->{clean_inputs};
1242 my $brapi = $self->brapi_module;
1243 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1244 my $brapi_package_result = $brapi_module->germplasm_markerprofiles(
1245 $c->stash->{stock_id}
1247 _standard_response_construction($c, $brapi_package_result);
1252 # Germplasm Attributes
1255 sub germplasm_attributes_list : Chained('brapi') PathPart('attributes') Args(0) : ActionClass('REST') { }
1257 sub germplasm_attributes_list_GET {
1258 my $self = shift;
1259 my $c = shift;
1260 germplasm_attributes_process($self, $c);
1263 sub germplasm_attributes_process {
1264 my $self = shift;
1265 my $c = shift;
1266 my ($auth) = _authenticate_user($c);
1267 my $clean_inputs = $c->stash->{clean_inputs};
1268 my $brapi = $self->brapi_module;
1269 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1270 my $brapi_package_result = $brapi_module->search($clean_inputs);
1271 _standard_response_construction($c, $brapi_package_result);
1274 sub attribute_single : Chained('brapi') PathPart('attributes') CaptureArgs(1) {
1275 my $self = shift;
1276 my $c = shift;
1277 my $attribute_id = shift;
1279 $c->stash->{attribute_id} = $attribute_id;
1282 sub attribute_detail : Chained('attribute_single') PathPart('') Args(0) : ActionClass('REST') { }
1284 sub attribute_detail_GET {
1285 my $self = shift;
1286 my $c = shift;
1287 my ($auth) = _authenticate_user($c);
1288 my $clean_inputs = $c->stash->{clean_inputs};
1289 my $brapi = $self->brapi_module;
1290 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1291 my $brapi_package_result = $brapi_module->detail($c->stash->{attribute_id});
1292 _standard_response_construction($c, $brapi_package_result);
1295 sub germplasm_attribute_categories_list : Chained('brapi') PathPart('attributes/categories') Args(0) : ActionClass('REST') { }
1297 sub germplasm_attribute_categories_list_GET {
1298 my $self = shift;
1299 my $c = shift;
1300 my ($auth) = _authenticate_user($c);
1301 my $brapi = $self->brapi_module;
1302 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1303 my $brapi_package_result = $brapi_module->germplasm_attributes_categories_list();
1304 _standard_response_construction($c, $brapi_package_result);
1307 sub attributes_save : Chained('brapi') PathPart('search/attributes') Args(0) : ActionClass('REST') { }
1309 sub attributes_save_POST {
1310 my $self = shift;
1311 my $c = shift;
1312 save_results($self,$c,$c->stash->{clean_inputs},'GermplasmAttributes');
1315 sub attributes_retrieve : Chained('brapi') PathPart('search/attributes') Args(1) {
1316 my $self = shift;
1317 my $c = shift;
1318 my $search_id = shift;
1319 retrieve_results($self, $c, $search_id, 'GermplasmAttributes');
1323 sub germplasm_attributes_values : Chained('brapi') PathPart('attributevalues') Args(0) : ActionClass('REST') { }
1325 sub germplasm_attributes_values_GET {
1326 my $self = shift;
1327 my $c = shift;
1328 my ($auth) = _authenticate_user($c);
1329 my $clean_inputs = $c->stash->{clean_inputs};
1330 my $brapi = $self->brapi_module;
1331 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributeValues');
1332 my $brapi_package_result = $brapi_module->search($clean_inputs);
1333 _standard_response_construction($c, $brapi_package_result);
1336 sub germplasm_attributes_values_single : Chained('brapi') PathPart('attributevalues') CaptureArgs(1) {
1337 my $self = shift;
1338 my $c = shift;
1339 my $value_id = shift;
1341 $c->stash->{value_id} = $value_id;
1344 sub germplasm_attributes_values_detail : Chained('germplasm_attributes_values_single') PathPart('') Args(0) : ActionClass('REST') { }
1346 sub germplasm_attributes_values_detail_GET {
1347 my $self = shift;
1348 my $c = shift;
1349 my ($auth) = _authenticate_user($c);
1350 my $clean_inputs = $c->stash->{clean_inputs};
1351 $clean_inputs->{attributeValueDbId}=[$c->stash->{value_id}];
1352 my $brapi = $self->brapi_module;
1353 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributeValues');
1354 my $brapi_package_result = $brapi_module->search($clean_inputs);
1355 _standard_response_construction($c, $brapi_package_result);
1358 sub attributes_values_save : Chained('brapi') PathPart('search/attributevalues') Args(0) : ActionClass('REST') { }
1360 sub attributes_values_save_POST {
1361 my $self = shift;
1362 my $c = shift;
1363 save_results($self,$c,$c->stash->{clean_inputs},'GermplasmAttributeValues');
1366 sub attributes_values_retrieve : Chained('brapi') PathPart('search/attributevalues') Args(1) {
1367 my $self = shift;
1368 my $c = shift;
1369 my $search_id = shift;
1370 retrieve_results($self, $c, $search_id, 'GermplasmAttributeValues');
1373 =head2 brapi/v1/markerprofiles?germplasm=germplasmDbId&extract=extractDbId&method=methodDbId
1375 Usage: To retrieve markerprofile ids for a single germplasm
1376 Desc:
1377 Return JSON example:
1379 "metadata" : {
1380 "pagination": {
1381 "pageSize": 10,
1382 "currentPage": 1,
1383 "totalCount": 10,
1384 "totalPages": 1
1386 "status": []
1388 "result" : {
1389 "data" : [
1391 "markerProfileDbId": "993",
1392 "germplasmDbId" : 2374,
1393 "extractDbId" : 3939,
1394 "analysisMethod": "GoldenGate",
1395 "resultCount": 1470
1398 "markerProfileDbId": "994",
1399 "germplasmDbId" : 2374,
1400 "extractDbId" : 3939,
1401 "analysisMethod": "GBS",
1402 "resultCount": 1470
1407 Args:
1408 Side Effects:
1410 =cut
1412 sub markerprofile_search_process {
1413 my $self = shift;
1414 my $c = shift;
1415 my ($auth) = _authenticate_user($c);
1416 my $default_protocol = $self->bcs_schema->resultset('NaturalDiversity::NdProtocol')->find({name=>$c->config->{default_genotyping_protocol}});
1417 my $default_protocol_id = $default_protocol ? $default_protocol->nd_protocol_id : 0;
1418 my $clean_inputs = $c->stash->{clean_inputs};
1419 my $brapi = $self->brapi_module;
1420 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1421 my $brapi_package_result = $brapi_module->markerprofiles_search({
1422 cache_file_path => $c->config->{cache_file_path},
1423 shared_cluster_dir => $c->config->{cluster_shared_tempdir},
1424 study_ids => $clean_inputs->{studyDbId},
1425 stock_ids => $clean_inputs->{germplasmDbId},
1426 extract_ids => $clean_inputs->{extractDbId},
1427 sample_ids => $clean_inputs->{sampleDbId},
1428 protocol_ids => $clean_inputs->{methodDbId}
1430 _standard_response_construction($c, $brapi_package_result);
1433 sub markerprofiles_list : Chained('brapi') PathPart('markerprofiles') Args(0) : ActionClass('REST') { }
1435 sub markerprofiles_list_POST {
1436 my $self = shift;
1437 my $c = shift;
1438 markerprofile_search_process($self, $c);
1441 sub markerprofiles_list_GET {
1442 my $self = shift;
1443 my $c = shift;
1444 markerprofile_search_process($self, $c);
1448 =head2 brapi/v1/markerprofiles/markerprofilesDbId
1450 Usage: To retrieve data for a single markerprofile
1451 Desc:
1452 Return JSON example:
1454 "metadata" : {
1455 "pagination": {
1456 "pageSize": 10,
1457 "currentPage": 1,
1458 "totalCount": 10,
1459 "totalPages": 1
1461 "status": []
1464 "result": {
1465 "germplasmDbId": 993,
1466 "extractDbId" : 38383,
1467 "markerprofileDbId": 37484,
1468 "analysisMethod": "GBS-Pst1",
1469 "encoding": "AA,BB,AB",
1470 "data" : [ { "marker1": "AA" }, { "marker2":"AB" }, ... ]
1473 Args:
1474 Side Effects:
1476 =cut
1478 sub markerprofiles_single : Chained('brapi') PathPart('markerprofiles') CaptureArgs(1) {
1479 my $self = shift;
1480 my $c = shift;
1481 my $id = shift;
1482 $c->stash->{markerprofile_id} = $id; # this is genotypeprop_id
1485 sub genotype_fetch : Chained('markerprofiles_single') PathPart('') Args(0) : ActionClass('REST') { }
1487 sub genotype_fetch_POST {
1488 my $self = shift;
1489 my $c = shift;
1490 #my $auth = _authenticate_user($c);
1493 sub genotype_fetch_GET {
1494 my $self = shift;
1495 my $c = shift;
1496 my ($auth) = _authenticate_user($c);
1497 my $clean_inputs = $c->stash->{clean_inputs};
1498 my $brapi = $self->brapi_module;
1499 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1500 my $brapi_package_result = $brapi_module->markerprofiles_detail({
1501 cache_file_path => $c->config->{cache_file_path},
1502 shared_cluster_dir => $c->config->{cluster_shared_tempdir},
1503 markerprofile_id => $c->stash->{markerprofile_id},
1504 unknown_string => $clean_inputs->{unknownString}->[0],
1505 sep_phased => $clean_inputs->{sepPhased}->[0],
1506 sep_unphased => $clean_inputs->{sepUnphased}->[0],
1507 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
1509 _standard_response_construction($c, $brapi_package_result);
1513 sub markerprofiles_methods : Chained('brapi') PathPart('markerprofiles/methods') Args(0) {
1514 my $self = shift;
1515 my $c = shift;
1516 my ($auth) = _authenticate_user($c);
1517 my $brapi = $self->brapi_module;
1518 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1519 my $brapi_package_result = $brapi_module->markerprofiles_methods();
1520 _standard_response_construction($c, $brapi_package_result);
1525 =head2 brapi/v1/allelematrices-search?markerprofileDbId=100&markerprofileDbId=101
1527 Usage: Gives a matrix data structure for a given list of markerprofileDbIds
1528 Desc:
1529 Return JSON example:
1531 "metadata": {
1532 "status": [],
1533 "pagination": {
1534 "pageSize": 100,
1535 "currentPage": 1,
1536 "totalCount": 1,
1537 "totalPages": 1
1540 "result" : {
1541 "makerprofileDbIds": ["markerprofileId1","markerprofileId2","markerprofileId3"],
1542 "data" : [
1543 { "markerDbId1":["AB","AA","AA"] },
1544 { "markerDbId2":["AA","AB","AA"] },
1545 { "markerDbId3":["AB","AB","BB"] }
1549 Args:
1550 Side Effects:
1552 =cut
1554 sub allelematrices : Chained('brapi') PathPart('allelematrices-search') Args(0) : ActionClass('REST') { }
1556 sub allelematrices_POST {
1557 my $self = shift;
1558 my $c = shift;
1559 allelematrix_search_process($self, $c);
1562 sub allelematrices_GET {
1563 my $self = shift;
1564 my $c = shift;
1565 allelematrix_search_process($self, $c);
1568 sub allelematrices_new : Chained('brapi') PathPart('allelematrices') Args(0) : ActionClass('REST') { }
1570 sub allelematrices_new_GET {
1571 my $self = shift;
1572 my $c = shift;
1573 allelematrix_search_process($self, $c);
1576 sub allelematrices_cached : Chained('brapi') PathPart('search/allelematrices') Args(0) : ActionClass('REST') { }
1578 sub allelematrices_cached_POST {
1579 my $self = shift;
1580 my $c = shift;
1581 allelematrix_search_process($self, $c);
1584 sub allelematrices_cached_GET {
1585 my $self = shift;
1586 my $c = shift;
1587 allelematrix_search_process($self, $c);
1591 sub allelematrix : Chained('brapi') PathPart('allelematrix-search') Args(0) : ActionClass('REST') { }
1593 sub allelematrix_POST {
1594 my $self = shift;
1595 my $c = shift;
1596 allelematrix_search_process($self, $c);
1599 sub allelematrix_GET {
1600 my $self = shift;
1601 my $c = shift;
1602 allelematrix_search_process($self, $c);
1605 sub allelematrix_search_process {
1606 my $self = shift;
1607 my $c = shift;
1608 # my ($auth) = _authenticate_user($c);
1610 my $clean_inputs = $c->stash->{clean_inputs};
1611 my $format = $clean_inputs->{format}->[0];
1612 my $file_path;
1613 my $uri;
1614 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
1615 my $dir = $c->tempfiles_subdir('download');
1616 ($file_path, $uri) = $c->tempfile( TEMPLATE => 'download/allelematrix_'.$format.'_'.'XXXXX');
1618 my $brapi = $self->brapi_module;
1619 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1620 my $brapi_package_result = $brapi_module->markerprofiles_allelematrix({
1621 cache_file_path => $c->config->{cache_file_path},
1622 shared_cluster_dir => $c->config->{cluster_shared_tempdir},
1623 markerprofile_ids => $clean_inputs->{markerprofileDbId},
1624 marker_ids => $clean_inputs->{markerDbId},
1625 unknown_string => $clean_inputs->{unknownString}->[0],
1626 sep_phased => $clean_inputs->{sepPhased}->[0],
1627 sep_unphased => $clean_inputs->{sepUnphased}->[0],
1628 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
1629 format => $format,
1630 main_production_site_url => $c->config->{main_production_site_url},
1631 file_path => $file_path,
1632 file_uri => $uri
1634 _standard_response_construction($c, $brapi_package_result);
1637 =head2 brapi/v2/lists
1639 =cut
1641 sub lists : Chained('brapi') PathPart('lists') Args(0) : ActionClass('REST') { }
1643 sub lists_GET {
1644 my $self = shift;
1645 my $c = shift;
1646 my ($auth,$user_id) = _authenticate_user($c,1);
1647 my $clean_inputs = $c->stash->{clean_inputs};
1648 my $brapi = $self->brapi_module;
1649 my $brapi_module = $brapi->brapi_wrapper('Lists');
1650 my $brapi_package_result = $brapi_module->search($clean_inputs,$user_id);
1651 _standard_response_construction($c, $brapi_package_result);
1654 sub lists_POST {
1655 my $self = shift;
1656 my $c = shift;
1657 my ($auth,$user_id) = _authenticate_user($c);
1658 my $clean_inputs = $c->stash->{clean_inputs};
1659 my $data = $clean_inputs;
1660 my @all_lists;
1661 foreach my $list (values %{$data}) {
1662 push @all_lists, $list;
1664 my $brapi = $self->brapi_module;
1665 my $brapi_module = $brapi->brapi_wrapper('Lists');
1666 my $brapi_package_result = $brapi_module->store(\@all_lists,$user_id);
1667 _standard_response_construction($c, $brapi_package_result);
1670 sub list_single : Chained('brapi') PathPart('lists') CaptureArgs(1) {
1671 my $self = shift;
1672 my $c = shift;
1673 my $list_id = shift;
1675 $c->stash->{list_id} = $list_id;
1678 sub list_detail : Chained('list_single') PathPart('') Args(0) : ActionClass('REST') { }
1680 sub list_detail_GET {
1681 my $self = shift;
1682 my $c = shift;
1683 my ($auth,$user_id) = _authenticate_user($c);
1684 my $clean_inputs = $c->stash->{clean_inputs};
1685 my $brapi = $self->brapi_module;
1686 my $brapi_module = $brapi->brapi_wrapper('Lists');
1687 my $brapi_package_result = $brapi_module->detail($c->stash->{list_id},$user_id);
1688 _standard_response_construction($c, $brapi_package_result);
1691 sub list_detail_PUT {
1692 my $self = shift;
1693 my $c = shift;
1694 my ($auth,$user_id) = _authenticate_user($c);
1695 my $clean_inputs = $c->stash->{clean_inputs};
1696 my $data = $clean_inputs;
1697 $data->{listDbId} = $c->stash->{list_id};
1698 my $brapi = $self->brapi_module;
1699 my $brapi_module = $brapi->brapi_wrapper('Lists');
1700 my $brapi_package_result = $brapi_module->update($data,$user_id);
1701 _standard_response_construction($c, $brapi_package_result);
1704 sub list_items : Chained('list_single') PathPart('items') Args(0) : ActionClass('REST') { }
1706 sub list_items_POST {
1707 my $self = shift;
1708 my $c = shift;
1709 my ($auth,$user_id) = _authenticate_user($c);
1710 my $clean_inputs = $c->stash->{clean_inputs};
1711 my $brapi = $self->brapi_module;
1712 my $brapi_module = $brapi->brapi_wrapper('Lists');
1713 my $brapi_package_result = $brapi_module->store_items($c->stash->{list_id},$clean_inputs,$user_id);
1714 _standard_response_construction($c, $brapi_package_result);
1717 sub list_search_save : Chained('brapi') PathPart('search/lists') Args(0) : ActionClass('REST') { }
1719 sub list_search_save_POST {
1720 my $self = shift;
1721 my $c = shift;
1722 save_results($self,$c,$c->stash->{clean_inputs},'Lists');
1725 sub list_search_retrieve : Chained('brapi') PathPart('search/lists') Args(1) {
1726 my $self = shift;
1727 my $c = shift;
1728 my $search_id = shift;
1729 retrieve_results($self, $c, $search_id, 'Lists');
1732 =head2 brapi/v2/people
1734 =cut
1736 sub people : Chained('brapi') PathPart('people') Args(0) : ActionClass('REST') { }
1738 sub people_GET {
1739 my $self = shift;
1740 my $c = shift;
1741 my ($auth) = _authenticate_user($c);
1742 my $clean_inputs = $c->stash->{clean_inputs};
1743 my $brapi = $self->brapi_module;
1744 my $brapi_module = $brapi->brapi_wrapper('People');
1745 my $brapi_package_result = $brapi_module->search($clean_inputs,$c);
1746 _standard_response_construction($c, $brapi_package_result);
1749 sub people_single : Chained('brapi') PathPart('people') CaptureArgs(1) {
1750 my $self = shift;
1751 my $c = shift;
1752 my $people_id = shift;
1754 $c->stash->{people_id} = $people_id;
1757 sub people_detail : Chained('people_single') PathPart('') Args(0) : ActionClass('REST') { }
1759 sub people_detail_GET {
1760 my $self = shift;
1761 my $c = shift;
1762 my ($auth) = _authenticate_user($c);
1763 my $clean_inputs = $c->stash->{clean_inputs};
1764 my $brapi = $self->brapi_module;
1765 my $brapi_module = $brapi->brapi_wrapper('People');
1766 my $brapi_package_result = $brapi_module->detail($c->stash->{people_id},$c);
1767 _standard_response_construction($c, $brapi_package_result);
1770 sub people_search_save : Chained('brapi') PathPart('search/people') Args(0) : ActionClass('REST') { }
1772 sub people_search_save_POST {
1773 my $self = shift;
1774 my $c = shift;
1775 save_results($self,$c,$c->stash->{clean_inputs},'People');
1778 sub people_search_retrieve : Chained('brapi') PathPart('search/people') Args(1) {
1779 my $self = shift;
1780 my $c = shift;
1781 my $search_id = shift;
1782 retrieve_results($self, $c, $search_id, 'People');
1785 =head2 brapi/v1/programs
1787 Usage: To retrieve a list of programs being worked on
1788 Desc:
1789 Return JSON example:
1791 "metadata" : {
1792 "pagination": {
1793 "pageSize": 10,
1794 "currentPage": 1,
1795 "totalCount": 10,
1796 "totalPages": 1
1798 "status": []
1800 "result" : {
1801 "data" : [
1803 "programDbid": "123",
1804 "name": "Wheat Resistance Program",
1805 "objective" : "Disease resistance",
1806 "leadPerson" : "Dr. Henry Beachell"
1809 "programDbId": "456",
1810 "name": "Wheat Improvement Program",
1811 "objective" : "Yield improvement",
1812 "leadPerson" : "Dr. Norman Borlaug"
1817 Args:
1818 Side Effects:
1820 =cut
1822 sub programs_list : Chained('brapi') PathPart('programs') Args(0) : ActionClass('REST') { }
1824 sub programs_list_POST {
1825 my $self = shift;
1826 my $c = shift;
1827 my ($auth,$user_id) = _authenticate_user($c);
1828 my $clean_inputs = $c->stash->{clean_inputs};
1829 my $data = $clean_inputs;
1830 my @all_programs;
1831 foreach my $program (values %{$data}) {
1832 push @all_programs, $program;
1834 my $brapi = $self->brapi_module;
1835 my $brapi_module = $brapi->brapi_wrapper('Programs');
1836 my $brapi_package_result = $brapi_module->store(\@all_programs,$user_id);
1837 _standard_response_construction($c, $brapi_package_result);
1840 sub programs_list_GET {
1841 my $self = shift;
1842 my $c = shift;
1843 my ($auth) = _authenticate_user($c);
1844 my $clean_inputs = $c->stash->{clean_inputs};
1845 my $brapi = $self->brapi_module;
1846 my $brapi_module = $brapi->brapi_wrapper('Programs');
1847 my $brapi_package_result = $brapi_module->search({
1848 program_names => $clean_inputs->{programName},
1849 programNames => $clean_inputs->{programName},
1850 abbreviations => $clean_inputs->{abbreviation},
1851 externalReferenceIDs => $clean_inputs->{externalReferenceID},
1852 externalReferenceSources => $clean_inputs->{externalReferenceSource},
1853 commonCropNames => $clean_inputs->{commonCropName},
1854 crop => $c->config->{supportedCrop}
1856 _standard_response_construction($c, $brapi_package_result);
1859 sub programs_single : Chained('brapi') PathPart('programs') CaptureArgs(1) {
1860 my $self = shift;
1861 my $c = shift;
1862 my $program_id = shift;
1864 $c->stash->{program_id} = $program_id;
1867 sub programs_detail : Chained('programs_single') PathPart('') Args(0) : ActionClass('REST') { }
1869 sub programs_detail_GET {
1870 my $self = shift;
1871 my $c = shift;
1872 my ($auth) = _authenticate_user($c);
1873 my $clean_inputs = $c->stash->{clean_inputs};
1874 my $brapi = $self->brapi_module;
1875 my $brapi_module = $brapi->brapi_wrapper('Programs');
1876 my $brapi_package_result = $brapi_module->detail(
1877 $c->stash->{program_id},
1878 $c->config->{supportedCrop}
1880 _standard_response_construction($c, $brapi_package_result);
1883 sub programs_detail_PUT {
1884 my $self = shift;
1885 my $c = shift;
1886 my ($auth,$user_id) = _authenticate_user($c);
1887 my $clean_inputs = $c->stash->{clean_inputs};
1888 my $data = $clean_inputs;
1889 $data->{programDbId} = $c->stash->{program_id};
1890 my $brapi = $self->brapi_module;
1891 my $brapi_module = $brapi->brapi_wrapper('Programs');
1892 my $brapi_package_result = $brapi_module->update($data,$user_id);
1893 _standard_response_construction($c, $brapi_package_result);
1896 sub programs_search_save : Chained('brapi') PathPart('search/programs') Args(0) : ActionClass('REST') { }
1898 sub programs_search_save_POST {
1899 my $self = shift;
1900 my $c = shift; #print $self;
1901 save_results($self,$c,$c->stash->{clean_inputs},'Programs');
1904 sub programs_search_retrieve : Chained('brapi') PathPart('search/programs') Args(1) {
1905 my $self = shift;
1906 my $c = shift;
1907 my $search_id = shift;
1908 retrieve_results($self, $c, $search_id, 'Programs');
1912 =head2 brapi/v1/studies?programId=programId
1914 Usage: To retrieve studies
1915 Desc:
1916 Return JSON example:
1918 "metadata": {
1919 "pagination": {
1920 "pageSize": 2,
1921 "currentPage": 1,
1922 "totalCount": 100,
1923 "totalPages": 50
1925 "status" : []
1927 "result": {
1928 "data": [
1930 "studyDbId": 35,
1931 "name": "Earlygenerationtesting",
1932 "studyType": "Trial",
1933 "years": ["2005", "2008"],
1934 "locationDbId": 23,
1935 "programDbId": 27,
1936 "optionalInfo" : {
1937 "studyPUI" : "PUI string",
1938 "studyType": "Trial",
1939 "startDate": "2015-06-01",
1940 "endDate" : "2015-12-31",
1945 "studyDbId": 345,
1946 "name": "Earlygenerationtesting",
1947 "seasons": ["2005", "2008"],
1948 "locationDbId": 33,
1949 "programDbId": 58,
1950 "optionalInfo" : {
1951 "studyPUI" : "PUI string",
1952 "studyType": "Trial",
1953 "startDate": "2015-06-01",
1954 "endDate" : "2015-12-31",
1960 Args:
1961 Side Effects:
1963 =cut
1965 sub studies_search : Chained('brapi') PathPart('studies-search') Args(0) : ActionClass('REST') { }
1967 sub studies_search_POST {
1968 my $self = shift;
1969 my $c = shift;
1970 # my ($auth) = _authenticate_user($c);
1971 my $clean_inputs = $c->stash->{clean_inputs};
1972 my $brapi = $self->brapi_module;
1973 my $brapi_module = $brapi->brapi_wrapper('Studies');
1974 my $brapi_package_result = $brapi_module->search({
1975 programDbIds => $clean_inputs->{programDbIds},
1976 programNames => $clean_inputs->{programNames},
1977 studyDbIds => $clean_inputs->{studyDbIds},
1978 studyNames => $clean_inputs->{studyNames},
1979 trialDbIds => $clean_inputs->{trialDbIds},
1980 trialNames => $clean_inputs->{trialNames},
1981 studyLocationDbIds => $clean_inputs->{locationDbIds},
1982 studyLocationNames => $clean_inputs->{studyLocations},
1983 studyTypeName => $clean_inputs->{studyType},
1984 germplasmDbIds => $clean_inputs->{germplasmDbIds},
1985 germplasmNames => $clean_inputs->{germplasmNames},
1986 seasons => $clean_inputs->{seasonDbIds},
1987 observationVariableDbIds => $clean_inputs->{observationVariableDbIds},
1988 observationVariableNames => $clean_inputs->{observationVariableNames},
1989 active => $clean_inputs->{active}->[0],
1990 sortBy => $clean_inputs->{sortBy}->[0],
1991 sortOrder => $clean_inputs->{sortOrder}->[0],
1992 }, $c);
1993 _standard_response_construction($c, $brapi_package_result);
1996 sub studies_search_GET {
1997 my $self = shift;
1998 my $c = shift;
1999 my ($auth) = _authenticate_user($c);
2000 my $clean_inputs = $c->stash->{clean_inputs};
2001 my $brapi = $self->brapi_module;
2002 my $brapi_module = $brapi->brapi_wrapper('Studies');
2003 my $brapi_package_result = $brapi_module->search({
2004 programDbIds => $clean_inputs->{programDbId},
2005 programNames => $clean_inputs->{programName},
2006 studyDbIds => $clean_inputs->{studyDbId},
2007 studyNames => $clean_inputs->{studyName},
2008 trialDbIds => $clean_inputs->{trialDbId},
2009 trialNames => $clean_inputs->{trialName},
2010 studyLocationDbIds => $clean_inputs->{locationDbId},
2011 studyLocationNames => $clean_inputs->{locationName},
2012 seasons => $clean_inputs->{seasonDbId},
2013 studyTypeName => $clean_inputs->{studyType},
2014 germplasmDbIds => $clean_inputs->{germplasmDbId},
2015 germplasmNames => $clean_inputs->{germplasmName},
2016 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2017 observationVariableNames => $clean_inputs->{observationVariableName},
2018 active => $clean_inputs->{active}->[0],
2019 sortBy => $clean_inputs->{sortBy}->[0],
2020 sortOrder => $clean_inputs->{sortOrder}->[0],
2021 }, $c);
2022 _standard_response_construction($c, $brapi_package_result);
2025 sub studies : Chained('brapi') PathPart('studies') Args(0) : ActionClass('REST') { }
2027 sub studies_GET {
2028 my $self = shift;
2029 my $c = shift;
2030 my $auth = _authenticate_user($c);
2031 my $clean_inputs = $c->stash->{clean_inputs};
2032 my $brapi = $self->brapi_module;
2033 my $brapi_module = $brapi->brapi_wrapper('Studies');
2034 my $brapi_package_result = $brapi_module->search({
2035 programDbIds => $clean_inputs->{programDbId},
2036 programNames => $clean_inputs->{programName},
2037 studyDbIds => $clean_inputs->{studyDbId},
2038 studyNames => $clean_inputs->{studyName},
2039 trialDbIds => $clean_inputs->{trialDbId},
2040 trialNames => $clean_inputs->{trialName},
2041 studyLocationDbIds => $clean_inputs->{locationDbId},
2042 studyLocationNames => $clean_inputs->{locationName},
2043 seasons => $clean_inputs->{seasonDbId},
2044 seasonDbIds => $clean_inputs->{seasonDbId},
2045 studyTypes => $clean_inputs->{studyType},
2046 germplasmDbIds => $clean_inputs->{germplasmDbId},
2047 germplasmNames => $clean_inputs->{germplasmName},
2048 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2049 observationVariableNames => $clean_inputs->{observationVariableName},
2050 crop => $c->config->{supportedCrop},
2051 active => $clean_inputs->{active}->[0],
2052 sortBy => $clean_inputs->{sortBy}->[0],
2053 sortOrder => $clean_inputs->{sortOrder}->[0],
2054 commonCropNames => $clean_inputs->{commonCropName},
2055 }, $c);
2056 _standard_response_construction($c, $brapi_package_result);
2059 sub studies_POST {
2060 my $self = shift;
2061 my $c = shift;
2062 my ($auth, $user_id) = _authenticate_user($c);
2063 my $clean_inputs = $c->stash->{clean_inputs};
2064 my $data = $clean_inputs;
2065 _validate_request($c, 'ARRAY', $data, ['trialDbId', 'studyName', 'studyType', 'locationDbId', {'experimentalDesign' => ['PUI']}]);
2067 my @all_studies;
2068 foreach my $study (values %{$data}) {
2069 push @all_studies, $study;
2071 my $brapi = $self->brapi_module;
2072 my $brapi_module = $brapi->brapi_wrapper('Studies');
2073 my $brapi_package_result = $brapi_module->store(\@all_studies, $user_id, $c);
2074 _standard_response_construction($c, $brapi_package_result);
2077 sub studies_search_save : Chained('brapi') PathPart('search/studies') Args(0) : ActionClass('REST') { }
2079 sub studies_search_save_POST {
2080 my $self = shift;
2081 my $c = shift;
2082 save_results($self,$c,$c->stash->{clean_inputs},'Studies');
2085 sub studies_search_retrieve : Chained('brapi') PathPart('search/studies') Args(1) {
2086 my $self = shift;
2087 my $c = shift;
2088 my $search_id = shift;
2089 retrieve_results($self, $c, $search_id, 'Studies');
2093 =head2 brapi/v1/studies/{studyId}/germplasm?pageSize=20&page=1
2095 Usage: To retrieve all germplasm used in a study
2096 Desc:
2097 Return JSON example:
2099 "metadata": {
2100 "status": [],
2101 "pagination": {
2102 "pageSize": 1000,
2103 "currentPage": 1,
2104 "totalCount": 1,
2105 "totalPages": 1
2108 "result": {
2109 "studyDbId": 123,
2110 "studyName": "myBestTrial",
2111 "data": [
2113 "germplasmDbId": "382",
2114 "trialEntryNumberId": "1",
2115 "defaultDisplayName": "Pahang",
2116 "germplasmName": "Pahang",
2117 "accessionNumber": "ITC0609",
2118 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
2119 "pedigree": "TOBA97/SW90.1057",
2120 "seedSource": "",
2121 "synonyms": ["01BEL084609"],
2124 "germplasmDbId": "394",
2125 "trialEntryNumberId": "2",
2126 "defaultDisplayName": "Pahang",
2127 "germplasmName": "Pahang",
2128 "accessionNumber": "ITC0727",
2129 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084727",
2130 "pedigree": "TOBA97/SW90.1057",
2131 "seedSource": "",
2132 "synonyms": [ "01BEL084727"],
2137 Args:
2138 Side Effects:
2140 =cut
2142 sub studies_single : Chained('brapi') PathPart('studies') CaptureArgs(1) {
2143 my $self = shift;
2144 my $c = shift;
2145 my $study_id = shift;
2147 $c->stash->{study_id} = $study_id;
2151 sub studies_germplasm : Chained('studies_single') PathPart('germplasm') Args(0) : ActionClass('REST') { }
2153 sub studies_germplasm_POST {
2154 my $self = shift;
2155 my $c = shift;
2156 my ($auth) = _authenticate_user($c);
2158 my $metadata = $c->req->params("metadata");
2159 my $result = $c->req->params("result");
2160 my %metadata_hash = %$metadata;
2161 my %result_hash = %$result;
2163 #print STDERR Dumper($metadata);
2164 #print STDERR Dumper($result);
2166 my $pagintation = $metadata_hash{"pagination"};
2169 sub studies_germplasm_GET {
2170 my $self = shift;
2171 my $c = shift;
2172 my ($auth) = _authenticate_user($c);
2173 my $brapi = $self->brapi_module;
2174 my $brapi_module = $brapi->brapi_wrapper('Studies');
2175 my $brapi_package_result = $brapi_module->studies_germplasm(
2176 $c->stash->{study_id}
2178 _standard_response_construction($c, $brapi_package_result);
2181 sub studies_info : Chained('studies_single') PathPart('') Args(0) : ActionClass('REST') { }
2183 sub studies_info_POST {
2184 my $self = shift;
2185 my $c = shift;
2186 #my $auth = _authenticate_user($c);
2189 sub studies_info_GET {
2190 my $self = shift;
2191 my $c = shift;
2192 my ($auth) = _authenticate_user($c);
2193 my $clean_inputs = $c->stash->{clean_inputs};
2194 my $brapi = $self->brapi_module;
2195 my $brapi_module = $brapi->brapi_wrapper('Studies');
2196 my $brapi_package_result = $brapi_module->detail(
2197 $c->stash->{study_id},
2198 $c->config->{main_production_site_url},
2199 $c->config->{supportedCrop}
2201 _standard_response_construction($c, $brapi_package_result);
2204 sub studies_info_PUT {
2205 my $self = shift;
2206 my $c = shift;
2207 my ($auth,$user_id) = _authenticate_user($c);
2208 my $clean_inputs = $c->stash->{clean_inputs};
2209 my $data = $clean_inputs;
2210 _validate_request($c, 'HASH', $data, ['trialDbId', 'studyName', 'studyType', 'locationDbId', {'experimentalDesign' => ['PUI']}]);
2211 $data->{studyDbId} = $c->stash->{study_id};
2213 my $brapi = $self->brapi_module;
2214 my $brapi_module = $brapi->brapi_wrapper('Studies');
2215 my $brapi_package_result = $brapi_module->update($data,$user_id,$c);
2216 _standard_response_construction($c, $brapi_package_result);
2219 sub studies_observation_variables : Chained('studies_single') PathPart('observationvariables') Args(0) : ActionClass('REST') { }
2221 sub studies_observation_variables_POST {
2222 my $self = shift;
2223 my $c = shift;
2224 #my $auth = _authenticate_user($c);
2227 sub studies_observation_variables_GET {
2228 my $self = shift;
2229 my $c = shift;
2230 my ($auth) = _authenticate_user($c);
2231 my $brapi = $self->brapi_module;
2232 my $brapi_module = $brapi->brapi_wrapper('Studies');
2233 my $brapi_package_result = $brapi_module->studies_observation_variables(
2234 $c->stash->{study_id},
2235 $c->config->{supportedCrop}
2237 _standard_response_construction($c, $brapi_package_result);
2241 sub studies_layout : Chained('studies_single') PathPart('layout') Args(0) : ActionClass('REST') { }
2243 sub studies_layout_POST {
2244 my $self = shift;
2245 my $c = shift;
2246 #my $auth = _authenticate_user($c);
2249 sub studies_layout_GET {
2250 my $self = shift;
2251 my $c = shift;
2252 my $clean_inputs = $c->stash->{clean_inputs};
2253 my ($auth) = _authenticate_user($c);
2254 my $format = $clean_inputs->{format}->[0] || 'json';
2255 my $file_path;
2256 my $uri;
2257 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
2258 my $dir = $c->tempfiles_subdir('download');
2259 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2260 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
2261 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2264 my $brapi = $self->brapi_module;
2265 my $brapi_module = $brapi->brapi_wrapper('Studies');
2266 my $brapi_package_result = $brapi_module->studies_layout({
2267 study_id => $c->stash->{study_id},
2268 format => $format,
2269 main_production_site_url => $c->config->{main_production_site_url},
2270 file_path => $file_path,
2271 file_uri => $uri
2273 _standard_response_construction($c, $brapi_package_result);
2276 sub studies_layouts : Chained('studies_single') PathPart('layouts') Args(0) : ActionClass('REST') { }
2278 sub studies_layouts_GET {
2279 my $self = shift;
2280 my $c = shift;
2281 my $clean_inputs = $c->stash->{clean_inputs};
2282 my ($auth) = _authenticate_user($c);
2283 my $format = $clean_inputs->{format}->[0] || 'json';
2284 my $file_path;
2285 my $uri;
2286 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
2287 my $dir = $c->tempfiles_subdir('download');
2288 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2289 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
2290 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2293 my $brapi = $self->brapi_module;
2294 my $brapi_module = $brapi->brapi_wrapper('Studies');
2295 my $brapi_package_result = $brapi_module->studies_layout({
2296 study_id => $c->stash->{study_id},
2297 format => $format,
2298 main_production_site_url => $c->config->{main_production_site_url},
2299 file_path => $file_path,
2300 file_uri => $uri
2302 _standard_response_construction($c, $brapi_package_result);
2306 =head2 brapi/v1/studies/<studyDbId>/observationunits?observationVariableDbId=2
2308 Usage: To retrieve phenotypic values on a the plot level for an entire trial
2309 Desc:
2310 Return JSON example:
2312 "metadata" : "status": [],
2313 "pagination": {
2314 "pageSize": 1,
2315 "currentPage": 1,
2316 "totalCount": 1,
2317 "totalPages": 1
2319 "result" : {
2320 "data" : [
2322 "studyDbId": 1,
2323 "plotDbId": 11,
2324 "observationVariableDbId" : 393939,
2325 "observationVariableName" : "Yield",
2326 "plotName": "ZIPA_68_Ibadan_2014",
2327 "timestamp" : "2015-11-05 15:12",
2328 "uploadedBy" : {dbUserId},
2329 "operator" : "Jane Doe",
2330 "germplasmName": 143,
2331 "value" : 5,
2336 Args:
2337 Side Effects:
2339 =cut
2341 sub studies_observations : Chained('studies_single') PathPart('observationunits') Args(0) : ActionClass('REST') { }
2343 sub studies_observations_GET {
2344 my $self = shift;
2345 my $c = shift;
2346 my $clean_inputs = $c->stash->{clean_inputs};
2347 # my ($auth) = _authenticate_user($c);
2348 my $brapi = $self->brapi_module;
2349 my $brapi_module = $brapi->brapi_wrapper('Studies');
2350 my $brapi_package_result = $brapi_module->observation_units({
2351 study_id => $c->stash->{study_id},
2352 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2353 data_level => $clean_inputs->{observationLevel}->[0]
2355 _standard_response_construction($c, $brapi_package_result);
2359 =head2 brapi/v1/studies/<studyDbId>/table
2361 Usage: To retrieve phenotypic values for a study, in a manner representative of a table, with headers and data separated
2362 Desc:
2363 Return JSON example:
2365 "metadata": {
2366 "status": [],
2367 "pagination": {
2368 "pageSize": 1,
2369 "currentPage": 1,
2370 "totalCount": 1,
2371 "totalPages": 1
2374 "result" : {
2375 "studyDbId": 1,
2376 "observationVariableDbId": [ '', '', '', '', '', '', '', '', 44444, 55555, 66666...],
2377 "observationVariableName": [ "plotDbId", "plotName", "block", "rep", "germplasmID", "germplasmName", "operator", "timestamp", "Yield", "Color", "Dry Matter"...],
2379 "data" :
2381 [1, "plot1", 1, 1, "CIP1", 41, "user1", "2015-11-05 15:12", 10, "yellow", 9, ...],
2382 [2, "plot2", 1, 1, "CIP2", 42, "user1", "2015-11-05 20:12", 3, "red", 4, ...]
2386 Args:
2387 Side Effects:
2389 =cut
2391 sub studies_table : Chained('studies_single') PathPart('table') Args(0) : ActionClass('REST') { }
2393 sub studies_table_GET {
2394 my $self = shift;
2395 my $c = shift;
2396 my ($auth) = _authenticate_user($c);
2398 my $clean_inputs = $c->stash->{clean_inputs};
2399 my $format = $clean_inputs->{format}->[0];
2400 my $file_path;
2401 my $uri;
2402 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
2403 my $dir = $c->tempfiles_subdir('download');
2404 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2405 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
2406 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2408 my $brapi = $self->brapi_module;
2409 my $brapi_module = $brapi->brapi_wrapper('Studies');
2410 my $brapi_package_result = $brapi_module->studies_table({
2411 study_id => $c->stash->{study_id},
2412 data_level => $clean_inputs->{observationLevel}->[0],
2413 search_type => $clean_inputs->{search_type}->[0],
2414 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2415 trait_ids => $clean_inputs->{observationVariableDbId},
2416 trial_ids => $clean_inputs->{studyDbId},
2417 format => $format,
2418 main_production_site_url => $c->config->{main_production_site_url},
2419 file_path => $file_path,
2420 file_uri => $uri
2423 _standard_response_construction($c, $brapi_package_result);
2427 =head2 brapi/v1/studies/<studyDbId>/observations?observationVariableDbId=2
2429 Usage: To retrieve phenotypic values on a the plot level for an entire trial
2430 Desc:
2431 Return JSON example:
2433 "metadata" : "status": [],
2434 "pagination": {
2435 "pageSize": 1,
2436 "currentPage": 1,
2437 "totalCount": 1,
2438 "totalPages": 1
2440 "result" : {
2441 "data" : [
2443 "studyDbId": 1,
2444 "plotDbId": 11,
2445 "observationVariableDbId" : 393939,
2446 "observationVariableName" : "Yield",
2447 "plotName": "ZIPA_68_Ibadan_2014",
2448 "timestamp" : "2015-11-05 15:12",
2449 "uploadedBy" : {dbUserId},
2450 "operator" : "Jane Doe",
2451 "germplasmName": 143,
2452 "value" : 5,
2457 Args:
2458 Side Effects:
2460 =cut
2462 sub studies_observations_granular : Chained('studies_single') PathPart('observations') Args(0) : ActionClass('REST') { }
2464 sub studies_observations_granular_PUT {
2465 my $self = shift;
2466 my $c = shift;
2467 my $clean_inputs = $c->stash->{clean_inputs};
2468 my $observations = $clean_inputs->{observations};
2469 #print STDERR "Observations are ". Dumper($observations) . "\n";
2470 save_observation_results($self, $c, $observations, 'v1');
2473 sub studies_observations_granular_GET {
2474 my $self = shift;
2475 my $c = shift;
2476 my $clean_inputs = $c->stash->{clean_inputs};
2477 my ($auth) = _authenticate_user($c);
2478 my $brapi = $self->brapi_module;
2479 my $brapi_module = $brapi->brapi_wrapper('Studies');
2480 my $brapi_package_result = $brapi_module->observation_units_granular({
2481 study_id => $c->stash->{study_id},
2482 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2483 data_level => $clean_inputs->{observationLevel}->[0],
2484 search_type => $clean_inputs->{search_type}->[0],
2485 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2487 _standard_response_construction($c, $brapi_package_result);
2490 =head2 brapi/v1/phenotypes?observationUnitLevel=plot&studyDbId=876&studyPUI=&studyLocation=&studySet=&studyProject=&treatmentFactor=lowInput&germplasmGenus=&germplasmSubTaxa=&germplasmDbId&germplasmPUI=http://data.inra.fr/accession/234Col342&germplasmSpecies=Triticum&panel=diversitypanel1&collection=none&observationVariables=CO_321:000034,CO_321:000025&location=bergheim&season=2005,2006&pageSize={pageSize}&page={page}
2492 Usage: To retrieve a phenotype dataset
2493 Desc:d
2494 Return JSON example:
2496 "metadata": {
2497 "pagination": {
2498 "pageSize": 10,
2499 "currentPage": 1,
2500 "totalCount": 10,
2501 "totalPages": 1
2503 "status": []
2506 "result" : {
2507 "observationUnitDbId": 20,
2508 "observationUnitPUI": "http://phenome-fppn.fr/maugio/bloc/12/2345",
2509 "studyId": "RIGW1",
2510 "studyDbId": 25,
2511 "studyLocation": "Bergheim",
2512 "studyPUI": "http://phenome-fppn.fr/phenoarch/2014/1",
2513 "studyProject": "Inovine",
2514 "studySet": ["National Network", "Frost suceptibility network"],
2515 "studyPlatform": "Phenome",
2516 "observationUnitLevelTypes" : [ "plant","plot", "bloc"],
2517 "observationUnitLevelLabels": [ "1","26123", "1"],
2518 "germplasmPUI": "http://inra.fr/vassal/41207Col0001E",
2519 "germplasmDbId": 3425,
2520 "germplasmName": "charger",
2521 "treatments":
2524 "factor" : "water regimen" ,
2525 "modality":"water deficit"
2528 "attributes":
2530 {"att1" :"value"},
2531 {"numPot" :"23"}
2533 "X" : "",
2534 "Y" : "",
2535 "XLabel" : "",
2536 "YLabel" : "",
2537 "data": [
2539 "instanceNumber" : 1,
2540 "observationVariableDbId": 35,
2541 "season": "2005",
2542 "observationValue" : "red",
2543 "observationTimeStamp": null,
2544 "quality": "reliability of the observation",
2545 "collectionFacilityLabel": "phenodyne",
2546 "collector" : "John Doe and team"
2549 "instanceNumber" : 1,
2550 "observationVariableDbId": 35,
2551 "season": null,
2552 "observationValue" : 32,
2553 "observationTimeStamp": "2006-07-03::10:00",
2554 "quality": "8",
2555 "collectionFacilityLabel": null,
2556 "collector" : "userURIOrName"
2562 Args:
2563 Side Effects:
2565 =cut
2567 sub phenotypes_search : Chained('brapi') PathPart('phenotypes-search') Args(0) : ActionClass('REST') { }
2569 sub phenotypes_search_POST {
2570 my $self = shift;
2571 my $c = shift;
2572 # my ($auth) = _authenticate_user($c);
2573 my $clean_inputs = $c->stash->{clean_inputs};
2574 my $brapi = $self->brapi_module;
2575 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2576 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
2577 _standard_response_construction($c, $brapi_package_result);
2580 sub phenotypes_search_GET {
2581 my $self = shift;
2582 my $c = shift;
2583 my ($auth) = _authenticate_user($c);
2584 my $clean_inputs = $c->stash->{clean_inputs};
2585 my $brapi = $self->brapi_module;
2586 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2587 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
2588 _standard_response_construction($c, $brapi_package_result);
2591 # Observation units
2593 sub observation_units : Chained('brapi') PathPart('observationunits') Args(0) ActionClass('REST') { }
2595 sub observation_units_GET {
2597 my $self = shift;
2598 my $c = shift;
2599 my ($auth) = _authenticate_user($c);
2600 my $clean_inputs = $c->stash->{clean_inputs};
2601 my $brapi = $self->brapi_module;
2602 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2603 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
2604 _standard_response_construction($c, $brapi_package_result);
2607 sub observation_units_POST {
2609 my $self = shift;
2610 my $c = shift;
2611 # The observation units need an operator, so login required
2612 my $force_authenticate = 1;
2613 my ($auth,$user_id) = _authenticate_user($c, $force_authenticate);
2614 my $clean_inputs = $c->stash->{clean_inputs};
2615 my $data = $clean_inputs;
2616 _validate_request($c, 'ARRAY', $data, [
2617 'studyDbId',
2618 'observationUnitName',
2620 'observationUnitPosition' => [
2622 'observationLevel' => ['levelName', 'levelCode'],
2627 my @all_units;
2628 foreach my $unit (values %{$data}) {
2629 push @all_units, $unit;
2631 my $brapi = $self->brapi_module;
2632 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2633 my $brapi_package_result = $brapi_module->observationunits_store(\@all_units,$c,$user_id);
2634 _standard_response_construction($c, $brapi_package_result);
2637 sub observation_units_PUT {
2639 my $self = shift;
2640 my $c = shift;
2641 my ($auth,$user_id) = _authenticate_user($c);
2642 my $clean_inputs = $c->stash->{clean_inputs};
2643 my %data = %$clean_inputs;
2644 my @all_units;
2645 foreach my $unit (keys %data) {
2646 my $observationUnitDbId = $unit;
2647 my $units = $data{$unit};
2648 $units->{observationUnitDbId} = $observationUnitDbId;
2649 push @all_units, $units;
2651 my $brapi = $self->brapi_module;
2652 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2653 my $brapi_package_result = $brapi_module->observationunits_update(\@all_units,$c,$user_id);
2654 _standard_response_construction($c, $brapi_package_result);
2657 sub observation_units_table : Chained('brapi') PathPart('observationunits/table') Args(0) : ActionClass('REST') { }
2659 sub observation_units_table_GET {
2660 my $self = shift;
2661 my $c = shift;
2662 my ($auth) = _authenticate_user($c);
2663 my $clean_inputs = $c->stash->{clean_inputs};
2664 my $brapi = $self->brapi_module;
2665 my $brapi_module = $brapi->brapi_wrapper('ObservationTables');
2666 my $brapi_package_result = $brapi_module->search_observationunit_tables($c->stash->{clean_inputs});
2667 _standard_response_construction($c, $brapi_package_result);
2670 sub observation_unit_single : Chained('brapi') PathPart('observationunits') Args(1) ActionClass('REST') {
2671 my $self = shift;
2672 my $c = shift;
2673 my $observation_unit_db_id = shift;
2675 $c->stash->{observation_unit_db_id} = $observation_unit_db_id;
2678 sub observation_unit_single_PUT {
2679 my $self = shift;
2680 my $c = shift;
2681 my $observation_unit_db_id = shift;
2682 my $clean_inputs = $c->stash->{clean_inputs};
2683 my ($auth) = _authenticate_user($c);
2684 my $observationUnits = $clean_inputs;
2685 $observationUnits->{observationUnitDbId} = $observation_unit_db_id;
2686 my @all_observations_units;
2687 push @all_observations_units, $observationUnits;
2688 my $brapi = $self->brapi_module;
2689 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2690 my $brapi_package_result = $brapi_module->observationunits_update(\@all_observations_units, $c);
2692 _standard_response_construction($c, $brapi_package_result);
2695 sub observation_unit_single_GET {
2696 my $self = shift;
2697 my $c = shift;
2698 my ($auth) = _authenticate_user($c);
2699 my $clean_inputs = $c->stash->{clean_inputs};
2700 my $brapi = $self->brapi_module;
2701 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2702 my $brapi_package_result = $brapi_module->detail(
2703 $c->stash->{observation_unit_db_id});
2704 _standard_response_construction($c, $brapi_package_result);
2707 sub observation_units_search_save : Chained('brapi') PathPart('search/observationunits') Args(0) : ActionClass('REST') { }
2709 sub observation_units_search_save_POST {
2710 my $self = shift;
2711 my $c = shift;
2712 save_results($self,$c,$c->stash->{clean_inputs},'ObservationUnits');
2715 sub observation_units_search_retrieve : Chained('brapi') PathPart('search/observationunits') Args(1) {
2716 my $self = shift;
2717 my $c = shift;
2718 my $search_id = shift;
2719 retrieve_results($self, $c, $search_id, 'ObservationUnits');
2723 sub phenotypes_search_table : Chained('brapi') PathPart('phenotypes-search/table') Args(0) : ActionClass('REST') { }
2725 sub phenotypes_search_table_POST {
2726 my $self = shift;
2727 my $c = shift;
2728 process_phenotypes_search_table($self, $c);
2731 sub phenotypes_search_table_GET {
2732 my $self = shift;
2733 my $c = shift;
2734 process_phenotypes_search_table($self, $c);
2737 sub process_phenotypes_search_table {
2738 my $self = shift;
2739 my $c = shift;
2740 # my ($auth) = _authenticate_user($c);
2741 my $clean_inputs = $c->stash->{clean_inputs};
2742 my $brapi = $self->brapi_module;
2743 my $brapi_module = $brapi->brapi_wrapper('ObservationTables');
2744 my $brapi_package_result = $brapi_module->search_table($c->stash->{clean_inputs});
2745 _standard_response_construction($c, $brapi_package_result);
2748 sub observation_tables_search_save : Chained('brapi') PathPart('search/observationtables') Args(0) : ActionClass('REST') { }
2750 sub observation_tables_search_save_POST {
2751 my $self = shift;
2752 my $c = shift;
2753 save_results($self,$c,$c->stash->{clean_inputs},'ObservationTables');
2756 sub observation_tables_search_retrieve : Chained('brapi') PathPart('search/observationtables') Args(1) {
2757 my $self = shift;
2758 my $c = shift;
2759 my $search_id = shift;
2760 retrieve_results($self, $c, $search_id, 'ObservationTables');
2763 sub phenotypes_search_csv : Chained('brapi') PathPart('phenotypes-search/csv') Args(0) : ActionClass('REST') { }
2765 sub phenotypes_search_csv_POST {
2766 my $self = shift;
2767 my $c = shift;
2768 process_phenotypes_search_csv($self, $c);
2771 sub phenotypes_search_csv_GET {
2772 my $self = shift;
2773 my $c = shift;
2774 process_phenotypes_search_csv($self, $c);
2777 sub process_phenotypes_search_csv {
2778 my $self = shift;
2779 my $c = shift;
2780 # my ($auth) = _authenticate_user($c);
2781 my $clean_inputs = $c->stash->{clean_inputs};
2782 my $dir = $c->tempfiles_subdir('download');
2783 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2784 my $temp_file_name = $time_stamp . "phenotype_download_csv"."_XXXX";
2785 my ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2787 my $brapi = $self->brapi_module;
2788 my $brapi_module = $brapi->brapi_wrapper('Phenotypes');
2789 my $brapi_package_result = $brapi_module->search_table_csv_or_tsv({
2790 trait_ids => $clean_inputs->{observationVariableDbIds},
2791 accession_ids => $clean_inputs->{germplasmDbIds},
2792 study_ids => $clean_inputs->{studyDbIds},
2793 location_ids => $clean_inputs->{locationDbIds},
2794 years => $clean_inputs->{seasonDbIds},
2795 data_level => $clean_inputs->{observationLevel}->[0],
2796 search_type => $clean_inputs->{search_type}->[0],
2797 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2798 format => 'csv',
2799 main_production_site_url => $c->config->{main_production_site_url},
2800 file_path => $file_path,
2801 file_uri => $uri
2803 _standard_response_construction($c, $brapi_package_result);
2806 sub phenotypes_search_tsv : Chained('brapi') PathPart('phenotypes-search/tsv') Args(0) : ActionClass('REST') { }
2808 sub phenotypes_search_tsv_POST {
2809 my $self = shift;
2810 my $c = shift;
2811 process_phenotypes_search_tsv($self, $c);
2814 sub phenotypes_search_tsv_GET {
2815 my $self = shift;
2816 my $c = shift;
2817 process_phenotypes_search_tsv($self, $c);
2820 sub process_phenotypes_search_tsv {
2821 my $self = shift;
2822 my $c = shift;
2823 # my ($auth) = _authenticate_user($c);
2824 my $clean_inputs = $c->stash->{clean_inputs};
2825 my $dir = $c->tempfiles_subdir('download');
2826 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2827 my $temp_file_name = $time_stamp . "phenotype_download_tsv"."_XXXX";
2828 my ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2830 my $brapi = $self->brapi_module;
2831 my $brapi_module = $brapi->brapi_wrapper('Phenotypes');
2832 my $brapi_package_result = $brapi_module->search_table_csv_or_tsv({
2833 trait_ids => $clean_inputs->{observationVariableDbIds},
2834 accession_ids => $clean_inputs->{germplasmDbIds},
2835 study_ids => $clean_inputs->{studyDbIds},
2836 location_ids => $clean_inputs->{locationDbIds},
2837 years => $clean_inputs->{seasonDbIds},
2838 data_level => $clean_inputs->{observationLevel}->[0],
2839 search_type => $clean_inputs->{search_type}->[0],
2840 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2841 format => 'tsv',
2842 main_production_site_url => $c->config->{main_production_site_url},
2843 file_path => $file_path,
2844 file_uri => $uri
2846 _standard_response_construction($c, $brapi_package_result);
2850 sub traits_list : Chained('brapi') PathPart('traits') Args(0) : ActionClass('REST') { }
2852 sub traits_list_POST {
2853 my $self = shift;
2854 my $c = shift;
2855 #my $auth = _authenticate_user($c);
2858 sub traits_list_GET {
2859 my $self = shift;
2860 my $c = shift;
2861 my ($auth) = _authenticate_user($c);
2862 my $clean_inputs = $c->stash->{clean_inputs};
2863 my $brapi = $self->brapi_module;
2864 my $brapi_module = $brapi->brapi_wrapper('Traits');
2865 my $brapi_package_result = $brapi_module->list({
2866 trait_ids => $clean_inputs->{traitDbIds},
2867 names => $clean_inputs->{names}
2869 _standard_response_construction($c, $brapi_package_result);
2873 sub traits_single : Chained('brapi') PathPart('traits') CaptureArgs(1) {
2874 my $self = shift;
2875 my $c = shift;
2876 my $trait_id = shift;
2878 $c->stash->{trait_id} = $trait_id;
2882 sub trait_detail : Chained('traits_single') PathPart('') Args(0) : ActionClass('REST') { }
2884 sub trait_detail_GET {
2885 my $self = shift;
2886 my $c = shift;
2887 my ($auth) = _authenticate_user($c);
2888 my $clean_inputs = $c->stash->{clean_inputs};
2889 my $brapi = $self->brapi_module;
2890 my $brapi_module = $brapi->brapi_wrapper('Traits');
2891 my $brapi_package_result = $brapi_module->detail(
2892 $c->stash->{trait_id}
2894 _standard_response_construction($c, $brapi_package_result);
2898 =head2 brapi/v1/maps?species=speciesId
2900 Usage: To retrieve a list of all maps available in the database.
2901 Desc:
2902 Return JSON example:
2904 "metadata" : {
2905 "pagination" : {
2906 "pageSize": 30,
2907 "currentPage": 2,
2908 "totalCount": 40,
2909 "totalPages": 2
2911 "status" : []
2913 "result": {
2914 "data" : [
2916 "mapId": 1,
2917 "name": "Some Map",
2918 "species": "Some species",
2919 "type": "Genetic",
2920 "unit": "cM",
2921 "publishedDate": "2008-04-16",
2922 "markerCount": 1000,
2923 "linkageGroupCount": 7,
2924 "comments": "This map contains ..."
2927 "mapId": 2,
2928 "name": "Some Other map",
2929 "species": "Some Species",
2930 "type": "Genetic",
2931 "unit": "cM",
2932 "publishedDate": "2009-01-12",
2933 "markerCount": 1501,
2934 "linkageGroupCount": 7,
2935 "comments": "this is blah blah"
2940 Args:
2941 Side Effects:
2943 =cut
2945 sub maps_list : Chained('brapi') PathPart('maps') Args(0) : ActionClass('REST') { }
2947 sub maps_list_POST {
2948 my $self = shift;
2949 my $c = shift;
2950 #my $auth = _authenticate_user($c);
2953 sub maps_list_GET {
2954 my $self = shift;
2955 my $c = shift;
2956 my ($auth) = _authenticate_user($c);
2957 my $clean_inputs = $c->stash->{clean_inputs};
2958 my $brapi = $self->brapi_module;
2959 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
2960 my $brapi_package_result = $brapi_module->list({
2961 config => $c->config,
2962 mapDbId => $clean_inputs->{mapDbId},
2963 commonCropName => $clean_inputs->{commonCropName},
2964 scientificName => $clean_inputs->{scientificName},
2965 type => $clean_inputs->{type},
2968 _standard_response_construction($c, $brapi_package_result);
2973 =head2 brapi/v1/maps/<map_id>
2975 Usage: To retrieve details for a specific map_id
2976 Desc:
2977 Return JSON example:
2979 "metadata" : {
2980 "pagination" : {
2981 "pageSize": 30,
2982 "currentPage": 2,
2983 "totalCount": 40,
2984 "totalPages": 2
2986 "status" : []
2988 "result": {
2989 "mapId": "id",
2990 "name": "Some map",
2991 "type": "Genetic",
2992 "unit": "cM",
2993 "linkageGroups": [
2995 "linkageGroupId": 1,
2996 "numberMarkers": 100000,
2997 "maxPosition": 10000000
3000 "linkageGroupId": 2,
3001 "numberMarkers": 1247,
3002 "maxPostion": 12347889
3007 Args:
3008 Side Effects:
3010 =cut
3012 sub maps_single : Chained('brapi') PathPart('maps') CaptureArgs(1) {
3013 my $self = shift;
3014 my $c = shift;
3015 my $map_id = shift;
3017 $c->stash->{map_id} = $map_id;
3021 sub maps_details : Chained('maps_single') PathPart('') Args(0) : ActionClass('REST') { }
3023 sub maps_details_POST {
3024 my $self = shift;
3025 my $c = shift;
3026 #my $auth = _authenticate_user($c);
3029 sub maps_details_GET {
3030 my $self = shift;
3031 my $c = shift;
3032 my ($auth) = _authenticate_user($c);
3033 my $clean_inputs = $c->stash->{clean_inputs};
3034 my $brapi = $self->brapi_module;
3035 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3036 my $brapi_package_result = $brapi_module->detail(
3037 $c->stash->{map_id}
3039 _standard_response_construction($c, $brapi_package_result);
3043 =head2 brapi/v1/maps/<map_id>/position?linkageGroupIdList=1,2,3
3045 Usage: To retrieve marker position data for a species map_id. Can provide a list of linkage groups (e.g. chromosomes) to narrow result set.
3046 Desc:
3047 Return JSON example:
3049 "metadata" : {
3050 "pagination" : { "pageSize": 30, "currentPage": 2, "totalCount": 40, "totalPages":2 },
3051 "status: []
3053 "result": {
3054 "data" : [
3056 "markerDbId": 1,
3057 "markerName": "marker1",
3058 "location": "1000",
3059 "linkageGroup": "1A"
3060 }, {
3061 "markerDbId": 2,
3062 "markerName": "marker2",
3063 "location": "1001",
3064 "linkageGroup": "1A"
3069 Args:
3070 Side Effects:
3072 =cut
3074 sub maps_marker_detail : Chained('maps_single') PathPart('positions') Args(0) : ActionClass('REST') { }
3076 sub maps_marker_detail_POST {
3077 my $self = shift;
3078 my $c = shift;
3079 #my $auth = _authenticate_user($c);
3082 sub maps_marker_detail_GET {
3083 my $self = shift;
3084 my $c = shift;
3085 my ($auth) = _authenticate_user($c);
3086 my $clean_inputs = $c->stash->{clean_inputs};
3087 my $brapi = $self->brapi_module;
3088 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3089 my $brapi_package_result = $brapi_module->positions({
3090 map_id => $c->stash->{map_id},
3091 linkage_group_ids => $clean_inputs->{linkageGroupId},
3092 min => $clean_inputs->{min}->[0],
3093 max => $clean_inputs->{max}->[0],
3095 _standard_response_construction($c, $brapi_package_result);
3098 sub maps_marker_linkagegroup_detail : Chained('maps_single') PathPart('positions') Args(1) : ActionClass('REST') { }
3100 sub maps_marker_linkagegroup_detail_GET {
3101 my $self = shift;
3102 my $c = shift;
3103 my $linkage_group_id = shift;
3104 my ($auth) = _authenticate_user($c);
3105 my $clean_inputs = $c->stash->{clean_inputs};
3106 my $brapi = $self->brapi_module;
3107 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3108 my $brapi_package_result = $brapi_module->positions({
3109 map_id => $c->stash->{map_id},
3110 linkage_group_ids => [$linkage_group_id],
3111 min => $clean_inputs->{min}->[0],
3112 max => $clean_inputs->{max}->[0],
3114 _standard_response_construction($c, $brapi_package_result);
3117 =head2 brapi/v2/maps/map_id/linkagegroups
3118 =cut
3120 sub maps_marker_detail_lg : Chained('maps_single') PathPart('linkagegroups') Args(0) : ActionClass('REST') { }
3122 sub maps_marker_detail_lg_GET {
3123 my $self = shift;
3124 my $c = shift;
3125 my ($auth) = _authenticate_user($c);
3126 my $clean_inputs = $c->stash->{clean_inputs};
3127 my $brapi = $self->brapi_module;
3128 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3129 my $brapi_package_result = $brapi_module->linkagegroups({
3130 map_id => $c->stash->{map_id},
3131 linkage_group_ids => $clean_inputs->{linkageGroupId},
3132 min => $clean_inputs->{min}->[0],
3133 max => $clean_inputs->{max}->[0],
3135 _standard_response_construction($c, $brapi_package_result);
3138 =head2 brapi/v2/markerpositions
3139 =cut
3141 sub maps_markerpositions : Chained('brapi') PathPart('markerpositions') Args(0) : ActionClass('REST') { }
3143 sub maps_markerpositions_GET {
3144 my $self = shift;
3145 my $c = shift;
3146 my ($auth) = _authenticate_user($c);
3147 my $clean_inputs = $c->stash->{clean_inputs};
3148 my $brapi = $self->brapi_module;
3149 my $brapi_module = $brapi->brapi_wrapper('MarkerPositions');
3150 my $brapi_package_result = $brapi_module->search({
3151 mapDbId => $clean_inputs->{mapDbId},
3152 variantDbId => $clean_inputs->{variantDbId},
3153 linkageGroupName => $clean_inputs->{linkageGroupName},
3154 maxPosition => $clean_inputs->{maxPosition},
3155 minPosition => $clean_inputs->{minPosition},
3156 }, $c );
3157 _standard_response_construction($c, $brapi_package_result);
3160 sub maps_markerpositions_save : Chained('brapi') PathPart('search/markerpositions') Args(0) : ActionClass('REST') { }
3162 sub maps_markerpositions_save_POST {
3163 my $self = shift;
3164 my $c = shift;
3165 save_results($self,$c,$c->stash->{clean_inputs},'MarkerPositions');
3168 sub maps_markerpositions_retrieve : Chained('brapi') PathPart('search/markerpositions') Args(1) {
3169 my $self = shift;
3170 my $c = shift;
3171 my $search_id = shift;
3172 retrieve_results($self, $c, $search_id, 'MarkerPositions');
3175 =head2 brapi/<version>/locations
3177 Usage: To retrieve locations.
3178 Desc:
3179 Return JSON example:
3180 Args:
3181 Side Effects:
3183 =cut
3185 sub locations_list : Chained('brapi') PathPart('locations') Args(0) : ActionClass('REST') { }
3187 sub locations_list_POST {
3188 my $self = shift;
3189 my $c = shift;
3190 my ($auth,$user_id) = _authenticate_user($c);
3191 my $clean_inputs = $c->stash->{clean_inputs};
3192 my $data = $clean_inputs;
3193 my @all_locations;
3194 foreach my $location (values %{$data}) {
3195 push @all_locations, $location;
3197 my $brapi = $self->brapi_module;
3198 my $brapi_module = $brapi->brapi_wrapper('Locations');
3199 my $brapi_package_result = $brapi_module->store(\@all_locations,$user_id);
3200 _standard_response_construction($c, $brapi_package_result);
3203 sub locations_list_GET {
3204 my $self = shift;
3205 my $c = shift;
3206 my ($auth) = _authenticate_user($c);
3207 my $clean_inputs = $c->stash->{clean_inputs};
3208 my $brapi = $self->brapi_module;
3209 my $brapi_module = $brapi->brapi_wrapper('Locations');
3210 my $brapi_package_result = $brapi_module->search($clean_inputs);
3211 _standard_response_construction($c, $brapi_package_result);
3214 sub locations_detail : Chained('brapi') PathPart('locations') Args(1) : ActionClass('REST') { }
3216 sub locations_detail_GET {
3217 my $self = shift;
3218 my $c = shift;
3219 my $location_id = shift;
3220 my ($auth) = _authenticate_user($c);
3221 my $clean_inputs = $c->stash->{clean_inputs};
3222 my $brapi = $self->brapi_module;
3223 my $brapi_module = $brapi->brapi_wrapper('Locations');
3224 my $brapi_package_result = $brapi_module->detail($location_id);
3225 _standard_response_construction($c, $brapi_package_result);
3228 sub locations_detail_PUT {
3229 my $self = shift;
3230 my $c = shift;
3231 my $location_id = shift;
3232 my ($auth,$user_id) = _authenticate_user($c);
3233 my $clean_inputs = $c->stash->{clean_inputs};
3234 my $data = $clean_inputs;
3235 my @all_locations;
3236 $data->{locationDbId} = $location_id;
3237 push @all_locations, $data;
3238 my $brapi = $self->brapi_module;
3239 my $brapi_module = $brapi->brapi_wrapper('Locations');
3240 my $brapi_package_result = $brapi_module->store(\@all_locations,$user_id);
3241 # Format the response to be single hash
3242 $brapi_package_result->{result} = $brapi_package_result->{result}->{data}[0];
3243 _standard_response_construction($c, $brapi_package_result);
3246 sub locations_search_save : Chained('brapi') PathPart('search/locations') Args(0) : ActionClass('REST') { }
3248 sub locations_search_save_POST {
3249 my $self = shift;
3250 my $c = shift;
3251 save_results($self,$c,$c->stash->{clean_inputs},'Locations');
3254 sub locations_search_retrieve : Chained('brapi') PathPart('search/locations') Args(1) {
3255 my $self = shift;
3256 my $c = shift;
3257 my $search_id = shift;
3258 retrieve_results($self, $c, $search_id, 'Locations');
3261 sub observationvariable_data_type_list : Chained('brapi') PathPart('variables/datatypes') Args(0) : ActionClass('REST') { }
3263 sub observationvariable_data_type_list_POST {
3264 my $self = shift;
3265 my $c = shift;
3266 #my $auth = _authenticate_user($c);
3269 sub observationvariable_data_type_list_GET {
3270 my $self = shift;
3271 my $c = shift;
3272 my ($auth) = _authenticate_user($c);
3273 my $clean_inputs = $c->stash->{clean_inputs};
3274 my $brapi = $self->brapi_module;
3275 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3276 my $brapi_package_result = $brapi_module->observation_variable_data_types();
3277 _standard_response_construction($c, $brapi_package_result);
3280 sub observationvariable_ontologies : Chained('brapi') PathPart('ontologies') Args(0) : ActionClass('REST') { }
3282 sub observationvariable_ontologies_POST {
3283 my $self = shift;
3284 my $c = shift;
3285 #my $auth = _authenticate_user($c);
3288 sub observationvariable_ontologies_GET {
3289 my $self = shift;
3290 my $c = shift;
3291 my ($auth) = _authenticate_user($c);
3293 #Using code pattern found in SGN::Controller::Ontology->onto_browser
3294 my $onto_root_namespaces = $c->config->{onto_root_namespaces};
3295 my @namespaces = split ", ", $onto_root_namespaces;
3296 foreach my $n (@namespaces) {
3297 $n =~ s/\s*(\w+)\s*\(.*\)/$1/g;
3299 #print STDERR Dumper \@namespaces;
3301 my $clean_inputs = $c->stash->{clean_inputs};
3302 my $brapi = $self->brapi_module;
3303 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3304 my $brapi_package_result = $brapi_module->observation_variable_ontologies({
3305 name_spaces => \@namespaces,
3306 ontologyDbId => $clean_inputs->{ontologyDbId}
3308 _standard_response_construction($c, $brapi_package_result);
3311 sub observationvariable_search : Chained('brapi') PathPart('variables-search') Args(0) : ActionClass('REST') { }
3313 sub observationvariable_search_POST {
3314 my $self = shift;
3315 my $c = shift;
3316 _observationvariable_search_process($self, $c);
3319 sub observationvariable_search_GET {
3320 my $self = shift;
3321 my $c = shift;
3322 _observationvariable_search_process($self, $c);
3325 sub _observationvariable_search_process {
3326 my $self = shift;
3327 my $c = shift;
3328 # my ($auth) = _authenticate_user($c);
3330 my $clean_inputs = $c->stash->{clean_inputs};
3331 my $brapi = $self->brapi_module;
3332 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3333 my $brapi_package_result = $brapi_module->search({
3334 observationvariable_db_ids => $clean_inputs->{observationVariableDbId},
3335 ontology_db_names => $clean_inputs->{ontologyXref},
3336 ontology_dbxref_terms => $clean_inputs->{ontologyDbId},
3337 method_db_ids => $clean_inputs->{methodDbId},
3338 scale_db_ids => $clean_inputs->{scaleDbId},
3339 observationvariable_names => $clean_inputs->{name},
3340 observationvariable_datatypes => $clean_inputs->{datatype},
3341 observationvariable_classes => $clean_inputs->{traitClass},
3342 studyDbIds => $clean_inputs->{studyDbId},
3343 }, $c);
3344 _standard_response_construction($c, $brapi_package_result);
3347 sub variables_search_save : Chained('brapi') PathPart('search/variables') Args(0) : ActionClass('REST') { }
3349 sub variables_search_save_POST {
3350 my $self = shift;
3351 my $c = shift;
3352 save_results($self,$c,$c->stash->{clean_inputs},'ObservationVariables');
3355 sub variables_search_retrieve : Chained('brapi') PathPart('search/variables') Args(1) {
3356 my $self = shift;
3357 my $c = shift;
3358 my $search_id = shift;
3359 retrieve_results($self, $c, $search_id, 'ObservationVariables');
3362 sub observationvariable_list : Chained('brapi') PathPart('variables') Args(0) : ActionClass('REST') { }
3364 sub observationvariable_list_GET {
3365 my $self = shift;
3366 my $c = shift;
3367 my ($auth) = _authenticate_user($c);
3368 my $clean_inputs = $c->stash->{clean_inputs};
3369 my $supported_crop = $c->config->{'supportedCrop'};
3370 my $brapi = $self->brapi_module;
3371 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3372 my $brapi_package_result = $brapi_module->search({
3373 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
3374 traitClasses => $clean_inputs->{traitClass},
3375 studyDbIds => $clean_inputs->{studyDbId},
3376 externalReferenceIDs => $clean_inputs->{externalReferenceID},
3377 externalReferenceSources => $clean_inputs->{externalReferenceSource},
3378 supportedCrop =>$supported_crop,
3379 }, $c);
3380 _standard_response_construction($c, $brapi_package_result);
3383 sub observationvariable_detail : Chained('brapi') PathPart('variables') Args(1) : ActionClass('REST') { }
3385 sub observationvariable_detail_GET {
3386 my $self = shift;
3387 my $c = shift;
3388 my $trait_id = shift;
3389 my ($auth) = _authenticate_user($c);
3390 my $clean_inputs = $c->stash->{clean_inputs};
3391 my $supported_crop = $c->config->{'supportedCrop'};
3392 my $brapi = $self->brapi_module;
3393 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3394 my $brapi_package_result = $brapi_module->detail(
3395 $trait_id,$c
3397 _standard_response_construction($c, $brapi_package_result);
3401 sub samples_list : Chained('brapi') PathPart('samples-search') Args(0) : ActionClass('REST') { }
3403 sub samples_list_POST {
3404 my $self = shift;
3405 my $c = shift;
3406 _sample_search_process($self, $c);
3409 sub samples_list_GET {
3410 my $self = shift;
3411 my $c = shift;
3412 _sample_search_process($self, $c);
3415 sub _sample_search_process {
3416 my $self = shift;
3417 my $c = shift;
3418 # my ($auth) = _authenticate_user($c);
3419 my $clean_inputs = $c->stash->{clean_inputs};
3420 my $brapi = $self->brapi_module;
3421 my $brapi_module = $brapi->brapi_wrapper('Samples');
3422 my $brapi_package_result = $brapi_module->search({
3423 sampleDbId => $clean_inputs->{sampleDbId},
3424 sampleName => $clean_inputs->{sampleName},
3425 plateDbId => $clean_inputs->{plateDbId},
3426 plateName => $clean_inputs->{plateName},
3427 germplasmDbId => $clean_inputs->{germplasmDbId},
3428 germplasmName => $clean_inputs->{germplasmName},
3429 observationUnitDbId => $clean_inputs->{observationUnitDbId},
3430 observationUnitName => $clean_inputs->{observationUnitName},
3432 _standard_response_construction($c, $brapi_package_result);
3435 sub samples : Chained('brapi') PathPart('samples') Args(0) : ActionClass('REST') { }
3437 sub samples_GET {
3438 my $self = shift;
3439 my $c = shift;
3440 my $auth = _authenticate_user($c);
3441 my $clean_inputs = $c->stash->{clean_inputs};
3442 my $brapi = $self->brapi_module;
3443 my $brapi_module = $brapi->brapi_wrapper('Samples');
3444 my $brapi_package_result = $brapi_module->search($clean_inputs);
3445 _standard_response_construction($c, $brapi_package_result);
3448 sub samples_list_search : Chained('brapi') PathPart('search/samples') Args(0) : ActionClass('REST') { }
3450 sub samples_list_search_POST {
3451 my $self = shift;
3452 my $c = shift;
3453 save_results($self,$c,$c->stash->{clean_inputs},'Samples');
3456 sub samples_list_search_retrieve : Chained('brapi') PathPart('search/samples') Args(1) {
3457 my $self = shift;
3458 my $c = shift;
3459 my $search_id = shift;
3460 retrieve_results($self, $c, $search_id, 'Samples');
3464 =head2 brapi/v1/samples/<sampleDbId>
3466 Usage: To retrieve details for a specific sample
3467 Desc:
3468 Return JSON example:
3470 "metadata": {
3471 "pagination" : {
3472 "pageSize":0,
3473 "currentPage":0,
3474 "totalCount":0,
3475 "totalPages":0
3477 "status" : [],
3478 "datafiles": []
3480 "result": {
3481 "sampleDbId": "Unique-Plant-SampleID",
3482 "observationUnitDbId": "abc123",
3483 "germplasmDbId": "def456",
3484 "studyDbId": "StudyId-123",
3485 "plotDbId": "PlotId-123",
3486 "plantDbId" : "PlantID-123",
3487 "plateDbId": "PlateID-123",
3488 "plateIndex": 0,
3489 "takenBy": "Mr. Technician",
3490 "sampleTimestamp": "2016-07-27T14:43:22+0100",
3491 "sampleType" : "TypeOfSample",
3492 "tissueType" : "TypeOfTissue",
3493 "notes": "Cut from infected leaf",
3496 =cut
3498 sub samples_single : Chained('brapi') PathPart('samples') CaptureArgs(1) {
3499 my $self = shift;
3500 my $c = shift;
3501 my $sample_id = shift;
3503 $c->stash->{sample_id} = $sample_id;
3507 sub sample_details : Chained('samples_single') PathPart('') Args(0) : ActionClass('REST') { }
3509 sub sample_details_POST {
3510 my $self = shift;
3511 my $c = shift;
3512 #my $auth = _authenticate_user($c);
3515 sub sample_details_GET {
3516 my $self = shift;
3517 my $c = shift;
3518 my ($auth) = _authenticate_user($c);
3519 my $clean_inputs = $c->stash->{clean_inputs};
3520 my $brapi = $self->brapi_module;
3521 my $brapi_module = $brapi->brapi_wrapper('Samples');
3522 my $brapi_package_result = $brapi_module->detail(
3523 $c->stash->{sample_id}
3525 _standard_response_construction($c, $brapi_package_result);
3532 sub authenticate : Chained('brapi') PathPart('authenticate/oauth') Args(0) {
3533 my $self = shift;
3534 my $c = shift;
3536 my $host = $c->config->{main_production_site_url};
3537 $c->res->redirect("https://accounts.google.com/o/oauth2/auth?scope=profile&response_type=code&client_id=1068256137120-62dvk8sncnbglglrmiroms0f5d7lg111.apps.googleusercontent.com&redirect_uri=$host/oauth2callback");
3539 $c->stash->{rest} = { success => 1 };
3544 =head2 brapi/v1/phenotypes
3546 Usage: To store phenotypes
3547 Desc:
3548 Request body example:
3550 "data": [
3552 "observationUnitDbId": "observationUnitDbId0",
3553 "observations": [
3555 "collector": "collector0",
3556 "observationDbId": "observationDbId0",
3557 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3558 "observationVariableDbId": "observationVariableDbId0",
3559 "observationVariableName": "observationVariableName0",
3560 "season": "season0",
3561 "value": "value0"
3564 "collector": "collector1",
3565 "observationDbId": "observationDbId1",
3566 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3567 "observationVariableDbId": "observationVariableDbId1",
3568 "observationVariableName": "observationVariableName1",
3569 "season": "season1",
3570 "value": "value1"
3573 "studyDbId": "studyDbId0"
3576 "observationUnitDbId": "observationUnitDbId1",
3577 "observations": [
3579 "collector": "collector0",
3580 "observationDbId": "observationDbId0",
3581 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3582 "observationVariableDbId": "observationVariableDbId0",
3583 "observationVariableName": "observationVariableName0",
3584 "season": "season0",
3585 "value": "value0"
3588 "collector": "collector1",
3589 "observationDbId": "observationDbId1",
3590 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3591 "observationVariableDbId": "observationVariableDbId1",
3592 "observationVariableName": "observationVariableName1",
3593 "season": "season1",
3594 "value": "value1"
3597 "studyDbId": "studyDbId1"
3602 Response JSON example:
3604 "metadata": {
3605 "datafiles": [],
3606 "pagination": {
3607 "currentPage": 0,
3608 "pageSize": 1000,
3609 "totalCount": 2,
3610 "totalPages": 1
3612 "status": []
3614 "result": {
3615 "data": [
3617 "germplasmDbId": "8383",
3618 "germplasmName": "Pahang",
3619 "observationDbId": "12345",
3620 "observationLevel": "plot",
3621 "observationTimestamp": "2015-11-05T15:12:56+01:00",
3622 "observationUnitDbId": "11",
3623 "observationUnitName": "ZIPA_68_Ibadan_2014",
3624 "observationVariableDbId": "CO_334:0100632",
3625 "observationVariableName": "Yield",
3626 "operator": "Jane Doe",
3627 "studyDbId": "35",
3628 "uploadedBy": "dbUserId",
3629 "value": "5"
3634 Args:
3635 Side Effects:
3637 =cut
3639 sub phenotypes : Chained('brapi') PathPart('phenotypes') Args(0) : ActionClass('REST') { }
3641 sub phenotypes_POST {
3642 my $self = shift;
3643 my $c = shift;
3644 my $clean_inputs = $c->stash->{clean_inputs};
3645 my $data = $clean_inputs->{data};
3646 my @all_observations;
3647 foreach my $observationUnit (@{$data}) {
3648 my $observationUnitDbId = $observationUnit->{observationUnitDbId};
3649 my $observations = $observationUnit->{observations};
3650 foreach my $observation (@{$observations}) {
3651 $observation->{observationUnitDbId} = $observationUnitDbId;
3652 push @all_observations, $observation;
3655 save_observation_results($self, $c, \@all_observations, 'v1');
3658 =head2 brapi/v2/observations
3660 Usage: To store observations
3661 Desc:
3662 Request body example:
3664 "observations": [
3666 "collector": "string", //optional
3667 "observationDbId": "string", // if populated then update existing otherwise add new
3668 "observationTimeStamp": "2018-06-19T18:59:45.751Z", //optional
3669 "observationUnitDbId": "string", //required
3670 "observationVariableDbId": "string", //required
3671 "value": "string" //required
3675 Response JSON example:
3677 "metadata": {
3678 "datafiles": [],
3679 "pagination": {
3680 "currentPage": 0,
3681 "pageSize": 1000,
3682 "totalCount": 2,
3683 "totalPages": 1
3685 "status": []
3687 "result": {
3688 "data": [
3690 "germplasmDbId": "8383",
3691 "germplasmName": "Pahang",
3692 "observationDbId": "12345",
3693 "observationLevel": "plot",
3694 "observationTimestamp": "2015-11-05T15:12:56+01:00",
3695 "observationUnitDbId": "11",
3696 "observationUnitName": "ZIPA_68_Ibadan_2014",
3697 "observationVariableDbId": "CO_334:0100632",
3698 "observationVariableName": "Yield",
3699 "operator": "Jane Doe",
3700 "studyDbId": "35",
3701 "uploadedBy": "dbUserId",
3702 "value": "5"
3707 Args:
3708 Side Effects:
3710 =cut
3712 sub observations : Chained('brapi') PathPart('observations') Args(0) : ActionClass('REST') { }
3714 sub observations_PUT {
3715 my $self = shift;
3716 my $c = shift;
3717 my $version = $c->request->captures->[0];
3718 my $brapi_package_result;
3719 if ($version eq 'v2'){
3720 my $force_authenticate = 1;
3721 my ($auth,$user_id,$user_type) = _authenticate_user($c,$force_authenticate);
3722 my $clean_inputs = $c->stash->{clean_inputs};
3723 my %observations = %$clean_inputs;
3724 my @all_observations;
3725 foreach my $observation (keys %observations) {
3726 my $observationDbId = $observation;
3727 my $observations = $observations{$observation};
3728 $observations->{observationDbId} = $observationDbId;
3729 push @all_observations, $observations;
3731 my $brapi = $self->brapi_module;
3732 my $brapi_module = $brapi->brapi_wrapper('Observations');
3733 $brapi_package_result = $brapi_module->observations_store({
3734 observations => \@all_observations,
3735 user_id => $user_id,
3736 user_type => $user_type,
3737 overwrite => 1,
3738 },$c);
3739 } elsif ($version eq 'v1'){
3740 my $clean_inputs = $c->stash->{clean_inputs};
3741 my $observations = $clean_inputs->{observations};
3742 save_observation_results($self, $c, $observations, 'v1');
3745 my $status = $brapi_package_result->{status};
3746 my $http_status_code = _get_http_status_code($status);
3748 _standard_response_construction($c, $brapi_package_result, $http_status_code);
3751 sub observations_GET {
3752 my $self = shift;
3753 my $c = shift;
3754 my $auth = _authenticate_user($c);
3755 my $clean_inputs = $c->stash->{clean_inputs};
3756 my $brapi = $self->brapi_module;
3757 my $brapi_module = $brapi->brapi_wrapper('Observations');
3758 my $brapi_package_result = $brapi_module->search({
3759 observationLevel => $clean_inputs->{observationLevel},
3760 seasonDbId => $clean_inputs->{seasonDbId},
3761 locationDbId => $clean_inputs->{locationDbId},
3762 studyDbId => $clean_inputs->{studyDbId},
3763 germplasmDbId => $clean_inputs->{germplasmDbId},
3764 programDbId => $clean_inputs->{programDbId},
3765 observationTimeStampRangeStart => $clean_inputs->{observationTimeStampRangeStart},
3766 observationTimeStampRangeEnd => $clean_inputs->{observationTimeStampRangeEnd},
3767 observationUnitDbId => $clean_inputs->{observationUnitDbId},
3768 observationDbId => $clean_inputs->{observationDbId}
3771 _standard_response_construction($c, $brapi_package_result);
3774 sub observations_POST {
3775 my $self = shift;
3776 my $c = shift;
3777 my $force_authenticate = 1;
3778 my ($auth,$user_id,$user_type) = _authenticate_user($c, $force_authenticate);
3779 my $clean_inputs = $c->stash->{clean_inputs};
3780 my $data = $clean_inputs;
3781 my @all_observations;
3782 foreach my $observation (values %{$data}) {
3783 push @all_observations, $observation;
3785 my $brapi = $self->brapi_module;
3786 my $brapi_module = $brapi->brapi_wrapper('Observations');
3787 my $brapi_package_result = $brapi_module->observations_store({
3788 observations => \@all_observations,
3789 user_id => $user_id,
3790 user_type => $user_type,
3791 },$c);
3793 my $status = $brapi_package_result->{status};
3794 my $http_status_code = _get_http_status_code($status);
3796 _standard_response_construction($c, $brapi_package_result, $http_status_code);
3799 sub observations_table : Chained('brapi') PathPart('observations/table') Args(0) : ActionClass('REST') { }
3801 sub observations_table_GET {
3802 my $self = shift;
3803 my $c = shift;
3804 my ($auth) = _authenticate_user($c);
3805 my $clean_inputs = $c->stash->{clean_inputs};
3806 my $brapi = $self->brapi_module;
3807 my $brapi_module = $brapi->brapi_wrapper('ObservationTables');
3808 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
3809 _standard_response_construction($c, $brapi_package_result);
3812 sub observations_single : Chained('brapi') PathPart('observations') CaptureArgs(1) {
3813 my $self = shift;
3814 my $c = shift;
3815 print STDERR " Capturing id\n";
3816 $c->stash->{observation_id} = shift;
3819 sub observations_detail : Chained('observations_single') PathPart('') Args(0) ActionClass('REST') { }
3821 sub observations_detail_GET {
3822 my $self = shift;
3823 my $c = shift;
3824 my $clean_inputs = $c->stash->{clean_inputs};
3825 my $brapi = $self->brapi_module;
3826 my $brapi_module = $brapi->brapi_wrapper('Observations');
3827 my $brapi_package_result = $brapi_module->detail({
3828 observationDbId => $c->stash->{observation_id}
3830 _standard_response_construction($c, $brapi_package_result);
3833 sub observations_detail_PUT {
3834 my $self = shift;
3835 my $c = shift;
3836 my ($auth,$user_id,$user_type) = _authenticate_user($c);
3837 my $clean_inputs = $c->stash->{clean_inputs};
3838 my $observations = $clean_inputs;
3839 my @all_observations;
3840 $observations->{observationDbId} = $c->stash->{observation_id};
3841 push @all_observations, $observations;
3843 my $brapi = $self->brapi_module;
3844 my $brapi_module = $brapi->brapi_wrapper('Observations');
3845 my $brapi_package_result = $brapi_module->observations_store({
3846 observations => \@all_observations,
3847 user_id => $user_id,
3848 user_type => $user_type,
3849 },$c);
3852 my $status = $brapi_package_result->{status};
3853 my $http_status_code = _get_http_status_code($status);
3855 _standard_response_construction($c, $brapi_package_result, $http_status_code);
3858 sub observation_search_save : Chained('brapi') PathPart('search/observations') Args(0) : ActionClass('REST') { }
3860 sub observation_search_save_POST {
3861 my $self = shift;
3862 my $c = shift;
3863 save_results($self,$c,$c->stash->{clean_inputs},'Observations');
3866 sub observation_search_retrieve : Chained('brapi') PathPart('search/observations') Args(1) {
3867 my $self = shift;
3868 my $c = shift;
3869 my $search_id = shift;
3870 retrieve_results($self, $c, $search_id, 'Observations');
3873 sub save_observation_results {
3874 my $self = shift;
3875 my $c = shift;
3876 my $observations = shift;
3877 my $version = shift;
3879 # Check that the user is a user. We don't check other permissions for now.
3880 my $force_authenticate = 1;
3881 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
3883 my $dbh = $c->dbc->dbh;
3884 my $p = CXGN::People::Person->new($dbh, $user_id);
3885 my $username = $p->get_username;
3886 my $clean_inputs = $c->stash->{clean_inputs};
3887 my $brapi = $self->brapi_module;
3889 my $dir = $c->tempfiles_subdir('/delete_nd_experiment_ids');
3890 my $temp_file_nd_experiment_id = $c->config->{basepath}."/".$c->tempfile( TEMPLATE => 'delete_nd_experiment_ids/fileXXXX');
3892 my $brapi_module = $brapi->brapi_wrapper('Observations');
3893 my $brapi_package_result = $brapi_module->observations_store({
3894 observations => $observations,
3895 user_id => $user_id,
3896 username => $username,
3897 user_type => $user_type,
3898 version => $version,
3899 archive_path => $c->config->{archive_path},
3900 tempfiles_subdir => $c->config->{basepath}."/".$c->config->{tempfiles_subdir},
3901 basepath => $c->config->{basepath},
3902 dbhost => $c->config->{dbhost},
3903 dbname => $c->config->{dbname},
3904 dbuser => $c->config->{dbuser},
3905 dbpass => $c->config->{dbpass},
3906 temp_file_nd_experiment_id => $temp_file_nd_experiment_id
3907 },$c);
3909 my $status = $brapi_package_result->{status};
3910 my $http_status_code = _get_http_status_code($status);
3912 _standard_response_construction($c, $brapi_package_result, $http_status_code);
3915 =head2 brapi/v1/markers
3917 Usage: To retrieve markers
3918 Desc: BrAPI v1.3
3919 Args:
3920 Side Effects: deprecated on BrAPI v2.0
3922 =cut
3924 sub markers_search : Chained('brapi') PathPart('markers') Args(0) : ActionClass('REST') { }
3926 sub markers_search_GET {
3927 my $self = shift;
3928 my $c = shift;
3929 my ($auth) = _authenticate_user($c);
3930 my $clean_inputs = $c->stash->{clean_inputs};
3931 my $brapi = $self->brapi_module;
3932 my $brapi_module = $brapi->brapi_wrapper('Markers');
3933 my $brapi_package_result = $brapi_module->search();
3934 _standard_response_construction($c, $brapi_package_result);
3937 sub markers_search_save : Chained('brapi') PathPart('search/markers') Args(0) : ActionClass('REST') { }
3939 sub markers_search_save_POST {
3940 my $self = shift;
3941 my $c = shift; #print "--\n-" ; print Dumper($self); print "--\n-" ;
3942 save_results($self,$c,$c->stash->{clean_inputs},'Markers');
3945 sub markers_search_retrieve : Chained('brapi') PathPart('search/markers') Args(1) {
3946 my $self = shift;
3947 my $c = shift;
3948 my $search_id = shift;
3949 retrieve_results($self, $c, $search_id, 'Markers');
3953 =head2 brapi/v2/variants
3955 Usage: To retrieve variants
3956 Desc: BrAPI v2.0
3957 Args:
3958 Side Effects:
3960 =cut
3962 sub variants_search : Chained('brapi') PathPart('variants') Args(0) : ActionClass('REST') { }
3964 sub variants_search_GET {
3965 my $self = shift;
3966 my $c = shift;
3967 my ($auth) = _authenticate_user($c);
3968 my $clean_inputs = $c->stash->{clean_inputs};
3969 my $brapi = $self->brapi_module;
3970 my $brapi_module = $brapi->brapi_wrapper('Variants');
3971 my $brapi_package_result = $brapi_module->search($clean_inputs);
3972 _standard_response_construction($c, $brapi_package_result);
3975 sub variants_single : Chained('brapi') PathPart('variants') CaptureArgs(1) {
3976 my $self = shift;
3977 my $c = shift;
3978 print STDERR " Capturing variants id\n";
3979 $c->stash->{variants_id} = shift;
3982 sub variants_detail : Chained('variants_single') PathPart('') Args(0) ActionClass('REST') { }
3984 sub variants_detail_GET {
3985 my $self = shift;
3986 my $c = shift;
3987 my $clean_inputs = $c->stash->{clean_inputs};
3988 my $brapi = $self->brapi_module;
3989 my $brapi_module = $brapi->brapi_wrapper('Variants');
3990 my $brapi_package_result = $brapi_module->detail({
3991 variantDbId => $c->stash->{variants_id}
3993 _standard_response_construction($c, $brapi_package_result);
3996 sub variants_calls_detail : Chained('variants_single') PathPart('calls') Args(0) : ActionClass('REST') { }
3998 sub variants_calls_detail_POST {
3999 my $self = shift;
4000 my $c = shift;
4001 #my $auth = _authenticate_user($c);
4004 sub variants_calls_detail_GET {
4005 my $self = shift;
4006 my $c = shift;
4007 my ($auth) = _authenticate_user($c);
4008 my $clean_inputs = $c->stash->{clean_inputs};
4009 my $brapi = $self->brapi_module;
4010 my $brapi_module = $brapi->brapi_wrapper('Variants');
4011 my $brapi_package_result = $brapi_module->calls({
4012 variantDbId => $c->stash->{variants_id},
4013 variantSetDbId => $c->stash->{variantSetDbId},
4014 unknown_string => $clean_inputs->{unknownString}->[0],
4015 sep_phased => $clean_inputs->{sepPhased}->[0],
4016 sep_unphased => $clean_inputs->{sepUnphased}->[0],
4017 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
4019 _standard_response_construction($c, $brapi_package_result);
4022 sub variants_search_save : Chained('brapi') PathPart('search/variants') Args(0) : ActionClass('REST') { }
4024 sub variants_search_save_POST {
4025 my $self = shift;
4026 my $c = shift;
4027 save_results($self,$c,$c->stash->{clean_inputs},'Variants');
4030 sub variants_search_retrieve : Chained('brapi') PathPart('search/variants') Args(1) {
4031 my $self = shift;
4032 my $c = shift;
4033 my $search_id = shift;
4034 retrieve_results($self, $c, $search_id, 'Variants');
4038 =head2 brapi/v1/observations-search
4040 Usage: To retrieve observations
4041 Desc:
4042 Request body example:
4044 "collector": ["string","string"], //optional
4045 "observationDbId": ["string","string"], //optional
4046 "observationUnitDbId": ["string","string"], //optional
4047 "observationVariableDbId": ["string","string"] //optional
4049 Response JSON example:
4051 "metadata": {
4052 "datafiles": [],
4053 "pagination": {
4054 "currentPage": 0,
4055 "pageSize": 1000,
4056 "totalCount": 2,
4057 "totalPages": 1
4059 "status": []
4061 "result": {
4062 "data": [
4064 "germplasmDbId": "8383",
4065 "germplasmName": "Pahang",
4066 "observationDbId": "12345",
4067 "observationLevel": "plot",
4068 "observationTimestamp": "2015-11-05T15:12:56+01:00",
4069 "observationUnitDbId": "11",
4070 "observationUnitName": "ZIPA_68_Ibadan_2014",
4071 "observationVariableDbId": "CO_334:0100632",
4072 "observationVariableName": "Yield",
4073 "operator": "Jane Doe",
4074 "studyDbId": "35",
4075 "uploadedBy": "dbUserId",
4076 "value": "5"
4081 Args:
4082 Side Effects:
4084 =cut
4086 sub observations_search : Chained('brapi') PathPart('observations-search') Args(0) : ActionClass('REST') { }
4088 sub observations_search_POST {
4089 my $self = shift;
4090 my $c = shift;
4091 observations_search_process($self, $c);
4094 sub observations_search_GET {
4095 my $self = shift;
4096 my $c = shift;
4097 observations_search_process($self, $c);
4100 sub observations_search_process {
4101 my $self = shift;
4102 my $c = shift;
4103 # my ($auth) = _authenticate_user($c);
4104 my $clean_inputs = $c->stash->{clean_inputs};
4105 my $brapi = $self->brapi_module;
4106 my $brapi_module = $brapi->brapi_wrapper('Observations');
4107 my $brapi_package_result = $brapi_module->search({
4108 collectors => $clean_inputs->{collectors},
4109 observationDbIds => $clean_inputs->{observationDbIds},
4110 observationUnitDbIds => $clean_inputs->{observationUnitDbIds},
4111 observationVariableDbIds => $clean_inputs->{observationVariableDbIds}
4113 _standard_response_construction($c, $brapi_package_result);
4116 =head2 brapi/<version>/events
4117 Usage: To retrieve events (events are treatments/management factors in the database)
4118 Desc:
4119 Request body example:
4122 Response JSON example:
4124 "@context": [
4125 "https://brapi.org/jsonld/context/metadata.jsonld"
4127 "metadata": {
4128 "datafiles": [
4130 "fileDescription": "This is an Excel data file",
4131 "fileMD5Hash": "c2365e900c81a89cf74d83dab60df146",
4132 "fileName": "datafile.xlsx",
4133 "fileSize": 4398,
4134 "fileType": "application/vnd.ms-excel",
4135 "fileURL": "https://wiki.brapi.org/examples/datafile.xlsx"
4138 "pagination": {
4139 "currentPage": 0,
4140 "pageSize": 1000,
4141 "totalCount": 10,
4142 "totalPages": 1
4144 "status": [
4146 "message": "Request accepted, response successful",
4147 "messageType": "INFO"
4151 "result": {
4152 "data": [
4154 "additionalInfo": {},
4155 "date": [
4156 "2018-10-08T18:15:11Z",
4157 "2018-11-09T18:16:12Z"
4159 "eventDbId": "8566d4cb",
4160 "eventDescription": "A set of plots was watered",
4161 "eventParameters": [
4163 "key": "http://www.example.fr/vocabulary/2018#hasContact,",
4164 "value": "http://www.example.fr/id/agent/marie,",
4165 "valueRdfType": "http://xmlns.com/foaf/0.1/Agent,"
4168 "key": "fertilizer",
4169 "value": "nitrogen",
4170 "valueRdfType": null
4173 "eventType": "Watering",
4174 "eventTypeDbId": "4e7d691e",
4175 "observationUnitDbIds": [
4176 "8439eaff",
4177 "d7682e7a",
4178 "305ae51c"
4180 "studyDbId": "2cc2001f"
4185 Args:
4186 Side Effects:
4187 =cut
4189 sub events_search : Chained('brapi') PathPart('events') Args(0) : ActionClass('REST') { }
4191 sub events_search_POST {
4192 my $self = shift;
4193 my $c = shift;
4194 events_search_process($self, $c);
4197 sub events_search_GET {
4198 my $self = shift;
4199 my $c = shift;
4200 events_search_process($self, $c);
4203 sub events_search_process {
4204 my $self = shift;
4205 my $c = shift;
4206 my ($auth) = _authenticate_user($c);
4207 my $clean_inputs = $c->stash->{clean_inputs};
4208 my $brapi = $self->brapi_module;
4209 my $brapi_module = $brapi->brapi_wrapper('Events');
4210 my $brapi_package_result = $brapi_module->search($clean_inputs);
4211 _standard_response_construction($c, $brapi_package_result);
4214 =head2 brapi/<version>/images
4216 Usage: To retrieve observations
4217 Desc:
4218 Request body example:
4221 Response JSON example:
4224 "metadata": {
4225 "datafiles": [
4227 "pagination": {
4228 "currentPage": 0,
4229 "pageSize": 1000,
4230 "totalCount": 10,
4231 "totalPages": 1
4233 "status": [
4235 "message": "Request accepted, response successful",
4236 "messageType": "INFO"
4240 "result": {
4241 "data": [
4243 "additionalInfo": {},
4244 "copyright": "Copyright 2018 Bob Robertson",
4245 "description": "This is a picture of a tomato",
4246 "descriptiveOntologyTerms": [],
4247 "externalReferences": [
4249 "referenceID": "doi:10.155454/12349537E12",
4250 "referenceSource": "DOI"
4253 "imageDbId": "a55efb9c",
4254 "imageFileName": "image_0000231.jpg",
4255 "imageFileSize": 50000,
4256 "imageHeight": 550,
4257 "imageLocation": {
4258 "geometry": {
4259 "coordinates": [
4260 -76.506042,
4261 42.417373,
4264 "type": "Point"
4266 "type": "Feature"
4268 "imageName": "Tomato Image 1",
4269 "imageTimeStamp": "2018-01-01T14:47:23-0600",
4270 "imageURL": "https://wiki.brapi.org/images/tomato",
4271 "imageWidth": 700,
4272 "mimeType": "image/jpeg",
4273 "observationDbIds": [
4274 "d05dd235",
4275 "8875177d"
4277 "observationUnitDbId": "b7e690b6"
4283 Args:
4284 Side Effects:
4286 =cut
4288 sub images : Chained('brapi') PathPart('images') Args(0) : ActionClass('REST') { }
4290 sub images_GET {
4291 my $self = shift;
4292 my $c = shift;
4293 my ($auth) = _authenticate_user($c);
4294 my $clean_inputs = $c->stash->{clean_inputs};
4295 my $brapi = $self->brapi_module;
4296 my $brapi_module = $brapi->brapi_wrapper('Images');
4297 my $brapi_package_result = $brapi_module->search($clean_inputs);
4298 _standard_response_construction($c, $brapi_package_result);
4301 sub images_POST {
4302 my $self = shift;
4303 my $c = shift;
4305 # Check user auth. This matches observations PUT observations endpoint authorization.
4306 # No specific roles are check, just that the user has an account.
4307 my $force_authenticate = 1;
4308 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4310 my $clean_inputs = $c->stash->{clean_inputs};
4311 my @all_images;
4312 foreach my $image (values %{$clean_inputs}) {
4313 push @all_images, $image;
4315 my $brapi = $self->brapi_module;
4316 my $brapi_module = $brapi->brapi_wrapper('Images');
4317 my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir});
4319 my $brapi_package_result = $brapi_module->image_metadata_store(\@all_images, $image_dir, $user_id, $user_type);
4320 my $status = $brapi_package_result->{status};
4321 my $http_status_code = _get_http_status_code($status);
4323 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4326 sub images_by_id : Chained('brapi') PathPart('images') CaptureArgs(1) {
4327 my $self = shift;
4328 my $c = shift;
4329 print STDERR "Images_base... capturing image_id\n";
4330 $c->stash->{image_id} = shift;
4333 sub images_single : Chained('images_by_id') PathPart('') Args(0) ActionClass('REST') { }
4335 sub images_single_GET {
4336 my $self = shift;
4337 my $c = shift;
4338 my $brapi = $self->brapi_module;
4339 my $brapi_module = $brapi->brapi_wrapper('Images');
4340 my $brapi_package_result = $brapi_module->detail( { image_id => $c->stash->{image_id} });
4341 _standard_response_construction($c, $brapi_package_result);
4344 # /brapi/v1/images PUT
4345 # sub image_store : Chained('brapi') PathPart('images') Args(0) ActionClass('REST') { }
4347 sub images_single_PUT {
4348 my $self = shift;
4349 my $c = shift;
4351 # Check user auth. This matches observations PUT observations endpoint authorization.
4352 # No specific roles are check, just that the user has an account.
4353 my $force_authenticate = 1;
4354 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4356 my $clean_inputs = $c->stash->{clean_inputs};
4357 my $image = $clean_inputs;
4358 $image->{imageDbId} = $c->stash->{image_id};
4359 my @all_images;
4360 push @all_images, $image;
4361 my $brapi = $self->brapi_module;
4362 my $brapi_module = $brapi->brapi_wrapper('Images');
4363 my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir});
4364 my $brapi_package_result = $brapi_module->image_metadata_store(\@all_images, $image_dir, $user_id, $user_type, $c->stash->{image_id});
4365 my $status = $brapi_package_result->{status};
4366 my $http_status_code = _get_http_status_code($status);
4368 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4372 # /brapi/v1/images/<image_id>/imagecontent
4373 sub image_content_store : Chained('images_by_id') PathPart('imagecontent') Args(0) ActionClass('REST') { }
4375 sub image_content_store_PUT {
4376 my $self = shift;
4377 my $c = shift;
4379 # Check user auth. This matches observations PUT observations endpoint authorization.
4380 # No specific roles are check, just that the user has an account.
4381 my $force_authenticate = 0;
4382 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4384 my $clean_inputs = $c->stash->{clean_inputs};
4385 print STDERR Dumper($clean_inputs);print Dumper $c->req->body();
4386 my $brapi = $self->brapi_module;
4387 my $brapi_module = $brapi->brapi_wrapper('Images');
4388 my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir});
4390 my $brapi_package_result = $brapi_module->image_data_store($image_dir, $c->stash->{image_id}, $c->req->body(), $c->req->content_type());
4392 my $status = $brapi_package_result->{status};
4393 my $http_status_code = _get_http_status_code($status);
4395 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4398 sub image_search_save : Chained('brapi') PathPart('search/images') Args(0) : ActionClass('REST') { }
4400 sub image_search_save_POST {
4401 my $self = shift;
4402 my $c = shift; #print "--\n-" ; print Dumper($self); print "--\n-" ;
4403 save_results($self,$c,$c->stash->{clean_inputs},'Images');
4406 sub image_search_retrieve : Chained('brapi') PathPart('search/images') Args(1) {
4407 my $self = shift;
4408 my $c = shift;
4409 my $search_id = shift;
4410 retrieve_results($self, $c, $search_id, 'Images');
4413 sub _get_http_status_code {
4414 my $status = shift;
4415 my $http_status_code = 200;
4417 foreach(@$status) {
4419 if ($_->{messageType} eq "403") {
4420 $http_status_code = 403;
4421 last;
4423 elsif ($_->{messageType} eq "401") {
4424 $http_status_code = 401;
4425 last;
4427 elsif ($_->{messageType} eq "400") {
4428 $http_status_code = 400;
4429 last;
4431 elsif ($_->{messageType} eq "200") {
4432 $http_status_code = 200;
4433 last;
4437 return $http_status_code;
4440 =head2 brapi/v2/callsets
4442 Usage: To retrieve data for callsets
4443 Desc:
4444 Return JSON example:
4446 "metadata" : {
4447 "pagination": {
4448 "pageSize": 10,
4449 "currentPage": 1,
4450 "totalCount": 10,
4451 "totalPages": 1
4453 "status": []
4456 "result": {
4457 "data": [
4459 "additionalInfo": {},
4460 "callSetDbId": "eb2bfd3d",
4461 "callSetName": "Sample_123_DNA_Run_456",
4462 "created": "2018-01-01T14:47:23-0600",
4463 "sampleDbId": "5e50e11d",
4464 "studyDbId": "708149c1",
4465 "updated": "2018-01-01T14:47:23-0600",
4466 "variantSetIds": [
4467 "cfd3d60f",
4468 "a4e8bfe9"
4474 Args:
4475 Side Effects:
4477 =cut
4479 sub callsets : Chained('brapi') PathPart('callsets') Args(0) : ActionClass('REST') { }
4481 sub callsets_GET {
4482 my $self = shift;
4483 my $c = shift;
4484 my ($auth) = _authenticate_user($c);
4485 my $clean_inputs = $c->stash->{clean_inputs};
4486 my $brapi = $self->brapi_module;
4487 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4488 my $brapi_package_result = $brapi_module->search({
4489 variantSetDbId => $clean_inputs->{variantSetDbId},
4490 sampleDbId => $clean_inputs->{sampleDbId},
4491 callSetName => $clean_inputs->{callSetName},
4492 # studyDbId => $clean_inputs->{studyDbId},
4493 germplasmDbId => $clean_inputs->{germplasmDbId},
4494 callSetDbId => $clean_inputs->{callSetDbId},
4496 _standard_response_construction($c, $brapi_package_result);
4499 sub callsets_single : Chained('brapi') PathPart('callsets') CaptureArgs(1) {
4500 my $self = shift;
4501 my $c = shift;
4502 my $id = shift;
4503 $c->stash->{callset_id} = $id;
4506 sub callsets_fetch : Chained('callsets_single') PathPart('') Args(0) : ActionClass('REST') { }
4508 sub callsets_fetch_GET {
4509 my $self = shift;
4510 my $c = shift;
4511 my ($auth) = _authenticate_user($c);
4512 my $clean_inputs = $c->stash->{clean_inputs};
4513 my $brapi = $self->brapi_module;
4514 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4515 my $brapi_package_result = $brapi_module->detail({
4516 callset_id => $c->stash->{callset_id},
4517 unknown_string => $clean_inputs->{unknownString}->[0],
4518 sep_phased => $clean_inputs->{sepPhased}->[0],
4519 sep_unphased => $clean_inputs->{sepUnphased}->[0],
4520 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
4522 _standard_response_construction($c, $brapi_package_result);
4525 sub callsets_call_detail : Chained('callsets_single') PathPart('calls') Args(0) : ActionClass('REST') { }
4527 sub callsets_call_detail_GET {
4528 my $self = shift;
4529 my $c = shift;
4530 my ($auth) = _authenticate_user($c);
4531 my $clean_inputs = $c->stash->{clean_inputs};
4532 my $brapi = $self->brapi_module;
4533 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4534 my $brapi_package_result = $brapi_module->calls({
4535 callset_id => $c->stash->{callset_id},
4537 _standard_response_construction($c, $brapi_package_result);
4540 sub callsets_call_filter_detail : Chained('callsets_single') PathPart('calls') Args(1) : ActionClass('REST') { }
4542 sub callsets_call_filter_detail_GET {
4543 my $self = shift;
4544 my $c = shift;
4545 my ($auth) = _authenticate_user($c);
4546 my $clean_inputs = $c->stash->{clean_inputs};
4547 my $brapi = $self->brapi_module;
4548 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4549 my $brapi_package_result = $brapi_module->calls({
4550 callset_id => $c->stash->{callset_id},
4552 _standard_response_construction($c, $brapi_package_result);
4555 sub callsets_search_save : Chained('brapi') PathPart('search/callsets') Args(0) : ActionClass('REST') { }
4557 sub callsets_search_save_POST {
4558 my $self = shift;
4559 my $c = shift;
4560 save_results($self,$c,$c->stash->{clean_inputs},'CallSets');
4563 sub callsets_search_retrieve : Chained('brapi') PathPart('search/callsets') Args(1) {
4564 my $self = shift;
4565 my $c = shift;
4566 my $search_id = shift;
4567 retrieve_results($self, $c, $search_id, 'CallSets');
4571 =head2 brapi/v2/variantsets
4573 Usage: To retrieve data for variantsets
4574 Desc:
4575 Return JSON example:
4577 "metadata" : {
4578 "pagination": {
4579 "pageSize": 10,
4580 "currentPage": 1,
4581 "totalCount": 10,
4582 "totalPages": 1
4584 "status": []
4587 "result": {
4588 "data": [
4590 "additionalInfo": {},
4591 "analysis": [
4593 "analysisDbId": "6191a6bd",
4594 "analysisName": "Standard QC",
4595 "created": "2018-01-01T14:47:23-0600",
4596 "description": "This is a formal description of a QC methodology.",
4597 "software": [
4598 "https://github.com/genotyping/QC"
4600 "type": "QC",
4601 "updated": "2018-01-01T14:47:23-0600"
4604 "availableFormats": [
4606 "dataFormat": "VCF",
4607 "fileFormat": "application/excel",
4608 "fileURL": "https://brapi.org/example/VCF_1.xlsx"
4611 "dataFormat": "VCF",
4612 "fileFormat": "text/csv",
4613 "fileURL": "https://brapi.org/example/VCF_2.csv"
4616 "callSetCount": 341,
4617 "referenceSetDbId": "57eae639",
4618 "studyDbId": "2fc3b034",
4619 "variantCount": 250,
4620 "variantSetDbId": "87a6ac1e",
4621 "variantSetName": "Maize QC DataSet 002334"
4626 Args:
4627 Side Effects:
4629 =cut
4631 sub variantsets : Chained('brapi') PathPart('variantsets') Args(0) : ActionClass('REST') { }
4633 sub variantsets_GET {
4634 my $self = shift;
4635 my $c = shift;
4636 my ($auth) = _authenticate_user($c);
4637 my $clean_inputs = $c->stash->{clean_inputs};
4638 my $brapi = $self->brapi_module;
4639 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4640 my $brapi_package_result = $brapi_module->search({
4641 variantSetDbId => $clean_inputs->{variantSetDbId},
4642 variantDbId => $clean_inputs->{variantDbId},
4643 callSetDbId => $clean_inputs->{callSetDbId},
4644 studyDbId => $clean_inputs->{studyDbId},
4645 studyName => $clean_inputs->{studyName}
4647 _standard_response_construction($c, $brapi_package_result);
4650 ### VariantSet single
4652 sub variantsets_single : Chained('brapi') PathPart('variantsets') CaptureArgs(1) {
4653 my $self = shift;
4654 my $c = shift;
4655 my $id = shift;
4656 $c->stash->{variantSetDbId} = $id;
4659 sub variantsets_fetch : Chained('variantsets_single') PathPart('') Args(0) : ActionClass('REST') { }
4662 sub variantsets_fetch_GET {
4663 my $self = shift;
4664 my $c = shift;
4665 my ($auth) = _authenticate_user($c);
4666 my $clean_inputs = $c->stash->{clean_inputs};
4667 my $brapi = $self->brapi_module;
4668 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4669 my $brapi_package_result = $brapi_module->detail({
4670 variantSetDbId => $c->stash->{variantSetDbId},
4672 _standard_response_construction($c, $brapi_package_result);
4675 sub variantsets_callset_detail : Chained('variantsets_single') PathPart('callsets') Args(0) : ActionClass('REST') { }
4677 sub variantsets_callset_detail_GET {
4678 my $self = shift;
4679 my $c = shift;
4680 my ($auth) = _authenticate_user($c);
4681 my $clean_inputs = $c->stash->{clean_inputs};
4682 my $brapi = $self->brapi_module;
4683 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4684 my $brapi_package_result = $brapi_module->callsets({
4685 variantSetDbId => $c->stash->{variantSetDbId},
4686 callSetDbId => $clean_inputs->{callSetDbId},
4687 callSetName => $clean_inputs->{callSetName}
4689 _standard_response_construction($c, $brapi_package_result);
4692 sub variantsets_calls_detail : Chained('variantsets_single') PathPart('calls') Args(0) : ActionClass('REST') { }
4694 sub variantsets_calls_detail_GET {
4695 my $self = shift;
4696 my $c = shift;
4697 my ($auth) = _authenticate_user($c);
4698 my $clean_inputs = $c->stash->{clean_inputs};
4699 my $brapi = $self->brapi_module;
4700 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4701 my $brapi_package_result = $brapi_module->calls({
4702 variantSetDbId => $c->stash->{variantSetDbId},
4703 unknown_string => $clean_inputs->{unknownString}->[0],
4704 sep_phased => $clean_inputs->{sepPhased}->[0],
4705 sep_unphased => $clean_inputs->{sepUnphased}->[0],
4706 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
4708 _standard_response_construction($c, $brapi_package_result);
4711 sub variantsets_variants_detail : Chained('variantsets_single') PathPart('variants') Args(0) : ActionClass('REST') { }
4713 sub variantsets_variants_detail_GET {
4714 my $self = shift;
4715 my $c = shift;
4716 my ($auth) = _authenticate_user($c);
4717 my $clean_inputs = $c->stash->{clean_inputs};
4718 my $brapi = $self->brapi_module;
4719 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4720 my $brapi_package_result = $brapi_module->variants({
4721 variantSetDbId => $c->stash->{variantSetDbId},
4723 _standard_response_construction($c, $brapi_package_result);
4726 sub variantsets_extract : Chained('brapi') PathPart('variantsets/extract') Args(0) : ActionClass('REST') { }
4728 sub variantsets_extract_POST {
4729 my $self = shift;
4730 my $c = shift;
4731 # my $force_authenticate = 1;
4732 # my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4734 my $clean_inputs = $c->stash->{clean_inputs};
4735 my $brapi = $self->brapi_module;
4736 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4737 my $brapi_package_result = $brapi_module->extract($clean_inputs);
4738 my $status = $brapi_package_result->{status};
4739 my $http_status_code = _get_http_status_code($status);
4741 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4744 sub variantsets_search_save : Chained('brapi') PathPart('search/variantsets') Args(0) : ActionClass('REST') { }
4746 sub variantsets_search_save_POST {
4747 my $self = shift;
4748 my $c = shift;
4749 save_results($self,$c,$c->stash->{clean_inputs},'VariantSets');
4752 sub variantsets_search_retrieve : Chained('brapi') PathPart('search/variantsets') Args(1) {
4753 my $self = shift;
4754 my $c = shift;
4755 my $search_id = shift;
4756 retrieve_results($self, $c, $search_id, 'VariantSets');
4760 =head2 brapi/v2/calls
4762 Usage: To retrieve data for calls
4763 Desc:
4764 Return JSON example:
4766 "metadata" : {
4767 "pagination": {
4768 "pageSize": 10,
4769 "currentPage": 1,
4770 "totalCount": 10,
4771 "totalPages": 1
4773 "status": []
4776 "result": {
4777 "data": [
4779 "additionalInfo": {},
4780 "callSetDbId": "16466f55",
4781 "callSetName": "Sample_123_DNA_Run_456",
4782 "genotype": {
4783 "values": [
4784 "AA"
4787 "genotype_likelihood": [
4790 "phaseSet": "6410afc5",
4791 "variantDbId": "538c8ecf",
4792 "variantName": "Marker A"
4795 "expandHomozygotes": true,
4796 "sepPhased": "~",
4797 "sepUnphased": "|",
4798 "unknownString": "-"
4802 Args:
4803 Side Effects:
4805 =cut
4808 sub calls_search_save : Chained('brapi') PathPart('search/calls') Args(0) : ActionClass('REST') { }
4810 sub calls_search_save_POST {
4811 my $self = shift;
4812 my $c = shift;
4813 save_results($self,$c,$c->stash->{clean_inputs},'Calls');
4816 sub calls_search_retrieve : Chained('brapi') PathPart('search/calls') Args(1) {
4817 my $self = shift;
4818 my $c = shift;
4819 my $search_id = shift;
4820 retrieve_results($self, $c, $search_id, 'Calls');
4823 =head2 brapi/v2/referencesets
4825 Usage: To retrieve data for reference sets
4826 Desc:
4827 Return JSON example:
4829 "metadata" : {
4830 "pagination": {
4831 "pageSize": 10,
4832 "currentPage": 1,
4833 "totalCount": 10,
4834 "totalPages": 1
4836 "status": []
4839 "result": {
4840 "data": [
4842 "additionalInfo": {},
4843 "assemblyPUI": "doi://10.12345/fake/9876",
4844 "description": "Description for an assembly",
4845 "md5checksum": "c2365e900c81a89cf74d83dab60df146",
4846 "referenceSetDbId": "7e029a84",
4847 "referenceSetName": "Assembly version",
4848 "sourceAccessions": [
4849 "A0000002",
4850 "A0009393"
4852 "sourceURI": "https://wiki.brapi.org/files/demo.fast",
4853 "species": {
4854 "term": "sonic hedgehog",
4855 "termURI": "MGI:MGI:98297"
4861 Args:
4862 Side Effects:
4864 =cut
4866 sub referencesets : Chained('brapi') PathPart('referencesets') Args(0) : ActionClass('REST') { }
4868 sub referencesets_GET {
4869 my $self = shift;
4870 my $c = shift;
4871 my ($auth) = _authenticate_user($c);
4872 my $clean_inputs = $c->stash->{clean_inputs};
4873 my $brapi = $self->brapi_module;
4874 my $brapi_module = $brapi->brapi_wrapper('ReferenceSets');
4875 my $brapi_package_result = $brapi_module->search($clean_inputs);
4876 _standard_response_construction($c, $brapi_package_result);
4879 sub referencesets_single : Chained('brapi') PathPart('referencesets') CaptureArgs(1) {
4880 my $self = shift;
4881 my $c = shift;
4882 my $id = shift;
4883 $c->stash->{referenceSetDbId} = $id;
4886 sub referencesets_fetch : Chained('referencesets_single') PathPart('') Args(0) : ActionClass('REST') { }
4889 sub referencesets_fetch_GET {
4890 my $self = shift;
4891 my $c = shift;
4892 my ($auth) = _authenticate_user($c);
4893 my $clean_inputs = $c->stash->{clean_inputs};
4894 my $brapi = $self->brapi_module;
4895 my $brapi_module = $brapi->brapi_wrapper('ReferenceSets');
4896 my $brapi_package_result = $brapi_module->detail($c->stash->{referenceSetDbId});
4897 _standard_response_construction($c, $brapi_package_result);
4900 sub referencesets_search : Chained('brapi') PathPart('search/referencesets') Args(0) : ActionClass('REST') { }
4902 sub referencesets_search_POST {
4903 my $self = shift;
4904 my $c = shift;
4905 save_results($self,$c,$c->stash->{clean_inputs},'ReferenceSets');
4908 sub referencesets_search_retrieve : Chained('brapi') PathPart('search/referencesets') Args(1) {
4909 my $self = shift;
4910 my $c = shift;
4911 my $search_id = shift;
4912 retrieve_results($self, $c, $search_id, 'ReferenceSets');
4915 =head2 brapi/v2/reference
4917 Usage: To retrieve data for reference
4918 Desc:
4919 Return JSON example:
4921 "metadata" : {
4922 "pagination": {
4923 "pageSize": 10,
4924 "currentPage": 1,
4925 "totalCount": 10,
4926 "totalPages": 1
4928 "status": []
4931 "result": {
4932 "data": [
4934 "additionalInfo": {},
4935 "length": 50000000,
4936 "md5checksum": "c2365e900c81a89cf74d83dab60df146",
4937 "referenceDbId": "fc0a81d0",
4938 "referenceName": "Chromosome 2",
4939 "referenceSetDbId": "c1ecfef1",
4940 "sourceAccessions": [
4941 "GCF_000001405.26"
4943 "sourceDivergence": 0.01,
4944 "sourceURI": "https://wiki.brapi.org/files/demo.fast",
4945 "species": {
4946 "term": "sonic hedgehog",
4947 "termURI": "MGI:MGI:98297"
4953 Args:
4954 Side Effects:
4956 =cut
4958 sub reference : Chained('brapi') PathPart('references') Args(0) : ActionClass('REST') { }
4960 sub reference_GET {
4961 my $self = shift;
4962 my $c = shift;
4963 my ($auth) = _authenticate_user($c);
4964 my $clean_inputs = $c->stash->{clean_inputs};
4965 my $brapi = $self->brapi_module;
4966 my $brapi_module = $brapi->brapi_wrapper('References');
4967 my $brapi_package_result = $brapi_module->search($clean_inputs);
4968 _standard_response_construction($c, $brapi_package_result);
4971 sub reference_single : Chained('brapi') PathPart('references') CaptureArgs(1) {
4972 my $self = shift;
4973 my $c = shift;
4974 my $id = shift;
4975 $c->stash->{referenceDbId} = $id;
4978 sub reference_fetch : Chained('reference_single') PathPart('') Args(0) : ActionClass('REST') { }
4981 sub reference_fetch_GET {
4982 my $self = shift;
4983 my $c = shift;
4984 my ($auth) = _authenticate_user($c);
4985 my $clean_inputs = $c->stash->{clean_inputs};
4986 my $brapi = $self->brapi_module;
4987 my $brapi_module = $brapi->brapi_wrapper('References');
4988 my $brapi_package_result = $brapi_module->detail($c->stash->{referenceDbId});
4989 _standard_response_construction($c, $brapi_package_result);
4992 sub reference_search : Chained('brapi') PathPart('search/references') Args(0) : ActionClass('REST') { }
4994 sub reference_search_POST {
4995 my $self = shift;
4996 my $c = shift;
4997 save_results($self,$c,$c->stash->{clean_inputs},'References');
5000 sub reference_search_retrieve : Chained('brapi') PathPart('search/references') Args(1) {
5001 my $self = shift;
5002 my $c = shift;
5003 my $search_id = shift;
5004 retrieve_results($self, $c, $search_id, 'Referenced');
5008 =head2 brapi/v2/crossingprojects
5010 =cut
5012 sub crossingprojects : Chained('brapi') PathPart('crossingprojects') Args(0) : ActionClass('REST') { }
5014 sub crossingprojects_GET {
5015 my $self = shift;
5016 my $c = shift;
5017 my ($auth) = _authenticate_user($c);
5018 my $clean_inputs = $c->stash->{clean_inputs};
5019 my $brapi = $self->brapi_module;
5020 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5021 my $brapi_package_result = $brapi_module->search($clean_inputs);
5022 _standard_response_construction($c, $brapi_package_result);
5025 sub crossingprojects_POST {
5026 my $self = shift;
5027 my $c = shift;
5028 my ($auth,$user_id) = _authenticate_user($c);
5029 my $clean_inputs = $c->stash->{clean_inputs};
5031 my $data = $clean_inputs;
5032 my @all_data;
5033 foreach my $project (values %{$data}) {
5034 push @all_data, $project;
5036 my $brapi = $self->brapi_module;
5037 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5038 my $brapi_package_result = $brapi_module->store_crossingproject(\@all_data,$c,$user_id);
5041 my $status = $brapi_package_result->{status};
5042 my $http_status_code = _get_http_status_code($status);
5043 _standard_response_construction($c, $brapi_package_result);
5046 sub crossingproject_single : Chained('brapi') PathPart('crossingprojects') CaptureArgs(1) {
5047 my $self = shift;
5048 my $c = shift;
5049 my $id = shift;
5050 $c->stash->{crossingProjectDbId} = $id;
5053 sub crossingproject_fetch : Chained('crossingproject_single') PathPart('') Args(0) : ActionClass('REST') { }
5056 sub crossingproject_fetch_GET {
5057 my $self = shift;
5058 my $c = shift;
5059 my ($auth) = _authenticate_user($c);
5060 my $clean_inputs = $c->stash->{clean_inputs};
5061 my $brapi = $self->brapi_module;
5062 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5063 my $brapi_package_result = $brapi_module->detail($c->stash->{crossingProjectDbId});
5064 _standard_response_construction($c, $brapi_package_result);
5067 sub crossingproject_fetch_PUT {
5068 my $self = shift;
5069 my $c = shift;
5070 my ($auth,$user_id,$user_type) = _authenticate_user($c);
5071 my $clean_inputs = $c->stash->{clean_inputs};
5072 my $brapi = $self->brapi_module;
5073 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5074 my $brapi_package_result = $brapi_module->update_crossingproject($c->stash->{crossingProjectDbId}, $clean_inputs,$c,$user_id,$user_type);
5075 my $status = $brapi_package_result->{status};
5076 my $http_status_code = _get_http_status_code($status);
5077 _standard_response_construction($c, $brapi_package_result);
5080 =head2 brapi/v2/crosses
5082 =cut
5084 sub crosses : Chained('brapi') PathPart('crosses') Args(0) : ActionClass('REST') { }
5086 sub crosses_GET {
5087 my $self = shift;
5088 my $c = shift;
5089 my ($auth) = _authenticate_user($c);
5090 my $clean_inputs = $c->stash->{clean_inputs};
5091 my $brapi = $self->brapi_module;
5092 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5093 my $brapi_package_result = $brapi_module->crosses($clean_inputs);
5094 _standard_response_construction($c, $brapi_package_result);
5097 sub crosses_POST {
5098 my $self = shift;
5099 my $c = shift;
5100 my ($auth,$user_id) = _authenticate_user($c);
5101 my $clean_inputs = $c->stash->{clean_inputs};
5102 my $data = $clean_inputs;
5103 my @all_crosses;
5104 foreach my $cross (values %{$data}) {
5105 push @all_crosses, $cross;
5107 my $brapi = $self->brapi_module;
5108 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5109 my $brapi_package_result = $brapi_module->store_crosses(\@all_crosses,$c,$user_id);
5110 _standard_response_construction($c, $brapi_package_result);
5113 # sub crosses_PUT {
5114 # my $self = shift;
5115 # my $c = shift;
5116 # my ($auth) = _authenticate_user($c);
5117 # my $clean_inputs = $c->stash->{clean_inputs};
5118 # my $brapi = $self->brapi_module;
5119 # my $brapi_module = $brapi->brapi_wrapper('Crossing');
5120 # my $brapi_package_result = $brapi_module->update_crosses($clean_inputs);
5121 # _standard_response_construction($c, $brapi_package_result);
5124 =head2 brapi/v2/seedlots
5126 =cut
5128 sub seedlots : Chained('brapi') PathPart('seedlots') Args(0) : ActionClass('REST') { }
5130 sub seedlots_GET {
5131 my $self = shift;
5132 my $c = shift;
5133 my ($auth) = _authenticate_user($c);
5134 my $clean_inputs = $c->stash->{clean_inputs};
5135 my $brapi = $self->brapi_module;
5136 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5137 my $brapi_package_result = $brapi_module->search($clean_inputs);
5138 _standard_response_construction($c, $brapi_package_result);
5141 sub seedlots_POST {
5142 my $self = shift;
5143 my $c = shift;
5144 my ($auth,$user_id) = _authenticate_user($c);
5145 my $clean_inputs = $c->stash->{clean_inputs};
5146 my $data = $clean_inputs;
5147 my @all_data;
5148 foreach my $seedlot (values %{$data}) {
5149 push @all_data, $seedlot;
5151 my $brapi = $self->brapi_module;
5152 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5153 my $brapi_package_result = $brapi_module->store_seedlots(\@all_data,$c,$user_id);
5155 my $status = $brapi_package_result->{status};
5156 my $http_status_code = _get_http_status_code($status);
5158 _standard_response_construction($c, $brapi_package_result, $http_status_code);
5161 sub seedlot_transactions : Chained('brapi') PathPart('seedlots/transactions') Args(0) : ActionClass('REST') { }
5163 sub seedlot_transactions_GET {
5164 my $self = shift;
5165 my $c = shift;
5166 my ($auth) = _authenticate_user($c);
5167 my $clean_inputs = $c->stash->{clean_inputs};
5168 my $brapi = $self->brapi_module;
5169 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5170 my $brapi_package_result = $brapi_module->all_transactions($clean_inputs);
5171 _standard_response_construction($c, $brapi_package_result);
5174 sub seedlot_transactions_POST {
5175 my $self = shift;
5176 my $c = shift;
5177 my ($auth,$user_id) = _authenticate_user($c);
5178 my $clean_inputs = $c->stash->{clean_inputs};
5179 my $data = $clean_inputs;
5180 my @all_data;
5181 foreach my $transaction (values %{$data}) {
5182 push @all_data, $transaction;
5184 my $brapi = $self->brapi_module;
5185 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5186 my $brapi_package_result = $brapi_module->store_seedlot_transaction(\@all_data,$c,$user_id);
5187 my $status = $brapi_package_result->{status};
5188 my $http_status_code = _get_http_status_code($status);
5190 _standard_response_construction($c, $brapi_package_result);
5193 sub seedlot_single : Chained('brapi') PathPart('seedlots') CaptureArgs(1) {
5194 my $self = shift;
5195 my $c = shift;
5196 my $id = shift;
5197 $c->stash->{seedLotDbId} = $id;
5200 sub seedlot_single_fetch : Chained('seedlot_single') PathPart('') Args(0) : ActionClass('REST') { }
5203 sub seedlot_single_fetch_GET {
5204 my $self = shift;
5205 my $c = shift;
5206 my ($auth) = _authenticate_user($c);
5207 my $clean_inputs = $c->stash->{clean_inputs};
5208 my $brapi = $self->brapi_module;
5209 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5210 my $brapi_package_result = $brapi_module->detail($c->stash->{seedLotDbId});
5211 _standard_response_construction($c, $brapi_package_result);
5214 sub seedlot_single_fetch_PUT {
5215 my $self = shift;
5216 my $c = shift;
5217 my ($auth,$user_id) = _authenticate_user($c);
5218 my $clean_inputs = $c->stash->{clean_inputs};
5219 my $brapi = $self->brapi_module;
5220 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5221 my $brapi_package_result = $brapi_module->update_seedlot($c->stash->{seedLotDbId}, $clean_inputs,$c,$user_id);
5222 my $status = $brapi_package_result->{status};
5223 my $http_status_code = _get_http_status_code($status);
5224 _standard_response_construction($c, $brapi_package_result);
5227 sub seedlot_single_transaction_fetch : Chained('seedlot_single') PathPart('transactions') Args(0) : ActionClass('REST') { }
5230 sub seedlot_single_transaction_fetch_GET {
5231 my $self = shift;
5232 my $c = shift;
5233 my ($auth) = _authenticate_user($c);
5234 my $clean_inputs = $c->stash->{clean_inputs};
5235 my $brapi = $self->brapi_module;
5236 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5237 my $brapi_package_result = $brapi_module->transactions($c->stash->{seedLotDbId}, $clean_inputs);
5238 _standard_response_construction($c, $brapi_package_result);
5241 sub breedingmethods : Chained('brapi') PathPart('breedingmethods') Args(0) : ActionClass('REST') { }
5243 sub breedingmethods_GET {
5244 my $self = shift;
5245 my $c = shift;
5246 my $auth = _authenticate_user($c);
5247 my $clean_inputs = $c->stash->{clean_inputs};
5248 my $brapi = $self->brapi_module;
5249 my $brapi_module = $brapi->brapi_wrapper('BreedingMethods');
5250 my $brapi_package_result = $brapi_module->search($clean_inputs);
5252 _standard_response_construction($c, $brapi_package_result);
5255 sub nirs : Chained('brapi') PathPart('nirs') Args(0) : ActionClass('REST') { }
5257 sub nirs_GET {
5258 my $self = shift;
5259 my $c = shift;
5260 my $auth = _authenticate_user($c);
5261 my $clean_inputs = $c->stash->{clean_inputs};
5262 my $brapi = $self->brapi_module;
5263 my $brapi_module = $brapi->brapi_wrapper('Nirs');
5264 my $brapi_package_result = $brapi_module->search($clean_inputs);
5266 _standard_response_construction($c, $brapi_package_result);
5269 sub nirs_single : Chained('brapi') PathPart('nirs') CaptureArgs(1) {
5270 my $self = shift;
5271 my $c = shift;
5272 my $nd_protocol_id = shift;
5274 $c->stash->{nd_protocol_id} = $nd_protocol_id;
5277 sub nirs_detail : Chained('nirs_single') PathPart('') Args(0) : ActionClass('REST') { }
5279 sub nirs_detail_GET {
5280 my $self = shift;
5281 my $c = shift;
5282 my ($auth) = _authenticate_user($c);
5283 my $clean_inputs = $c->stash->{clean_inputs};
5284 my $brapi = $self->brapi_module;
5285 my $brapi_module = $brapi->brapi_wrapper('Nirs');
5286 my $brapi_package_result = $brapi_module->nirs_detail(
5287 $c->stash->{nd_protocol_id}
5289 _standard_response_construction($c, $brapi_package_result);
5292 sub nirs_matrix : Chained('nirs_single') PathPart('matrix') Args(0) : ActionClass('REST') { }
5294 sub nirs_matrix_GET {
5295 my $self = shift;
5296 my $c = shift;
5297 my ($auth) = _authenticate_user($c);
5298 my $clean_inputs = $c->stash->{clean_inputs};
5299 my $brapi = $self->brapi_module;
5300 my $brapi_module = $brapi->brapi_wrapper('Nirs');
5301 my $brapi_package_result = $brapi_module->nirs_matrix(
5302 $c->stash->{nd_protocol_id},
5303 $clean_inputs
5305 _standard_response_construction($c, $brapi_package_result);
5308 #functions
5309 sub save_results {
5310 my $self = shift;
5311 my $c = shift;
5312 my $search_params = shift;
5313 my $search_type = shift;
5315 my %server_permission;
5316 my $rc = eval{
5317 my $server_permission = $c->config->{"brapi_GET"};
5318 my @server_permission = split ',', $server_permission;
5319 %server_permission = map { $_ => 1 } @server_permission;
5320 1; };
5321 if($rc && !$server_permission{'any'}){
5322 my $auth = _authenticate_user($c);
5325 my $brapi = $self->brapi_module;
5326 my $brapi_module = $brapi->brapi_wrapper($search_type);
5328 #set default value to 100000 to get as much as possible records when page size is not a parameter
5329 if(!$search_params->{pageSize}) {
5330 $brapi_module->{page_size} = 100000;
5333 my $search_result = $brapi_module->search($search_params,$c);
5335 my $dir = $c->tempfiles_subdir('/brapi_searches');
5336 my $tempfile = $c->config->{basepath}."/".$c->tempfile( TEMPLATE => 'brapi_searches/XXXXXXXXXXXXXXXX');
5337 my $results_module = $brapi->brapi_wrapper('Results');
5338 my $brapi_package_result = $results_module->save_results($tempfile, $search_result, $search_type);
5340 _standard_response_construction($c, $brapi_package_result);
5343 sub retrieve_results {
5344 my $self = shift;
5345 my $c = shift;
5346 my $search_id = shift;
5347 my $search_type = shift;
5348 my $auth = _authenticate_user($c);
5350 my $clean_inputs = $c->stash->{clean_inputs};
5351 my $tempfiles_subdir = $c->config->{basepath} . $c->tempfiles_subdir('brapi_searches');
5352 my $brapi = $self->brapi_module;
5353 my $search_module = $brapi->brapi_wrapper('Results');
5354 my $brapi_package_result = $search_module->retrieve_results($tempfiles_subdir, $search_id);
5355 _standard_response_construction($c, $brapi_package_result);