1 package CXGN
::BrAPI
::v2
::GenomeMaps
;
5 use SGN
::Model
::Cvterm
;
7 use CXGN
::Cview
::MapFactory
;
8 use CXGN
::BrAPI
::Pagination
;
9 use CXGN
::BrAPI
::JSONResponse
;
11 extends
'CXGN::BrAPI::v2::Common';
16 Desc: lists all available maps.
17 Ret: returns a hash with all the map info
18 for each map, the following keys are present:
27 see brapi documentation for more information.
28 Args: usual brapi args (pageSize etc)
37 my $page_size = $self->page_size;
38 my $page = $self->page;
39 my $status = $self->status;
41 my $crop_id = $inputs->{commonCropName
} || ($inputs->{commonCropNames
} || ());
42 my $scientific_id = $inputs->{scientificName
} || ($inputs->{scientificNames
} || ());
43 my $type_id = $inputs->{type
} || ($inputs->{types
} || ());
44 my $map_id = $inputs->{mapDbId
} || ($inputs->{mapDbIds
} || ());
51 my $start = $page_size*$page;
52 my $end = $page_size*($page+1)-1;
54 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->bcs_schema()->storage->dbh(), $inputs->{config
});
57 @maps = $map_factory->create( { map_id
=> $map_id->[0] });
59 @maps = $map_factory->get_all_maps();
65 my $query = "SELECT map_id, date_loaded, count(distinct(location_id)) FROM sgn.map_version JOIN marker_location using (map_version_id) WHERE map_version_id=? GROUP BY 1,2";
66 my $sth = $self->bcs_schema->storage()->dbh()->prepare($query);
68 foreach my $m (@maps) {
69 my $map_version_id = $m->get_id();
70 if ($map_version_id =~ /\D/) { next; } # not a valid id
71 $sth->execute($map_version_id);
72 my ($map_id, $date_loaded, $marker_count) = $sth->fetchrow_array();
74 my $map_type = $m->get_type();
75 my $map_units = $m->get_units();
76 if ($map_type eq 'sequence'){
77 $map_type = 'Physical';
80 $map_type = 'Genetic';
83 my $scientific_name = $m->get_organism();
84 my $common_name = $m->get_common_name();
87 if ( $crop_id && ! grep { $_ eq $common_name } @
{$crop_id} ) { $passes_search = 0;};
88 if ( $scientific_id && ! grep { $_ eq $scientific_name } @
{$scientific_id} ) { $passes_search = 0;};
89 if ( $type_id && ! grep { $_ eq $map_type } @
{$type_id} ) { $passes_search = 0;};
91 if ( $passes_search ){
93 additionalInfo
=> {name
=> $m->get_long_name()},
94 comments
=> $m->get_abstract(),
95 commonCropName
=> $common_name,
96 documentationURL
=> "https://brapi.org",
97 linkageGroupCount
=> $m->get_chromosome_count(),
98 mapDbId
=> qq|$map_id|,
99 mapName
=> $m->get_short_name(),
101 markerCount
=> $marker_count,
102 publishedDate
=> $date_loaded,
103 scientificName
=> $scientific_name,
107 push @data, \
%map_info;
111 my $total_count = scalar(@maps);
112 my %result = (data
=> \
@data);
114 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($total_count,$page_size,$page);
116 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination,
117 \
@data_files, $status, 'Maps list result constructed');
123 Usage: $brapi->detail()
124 Desc: returns the detail information of a map in brapi format
136 my $page_size = $self->page_size;
137 my $page = $self->page;
138 my $status = $self->status;
141 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->bcs_schema->storage()->dbh());
142 my $map = $map_factory->create( { map_id
=> $map_id });
145 my $map_type = $map->get_type();
146 my $map_units = $map->get_units();
147 if ($map_type eq 'sequence'){
148 $map_type = 'Physical';
151 $map_type = 'Genetic';
155 my $scientific_name = $map->get_organism();
157 my $query = "SELECT map_id, date_loaded, count(distinct(location_id)) FROM sgn.map_version JOIN marker_location using (map_version_id) WHERE map_version_id=? GROUP BY 1,2";
158 my $sth = $self->bcs_schema->storage()->dbh()->prepare($query);
159 my $map_version_id = $map->get_id();
160 if ($map_version_id =~ /\D/) { next; }
161 $sth->execute($map_version_id);
162 my ($map_id1, $date_loaded, $marker_count) = $sth->fetchrow_array();
165 additionalInfo
=> { name
=> $map->get_long_name() },
166 comments
=> $map->get_abstract(),
167 commonCropName
=> $map->get_common_name(),
168 documentationURL
=> "https://brapi.org",
169 linkageGroupCount
=> $map->get_chromosome_count(),
170 mapDbId
=> qq|$map_id|,
171 mapName
=> $map->get_short_name(),
173 markerCount
=> $marker_count,
174 publishedDate
=> $date_loaded,
175 scientificName
=> $scientific_name,
182 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response(1,$page_size,$page);
184 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Maps detail result constructed');
191 my $map_id = $inputs->{map_id
};
192 my $page_size = $self->page_size;
193 my $page = $self->page;
194 my $status = $self->status;
198 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->bcs_schema->storage()->dbh());
199 my $map = $map_factory->create( { map_id
=> $map_id });
202 foreach my $chr ($map->get_chromosomes()) {
204 additionalInfo
=> {},
205 linkageGroupName
=> $chr->get_name(),
206 markerCount
=> scalar($chr->get_markers()),
207 maxPosition
=> $chr->get_length()
214 my %result = (data
=> \
@data);
215 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($total_count,$page_size,$page);
217 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Maps detail result constructed');
222 # Usage: genosort($a_chr, $a_pos, $b_chr, $b_pos)
223 # Desc: sorts marker coordinates according to position for marker names
224 # of the format S(\d+)_(.*)
233 # my ($a_chr, $a_pos, $b_chr, $b_pos);
234 # if ($a =~ m/S(\d+)\_(.*)/) {
238 # if ($b =~ m/S(\d+)\_(.*)/) {
243 # if ($a_chr && $b_chr) {
244 # if ($a_chr == $b_chr) {
245 # return $a_pos <=> $b_pos;
247 # return $a_chr <=> $b_chr;
253 # sub get_protocolprop_hash {
255 # my $nd_protocol_id = shift;
256 # my $prop_rs = $self->bcs_schema->resultset('NaturalDiversity::NdProtocolprop')->search({'me.nd_protocol_id' => $nd_protocol_id}, {join=>['type'], +select=>['type.name', 'me.value'], +as=>['name', 'value']});
258 # while (my $r = $prop_rs->next()){
259 # push @{ $prop_hash->{$r->get_column('name')} }, $r->get_column('value');