1 package CXGN
::BrAPI
::v1
::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::v1::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 $start = $page_size*$page;
42 my $end = $page_size*($page+1)-1;
44 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->bcs_schema()->storage->dbh(), $inputs->{config
});
46 my @maps = $map_factory->get_all_maps();
49 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";
50 my $sth = $self->bcs_schema->storage()->dbh()->prepare($query);
52 foreach my $m (@maps) {
53 my $map_version_id = $m->get_id();
54 if ($map_version_id =~ /\D/) { next; } # not a valid id
55 $sth->execute($map_version_id);
56 my ($map_id, $date_loaded, $marker_count) = $sth->fetchrow_array();
57 my $map_type = $m->get_type();
58 my $map_units = $m->get_units();
59 if ($map_type eq 'sequence'){
60 $map_type = 'Physical';
63 $map_type = 'Genetic';
66 my $scientific_name = $m->get_organism();
67 my ($genus,$species) = undef;
68 if ($scientific_name) { ($genus,$species) = split(" ", $scientific_name) };
70 mapDbId
=> qq|$map_id|,
71 name
=> $m->get_long_name(),
75 markerCount
=> $marker_count,
76 comments
=> $m->get_abstract(),
77 linkageGroupCount
=> $m->get_chromosome_count(),
78 commonCropName
=> $m->get_common_name(),
79 documentationURL
=> "https://brapi.org",
80 mapName
=> $m->get_short_name(),
81 publishedDate
=> $date_loaded,
82 scientificName
=> $scientific_name,
85 push @data, \
%map_info;
88 my $total_count = scalar(@maps);
89 my %result = (data
=> \
@data);
91 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($total_count,$page_size,$page);
93 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination,
94 \
@data_files, $status, 'Maps list result constructed');
100 Usage: $brapi->detail()
101 Desc: returns the detail information of a map in brapi format
112 my $page_size = $self->page_size;
113 my $page = $self->page;
114 my $status = $self->status;
116 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->bcs_schema->storage()->dbh());
118 my $map = $map_factory->create( { map_id
=> $map_id });
119 my $map_type = $map->get_type();
120 my $map_units = $map->get_units();
121 if ($map_type eq 'sequence'){
122 $map_type = 'Physical';
125 $map_type = 'Genetic';
131 foreach my $chr ($map->get_chromosomes()) {
133 linkageGroupName
=> $chr->get_name(),
134 markerCount
=> scalar($chr->get_markers()),
135 maxPosition
=> $chr->get_length()
138 my ($data_window, $pagination) = CXGN
::BrAPI
::Pagination
->paginate_array(\
@data,$page_size,$page);
141 mapDbId
=> qq|$map_id|,
142 mapName
=> $map->get_short_name(),
145 comments
=> $map->get_abstract(),
146 documentationURL
=> "https://brapi.org",
147 data
=> $data_window,
151 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Maps detail result constructed');
156 Usage: $brapi->positions()
157 Desc: returns all the positions and marker scores for a given
169 my $map_id = $inputs->{map_id
};
170 my $min = $inputs->{min
};
171 my $max = $inputs->{max
};
172 my @linkage_group_ids = $inputs->{linkage_group_ids
} ? @
{$inputs->{linkage_group_ids
}} : ();
173 my $page_size = $self->page_size;
174 my $page = $self->page;
175 my $status = $self->status;
177 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->bcs_schema->storage()->dbh());
179 my $map = $map_factory->create( { map_id
=> $map_id });
183 foreach my $chr ($map->get_chromosomes()) {
184 foreach my $m ($chr->get_markers()) {
185 if (@linkage_group_ids) {
186 if (grep $_ eq $chr->get_name(), @linkage_group_ids) {
188 markerDbId
=> $m->get_id(),
189 markerName
=> $m->get_name(),
190 location
=> $m->get_offset(),
191 linkageGroupName
=> $chr->get_name(),
197 markerDbId
=> $m->get_id(),
198 markerName
=> $m->get_name(),
199 location
=> $m->get_offset(),
200 linkageGroupName
=> $chr->get_name()
205 my $marker_count = scalar(@data);
206 my ($data_window, $pagination) = CXGN
::BrAPI
::Pagination
->paginate_array(\
@data,$marker_count,$page); #set page size to total number of markers
208 my %result = ( data
=> $data_window );
210 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Maps detail result constructed');
215 Usage: genosort($a_chr, $a_pos, $b_chr, $b_pos)
216 Desc: sorts marker coordinates according to position for marker names
217 of the format S(\d+)_(.*)
226 my ($a_chr, $a_pos, $b_chr, $b_pos);
227 if ($a =~ m/S(\d+)\_(.*)/) {
231 if ($b =~ m/S(\d+)\_(.*)/) {
236 if ($a_chr && $b_chr) {
237 if ($a_chr == $b_chr) {
238 return $a_pos <=> $b_pos;
240 return $a_chr <=> $b_chr;
246 sub get_protocolprop_hash
{
248 my $nd_protocol_id = shift;
249 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']});
251 while (my $r = $prop_rs->next()){
252 push @
{ $prop_hash->{$r->get_column('name')} }, $r->get_column('value');