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
;
17 use JSON
qw( decode_json );
20 use File
::Slurp qw
| read_file
|;
21 use Spreadsheet
::WriteExcel
;
26 BEGIN { extends
'Catalyst::Controller::REST' };
29 default => 'application/json',
31 map => { 'application/json' => 'JSON' },
34 has
'brapi_module' => (
40 isa
=> 'Bio::Chado::Schema',
44 my $DEFAULT_PAGE_SIZE=10;
46 sub brapi
: Chained
('/') PathPart
('brapi') CaptureArgs
(1) {
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({
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,
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);
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
97 no warnings
'uninitialized';
99 foreach (keys %$params){
100 my $values = $params->{$_};
102 if (ref \
$values eq 'SCALAR'){
103 push @
$ret_val, $values;
104 } elsif (ref $values eq 'ARRAY'){
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;
117 sub _authenticate_user
{
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);
134 sub _standard_response_construction
{
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;
148 =head2 /brapi/v1/token
150 Usage: For logging a user in and loggin a user out through the API
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.
169 "userDisplayName": "John Smith",
170 "access_token": "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4",
171 "expires_in": "The lifetime in seconds of the access token"
178 "access_token" : "R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4" // (optional, text, `R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4`) ... The user access token. Default: current user token.
185 "status" : { "message" : "User has been logged out successfully."},
193 sub authenticate_token
: Chained
('brapi') PathPart
('token') Args
(0) : ActionClass
('REST') { }
195 sub authenticate_token_DELETE
{
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
{
207 process_authenticate_token
($self,$c);
210 sub authenticate_token_POST
{
213 process_authenticate_token
($self,$c);
216 sub process_authenticate_token
{
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;
239 =head2 /brapi/v1/calls
241 Usage: For determining which calls have been implemented and with which datafile types and methods
261 "call": "allelematrix",
272 "call": "germplasm/id/mcpd",
281 "call": "doesntexistyet",
296 sub calls
: Chained
('brapi') PathPart
('calls') Args
(0) : ActionClass
('REST') { }
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') { }
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
{
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') { }
338 seasons_process
($self, $c);
344 seasons_process
($self, $c);
347 sub seasons_process
{
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
377 "description": "Description for Nursery study type"
381 "description": "Description for Nursery study type"
391 sub study_types
: Chained
('brapi') PathPart
('studyTypes') Args
(0) : ActionClass
('REST') { }
393 sub study_types_POST
{
396 study_types_process
($self, $c);
399 sub study_types_GET
{
402 study_types_process
($self, $c);
405 sub study_types_process
{
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
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
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",
460 "commonCropName": "banana",
461 "instituteCode": "01BEL084",
462 "instituteName": "ITC",
463 "biologicalStatusOfAccessionCode": 412,
464 "countryOfOriginCode": "UNK",
465 "typeOfGermplasmStorageCode": 10,
467 "species": "acuminata",
468 "speciesAuthority": "",
469 "subtaxa": "sp malaccensis var pahang",
470 "subtaxaAuthority": "",
474 "donorAccessionNumber": "",
475 "donorInstituteCode": "",
479 "acquisitionDate": "19470131"
487 sub germplasm_list
: Chained
('brapi') PathPart
('germplasm-search') Args
(0) : ActionClass
('REST') { }
489 sub germplasm_list_GET
{
492 germplasm_search_process
($self, $c);
495 sub germplasm_list_POST
{
498 germplasm_search_process
($self, $c);
501 sub germplasm_search_process
{
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
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"],
548 sub germplasm_single
: Chained
('brapi') PathPart
('germplasm') CaptureArgs
(1) {
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
{
562 #my $auth = _authenticate_user($c);
565 sub germplasm_detail_GET
{
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
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",
599 "commonCropName": "banana",
600 "instituteCode": "01BEL084",
601 "instituteName": "ITC",
602 "biologicalStatusOfAccessionCode": 412,
603 "countryOfOriginCode": "UNK",
604 "typeOfGermplasmStorageCode": 10,
606 "species": "acuminata",
607 "speciesAuthority": "",
608 "subtaxa": "sp malaccensis var pahang",
609 "subtaxaAuthority": "",
613 "donorAccessionNumber": "",
614 "donorInstituteCode": "",
618 "acquisitionDate": "19470131"
625 #sub germplasm_mcpd : Chained('germplasm_single') PathPart('MCPD') Args(0) : ActionClass('REST') { }
627 #sub germplasm_mcpd_POST {
630 # my $auth = _authenticate_user($c);
631 # my $status = $c->stash->{status};
633 # $c->stash->{rest} = {status=>$status};
636 #sub germplasm_mcpd_GET {
639 # #my $auth = _authenticate_user($c);
640 # my $schema = $self->bcs_schema();
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=>'');
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
675 "name": "Earlygenerationtesting",
676 "studyType": "Trial",
677 "years": ["2005", "2008"],
681 "studyPUI" : "PUI string",
682 "studyType": "Trial",
683 "startDate": "2015-06-01",
684 "endDate" : "2015-12-31",
690 "name": "Earlygenerationtesting",
691 "seasons": ["2005", "2008"],
695 "studyPUI" : "PUI string",
696 "studyType": "Trial",
697 "startDate": "2015-06-01",
698 "endDate" : "2015-12-31",
709 sub studies_search
: Chained
('brapi') PathPart
('studies-search') Args
(0) : ActionClass
('REST') { }
711 #sub studies_list_POST {
714 # my $auth = _authenticate_user($c);
715 # my $status = $c->stash->{status};
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');
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();
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 };
749 # my $locations = $program_obj->get_all_locations();
750 # my $location_check;
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 };
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,
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 };
789 # $trial_create->save_trial();
791 # $message .= "Error saving trial in the database $_";
792 # $status->{'message'} = $message;
793 # $c->stash->{rest} = {status => $status };
797 # $message .= "Study saved successfully.";
798 # $status->{'message'} = $message;
799 # $c->stash->{rest} = {status => $status };
802 sub studies_search_POST
{
805 studies_search_process
($self, $c);
808 sub studies_search_GET
{
811 studies_search_process
($self, $c);
814 sub studies_search_process
{
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
{
843 trials_search_process
($self, $c);
846 sub trials_list_POST
{
849 trials_search_process
($self, $c);
852 sub trials_search_process
{
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) {
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
{
881 #my $auth = _authenticate_user($c);
884 sub trials_detail_GET
{
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
914 "studyName": "myBestTrial",
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",
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",
936 "synonyms": [ "01BEL084727"],
946 sub studies_single
: Chained
('brapi') PathPart
('studies') CaptureArgs
(1) {
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
{
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
{
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
997 "germplasmDbId": "382",
998 "pedigree": "TOBA97/SW90.1057",
1008 sub germplasm_pedigree
: Chained
('germplasm_single') PathPart
('pedigree') Args
(0) : ActionClass
('REST') { }
1010 sub germplasm_pedigree_POST
{
1013 #my $auth = _authenticate_user($c);
1016 sub germplasm_pedigree_GET
{
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
1035 Return JSON example:
1043 "germplasmDbId": "382",
1044 "defaultDisplayName": "Pahang",
1046 "progenyGermplasmDbId": "403",
1047 "parentType": "FEMALE"
1049 "progenyGermplasmDbId": "402",
1050 "parentType": "MALE"
1052 "progenyGermplasmDbId": "405",
1053 "parentType": "SELF"
1062 sub germplasm_progeny
: Chained
('germplasm_single') PathPart
('progeny') Args
(0) : ActionClass
('REST') { }
1064 sub germplasm_progeny_POST
{
1069 sub germplasm_progeny_GET
{
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
{
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
1105 Return JSON example:
1112 "germplasmDbId": "382",
1124 sub germplasm_markerprofile
: Chained
('germplasm_single') PathPart
('markerprofiles') Args
(0) : ActionClass
('REST') { }
1126 sub germplasm_markerprofile_POST
{
1129 #my $auth = _authenticate_user($c);
1132 sub germplasm_markerprofile_GET
{
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
{
1155 germplasm_attributes_process
($self, $c);
1158 sub germplasm_attributes_process
{
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
{
1177 germplasm_attributes_categories_process
($self, $c);
1180 sub germplasm_attributes_categories_process
{
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
1196 Return JSON example:
1210 "markerProfileDbId": "993",
1211 "germplasmDbId" : 2374,
1212 "extractDbId" : 3939,
1213 "analysisMethod": "GoldenGate",
1217 "markerProfileDbId": "994",
1218 "germplasmDbId" : 2374,
1219 "extractDbId" : 3939,
1220 "analysisMethod": "GBS",
1231 sub markerprofile_search_process
{
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
{
1255 markerprofile_search_process
($self, $c);
1258 sub markerprofiles_list_GET
{
1261 markerprofile_search_process
($self, $c);
1265 =head2 brapi/v1/markerprofiles/markerprofilesDbId
1267 Usage: To retrieve data for a single markerprofile
1269 Return JSON example:
1282 "germplasmDbId": 993,
1283 "extractDbId" : 38383,
1284 "markerprofileDbId": 37484,
1285 "analysisMethod": "GBS-Pst1",
1286 "encoding": "AA,BB,AB",
1287 "data" : [ { "marker1": "AA" }, { "marker2":"AB" }, ... ]
1295 sub markerprofiles_single
: Chained
('brapi') PathPart
('markerprofiles') CaptureArgs
(1) {
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
{
1307 #my $auth = _authenticate_user($c);
1310 sub genotype_fetch_GET
{
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) {
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
1344 Return JSON example:
1356 "makerprofileDbIds": ["markerprofileId1","markerprofileId2","markerprofileId3"],
1358 { "markerDbId1":["AB","AA","AA"] },
1359 { "markerDbId2":["AA","AB","AA"] },
1360 { "markerDbId3":["AB","AB","BB"] }
1369 sub allelematrix
: Chained
('brapi') PathPart
('allelematrix-search') Args
(0) : ActionClass
('REST') { }
1371 sub allelematrix_POST
{
1374 allelematrix_search_process
($self, $c);
1377 sub allelematrix_GET
{
1380 allelematrix_search_process
($self, $c);
1383 sub allelematrix_search_process
{
1386 my $auth = _authenticate_user
($c);
1388 my $clean_inputs = $c->stash->{clean_inputs
};
1389 my $format = $clean_inputs->{format
}->[0];
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],
1406 main_production_site_url
=> $c->config->{main_production_site_url
},
1407 file_path
=> $file_path,
1410 _standard_response_construction
($c, $brapi_package_result);
1414 =head2 brapi/v1/programs
1416 Usage: To retrieve a list of programs being worked on
1418 Return JSON example:
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"
1451 sub programs_list
: Chained
('brapi') PathPart
('programs') Args
(0) : ActionClass
('REST') { }
1453 sub programs_list_POST
{
1456 #my $auth = _authenticate_user($c);
1459 sub programs_list_GET
{
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
{
1481 #my $auth = _authenticate_user($c);
1484 sub studies_info_GET
{
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
{
1503 #my $auth = _authenticate_user($c);
1506 sub studies_observation_variables_GET
{
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
{
1525 #my $auth = _authenticate_user($c);
1528 sub studies_layout_GET
{
1531 my $clean_inputs = $c->stash->{clean_inputs
};
1532 my $auth = _authenticate_user
($c);
1533 my $format = $clean_inputs->{format
}->[0] || 'json';
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
},
1548 main_production_site_url
=> $c->config->{main_production_site_url
},
1549 file_path
=> $file_path,
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
1560 Return JSON example:
1562 "metadata" : "status": [],
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,
1591 sub studies_observations
: Chained
('studies_single') PathPart
('observationunits') Args
(0) : ActionClass
('REST') { }
1593 sub studies_observations_POST
{
1596 #my $auth = _authenticate_user($c);
1599 sub studies_observations_GET
{
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
1619 Return JSON example:
1632 "observationVariableDbId": [ '', '', '', '', '', '', '', '', 44444, 55555, 66666...],
1633 "observationVariableName": [ "plotDbId", "plotName", "block", "rep", "germplasmID", "germplasmName", "operator", "timestamp", "Yield", "Color", "Dry Matter"...],
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, ...]
1647 sub studies_table
: Chained
('studies_single') PathPart
('table') Args
(0) : ActionClass
('REST') { }
1649 sub studies_table_POST
{
1652 my $trait_id = shift;
1653 #my $auth = _authenticate_user($c);
1656 sub studies_table_GET
{
1659 my $auth = _authenticate_user
($c);
1661 my $clean_inputs = $c->stash->{clean_inputs
};
1662 my $format = $clean_inputs->{format
}->[0];
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
},
1681 main_production_site_url
=> $c->config->{main_production_site_url
},
1682 file_path
=> $file_path,
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
1693 Return JSON example:
1695 "metadata" : "status": [],
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,
1724 sub studies_observations_granular
: Chained
('studies_single') PathPart
('observations') Args
(0) : ActionClass
('REST') { }
1726 sub studies_observations_granular_POST
{
1729 #my $auth = _authenticate_user($c);
1732 sub studies_observations_granular_GET
{
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
1753 Return JSON example:
1766 "observationUnitDbId": 20,
1767 "observationUnitPUI": "http://phenome-fppn.fr/maugio/bloc/12/2345",
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",
1783 "factor" : "water regimen" ,
1784 "modality":"water deficit"
1798 "instanceNumber" : 1,
1799 "observationVariableId": "CO_321:0000045",
1800 //"observationVariableDbId": 35,
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,
1813 "observationValue" : 32,
1814 "observationTimeStamp": "2006-07-03::10:00",
1816 "collectionFacilityLabel": null,
1817 "collector" : "userURIOrName"
1828 sub phenotypes_search
: Chained
('brapi') PathPart
('phenotypes-search') Args
(0) : ActionClass
('REST') { }
1830 sub phenotypes_search_POST
{
1833 process_phenotypes_search
($self, $c);
1836 sub phenotypes_search_GET
{
1839 process_phenotypes_search
($self, $c);
1842 sub process_phenotypes_search
{
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
{
1867 #my $auth = _authenticate_user($c);
1870 sub traits_list_GET
{
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) {
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
{
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.
1914 Return JSON example:
1930 "species": "Some species",
1933 "publishedDate": "2008-04-16",
1934 "markerCount": 1000,
1935 "linkageGroupCount": 7,
1936 "comments": "This map contains ..."
1940 "name": "Some Other map",
1941 "species": "Some Species",
1944 "publishedDate": "2009-01-12",
1945 "markerCount": 1501,
1946 "linkageGroupCount": 7,
1947 "comments": "this is blah blah"
1957 sub maps_list
: Chained
('brapi') PathPart
('maps') Args
(0) : ActionClass
('REST') { }
1959 sub maps_list_POST
{
1962 #my $auth = _authenticate_user($c);
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
1982 Return JSON example:
2000 "linkageGroupId": 1,
2001 "numberMarkers": 100000,
2002 "maxPosition": 10000000
2005 "linkageGroupId": 2,
2006 "numberMarkers": 1247,
2007 "maxPostion": 12347889
2017 sub maps_single
: Chained
('brapi') PathPart
('maps') CaptureArgs
(1) {
2022 $c->stash->{map_id
} = $map_id;
2026 sub maps_details
: Chained
('maps_single') PathPart
('') Args
(0) : ActionClass
('REST') { }
2028 sub maps_details_POST
{
2031 #my $auth = _authenticate_user($c);
2034 sub maps_details_GET
{
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(
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.
2052 Return JSON example:
2055 "pagination" : { "pageSize": 30, "currentPage": 2, "totalCount": 40, "totalPages":2 },
2062 "markerName": "marker1",
2064 "linkageGroup": "1A"
2067 "markerName": "marker2",
2069 "linkageGroup": "1A"
2079 sub maps_marker_detail
: Chained
('maps_single') PathPart
('positions') Args
(0) : ActionClass
('REST') { }
2081 sub maps_marker_detail_POST
{
2084 #my $auth = _authenticate_user($c);
2087 sub maps_marker_detail_GET
{
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
{
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
{
2127 #my $auth = _authenticate_user($c);
2130 sub locations_list_GET
{
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
{
2146 #my $auth = _authenticate_user($c);
2149 sub observationvariable_data_type_list_GET
{
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
{
2165 #my $auth = _authenticate_user($c);
2168 sub observationvariable_ontologies_GET
{
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
{
2195 _observationvariable_search_process
($self, $c);
2198 sub observationvariable_search_GET
{
2201 _observationvariable_search_process
($self, $c);
2204 sub _observationvariable_search_process
{
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
{
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
{
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(
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
{
2260 $c->forward('samples_search_POST');
2263 sub samples_list_GET
{
2266 $c->forward('samples_search_GET');
2270 =head2 brapi/v1/samples/<sampleDbId>
2272 Usage: To retrieve details for a specific sample
2274 Return JSON example:
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",
2295 "takenBy": "Mr. Technician",
2296 "sampleTimestamp": "2016-07-27T14:43:22+0100",
2297 "sampleType" : "TypeOfSample",
2298 "tissueType" : "TypeOfTissue",
2299 "notes": "Cut from infected leaf",
2304 sub samples_single
: Chained
('brapi') PathPart
('samples') CaptureArgs
(1) {
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
{
2318 #my $auth = _authenticate_user($c);
2321 sub sample_details_GET
{
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) {
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 };