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