seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / AJAX / BrAPI.pm
blob4790667a0afb59f0b51756f0235002e168085d98
2 package SGN::Controller::AJAX::BrAPI;
4 use Moose;
5 use JSON::Any;
6 use Data::Dumper;
8 use POSIX;
9 use CXGN::BreedersToolbox::Projects;
10 use CXGN::Trial;
11 use CXGN::Trial::TrialLayout;
12 use CXGN::Stock;
13 use CXGN::Login;
14 use CXGN::Trial::TrialCreate;
15 use CXGN::Trial::Search;
16 use CXGN::Location::LocationLookup;
17 use JSON qw( decode_json );
18 use Data::Dumper;
19 use Try::Tiny;
20 use File::Slurp qw | read_file |;
21 use Spreadsheet::WriteExcel;
22 use Time::Piece;
24 use CXGN::BrAPI;
26 BEGIN { extends 'Catalyst::Controller::REST' };
28 __PACKAGE__->config(
29 default => 'application/json',
30 stash_key => 'rest',
31 map => { 'application/json' => 'JSON' },
34 has 'brapi_module' => (
35 isa => 'CXGN::BrAPI',
36 is => 'rw',
39 has 'bcs_schema' => (
40 isa => 'Bio::Chado::Schema',
41 is => 'rw',
44 my $DEFAULT_PAGE_SIZE=10;
46 sub brapi : Chained('/') PathPart('brapi') CaptureArgs(1) {
47 my $self = shift;
48 my $c = shift;
49 my $version = shift;
50 my @status;
52 my $page = $c->req->param("page") || 0;
53 my $page_size = $c->req->param("pageSize") || $DEFAULT_PAGE_SIZE;
54 my $session_token = $c->req->param("access_token");
55 if (defined $c->request->data){
56 $page = $c->request->data->{"page"} || $page || 0;
57 $page_size = $c->request->data->{"pageSize"} || $page_size || $DEFAULT_PAGE_SIZE;
58 $session_token = $c->request->data->{"access_token"} || $session_token;
60 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
61 my $metadata_schema = $c->dbic_schema("CXGN::Metadata::Schema");
62 my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema");
63 my $people_schema = $c->dbic_schema("CXGN::People::Schema");
64 push @status, { 'info' => "BrAPI base call found with page=$page, pageSize=$page_size" };
66 my $brapi = CXGN::BrAPI->new({
67 version => $version,
68 brapi_module_inst => {
69 bcs_schema => $bcs_schema,
70 metadata_schema => $metadata_schema,
71 phenome_schema => $phenome_schema,
72 people_schema => $people_schema,
73 page_size => $page_size,
74 page => $page,
75 status => \@status
77 });
78 $self->brapi_module($brapi);
79 $self->bcs_schema($bcs_schema);
81 $c->response->headers->header( "Access-Control-Allow-Origin" => '*' );
82 $c->response->headers->header( "Access-Control-Allow-Methods" => "POST, GET, PUT, DELETE" );
83 $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');
84 $c->stash->{session_token} = $session_token;
86 if (defined $c->request->data){
87 my %allParams = (%{$c->request->data}, %{$c->req->params});
88 $c->stash->{clean_inputs} = _clean_inputs(\%allParams);
90 else {
91 $c->stash->{clean_inputs} = _clean_inputs($c->req->params);
95 #useful because javascript can pass 'undef' as an empty value, and also standardizes all inputs as arrayrefs
96 sub _clean_inputs {
97 no warnings 'uninitialized';
98 my $params = shift;
99 foreach (keys %$params){
100 my $values = $params->{$_};
101 my $ret_val;
102 if (ref \$values eq 'SCALAR'){
103 push @$ret_val, $values;
104 } elsif (ref $values eq 'ARRAY'){
105 $ret_val = $values;
106 } else {
107 die "Input is not a scalar or an arrayref\n";
109 @$ret_val = grep {$_ ne undef} @$ret_val;
110 @$ret_val = grep {$_ ne ''} @$ret_val;
111 $_ =~ 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 [].
112 $params->{$_} = $ret_val;
114 return $params;
117 sub _authenticate_user {
118 my $c = shift;
119 my $status = $c->stash->{status};
121 if ($c->config->{brapi_require_login} == 1){
122 my ($person_id, $user_type, $user_pref, $expired) = CXGN::Login->new($c->dbc->dbh)->query_from_cookie($c->stash->{session_token});
123 #print STDERR $person_id." : ".$user_type." : ".$expired;
125 if (!$person_id || $expired || !$user_type) {
126 my $brapi_package_result = CXGN::BrAPI::JSONResponse->return_error($status, 'You must login and have permission to access this BrAPI call.');
127 _standard_response_construction($c, $brapi_package_result);
131 return 1;
134 sub _standard_response_construction {
135 my $c = shift;
136 my $brapi_package_result = shift;
137 my $status = $brapi_package_result->{status};
138 my $pagination = $brapi_package_result->{pagination};
139 my $result = $brapi_package_result->{result};
140 my $datafiles = $brapi_package_result->{datafiles};
142 my %metadata = (pagination=>$pagination, status=>$status, datafiles=>$datafiles);
143 my %response = (metadata=>\%metadata, result=>$result);
144 $c->stash->{rest} = \%response;
145 $c->detach;
148 =head2 /brapi/v1/token
150 Usage: For logging a user in and loggin a user out through the API
151 Desc:
153 For Logging In
154 POST Request:
156 "grant_type" : "password", //(optional, text, `password`) ... The grant type, only allowed value is password, but can be ignored
157 "username" : "user38", // (required, text, `thepoweruser`) ... The username
158 "password" : "secretpw", // (optional, text, `mylittlesecret`) ... The password
159 "client_id" : "blabla" // (optional, text, `blabla`) ... The client id, currently ignored.
162 POST Response:
164 "metadata": {
165 "pagination": {},
166 "status": {},
167 "datafiles": []
169 "userDisplayName": "John Smith",
170 "access_token": "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4",
171 "expires_in": "The lifetime in seconds of the access token"
174 For Logging out
175 DELETE Request:
178 "access_token" : "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4" // (optional, text, `R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4`) ... The user access token. Default: current user token.
181 DELETE Response:
183 "metadata": {
184 "pagination" : {},
185 "status" : { "message" : "User has been logged out successfully."},
186 "datafiles": []
188 "result" : {}
191 =cut
193 sub authenticate_token : Chained('brapi') PathPart('token') Args(0) : ActionClass('REST') { }
195 sub authenticate_token_DELETE {
196 my $self = shift;
197 my $c = shift;
198 my $brapi = $self->brapi_module;
199 my $brapi_module = $brapi->brapi_wrapper('Authentication');
200 my $brapi_package_result = $brapi_module->logout();
201 _standard_response_construction($c, $brapi_package_result);
204 sub authenticate_token_GET {
205 my $self = shift;
206 my $c = shift;
207 process_authenticate_token($self,$c);
210 sub authenticate_token_POST {
211 my $self = shift;
212 my $c = shift;
213 process_authenticate_token($self,$c);
216 sub process_authenticate_token {
217 my $self = shift;
218 my $c = shift;
219 my $clean_inputs = $c->stash->{clean_inputs};
220 my $brapi = $self->brapi_module;
221 my $brapi_module = $brapi->brapi_wrapper('Authentication');
222 my $brapi_package_result = $brapi_module->login(
223 $clean_inputs->{grant_type}->[0],
224 $clean_inputs->{password}->[0],
225 $clean_inputs->{username}->[0],
226 $clean_inputs->{client_id}->[0],
228 my $status = $brapi_package_result->{status};
229 my $pagination = $brapi_package_result->{pagination};
230 my $result = $brapi_package_result->{result};
231 my $datafiles = $brapi_package_result->{datafiles};
233 my %metadata = (pagination=>$pagination, status=>$status, datafiles=>$datafiles);
234 my %response = (metadata=>\%metadata, access_token=>$result->{access_token}, userDisplayName=>$result->{userDisplayName}, expires_in=>$CXGN::Login::LOGIN_TIMEOUT);
235 $c->stash->{rest} = \%response;
236 $c->detach();
239 =head2 /brapi/v1/calls
241 Usage: For determining which calls have been implemented and with which datafile types and methods
242 Desc:
244 GET Request:
246 GET Response:
248 "metadata": {
249 "pagination": {
250 "pageSize": 3,
251 "currentPage": 0,
252 "totalCount": 3,
253 "totalPages": 1
255 "status": {},
256 "datafiles": []
258 "result": {
259 "data": [
261 "call": "allelematrix",
262 "datatypes": [
263 "json",
264 "tsv"
266 "methods": [
267 "GET",
268 "POST"
272 "call": "germplasm/id/mcpd",
273 "datatypes": [
274 "json"
276 "methods": [
277 "GET"
281 "call": "doesntexistyet",
282 "datatypes": [
283 "png",
284 "jpg"
286 "methods": [
287 "GET"
294 =cut
296 sub calls : Chained('brapi') PathPart('calls') Args(0) : ActionClass('REST') { }
298 sub calls_GET {
299 my $self = shift;
300 my $c = shift;
301 my $clean_inputs = $c->stash->{clean_inputs};
302 my $brapi = $self->brapi_module;
303 my $brapi_module = $brapi->brapi_wrapper('Calls');
304 my $brapi_package_result = $brapi_module->calls(
305 $clean_inputs->{datatype}->[0],
307 _standard_response_construction($c, $brapi_package_result);
310 sub crops : Chained('brapi') PathPart('crops') Args(0) : ActionClass('REST') { }
312 sub crops_GET {
313 my $self = shift;
314 my $c = shift;
315 my $supported_crop = $c->config->{'supportedCrop'};
316 my $brapi = $self->brapi_module;
317 my $brapi_module = $brapi->brapi_wrapper('Crops');
318 my $brapi_package_result = $brapi_module->crops($supported_crop);
319 _standard_response_construction($c, $brapi_package_result);
322 sub observation_levels : Chained('brapi') PathPart('observationLevels') Args(0) : ActionClass('REST') { }
324 sub observation_levels_GET {
325 my $self = shift;
326 my $c = shift;
327 my $brapi = $self->brapi_module;
328 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
329 my $brapi_package_result = $brapi_module->observation_levels();
330 _standard_response_construction($c, $brapi_package_result);
333 sub seasons : Chained('brapi') PathPart('seasons') Args(0) : ActionClass('REST') { }
335 sub seasons_POST {
336 my $self = shift;
337 my $c = shift;
338 seasons_process($self, $c);
341 sub seasons_GET {
342 my $self = shift;
343 my $c = shift;
344 seasons_process($self, $c);
347 sub seasons_process {
348 my $self = shift;
349 my $c = shift;
350 my $auth = _authenticate_user($c);
351 my $brapi = $self->brapi_module;
352 my $brapi_module = $brapi->brapi_wrapper('Studies');
353 my $brapi_package_result = $brapi_module->seasons();
354 _standard_response_construction($c, $brapi_package_result);
358 =head2 brapi/v1/studyTypes
360 Usage: To retrieve a list of programs being worked onthe various study types
361 Desc:
362 Return JSON example:
364 "metadata" : {
365 "pagination": {
366 "pageSize": 10,
367 "currentPage": 1,
368 "totalCount": 10,
369 "totalPages": 1
371 "status": []
373 "result" : {
374 "data" : [
376 "name": "Nursery",
377 "description": "Description for Nursery study type"
380 "name": "Trial",
381 "description": "Description for Nursery study type"
386 Args:
387 Side Effects:
389 =cut
391 sub study_types : Chained('brapi') PathPart('studyTypes') Args(0) : ActionClass('REST') { }
393 sub study_types_POST {
394 my $self = shift;
395 my $c = shift;
396 study_types_process($self, $c);
399 sub study_types_GET {
400 my $self = shift;
401 my $c = shift;
402 study_types_process($self, $c);
405 sub study_types_process {
406 my $self = shift;
407 my $c = shift;
408 my $auth = _authenticate_user($c);
409 my $brapi = $self->brapi_module;
410 my $brapi_module = $brapi->brapi_wrapper('Studies');
411 my $brapi_package_result = $brapi_module->study_types();
412 _standard_response_construction($c, $brapi_package_result);
418 =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
420 Usage: For searching a germplasm by name. Allows for exact and wildcard match methods. http://docs.brapi.apiary.io/#germplasm
421 Desc:
423 POST Request:
426 "germplasmPUI" : "http://...", // (optional, text, `http://data.inra.fr/accession/234Col342`) ... The name or synonym of external genebank accession identifier
427 "germplasmDbId" : 986, // (optional, text, `986`) ... The name or synonym of external genebank accession identifier
428 "germplasmSpecies" : "tomato", // (optional, text, `aestivum`) ... The name or synonym of genus or species ( merge with below ?)
429 "germplasmGenus" : "Solanum lycopersicum", //(optional, text, `Triticum, Hordeum`) ... The name or synonym of genus or species
430 "germplasmName" : "XYZ1", // (optional, text, `Triticum, Hordeum`) ... The name or synonym of the accession
431 "accessionNumber" : "ITC1234" // optional
432 "pageSize" : 100, // (optional, integer, `1000`) ... The size of the pages to be returned. Default is `1000`.
433 "page": 1 (optional, integer, `10`) ... Which result page is requested
437 POST Response:
439 "metadata": {
440 "status": {},
441 "datafiles": [],
442 "pagination": {
443 "pageSize": 10,
444 "currentPage": 1,
445 "totalCount": 2,
446 "totalPages": 1
449 "result": {
450 "data":[
452 "germplasmDbId": "01BEL084609",
453 "defaultDisplayName": "Pahang",
454 "accessionNumber": "ITC0609",
455 "germplasmName": "Pahang",
456 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
457 "pedigree": "TOBA97/SW90.1057",
458 "germplasmSeedSource": "Female GID:4/Male GID:4",
459 "synonyms": [ ],
460 "commonCropName": "banana",
461 "instituteCode": "01BEL084",
462 "instituteName": "ITC",
463 "biologicalStatusOfAccessionCode": 412,
464 "countryOfOriginCode": "UNK",
465 "typeOfGermplasmStorageCode": 10,
466 "genus": "Musa",
467 "species": "acuminata",
468 "speciesAuthority": "",
469 "subtaxa": "sp malaccensis var pahang",
470 "subtaxaAuthority": "",
471 "donors":
474 "donorAccessionNumber": "",
475 "donorInstituteCode": "",
476 "germplasmPUI": ""
479 "acquisitionDate": "19470131"
485 =cut
487 sub germplasm_list : Chained('brapi') PathPart('germplasm-search') Args(0) : ActionClass('REST') { }
489 sub germplasm_list_GET {
490 my $self = shift;
491 my $c = shift;
492 germplasm_search_process($self, $c);
495 sub germplasm_list_POST {
496 my $self = shift;
497 my $c = shift;
498 germplasm_search_process($self, $c);
501 sub germplasm_search_process {
502 my $self = shift;
503 my $c = shift;
504 my $auth = _authenticate_user($c);
505 my $clean_inputs = $c->stash->{clean_inputs};
506 my $brapi = $self->brapi_module;
507 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
508 my $brapi_package_result = $brapi_module->germplasm_search({
509 germplasmName => $clean_inputs->{germplasmName},
510 accessionNumber => $clean_inputs->{accessionNumber},
511 germplasmGenus => $clean_inputs->{germplasmGenus},
512 germplasmSubTaxa => $clean_inputs->{germplasmSubTaxa},
513 germplasmSpecies => $clean_inputs->{germplasmSpecies},
514 germplasmDbId => $clean_inputs->{germplasmDbId},
515 germplasmPUI => $clean_inputs->{germplasmPUI},
516 matchMethod => $clean_inputs->{matchMethod},
518 _standard_response_construction($c, $brapi_package_result);
522 =head2 brapi/v1/germplasm/{id}
524 Usage: To retrieve details for a single germplasm
525 Desc:
526 Return JSON example:
528 "metadata": {
529 "status": [],
530 "pagination": {}
532 "result": {
533 "germplasmDbId": "01BEL084609",
534 "defaultDisplayName": "Pahang",
535 "germplasmName": "Pahang",
536 "accessionNumber": "ITC0609",
537 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
538 "pedigree": "TOBA97/SW90.1057",
539 "seedSource": "Female GID:4/Male GID:4",
540 "synonyms": ["Pahanga","Pahange"],
543 Args:
544 Side Effects:
546 =cut
548 sub germplasm_single : Chained('brapi') PathPart('germplasm') CaptureArgs(1) {
549 my $self = shift;
550 my $c = shift;
551 my $stock_id = shift;
553 $c->stash->{stock_id} = $stock_id;
557 sub germplasm_detail : Chained('germplasm_single') PathPart('') Args(0) : ActionClass('REST') { }
559 sub germplasm_detail_POST {
560 my $self = shift;
561 my $c = shift;
562 #my $auth = _authenticate_user($c);
565 sub germplasm_detail_GET {
566 my $self = shift;
567 my $c = shift;
568 my $auth = _authenticate_user($c);
569 my $clean_inputs = $c->stash->{clean_inputs};
570 my $brapi = $self->brapi_module;
571 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
572 my $brapi_package_result = $brapi_module->germplasm_detail(
573 $c->stash->{stock_id}
575 _standard_response_construction($c, $brapi_package_result);
578 =head2 brapi/v1/germplasm/{id}/MCPD
580 MCPD CALL NO LONGER IN BRAPI SPEC
582 Usage: To retrieve multi crop passport descriptor for a single germplasm
583 Desc:
584 Return JSON example:
586 "metadata": {
587 "status": [],
588 "pagination": {}
590 "result": {
591 "germplasmDbId": "01BEL084609",
592 "defaultDisplayName": "Pahang",
593 "accessionNumber": "ITC0609",
594 "germplasmName": "Pahang",
595 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
596 "pedigree": "TOBA97/SW90.1057",
597 "germplasmSeedSource": "Female GID:4/Male GID:4",
598 "synonyms": [ ],
599 "commonCropName": "banana",
600 "instituteCode": "01BEL084",
601 "instituteName": "ITC",
602 "biologicalStatusOfAccessionCode": 412,
603 "countryOfOriginCode": "UNK",
604 "typeOfGermplasmStorageCode": 10,
605 "genus": "Musa",
606 "species": "acuminata",
607 "speciesAuthority": "",
608 "subtaxa": "sp malaccensis var pahang",
609 "subtaxaAuthority": "",
610 "donors":
613 "donorAccessionNumber": "",
614 "donorInstituteCode": "",
615 "germplasmPUI": ""
618 "acquisitionDate": "19470131"
620 Args:
621 Side Effects:
623 =cut
625 #sub germplasm_mcpd : Chained('germplasm_single') PathPart('MCPD') Args(0) : ActionClass('REST') { }
627 #sub germplasm_mcpd_POST {
628 # my $self = shift;
629 # my $c = shift;
630 # my $auth = _authenticate_user($c);
631 # my $status = $c->stash->{status};
633 # $c->stash->{rest} = {status=>$status};
636 #sub germplasm_mcpd_GET {
637 # my $self = shift;
638 # my $c = shift;
639 # #my $auth = _authenticate_user($c);
640 # my $schema = $self->bcs_schema();
641 # my %result;
642 # my $status = $c->stash->{status};
644 # my $synonym_id = $schema->resultset("Cv::Cvterm")->find( { name => "synonym" })->cvterm_id();
645 # my $organism = CXGN::Chado::Organism->new( $schema, $c->stash->{stock}->get_organism_id() );
647 # %result = (germplasmDbId=>$c->stash->{stock_id}, defaultDisplayName=>$c->stash->{stock}->get_uniquename(), accessionNumber=>$c->stash->{stock}->get_uniquename(), germplasmName=>$c->stash->{stock}->get_name(), germplasmPUI=>$c->stash->{stock}->get_uniquename(), pedigree=>germplasm_pedigree_string($schema, $c->stash->{stock_id}), germplasmSeedSource=>'', synonyms=>germplasm_synonyms($schema, $c->stash->{stock_id}, $synonym_id), commonCropName=>$organism->get_common_name(), instituteCode=>'', instituteName=>'', biologicalStatusOfAccessionCode=>'', countryOfOriginCode=>'', typeOfGermplasmStorageCode=>'', genus=>$organism->get_genus(), species=>$organism->get_species(), speciesAuthority=>'', subtaxa=>$organism->get_taxon(), subtaxaAuthority=>'', donors=>'', acquisitionDate=>'');
649 # my %pagination;
650 # my %metadata = (pagination=>\%pagination, status=>$status);
651 # my %response = (metadata=>\%metadata, result=>\%result);
652 # $c->stash->{rest} = \%response;
656 =head2 brapi/v1/studies?programId=programId
658 Usage: To retrieve studies
659 Desc:
660 Return JSON example:
662 "metadata": {
663 "pagination": {
664 "pageSize": 2,
665 "currentPage": 1,
666 "totalCount": 100,
667 "totalPages": 50
669 "status" : []
671 "result": {
672 "data": [
674 "studyDbId": 35,
675 "name": "Earlygenerationtesting",
676 "studyType": "Trial",
677 "years": ["2005", "2008"],
678 "locationDbId": 23,
679 "programDbId": 27,
680 "optionalInfo" : {
681 "studyPUI" : "PUI string",
682 "studyType": "Trial",
683 "startDate": "2015-06-01",
684 "endDate" : "2015-12-31",
689 "studyDbId": 345,
690 "name": "Earlygenerationtesting",
691 "seasons": ["2005", "2008"],
692 "locationDbId": 33,
693 "programDbId": 58,
694 "optionalInfo" : {
695 "studyPUI" : "PUI string",
696 "studyType": "Trial",
697 "startDate": "2015-06-01",
698 "endDate" : "2015-12-31",
704 Args:
705 Side Effects:
707 =cut
709 sub studies_search : Chained('brapi') PathPart('studies-search') Args(0) : ActionClass('REST') { }
711 #sub studies_list_POST {
712 # my $self = shift;
713 # my $c = shift;
714 # my $auth = _authenticate_user($c);
715 # my $status = $c->stash->{status};
716 # my $message = '';
718 # my $study_name = $c->req->param('studyName');
719 # my $location_id = $c->req->param('locationDbId');
720 # my $years = $c->req->param('studyYears');
721 # my $program_id = $c->req->param('programDbId');
722 # my $optional_info = $c->req->param('optionalInfo');
724 # my $description;
725 # my $study_type;
726 # if ($optional_info) {
727 # my $opt_info_hash = decode_json($optional_info);
728 # $description = $opt_info_hash->{"studyObjective"};
729 # $study_type = $opt_info_hash->{"studyType"};
732 # my $program_obj = CXGN::BreedersToolbox::Projects->new({schema => $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado') });
733 # my $programs = $program_obj->get_breeding_programs();
734 # my $program_check;
735 # my $program_name;
736 # foreach (@$programs) {
737 # if ($_->[0] == $program_id) {
738 # $program_check = 1;
739 # $program_name = $_->[1];
742 # if (!$program_check) {
743 # $message .= "Program not found with programDbId = ".$program_id;
744 # $status->{'message'} = $message;
745 # $c->stash->{rest} = {status => $status };
746 # $c->detach();
749 # my $locations = $program_obj->get_all_locations();
750 # my $location_check;
751 # my $location_name;
752 # foreach (@$locations) {
753 # if ($_->[0] == $location_id) {
754 # $location_check = 1;
755 # $location_name = $_->[1];
758 # if (!$location_check) {
759 # $message .= "Location not found with locationDbId = ".$location_id;
760 # $status->{'message'} = $message;
761 # $c->stash->{rest} = {status => $status };
762 # $c->detach();
765 # my $trial_design;
766 # my $trial_create = CXGN::Trial::TrialCreate->new({
767 # dbh => $c->dbc->dbh,
768 # chado_schema => $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado'),
769 # metadata_schema => $c->dbic_schema("CXGN::Metadata::Schema"),
770 # phenome_schema => $c->dbic_schema("CXGN::Phenome::Schema"),
771 # user_name => $c->user()->get_object()->get_username(), #not implemented
772 # program => $program_name,
773 # trial_year => $years,
774 # trial_description => $description,
775 # design_type => $study_type,
776 # trial_location => $location_name,
777 # trial_name => $study_name,
778 # design => $trial_design,
779 # });
781 # if ($trial_create->trial_name_already_exists()) {
782 # $message .= "Trial name \"".$trial_create->get_trial_name()."\" already exists.";
783 # $status->{'message'} = $message;
784 # $c->stash->{rest} = {status => $status };
785 # $c->detach();
788 # try {
789 # $trial_create->save_trial();
790 # } catch {
791 # $message .= "Error saving trial in the database $_";
792 # $status->{'message'} = $message;
793 # $c->stash->{rest} = {status => $status };
794 # $c->detach();
795 # };
797 # $message .= "Study saved successfully.";
798 # $status->{'message'} = $message;
799 # $c->stash->{rest} = {status => $status };
802 sub studies_search_POST {
803 my $self = shift;
804 my $c = shift;
805 studies_search_process($self, $c);
808 sub studies_search_GET {
809 my $self = shift;
810 my $c = shift;
811 studies_search_process($self, $c);
814 sub studies_search_process {
815 my $self = shift;
816 my $c = shift;
817 my $auth = _authenticate_user($c);
818 my $clean_inputs = $c->stash->{clean_inputs};
819 my $brapi = $self->brapi_module;
820 my $brapi_module = $brapi->brapi_wrapper('Studies');
821 my $brapi_package_result = $brapi_module->studies_search({
822 programDbIds => $clean_inputs->{programDbId},
823 programNames => $clean_inputs->{programName},
824 studyDbIds => $clean_inputs->{studyDbId},
825 studyNames => $clean_inputs->{studyName},
826 studyLocationDbIds => $clean_inputs->{locationDbId},
827 studyLocationNames => $clean_inputs->{locationName},
828 studyTypeName => $clean_inputs->{studyType},
829 germplasmDbIds => $clean_inputs->{germplasmDbId},
830 germplasmNames => $clean_inputs->{germplasmName},
831 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
832 observationVariableNames => $clean_inputs->{observationVariableName},
834 _standard_response_construction($c, $brapi_package_result);
837 #BrAPI Trials are modeled as Folders
838 sub trials_list : Chained('brapi') PathPart('trials') Args(0) : ActionClass('REST') { }
840 sub trials_list_GET {
841 my $self = shift;
842 my $c = shift;
843 trials_search_process($self, $c);
846 sub trials_list_POST {
847 my $self = shift;
848 my $c = shift;
849 trials_search_process($self, $c);
852 sub trials_search_process {
853 my $self = shift;
854 my $c = shift;
855 my $auth = _authenticate_user($c);
856 my $clean_inputs = $c->stash->{clean_inputs};
857 my $brapi = $self->brapi_module;
858 my $brapi_module = $brapi->brapi_wrapper('Trials');
859 my $brapi_package_result = $brapi_module->trials_search({
860 locationDbIds => $clean_inputs->{locationDbId},
861 programDbIds => $clean_inputs->{programDbId},
863 _standard_response_construction($c, $brapi_package_result);
867 sub trials_single : Chained('brapi') PathPart('trials') CaptureArgs(1) {
868 my $self = shift;
869 my $c = shift;
870 my $folder_id = shift;
872 $c->stash->{trial_id} = $folder_id;
876 sub trials_detail : Chained('trials_single') PathPart('') Args(0) : ActionClass('REST') { }
878 sub trials_detail_POST {
879 my $self = shift;
880 my $c = shift;
881 #my $auth = _authenticate_user($c);
884 sub trials_detail_GET {
885 my $self = shift;
886 my $c = shift;
887 my $auth = _authenticate_user($c);
888 my $clean_inputs = $c->stash->{clean_inputs};
889 my $brapi = $self->brapi_module;
890 my $brapi_module = $brapi->brapi_wrapper('Trials');
891 my $brapi_package_result = $brapi_module->trial_details(
892 $c->stash->{trial_id}
894 _standard_response_construction($c, $brapi_package_result);
897 =head2 brapi/v1/studies/{studyId}/germplasm?pageSize=20&page=1
899 Usage: To retrieve all germplasm used in a study
900 Desc:
901 Return JSON example:
903 "metadata": {
904 "status": [],
905 "pagination": {
906 "pageSize": 1000,
907 "currentPage": 1,
908 "totalCount": 1,
909 "totalPages": 1
912 "result": {
913 "studyDbId": 123,
914 "studyName": "myBestTrial",
915 "data": [
917 "germplasmDbId": "382",
918 "trialEntryNumberId": "1",
919 "defaultDisplayName": "Pahang",
920 "germplasmName": "Pahang",
921 "accessionNumber": "ITC0609",
922 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
923 "pedigree": "TOBA97/SW90.1057",
924 "seedSource": "",
925 "synonyms": ["01BEL084609"],
928 "germplasmDbId": "394",
929 "trialEntryNumberId": "2",
930 "defaultDisplayName": "Pahang",
931 "germplasmName": "Pahang",
932 "accessionNumber": "ITC0727",
933 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084727",
934 "pedigree": "TOBA97/SW90.1057",
935 "seedSource": "",
936 "synonyms": [ "01BEL084727"],
941 Args:
942 Side Effects:
944 =cut
946 sub studies_single : Chained('brapi') PathPart('studies') CaptureArgs(1) {
947 my $self = shift;
948 my $c = shift;
949 my $study_id = shift;
951 $c->stash->{study_id} = $study_id;
955 sub studies_germplasm : Chained('studies_single') PathPart('germplasm') Args(0) : ActionClass('REST') { }
957 sub studies_germplasm_POST {
958 my $self = shift;
959 my $c = shift;
960 my $auth = _authenticate_user($c);
962 my $metadata = $c->req->params("metadata");
963 my $result = $c->req->params("result");
964 my %metadata_hash = %$metadata;
965 my %result_hash = %$result;
967 #print STDERR Dumper($metadata);
968 #print STDERR Dumper($result);
970 my $pagintation = $metadata_hash{"pagination"};
973 sub studies_germplasm_GET {
974 my $self = shift;
975 my $c = shift;
976 my $auth = _authenticate_user($c);
977 my $brapi = $self->brapi_module;
978 my $brapi_module = $brapi->brapi_wrapper('Studies');
979 my $brapi_package_result = $brapi_module->studies_germplasm(
980 $c->stash->{study_id}
982 _standard_response_construction($c, $brapi_package_result);
986 =head2 brapi/v1/germplasm/{id}/pedigree?notation=purdy
988 Usage: To retrieve pedigree information for a single germplasm
989 Desc:
990 Return JSON example:
992 "metadata": {
993 "status": [],
994 "pagination": {}
996 "result": {
997 "germplasmDbId": "382",
998 "pedigree": "TOBA97/SW90.1057",
999 "parent1Id": "23",
1000 "parent2Id": "55"
1003 Args:
1004 Side Effects:
1006 =cut
1008 sub germplasm_pedigree : Chained('germplasm_single') PathPart('pedigree') Args(0) : ActionClass('REST') { }
1010 sub germplasm_pedigree_POST {
1011 my $self = shift;
1012 my $c = shift;
1013 #my $auth = _authenticate_user($c);
1016 sub germplasm_pedigree_GET {
1017 my $self = shift;
1018 my $c = shift;
1019 my $auth = _authenticate_user($c);
1020 my $clean_inputs = $c->stash->{clean_inputs};
1021 my $brapi = $self->brapi_module;
1022 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1023 my $brapi_package_result = $brapi_module->germplasm_pedigree({
1024 stock_id => $c->stash->{stock_id},
1025 notation => $clean_inputs->{notation}->[0]
1027 _standard_response_construction($c, $brapi_package_result);
1031 =head2 brapi/v1/germplasm/{id}/progeny?notation=purdy
1033 Usage: To retrieve progeny (direct descendant) information for a single germplasm
1034 Desc:
1035 Return JSON example:
1037 "metadata" : {
1038 "pagination": {},
1039 "status": [],
1040 "datafiles": []
1042 "result" : {
1043 "germplasmDbId": "382",
1044 "defaultDisplayName": "Pahang",
1045 "data" : [{
1046 "progenyGermplasmDbId": "403",
1047 "parentType": "FEMALE"
1048 }, {
1049 "progenyGermplasmDbId": "402",
1050 "parentType": "MALE"
1051 }, {
1052 "progenyGermplasmDbId": "405",
1053 "parentType": "SELF"
1057 Args:
1058 Side Effects:
1060 =cut
1062 sub germplasm_progeny : Chained('germplasm_single') PathPart('progeny') Args(0) : ActionClass('REST') { }
1064 sub germplasm_progeny_POST {
1065 my $self = shift;
1066 my $c = shift;
1069 sub germplasm_progeny_GET {
1070 my $self = shift;
1071 my $c = shift;
1072 my $auth = _authenticate_user($c);
1073 my $clean_inputs = $c->stash->{clean_inputs};
1074 my $brapi = $self->brapi_module;
1075 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1076 my $brapi_package_result = $brapi_module->germplasm_progeny({
1077 stock_id => $c->stash->{stock_id}
1079 _standard_response_construction($c, $brapi_package_result);
1085 sub germplasm_attributes_detail : Chained('germplasm_single') PathPart('attributes') Args(0) : ActionClass('REST') { }
1087 sub germplasm_attributes_detail_GET {
1088 my $self = shift;
1089 my $c = shift;
1090 my $auth = _authenticate_user($c);
1091 my $clean_inputs = $c->stash->{clean_inputs};
1092 my $brapi = $self->brapi_module;
1093 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1094 my $brapi_package_result = $brapi_module->germplasm_attributes_germplasm_detail({
1095 stock_id => $c->stash->{stock_id},
1096 attribute_dbids => $clean_inputs->{attributeDbId}
1098 _standard_response_construction($c, $brapi_package_result);
1101 =head2 brapi/v1/germplasm/{id}/markerprofiles
1103 Usage: To retrieve markerprofile ids for a single germplasm
1104 Desc:
1105 Return JSON example:
1107 "metadata": {
1108 "status": [],
1109 "pagination": {}
1111 "result": {
1112 "germplasmDbId": "382",
1113 "markerProfiles": [
1114 "123",
1115 "456"
1119 Args:
1120 Side Effects:
1122 =cut
1124 sub germplasm_markerprofile : Chained('germplasm_single') PathPart('markerprofiles') Args(0) : ActionClass('REST') { }
1126 sub germplasm_markerprofile_POST {
1127 my $self = shift;
1128 my $c = shift;
1129 #my $auth = _authenticate_user($c);
1132 sub germplasm_markerprofile_GET {
1133 my $self = shift;
1134 my $c = shift;
1135 my $auth = _authenticate_user($c);
1136 my $clean_inputs = $c->stash->{clean_inputs};
1137 my $brapi = $self->brapi_module;
1138 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1139 my $brapi_package_result = $brapi_module->germplasm_markerprofiles(
1140 $c->stash->{stock_id}
1142 _standard_response_construction($c, $brapi_package_result);
1147 # Need to implement Germplasm Attributes
1150 sub germplasm_attributes_list : Chained('brapi') PathPart('attributes') Args(0) : ActionClass('REST') { }
1152 sub germplasm_attributes_list_GET {
1153 my $self = shift;
1154 my $c = shift;
1155 germplasm_attributes_process($self, $c);
1158 sub germplasm_attributes_process {
1159 my $self = shift;
1160 my $c = shift;
1161 my $auth = _authenticate_user($c);
1162 my $clean_inputs = $c->stash->{clean_inputs};
1163 my $brapi = $self->brapi_module;
1164 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1165 my $brapi_package_result = $brapi_module->germplasm_attributes_list({
1166 attribute_category_dbids => $clean_inputs->{attributeCategoryDbId}
1168 _standard_response_construction($c, $brapi_package_result);
1172 sub germplasm_attribute_categories_list : Chained('brapi') PathPart('attributes/categories') Args(0) : ActionClass('REST') { }
1174 sub germplasm_attribute_categories_list_GET {
1175 my $self = shift;
1176 my $c = shift;
1177 germplasm_attributes_categories_process($self, $c);
1180 sub germplasm_attributes_categories_process {
1181 my $self = shift;
1182 my $c = shift;
1183 my $auth = _authenticate_user($c);
1184 my $brapi = $self->brapi_module;
1185 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1186 my $brapi_package_result = $brapi_module->germplasm_attributes_categories_list();
1187 _standard_response_construction($c, $brapi_package_result);
1192 =head2 brapi/v1/markerprofiles?germplasm=germplasmDbId&extract=extractDbId&method=methodDbId
1194 Usage: To retrieve markerprofile ids for a single germplasm
1195 Desc:
1196 Return JSON example:
1198 "metadata" : {
1199 "pagination": {
1200 "pageSize": 10,
1201 "currentPage": 1,
1202 "totalCount": 10,
1203 "totalPages": 1
1205 "status": []
1207 "result" : {
1208 "data" : [
1210 "markerProfileDbId": "993",
1211 "germplasmDbId" : 2374,
1212 "extractDbId" : 3939,
1213 "analysisMethod": "GoldenGate",
1214 "resultCount": 1470
1217 "markerProfileDbId": "994",
1218 "germplasmDbId" : 2374,
1219 "extractDbId" : 3939,
1220 "analysisMethod": "GBS",
1221 "resultCount": 1470
1226 Args:
1227 Side Effects:
1229 =cut
1231 sub markerprofile_search_process {
1232 my $self = shift;
1233 my $c = shift;
1234 my $auth = _authenticate_user($c);
1235 my $default_protocol = $self->bcs_schema->resultset('NaturalDiversity::NdProtocol')->find({name=>$c->config->{default_genotyping_protocol}});
1236 my $default_protocol_id = $default_protocol ? $default_protocol->nd_protocol_id : 0;
1237 my $clean_inputs = $c->stash->{clean_inputs};
1238 my $brapi = $self->brapi_module;
1239 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1240 my $brapi_package_result = $brapi_module->markerprofiles_search({
1241 study_ids => $clean_inputs->{studyDbId},
1242 stock_ids => $clean_inputs->{germplasmDbId},
1243 extract_ids => $clean_inputs->{extractDbId},
1244 sample_ids => $clean_inputs->{sampleDbId},
1245 protocol_id => $clean_inputs->{methodDbId}->[0] ? $clean_inputs->{methodDbId}->[0] : $default_protocol_id
1247 _standard_response_construction($c, $brapi_package_result);
1250 sub markerprofiles_list : Chained('brapi') PathPart('markerprofiles') Args(0) : ActionClass('REST') { }
1252 sub markerprofiles_list_POST {
1253 my $self = shift;
1254 my $c = shift;
1255 markerprofile_search_process($self, $c);
1258 sub markerprofiles_list_GET {
1259 my $self = shift;
1260 my $c = shift;
1261 markerprofile_search_process($self, $c);
1265 =head2 brapi/v1/markerprofiles/markerprofilesDbId
1267 Usage: To retrieve data for a single markerprofile
1268 Desc:
1269 Return JSON example:
1271 "metadata" : {
1272 "pagination": {
1273 "pageSize": 10,
1274 "currentPage": 1,
1275 "totalCount": 10,
1276 "totalPages": 1
1278 "status": []
1281 "result": {
1282 "germplasmDbId": 993,
1283 "extractDbId" : 38383,
1284 "markerprofileDbId": 37484,
1285 "analysisMethod": "GBS-Pst1",
1286 "encoding": "AA,BB,AB",
1287 "data" : [ { "marker1": "AA" }, { "marker2":"AB" }, ... ]
1290 Args:
1291 Side Effects:
1293 =cut
1295 sub markerprofiles_single : Chained('brapi') PathPart('markerprofiles') CaptureArgs(1) {
1296 my $self = shift;
1297 my $c = shift;
1298 my $id = shift;
1299 $c->stash->{markerprofile_id} = $id; # this is genotypeprop_id
1302 sub genotype_fetch : Chained('markerprofiles_single') PathPart('') Args(0) : ActionClass('REST') { }
1304 sub genotype_fetch_POST {
1305 my $self = shift;
1306 my $c = shift;
1307 #my $auth = _authenticate_user($c);
1310 sub genotype_fetch_GET {
1311 my $self = shift;
1312 my $c = shift;
1313 my $auth = _authenticate_user($c);
1314 my $clean_inputs = $c->stash->{clean_inputs};
1315 my $brapi = $self->brapi_module;
1316 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1317 my $brapi_package_result = $brapi_module->markerprofiles_detail({
1318 markerprofile_id => $c->stash->{markerprofile_id},
1319 unknown_string => $clean_inputs->{unknownString}->[0],
1320 sep_phased => $clean_inputs->{sepPhased}->[0],
1321 sep_unphased => $clean_inputs->{sepUnphased}->[0],
1322 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
1324 _standard_response_construction($c, $brapi_package_result);
1328 sub markerprofiles_methods : Chained('brapi') PathPart('markerprofiles/methods') Args(0) {
1329 my $self = shift;
1330 my $c = shift;
1331 my $auth = _authenticate_user($c);
1332 my $brapi = $self->brapi_module;
1333 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1334 my $brapi_package_result = $brapi_module->markerprofiles_methods();
1335 _standard_response_construction($c, $brapi_package_result);
1340 =head2 brapi/v1/allelematrix?markerprofileDbId=100&markerprofileDbId=101
1342 Usage: Gives a matrix data structure for a given list of markerprofileDbIds
1343 Desc:
1344 Return JSON example:
1346 "metadata": {
1347 "status": [],
1348 "pagination": {
1349 "pageSize": 100,
1350 "currentPage": 1,
1351 "totalCount": 1,
1352 "totalPages": 1
1355 "result" : {
1356 "makerprofileDbIds": ["markerprofileId1","markerprofileId2","markerprofileId3"],
1357 "data" : [
1358 { "markerDbId1":["AB","AA","AA"] },
1359 { "markerDbId2":["AA","AB","AA"] },
1360 { "markerDbId3":["AB","AB","BB"] }
1364 Args:
1365 Side Effects:
1367 =cut
1369 sub allelematrix : Chained('brapi') PathPart('allelematrix-search') Args(0) : ActionClass('REST') { }
1371 sub allelematrix_POST {
1372 my $self = shift;
1373 my $c = shift;
1374 allelematrix_search_process($self, $c);
1377 sub allelematrix_GET {
1378 my $self = shift;
1379 my $c = shift;
1380 allelematrix_search_process($self, $c);
1383 sub allelematrix_search_process {
1384 my $self = shift;
1385 my $c = shift;
1386 my $auth = _authenticate_user($c);
1388 my $clean_inputs = $c->stash->{clean_inputs};
1389 my $format = $clean_inputs->{format}->[0];
1390 my $file_path;
1391 my $uri;
1392 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
1393 my $dir = $c->tempfiles_subdir('download');
1394 ($file_path, $uri) = $c->tempfile( TEMPLATE => 'download/allelematrix_'.$format.'_'.'XXXXX');
1396 my $brapi = $self->brapi_module;
1397 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1398 my $brapi_package_result = $brapi_module->markerprofiles_allelematrix({
1399 markerprofile_ids => $clean_inputs->{markerprofileDbId},
1400 marker_ids => $clean_inputs->{markerDbId},
1401 unknown_string => $clean_inputs->{unknownString}->[0],
1402 sep_phased => $clean_inputs->{sepPhased}->[0],
1403 sep_unphased => $clean_inputs->{sepUnphased}->[0],
1404 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
1405 format => $format,
1406 main_production_site_url => $c->config->{main_production_site_url},
1407 file_path => $file_path,
1408 file_uri => $uri
1410 _standard_response_construction($c, $brapi_package_result);
1414 =head2 brapi/v1/programs
1416 Usage: To retrieve a list of programs being worked on
1417 Desc:
1418 Return JSON example:
1420 "metadata" : {
1421 "pagination": {
1422 "pageSize": 10,
1423 "currentPage": 1,
1424 "totalCount": 10,
1425 "totalPages": 1
1427 "status": []
1429 "result" : {
1430 "data" : [
1432 "programDbid": "123",
1433 "name": "Wheat Resistance Program",
1434 "objective" : "Disease resistance",
1435 "leadPerson" : "Dr. Henry Beachell"
1438 "programDbId": "456",
1439 "name": "Wheat Improvement Program",
1440 "objective" : "Yield improvement",
1441 "leadPerson" : "Dr. Norman Borlaug"
1446 Args:
1447 Side Effects:
1449 =cut
1451 sub programs_list : Chained('brapi') PathPart('programs') Args(0) : ActionClass('REST') { }
1453 sub programs_list_POST {
1454 my $self = shift;
1455 my $c = shift;
1456 #my $auth = _authenticate_user($c);
1459 sub programs_list_GET {
1460 my $self = shift;
1461 my $c = shift;
1462 my $auth = _authenticate_user($c);
1463 my $clean_inputs = $c->stash->{clean_inputs};
1464 my $brapi = $self->brapi_module;
1465 my $brapi_module = $brapi->brapi_wrapper('Programs');
1466 my $brapi_package_result = $brapi_module->programs_list({
1467 program_names => $clean_inputs->{programName},
1468 abbreviations => $clean_inputs->{abbreviation},
1470 _standard_response_construction($c, $brapi_package_result);
1476 sub studies_info : Chained('studies_single') PathPart('') Args(0) : ActionClass('REST') { }
1478 sub studies_info_POST {
1479 my $self = shift;
1480 my $c = shift;
1481 #my $auth = _authenticate_user($c);
1484 sub studies_info_GET {
1485 my $self = shift;
1486 my $c = shift;
1487 my $auth = _authenticate_user($c);
1488 my $clean_inputs = $c->stash->{clean_inputs};
1489 my $brapi = $self->brapi_module;
1490 my $brapi_module = $brapi->brapi_wrapper('Studies');
1491 my $brapi_package_result = $brapi_module->studies_detail(
1492 $c->stash->{study_id}
1494 _standard_response_construction($c, $brapi_package_result);
1498 sub studies_observation_variables : Chained('studies_single') PathPart('observationVariables') Args(0) : ActionClass('REST') { }
1500 sub studies_observation_variables_POST {
1501 my $self = shift;
1502 my $c = shift;
1503 #my $auth = _authenticate_user($c);
1506 sub studies_observation_variables_GET {
1507 my $self = shift;
1508 my $c = shift;
1509 my $auth = _authenticate_user($c);
1510 my $brapi = $self->brapi_module;
1511 my $brapi_module = $brapi->brapi_wrapper('Studies');
1512 my $brapi_package_result = $brapi_module->studies_observation_variables(
1513 $c->stash->{study_id}
1515 _standard_response_construction($c, $brapi_package_result);
1520 sub studies_layout : Chained('studies_single') PathPart('layout') Args(0) : ActionClass('REST') { }
1522 sub studies_layout_POST {
1523 my $self = shift;
1524 my $c = shift;
1525 #my $auth = _authenticate_user($c);
1528 sub studies_layout_GET {
1529 my $self = shift;
1530 my $c = shift;
1531 my $clean_inputs = $c->stash->{clean_inputs};
1532 my $auth = _authenticate_user($c);
1533 my $format = $clean_inputs->{format}->[0] || 'json';
1534 my $file_path;
1535 my $uri;
1536 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
1537 my $dir = $c->tempfiles_subdir('download');
1538 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
1539 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
1540 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
1543 my $brapi = $self->brapi_module;
1544 my $brapi_module = $brapi->brapi_wrapper('Studies');
1545 my $brapi_package_result = $brapi_module->studies_layout({
1546 study_id => $c->stash->{study_id},
1547 format => $format,
1548 main_production_site_url => $c->config->{main_production_site_url},
1549 file_path => $file_path,
1550 file_uri => $uri
1552 _standard_response_construction($c, $brapi_package_result);
1556 =head2 brapi/v1/studies/<studyDbId>/observationUnits?observationVariableDbId=2
1558 Usage: To retrieve phenotypic values on a the plot level for an entire trial
1559 Desc:
1560 Return JSON example:
1562 "metadata" : "status": [],
1563 "pagination": {
1564 "pageSize": 1,
1565 "currentPage": 1,
1566 "totalCount": 1,
1567 "totalPages": 1
1569 "result" : {
1570 "data" : [
1572 "studyDbId": 1,
1573 "plotDbId": 11,
1574 "observationVariableDbId" : 393939,
1575 "observationVariableName" : "Yield",
1576 "plotName": "ZIPA_68_Ibadan_2014",
1577 "timestamp" : "2015-11-05 15:12",
1578 "uploadedBy" : {dbUserId},
1579 "operator" : "Jane Doe",
1580 "germplasmName": 143,
1581 "value" : 5,
1586 Args:
1587 Side Effects:
1589 =cut
1591 sub studies_observations : Chained('studies_single') PathPart('observationunits') Args(0) : ActionClass('REST') { }
1593 sub studies_observations_POST {
1594 my $self = shift;
1595 my $c = shift;
1596 #my $auth = _authenticate_user($c);
1599 sub studies_observations_GET {
1600 my $self = shift;
1601 my $c = shift;
1602 my $clean_inputs = $c->stash->{clean_inputs};
1603 my $auth = _authenticate_user($c);
1604 my $brapi = $self->brapi_module;
1605 my $brapi_module = $brapi->brapi_wrapper('Studies');
1606 my $brapi_package_result = $brapi_module->observation_units({
1607 study_id => $c->stash->{study_id},
1608 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
1609 data_level => $clean_inputs->{observationLevel}->[0]
1611 _standard_response_construction($c, $brapi_package_result);
1615 =head2 brapi/v1/studies/<studyDbId>/table
1617 Usage: To retrieve phenotypic values for a study, in a manner representative of a table, with headers and data separated
1618 Desc:
1619 Return JSON example:
1621 "metadata": {
1622 "status": [],
1623 "pagination": {
1624 "pageSize": 1,
1625 "currentPage": 1,
1626 "totalCount": 1,
1627 "totalPages": 1
1630 "result" : {
1631 "studyDbId": 1,
1632 "observationVariableDbId": [ '', '', '', '', '', '', '', '', 44444, 55555, 66666...],
1633 "observationVariableName": [ "plotDbId", "plotName", "block", "rep", "germplasmID", "germplasmName", "operator", "timestamp", "Yield", "Color", "Dry Matter"...],
1635 "data" :
1637 [1, "plot1", 1, 1, "CIP1", 41, "user1", "2015-11-05 15:12", 10, "yellow", 9, ...],
1638 [2, "plot2", 1, 1, "CIP2", 42, "user1", "2015-11-05 20:12", 3, "red", 4, ...]
1642 Args:
1643 Side Effects:
1645 =cut
1647 sub studies_table : Chained('studies_single') PathPart('table') Args(0) : ActionClass('REST') { }
1649 sub studies_table_POST {
1650 my $self = shift;
1651 my $c = shift;
1652 my $trait_id = shift;
1653 #my $auth = _authenticate_user($c);
1656 sub studies_table_GET {
1657 my $self = shift;
1658 my $c = shift;
1659 my $auth = _authenticate_user($c);
1661 my $clean_inputs = $c->stash->{clean_inputs};
1662 my $format = $clean_inputs->{format}->[0];
1663 my $file_path;
1664 my $uri;
1665 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
1666 my $dir = $c->tempfiles_subdir('download');
1667 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
1668 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
1669 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
1671 my $brapi = $self->brapi_module;
1672 my $brapi_module = $brapi->brapi_wrapper('Studies');
1673 my $brapi_package_result = $brapi_module->studies_table({
1674 study_id => $c->stash->{study_id},
1675 data_level => $clean_inputs->{observationLevel}->[0],
1676 search_type => $clean_inputs->{search_type}->[0],
1677 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
1678 trait_ids => $clean_inputs->{observationVariableDbId},
1679 trial_ids => $clean_inputs->{studyDbId},
1680 format => $format,
1681 main_production_site_url => $c->config->{main_production_site_url},
1682 file_path => $file_path,
1683 file_uri => $uri
1685 _standard_response_construction($c, $brapi_package_result);
1689 =head2 brapi/v1/studies/<studyDbId>/observations?observationVariableDbId=2
1691 Usage: To retrieve phenotypic values on a the plot level for an entire trial
1692 Desc:
1693 Return JSON example:
1695 "metadata" : "status": [],
1696 "pagination": {
1697 "pageSize": 1,
1698 "currentPage": 1,
1699 "totalCount": 1,
1700 "totalPages": 1
1702 "result" : {
1703 "data" : [
1705 "studyDbId": 1,
1706 "plotDbId": 11,
1707 "observationVariableDbId" : 393939,
1708 "observationVariableName" : "Yield",
1709 "plotName": "ZIPA_68_Ibadan_2014",
1710 "timestamp" : "2015-11-05 15:12",
1711 "uploadedBy" : {dbUserId},
1712 "operator" : "Jane Doe",
1713 "germplasmName": 143,
1714 "value" : 5,
1719 Args:
1720 Side Effects:
1722 =cut
1724 sub studies_observations_granular : Chained('studies_single') PathPart('observations') Args(0) : ActionClass('REST') { }
1726 sub studies_observations_granular_POST {
1727 my $self = shift;
1728 my $c = shift;
1729 #my $auth = _authenticate_user($c);
1732 sub studies_observations_granular_GET {
1733 my $self = shift;
1734 my $c = shift;
1735 my $clean_inputs = $c->stash->{clean_inputs};
1736 my $auth = _authenticate_user($c);
1737 my $brapi = $self->brapi_module;
1738 my $brapi_module = $brapi->brapi_wrapper('Studies');
1739 my $brapi_package_result = $brapi_module->observation_units_granular({
1740 study_id => $c->stash->{study_id},
1741 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
1742 data_level => $clean_inputs->{observationLevel}->[0],
1743 search_type => $clean_inputs->{search_type}->[0],
1744 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
1746 _standard_response_construction($c, $brapi_package_result);
1749 =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}
1751 Usage: To retrieve a phenotype dataset
1752 Desc:d
1753 Return JSON example:
1755 "metadata": {
1756 "pagination": {
1757 "pageSize": 10,
1758 "currentPage": 1,
1759 "totalCount": 10,
1760 "totalPages": 1
1762 "status": []
1765 "result" : {
1766 "observationUnitDbId": 20,
1767 "observationUnitPUI": "http://phenome-fppn.fr/maugio/bloc/12/2345",
1768 "studyId": "RIGW1",
1769 "studyDbId": 25,
1770 "studyLocation": "Bergheim",
1771 "studyPUI": "http://phenome-fppn.fr/phenoarch/2014/1",
1772 "studyProject": "Inovine",
1773 "studySet": ["National Network", "Frost suceptibility network"],
1774 "studyPlatform": "Phenome",
1775 "observationUnitLevelTypes" : [ "plant","plot", "bloc"],
1776 "observationUnitLevelLabels": [ "1","26123", "1"],
1777 "germplasmPUI": "http://inra.fr/vassal/41207Col0001E",
1778 "germplasmDbId": 3425,
1779 "germplasmName": "charger",
1780 "treatments":
1783 "factor" : "water regimen" ,
1784 "modality":"water deficit"
1787 "attributes":
1789 {"att1" :"value"},
1790 {"numPot" :"23"}
1792 "X" : "",
1793 "Y" : "",
1794 "XLabel" : "",
1795 "YLabel" : "",
1796 "data": [
1798 "instanceNumber" : 1,
1799 "observationVariableId": "CO_321:0000045",
1800 //"observationVariableDbId": 35,
1801 "season": "2005",
1802 "observationValue" : "red",
1803 "observationTimeStamp": null,
1804 "quality": "reliability of the observation",
1805 "collectionFacilityLabel": "phenodyne",
1806 "collector" : "John Doe and team"
1809 "instanceNumber" : 1,
1810 "observationVariableId": "http://www.cropontology.org/rdf/CO_321:0000025",
1811 //"observationVariableDbId": 35,
1812 "season": null,
1813 "observationValue" : 32,
1814 "observationTimeStamp": "2006-07-03::10:00",
1815 "quality": "8",
1816 "collectionFacilityLabel": null,
1817 "collector" : "userURIOrName"
1823 Args:
1824 Side Effects:
1826 =cut
1828 sub phenotypes_search : Chained('brapi') PathPart('phenotypes-search') Args(0) : ActionClass('REST') { }
1830 sub phenotypes_search_POST {
1831 my $self = shift;
1832 my $c = shift;
1833 process_phenotypes_search($self, $c);
1836 sub phenotypes_search_GET {
1837 my $self = shift;
1838 my $c = shift;
1839 process_phenotypes_search($self, $c);
1842 sub process_phenotypes_search {
1843 my $self = shift;
1844 my $c = shift;
1845 my $auth = _authenticate_user($c);
1846 my $clean_inputs = $c->stash->{clean_inputs};
1847 my $brapi = $self->brapi_module;
1848 my $brapi_module = $brapi->brapi_wrapper('Phenotypes');
1849 my $brapi_package_result = $brapi_module->search({
1850 trait_ids => $clean_inputs->{observationVariableDbIds},
1851 accession_ids => $clean_inputs->{germplasmDbIds},
1852 study_ids => $clean_inputs->{studyDbIds},
1853 location_ids => $clean_inputs->{locationDbIds},
1854 years => $clean_inputs->{seasonDbIds},
1855 data_level => $clean_inputs->{observationLevel}->[0],
1856 search_type => $clean_inputs->{search_type}->[0],
1857 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
1859 _standard_response_construction($c, $brapi_package_result);
1862 sub traits_list : Chained('brapi') PathPart('traits') Args(0) : ActionClass('REST') { }
1864 sub traits_list_POST {
1865 my $self = shift;
1866 my $c = shift;
1867 #my $auth = _authenticate_user($c);
1870 sub traits_list_GET {
1871 my $self = shift;
1872 my $c = shift;
1873 my $auth = _authenticate_user($c);
1874 my $clean_inputs = $c->stash->{clean_inputs};
1875 my $brapi = $self->brapi_module;
1876 my $brapi_module = $brapi->brapi_wrapper('Traits');
1877 my $brapi_package_result = $brapi_module->list({
1878 trait_ids => $clean_inputs->{traitDbIds},
1879 names => $clean_inputs->{names}
1881 _standard_response_construction($c, $brapi_package_result);
1885 sub traits_single : Chained('brapi') PathPart('traits') CaptureArgs(1) {
1886 my $self = shift;
1887 my $c = shift;
1888 my $trait_id = shift;
1890 $c->stash->{trait_id} = $trait_id;
1894 sub trait_detail : Chained('traits_single') PathPart('') Args(0) : ActionClass('REST') { }
1896 sub trait_detail_GET {
1897 my $self = shift;
1898 my $c = shift;
1899 my $auth = _authenticate_user($c);
1900 my $clean_inputs = $c->stash->{clean_inputs};
1901 my $brapi = $self->brapi_module;
1902 my $brapi_module = $brapi->brapi_wrapper('Traits');
1903 my $brapi_package_result = $brapi_module->detail(
1904 $c->stash->{trait_id}
1906 _standard_response_construction($c, $brapi_package_result);
1910 =head2 brapi/v1/maps?species=speciesId
1912 Usage: To retrieve a list of all maps available in the database.
1913 Desc:
1914 Return JSON example:
1916 "metadata" : {
1917 "pagination" : {
1918 "pageSize": 30,
1919 "currentPage": 2,
1920 "totalCount": 40,
1921 "totalPages": 2
1923 "status" : []
1925 "result": {
1926 "data" : [
1928 "mapId": 1,
1929 "name": "Some Map",
1930 "species": "Some species",
1931 "type": "Genetic",
1932 "unit": "cM",
1933 "publishedDate": "2008-04-16",
1934 "markerCount": 1000,
1935 "linkageGroupCount": 7,
1936 "comments": "This map contains ..."
1939 "mapId": 2,
1940 "name": "Some Other map",
1941 "species": "Some Species",
1942 "type": "Genetic",
1943 "unit": "cM",
1944 "publishedDate": "2009-01-12",
1945 "markerCount": 1501,
1946 "linkageGroupCount": 7,
1947 "comments": "this is blah blah"
1952 Args:
1953 Side Effects:
1955 =cut
1957 sub maps_list : Chained('brapi') PathPart('maps') Args(0) : ActionClass('REST') { }
1959 sub maps_list_POST {
1960 my $self = shift;
1961 my $c = shift;
1962 #my $auth = _authenticate_user($c);
1965 sub maps_list_GET {
1966 my $self = shift;
1967 my $c = shift;
1968 my $auth = _authenticate_user($c);
1969 my $clean_inputs = $c->stash->{clean_inputs};
1970 my $brapi = $self->brapi_module;
1971 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
1972 my $brapi_package_result = $brapi_module->list();
1973 _standard_response_construction($c, $brapi_package_result);
1978 =head2 brapi/v1/maps/<map_id>
1980 Usage: To retrieve details for a specific map_id
1981 Desc:
1982 Return JSON example:
1984 "metadata" : {
1985 "pagination" : {
1986 "pageSize": 30,
1987 "currentPage": 2,
1988 "totalCount": 40,
1989 "totalPages": 2
1991 "status" : []
1993 "result": {
1994 "mapId": "id",
1995 "name": "Some map",
1996 "type": "Genetic",
1997 "unit": "cM",
1998 "linkageGroups": [
2000 "linkageGroupId": 1,
2001 "numberMarkers": 100000,
2002 "maxPosition": 10000000
2005 "linkageGroupId": 2,
2006 "numberMarkers": 1247,
2007 "maxPostion": 12347889
2012 Args:
2013 Side Effects:
2015 =cut
2017 sub maps_single : Chained('brapi') PathPart('maps') CaptureArgs(1) {
2018 my $self = shift;
2019 my $c = shift;
2020 my $map_id = shift;
2022 $c->stash->{map_id} = $map_id;
2026 sub maps_details : Chained('maps_single') PathPart('') Args(0) : ActionClass('REST') { }
2028 sub maps_details_POST {
2029 my $self = shift;
2030 my $c = shift;
2031 #my $auth = _authenticate_user($c);
2034 sub maps_details_GET {
2035 my $self = shift;
2036 my $c = shift;
2037 my $auth = _authenticate_user($c);
2038 my $clean_inputs = $c->stash->{clean_inputs};
2039 my $brapi = $self->brapi_module;
2040 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
2041 my $brapi_package_result = $brapi_module->detail(
2042 $c->stash->{map_id}
2044 _standard_response_construction($c, $brapi_package_result);
2048 =head2 brapi/v1/maps/<map_id>/position?linkageGroupIdList=1,2,3
2050 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.
2051 Desc:
2052 Return JSON example:
2054 "metadata" : {
2055 "pagination" : { "pageSize": 30, "currentPage": 2, "totalCount": 40, "totalPages":2 },
2056 "status: []
2058 "result": {
2059 "data" : [
2061 "markerDbId": 1,
2062 "markerName": "marker1",
2063 "location": "1000",
2064 "linkageGroup": "1A"
2065 }, {
2066 "markerDbId": 2,
2067 "markerName": "marker2",
2068 "location": "1001",
2069 "linkageGroup": "1A"
2074 Args:
2075 Side Effects:
2077 =cut
2079 sub maps_marker_detail : Chained('maps_single') PathPart('positions') Args(0) : ActionClass('REST') { }
2081 sub maps_marker_detail_POST {
2082 my $self = shift;
2083 my $c = shift;
2084 #my $auth = _authenticate_user($c);
2087 sub maps_marker_detail_GET {
2088 my $self = shift;
2089 my $c = shift;
2090 my $auth = _authenticate_user($c);
2091 my $clean_inputs = $c->stash->{clean_inputs};
2092 my $brapi = $self->brapi_module;
2093 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
2094 my $brapi_package_result = $brapi_module->positions({
2095 map_id => $c->stash->{map_id},
2096 linkage_group_ids => $clean_inputs->{linkageGroupId},
2097 min => $clean_inputs->{min}->[0],
2098 max => $clean_inputs->{max}->[0],
2100 _standard_response_construction($c, $brapi_package_result);
2103 sub maps_marker_linkagegroup_detail : Chained('maps_single') PathPart('positions') Args(1) : ActionClass('REST') { }
2105 sub maps_marker_linkagegroup_detail_GET {
2106 my $self = shift;
2107 my $c = shift;
2108 my $linkage_group_id = shift;
2109 my $auth = _authenticate_user($c);
2110 my $clean_inputs = $c->stash->{clean_inputs};
2111 my $brapi = $self->brapi_module;
2112 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
2113 my $brapi_package_result = $brapi_module->positions({
2114 map_id => $c->stash->{map_id},
2115 linkage_group_ids => [$linkage_group_id],
2116 min => $clean_inputs->{min}->[0],
2117 max => $clean_inputs->{max}->[0],
2119 _standard_response_construction($c, $brapi_package_result);
2122 sub locations_list : Chained('brapi') PathPart('locations') Args(0) : ActionClass('REST') { }
2124 sub locations_list_POST {
2125 my $self = shift;
2126 my $c = shift;
2127 #my $auth = _authenticate_user($c);
2130 sub locations_list_GET {
2131 my $self = shift;
2132 my $c = shift;
2133 my $auth = _authenticate_user($c);
2134 my $clean_inputs = $c->stash->{clean_inputs};
2135 my $brapi = $self->brapi_module;
2136 my $brapi_module = $brapi->brapi_wrapper('Locations');
2137 my $brapi_package_result = $brapi_module->locations_list();
2138 _standard_response_construction($c, $brapi_package_result);
2141 sub observationvariable_data_type_list : Chained('brapi') PathPart('variables/datatypes') Args(0) : ActionClass('REST') { }
2143 sub observationvariable_data_type_list_POST {
2144 my $self = shift;
2145 my $c = shift;
2146 #my $auth = _authenticate_user($c);
2149 sub observationvariable_data_type_list_GET {
2150 my $self = shift;
2151 my $c = shift;
2152 my $auth = _authenticate_user($c);
2153 my $clean_inputs = $c->stash->{clean_inputs};
2154 my $brapi = $self->brapi_module;
2155 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
2156 my $brapi_package_result = $brapi_module->observation_variable_data_types();
2157 _standard_response_construction($c, $brapi_package_result);
2160 sub observationvariable_ontologies : Chained('brapi') PathPart('ontologies') Args(0) : ActionClass('REST') { }
2162 sub observationvariable_ontologies_POST {
2163 my $self = shift;
2164 my $c = shift;
2165 #my $auth = _authenticate_user($c);
2168 sub observationvariable_ontologies_GET {
2169 my $self = shift;
2170 my $c = shift;
2171 my $auth = _authenticate_user($c);
2173 #Using code pattern found in SGN::Controller::Ontology->onto_browser
2174 my $onto_root_namespaces = $c->config->{onto_root_namespaces};
2175 my @namespaces = split ", ", $onto_root_namespaces;
2176 foreach my $n (@namespaces) {
2177 $n =~ s/\s*(\w+)\s*\(.*\)/$1/g;
2179 #print STDERR Dumper \@namespaces;
2181 my $clean_inputs = $c->stash->{clean_inputs};
2182 my $brapi = $self->brapi_module;
2183 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
2184 my $brapi_package_result = $brapi_module->observation_variable_ontologies({
2185 name_spaces => \@namespaces
2187 _standard_response_construction($c, $brapi_package_result);
2190 sub observationvariable_search : Chained('brapi') PathPart('variables-search') Args(0) : ActionClass('REST') { }
2192 sub observationvariable_search_POST {
2193 my $self = shift;
2194 my $c = shift;
2195 _observationvariable_search_process($self, $c);
2198 sub observationvariable_search_GET {
2199 my $self = shift;
2200 my $c = shift;
2201 _observationvariable_search_process($self, $c);
2204 sub _observationvariable_search_process {
2205 my $self = shift;
2206 my $c = shift;
2207 my $auth = _authenticate_user($c);
2209 my $clean_inputs = $c->stash->{clean_inputs};
2210 my $brapi = $self->brapi_module;
2211 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
2212 my $brapi_package_result = $brapi_module->observation_variable_search({
2213 observationvariable_db_ids => $clean_inputs->{observationVariableDbId},
2214 ontology_db_names => $clean_inputs->{ontologyXref},
2215 ontology_dbxref_terms => $clean_inputs->{ontologyDbId},
2216 method_db_ids => $clean_inputs->{methodDbId},
2217 scale_db_ids => $clean_inputs->{scaleDbId},
2218 observationvariable_names => $clean_inputs->{name},
2219 observationvariable_datatypes => $clean_inputs->{datatype},
2220 observationvariable_classes => $clean_inputs->{traitClass},
2222 _standard_response_construction($c, $brapi_package_result);
2225 sub observationvariable_list : Chained('brapi') PathPart('variables') Args(0) : ActionClass('REST') { }
2227 sub observationvariable_list_GET {
2228 my $self = shift;
2229 my $c = shift;
2230 my $auth = _authenticate_user($c);
2231 my $clean_inputs = $c->stash->{clean_inputs};
2232 my $brapi = $self->brapi_module;
2233 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
2234 my $brapi_package_result = $brapi_module->observation_variable_search();
2235 _standard_response_construction($c, $brapi_package_result);
2238 sub observationvariable_detail : Chained('brapi') PathPart('variables') Args(1) : ActionClass('REST') { }
2240 sub observationvariable_detail_GET {
2241 my $self = shift;
2242 my $c = shift;
2243 my $trait_id = shift;
2244 my $auth = _authenticate_user($c);
2245 my $clean_inputs = $c->stash->{clean_inputs};
2246 my $brapi = $self->brapi_module;
2247 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
2248 my $brapi_package_result = $brapi_module->observation_variable_detail(
2249 $trait_id
2251 _standard_response_construction($c, $brapi_package_result);
2255 sub samples_list : Chained('brapi') PathPart('samples') Args(0) : ActionClass('REST') { }
2257 sub samples_list_POST {
2258 my $self = shift;
2259 my $c = shift;
2260 $c->forward('samples_search_POST');
2263 sub samples_list_GET {
2264 my $self = shift;
2265 my $c = shift;
2266 $c->forward('samples_search_GET');
2270 =head2 brapi/v1/samples/<sampleDbId>
2272 Usage: To retrieve details for a specific sample
2273 Desc:
2274 Return JSON example:
2276 "metadata": {
2277 "pagination" : {
2278 "pageSize":0,
2279 "currentPage":0,
2280 "totalCount":0,
2281 "totalPages":0
2283 "status" : [],
2284 "datafiles": []
2286 "result": {
2287 "sampleDbId": "Unique-Plant-SampleID",
2288 "observationUnitDbId": "abc123",
2289 "germplasmDbId": "def456",
2290 "studyDbId": "StudyId-123",
2291 "plotDbId": "PlotId-123",
2292 "plantDbId" : "PlantID-123",
2293 "plateDbId": "PlateID-123",
2294 "plateIndex": 0,
2295 "takenBy": "Mr. Technician",
2296 "sampleTimestamp": "2016-07-27T14:43:22+0100",
2297 "sampleType" : "TypeOfSample",
2298 "tissueType" : "TypeOfTissue",
2299 "notes": "Cut from infected leaf",
2302 =cut
2304 sub samples_single : Chained('brapi') PathPart('samples') CaptureArgs(1) {
2305 my $self = shift;
2306 my $c = shift;
2307 my $sample_id = shift;
2309 $c->stash->{sample_id} = $sample_id;
2313 sub sample_details : Chained('samples_single') PathPart('') Args(0) : ActionClass('REST') { }
2315 sub sample_details_POST {
2316 my $self = shift;
2317 my $c = shift;
2318 #my $auth = _authenticate_user($c);
2321 sub sample_details_GET {
2322 my $self = shift;
2323 my $c = shift;
2324 my $auth = _authenticate_user($c);
2325 my $clean_inputs = $c->stash->{clean_inputs};
2326 my $brapi = $self->brapi_module;
2327 my $brapi_module = $brapi->brapi_wrapper('Samples');
2328 my $brapi_package_result = $brapi_module->detail(
2329 $c->stash->{sample_id}
2331 _standard_response_construction($c, $brapi_package_result);
2338 sub authenticate : Chained('brapi') PathPart('authenticate/oauth') Args(0) {
2339 my $self = shift;
2340 my $c = shift;
2342 $c->res->redirect("https://accounts.google.com/o/oauth2/auth?scope=profile&response_type=code&client_id=1068256137120-62dvk8sncnbglglrmiroms0f5d7lg111.apps.googleusercontent.com&redirect_uri=https://cassavabase.org/oauth2callback");
2344 $c->stash->{rest} = { success => 1 };