2 package SGN
::Controller
::AJAX
::BrAPI
;
9 use CXGN
::BreedersToolbox
::Projects
;
11 use CXGN
::Trial
::TrialLayout
;
14 use CXGN
::Trial
::TrialCreate
;
15 use CXGN
::Trial
::Search
;
16 use CXGN
::Location
::LocationLookup
;
18 use JSON
qw( decode_json );
22 use File
::Slurp qw
| read_file
|;
23 use Spreadsheet
::WriteExcel
;
28 BEGIN { extends
'Catalyst::Controller::REST' };
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',
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' => (
54 isa
=> 'Bio::Chado::Schema',
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
67 # have to serialize the json because using the callbacks in the config map
69 my ( $self, $data, $c ) = @_;
70 my $json = JSON
->new->allow_nonref;
73 $json->convert_blessed;
74 my $json_text = $json->encode( $c->stash->{rest
} );
76 $c->response->content_type('application/json');
80 sub brapi
: Chained
('/') PathPart
('brapi') CaptureArgs
(1) {
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({
119 brapi_module_inst
=> {
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,
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;
153 $c->stash->{clean_inputs
} = $c->request->data;
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
163 no warnings
'uninitialized';
168 my %data = ref $alldata eq 'ARRAY' ?
map { $_ => $_} @
{$alldata} : %{$alldata};
169 %$params = $params ?
(%data, %$params) : %data;
172 foreach (keys %$params){
173 my $values = $params->{$_};
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'){
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;
192 die "Input $_ is not a scalar, arrayref, or a single level hash\n";
199 sub _validate_request
{
201 my $data_type = 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);
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);
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
{
247 my $field_name = 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
{
255 my $force_authenticate = shift;
256 my $status = $c->stash->{status
};
261 my $wildcard = 'any';
263 my %server_permission;
265 my $server_permission = $c->config->{"brapi_" . $c->request->method};
266 my @server_permission = split ',', $server_permission;
267 %server_permission = map { $_ => 1 } @server_permission;
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
{
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);
309 =head2 /brapi/v1/token
311 Usage: For logging a user in and loggin a user out through the API
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.
330 "userDisplayName": "John Smith",
331 "access_token": "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4",
332 "expires_in": "The lifetime in seconds of the access token"
339 "access_token" : "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4" // (optional, text, `R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4`) ... The user access token. Default: current user token.
346 "status" : { "message" : "User has been logged out successfully."},
354 sub authenticate_token
: Chained
('brapi') PathPart
('token') Args
(0) : ActionClass
('REST') { }
356 sub authenticate_token_DELETE
{
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
{
368 process_authenticate_token
($self,$c);
371 sub authenticate_token_POST
{
374 process_authenticate_token
($self,$c);
377 sub process_authenticate_token
{
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;
401 =head2 /brapi/v1/calls
403 Usage: For determining which calls have been implemented and with which datafile types and methods
423 "call": "allelematrix",
434 "call": "germplasm/id/mcpd",
443 "call": "doesntexistyet",
458 sub calls
: Chained
('brapi') PathPart
('calls') Args
(0) : ActionClass
('REST') { }
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(
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
495 "call": "allelematrix",
506 "call": "germplasm/id/mcpd",
515 "call": "doesntexistyet",
530 sub serverinfo
: Chained
('brapi') PathPart
('serverinfo') Args
(0) : ActionClass
('REST') { }
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') { }
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
{
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
{
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') { }
583 seasons_process
($self, $c);
589 seasons_process
($self, $c);
592 sub seasons_process
{
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) {
609 $c->stash->{seasonDbId
} = $id;
612 sub season_fetch
: Chained
('season_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
615 sub season_fetch_GET
{
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
{
631 save_results
($self,$c,$c->stash->{clean_inputs
},'Seasons');
634 sub season_search_retrieve
: Chained
('brapi') PathPart
('search/seasons') Args
(1) {
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
661 "description": "Description for Nursery study type"
665 "description": "Description for Nursery study type"
675 sub study_types
: Chained
('brapi') PathPart
('studytypes') Args
(0) : ActionClass
('REST') { }
677 sub study_types_POST
{
680 study_types_process
($self, $c);
683 sub study_types_GET
{
686 study_types_process
($self, $c);
689 sub study_types_process
{
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
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
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",
744 "commonCropName": "banana",
745 "instituteCode": "01BEL084",
746 "instituteName": "ITC",
747 "biologicalStatusOfAccessionCode": 412,
748 "countryOfOriginCode": "UNK",
749 "typeOfGermplasmStorageCode": 10,
751 "species": "acuminata",
752 "speciesAuthority": "",
753 "subtaxa": "sp malaccensis var pahang",
754 "subtaxaAuthority": "",
758 "donorAccessionNumber": "",
759 "donorInstituteCode": "",
763 "acquisitionDate": "19470131"
771 sub germplasm_search_old
: Chained
('brapi') PathPart
('germplasm-search') Args
(0) : ActionClass
('REST') { }
773 sub germplasm_search_old_GET
{
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
{
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') { }
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);
830 my ($auth,$user_id) = _authenticate_user
($c);
831 my $clean_inputs = $c->stash->{clean_inputs
};
832 my $data = $clean_inputs;
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
{
849 save_results
($self,$c,$c->stash->{clean_inputs
},'Germplasm');
852 sub germplasm_search_retrieve
: Chained
('brapi') PathPart
('search/germplasm') Args
(1) {
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
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"],
885 sub germplasm_single
: Chained
('brapi') PathPart
('germplasm') CaptureArgs
(1) {
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
{
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
{
912 my ($auth,$user_id) = _authenticate_user
($c);
913 my $clean_inputs = $c->stash->{clean_inputs
};
914 my $data = $clean_inputs;
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
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",
945 "commonCropName": "banana",
946 "instituteCode": "01BEL084",
947 "instituteName": "ITC",
948 "biologicalStatusOfAccessionCode": 412,
949 "countryOfOriginCode": "UNK",
950 "typeOfGermplasmStorageCode": 10,
952 "species": "acuminata",
953 "speciesAuthority": "",
954 "subtaxa": "sp malaccensis var pahang",
955 "subtaxaAuthority": "",
959 "donorAccessionNumber": "",
960 "donorInstituteCode": "",
964 "acquisitionDate": "19470131"
971 sub germplasm_mcpd
: Chained
('germplasm_single') PathPart
('mcpd') Args
(0) : ActionClass
('REST') { }
973 sub germplasm_mcpd_GET
{
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
{
993 trials_search_process
($self, $c);
996 sub trials_list_POST
{
999 my ($auth,$user_id) = _authenticate_user
($c);
1000 my $clean_inputs = $c->stash->{clean_inputs
};
1001 my $data = $clean_inputs;
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
{
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) {
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
{
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
{
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
{
1083 save_results
($self,$c,$c->stash->{clean_inputs
},'Trials');
1086 sub trials_search_retrieve
: Chained
('brapi') PathPart
('search/trials') Args
(1) {
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
1098 Return JSON example:
1105 "germplasmDbId": "382",
1106 "pedigree": "TOBA97/SW90.1057",
1116 sub germplasm_pedigree
: Chained
('germplasm_single') PathPart
('pedigree') Args
(0) : ActionClass
('REST') { }
1118 sub germplasm_pedigree_POST
{
1121 #my $auth = _authenticate_user($c);
1124 sub germplasm_pedigree_GET
{
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
1143 Return JSON example:
1151 "germplasmDbId": "382",
1152 "defaultDisplayName": "Pahang",
1154 "progenyGermplasmDbId": "403",
1155 "parentType": "FEMALE"
1157 "progenyGermplasmDbId": "402",
1158 "parentType": "MALE"
1160 "progenyGermplasmDbId": "405",
1161 "parentType": "SELF"
1170 sub germplasm_progeny
: Chained
('germplasm_single') PathPart
('progeny') Args
(0) : ActionClass
('REST') { }
1172 sub germplasm_progeny_POST
{
1177 sub germplasm_progeny_GET
{
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
{
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
1210 Return JSON example:
1217 "germplasmDbId": "382",
1229 sub germplasm_markerprofile
: Chained
('germplasm_single') PathPart
('markerprofiles') Args
(0) : ActionClass
('REST') { }
1231 sub germplasm_markerprofile_POST
{
1234 #my $auth = _authenticate_user($c);
1237 sub germplasm_markerprofile_GET
{
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
{
1260 germplasm_attributes_process
($self, $c);
1263 sub germplasm_attributes_process
{
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) {
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
{
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
{
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
{
1312 save_results
($self,$c,$c->stash->{clean_inputs
},'GermplasmAttributes');
1315 sub attributes_retrieve
: Chained
('brapi') PathPart
('search/attributes') Args
(1) {
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
{
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) {
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
{
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
{
1363 save_results
($self,$c,$c->stash->{clean_inputs
},'GermplasmAttributeValues');
1366 sub attributes_values_retrieve
: Chained
('brapi') PathPart
('search/attributevalues') Args
(1) {
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
1377 Return JSON example:
1391 "markerProfileDbId": "993",
1392 "germplasmDbId" : 2374,
1393 "extractDbId" : 3939,
1394 "analysisMethod": "GoldenGate",
1398 "markerProfileDbId": "994",
1399 "germplasmDbId" : 2374,
1400 "extractDbId" : 3939,
1401 "analysisMethod": "GBS",
1412 sub markerprofile_search_process
{
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
{
1438 markerprofile_search_process
($self, $c);
1441 sub markerprofiles_list_GET
{
1444 markerprofile_search_process
($self, $c);
1448 =head2 brapi/v1/markerprofiles/markerprofilesDbId
1450 Usage: To retrieve data for a single markerprofile
1452 Return JSON example:
1465 "germplasmDbId": 993,
1466 "extractDbId" : 38383,
1467 "markerprofileDbId": 37484,
1468 "analysisMethod": "GBS-Pst1",
1469 "encoding": "AA,BB,AB",
1470 "data" : [ { "marker1": "AA" }, { "marker2":"AB" }, ... ]
1478 sub markerprofiles_single
: Chained
('brapi') PathPart
('markerprofiles') CaptureArgs
(1) {
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
{
1490 #my $auth = _authenticate_user($c);
1493 sub genotype_fetch_GET
{
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) {
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
1529 Return JSON example:
1541 "makerprofileDbIds": ["markerprofileId1","markerprofileId2","markerprofileId3"],
1543 { "markerDbId1":["AB","AA","AA"] },
1544 { "markerDbId2":["AA","AB","AA"] },
1545 { "markerDbId3":["AB","AB","BB"] }
1554 sub allelematrices
: Chained
('brapi') PathPart
('allelematrices-search') Args
(0) : ActionClass
('REST') { }
1556 sub allelematrices_POST
{
1559 allelematrix_search_process
($self, $c);
1562 sub allelematrices_GET
{
1565 allelematrix_search_process
($self, $c);
1568 sub allelematrices_new
: Chained
('brapi') PathPart
('allelematrices') Args
(0) : ActionClass
('REST') { }
1570 sub allelematrices_new_GET
{
1573 allelematrix_search_process
($self, $c);
1576 sub allelematrices_cached
: Chained
('brapi') PathPart
('search/allelematrices') Args
(0) : ActionClass
('REST') { }
1578 sub allelematrices_cached_POST
{
1581 allelematrix_search_process
($self, $c);
1584 sub allelematrices_cached_GET
{
1587 allelematrix_search_process
($self, $c);
1591 sub allelematrix
: Chained
('brapi') PathPart
('allelematrix-search') Args
(0) : ActionClass
('REST') { }
1593 sub allelematrix_POST
{
1596 allelematrix_search_process
($self, $c);
1599 sub allelematrix_GET
{
1602 allelematrix_search_process
($self, $c);
1605 sub allelematrix_search_process
{
1608 # my ($auth) = _authenticate_user($c);
1610 my $clean_inputs = $c->stash->{clean_inputs
};
1611 my $format = $clean_inputs->{format
}->[0];
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],
1630 main_production_site_url
=> $c->config->{main_production_site_url
},
1631 file_path
=> $file_path,
1634 _standard_response_construction
($c, $brapi_package_result);
1637 =head2 brapi/v2/lists
1641 sub lists
: Chained
('brapi') PathPart
('lists') Args
(0) : ActionClass
('REST') { }
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);
1657 my ($auth,$user_id) = _authenticate_user
($c);
1658 my $clean_inputs = $c->stash->{clean_inputs
};
1659 my $data = $clean_inputs;
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) {
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
{
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
{
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
{
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
{
1722 save_results
($self,$c,$c->stash->{clean_inputs
},'Lists');
1725 sub list_search_retrieve
: Chained
('brapi') PathPart
('search/lists') Args
(1) {
1728 my $search_id = shift;
1729 retrieve_results
($self, $c, $search_id, 'Lists');
1732 =head2 brapi/v2/people
1736 sub people
: Chained
('brapi') PathPart
('people') Args
(0) : ActionClass
('REST') { }
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) {
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
{
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
{
1775 save_results
($self,$c,$c->stash->{clean_inputs
},'People');
1778 sub people_search_retrieve
: Chained
('brapi') PathPart
('search/people') Args
(1) {
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
1789 Return JSON example:
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"
1822 sub programs_list
: Chained
('brapi') PathPart
('programs') Args
(0) : ActionClass
('REST') { }
1824 sub programs_list_POST
{
1827 my ($auth,$user_id) = _authenticate_user
($c);
1828 my $clean_inputs = $c->stash->{clean_inputs
};
1829 my $data = $clean_inputs;
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
{
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) {
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
{
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
{
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
{
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) {
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
1916 Return JSON example:
1931 "name": "Earlygenerationtesting",
1932 "studyType": "Trial",
1933 "years": ["2005", "2008"],
1937 "studyPUI" : "PUI string",
1938 "studyType": "Trial",
1939 "startDate": "2015-06-01",
1940 "endDate" : "2015-12-31",
1946 "name": "Earlygenerationtesting",
1947 "seasons": ["2005", "2008"],
1951 "studyPUI" : "PUI string",
1952 "studyType": "Trial",
1953 "startDate": "2015-06-01",
1954 "endDate" : "2015-12-31",
1965 sub studies_search
: Chained
('brapi') PathPart
('studies-search') Args
(0) : ActionClass
('REST') { }
1967 sub studies_search_POST
{
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],
1993 _standard_response_construction
($c, $brapi_package_result);
1996 sub studies_search_GET
{
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],
2022 _standard_response_construction
($c, $brapi_package_result);
2025 sub studies
: Chained
('brapi') PathPart
('studies') Args
(0) : ActionClass
('REST') { }
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
},
2056 _standard_response_construction
($c, $brapi_package_result);
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']}]);
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
{
2082 save_results
($self,$c,$c->stash->{clean_inputs
},'Studies');
2085 sub studies_search_retrieve
: Chained
('brapi') PathPart
('search/studies') Args
(1) {
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
2097 Return JSON example:
2110 "studyName": "myBestTrial",
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",
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",
2132 "synonyms": [ "01BEL084727"],
2142 sub studies_single
: Chained
('brapi') PathPart
('studies') CaptureArgs
(1) {
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
{
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
{
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
{
2186 #my $auth = _authenticate_user($c);
2189 sub studies_info_GET
{
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
{
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
{
2224 #my $auth = _authenticate_user($c);
2227 sub studies_observation_variables_GET
{
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
{
2246 #my $auth = _authenticate_user($c);
2249 sub studies_layout_GET
{
2252 my $clean_inputs = $c->stash->{clean_inputs
};
2253 my ($auth) = _authenticate_user
($c);
2254 my $format = $clean_inputs->{format
}->[0] || 'json';
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
},
2269 main_production_site_url
=> $c->config->{main_production_site_url
},
2270 file_path
=> $file_path,
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
{
2281 my $clean_inputs = $c->stash->{clean_inputs
};
2282 my ($auth) = _authenticate_user
($c);
2283 my $format = $clean_inputs->{format
}->[0] || 'json';
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
},
2298 main_production_site_url
=> $c->config->{main_production_site_url
},
2299 file_path
=> $file_path,
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
2310 Return JSON example:
2312 "metadata" : "status": [],
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,
2341 sub studies_observations
: Chained
('studies_single') PathPart
('observationunits') Args
(0) : ActionClass
('REST') { }
2343 sub studies_observations_GET
{
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
2363 Return JSON example:
2376 "observationVariableDbId": [ '', '', '', '', '', '', '', '', 44444, 55555, 66666...],
2377 "observationVariableName": [ "plotDbId", "plotName", "block", "rep", "germplasmID", "germplasmName", "operator", "timestamp", "Yield", "Color", "Dry Matter"...],
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, ...]
2391 sub studies_table
: Chained
('studies_single') PathPart
('table') Args
(0) : ActionClass
('REST') { }
2393 sub studies_table_GET
{
2396 my ($auth) = _authenticate_user
($c);
2398 my $clean_inputs = $c->stash->{clean_inputs
};
2399 my $format = $clean_inputs->{format
}->[0];
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
},
2418 main_production_site_url
=> $c->config->{main_production_site_url
},
2419 file_path
=> $file_path,
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
2431 Return JSON example:
2433 "metadata" : "status": [],
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,
2462 sub studies_observations_granular
: Chained
('studies_single') PathPart
('observations') Args
(0) : ActionClass
('REST') { }
2464 sub studies_observations_granular_PUT
{
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
{
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
2494 Return JSON example:
2507 "observationUnitDbId": 20,
2508 "observationUnitPUI": "http://phenome-fppn.fr/maugio/bloc/12/2345",
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",
2524 "factor" : "water regimen" ,
2525 "modality":"water deficit"
2539 "instanceNumber" : 1,
2540 "observationVariableDbId": 35,
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,
2552 "observationValue" : 32,
2553 "observationTimeStamp": "2006-07-03::10:00",
2555 "collectionFacilityLabel": null,
2556 "collector" : "userURIOrName"
2567 sub phenotypes_search
: Chained
('brapi') PathPart
('phenotypes-search') Args
(0) : ActionClass
('REST') { }
2569 sub phenotypes_search_POST
{
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
{
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);
2593 sub observation_units
: Chained
('brapi') PathPart
('observationunits') Args
(0) ActionClass
('REST') { }
2595 sub observation_units_GET
{
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
{
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, [
2618 'observationUnitName',
2620 'observationUnitPosition' => [
2622 'observationLevel' => ['levelName', 'levelCode'],
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
{
2641 my ($auth,$user_id) = _authenticate_user
($c);
2642 my $clean_inputs = $c->stash->{clean_inputs
};
2643 my %data = %$clean_inputs;
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
{
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') {
2673 my $observation_unit_db_id = shift;
2675 $c->stash->{observation_unit_db_id
} = $observation_unit_db_id;
2678 sub observation_unit_single_PUT
{
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
{
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
{
2712 save_results
($self,$c,$c->stash->{clean_inputs
},'ObservationUnits');
2715 sub observation_units_search_retrieve
: Chained
('brapi') PathPart
('search/observationunits') Args
(1) {
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
{
2728 process_phenotypes_search_table
($self, $c);
2731 sub phenotypes_search_table_GET
{
2734 process_phenotypes_search_table
($self, $c);
2737 sub process_phenotypes_search_table
{
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
{
2753 save_results
($self,$c,$c->stash->{clean_inputs
},'ObservationTables');
2756 sub observation_tables_search_retrieve
: Chained
('brapi') PathPart
('search/observationtables') Args
(1) {
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
{
2768 process_phenotypes_search_csv
($self, $c);
2771 sub phenotypes_search_csv_GET
{
2774 process_phenotypes_search_csv
($self, $c);
2777 sub process_phenotypes_search_csv
{
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],
2799 main_production_site_url
=> $c->config->{main_production_site_url
},
2800 file_path
=> $file_path,
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
{
2811 process_phenotypes_search_tsv
($self, $c);
2814 sub phenotypes_search_tsv_GET
{
2817 process_phenotypes_search_tsv
($self, $c);
2820 sub process_phenotypes_search_tsv
{
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],
2842 main_production_site_url
=> $c->config->{main_production_site_url
},
2843 file_path
=> $file_path,
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
{
2855 #my $auth = _authenticate_user($c);
2858 sub traits_list_GET
{
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) {
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
{
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.
2902 Return JSON example:
2918 "species": "Some species",
2921 "publishedDate": "2008-04-16",
2922 "markerCount": 1000,
2923 "linkageGroupCount": 7,
2924 "comments": "This map contains ..."
2928 "name": "Some Other map",
2929 "species": "Some Species",
2932 "publishedDate": "2009-01-12",
2933 "markerCount": 1501,
2934 "linkageGroupCount": 7,
2935 "comments": "this is blah blah"
2945 sub maps_list
: Chained
('brapi') PathPart
('maps') Args
(0) : ActionClass
('REST') { }
2947 sub maps_list_POST
{
2950 #my $auth = _authenticate_user($c);
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
2977 Return JSON example:
2995 "linkageGroupId": 1,
2996 "numberMarkers": 100000,
2997 "maxPosition": 10000000
3000 "linkageGroupId": 2,
3001 "numberMarkers": 1247,
3002 "maxPostion": 12347889
3012 sub maps_single
: Chained
('brapi') PathPart
('maps') CaptureArgs
(1) {
3017 $c->stash->{map_id
} = $map_id;
3021 sub maps_details
: Chained
('maps_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
3023 sub maps_details_POST
{
3026 #my $auth = _authenticate_user($c);
3029 sub maps_details_GET
{
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(
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.
3047 Return JSON example:
3050 "pagination" : { "pageSize": 30, "currentPage": 2, "totalCount": 40, "totalPages":2 },
3057 "markerName": "marker1",
3059 "linkageGroup": "1A"
3062 "markerName": "marker2",
3064 "linkageGroup": "1A"
3074 sub maps_marker_detail
: Chained
('maps_single') PathPart
('positions') Args
(0) : ActionClass
('REST') { }
3076 sub maps_marker_detail_POST
{
3079 #my $auth = _authenticate_user($c);
3082 sub maps_marker_detail_GET
{
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
{
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
3120 sub maps_marker_detail_lg
: Chained
('maps_single') PathPart
('linkagegroups') Args
(0) : ActionClass
('REST') { }
3122 sub maps_marker_detail_lg_GET
{
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
3141 sub maps_markerpositions
: Chained
('brapi') PathPart
('markerpositions') Args
(0) : ActionClass
('REST') { }
3143 sub maps_markerpositions_GET
{
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
},
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
{
3165 save_results
($self,$c,$c->stash->{clean_inputs
},'MarkerPositions');
3168 sub maps_markerpositions_retrieve
: Chained
('brapi') PathPart
('search/markerpositions') Args
(1) {
3171 my $search_id = shift;
3172 retrieve_results
($self, $c, $search_id, 'MarkerPositions');
3175 =head2 brapi/<version>/locations
3177 Usage: To retrieve locations.
3179 Return JSON example:
3185 sub locations_list
: Chained
('brapi') PathPart
('locations') Args
(0) : ActionClass
('REST') { }
3187 sub locations_list_POST
{
3190 my ($auth,$user_id) = _authenticate_user
($c);
3191 my $clean_inputs = $c->stash->{clean_inputs
};
3192 my $data = $clean_inputs;
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
{
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
{
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
{
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;
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
{
3251 save_results
($self,$c,$c->stash->{clean_inputs
},'Locations');
3254 sub locations_search_retrieve
: Chained
('brapi') PathPart
('search/locations') Args
(1) {
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
{
3266 #my $auth = _authenticate_user($c);
3269 sub observationvariable_data_type_list_GET
{
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
{
3285 #my $auth = _authenticate_user($c);
3288 sub observationvariable_ontologies_GET
{
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
{
3316 _observationvariable_search_process
($self, $c);
3319 sub observationvariable_search_GET
{
3322 _observationvariable_search_process
($self, $c);
3325 sub _observationvariable_search_process
{
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
},
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
{
3352 save_results
($self,$c,$c->stash->{clean_inputs
},'ObservationVariables');
3355 sub variables_search_retrieve
: Chained
('brapi') PathPart
('search/variables') Args
(1) {
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
{
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,
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
{
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(
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
{
3406 _sample_search_process
($self, $c);
3409 sub samples_list_GET
{
3412 _sample_search_process
($self, $c);
3415 sub _sample_search_process
{
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') { }
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
{
3453 save_results
($self,$c,$c->stash->{clean_inputs
},'Samples');
3456 sub samples_list_search_retrieve
: Chained
('brapi') PathPart
('search/samples') Args
(1) {
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
3468 Return JSON example:
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",
3489 "takenBy": "Mr. Technician",
3490 "sampleTimestamp": "2016-07-27T14:43:22+0100",
3491 "sampleType" : "TypeOfSample",
3492 "tissueType" : "TypeOfTissue",
3493 "notes": "Cut from infected leaf",
3498 sub samples_single
: Chained
('brapi') PathPart
('samples') CaptureArgs
(1) {
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
{
3512 #my $auth = _authenticate_user($c);
3515 sub sample_details_GET
{
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) {
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
3548 Request body example:
3552 "observationUnitDbId": "observationUnitDbId0",
3555 "collector": "collector0",
3556 "observationDbId": "observationDbId0",
3557 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3558 "observationVariableDbId": "observationVariableDbId0",
3559 "observationVariableName": "observationVariableName0",
3560 "season": "season0",
3564 "collector": "collector1",
3565 "observationDbId": "observationDbId1",
3566 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3567 "observationVariableDbId": "observationVariableDbId1",
3568 "observationVariableName": "observationVariableName1",
3569 "season": "season1",
3573 "studyDbId": "studyDbId0"
3576 "observationUnitDbId": "observationUnitDbId1",
3579 "collector": "collector0",
3580 "observationDbId": "observationDbId0",
3581 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3582 "observationVariableDbId": "observationVariableDbId0",
3583 "observationVariableName": "observationVariableName0",
3584 "season": "season0",
3588 "collector": "collector1",
3589 "observationDbId": "observationDbId1",
3590 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3591 "observationVariableDbId": "observationVariableDbId1",
3592 "observationVariableName": "observationVariableName1",
3593 "season": "season1",
3597 "studyDbId": "studyDbId1"
3602 Response JSON example:
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",
3628 "uploadedBy": "dbUserId",
3639 sub phenotypes
: Chained
('brapi') PathPart
('phenotypes') Args
(0) : ActionClass
('REST') { }
3641 sub phenotypes_POST
{
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
3662 Request body example:
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:
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",
3701 "uploadedBy": "dbUserId",
3712 sub observations
: Chained
('brapi') PathPart
('observations') Args
(0) : ActionClass
('REST') { }
3714 sub observations_PUT
{
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,
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
{
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
{
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,
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
{
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) {
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
{
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
{
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,
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
{
3863 save_results
($self,$c,$c->stash->{clean_inputs
},'Observations');
3866 sub observation_search_retrieve
: Chained
('brapi') PathPart
('search/observations') Args
(1) {
3869 my $search_id = shift;
3870 retrieve_results
($self, $c, $search_id, 'Observations');
3873 sub save_observation_results
{
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
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
3920 Side Effects: deprecated on BrAPI v2.0
3924 sub markers_search
: Chained
('brapi') PathPart
('markers') Args
(0) : ActionClass
('REST') { }
3926 sub markers_search_GET
{
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
{
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) {
3948 my $search_id = shift;
3949 retrieve_results
($self, $c, $search_id, 'Markers');
3953 =head2 brapi/v2/variants
3955 Usage: To retrieve variants
3962 sub variants_search
: Chained
('brapi') PathPart
('variants') Args
(0) : ActionClass
('REST') { }
3964 sub variants_search_GET
{
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) {
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
{
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
{
4001 #my $auth = _authenticate_user($c);
4004 sub variants_calls_detail_GET
{
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
{
4027 save_results
($self,$c,$c->stash->{clean_inputs
},'Variants');
4030 sub variants_search_retrieve
: Chained
('brapi') PathPart
('search/variants') Args
(1) {
4033 my $search_id = shift;
4034 retrieve_results
($self, $c, $search_id, 'Variants');
4038 =head2 brapi/v1/observations-search
4040 Usage: To retrieve observations
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:
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",
4075 "uploadedBy": "dbUserId",
4086 sub observations_search
: Chained
('brapi') PathPart
('observations-search') Args
(0) : ActionClass
('REST') { }
4088 sub observations_search_POST
{
4091 observations_search_process
($self, $c);
4094 sub observations_search_GET
{
4097 observations_search_process
($self, $c);
4100 sub observations_search_process
{
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)
4119 Request body example:
4122 Response JSON example:
4125 "https://brapi.org/jsonld/context/metadata.jsonld"
4130 "fileDescription": "This is an Excel data file",
4131 "fileMD5Hash": "c2365e900c81a89cf74d83dab60df146",
4132 "fileName": "datafile.xlsx",
4134 "fileType": "application/vnd.ms-excel",
4135 "fileURL": "https://wiki.brapi.org/examples/datafile.xlsx"
4146 "message": "Request accepted, response successful",
4147 "messageType": "INFO"
4154 "additionalInfo": {},
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": [
4180 "studyDbId": "2cc2001f"
4189 sub events_search
: Chained
('brapi') PathPart
('events') Args
(0) : ActionClass
('REST') { }
4191 sub events_search_POST
{
4194 events_search_process
($self, $c);
4197 sub events_search_GET
{
4200 events_search_process
($self, $c);
4203 sub events_search_process
{
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
4218 Request body example:
4221 Response JSON example:
4235 "message": "Request accepted, response successful",
4236 "messageType": "INFO"
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,
4268 "imageName": "Tomato Image 1",
4269 "imageTimeStamp": "2018-01-01T14:47:23-0600",
4270 "imageURL": "https://wiki.brapi.org/images/tomato",
4272 "mimeType": "image/jpeg",
4273 "observationDbIds": [
4277 "observationUnitDbId": "b7e690b6"
4288 sub images
: Chained
('brapi') PathPart
('images') Args
(0) : ActionClass
('REST') { }
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);
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
};
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) {
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
{
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
{
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
};
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
{
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
{
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) {
4409 my $search_id = shift;
4410 retrieve_results
($self, $c, $search_id, 'Images');
4413 sub _get_http_status_code
{
4415 my $http_status_code = 200;
4419 if ($_->{messageType
} eq "403") {
4420 $http_status_code = 403;
4423 elsif ($_->{messageType
} eq "401") {
4424 $http_status_code = 401;
4427 elsif ($_->{messageType
} eq "400") {
4428 $http_status_code = 400;
4431 elsif ($_->{messageType
} eq "200") {
4432 $http_status_code = 200;
4437 return $http_status_code;
4440 =head2 brapi/v2/callsets
4442 Usage: To retrieve data for callsets
4444 Return JSON example:
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",
4479 sub callsets
: Chained
('brapi') PathPart
('callsets') Args
(0) : ActionClass
('REST') { }
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) {
4503 $c->stash->{callset_id
} = $id;
4506 sub callsets_fetch
: Chained
('callsets_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
4508 sub callsets_fetch_GET
{
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
{
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
{
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
{
4560 save_results
($self,$c,$c->stash->{clean_inputs
},'CallSets');
4563 sub callsets_search_retrieve
: Chained
('brapi') PathPart
('search/callsets') Args
(1) {
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
4575 Return JSON example:
4590 "additionalInfo": {},
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.",
4598 "https://github.com/genotyping/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"
4631 sub variantsets
: Chained
('brapi') PathPart
('variantsets') Args
(0) : ActionClass
('REST') { }
4633 sub variantsets_GET
{
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) {
4656 $c->stash->{variantSetDbId
} = $id;
4659 sub variantsets_fetch
: Chained
('variantsets_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
4662 sub variantsets_fetch_GET
{
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
{
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
{
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
{
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
{
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
{
4749 save_results
($self,$c,$c->stash->{clean_inputs
},'VariantSets');
4752 sub variantsets_search_retrieve
: Chained
('brapi') PathPart
('search/variantsets') Args
(1) {
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
4764 Return JSON example:
4779 "additionalInfo": {},
4780 "callSetDbId": "16466f55",
4781 "callSetName": "Sample_123_DNA_Run_456",
4787 "genotype_likelihood": [
4790 "phaseSet": "6410afc5",
4791 "variantDbId": "538c8ecf",
4792 "variantName": "Marker A"
4795 "expandHomozygotes": true,
4798 "unknownString": "-"
4808 sub calls_search_save
: Chained
('brapi') PathPart
('search/calls') Args
(0) : ActionClass
('REST') { }
4810 sub calls_search_save_POST
{
4813 save_results
($self,$c,$c->stash->{clean_inputs
},'Calls');
4816 sub calls_search_retrieve
: Chained
('brapi') PathPart
('search/calls') Args
(1) {
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
4827 Return JSON example:
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": [
4852 "sourceURI": "https://wiki.brapi.org/files/demo.fast",
4854 "term": "sonic hedgehog",
4855 "termURI": "MGI:MGI:98297"
4866 sub referencesets
: Chained
('brapi') PathPart
('referencesets') Args
(0) : ActionClass
('REST') { }
4868 sub referencesets_GET
{
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) {
4883 $c->stash->{referenceSetDbId
} = $id;
4886 sub referencesets_fetch
: Chained
('referencesets_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
4889 sub referencesets_fetch_GET
{
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
{
4905 save_results
($self,$c,$c->stash->{clean_inputs
},'ReferenceSets');
4908 sub referencesets_search_retrieve
: Chained
('brapi') PathPart
('search/referencesets') Args
(1) {
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
4919 Return JSON example:
4934 "additionalInfo": {},
4936 "md5checksum": "c2365e900c81a89cf74d83dab60df146",
4937 "referenceDbId": "fc0a81d0",
4938 "referenceName": "Chromosome 2",
4939 "referenceSetDbId": "c1ecfef1",
4940 "sourceAccessions": [
4943 "sourceDivergence": 0.01,
4944 "sourceURI": "https://wiki.brapi.org/files/demo.fast",
4946 "term": "sonic hedgehog",
4947 "termURI": "MGI:MGI:98297"
4958 sub reference
: Chained
('brapi') PathPart
('references') Args
(0) : ActionClass
('REST') { }
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) {
4975 $c->stash->{referenceDbId
} = $id;
4978 sub reference_fetch
: Chained
('reference_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
4981 sub reference_fetch_GET
{
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
{
4997 save_results
($self,$c,$c->stash->{clean_inputs
},'References');
5000 sub reference_search_retrieve
: Chained
('brapi') PathPart
('search/references') Args
(1) {
5003 my $search_id = shift;
5004 retrieve_results
($self, $c, $search_id, 'Referenced');
5008 =head2 brapi/v2/crossingprojects
5012 sub crossingprojects
: Chained
('brapi') PathPart
('crossingprojects') Args
(0) : ActionClass
('REST') { }
5014 sub crossingprojects_GET
{
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
{
5028 my ($auth,$user_id) = _authenticate_user
($c);
5029 my $clean_inputs = $c->stash->{clean_inputs
};
5031 my $data = $clean_inputs;
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) {
5050 $c->stash->{crossingProjectDbId
} = $id;
5053 sub crossingproject_fetch
: Chained
('crossingproject_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
5056 sub crossingproject_fetch_GET
{
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
{
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
5084 sub crosses
: Chained
('brapi') PathPart
('crosses') Args
(0) : ActionClass
('REST') { }
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);
5100 my ($auth,$user_id) = _authenticate_user
($c);
5101 my $clean_inputs = $c->stash->{clean_inputs
};
5102 my $data = $clean_inputs;
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);
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
5128 sub seedlots
: Chained
('brapi') PathPart
('seedlots') Args
(0) : ActionClass
('REST') { }
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);
5144 my ($auth,$user_id) = _authenticate_user
($c);
5145 my $clean_inputs = $c->stash->{clean_inputs
};
5146 my $data = $clean_inputs;
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
{
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
{
5177 my ($auth,$user_id) = _authenticate_user
($c);
5178 my $clean_inputs = $c->stash->{clean_inputs
};
5179 my $data = $clean_inputs;
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) {
5197 $c->stash->{seedLotDbId
} = $id;
5200 sub seedlot_single_fetch
: Chained
('seedlot_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
5203 sub seedlot_single_fetch_GET
{
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
{
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
{
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
{
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') { }
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) {
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
{
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
{
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
},
5305 _standard_response_construction
($c, $brapi_package_result);
5312 my $search_params = shift;
5313 my $search_type = shift;
5315 my %server_permission;
5317 my $server_permission = $c->config->{"brapi_GET"};
5318 my @server_permission = split ',', $server_permission;
5319 %server_permission = map { $_ => 1 } @server_permission;
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
{
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);