1 package CXGN
::BrAPI
::v2
::References
;
5 use CXGN
::BrAPI
::Pagination
;
6 use CXGN
::BrAPI
::JSONResponse
;
9 extends
'CXGN::BrAPI::v2::Common';
14 my $schema = $self->bcs_schema();
15 my $status = $self->status;
16 my $page_size = $self->page_size;
17 my $page = $self->page;
19 my $referenceset_ids = $inputs->{referenceSetDbId
} || ($inputs->{referenceSetDbIds
} || ());
20 my $reference_ids = $inputs->{referenceDbId
} || ($inputs->{referenceDbIds
} || ());
21 my $accession = $inputs->{accession
} || ($inputs->{accessions
} || ());
22 my $is_derived = $inputs->{isDerived
} || ($inputs->{isDerived
} || ());
23 my $md5checksum = $inputs->{md5checksum
} || ($inputs->{md5checksums
} || ());
24 my $max_length = $inputs->{maxLength
} || ($inputs->{maxLength
} || ());
25 my $min_length = $inputs->{minLength
} || ($inputs->{minLength
} || ());
27 if ($md5checksum || $accession || $is_derived ){
28 push @
$status, { 'error' => 'The following parameters search are not implemented: md5checksum, accession, isDerived' };
33 my $where_clause = "";
36 my $vcf_map_details_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($self->bcs_schema, 'vcf_map_details', 'protocol_property')->cvterm_id();
38 if ($referenceset_ids && scalar(@
$referenceset_ids)>0) {
39 my $protocol_sql = join ("," , @
$referenceset_ids);
40 $where_clause = "AND nd_protocolprop.nd_protocol_id in ($protocol_sql)";
43 my $subquery = "SELECT distinct value->'reference_genome_name', value->'species_name', nd_protocol_id, value->'header_information_lines' from nd_protocolprop where type_id = $vcf_map_details_cvterm_id $where_clause";
45 my $h = $schema->storage->dbh()->prepare($subquery);
48 my $start_index = $page*$page_size;
49 my $end_index = $page*$page_size + $page_size - 1;
51 while (my ($referenceset, $species, $protocol, $header ) = $h->fetchrow_array()) {
52 $referenceset =~ s/"//g;
57 my $head = decode_json
$header;
60 $source = $1 if ($_ =~ /##source=(\w+)/);
64 my $referenceName = $1 if ($_ =~ /##contig=<ID=(\w+)/) ;
65 my $length = $1 if ($_ =~ /,length=(\d+)/) ;
66 my $md5 = $1 if ($_ =~ /,md5=(\w+)/) ;
67 if ( $md5checksum && $md5 && ! grep { $_ eq $md5 } @
{$md5checksum} ) { next; }
68 if ( $referenceName && $reference_ids && ! grep { $_ eq $referenceName } @
{$reference_ids} ) { next; }
69 if ( $max_length && $length && $max_length->[0] < $length + 0 ) { next; }
70 if ( $min_length && $length && $min_length->[0] > $length + 0 ) { next; }
73 if ($counter >= $start_index && $counter <= $end_index) {
76 isDerived
=> JSON
::false
,
77 length => $length + 0,
79 referenceSetDbId
=> qq|$protocol|,
80 referenceSetName
=> $referenceset,
81 referenceDbId
=> qq|$referenceName|,
82 referenceName
=> qq|$referenceName|,
83 sourceAccessions
=> undef,
84 sourceDivergence
=> undef,
97 my %result = (data
=>\
@data);
99 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($counter,$page_size,$page);
100 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'References result constructed');
105 my $reference_ids = shift;
106 my $schema = $self->bcs_schema();
107 my $page_size = $self->page_size;
108 my $page = $self->page;
115 my $vcf_map_details_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($self->bcs_schema, 'vcf_map_details', 'protocol_property')->cvterm_id();
117 my $subquery = "SELECT distinct value->'reference_genome_name', value->'species_name', nd_protocol_id, value->'header_information_lines' from nd_protocolprop where type_id = $vcf_map_details_cvterm_id $where_clause";
119 my $h = $schema->storage->dbh()->prepare($subquery);
122 while (my ($referenceset, $species, $protocol, $header ) = $h->fetchrow_array()) {
123 $referenceset =~ s/"//g;
128 my $head = decode_json
$header;
131 $source = $1 if ($_ =~ /##source=(\w+)/);
135 my $referenceName = $1 if ($_ =~ /##contig=<ID=(\w+)/) ;
136 my $length = $1 if ($_ =~ /,length=(\d+)/) ;
137 my $md5 = $1 if ($_ =~ /,md5=(\w+)/) ;
139 if($referenceName && $reference_ids eq $referenceName ){
141 additionalInfo
=> {},
142 isDerived
=> JSON
::false
,
143 length => $length + 0,
145 referenceSetDbId
=> qq|$protocol|,
146 referenceSetName
=> $referenceset,
147 referenceDbId
=> qq|$referenceName|,
148 referenceName
=> qq|$referenceName|,
149 sourceAccessions
=> undef,
150 sourceDivergence
=> undef,
163 my $status = $self->status;
165 my %result = (data
=>\
@data);
167 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($counter,$page_size,$page);
168 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'References result constructed');