1 package CXGN
::Marker
::SearchBrAPI
;
5 CXGN::Marker::SearchBrAPI - an object to handle searching for markers given criteria
9 my $marker_search = CXGN::Marker::SearchBrAPI->new({
11 marker_ids=>\@marker_ids,
12 marker_names=>\@marker_names,
13 get_synonyms=>$synonyms,
14 match_method=>$method,
16 offset=>$page_size*$page,
19 my ($result, $total_count) = $marker_search->search();
36 use CXGN
::Marker
::LocMarker
;
37 use CXGN
::Marker
::Tools
qw(clean_marker_name);
38 use SGN
::Model
::Cvterm
;
43 isa
=> 'Bio::Chado::Schema',
48 has
'nd_protocol_id' => (
54 isa
=> 'ArrayRef[Int]|Undef',
58 has
'marker_names' => (
59 isa
=> 'ArrayRef[Int]|Undef',
63 has
'get_synonyms' => (
69 has
'match_method' => (
75 isa
=> 'ArrayRef[Int]|Undef',
92 my $schema = $self->bcs_schema();
93 my $marker_ids = $self->marker_ids;
94 my $marker_names = $self->marker_names;
95 my $get_synonyms = $self->get_synonyms;
96 my $match_method = $self->match_method;
97 my $types = $self->types;
98 my $limit = $self->limit;
99 my $offset = $self->offset;
103 if ($match_method eq 'exact'){ $comparison = 'in';}
104 elsif ($match_method eq 'case_insensitive'){ $comparison = 'ilike'; }
105 else { $comparison = 'like'; }
107 if ($marker_ids && scalar(@
$marker_ids)>0) {
108 my $sql = join ("," , @
$marker_ids);
109 push @where_clause, "marker.marker_id in ($sql)";
112 if ($marker_names && scalar(@
$marker_names)>0) {
113 my $sql = join ("," , @
$marker_names);
114 push @where_clause, "marker_names.name in ($sql)";
117 if ($types && scalar(@
$types)>0) {
118 my $sql = join ("," , @
$types);
119 push @where_clause, "protocol in ($sql)";
122 my $where_clause = scalar(@where_clause)>0 ?
" WHERE " . (join (" AND " , @where_clause)) : '';
125 my $subquery = "SELECT distinct m2m.marker_id,name,alias,protocol,organism_name,common_name.common_name FROM sgn.marker
126 LEFT JOIN sgn.marker_to_map as m2m using(marker_id)
127 INNER JOIN sgn.accession ON(parent_1 = accession.accession_id OR parent_2 = accession.accession_id)
128 INNER JOIN sgn.organism using(organism_id)
129 INNER JOIN sgn.common_name USING(common_name_id)
130 INNER JOIN marker_names ON(m2m.marker_id=marker_names.marker_id)
131 INNER JOIN marker_alias ON(m2m.marker_id=marker_alias.marker_id) $where_clause";
133 my $h = $schema->storage->dbh()->prepare($subquery);
138 my $subtract_count = 0;
140 while (my ($marker_id, $marker_name, $reference, $alias, $protocol, $full_count) = $h->fetchrow_array()) {
142 marker_id
=> $marker_id,
143 marker_name
=> $marker_name,
145 references
=> $reference,
149 $total_count = $full_count;
153 if (($limit && defined($limit) || ($offset && defined($offset)))){
155 my $end = $offset + $limit - 1;
156 for( my $i = $start; $i <= $end; $i++ ) {
158 push @data_window, $result[$i];
162 @data_window = @result;
165 $total_count = $total_count-$subtract_count;
166 return (\
@data_window, $total_count);