1 package CXGN
::BrAPI
::v1
::Phenotypes
;
5 use SGN
::Model
::Cvterm
;
8 use CXGN
::Phenotypes
::SearchFactory
;
9 use CXGN
::BrAPI
::Pagination
;
10 use CXGN
::BrAPI
::JSONResponse
;
13 isa
=> 'Bio::Chado::Schema',
18 has
'metadata_schema' => (
19 isa
=> 'CXGN::Metadata::Schema',
24 has
'phenome_schema' => (
25 isa
=> 'CXGN::Phenome::Schema',
43 isa
=> 'ArrayRef[Maybe[HashRef]]',
52 my $data_level = $inputs->{data_level
} || 'plot';
53 my $search_type = $inputs->{search_type
} || 'complete';
54 my @trait_ids_array = $inputs->{trait_ids
} ? @
{$inputs->{trait_ids
}} : ();
55 my @accession_ids_array = $inputs->{accession_ids
} ? @
{$inputs->{accession_ids
}} : ();
56 my @study_ids_array = $inputs->{study_ids
} ? @
{$inputs->{study_ids
}} : ();
57 my @location_ids_array = $inputs->{location_ids
} ? @
{$inputs->{location_ids
}} : ();
58 my @years_array = $inputs->{years
} ? @
{$inputs->{years
}} : ();
59 my $page_size = $self->page_size;
60 my $page = $self->page;
61 my $status = $self->status;
64 if ($search_type eq 'complete'){
65 $factory_type = 'Native';
67 if ($search_type eq 'fast'){
68 $factory_type = 'MaterializedView';
70 my $phenotypes_search = CXGN
::Phenotypes
::SearchFactory
->instantiate(
71 $factory_type, #can be either 'MaterializedView', or 'Native'
73 bcs_schema
=>$self->bcs_schema,
74 data_level
=>$data_level,
75 trial_list
=>\
@study_ids_array,
76 trait_list
=>\
@trait_ids_array,
78 year_list
=>\
@years_array,
79 location_list
=>\
@location_ids_array,
80 accession_list
=>\
@accession_ids_array,
83 my $data = $phenotypes_search->search();
84 #print STDERR Dumper $data;
88 if (exists($obs_units{$_->[14]})){
89 my $observations = $obs_units{$_->[14]}->{observations
};
90 push @
$observations, {
91 observationDbId
=> $_->[19],
92 observationVariableDbId
=> $_->[10],
93 observationVariableName
=> $_->[4],
94 observationTimestamp
=> $_->[15],
99 $obs_units{$_->[14]}->{observations
} = $observations;
101 $obs_units{$_->[14]} = {
102 observationUnitDbId
=> $_->[14],
103 observationLevel
=> $_->[18],
104 observationLevels
=> $_->[18],
105 plotNumber
=> $_->[9],
107 blockNumber
=> $_->[8],
108 replicate
=> $_->[7],
109 observationUnitName
=> $_->[6],
110 germplasmDbId
=> $_->[13],
111 germplasmName
=> $_->[2],
112 studyDbId
=> $_->[11],
113 studyName
=> $_->[1],
114 studyLocationDbId
=> $_->[12],
115 studyLocation
=> $_->[3],
123 observationDbId
=> $_->[19],
124 observationVariableDbId
=> $_->[10],
125 observationVariableName
=> $_->[4],
126 observationTimestamp
=> $_->[15],
134 my $total_count = scalar(keys %obs_units);
136 my $offset = $page*$page_size;
137 my $limit = $page_size*($page+1)-1;
138 foreach my $obs_unit_id (sort keys %obs_units) {
139 if ($count >= $offset && $count <= ($offset+$limit)){
140 push @data_window, $obs_units{$obs_unit_id};
144 my %result = (data
=>\
@data_window);
146 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($total_count,$page_size,$page);
147 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Studies observations result constructed');