| 1 | |||||||||||||||||||||||||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | Bio::DB::GFF::Adaptor::dbi -- Database adaptor for DBI (SQL) databases | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | See L<Bio::DB::GFF> | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | This is the base class for DBI-based adaptors. It does everything | ||||||||||||||||||||||||||||||||||||||||||
| 13 | except generating the text of the queries to be used. See the section | ||||||||||||||||||||||||||||||||||||||||||
| 14 | QUERIES TO IMPLEMENT for the list of methods that must be implemented. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | package Bio::DB::GFF::Adaptor::dbi; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | $Bio::DB::GFF::Adaptor::dbi::VERSION = '1.7.4'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | # base class for dbi-based implementations | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | use Bio::DB::GFF::Util::Rearrange; # for rearrange() | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use Bio::DB::GFF::Util::Binning; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use Bio::DB::GFF::Adaptor::dbi::iterator; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use Bio::DB::GFF::Adaptor::dbi::caching_handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | use base qw(Bio::DB::GFF); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # constants for choosing | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | use constant MAX_SEGMENT => 1_000_000_000; # the largest a segment can get | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # this is the largest that any reference sequence can be (100 megabases) | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | use constant MAX_BIN => 1_000_000_000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # this is the smallest bin (1 K) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | use constant MIN_BIN => 1000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # size of range over which it is faster to force the database to use the range for indexing | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ▶ | use constant STRAIGHT_JOIN_LIMIT => 200_000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # this is the size to which DNA should be shredded | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | use constant DNA_CHUNK_SIZE => 2000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # size of summary bins for interval coverage statistics | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | use constant SUMMARY_BIN_SIZE => 1000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # for debugging fbin optimization | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | use constant EPSILON => 1e-7; # set to zero if you trust mysql's floating point comparisons | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | use constant OPTIMIZE => 1; # set to zero to turn off optimization completely | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | Title : new | ||||||||||||||||||||||||||||||||||||||||||
| 60 | Usage : $db = Bio::DB::GFF->new(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | Function: create a new adaptor | ||||||||||||||||||||||||||||||||||||||||||
| 62 | Returns : a Bio::DB::GFF object | ||||||||||||||||||||||||||||||||||||||||||
| 63 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 64 | Status : Public | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | This is the constructor for the adaptor. It is called automatically | ||||||||||||||||||||||||||||||||||||||||||
| 67 | by Bio::DB::GFF-E<gt>new. In addition to arguments that are common among | ||||||||||||||||||||||||||||||||||||||||||
| 68 | all adaptors, the following class-specific arguments are recgonized: | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | Argument Description | ||||||||||||||||||||||||||||||||||||||||||
| 71 | -------- ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | -dsn the DBI data source, e.g. 'dbi:mysql:ens0040' | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | -user username for authentication | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | -pass the password for authentication | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Create a new Bio::DB::GFF::Adaptor::dbi object | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($features_db,$username,$auth,$other) = rearrange([ | |||||||||||||||||||||||||||||||||||||||||
| 85 | [qw(FEATUREDB DB DSN)], | ||||||||||||||||||||||||||||||||||||||||||
| 86 | [qw(USERNAME USER)], | ||||||||||||||||||||||||||||||||||||||||||
| 87 | [qw(PASSWORD PASSWD PASS)], | ||||||||||||||||||||||||||||||||||||||||||
| 88 | ],@_); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $features_db || $class->throw("new(): Provide a data source or DBI database"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (!ref($features_db)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $dsn = $features_db; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | push @args,$username if defined $username; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | push @args,$auth if defined $auth; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $features_db = Bio::DB::GFF::Adaptor::dbi::caching_handle->new($dsn,@args) | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
'Bio::DB::GFF::Adaptor::dbi::caching_handle'->new($dsn, @args) || $class->throw("new(): Failed to connect to ${dsn}: " . 'Bio::DB::GFF::Adaptor::dbi::caching_handle'->errstr)
MC/DC0%0/2
'Bio::DB::GFF::Adaptor::dbi::caching_handle'->new($dsn, @args) || $class->throw("new(): Failed to connect to ${dsn}: " . 'Bio::DB::GFF::Adaptor::dbi::caching_handle'->errstr)
'Bio::DB::GFF::Adaptor::dbi::caching_handle'->new($dsn, @args)
$class->throw("new(): Failed to connect to ${dsn}: " . 'Bio::DB::GFF::Adaptor::dbi::caching_handle'->errstr)
Truth table0%0/3
A || B
A= 'Bio::DB::GFF::Adaptor::dbi::caching_handle'->new($dsn, @args)B= $class->throw("new(): Failed to connect to ${dsn}: " . 'Bio::DB::GFF::Adaptor::dbi::caching_handle'->errstr)
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | || $class->throw("new(): Failed to connect to $dsn: " | ||||||||||||||||||||||||||||||||||||||||||
| 99 | . Bio::DB::GFF::Adaptor::dbi::caching_handle->errstr); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $features_db->isa('DBI::db') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | || $class->throw("new(): $features_db is not a DBI handle"); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # fill in object | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 107 | features_db => $features_db | ||||||||||||||||||||||||||||||||||||||||||
| 108 | },$class; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->features_db->debug(@_); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $self->SUPER::debug(@_); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =head2 features_db | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | Title : features_db | ||||||||||||||||||||||||||||||||||||||||||
| 120 | Usage : $dbh = $db->features_db | ||||||||||||||||||||||||||||||||||||||||||
| 121 | Function: get database handle | ||||||||||||||||||||||||||||||||||||||||||
| 122 | Returns : a DBI handle | ||||||||||||||||||||||||||||||||||||||||||
| 123 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 124 | Status : Public | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | Note: what is returned is not really a DBI::db handle, but a | ||||||||||||||||||||||||||||||||||||||||||
| 127 | subclass of one. This means that you cannot manipulate the | ||||||||||||||||||||||||||||||||||||||||||
| 128 | handle's attributes directly. Instead call the attribute | ||||||||||||||||||||||||||||||||||||||||||
| 129 | method: | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | my $dbh = $db->features_db; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | $dbh->attribute(AutoCommit=>0); | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub features_db { shift->{features_db} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
features_db: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub dbh { shift->{features_db} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | =head2 get_dna | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | Title : get_dna | ||||||||||||||||||||||||||||||||||||||||||
| 142 | Usage : $string = $db->get_dna($name,$start,$stop,$class) | ||||||||||||||||||||||||||||||||||||||||||
| 143 | Function: get DNA string | ||||||||||||||||||||||||||||||||||||||||||
| 144 | Returns : a string | ||||||||||||||||||||||||||||||||||||||||||
| 145 | Args : name, class, start and stop of desired segment | ||||||||||||||||||||||||||||||||||||||||||
| 146 | Status : Public | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | This method performs the low-level fetch of a DNA substring given its | ||||||||||||||||||||||||||||||||||||||||||
| 149 | name, class and the desired range. It is actually a front end to the | ||||||||||||||||||||||||||||||||||||||||||
| 150 | abstract method make_dna_query(), which it calls after some argument | ||||||||||||||||||||||||||||||||||||||||||
| 151 | consistency checking. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub get_dna { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_dna: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my ($ref,$start,$stop,$class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my ($offset_start,$offset_stop); | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $has_start = defined $start; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $has_stop = defined $stop; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $reversed; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ($has_start && $has_stop && $start > $stop) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$has_start and $has_stop and $start > $stop
$has_start and $has_stop
MC/DC0%0/3
$has_start and $has_stop and $start > $stop
$has_start
$has_stop
$start > $stop
Truth table0%0/4
A and B and C
A= $has_startB= $has_stopC= $start > $stop
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $reversed++; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ($start,$stop) = ($stop,$start); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # turn start and stop into 0-based offsets | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $cs = $self->dna_chunk_size; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $start -= 1; $stop -= 1; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $offset_start = int($start/$cs)*$cs; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $offset_stop = int($stop/$cs)*$cs; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $sth; | |||||||||||||||||||||||||||||||||||||||||
| 177 | # special case, get it all | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if (!($has_start || $has_stop)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$has_start || $has_stop
MC/DC0%0/2
$has_start || $has_stop
$has_start
$has_stop
Truth table0%0/3
A || B
A= $has_startB= $has_stop
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $sth = $self->dbh->do_query('select fdna,foffset from fdna where fref=? order by foffset',$ref); | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | elsif (!$has_stop) { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $sth = $self->dbh->do_query('select fdna,foffset from fdna where fref=? and foffset>=? order by foffset', | |||||||||||||||||||||||||||||||||||||||||
| 184 | $ref,$offset_start); | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | else { # both start and stop defined | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $sth = $self->dbh->do_query('select fdna,foffset from fdna where fref=? and foffset>=? and foffset<=? order by foffset', | |||||||||||||||||||||||||||||||||||||||||
| 189 | $ref,$offset_start,$offset_stop); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $dna = ''; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | while (my($frag,$offset) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | substr($frag,0,$start-$offset) = '' if $has_start && $start > $offset; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$has_start and $start > $offset
MC/DC0%0/2
$has_start and $start > $offset
$has_start
$start > $offset
Truth table0%0/3
A and B
A= $has_startB= $start > $offset
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $dna .= $frag; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | substr($dna,$stop-$start+1) = '' if $has_stop && $stop-$start+1 < length($dna); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$has_stop and $stop - $start + 1 < length $dna
MC/DC0%0/2
$has_stop and $stop - $start + 1 < length $dna
$has_stop
$stop - $start + 1 < length $dna
Truth table0%0/3
A and B
A= $has_stopB= $stop - $start + 1 < length $dna
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ($reversed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $dna = reverse $dna; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $dna =~ tr/gatcGATC/ctagCTAG/; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $dna; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =head2 get_abscoords | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | Title : get_abscoords | ||||||||||||||||||||||||||||||||||||||||||
| 211 | Usage : ($refseq,$refclass,$start,$stop,$strand) = $db->get_abscoords($name,$class) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | Function: get absolute coordinates for landmark | ||||||||||||||||||||||||||||||||||||||||||
| 213 | Returns : an array ref -- see below | ||||||||||||||||||||||||||||||||||||||||||
| 214 | Args : name and class of desired landmark | ||||||||||||||||||||||||||||||||||||||||||
| 215 | Status : Public | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | This method performs the low-level resolution of a landmark into a | ||||||||||||||||||||||||||||||||||||||||||
| 218 | reference sequence and position. | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | The result is an array ref, each element of which is a five-element | ||||||||||||||||||||||||||||||||||||||||||
| 221 | list containing reference sequence name, class, start, stop and strand. | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub get_abscoords { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_abscoords: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ($name,$class,$refseq) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $sth = $self->make_abscoord_query($name,$class,$refseq); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | while (my @row = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | push @result,\@row | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (@result == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | #$self->error("$name not found in database"); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $sth2 = $self->make_aliasabscoord_query($name,$class); | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | while (my @row2 = $sth2->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | push @result,\@row2 | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if (@result == 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->error("$name not found in database"); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | return \@result; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | =head2 get_features | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | Title : get_features | ||||||||||||||||||||||||||||||||||||||||||
| 258 | Usage : $db->get_features($search,$options,$callback) | ||||||||||||||||||||||||||||||||||||||||||
| 259 | Function: retrieve features from the database | ||||||||||||||||||||||||||||||||||||||||||
| 260 | Returns : number of features retrieved | ||||||||||||||||||||||||||||||||||||||||||
| 261 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 262 | Status : Public | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | This is the low-level method that is called to retrieve GFF lines from | ||||||||||||||||||||||||||||||||||||||||||
| 265 | the database. It is responsible for retrieving features that satisfy | ||||||||||||||||||||||||||||||||||||||||||
| 266 | range and feature type criteria, and passing the GFF fields to a | ||||||||||||||||||||||||||||||||||||||||||
| 267 | callback subroutine. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | See the manual page for Bio::DB::GFF for the interpretation of the | ||||||||||||||||||||||||||||||||||||||||||
| 270 | arguments and how the information retrieved by get_features is passed | ||||||||||||||||||||||||||||||||||||||||||
| 271 | to the callback for processing. | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | Internally, get_features() is a front end for range_query(). The | ||||||||||||||||||||||||||||||||||||||||||
| 274 | latter method constructs the query and executes it. get_features() | ||||||||||||||||||||||||||||||||||||||||||
| 275 | calls fetchrow_array() to recover the fields and passes them to the | ||||||||||||||||||||||||||||||||||||||||||
| 276 | callback. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # Given sequence name, range, and optional filter, retrieve list of | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # all features. Passes features through callback. | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub get_features { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_features: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($search,$options,$callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $callback || $self->throw('must provide a callback argument'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $sth = $self->range_query(@{$search}{qw(rangetype | |||||||||||||||||||||||||||||||||||||||||
| 288 | refseq | ||||||||||||||||||||||||||||||||||||||||||
| 289 | refclass | ||||||||||||||||||||||||||||||||||||||||||
| 290 | start | ||||||||||||||||||||||||||||||||||||||||||
| 291 | stop | ||||||||||||||||||||||||||||||||||||||||||
| 292 | types) }, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | @{$options}{qw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | sparse | ||||||||||||||||||||||||||||||||||||||||||
| 295 | sort_by_group | ||||||||||||||||||||||||||||||||||||||||||
| 296 | ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 297 | BINSIZE)}) or return; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | while (my @row = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $callback->(@row); | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | =head2 classes | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | Title : classes | ||||||||||||||||||||||||||||||||||||||||||
| 311 | Usage : $db->classes | ||||||||||||||||||||||||||||||||||||||||||
| 312 | Function: return list of landmark classes in database | ||||||||||||||||||||||||||||||||||||||||||
| 313 | Returns : a list of classes | ||||||||||||||||||||||||||||||||||||||||||
| 314 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 315 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | This routine returns the list of reference classes known to the | ||||||||||||||||||||||||||||||||||||||||||
| 318 | database, or empty if classes are not used by the database. Classes | ||||||||||||||||||||||||||||||||||||||||||
| 319 | are distinct from types, being essentially qualifiers on the reference | ||||||||||||||||||||||||||||||||||||||||||
| 320 | namespaces. | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | NOTE: In the current mysql-based schema, this query takes a while to | ||||||||||||||||||||||||||||||||||||||||||
| 323 | run due to the classes not being normalized. | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub classes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
classes: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | my ($query,@args) = $self->make_classes_query or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $sth = $self->dbh->do_query($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my @classes; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | while (my ($c) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | push @classes,$c; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | @classes; | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | =head2 make_classes_query | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | Title : make_classes_query | ||||||||||||||||||||||||||||||||||||||||||
| 341 | Usage : ($query,@args) = $db->make_classes_query | ||||||||||||||||||||||||||||||||||||||||||
| 342 | Function: return query fragment for generating list of reference classes | ||||||||||||||||||||||||||||||||||||||||||
| 343 | Returns : a query and args | ||||||||||||||||||||||||||||||||||||||||||
| 344 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 345 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub make_classes_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_classes_query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | =head2 _feature_by_name | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | Title : _feature_by_name | ||||||||||||||||||||||||||||||||||||||||||
| 357 | Usage : $db->get_features_by_name($name,$class,$callback) | ||||||||||||||||||||||||||||||||||||||||||
| 358 | Function: get a list of features by name and class | ||||||||||||||||||||||||||||||||||||||||||
| 359 | Returns : count of number of features retrieved | ||||||||||||||||||||||||||||||||||||||||||
| 360 | Args : name of feature, class of feature, and a callback | ||||||||||||||||||||||||||||||||||||||||||
| 361 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | This method is used internally. The callback arguments are those used | ||||||||||||||||||||||||||||||||||||||||||
| 364 | by make_feature(). Internally, it invokes the following abstract procedures: | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | make_features_select_part | ||||||||||||||||||||||||||||||||||||||||||
| 367 | make_features_from_part | ||||||||||||||||||||||||||||||||||||||||||
| 368 | make_features_by_name_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 369 | make_features_by_alias_where_part (for aliases) | ||||||||||||||||||||||||||||||||||||||||||
| 370 | make_features_join_part | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub _feature_by_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_feature_by_name: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my ($class,$name,$location,$callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | $callback || $self->throw('must provide a callback argument'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $select = $self->make_features_select_part; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $from = $self->make_features_from_part(undef,{sparse_groups=>1}); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my ($where,@args) = $self->make_features_by_name_where_part($class,$name); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $join = $self->make_features_join_part; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $range = $self->make_features_by_range_where_part('overlaps', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | {refseq=>$location->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 385 | class =>'', | ||||||||||||||||||||||||||||||||||||||||||
| 386 | start=>$location->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 387 | stop =>$location->[2]}) if $location; | ||||||||||||||||||||||||||||||||||||||||||
| 388 | # group query | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $query1 = "SELECT $select FROM $from WHERE $where AND $join"; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | $query1 .= " AND $range" if $range; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | # alias query | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $from = $self->make_features_from_part(undef,{attributes=>1}); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ($where,@args) = $self->make_features_by_alias_where_part($class,$name); # potential bug - @args1==@args2? | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $query2 = "SELECT $select FROM $from WHERE $where AND $join"; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $query2 .= " AND $range" if $range; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | for my $query ($query1,$query2) { | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $sth = $self->dbh->do_query($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | while (my @row = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $callback->(@row); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | =head2 _feature_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | Title : _feature_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 416 | Usage : $db->_feature_by_id($ids,$type,$callback) | ||||||||||||||||||||||||||||||||||||||||||
| 417 | Function: get a list of features by ID | ||||||||||||||||||||||||||||||||||||||||||
| 418 | Returns : count of number of features retrieved | ||||||||||||||||||||||||||||||||||||||||||
| 419 | Args : arrayref containing list of IDs to fetch and a callback | ||||||||||||||||||||||||||||||||||||||||||
| 420 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | This method is used internally. The $type selector is one of | ||||||||||||||||||||||||||||||||||||||||||
| 423 | "feature" or "group". The callback arguments are those used by | ||||||||||||||||||||||||||||||||||||||||||
| 424 | make_feature(). Internally, it invokes the following abstract | ||||||||||||||||||||||||||||||||||||||||||
| 425 | procedures: | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | make_features_select_part | ||||||||||||||||||||||||||||||||||||||||||
| 428 | make_features_from_part | ||||||||||||||||||||||||||||||||||||||||||
| 429 | make_features_by_id_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 430 | make_features_join_part | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | sub _feature_by_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_feature_by_id: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my ($ids,$type,$callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | $callback || $self->throw('must provide a callback argument'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $select = $self->make_features_select_part; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $from = $self->make_features_from_part; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | my ($where,@args) = $type eq 'feature' ? $self->make_features_by_id_where_part($ids) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | : $self->make_features_by_gid_where_part($ids); | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $join = $self->make_features_join_part; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $query = "SELECT $select FROM $from WHERE $where AND $join"; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $sth = $self->dbh->do_query($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | while (my @row = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $callback->(@row); | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | sub _feature_by_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_feature_by_attribute: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my ($attributes,$callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | $callback || $self->throw('must provide a callback argument'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $select = $self->make_features_select_part; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my $from = $self->make_features_from_part(undef,{attributes=>$attributes}); | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my ($where,@args) = $self->make_features_by_range_where_part('',{attributes=>$attributes}); | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my $join = $self->make_features_join_part({attributes=>$attributes}); | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $query = "SELECT $select FROM $from WHERE $where AND $join"; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | my $sth = $self->dbh->do_query($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | while (my @row = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $callback->(@row); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | =head2 get_types | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | Title : get_types | ||||||||||||||||||||||||||||||||||||||||||
| 480 | Usage : $db->get_types($refseq,$refclass,$start,$stop,$count) | ||||||||||||||||||||||||||||||||||||||||||
| 481 | Function: get list of types | ||||||||||||||||||||||||||||||||||||||||||
| 482 | Returns : a list of Bio::DB::GFF::Typename objects | ||||||||||||||||||||||||||||||||||||||||||
| 483 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 484 | Status : Public | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | This method is responsible for fetching the list of feature type names | ||||||||||||||||||||||||||||||||||||||||||
| 487 | from the database. The query may be limited to a particular range, in | ||||||||||||||||||||||||||||||||||||||||||
| 488 | which case the range is indicated by a landmark sequence name and | ||||||||||||||||||||||||||||||||||||||||||
| 489 | class and its subrange, if any. These arguments may be undef if it is | ||||||||||||||||||||||||||||||||||||||||||
| 490 | desired to retrieve all feature types in the database (which may be a | ||||||||||||||||||||||||||||||||||||||||||
| 491 | slow operation in some implementations). | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | If the $count flag is false, the method returns a simple list of | ||||||||||||||||||||||||||||||||||||||||||
| 494 | vBio::DB::GFF::Typename objects. If $count is true, the method returns | ||||||||||||||||||||||||||||||||||||||||||
| 495 | a list of $name=E<gt>$count pairs, where $count indicates the number of | ||||||||||||||||||||||||||||||||||||||||||
| 496 | times this feature occurs in the range. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | Internally, this method calls upon the following functions to generate | ||||||||||||||||||||||||||||||||||||||||||
| 499 | the SQL and its bind variables: | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | ($q1,@args) = make_types_select_part(@args); | ||||||||||||||||||||||||||||||||||||||||||
| 502 | ($q2,@args) = make_types_from_part(@args); | ||||||||||||||||||||||||||||||||||||||||||
| 503 | ($q3,@args) = make_types_where_part(@args); | ||||||||||||||||||||||||||||||||||||||||||
| 504 | ($q4,@args) = make_types_join_part(@args); | ||||||||||||||||||||||||||||||||||||||||||
| 505 | ($q5,@args) = make_types_group_part(@args); | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | The components are then combined as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | $query = "SELECT $q1 FROM $q2 WHERE $q3 AND $q4 GROUP BY $q5"; | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | If any of the query fragments contain the ? bind variable, then the | ||||||||||||||||||||||||||||||||||||||||||
| 512 | same number of bind arguments must be provided in @args. The | ||||||||||||||||||||||||||||||||||||||||||
| 513 | fragment-generating functions are described below. | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | sub get_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_types: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my ($srcseq,$class,$start,$stop,$want_count,$typelist) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | my $straight = $self->do_straight_join($srcseq,$start,$stop,[]) ? 'straight_join' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my ($select,@args1) = $self->make_types_select_part($srcseq,$start,$stop,$want_count,$typelist); | |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my ($from,@args2) = $self->make_types_from_part($srcseq,$start,$stop,$want_count,$typelist); | |||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my ($join,@args3) = $self->make_types_join_part($srcseq,$start,$stop,$want_count,$typelist); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my ($where,@args4) = $self->make_types_where_part($srcseq,$start,$stop,$want_count,$typelist); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my ($group,@args5) = $self->make_types_group_part($srcseq,$start,$stop,$want_count,$typelist); | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $query = "SELECT $straight $select FROM $from WHERE $join AND $where"; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | $query .= " GROUP BY $group" if $group; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my @args = (@args1,@args2,@args3,@args4,@args5); | |||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | my $sth = $self->dbh->do_query($query,@args) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my (%result,%obj); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | while (my ($method,$source,$count) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my $type = Bio::DB::GFF::Typename->new($method,$source); | |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | $result{$type} = $count; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $obj{$type} = $type; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | return $want_count ? %result : values %obj; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | =head2 range_query | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | Title : range_query | ||||||||||||||||||||||||||||||||||||||||||
| 544 | Usage : $db->range_query($range_type,$refseq,$refclass,$start,$stop,$types,$order_by_group,$attributes,$binsize) | ||||||||||||||||||||||||||||||||||||||||||
| 545 | Function: create statement handle for range/overlap queries | ||||||||||||||||||||||||||||||||||||||||||
| 546 | Returns : a DBI statement handle | ||||||||||||||||||||||||||||||||||||||||||
| 547 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 548 | Status : Protected | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | This method constructs the statement handle for this module's central | ||||||||||||||||||||||||||||||||||||||||||
| 551 | query: given a range and/or a list of feature types, fetch their GFF | ||||||||||||||||||||||||||||||||||||||||||
| 552 | records. | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | The positional arguments are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | Argument Description | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | $isrange A flag indicating that this is a range. | ||||||||||||||||||||||||||||||||||||||||||
| 559 | query. Otherwise an overlap query is | ||||||||||||||||||||||||||||||||||||||||||
| 560 | assumed. | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | $refseq The reference sequence name (undef if no range). | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | $refclass The reference sequence class (undef if no range). | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | $start The start of the range (undef if none). | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | $stop The stop of the range (undef if none). | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | $types Array ref containing zero or feature types in the | ||||||||||||||||||||||||||||||||||||||||||
| 571 | format [method,source]. | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | $order_by_group A flag indicating that statement handler should group | ||||||||||||||||||||||||||||||||||||||||||
| 574 | the features by group id (handy for iterative fetches) | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | $attributes A hash containing select attributes. | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | $binsize A bin size for generating tables of feature density. | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | If successful, this method returns a statement handle. The handle is | ||||||||||||||||||||||||||||||||||||||||||
| 581 | expected to return the fields described for get_features(). | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | Internally, range_query() makes calls to the following methods, | ||||||||||||||||||||||||||||||||||||||||||
| 584 | each of which is expected to be overridden in subclasses: | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | $select = $self->make_features_select_part; | ||||||||||||||||||||||||||||||||||||||||||
| 587 | $from = $self->make_features_from_part; | ||||||||||||||||||||||||||||||||||||||||||
| 588 | $join = $self->make_features_join_part; | ||||||||||||||||||||||||||||||||||||||||||
| 589 | ($where,@args) = $self->make_features_by_range_where_part($isrange,$srcseq,$class, | ||||||||||||||||||||||||||||||||||||||||||
| 590 | $start,$stop,$types,$class); | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | The query that is constructed looks like this: | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | SELECT $select FROM $from WHERE $join AND $where | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | The arguments that are returned from make_features_by_range_where_part() are | ||||||||||||||||||||||||||||||||||||||||||
| 597 | passed to the statement handler's execute() method. | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | range_query() also calls a do_straight_join() method, described | ||||||||||||||||||||||||||||||||||||||||||
| 600 | below. If this method returns true, then the keyword "straight_join" | ||||||||||||||||||||||||||||||||||||||||||
| 601 | is inserted right after SELECT. | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | sub range_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
range_query: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my($rangetype,$refseq,$class,$start,$stop,$types,$sparse,$order_by_group,$attributes,$bin) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | # NOTE: straight_join is necessary in some database to force the right index to be used. | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my %a = (refseq=>$refseq,class=>$class,start=>$start,stop=>$stop,types=>$types,attributes=>$attributes,bin_width=>$bin); | |||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | my $straight = $self->do_straight_join(\%a) ? 'straight_join' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | my $select = $self->make_features_select_part(\%a); | |||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my $from = $self->make_features_from_part($sparse,\%a); | |||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | my $join = $self->make_features_join_part(\%a); | |||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my ($where,@args) = $self->make_features_by_range_where_part($rangetype,\%a); | |||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my ($group_by,@more_args) = $self->make_features_group_by_part(\%a); | |||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | my $order_by = $self->make_features_order_by_part(\%a) if $order_by_group; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | my $query = "SELECT $straight $select FROM $from WHERE $join"; | |||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | $query .= " AND $where" if $where; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | if ($group_by) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | $query .= " GROUP BY $group_by"; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | push @args,@more_args; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | $query .= " ORDER BY $order_by" if $order_by; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | my $sth = $self->dbh->do_query($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | $sth; | |||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | =head2 make_features_by_range_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | Title : make_features_by_range_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 636 | Usage : ($string,@args) = | ||||||||||||||||||||||||||||||||||||||||||
| 637 | $db->make_features_select_part($isrange,$refseq,$class,$start,$stop,$types) | ||||||||||||||||||||||||||||||||||||||||||
| 638 | Function: make where part of the features query | ||||||||||||||||||||||||||||||||||||||||||
| 639 | Returns : the list ($query,@bind_args) | ||||||||||||||||||||||||||||||||||||||||||
| 640 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 641 | Status : Protected | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | This method creates the part of the features query that immediately | ||||||||||||||||||||||||||||||||||||||||||
| 644 | follows the WHERE keyword and is ANDed with the string returned by | ||||||||||||||||||||||||||||||||||||||||||
| 645 | make_features_join_part(). | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | The six positional arguments are a flag indicating whether to perform | ||||||||||||||||||||||||||||||||||||||||||
| 648 | a range search or an overlap search, the reference sequence, class, | ||||||||||||||||||||||||||||||||||||||||||
| 649 | start and stop, all of which define an optional range to search in, | ||||||||||||||||||||||||||||||||||||||||||
| 650 | and an array reference containing a list [$method,$souce] pairs. | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | The method result is a multi-element list containing the query string | ||||||||||||||||||||||||||||||||||||||||||
| 653 | and the list of runtime arguments to bind to it with the execute() | ||||||||||||||||||||||||||||||||||||||||||
| 654 | method. | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | This method's job is to clean up arguments and perform consistency | ||||||||||||||||||||||||||||||||||||||||||
| 657 | checking. The real work is done by the following abstract methods: | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | Method Description | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | refseq_query() Return the query string needed to match the reference | ||||||||||||||||||||||||||||||||||||||||||
| 662 | sequence. | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | range_query() Return the query string needed to find all features contained | ||||||||||||||||||||||||||||||||||||||||||
| 665 | within a range. | ||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | overlap_query() Return the query string needed to find all features that overlap | ||||||||||||||||||||||||||||||||||||||||||
| 668 | a range. | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | See Bio::DB::Adaptor::dbi::mysql for an example of how this works. | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | #' | ||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | sub make_features_by_range_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_by_range_where_part: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | my ($rangetype,$options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | my ($refseq,$class,$start,$stop,$types,$attributes) = | ||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | @{$options}{qw(refseq class start stop types attributes)}; | |||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | my (@query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | if ($refseq) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my ($q,@a) = $self->refseq_query($refseq,$class); | |||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | push @query,$q; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | push @args,@a; | |||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | if (defined $start or defined $stop) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $start or defined $stop
MC/DC0%0/2
defined $start or defined $stop
defined $start
defined $stop
Truth table0%0/3
A or B
A= defined $startB= defined $stop
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | $start = 0 unless defined($start); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | $stop = MAX_SEGMENT unless defined($stop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | my ($range_query,@range_args) = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | $rangetype eq 'overlaps' ? $self->overlap_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 697 | : $rangetype eq 'contains' ? $self->contains_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 698 | : $rangetype eq 'contained_in' ? $self->contained_in_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 699 | : (); | ||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | push @query,$range_query; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | push @args,@range_args; | |||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | if (defined $types && @$types) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $types and @$types
MC/DC0%0/2
defined $types and @$types
defined $types
@$types
Truth table0%0/3
A and B
A= defined $typesB= @$types
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | my ($type_query,@type_args) = $self->types_query($types); | |||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | push @query,$type_query; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | push @args,@type_args; | |||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | if ($attributes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | my ($attribute_query,@attribute_args) = $self->make_features_by_attribute_where_part($attributes); | |||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | push @query,"($attribute_query)"; | |||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | push @args,@attribute_args; | |||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | my $query = join "\n\tAND ",@query; | |||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | =head2 do_straight_join | ||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | Title : do_straight_join | ||||||||||||||||||||||||||||||||||||||||||
| 724 | Usage : $boolean = $db->do_straight_join($refseq,$class,$start,$stop,$types) | ||||||||||||||||||||||||||||||||||||||||||
| 725 | Function: optimization flag | ||||||||||||||||||||||||||||||||||||||||||
| 726 | Returns : a flag | ||||||||||||||||||||||||||||||||||||||||||
| 727 | Args : see range_query() | ||||||||||||||||||||||||||||||||||||||||||
| 728 | Status : Protected | ||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||
| 730 | This subroutine, called by range_query() returns a boolean flag. | ||||||||||||||||||||||||||||||||||||||||||
| 731 | If true, range_query() will perform a straight join, which can be | ||||||||||||||||||||||||||||||||||||||||||
| 732 | used to optimize certain SQL queries. The four arguments correspond | ||||||||||||||||||||||||||||||||||||||||||
| 733 | to similarly-named arguments passed to range_query(). | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | sub do_straight_join { 0 } # false by default | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_straight_join: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | =head2 string_match | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | Title : string_match | ||||||||||||||||||||||||||||||||||||||||||
| 742 | Usage : $string = $db->string_match($field,$value) | ||||||||||||||||||||||||||||||||||||||||||
| 743 | Function: create a SQL fragment for performing exact or regexp string matching | ||||||||||||||||||||||||||||||||||||||||||
| 744 | Returns : query string | ||||||||||||||||||||||||||||||||||||||||||
| 745 | Args : the table field and match value | ||||||||||||||||||||||||||||||||||||||||||
| 746 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | This method examines the passed value for meta characters. If so it | ||||||||||||||||||||||||||||||||||||||||||
| 749 | produces a SQL fragment that performs a regular expression match. | ||||||||||||||||||||||||||||||||||||||||||
| 750 | Otherwise, it produces a fragment that performs an exact string match. | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | This method is not used in the module, but is available for use by | ||||||||||||||||||||||||||||||||||||||||||
| 753 | subclasses. | ||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | sub string_match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string_match: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | my ($field,$value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | ▶ | return qq($field = ?) if $value =~ /^[!@%&a-zA-Z0-9_\'\" ~-]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | return qq($field REGEXP ?); | |||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | =head2 exact_match | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | Title : exact_match | ||||||||||||||||||||||||||||||||||||||||||
| 767 | Usage : $string = $db->exact_match($field,$value) | ||||||||||||||||||||||||||||||||||||||||||
| 768 | Function: create a SQL fragment for performing exact string matching | ||||||||||||||||||||||||||||||||||||||||||
| 769 | Returns : query string | ||||||||||||||||||||||||||||||||||||||||||
| 770 | Args : the table field and match value | ||||||||||||||||||||||||||||||||||||||||||
| 771 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | This method produces the SQL fragment for matching a field name to a | ||||||||||||||||||||||||||||||||||||||||||
| 774 | constant string value. | ||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | ▶ | sub exact_match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exact_match: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | my ($field,$value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | return qq($field = ?); | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | =head2 search_notes | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | Title : search_notes | ||||||||||||||||||||||||||||||||||||||||||
| 787 | Usage : @search_results = $db->search_notes("full text search string",$limit) | ||||||||||||||||||||||||||||||||||||||||||
| 788 | Function: Search the notes for a text string, using mysql full-text search | ||||||||||||||||||||||||||||||||||||||||||
| 789 | Returns : array of results | ||||||||||||||||||||||||||||||||||||||||||
| 790 | Args : full text search string, and an optional row limit | ||||||||||||||||||||||||||||||||||||||||||
| 791 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | This is a mysql-specific method. Given a search string, it performs a | ||||||||||||||||||||||||||||||||||||||||||
| 794 | full-text search of the notes table and returns an array of results. | ||||||||||||||||||||||||||||||||||||||||||
| 795 | Each row of the returned array is a arrayref containing the following fields: | ||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | column 1 A Bio::DB::GFF::Featname object, suitable for passing to segment() | ||||||||||||||||||||||||||||||||||||||||||
| 798 | column 2 The text of the note | ||||||||||||||||||||||||||||||||||||||||||
| 799 | column 3 A relevance score. | ||||||||||||||||||||||||||||||||||||||||||
| 800 | column 4 A Bio::DB::GFF::Typename object | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | sub search_notes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_notes: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | my ($search_string,$limit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | $search_string =~ tr/*?//d; | |||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | my @words = $search_string =~ /(\w+)/g; | |||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | my $regex = join '|',@words; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | my @searches = map {"fattribute_value LIKE '%${_}%'"} @words; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | my $search = join(' OR ',@searches); | |||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | my $query = <<END; | |||||||||||||||||||||||||||||||||||||||||
| 816 | SELECT distinct gclass,gname,fattribute_value,fmethod,fsource | ||||||||||||||||||||||||||||||||||||||||||
| 817 | FROM fgroup,fattribute_to_feature,fdata,ftype | ||||||||||||||||||||||||||||||||||||||||||
| 818 | WHERE fgroup.gid=fdata.gid | ||||||||||||||||||||||||||||||||||||||||||
| 819 | AND fdata.fid=fattribute_to_feature.fid | ||||||||||||||||||||||||||||||||||||||||||
| 820 | AND fdata.ftypeid=ftype.ftypeid | ||||||||||||||||||||||||||||||||||||||||||
| 821 | AND ($search) | ||||||||||||||||||||||||||||||||||||||||||
| 822 | END | ||||||||||||||||||||||||||||||||||||||||||
| 823 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | my $sth = $self->dbh->do_query($query); | |||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | while (my ($class,$name,$note,$method,$source) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | next unless $class && $name; # sorry, ignore NULL objects | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class and $name
MC/DC0%0/2
$class and $name
$class
$name
Truth table0%0/3
A and B
A= $classB= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | my @matches = $note =~ /($regex)/g; | |||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | my $relevance = 10*@matches; | |||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | my $featname = Bio::DB::GFF::Featname->new($class=>$name); | |||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | my $type = Bio::DB::GFF::Typename->new($method,$source); | |||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | push @results,[$featname,$note,$relevance,$type]; | |||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | last if $limit && @results >= $limit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$limit and @results >= $limit
MC/DC0%0/2
$limit and @results >= $limit
$limit
@results >= $limit
Truth table0%0/3
A and B
A= $limitB= @results >= $limit
| |||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | @results; | |||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | =head2 meta | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | Title : meta | ||||||||||||||||||||||||||||||||||||||||||
| 843 | Usage : $value = $db->meta($name [,$newval]) | ||||||||||||||||||||||||||||||||||||||||||
| 844 | Function: get or set a meta variable | ||||||||||||||||||||||||||||||||||||||||||
| 845 | Returns : a string | ||||||||||||||||||||||||||||||||||||||||||
| 846 | Args : meta variable name and optionally value | ||||||||||||||||||||||||||||||||||||||||||
| 847 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | Get or set a named metavariable for the database. Metavariables can | ||||||||||||||||||||||||||||||||||||||||||
| 850 | be used for database-specific settings. This method calls two | ||||||||||||||||||||||||||||||||||||||||||
| 851 | class-specific methods which must be implemented: | ||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | make_meta_get_query() Returns a sql fragment which given a meta | ||||||||||||||||||||||||||||||||||||||||||
| 854 | parameter name, returns its value. One bind | ||||||||||||||||||||||||||||||||||||||||||
| 855 | variable. | ||||||||||||||||||||||||||||||||||||||||||
| 856 | make_meta_set_query() Returns a sql fragment which takes two bind | ||||||||||||||||||||||||||||||||||||||||||
| 857 | arguments, the parameter name and its value | ||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | Don't make changes unless you know what you're doing! It will affect the | ||||||||||||||||||||||||||||||||||||||||||
| 861 | persistent database. | ||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | ▶ | sub meta { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | my $param_name = uc shift; | |||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | # getting | ||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | my $sql = $self->make_meta_set_query() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | ▶ | my $sth = $self->dbh->prepare_delayed($sql) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 874 | or $self->error("Can't prepare $sql: ",$self->dbh->errstr), return; | ||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | ▶ | $sth->execute($param_name,$value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 876 | or $self->error("Can't execute $sql: ",$self->dbh->errstr), return; | ||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | return $self->{meta}{$param_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||
| 881 | elsif (exists $self->{meta}{$param_name}) { | ||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | return $self->{meta}{$param_name}; | |||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | undef $self->{meta}{$param_name}; # so that we don't check again | |||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | ▶ | my $sql = $self->make_meta_get_query() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | ▶ | my $sth = $self->dbh->prepare_delayed($sql) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | or $self->error("Can't prepare $sql: ",$self->dbh->errstr), return; | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | ▶ | $sth->execute($param_name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | or $self->error("Can't execute $sql: ",$sth->errstr),return; | ||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | my ($value) = $sth->fetchrow_array; | |||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | return $self->{meta}{$param_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | =head2 make_meta_get_query | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | Title : make_meta_get_query | ||||||||||||||||||||||||||||||||||||||||||
| 902 | Usage : $sql = $db->make_meta_get_query | ||||||||||||||||||||||||||||||||||||||||||
| 903 | Function: return SQL fragment for getting a meta parameter | ||||||||||||||||||||||||||||||||||||||||||
| 904 | Returns : SQL fragment | ||||||||||||||||||||||||||||||||||||||||||
| 905 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 906 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | By default this does nothing; meta parameters are not stored or | ||||||||||||||||||||||||||||||||||||||||||
| 909 | retrieved. | ||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | ▶ | sub make_meta_get_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_meta_get_query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | return 'SELECT fvalue FROM fmeta WHERE fname=?'; | |||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | ▶ | sub dna_chunk_size { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dna_chunk_size: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | ▶ | $self->meta('chunk_size') || DNA_CHUNK_SIZE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | =head2 make_meta_set_query | ||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | Title : make_meta_set_query | ||||||||||||||||||||||||||||||||||||||||||
| 926 | Usage : $sql = $db->make_meta_set_query | ||||||||||||||||||||||||||||||||||||||||||
| 927 | Function: return SQL fragment for setting a meta parameter | ||||||||||||||||||||||||||||||||||||||||||
| 928 | Returns : SQL fragment | ||||||||||||||||||||||||||||||||||||||||||
| 929 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 930 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | By default this does nothing; meta parameters are not stored or | ||||||||||||||||||||||||||||||||||||||||||
| 933 | retrieved. | ||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | ▶ | sub make_meta_set_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_meta_set_query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | =head2 default_meta_values | ||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | Title : default_meta_values | ||||||||||||||||||||||||||||||||||||||||||
| 944 | Usage : %values = $db->default_meta_values | ||||||||||||||||||||||||||||||||||||||||||
| 945 | Function: empty the database | ||||||||||||||||||||||||||||||||||||||||||
| 946 | Returns : a list of tag=>value pairs | ||||||||||||||||||||||||||||||||||||||||||
| 947 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 948 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | This method returns a list of tag=E<gt>value pairs that contain default | ||||||||||||||||||||||||||||||||||||||||||
| 951 | meta information about the database. It is invoked by initialize() to | ||||||||||||||||||||||||||||||||||||||||||
| 952 | write out the default meta values. The base class version returns an | ||||||||||||||||||||||||||||||||||||||||||
| 953 | empty list. | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | For things to work properly, meta value names must be UPPERCASE. | ||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||
| 957 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | ▶ | sub default_meta_values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_meta_values: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 961 | 0 | my @values = $self->SUPER::default_meta_values; | |||||||||||||||||||||||||||||||||||||||||
| 962 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 963 | 0 | @values, | |||||||||||||||||||||||||||||||||||||||||
| 964 | max_bin => MAX_BIN, | ||||||||||||||||||||||||||||||||||||||||||
| 965 | min_bin => MIN_BIN, | ||||||||||||||||||||||||||||||||||||||||||
| 966 | straight_join_limit => STRAIGHT_JOIN_LIMIT, | ||||||||||||||||||||||||||||||||||||||||||
| 967 | chunk_size => DNA_CHUNK_SIZE, | ||||||||||||||||||||||||||||||||||||||||||
| 968 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | ▶ | sub min_bin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_bin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | ▶ | return $self->meta('min_bin') || MIN_BIN; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->meta('min_bin') || 1000
MC/DC0%0/1
$self->meta('min_bin') || 1000
$self->meta('min_bin')
Truth table0%0/2
A
A= $self->meta('min_bin')
| |||||||||||||||||||||||||||||||||||||||||||
| 974 | } | ||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | ▶ | sub max_bin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_bin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | return $self->meta('max_bin') || MAX_BIN; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->meta('max_bin') || 1000000000
MC/DC0%0/1
$self->meta('max_bin') || 1000000000
$self->meta('max_bin')
Truth table0%0/2
A
A= $self->meta('max_bin')
| |||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | ▶ | sub straight_join_limit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
straight_join_limit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | return $self->meta('straight_join_limit') || STRAIGHT_JOIN_LIMIT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->meta('straight_join_limit') || 200000
MC/DC0%0/1
$self->meta('straight_join_limit') || 200000
$self->meta('straight_join_limit')
Truth table0%0/2
A
A= $self->meta('straight_join_limit')
| |||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | =head2 get_features_iterator | ||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | Title : get_features_iterator | ||||||||||||||||||||||||||||||||||||||||||
| 988 | Usage : $iterator = $db->get_features_iterator($search,$options,$callback) | ||||||||||||||||||||||||||||||||||||||||||
| 989 | Function: create an iterator on a features() query | ||||||||||||||||||||||||||||||||||||||||||
| 990 | Returns : A Bio::DB::GFF::Adaptor::dbi::iterator object | ||||||||||||||||||||||||||||||||||||||||||
| 991 | Args : see get_features() | ||||||||||||||||||||||||||||||||||||||||||
| 992 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||
| 994 | This method is similar to get_features(), except that it returns an | ||||||||||||||||||||||||||||||||||||||||||
| 995 | iterator across the query. See | ||||||||||||||||||||||||||||||||||||||||||
| 996 | L<Bio::DB::GFF::Adaptor::dbi::iterator>. | ||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||
| 998 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | ▶ | sub get_features_iterator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_features_iterator: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1001 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | my ($search,$options,$callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | ▶ | $callback || $self->throw('must provide a callback argument'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | my $sth = $self->range_query(@{$search}{qw(rangetype | |||||||||||||||||||||||||||||||||||||||||
| 1005 | refseq | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | refclass | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | start | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | stop | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | types)}, | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | ▶ | @{$options}{qw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1011 | sparse | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | sort_by_group | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | BINSIZE)}) or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | return Bio::DB::GFF::Adaptor::dbi::iterator->new($sth,$callback); | |||||||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||
| 1018 | ########################## loading and initialization ##################### | ||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||
| 1020 | =head2 do_initialize | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | Title : do_initialize | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | Usage : $success = $db->do_initialize($drop_all) | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | Function: initialize the database | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | Returns : a boolean indicating the success of the operation | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | Args : a boolean indicating whether to delete existing data | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||
| 1029 | This method will load the schema into the database. If $drop_all is | ||||||||||||||||||||||||||||||||||||||||||
| 1030 | true, then any existing data in the tables known to the schema will be | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||
| 1033 | Internally, this method calls schema() to get the schema data. | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||
| 1035 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||
| 1037 | # Create the schema from scratch. | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | # You will need create privileges for this. | ||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | ▶ | sub do_initialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_initialize: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1040 | #shift->throw("do_initialize(): must be implemented by subclass"); | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | my $erase = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | ▶ | $self->drop_all if $erase; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | foreach my $table_name ($self->tables) { | |||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | my $create_table_stmt = $schema->{$table_name}{table} ; | |||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | ▶ | $dbh->do($create_table_stmt) || warn $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | $self->create_other_schema_objects(\%{$schema->{$table_name}}); | |||||||||||||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||
| 1056 | =head2 finish_load | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||
| 1058 | Title : finish_load | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | Usage : $db->finish_load | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | Function: called after load_gff_line() | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | Returns : number of records loaded | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||
| 1065 | This method performs schema-specific cleanup after loading a set of | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | GFF records. It finishes each of the statement handlers prepared by | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | setup_load(). | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||
| 1069 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||
| 1071 | 0 | ▶ | sub finish_load { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish_load: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1072 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | ▶ | my $dbh = $self->features_db or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | ▶ | $dbh->do('UNLOCK TABLES') if $self->lock_on_load; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | foreach (keys %{$self->{load_stuff}{sth}}) { | |||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | $self->{load_stuff}{sth}{$_}->finish; | |||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | my $counter = $self->{load_stuff}{counter}; | |||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | delete $self->{load_stuff}; | |||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | return $counter; | |||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||
| 1087 | =head2 create_other_schema_objects | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||
| 1089 | Title : create_other_schema_objects | ||||||||||||||||||||||||||||||||||||||||||
| 1090 | Usage : $self->create_other_schema_objects($table_name) | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | Function: create other schema objects like : indexes, sequences, triggers | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | Returns : | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | Args : | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | Status : Abstract | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||
| 1096 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||
| 1098 | 0 | ▶ | sub create_other_schema_objects{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_other_schema_objects: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1099 | #shift->throw("create_other_schema_objects(): must be implemented by subclass"); | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | 0 | my $self = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 1101 | 0 | my $table_schema = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 1102 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | foreach my $object_type(keys %$table_schema){ | |||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | ▶ | if ($object_type !~ /table/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1105 | 0 | foreach my $object_name(keys %{$table_schema->{$object_type}}){ | |||||||||||||||||||||||||||||||||||||||||
| 1106 | 0 | my $create_object_stmt = $table_schema->{$object_type}{$object_name}; | |||||||||||||||||||||||||||||||||||||||||
| 1107 | 0 | ▶ | $dbh->do($create_object_stmt) || warn $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||
| 1114 | =head2 drop_all | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||||||||||||||||
| 1116 | Title : drop_all | ||||||||||||||||||||||||||||||||||||||||||
| 1117 | Usage : $db->drop_all | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | Function: empty the database | ||||||||||||||||||||||||||||||||||||||||||
| 1119 | Returns : void | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||
| 1123 | This method drops the tables known to this module. Internally it | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | calls the abstract tables() method. | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||
| 1126 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||
| 1128 | # Drop all the GFF tables -- dangerous! | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | ▶ | sub drop_all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_all: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1130 | #shift->throw("drop_all(): must be implemented by subclass"); | ||||||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | local $dbh->{PrintError} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1136 | 0 | foreach ($self->tables) { | |||||||||||||||||||||||||||||||||||||||||
| 1137 | 0 | ▶ | $dbh->do("drop table $_") || warn $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||
| 1139 | #when dropping a table - the indexes and triggers are being dropped automatically | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | # sequences needs to be dropped - if there are any (Oracle, PostgreSQL) | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | ▶ | if ($schema->{$_}{sequence}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | foreach my $sequence_name(keys %{$schema->{$_}{sequence}}) { | |||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | $dbh->do("drop sequence $sequence_name"); | |||||||||||||||||||||||||||||||||||||||||
| 1144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||
| 1147 | #$self->drop_other_schema_objects($_); | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | |||||||||||||||||||||||||||||||||||||||||||
| 1152 | =head2 clone | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | The clone() method should be used when you want to pass the | ||||||||||||||||||||||||||||||||||||||||||
| 1155 | Bio::DB::GFF object to a child process across a fork(). The child must | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | call clone() before making any queries. | ||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||
| 1158 | This method does two things: (1) it sets the underlying database | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | handle's InactiveDestroy parameter to 1, thereby preventing the | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | database connection from being destroyed in the parent when the dbh's | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | destructor is called; (2) it replaces the dbh with the result of | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | dbh-E<gt>clone(), so that we now have an independent handle. | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||
| 1164 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | $self->features_db->clone; | |||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||
| 1172 | =head1 QUERIES TO IMPLEMENT | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||
| 1174 | The following astract methods either return DBI statement handles or | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | fragments of SQL. They must be implemented by subclasses of this | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | module. See Bio::DB::GFF::Adaptor::dbi::mysql for examples. | ||||||||||||||||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||
| 1181 | =head2 drop_other_schema_objects | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||
| 1183 | Title : drop_other_schema_objects | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | Usage : $self->create_other_schema_objects($table_name) | ||||||||||||||||||||||||||||||||||||||||||
| 1185 | Function: create other schema objects like : indexes, sequences, triggers | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | Returns : | ||||||||||||||||||||||||||||||||||||||||||
| 1187 | Args : | ||||||||||||||||||||||||||||||||||||||||||
| 1188 | Status : Abstract | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||
| 1191 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | ▶ | sub drop_other_schema_objects{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_other_schema_objects: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1194 | #shift->throw("drop_other_schema_objects(): must be implemented by subclass"); | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||
| 1198 | =head2 make_features_select_part | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||
| 1200 | Title : make_features_select_part | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | Usage : $string = $db->make_features_select_part() | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | Function: make select part of the features query | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | Returns : a string | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | Status : Abstract | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||
| 1207 | This abstract method creates the part of the features query that | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | immediately follows the SELECT keyword. | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||
| 1210 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | ▶ | sub make_features_select_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_select_part: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | shift->throw("make_features_select_part(): must be implemented by subclass"); | |||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||
| 1216 | =head2 tables | ||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||
| 1218 | Title : tables | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | Usage : @tables = $db->tables | ||||||||||||||||||||||||||||||||||||||||||
| 1220 | Function: return list of tables that belong to this module | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | Returns : list of tables | ||||||||||||||||||||||||||||||||||||||||||
| 1222 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||
| 1225 | This method lists the tables known to the module. | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||
| 1227 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||
| 1229 | # return list of tables that "belong" to us. | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | 0 | ▶ | sub tables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | my $schema = shift->schema; | |||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | return keys %$schema; | |||||||||||||||||||||||||||||||||||||||||
| 1233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||
| 1235 | =head2 schema | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||
| 1237 | Title : schema | ||||||||||||||||||||||||||||||||||||||||||
| 1238 | Usage : $schema = $db->schema | ||||||||||||||||||||||||||||||||||||||||||
| 1239 | Function: return the CREATE script for the schema | ||||||||||||||||||||||||||||||||||||||||||
| 1240 | Returns : a hashref | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1242 | Status : abstract | ||||||||||||||||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||||||||||||||||
| 1244 | This method returns an array ref containing the various CREATE | ||||||||||||||||||||||||||||||||||||||||||
| 1245 | statements needed to initialize the database tables. The keys are the | ||||||||||||||||||||||||||||||||||||||||||
| 1246 | table names, and the values are strings containing the appropriate | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | CREATE statement. | ||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||
| 1249 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||
| 1251 | 0 | ▶ | sub schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1252 | 0 | shift->throw("The schema() method must be implemented by subclass"); | |||||||||||||||||||||||||||||||||||||||||
| 1253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||
| 1255 | =head2 DESTROY | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||
| 1257 | Title : DESTROY | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | Usage : $db->DESTROY | ||||||||||||||||||||||||||||||||||||||||||
| 1259 | Function: disconnect database at destruct time | ||||||||||||||||||||||||||||||||||||||||||
| 1260 | Returns : void | ||||||||||||||||||||||||||||||||||||||||||
| 1261 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1263 | |||||||||||||||||||||||||||||||||||||||||||
| 1264 | This is the destructor for the class. | ||||||||||||||||||||||||||||||||||||||||||
| 1265 | |||||||||||||||||||||||||||||||||||||||||||
| 1266 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||||||||||||||||
| 1268 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1269 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1270 | 0 | ▶ | $self->features_db->disconnect if defined $self->features_db; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||
| 1273 | ################## query cache ################## | ||||||||||||||||||||||||||||||||||||||||||
| 1274 | |||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||
| 1276 | ######################################### | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | ## Moved from mysql.pm and mysqlopt.pm ## | ||||||||||||||||||||||||||||||||||||||||||
| 1278 | ######################################### | ||||||||||||||||||||||||||||||||||||||||||
| 1279 | |||||||||||||||||||||||||||||||||||||||||||
| 1280 | =head2 make_features_by_name_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||
| 1282 | Title : make_features_by_name_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | Usage : $db->make_features_by_name_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1284 | Function: create the SQL fragment needed to select a feature by its group name & class | ||||||||||||||||||||||||||||||||||||||||||
| 1285 | Returns : a SQL fragment and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1286 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 1287 | Status : Protected | ||||||||||||||||||||||||||||||||||||||||||
| 1288 | |||||||||||||||||||||||||||||||||||||||||||
| 1289 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | ▶ | sub make_features_by_name_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_by_name_where_part: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1293 | 0 | my ($class,$name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1294 | 0 | ▶ | if ($name =~ /\*/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1295 | 0 | $name =~ s/%/\\%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1296 | 0 | $name =~ s/_/\\_/g; | |||||||||||||||||||||||||||||||||||||||||
| 1297 | 0 | $name =~ tr/*/%/; | |||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | return ("fgroup.gclass=? AND fgroup.gname LIKE ?",$class,$name); | |||||||||||||||||||||||||||||||||||||||||
| 1299 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | return ("fgroup.gclass=? AND fgroup.gname=?",$class,$name); | |||||||||||||||||||||||||||||||||||||||||
| 1301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||
| 1304 | 0 | ▶ | sub make_features_by_alias_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_by_alias_where_part: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1305 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | my ($class,$name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1307 | 0 | ▶ | if ($name =~ /\*/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | $name =~ tr/*/%/; | |||||||||||||||||||||||||||||||||||||||||
| 1309 | 0 | $name =~ s/_/\\_/g; | |||||||||||||||||||||||||||||||||||||||||
| 1310 | 0 | return ("fgroup.gclass=? AND fattribute_to_feature.fattribute_value LIKE ? AND fgroup.gid=fdata.gid AND fattribute.fattribute_name in ('Alias','Name') AND fattribute_to_feature.fattribute_id=fattribute.fattribute_id AND fattribute_to_feature.fid=fdata.fid AND ftype.ftypeid=fdata.ftypeid",$class,$name) | |||||||||||||||||||||||||||||||||||||||||
| 1311 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | 0 | return ("fgroup.gclass=? AND fattribute_to_feature.fattribute_value=? AND fgroup.gid=fdata.gid AND fattribute.fattribute_name in ('Alias','Name') AND fattribute_to_feature.fattribute_id=fattribute.fattribute_id AND fattribute_to_feature.fid=fdata.fid AND ftype.ftypeid=fdata.ftypeid",$class,$name); | |||||||||||||||||||||||||||||||||||||||||
| 1313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||||||||||||||||
| 1315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | ▶ | sub make_features_by_attribute_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_by_attribute_where_part: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1318 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | my $attributes = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1320 | 0 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 1321 | my @sql; | ||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | foreach (keys %$attributes) { | |||||||||||||||||||||||||||||||||||||||||
| 1323 | 0 | push @sql,"(fattribute.fattribute_name=? AND fattribute_to_feature.fattribute_value=?)"; | |||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | push @args,($_,$attributes->{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | 0 | return (join(' OR ',@sql),@args); | |||||||||||||||||||||||||||||||||||||||||
| 1327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||
| 1329 | =head2 make_features_by_id_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||
| 1331 | Title : make_features_by_id_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1332 | Usage : $db->make_features_by_id_where_part($ids) | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | Function: create the SQL fragment needed to select a set of features by their ids | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | Returns : a SQL fragment and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | Args : arrayref of IDs | ||||||||||||||||||||||||||||||||||||||||||
| 1336 | Status : Protected | ||||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||
| 1338 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||||||||||||||||
| 1340 | 0 | ▶ | sub make_features_by_id_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_by_id_where_part: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1341 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1342 | 0 | my $ids = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1343 | 0 | my $set = join ",",@$ids; | |||||||||||||||||||||||||||||||||||||||||
| 1344 | 0 | return ("fdata.fid IN ($set)"); | |||||||||||||||||||||||||||||||||||||||||
| 1345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | |||||||||||||||||||||||||||||||||||||||||||
| 1347 | =head2 make_features_by_gid_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||||||||||||||||
| 1349 | Title : make_features_by_id_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | Usage : $db->make_features_by_gid_where_part($ids) | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | Function: create the SQL fragment needed to select a set of features by their ids | ||||||||||||||||||||||||||||||||||||||||||
| 1352 | Returns : a SQL fragment and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1353 | Args : arrayref of IDs | ||||||||||||||||||||||||||||||||||||||||||
| 1354 | Status : Protected | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | |||||||||||||||||||||||||||||||||||||||||||
| 1356 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||||||||||||||||
| 1358 | 0 | ▶ | sub make_features_by_gid_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_by_gid_where_part: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1359 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1360 | 0 | my $ids = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1361 | 0 | my $set = join ",",@$ids; | |||||||||||||||||||||||||||||||||||||||||
| 1362 | 0 | return ("fgroup.gid IN ($set)"); | |||||||||||||||||||||||||||||||||||||||||
| 1363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||||||||||||||||
| 1365 | |||||||||||||||||||||||||||||||||||||||||||
| 1366 | =head2 make_features_from_part | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||
| 1368 | Title : make_features_from_part | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | Usage : $string = $db->make_features_from_part() | ||||||||||||||||||||||||||||||||||||||||||
| 1370 | Function: make from part of the features query | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | Returns : a string | ||||||||||||||||||||||||||||||||||||||||||
| 1372 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1373 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1374 | |||||||||||||||||||||||||||||||||||||||||||
| 1375 | This method creates the part of the features query that immediately | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | follows the FROM keyword. | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||||||||||||||||
| 1378 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||
| 1380 | 0 | ▶ | sub make_features_from_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_from_part: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1381 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1382 | 0 | my $sparse = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1383 | 0 | ▶ | my $options = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 1384 | 0 | ▶ | return $options->{attributes} ? "fdata,ftype,fgroup,fattribute,fattribute_to_feature\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1385 | : "fdata,ftype,fgroup\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||||||||||||||||
| 1389 | =head2 make_features_join_part | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||
| 1391 | Title : make_features_join_part | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | Usage : $string = $db->make_features_join_part() | ||||||||||||||||||||||||||||||||||||||||||
| 1393 | Function: make join part of the features query | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | Returns : a string | ||||||||||||||||||||||||||||||||||||||||||
| 1395 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||||||||||||||||
| 1398 | This method creates the part of the features query that immediately | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | follows the WHERE keyword. | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||
| 1401 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||
| 1403 | 0 | ▶ | sub make_features_join_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_join_part: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1404 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1405 | 0 | ▶ | my $options = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 1406 | 0 | ▶ | return !$options->{attributes} ? <<END1 : <<END2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1407 | fgroup.gid = fdata.gid | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | AND ftype.ftypeid = fdata.ftypeid | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | END1 | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | fgroup.gid = fdata.gid | ||||||||||||||||||||||||||||||||||||||||||
| 1411 | AND ftype.ftypeid = fdata.ftypeid | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | AND fattribute.fattribute_id=fattribute_to_feature.fattribute_id | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | AND fdata.fid=fattribute_to_feature.fid | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | END2 | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||||||||||||||||
| 1417 | =head2 make_features_order_by_part | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||
| 1419 | Title : make_features_order_by_part | ||||||||||||||||||||||||||||||||||||||||||
| 1420 | Usage : ($query,@args) = $db->make_features_order_by_part() | ||||||||||||||||||||||||||||||||||||||||||
| 1421 | Function: make the ORDER BY part of the features() query | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | Returns : a SQL fragment and bind arguments, if any | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | |||||||||||||||||||||||||||||||||||||||||||
| 1426 | This method creates the part of the features query that immediately | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | follows the ORDER BY part of the query issued by features() and | ||||||||||||||||||||||||||||||||||||||||||
| 1428 | related methods. | ||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||
| 1430 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||||||||||||||||
| 1432 | 0 | ▶ | sub make_features_order_by_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_order_by_part: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1433 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1434 | 0 | ▶ | my $options = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 1435 | 0 | return "fgroup.gname"; | |||||||||||||||||||||||||||||||||||||||||
| 1436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||
| 1438 | =head2 make_features_group_by_part | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||
| 1440 | Title : make_features_group_by_part | ||||||||||||||||||||||||||||||||||||||||||
| 1441 | Usage : ($query,@args) = $db->make_features_group_by_part() | ||||||||||||||||||||||||||||||||||||||||||
| 1442 | Function: make the GROUP BY part of the features() query | ||||||||||||||||||||||||||||||||||||||||||
| 1443 | Returns : a SQL fragment and bind arguments, if any | ||||||||||||||||||||||||||||||||||||||||||
| 1444 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1445 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1446 | |||||||||||||||||||||||||||||||||||||||||||
| 1447 | This method creates the part of the features query that immediately | ||||||||||||||||||||||||||||||||||||||||||
| 1448 | follows the GROUP BY part of the query issued by features() and | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | related methods. | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||
| 1451 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||
| 1453 | 0 | ▶ | sub make_features_group_by_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_features_group_by_part: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1454 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1455 | 0 | ▶ | my $options = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 1456 | 0 | ▶ | if (my $att = $options->{attributes}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1457 | 0 | my $key_count = keys %$att; | |||||||||||||||||||||||||||||||||||||||||
| 1458 | 0 | ▶ | return unless $key_count > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1459 | 0 | return ("fdata.fid,fref,fstart,fstop,fsource, | |||||||||||||||||||||||||||||||||||||||||
| 1460 | fmethod,fscore,fstrand,fphase,gclass,gname,ftarget_start, | ||||||||||||||||||||||||||||||||||||||||||
| 1461 | ftarget_stop,fdata.gid | ||||||||||||||||||||||||||||||||||||||||||
| 1462 | HAVING count(fdata.fid) > ?",$key_count-1); | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1464 | elsif (my $b = $options->{bin_width}) { | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | 0 | return "fref,fstart,fdata.ftypeid"; | |||||||||||||||||||||||||||||||||||||||||
| 1466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||
| 1468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||||||||||||||||
| 1470 | =head2 refseq_query | ||||||||||||||||||||||||||||||||||||||||||
| 1471 | |||||||||||||||||||||||||||||||||||||||||||
| 1472 | Title : refseq_query | ||||||||||||||||||||||||||||||||||||||||||
| 1473 | Usage : ($query,@args) = $db->refseq_query($name,$class) | ||||||||||||||||||||||||||||||||||||||||||
| 1474 | Function: create SQL fragment that selects the desired reference sequence | ||||||||||||||||||||||||||||||||||||||||||
| 1475 | Returns : a list containing the query and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1476 | Args : reference sequence name and class | ||||||||||||||||||||||||||||||||||||||||||
| 1477 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | |||||||||||||||||||||||||||||||||||||||||||
| 1479 | This method is called by make_features_by_range_where_part() to | ||||||||||||||||||||||||||||||||||||||||||
| 1480 | construct the part of the select WHERE section that selects a | ||||||||||||||||||||||||||||||||||||||||||
| 1481 | particular reference sequence. It returns a mult-element list in | ||||||||||||||||||||||||||||||||||||||||||
| 1482 | which the first element is the SQL fragment and subsequent elements | ||||||||||||||||||||||||||||||||||||||||||
| 1483 | are bind values. | ||||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||
| 1485 | For example: | ||||||||||||||||||||||||||||||||||||||||||
| 1486 | |||||||||||||||||||||||||||||||||||||||||||
| 1487 | sub refseq_query { | ||||||||||||||||||||||||||||||||||||||||||
| 1488 | my ($name,$class) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | return ('gff.refseq=? AND gff.refclass=?', | ||||||||||||||||||||||||||||||||||||||||||
| 1490 | $name,$class); | ||||||||||||||||||||||||||||||||||||||||||
| 1491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||||||||||||||||
| 1493 | The current schema does not distinguish among different classes of | ||||||||||||||||||||||||||||||||||||||||||
| 1494 | reference sequence. | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||||||||||
| 1496 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||
| 1498 | # IMPORTANT NOTE: THE MYSQL SCHEMA IGNORES THE SEQUENCE CLASS | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | # THIS SHOULD BE FIXED | ||||||||||||||||||||||||||||||||||||||||||
| 1500 | 0 | ▶ | sub refseq_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refseq_query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1501 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1502 | 0 | my ($refseq,$refclass) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1503 | 0 | my $query = "fdata.fref=?"; | |||||||||||||||||||||||||||||||||||||||||
| 1504 | 0 | ▶ | return wantarray ? ($query,$refseq) : $self->dbh->dbi_quote($query,$refseq); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||||||||||||||||
| 1507 | =head2 attributes | ||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||
| 1509 | Title : attributes | ||||||||||||||||||||||||||||||||||||||||||
| 1510 | Usage : @attributes = $db->attributes($id,$name) | ||||||||||||||||||||||||||||||||||||||||||
| 1511 | Function: get the attributes on a particular feature | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | Returns : an array of string | ||||||||||||||||||||||||||||||||||||||||||
| 1513 | Args : feature ID | ||||||||||||||||||||||||||||||||||||||||||
| 1514 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||||||||||||||||
| 1516 | Some GFF version 2 files use the groups column to store a series of | ||||||||||||||||||||||||||||||||||||||||||
| 1517 | attribute/value pairs. In this interpretation of GFF, the first such | ||||||||||||||||||||||||||||||||||||||||||
| 1518 | pair is treated as the primary group for the feature; subsequent pairs | ||||||||||||||||||||||||||||||||||||||||||
| 1519 | are treated as attributes. Two attributes have special meaning: | ||||||||||||||||||||||||||||||||||||||||||
| 1520 | "Note" is for backward compatibility and is used for unstructured text | ||||||||||||||||||||||||||||||||||||||||||
| 1521 | remarks. "Alias" is considered as a synonym for the feature name. | ||||||||||||||||||||||||||||||||||||||||||
| 1522 | |||||||||||||||||||||||||||||||||||||||||||
| 1523 | If no name is provided, then attributes() returns a flattened hash, of | ||||||||||||||||||||||||||||||||||||||||||
| 1524 | attribute=E<gt>value pairs. This lets you do: | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||
| 1526 | %attributes = $db->attributes($id); | ||||||||||||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||||||||||
| 1528 | Normally, attributes() will be called by the feature: | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||
| 1530 | @notes = $feature->attributes('Note'); | ||||||||||||||||||||||||||||||||||||||||||
| 1531 | |||||||||||||||||||||||||||||||||||||||||||
| 1532 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1533 | |||||||||||||||||||||||||||||||||||||||||||
| 1534 | 0 | ▶ | sub do_attributes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_attributes: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1535 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1536 | 0 | my ($id,$tag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1537 | 0 | my $sth; | |||||||||||||||||||||||||||||||||||||||||
| 1538 | 0 | ▶ | if ($id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1539 | 0 | my $from = 'fattribute_to_feature,fattribute'; | |||||||||||||||||||||||||||||||||||||||||
| 1540 | 0 | my $join = 'fattribute.fattribute_id=fattribute_to_feature.fattribute_id'; | |||||||||||||||||||||||||||||||||||||||||
| 1541 | 0 | my $where1 = 'fid=? AND fattribute_name=?'; | |||||||||||||||||||||||||||||||||||||||||
| 1542 | 0 | my $where2 = 'fid=?'; | |||||||||||||||||||||||||||||||||||||||||
| 1543 | 0 | ▶ | $sth = defined($tag) ? $self->dbh->do_query("SELECT fattribute_value FROM $from WHERE $where1 AND $join",$id,$tag) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1544 | : $self->dbh->do_query("SELECT fattribute_name,fattribute_value FROM $from WHERE $where2 AND $join",$id); | ||||||||||||||||||||||||||||||||||||||||||
| 1545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | 0 | $sth = $self->dbh->do_query("SELECT fattribute_name FROM fattribute"); | |||||||||||||||||||||||||||||||||||||||||
| 1548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1549 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 1550 | 0 | ▶ | while (my @stuff = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1551 | 0 | push @result,@stuff; | |||||||||||||||||||||||||||||||||||||||||
| 1552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 1554 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||
| 1555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||||||||||||||||
| 1558 | |||||||||||||||||||||||||||||||||||||||||||
| 1559 | =head2 overlap_query_nobin | ||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||
| 1561 | Title : overlap_query | ||||||||||||||||||||||||||||||||||||||||||
| 1562 | Usage : ($query,@args) = $db->overlap_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | Function: create SQL fragment that selects the desired features by range | ||||||||||||||||||||||||||||||||||||||||||
| 1564 | Returns : a list containing the query and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1565 | Args : the start and stop of a range, inclusive | ||||||||||||||||||||||||||||||||||||||||||
| 1566 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||||||||||||||||
| 1568 | This method is called by make_features_byrange_where_part() to construct the | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | part of the select WHERE section that selects a set of features that | ||||||||||||||||||||||||||||||||||||||||||
| 1570 | overlap a range. It returns a multi-element list in which the first | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | element is the SQL fragment and subsequent elements are bind values. | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | |||||||||||||||||||||||||||||||||||||||||||
| 1573 | |||||||||||||||||||||||||||||||||||||||||||
| 1574 | sub overlap_query_nobin { | ||||||||||||||||||||||||||||||||||||||||||
| 1575 | my ($start,$stop) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1576 | return ('gff.stopE<gt>=? AND gff.startE<lt>=?', | ||||||||||||||||||||||||||||||||||||||||||
| 1577 | $start,$stop); | ||||||||||||||||||||||||||||||||||||||||||
| 1578 | |||||||||||||||||||||||||||||||||||||||||||
| 1579 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||||||||||||||||
| 1581 | # find features that overlap a given range | ||||||||||||||||||||||||||||||||||||||||||
| 1582 | 0 | ▶ | sub overlap_query_nobin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
overlap_query_nobin: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1583 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1584 | 0 | my ($start,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1585 | |||||||||||||||||||||||||||||||||||||||||||
| 1586 | 0 | my $query = qq(fdata.fstop>=? AND fdata.fstart<=?); | |||||||||||||||||||||||||||||||||||||||||
| 1587 | 0 | ▶ | return wantarray ? ($query,$start,$stop) : $self->dbh->dbi_quote($query,$start,$stop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1589 | |||||||||||||||||||||||||||||||||||||||||||
| 1590 | =head2 contains_query_nobin | ||||||||||||||||||||||||||||||||||||||||||
| 1591 | |||||||||||||||||||||||||||||||||||||||||||
| 1592 | Title : contains_query | ||||||||||||||||||||||||||||||||||||||||||
| 1593 | Usage : ($query,@args) = $db->contains_query_nobin($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | Function: create SQL fragment that selects the desired features by range | ||||||||||||||||||||||||||||||||||||||||||
| 1595 | Returns : a list containing the query and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1596 | Args : the start and stop of a range, inclusive | ||||||||||||||||||||||||||||||||||||||||||
| 1597 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1598 | |||||||||||||||||||||||||||||||||||||||||||
| 1599 | This method is called by make_features_byrange_where_part() to construct the | ||||||||||||||||||||||||||||||||||||||||||
| 1600 | part of the select WHERE section that selects a set of features | ||||||||||||||||||||||||||||||||||||||||||
| 1601 | entirely enclosed by a range. It returns a multi-element list in which | ||||||||||||||||||||||||||||||||||||||||||
| 1602 | the first element is the SQL fragment and subsequent elements are bind | ||||||||||||||||||||||||||||||||||||||||||
| 1603 | values. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 1604 | |||||||||||||||||||||||||||||||||||||||||||
| 1605 | sub contains_query_nobin { | ||||||||||||||||||||||||||||||||||||||||||
| 1606 | my ($start,$stop) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1607 | return ('gff.start>=? AND gff.stop<=?', | ||||||||||||||||||||||||||||||||||||||||||
| 1608 | $start,$stop); | ||||||||||||||||||||||||||||||||||||||||||
| 1609 | |||||||||||||||||||||||||||||||||||||||||||
| 1610 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1611 | |||||||||||||||||||||||||||||||||||||||||||
| 1612 | # find features that are completely contained within a range | ||||||||||||||||||||||||||||||||||||||||||
| 1613 | 0 | ▶ | sub contains_query_nobin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains_query_nobin: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1614 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1615 | 0 | my ($start,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1616 | 0 | my $query = qq(fdata.fstart>=? AND fdata.fstop<=?); | |||||||||||||||||||||||||||||||||||||||||
| 1617 | 0 | ▶ | return wantarray ? ($query,$start,$stop) : $self->dbh->dbi_quote($query,$start,$stop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | |||||||||||||||||||||||||||||||||||||||||||
| 1620 | =head2 contained_in_query_nobin | ||||||||||||||||||||||||||||||||||||||||||
| 1621 | |||||||||||||||||||||||||||||||||||||||||||
| 1622 | Title : contained_in_query_nobin | ||||||||||||||||||||||||||||||||||||||||||
| 1623 | Usage : ($query,@args) = $db->contained_in_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 1624 | Function: create SQL fragment that selects the desired features by range | ||||||||||||||||||||||||||||||||||||||||||
| 1625 | Returns : a list containing the query and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1626 | Args : the start and stop of a range, inclusive | ||||||||||||||||||||||||||||||||||||||||||
| 1627 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||
| 1629 | This method is called by make_features_byrange_where_part() to construct the | ||||||||||||||||||||||||||||||||||||||||||
| 1630 | part of the select WHERE section that selects a set of features | ||||||||||||||||||||||||||||||||||||||||||
| 1631 | entirely enclosed by a range. It returns a multi-element list in which | ||||||||||||||||||||||||||||||||||||||||||
| 1632 | the first element is the SQL fragment and subsequent elements are bind | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | values.For example: | ||||||||||||||||||||||||||||||||||||||||||
| 1634 | |||||||||||||||||||||||||||||||||||||||||||
| 1635 | sub contained_in_query_nobin { | ||||||||||||||||||||||||||||||||||||||||||
| 1636 | my ($start,$stop) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1637 | return ('gff.start<=? AND gff.stop>=?', | ||||||||||||||||||||||||||||||||||||||||||
| 1638 | $start,$stop); | ||||||||||||||||||||||||||||||||||||||||||
| 1639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1640 | |||||||||||||||||||||||||||||||||||||||||||
| 1641 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1642 | |||||||||||||||||||||||||||||||||||||||||||
| 1643 | # find features that are completely contained within a range | ||||||||||||||||||||||||||||||||||||||||||
| 1644 | 0 | ▶ | sub contained_in_query_nobin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contained_in_query_nobin: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1645 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1646 | 0 | my ($start,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1647 | 0 | my $query = qq(fdata.fstart<=? AND fdata.fstop>=?); | |||||||||||||||||||||||||||||||||||||||||
| 1648 | 0 | ▶ | return wantarray ? ($query,$start,$stop) : $self->dbh->dbi_quote($query,$start,$stop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1649 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1650 | |||||||||||||||||||||||||||||||||||||||||||
| 1651 | =head2 types_query | ||||||||||||||||||||||||||||||||||||||||||
| 1652 | |||||||||||||||||||||||||||||||||||||||||||
| 1653 | Title : types_query | ||||||||||||||||||||||||||||||||||||||||||
| 1654 | Usage : ($query,@args) = $db->types_query($types) | ||||||||||||||||||||||||||||||||||||||||||
| 1655 | Function: create SQL fragment that selects the desired features by type | ||||||||||||||||||||||||||||||||||||||||||
| 1656 | Returns : a list containing the query and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1657 | Args : an array reference containing the types | ||||||||||||||||||||||||||||||||||||||||||
| 1658 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1659 | |||||||||||||||||||||||||||||||||||||||||||
| 1660 | This method is called by make_features_byrange_where_part() to construct the | ||||||||||||||||||||||||||||||||||||||||||
| 1661 | part of the select WHERE section that selects a set of features based | ||||||||||||||||||||||||||||||||||||||||||
| 1662 | on their type. It returns a multi-element list in which the first | ||||||||||||||||||||||||||||||||||||||||||
| 1663 | element is the SQL fragment and subsequent elements are bind values. | ||||||||||||||||||||||||||||||||||||||||||
| 1664 | The argument is an array reference containing zero or more | ||||||||||||||||||||||||||||||||||||||||||
| 1665 | [$method,$source] pairs. | ||||||||||||||||||||||||||||||||||||||||||
| 1666 | |||||||||||||||||||||||||||||||||||||||||||
| 1667 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1668 | |||||||||||||||||||||||||||||||||||||||||||
| 1669 | # generate the fragment of SQL responsible for searching for | ||||||||||||||||||||||||||||||||||||||||||
| 1670 | # features with particular types and methods | ||||||||||||||||||||||||||||||||||||||||||
| 1671 | 0 | ▶ | sub types_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
types_query: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1672 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1673 | 0 | my $types = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1674 | |||||||||||||||||||||||||||||||||||||||||||
| 1675 | 0 | my @method_queries; | |||||||||||||||||||||||||||||||||||||||||
| 1676 | my @args; | ||||||||||||||||||||||||||||||||||||||||||
| 1677 | 0 | for my $type (@$types) { | |||||||||||||||||||||||||||||||||||||||||
| 1678 | 0 | my ($method,$source) = @$type; | |||||||||||||||||||||||||||||||||||||||||
| 1679 | 0 | my ($mlike, $slike) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 1680 | 0 | ▶ | if ($method && $method =~ m/\.\*/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$method and $method =~ /\.\*/
MC/DC0%0/2
$method and $method =~ /\.\*/
$method
$method =~ /\.\*/
Truth table0%0/3
A and B
A= $methodB= $method =~ /\.\*/
| |||||||||||||||||||||||||||||||||||||||||||
| 1681 | 0 | $method =~ s/%/\\%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1682 | 0 | $method =~ s/_/\\_/g; | |||||||||||||||||||||||||||||||||||||||||
| 1683 | 0 | $method =~ s/\.\*\??/%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1684 | 0 | $mlike++; | |||||||||||||||||||||||||||||||||||||||||
| 1685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1686 | 0 | ▶ | if ($source && $source =~ m/\.\*/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$source and $source =~ /\.\*/
MC/DC0%0/2
$source and $source =~ /\.\*/
$source
$source =~ /\.\*/
Truth table0%0/3
A and B
A= $sourceB= $source =~ /\.\*/
| |||||||||||||||||||||||||||||||||||||||||||
| 1687 | 0 | $source =~ s/%/\\%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1688 | 0 | $source =~ s/_/\\_/g; | |||||||||||||||||||||||||||||||||||||||||
| 1689 | 0 | $source =~ s/\.\*\??/%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1690 | 0 | $slike++; | |||||||||||||||||||||||||||||||||||||||||
| 1691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1692 | 0 | my @pair; | |||||||||||||||||||||||||||||||||||||||||
| 1693 | 0 | ▶ | if (defined $method && length $method) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $method and length $method
MC/DC0%0/2
defined $method and length $method
defined $method
length $method
Truth table0%0/3
A and B
A= defined $methodB= length $method
| |||||||||||||||||||||||||||||||||||||||||||
| 1694 | 0 | ▶ | push @pair, $mlike ? qq(fmethod LIKE ?) : qq(fmethod = ?); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1695 | 0 | push @args, $method; | |||||||||||||||||||||||||||||||||||||||||
| 1696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1697 | 0 | ▶ | if (defined $source && length $source) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $source and length $source
MC/DC0%0/2
defined $source and length $source
defined $source
length $source
Truth table0%0/3
A and B
A= defined $sourceB= length $source
| |||||||||||||||||||||||||||||||||||||||||||
| 1698 | 0 | ▶ | push @pair, $slike ? qq(fsource LIKE ?) : qq(fsource = ?); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1699 | 0 | push @args, $source; | |||||||||||||||||||||||||||||||||||||||||
| 1700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1701 | 0 | ▶ | push @method_queries,"(" . join(' AND ',@pair) .")" if @pair; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1702 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1703 | 0 | ▶ | my $query = " (".join(' OR ',@method_queries).")\n" if @method_queries; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1704 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1706 | |||||||||||||||||||||||||||||||||||||||||||
| 1707 | =head2 make_types_select_part | ||||||||||||||||||||||||||||||||||||||||||
| 1708 | |||||||||||||||||||||||||||||||||||||||||||
| 1709 | Title : make_types_select_part | ||||||||||||||||||||||||||||||||||||||||||
| 1710 | Usage : ($string,@args) = $db->make_types_select_part(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 1711 | Function: create the select portion of the SQL for fetching features type list | ||||||||||||||||||||||||||||||||||||||||||
| 1712 | Returns : query string and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1713 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 1714 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1715 | |||||||||||||||||||||||||||||||||||||||||||
| 1716 | This method is called by get_types() to generate the query fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1717 | and bind arguments for the SELECT part of the query that retrieves | ||||||||||||||||||||||||||||||||||||||||||
| 1718 | lists of feature types. The four positional arguments are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 1719 | |||||||||||||||||||||||||||||||||||||||||||
| 1720 | $refseq reference sequence name | ||||||||||||||||||||||||||||||||||||||||||
| 1721 | $start start of region | ||||||||||||||||||||||||||||||||||||||||||
| 1722 | $stop end of region | ||||||||||||||||||||||||||||||||||||||||||
| 1723 | $want_count true to return the count of this feature type | ||||||||||||||||||||||||||||||||||||||||||
| 1724 | |||||||||||||||||||||||||||||||||||||||||||
| 1725 | If $want_count is false, the SQL fragment returned must produce a list | ||||||||||||||||||||||||||||||||||||||||||
| 1726 | of feature types in the format (method, source). | ||||||||||||||||||||||||||||||||||||||||||
| 1727 | |||||||||||||||||||||||||||||||||||||||||||
| 1728 | If $want_count is true, the returned fragment must produce a list of | ||||||||||||||||||||||||||||||||||||||||||
| 1729 | feature types in the format (method, source, count). | ||||||||||||||||||||||||||||||||||||||||||
| 1730 | |||||||||||||||||||||||||||||||||||||||||||
| 1731 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1732 | |||||||||||||||||||||||||||||||||||||||||||
| 1733 | #------------------------- support for the types() query ------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 1734 | 0 | ▶ | sub make_types_select_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_types_select_part: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1735 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1736 | 0 | my ($srcseq,$start,$stop,$want_count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1737 | 0 | ▶ | my $query = $want_count ? 'ftype.fmethod,ftype.fsource,count(fdata.ftypeid)' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1738 | : 'fmethod,fsource'; | ||||||||||||||||||||||||||||||||||||||||||
| 1739 | 0 | return $query; | |||||||||||||||||||||||||||||||||||||||||
| 1740 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1741 | |||||||||||||||||||||||||||||||||||||||||||
| 1742 | =head2 make_types_from_part | ||||||||||||||||||||||||||||||||||||||||||
| 1743 | |||||||||||||||||||||||||||||||||||||||||||
| 1744 | Title : make_types_from_part | ||||||||||||||||||||||||||||||||||||||||||
| 1745 | Usage : ($string,@args) = $db->make_types_from_part(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 1746 | Function: create the FROM portion of the SQL for fetching features type lists | ||||||||||||||||||||||||||||||||||||||||||
| 1747 | Returns : query string and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1748 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 1749 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1750 | |||||||||||||||||||||||||||||||||||||||||||
| 1751 | This method is called by get_types() to generate the query fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1752 | and bind arguments for the FROM part of the query that retrieves lists | ||||||||||||||||||||||||||||||||||||||||||
| 1753 | of feature types. The four positional arguments are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 1754 | |||||||||||||||||||||||||||||||||||||||||||
| 1755 | $refseq reference sequence name | ||||||||||||||||||||||||||||||||||||||||||
| 1756 | $start start of region | ||||||||||||||||||||||||||||||||||||||||||
| 1757 | $stop end of region | ||||||||||||||||||||||||||||||||||||||||||
| 1758 | $want_count true to return the count of this feature type | ||||||||||||||||||||||||||||||||||||||||||
| 1759 | |||||||||||||||||||||||||||||||||||||||||||
| 1760 | If $want_count is false, the SQL fragment returned must produce a list | ||||||||||||||||||||||||||||||||||||||||||
| 1761 | of feature types in the format (method, source). | ||||||||||||||||||||||||||||||||||||||||||
| 1762 | |||||||||||||||||||||||||||||||||||||||||||
| 1763 | If $want_count is true, the returned fragment must produce a list of | ||||||||||||||||||||||||||||||||||||||||||
| 1764 | feature types in the format (method, source, count). | ||||||||||||||||||||||||||||||||||||||||||
| 1765 | |||||||||||||||||||||||||||||||||||||||||||
| 1766 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1767 | |||||||||||||||||||||||||||||||||||||||||||
| 1768 | 0 | ▶ | sub make_types_from_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_types_from_part: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1769 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1770 | 0 | my ($srcseq,$start,$stop,$want_count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1771 | 0 | ▶ | my $query = defined($srcseq) || $want_count ? 'fdata,ftype' : 'ftype'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $srcseq or $want_count
MC/DC0%0/2
defined $srcseq or $want_count
defined $srcseq
$want_count
Truth table0%0/3
A or B
A= defined $srcseqB= $want_count
| |||||||||||||||||||||||||||||||||||||||||||
| 1772 | 0 | return $query; | |||||||||||||||||||||||||||||||||||||||||
| 1773 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1774 | |||||||||||||||||||||||||||||||||||||||||||
| 1775 | =head2 make_types_join_part | ||||||||||||||||||||||||||||||||||||||||||
| 1776 | |||||||||||||||||||||||||||||||||||||||||||
| 1777 | Title : make_types_join_part | ||||||||||||||||||||||||||||||||||||||||||
| 1778 | Usage : ($string,@args) = $db->make_types_join_part(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 1779 | Function: create the JOIN portion of the SQL for fetching features type lists | ||||||||||||||||||||||||||||||||||||||||||
| 1780 | Returns : query string and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1781 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 1782 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1783 | |||||||||||||||||||||||||||||||||||||||||||
| 1784 | This method is called by get_types() to generate the query fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1785 | and bind arguments for the JOIN part of the query that retrieves lists | ||||||||||||||||||||||||||||||||||||||||||
| 1786 | of feature types. The four positional arguments are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 1787 | |||||||||||||||||||||||||||||||||||||||||||
| 1788 | $refseq reference sequence name | ||||||||||||||||||||||||||||||||||||||||||
| 1789 | $start start of region | ||||||||||||||||||||||||||||||||||||||||||
| 1790 | $stop end of region | ||||||||||||||||||||||||||||||||||||||||||
| 1791 | $want_count true to return the count of this feature type | ||||||||||||||||||||||||||||||||||||||||||
| 1792 | |||||||||||||||||||||||||||||||||||||||||||
| 1793 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1794 | |||||||||||||||||||||||||||||||||||||||||||
| 1795 | 0 | ▶ | sub make_types_join_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_types_join_part: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1796 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1797 | 0 | my ($srcseq,$start,$stop,$want_count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1798 | 0 | ▶ | my $query = defined($srcseq) || $want_count ? 'fdata.ftypeid=ftype.ftypeid' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $srcseq or $want_count
MC/DC0%0/2
defined $srcseq or $want_count
defined $srcseq
$want_count
Truth table0%0/3
A or B
A= defined $srcseqB= $want_count
| |||||||||||||||||||||||||||||||||||||||||||
| 1799 | : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 1800 | 0 | ▶ | return $query || '1=1'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$query || '1=1'
MC/DC0%0/1
$query || '1=1'
$query
Truth table0%0/2
A
A= $query
| |||||||||||||||||||||||||||||||||||||||||||
| 1801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1802 | |||||||||||||||||||||||||||||||||||||||||||
| 1803 | =head2 make_types_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1804 | |||||||||||||||||||||||||||||||||||||||||||
| 1805 | Title : make_types_where_part | ||||||||||||||||||||||||||||||||||||||||||
| 1806 | Usage : ($string,@args) = $db->make_types_where_part(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 1807 | Function: create the WHERE portion of the SQL for fetching features type lists | ||||||||||||||||||||||||||||||||||||||||||
| 1808 | Returns : query string and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1809 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 1810 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1811 | |||||||||||||||||||||||||||||||||||||||||||
| 1812 | This method is called by get_types() to generate the query fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1813 | and bind arguments for the WHERE part of the query that retrieves | ||||||||||||||||||||||||||||||||||||||||||
| 1814 | lists of feature types. The four positional arguments are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 1815 | |||||||||||||||||||||||||||||||||||||||||||
| 1816 | $refseq reference sequence name | ||||||||||||||||||||||||||||||||||||||||||
| 1817 | $start start of region | ||||||||||||||||||||||||||||||||||||||||||
| 1818 | $stop end of region | ||||||||||||||||||||||||||||||||||||||||||
| 1819 | $want_count true to return the count of this feature type | ||||||||||||||||||||||||||||||||||||||||||
| 1820 | |||||||||||||||||||||||||||||||||||||||||||
| 1821 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1822 | |||||||||||||||||||||||||||||||||||||||||||
| 1823 | 0 | ▶ | sub make_types_where_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_types_where_part: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1824 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1825 | 0 | my ($srcseq,$start,$stop,$want_count,$typelist) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1826 | 0 | my (@query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 1827 | 0 | ▶ | if (defined($srcseq)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1828 | 0 | push @query,'fdata.fref=?'; | |||||||||||||||||||||||||||||||||||||||||
| 1829 | 0 | push @args,$srcseq; | |||||||||||||||||||||||||||||||||||||||||
| 1830 | 0 | ▶ | if (defined $start or defined $stop) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $start or defined $stop
MC/DC0%0/2
defined $start or defined $stop
defined $start
defined $stop
Truth table0%0/3
A or B
A= defined $startB= defined $stop
| |||||||||||||||||||||||||||||||||||||||||||
| 1831 | 0 | ▶ | $start = 1 unless defined $start; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1832 | 0 | ▶ | $stop = MAX_SEGMENT unless defined $stop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1833 | 0 | my ($q,@a) = $self->overlap_query($start,$stop); | |||||||||||||||||||||||||||||||||||||||||
| 1834 | 0 | push @query,"($q)"; | |||||||||||||||||||||||||||||||||||||||||
| 1835 | 0 | push @args,@a; | |||||||||||||||||||||||||||||||||||||||||
| 1836 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1838 | 0 | ▶ | if (defined $typelist && @$typelist) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $typelist and @$typelist
MC/DC0%0/2
defined $typelist and @$typelist
defined $typelist
@$typelist
Truth table0%0/3
A and B
A= defined $typelistB= @$typelist
| |||||||||||||||||||||||||||||||||||||||||||
| 1839 | 0 | my ($q,@a) = $self->types_query($typelist); | |||||||||||||||||||||||||||||||||||||||||
| 1840 | 0 | push @query,($q); | |||||||||||||||||||||||||||||||||||||||||
| 1841 | 0 | push @args,@a; | |||||||||||||||||||||||||||||||||||||||||
| 1842 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1843 | 0 | ▶ | my $query = @query ? join(' AND ',@query) : '1=1'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1844 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1845 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1846 | |||||||||||||||||||||||||||||||||||||||||||
| 1847 | =head2 make_types_group_part | ||||||||||||||||||||||||||||||||||||||||||
| 1848 | |||||||||||||||||||||||||||||||||||||||||||
| 1849 | Title : make_types_group_part | ||||||||||||||||||||||||||||||||||||||||||
| 1850 | Usage : ($string,@args) = $db->make_types_group_part(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 1851 | Function: create the GROUP BY portion of the SQL for fetching features type lists | ||||||||||||||||||||||||||||||||||||||||||
| 1852 | Returns : query string and bind arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1853 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 1854 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1855 | |||||||||||||||||||||||||||||||||||||||||||
| 1856 | This method is called by get_types() to generate the query fragment | ||||||||||||||||||||||||||||||||||||||||||
| 1857 | and bind arguments for the GROUP BY part of the query that retrieves | ||||||||||||||||||||||||||||||||||||||||||
| 1858 | lists of feature types. The four positional arguments are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 1859 | |||||||||||||||||||||||||||||||||||||||||||
| 1860 | $refseq reference sequence name | ||||||||||||||||||||||||||||||||||||||||||
| 1861 | $start start of region | ||||||||||||||||||||||||||||||||||||||||||
| 1862 | $stop end of region | ||||||||||||||||||||||||||||||||||||||||||
| 1863 | $want_count true to return the count of this feature type | ||||||||||||||||||||||||||||||||||||||||||
| 1864 | |||||||||||||||||||||||||||||||||||||||||||
| 1865 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1866 | |||||||||||||||||||||||||||||||||||||||||||
| 1867 | 0 | ▶ | sub make_types_group_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_types_group_part: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1868 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1869 | 0 | my ($srcseq,$start,$stop,$want_count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1870 | 0 | ▶ | return unless $srcseq or $want_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$srcseq or $want_count
MC/DC0%0/2
$srcseq or $want_count
$srcseq
$want_count
Truth table0%0/3
A or B
A= $srcseqB= $want_count
| |||||||||||||||||||||||||||||||||||||||||||
| 1871 | 0 | return 'ftype.ftypeid,ftype.fmethod,ftype.fsource'; | |||||||||||||||||||||||||||||||||||||||||
| 1872 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1873 | |||||||||||||||||||||||||||||||||||||||||||
| 1874 | |||||||||||||||||||||||||||||||||||||||||||
| 1875 | =head2 get_feature_id | ||||||||||||||||||||||||||||||||||||||||||
| 1876 | |||||||||||||||||||||||||||||||||||||||||||
| 1877 | Title : get_feature_id | ||||||||||||||||||||||||||||||||||||||||||
| 1878 | Usage : $integer = $db->get_feature_id($ref,$start,$stop,$typeid,$groupid) | ||||||||||||||||||||||||||||||||||||||||||
| 1879 | Function: get the ID of a feature | ||||||||||||||||||||||||||||||||||||||||||
| 1880 | Returns : an integer ID or undef | ||||||||||||||||||||||||||||||||||||||||||
| 1881 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 1882 | Status : private | ||||||||||||||||||||||||||||||||||||||||||
| 1883 | |||||||||||||||||||||||||||||||||||||||||||
| 1884 | This internal method is called by load_gff_line to look up the integer | ||||||||||||||||||||||||||||||||||||||||||
| 1885 | ID of an existing feature. It is ony needed when replacing a feature | ||||||||||||||||||||||||||||||||||||||||||
| 1886 | with new information. | ||||||||||||||||||||||||||||||||||||||||||
| 1887 | |||||||||||||||||||||||||||||||||||||||||||
| 1888 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1889 | |||||||||||||||||||||||||||||||||||||||||||
| 1890 | # this method is called when needed to look up a feature's ID | ||||||||||||||||||||||||||||||||||||||||||
| 1891 | 0 | ▶ | sub get_feature_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_feature_id: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1892 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1893 | 0 | my ($ref,$start,$stop,$typeid,$groupid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1894 | 0 | my $s = $self->{load_stuff}; | |||||||||||||||||||||||||||||||||||||||||
| 1895 | 0 | ▶ | unless ($s->{get_feature_id}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1896 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 1897 | $s->{get_feature_id} = | ||||||||||||||||||||||||||||||||||||||||||
| 1898 | 0 | $dbh->prepare_delayed('SELECT fid FROM fdata WHERE fref=? AND fstart=? AND fstop=? AND ftypeid=? AND gid=?'); | |||||||||||||||||||||||||||||||||||||||||
| 1899 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1900 | 0 | ▶ | my $sth = $s->{get_feature_id} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1901 | 0 | ▶ | $sth->execute($ref,$start,$stop,$typeid,$groupid) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1902 | 0 | my ($fid) = $sth->fetchrow_array; | |||||||||||||||||||||||||||||||||||||||||
| 1903 | 0 | return $fid; | |||||||||||||||||||||||||||||||||||||||||
| 1904 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1905 | |||||||||||||||||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||||||||||||||||
| 1907 | |||||||||||||||||||||||||||||||||||||||||||
| 1908 | =head2 make_abscoord_query | ||||||||||||||||||||||||||||||||||||||||||
| 1909 | |||||||||||||||||||||||||||||||||||||||||||
| 1910 | Title : make_abscoord_query | ||||||||||||||||||||||||||||||||||||||||||
| 1911 | Usage : $sth = $db->make_abscoord_query($name,$class); | ||||||||||||||||||||||||||||||||||||||||||
| 1912 | Function: create query that finds the reference sequence coordinates given a landmark & classa | ||||||||||||||||||||||||||||||||||||||||||
| 1913 | Returns : a DBI statement handle | ||||||||||||||||||||||||||||||||||||||||||
| 1914 | Args : name and class of landmark | ||||||||||||||||||||||||||||||||||||||||||
| 1915 | Status : protected | ||||||||||||||||||||||||||||||||||||||||||
| 1916 | |||||||||||||||||||||||||||||||||||||||||||
| 1917 | The statement handler should return rows containing five fields: | ||||||||||||||||||||||||||||||||||||||||||
| 1918 | |||||||||||||||||||||||||||||||||||||||||||
| 1919 | 1. reference sequence name | ||||||||||||||||||||||||||||||||||||||||||
| 1920 | 2. reference sequence class | ||||||||||||||||||||||||||||||||||||||||||
| 1921 | 3. start position | ||||||||||||||||||||||||||||||||||||||||||
| 1922 | 4. stop position | ||||||||||||||||||||||||||||||||||||||||||
| 1923 | 5. strand ("+" or "-") | ||||||||||||||||||||||||||||||||||||||||||
| 1924 | |||||||||||||||||||||||||||||||||||||||||||
| 1925 | This query always returns "Sequence" as the class of the reference | ||||||||||||||||||||||||||||||||||||||||||
| 1926 | sequence. | ||||||||||||||||||||||||||||||||||||||||||
| 1927 | |||||||||||||||||||||||||||||||||||||||||||
| 1928 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1929 | |||||||||||||||||||||||||||||||||||||||||||
| 1930 | # given sequence name, return (reference,start,stop,strand) | ||||||||||||||||||||||||||||||||||||||||||
| 1931 | 0 | ▶ | sub make_abscoord_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_abscoord_query: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1932 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1933 | 0 | my ($name,$class,$refseq) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1934 | #my $query = GETSEQCOORDS; | ||||||||||||||||||||||||||||||||||||||||||
| 1935 | 0 | my $query = $self->getseqcoords_query(); | |||||||||||||||||||||||||||||||||||||||||
| 1936 | 0 | my $getforcedseqcoords = $self->getforcedseqcoords_query() ; | |||||||||||||||||||||||||||||||||||||||||
| 1937 | 0 | ▶ | if ($name =~ /\*/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1938 | 0 | $name =~ s/%/\\%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1939 | 0 | $name =~ s/_/\\_/g; | |||||||||||||||||||||||||||||||||||||||||
| 1940 | 0 | $name =~ tr/*/%/; | |||||||||||||||||||||||||||||||||||||||||
| 1941 | 0 | $query =~ s/gname=\?/gname LIKE ?/; | |||||||||||||||||||||||||||||||||||||||||
| 1942 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1943 | 0 | ▶ | defined $refseq ? $self->dbh->do_query($getforcedseqcoords,$name,$class,$refseq) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1944 | : $self->dbh->do_query($query,$name,$class); | ||||||||||||||||||||||||||||||||||||||||||
| 1945 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||||||||||||||||
| 1947 | 0 | ▶ | sub make_aliasabscoord_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_aliasabscoord_query: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1948 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1949 | 0 | my ($name,$class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1950 | #my $query = GETALIASCOORDS; | ||||||||||||||||||||||||||||||||||||||||||
| 1951 | 0 | my $query = $self->getaliascoords_query(); | |||||||||||||||||||||||||||||||||||||||||
| 1952 | 0 | ▶ | if ($name =~ /\*/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1953 | 0 | $name =~ s/%/\\%/g; | |||||||||||||||||||||||||||||||||||||||||
| 1954 | 0 | $name =~ s/_/\\_/g; | |||||||||||||||||||||||||||||||||||||||||
| 1955 | 0 | $name =~ tr/*/%/; | |||||||||||||||||||||||||||||||||||||||||
| 1956 | 0 | $query =~ s/gname=\?/gname LIKE ?/; | |||||||||||||||||||||||||||||||||||||||||
| 1957 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1958 | 0 | $self->dbh->do_query($query,$name,$class); | |||||||||||||||||||||||||||||||||||||||||
| 1959 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1960 | |||||||||||||||||||||||||||||||||||||||||||
| 1961 | 0 | ▶ | sub getseqcoords_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getseqcoords_query: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1962 | 0 | shift->throw("getseqcoords_query(): must be implemented by a subclass"); | |||||||||||||||||||||||||||||||||||||||||
| 1963 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1964 | |||||||||||||||||||||||||||||||||||||||||||
| 1965 | 0 | ▶ | sub getaliascoords_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getaliascoords_query: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1966 | 0 | shift->throw("getaliascoords_query(): must be implemented by a subclass"); | |||||||||||||||||||||||||||||||||||||||||
| 1967 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1968 | |||||||||||||||||||||||||||||||||||||||||||
| 1969 | 0 | ▶ | sub bin_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bin_query: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1970 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1971 | 0 | my ($start,$stop,$minbin,$maxbin) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1972 | 0 | ▶ | if ($start && $start < 0 && $stop > 0) { # split the queries | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$start and $start < 0 and $stop > 0
$start and $start < 0
MC/DC0%0/3
$start and $start < 0 and $stop > 0
$start
$start < 0
$stop > 0
Truth table0%0/4
A and B and C
A= $startB= $start < 0C= $stop > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1973 | 0 | my ($lower_query,@lower_args) = $self->_bin_query($start,0,$minbin,$maxbin); | |||||||||||||||||||||||||||||||||||||||||
| 1974 | 0 | my ($upper_query,@upper_args) = $self->_bin_query(0,$stop,$minbin,$maxbin); | |||||||||||||||||||||||||||||||||||||||||
| 1975 | 0 | my $query = "$lower_query\n\t OR $upper_query"; | |||||||||||||||||||||||||||||||||||||||||
| 1976 | 0 | my @args = (@lower_args,@upper_args); | |||||||||||||||||||||||||||||||||||||||||
| 1977 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1978 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1979 | 0 | return $self->_bin_query($start,$stop,$minbin,$maxbin); | |||||||||||||||||||||||||||||||||||||||||
| 1980 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1981 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1982 | |||||||||||||||||||||||||||||||||||||||||||
| 1983 | 0 | ▶ | sub _bin_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bin_query: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1984 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1985 | 0 | my ($start,$stop,$minbin,$maxbin) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1986 | 0 | my ($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 1987 | |||||||||||||||||||||||||||||||||||||||||||
| 1988 | 0 | ▶ | $start = 0 unless defined($start); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1989 | 0 | ▶ | $stop = $self->meta('max_bin') unless defined($stop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1990 | |||||||||||||||||||||||||||||||||||||||||||
| 1991 | 0 | my @bins; | |||||||||||||||||||||||||||||||||||||||||
| 1992 | 0 | ▶ | $minbin = defined $minbin ? $minbin : $self->min_bin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1993 | 0 | ▶ | $maxbin = defined $maxbin ? $maxbin : $self->max_bin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1994 | 0 | my $tier = $maxbin; | |||||||||||||||||||||||||||||||||||||||||
| 1995 | 0 | ▶ | while ($tier >= $minbin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1996 | 0 | my ($tier_start,$tier_stop) = (bin_bot($tier,$start)-EPSILON(),bin_top($tier,$stop)+EPSILON()); | |||||||||||||||||||||||||||||||||||||||||
| 1997 | 0 | ▶ | ($tier_start,$tier_stop) = ($tier_stop,$tier_start) if $tier_start > $tier_stop; # can happen when working with negative coordinates | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1998 | 0 | ▶ | if ($tier_start == $tier_stop) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1999 | 0 | push @bins,'fbin=?'; | |||||||||||||||||||||||||||||||||||||||||
| 2000 | 0 | push @args,$tier_start; | |||||||||||||||||||||||||||||||||||||||||
| 2001 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 2002 | 0 | push @bins,'fbin between ? and ?'; | |||||||||||||||||||||||||||||||||||||||||
| 2003 | 0 | push @args,($tier_start,$tier_stop); | |||||||||||||||||||||||||||||||||||||||||
| 2004 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2005 | 0 | $tier /= 10; | |||||||||||||||||||||||||||||||||||||||||
| 2006 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2007 | 0 | $query = join("\n\t OR ",@bins); | |||||||||||||||||||||||||||||||||||||||||
| 2008 | 0 | ▶ | return wantarray ? ($query,@args) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2009 | : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||||
| 2010 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2011 | |||||||||||||||||||||||||||||||||||||||||||
| 2012 | # find features that overlap a given range | ||||||||||||||||||||||||||||||||||||||||||
| 2013 | 0 | ▶ | sub overlap_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
overlap_query: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2014 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2015 | 0 | my ($start,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2016 | |||||||||||||||||||||||||||||||||||||||||||
| 2017 | 0 | my ($query,@args); | |||||||||||||||||||||||||||||||||||||||||
| 2018 | 0 | my ($iq,@iargs) = $self->overlap_query_nobin($start,$stop); | |||||||||||||||||||||||||||||||||||||||||
| 2019 | 0 | if (OPTIMIZE) { | |||||||||||||||||||||||||||||||||||||||||
| 2020 | 0 | my ($bq,@bargs) = $self->bin_query($start,$stop); | |||||||||||||||||||||||||||||||||||||||||
| 2021 | 0 | $query = "($bq)\n\tAND $iq"; | |||||||||||||||||||||||||||||||||||||||||
| 2022 | 0 | @args = (@bargs,@iargs); | |||||||||||||||||||||||||||||||||||||||||
| 2023 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2024 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 2025 | $query = $iq; | ||||||||||||||||||||||||||||||||||||||||||
| 2026 | @args = @iargs; | ||||||||||||||||||||||||||||||||||||||||||
| 2027 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2028 | |||||||||||||||||||||||||||||||||||||||||||
| 2029 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2030 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2031 | |||||||||||||||||||||||||||||||||||||||||||
| 2032 | # find features that are completely contained within a ranged | ||||||||||||||||||||||||||||||||||||||||||
| 2033 | 0 | ▶ | sub contains_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains_query: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2034 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2035 | 0 | my ($start,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2036 | 0 | my ($bq,@bargs) = $self->bin_query($start,$stop,undef,bin($start,$stop,$self->min_bin)); | |||||||||||||||||||||||||||||||||||||||||
| 2037 | 0 | my ($iq,@iargs) = $self->contains_query_nobin($start,$stop); | |||||||||||||||||||||||||||||||||||||||||
| 2038 | 0 | my $query = "($bq)\n\tAND $iq"; | |||||||||||||||||||||||||||||||||||||||||
| 2039 | 0 | my @args = (@bargs,@iargs); | |||||||||||||||||||||||||||||||||||||||||
| 2040 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2041 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2042 | |||||||||||||||||||||||||||||||||||||||||||
| 2043 | # find features that are completely contained within a range | ||||||||||||||||||||||||||||||||||||||||||
| 2044 | 0 | ▶ | sub contained_in_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contained_in_query: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2045 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2046 | 0 | my ($start,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2047 | 0 | my ($bq,@bargs) = $self->bin_query($start,$stop,abs($stop-$start)+1,undef); | |||||||||||||||||||||||||||||||||||||||||
| 2048 | 0 | my ($iq,@iargs) = $self->contained_in_query_nobin($start,$stop); | |||||||||||||||||||||||||||||||||||||||||
| 2049 | 0 | my $query = "($bq)\n\tAND $iq"; | |||||||||||||||||||||||||||||||||||||||||
| 2050 | 0 | my @args = (@bargs,@iargs); | |||||||||||||||||||||||||||||||||||||||||
| 2051 | 0 | ▶ | return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2052 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2053 | |||||||||||||||||||||||||||||||||||||||||||
| 2054 | # implement the _delete_fattribute_to_feature() method | ||||||||||||||||||||||||||||||||||||||||||
| 2055 | 0 | ▶ | sub _delete_fattribute_to_feature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delete_fattribute_to_feature: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 2056 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2057 | 0 | my @feature_ids = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2058 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 2059 | 0 | my $fields = join ',',map{$dbh->quote($_)} @feature_ids; | |||||||||||||||||||||||||||||||||||||||||
| 2060 | |||||||||||||||||||||||||||||||||||||||||||
| 2061 | 0 | my $query = "delete from fattribute_to_feature where fid in ($fields)"; | |||||||||||||||||||||||||||||||||||||||||
| 2062 | 0 | ▶ | warn "$query\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2063 | 0 | my $result = $dbh->do($query); | |||||||||||||||||||||||||||||||||||||||||
| 2064 | 0 | ▶ | defined $result or $self->throw($dbh->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2065 | 0 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 2066 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2067 | |||||||||||||||||||||||||||||||||||||||||||
| 2068 | # implement the _delete_features() method | ||||||||||||||||||||||||||||||||||||||||||
| 2069 | 0 | ▶ | sub _delete_features { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delete_features: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 2070 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2071 | 0 | my @feature_ids = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2072 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 2073 | 0 | my $fields = join ',',map{$dbh->quote($_)} @feature_ids; | |||||||||||||||||||||||||||||||||||||||||
| 2074 | |||||||||||||||||||||||||||||||||||||||||||
| 2075 | # delete from fattribute_to_feature | ||||||||||||||||||||||||||||||||||||||||||
| 2076 | 0 | $self->_delete_fattribute_to_feature(@feature_ids); | |||||||||||||||||||||||||||||||||||||||||
| 2077 | |||||||||||||||||||||||||||||||||||||||||||
| 2078 | 0 | my $query = "delete from fdata where fid in ($fields)"; | |||||||||||||||||||||||||||||||||||||||||
| 2079 | 0 | ▶ | warn "$query\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2080 | 0 | my $result = $dbh->do($query); | |||||||||||||||||||||||||||||||||||||||||
| 2081 | 0 | ▶ | defined $result or $self->throw($dbh->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2082 | 0 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 2083 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2084 | |||||||||||||||||||||||||||||||||||||||||||
| 2085 | # implement the _delete_groups() method | ||||||||||||||||||||||||||||||||||||||||||
| 2086 | 0 | ▶ | sub _delete_groups { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delete_groups: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2087 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2088 | 0 | my @group_ids = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2089 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 2090 | 0 | my $fields = join ',',map{$dbh->quote($_)} @group_ids; | |||||||||||||||||||||||||||||||||||||||||
| 2091 | |||||||||||||||||||||||||||||||||||||||||||
| 2092 | 0 | foreach my $gid (@group_ids){ | |||||||||||||||||||||||||||||||||||||||||
| 2093 | 0 | my @features = $self->get_feature_by_gid($gid); | |||||||||||||||||||||||||||||||||||||||||
| 2094 | 0 | $self->delete_features(@features); | |||||||||||||||||||||||||||||||||||||||||
| 2095 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2096 | |||||||||||||||||||||||||||||||||||||||||||
| 2097 | 0 | my $query = "delete from fgroup where gid in ($fields)"; | |||||||||||||||||||||||||||||||||||||||||
| 2098 | 0 | ▶ | warn "$query\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2099 | 0 | my $result = $dbh->do($query); | |||||||||||||||||||||||||||||||||||||||||
| 2100 | 0 | ▶ | defined $result or $self->throw($dbh->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2101 | 0 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 2102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2103 | |||||||||||||||||||||||||||||||||||||||||||
| 2104 | # implement the _delete() method | ||||||||||||||||||||||||||||||||||||||||||
| 2105 | 0 | ▶ | sub _delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delete: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||
| 2106 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2107 | 0 | my $delete_spec = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2108 | 0 | ▶ | my $ranges = $delete_spec->{segments} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$delete_spec->{'segments'} || []
MC/DC0%0/1
$delete_spec->{'segments'} || []
$delete_spec->{'segments'}
Truth table0%0/2
A
A= $delete_spec->{'segments'}
| |||||||||||||||||||||||||||||||||||||||||||
| 2109 | 0 | ▶ | my $types = $delete_spec->{types} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$delete_spec->{'types'} || []
MC/DC0%0/1
$delete_spec->{'types'} || []
$delete_spec->{'types'}
Truth table0%0/2
A
A= $delete_spec->{'types'}
| |||||||||||||||||||||||||||||||||||||||||||
| 2110 | 0 | my $force = $delete_spec->{force}; | |||||||||||||||||||||||||||||||||||||||||
| 2111 | 0 | my $range_type = $delete_spec->{range_type}; | |||||||||||||||||||||||||||||||||||||||||
| 2112 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 2113 | |||||||||||||||||||||||||||||||||||||||||||
| 2114 | 0 | my $query = 'delete from fdata'; | |||||||||||||||||||||||||||||||||||||||||
| 2115 | 0 | my @where; | |||||||||||||||||||||||||||||||||||||||||
| 2116 | |||||||||||||||||||||||||||||||||||||||||||
| 2117 | my @range_part; | ||||||||||||||||||||||||||||||||||||||||||
| 2118 | 0 | for my $segment (@$ranges) { | |||||||||||||||||||||||||||||||||||||||||
| 2119 | 0 | my $ref = $dbh->quote($segment->abs_ref); | |||||||||||||||||||||||||||||||||||||||||
| 2120 | 0 | my $start = $segment->abs_start; | |||||||||||||||||||||||||||||||||||||||||
| 2121 | 0 | my $stop = $segment->abs_stop; | |||||||||||||||||||||||||||||||||||||||||
| 2122 | 0 | ▶ | my $range = $range_type eq 'overlaps' ? $self->overlap_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 2123 | : $range_type eq 'contains' ? $self->contains_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 2124 | : $range_type eq 'contained_in' ? $self->contained_in_query($start,$stop) | ||||||||||||||||||||||||||||||||||||||||||
| 2125 | : $self->throw("Invalid range type '$range_type'"); | ||||||||||||||||||||||||||||||||||||||||||
| 2126 | 0 | push @range_part,"(fref=$ref AND $range)"; | |||||||||||||||||||||||||||||||||||||||||
| 2127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2128 | 0 | ▶ | push @where,'('. join(' OR ',@range_part).')' if @range_part; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2129 | |||||||||||||||||||||||||||||||||||||||||||
| 2130 | # get all the types | ||||||||||||||||||||||||||||||||||||||||||
| 2131 | 0 | ▶ | if (@$types) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2132 | 0 | my $types_where = $self->types_query($types); | |||||||||||||||||||||||||||||||||||||||||
| 2133 | 0 | my $types_query = "select ftypeid from ftype where $types_where"; | |||||||||||||||||||||||||||||||||||||||||
| 2134 | 0 | my $result = $dbh->selectall_arrayref($types_query); | |||||||||||||||||||||||||||||||||||||||||
| 2135 | 0 | my @typeids = map {$_->[0]} @$result; | |||||||||||||||||||||||||||||||||||||||||
| 2136 | 0 | my $typelist = join ',',map{$dbh->quote($_)} @typeids; | |||||||||||||||||||||||||||||||||||||||||
| 2137 | 0 | ▶ | $typelist ||= "0"; # don't cause DBI to die with invalid SQL when | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$typelist ||= 0
MC/DC0%0/1
$typelist ||= 0
$typelist
Truth table0%0/2
A
A= $typelist
| |||||||||||||||||||||||||||||||||||||||||||
| 2138 | # unknown feature types were requested. | ||||||||||||||||||||||||||||||||||||||||||
| 2139 | 0 | push @where,"(ftypeid in ($typelist))"; | |||||||||||||||||||||||||||||||||||||||||
| 2140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2141 | 0 | ▶ | $self->throw("This operation would delete all feature data and -force not specified") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@where or $force
MC/DC0%0/2
@where or $force
@where
$force
Truth table0%0/3
A or B
A= @whereB= $force
| |||||||||||||||||||||||||||||||||||||||||||
| 2142 | unless @where || $force; | ||||||||||||||||||||||||||||||||||||||||||
| 2143 | 0 | ▶ | $query .= " where ".join(' and ',@where) if @where; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2144 | 0 | ▶ | warn "$query\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2145 | 0 | my $result = $dbh->do($query); | |||||||||||||||||||||||||||||||||||||||||
| 2146 | |||||||||||||||||||||||||||||||||||||||||||
| 2147 | 0 | ▶ | defined $result or $self->throw($dbh->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2148 | 0 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 2149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2150 | |||||||||||||||||||||||||||||||||||||||||||
| 2151 | |||||||||||||||||||||||||||||||||||||||||||
| 2152 | =head2 feature_summary | ||||||||||||||||||||||||||||||||||||||||||
| 2153 | |||||||||||||||||||||||||||||||||||||||||||
| 2154 | Title : feature_summary | ||||||||||||||||||||||||||||||||||||||||||
| 2155 | Usage : $summary = $db->feature_summary(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 2156 | Function: returns a coverage summary across indicated region/type | ||||||||||||||||||||||||||||||||||||||||||
| 2157 | Returns : a Bio::SeqFeatureI object containing the "coverage" tag | ||||||||||||||||||||||||||||||||||||||||||
| 2158 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 2159 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 2160 | |||||||||||||||||||||||||||||||||||||||||||
| 2161 | This method is used to get coverage density information across a | ||||||||||||||||||||||||||||||||||||||||||
| 2162 | region of interest. You provide it with a region of interest, optional | ||||||||||||||||||||||||||||||||||||||||||
| 2163 | a list of feature types, and a count of the number of bins over which | ||||||||||||||||||||||||||||||||||||||||||
| 2164 | you want to calculate the coverage density. An object is returned | ||||||||||||||||||||||||||||||||||||||||||
| 2165 | corresponding to the requested region. It contains a tag called | ||||||||||||||||||||||||||||||||||||||||||
| 2166 | "coverage" that will return an array ref of "bins" length. Each | ||||||||||||||||||||||||||||||||||||||||||
| 2167 | element of the array describes the number of features that overlap the | ||||||||||||||||||||||||||||||||||||||||||
| 2168 | bin at this position. | ||||||||||||||||||||||||||||||||||||||||||
| 2169 | |||||||||||||||||||||||||||||||||||||||||||
| 2170 | Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 2171 | |||||||||||||||||||||||||||||||||||||||||||
| 2172 | Argument Description | ||||||||||||||||||||||||||||||||||||||||||
| 2173 | -------- ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 2174 | |||||||||||||||||||||||||||||||||||||||||||
| 2175 | -seq_id Sequence ID for the region | ||||||||||||||||||||||||||||||||||||||||||
| 2176 | -start Start of region | ||||||||||||||||||||||||||||||||||||||||||
| 2177 | -end End of region | ||||||||||||||||||||||||||||||||||||||||||
| 2178 | -type/-types Feature type of interest or array ref of types | ||||||||||||||||||||||||||||||||||||||||||
| 2179 | -bins Number of bins across region. Defaults to 1000. | ||||||||||||||||||||||||||||||||||||||||||
| 2180 | -iterator Return an iterator across the region | ||||||||||||||||||||||||||||||||||||||||||
| 2181 | |||||||||||||||||||||||||||||||||||||||||||
| 2182 | Note that this method uses an approximate algorithm that is only | ||||||||||||||||||||||||||||||||||||||||||
| 2183 | accurate to 500 bp, so when dealing with bins that are smaller than | ||||||||||||||||||||||||||||||||||||||||||
| 2184 | 1000 bp, you may see some shifting of counts between adjacent bins. | ||||||||||||||||||||||||||||||||||||||||||
| 2185 | |||||||||||||||||||||||||||||||||||||||||||
| 2186 | Although an -iterator option is provided, the method only ever returns | ||||||||||||||||||||||||||||||||||||||||||
| 2187 | a single feature, so this is fairly useless. | ||||||||||||||||||||||||||||||||||||||||||
| 2188 | |||||||||||||||||||||||||||||||||||||||||||
| 2189 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2190 | |||||||||||||||||||||||||||||||||||||||||||
| 2191 | |||||||||||||||||||||||||||||||||||||||||||
| 2192 | 0 | ▶ | sub feature_summary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
feature_summary: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 2193 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2194 | 0 | my ($seq_name,$start,$end,$types,$bins,$iterator) = | |||||||||||||||||||||||||||||||||||||||||
| 2195 | rearrange([['SEQID','SEQ_ID','REF'],'START',['STOP','END'], | ||||||||||||||||||||||||||||||||||||||||||
| 2196 | ['TYPES','TYPE','PRIMARY_TAG'], | ||||||||||||||||||||||||||||||||||||||||||
| 2197 | 'BINS', | ||||||||||||||||||||||||||||||||||||||||||
| 2198 | 'ITERATOR', | ||||||||||||||||||||||||||||||||||||||||||
| 2199 | ],@_); | ||||||||||||||||||||||||||||||||||||||||||
| 2200 | 0 | ▶ | my ($coverage,$tag) = $self->coverage_array(-seqid=> $seq_name, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2201 | -start=> $start, | ||||||||||||||||||||||||||||||||||||||||||
| 2202 | -end => $end, | ||||||||||||||||||||||||||||||||||||||||||
| 2203 | -type => $types, | ||||||||||||||||||||||||||||||||||||||||||
| 2204 | -bins => $bins) or return; | ||||||||||||||||||||||||||||||||||||||||||
| 2205 | 0 | my $score = 0; | |||||||||||||||||||||||||||||||||||||||||
| 2206 | 0 | for (@$coverage) { $score += $_ } | |||||||||||||||||||||||||||||||||||||||||
| 2207 | 0 | $score /= @$coverage; | |||||||||||||||||||||||||||||||||||||||||
| 2208 | |||||||||||||||||||||||||||||||||||||||||||
| 2209 | 0 | my $feature = Bio::SeqFeature::Lite->new(-seq_id => $seq_name, | |||||||||||||||||||||||||||||||||||||||||
| 2210 | -start => $start, | ||||||||||||||||||||||||||||||||||||||||||
| 2211 | -end => $end, | ||||||||||||||||||||||||||||||||||||||||||
| 2212 | -type => $tag, | ||||||||||||||||||||||||||||||||||||||||||
| 2213 | -score => $score, | ||||||||||||||||||||||||||||||||||||||||||
| 2214 | -attributes => | ||||||||||||||||||||||||||||||||||||||||||
| 2215 | { coverage => [$coverage] }); | ||||||||||||||||||||||||||||||||||||||||||
| 2216 | 0 | ▶ | return $iterator | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2217 | ? Bio::DB::GFF::FeatureIterator->new($feature) | ||||||||||||||||||||||||||||||||||||||||||
| 2218 | : $feature; | ||||||||||||||||||||||||||||||||||||||||||
| 2219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2220 | |||||||||||||||||||||||||||||||||||||||||||
| 2221 | =head2 coverage_array | ||||||||||||||||||||||||||||||||||||||||||
| 2222 | |||||||||||||||||||||||||||||||||||||||||||
| 2223 | Title : coverage_array | ||||||||||||||||||||||||||||||||||||||||||
| 2224 | Usage : $arrayref = $db->coverage_array(@args) | ||||||||||||||||||||||||||||||||||||||||||
| 2225 | Function: returns a coverage summary across indicated region/type | ||||||||||||||||||||||||||||||||||||||||||
| 2226 | Returns : an array reference | ||||||||||||||||||||||||||||||||||||||||||
| 2227 | Args : see below | ||||||||||||||||||||||||||||||||||||||||||
| 2228 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 2229 | |||||||||||||||||||||||||||||||||||||||||||
| 2230 | This method is used to get coverage density information across a | ||||||||||||||||||||||||||||||||||||||||||
| 2231 | region of interest. The arguments are identical to feature_summary, | ||||||||||||||||||||||||||||||||||||||||||
| 2232 | except that instead of returning a Bio::SeqFeatureI object, it returns | ||||||||||||||||||||||||||||||||||||||||||
| 2233 | an array reference of the desired number of bins. The value of each | ||||||||||||||||||||||||||||||||||||||||||
| 2234 | element corresponds to the number of features in the bin. | ||||||||||||||||||||||||||||||||||||||||||
| 2235 | |||||||||||||||||||||||||||||||||||||||||||
| 2236 | Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 2237 | |||||||||||||||||||||||||||||||||||||||||||
| 2238 | Argument Description | ||||||||||||||||||||||||||||||||||||||||||
| 2239 | -------- ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 2240 | |||||||||||||||||||||||||||||||||||||||||||
| 2241 | -seq_id Sequence ID for the region | ||||||||||||||||||||||||||||||||||||||||||
| 2242 | -start Start of region | ||||||||||||||||||||||||||||||||||||||||||
| 2243 | -end End of region | ||||||||||||||||||||||||||||||||||||||||||
| 2244 | -type/-types Feature type of interest or array ref of types | ||||||||||||||||||||||||||||||||||||||||||
| 2245 | -bins Number of bins across region. Defaults to 1000. | ||||||||||||||||||||||||||||||||||||||||||
| 2246 | |||||||||||||||||||||||||||||||||||||||||||
| 2247 | Note that this method uses an approximate algorithm that is only | ||||||||||||||||||||||||||||||||||||||||||
| 2248 | accurate to 500 bp, so when dealing with bins that are smaller than | ||||||||||||||||||||||||||||||||||||||||||
| 2249 | 1000 bp, you may see some shifting of counts between adjacent bins. | ||||||||||||||||||||||||||||||||||||||||||
| 2250 | |||||||||||||||||||||||||||||||||||||||||||
| 2251 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2252 | |||||||||||||||||||||||||||||||||||||||||||
| 2253 | 0 | ▶ | sub coverage_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coverage_array: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 2254 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2255 | 0 | my ($seq_name,$start,$end,$types,$bins) = | |||||||||||||||||||||||||||||||||||||||||
| 2256 | rearrange([['SEQID','SEQ_ID','REF'],'START',['STOP','END'], | ||||||||||||||||||||||||||||||||||||||||||
| 2257 | ['TYPES','TYPE','PRIMARY_TAG'],'BINS'],@_); | ||||||||||||||||||||||||||||||||||||||||||
| 2258 | |||||||||||||||||||||||||||||||||||||||||||
| 2259 | 0 | $types = $self->parse_types($types); | |||||||||||||||||||||||||||||||||||||||||
| 2260 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 2261 | |||||||||||||||||||||||||||||||||||||||||||
| 2262 | 0 | ▶ | $bins ||= 1000; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$bins ||= 1000
MC/DC0%0/1
$bins ||= 1000
$bins
Truth table0%0/2
A
A= $bins
| |||||||||||||||||||||||||||||||||||||||||||
| 2263 | 0 | ▶ | $start ||= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$start ||= 1
MC/DC0%0/1
$start ||= 1
$start
Truth table0%0/2
A
A= $start
| |||||||||||||||||||||||||||||||||||||||||||
| 2264 | 0 | ▶ | unless ($end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2265 | 0 | ▶ | my $segment = $self->segment($seq_name) or $self->throw("unknown seq_id $seq_name"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2266 | 0 | $end = $segment->end; | |||||||||||||||||||||||||||||||||||||||||
| 2267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2268 | |||||||||||||||||||||||||||||||||||||||||||
| 2269 | 0 | my $binsize = ($end-$start+1)/$bins; | |||||||||||||||||||||||||||||||||||||||||
| 2270 | 0 | my $seqid = $seq_name; | |||||||||||||||||||||||||||||||||||||||||
| 2271 | |||||||||||||||||||||||||||||||||||||||||||
| 2272 | 0 | ▶ | return [] unless $seqid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2273 | |||||||||||||||||||||||||||||||||||||||||||
| 2274 | # where each bin starts | ||||||||||||||||||||||||||||||||||||||||||
| 2275 | 0 | my @his_bin_array = map {$start + $binsize * $_} (0..$bins); | |||||||||||||||||||||||||||||||||||||||||
| 2276 | 0 | my @sum_bin_array = map {int(($_-1)/SUMMARY_BIN_SIZE)} @his_bin_array; | |||||||||||||||||||||||||||||||||||||||||
| 2277 | |||||||||||||||||||||||||||||||||||||||||||
| 2278 | 0 | my $interval_stats_table = 'finterval_stats'; | |||||||||||||||||||||||||||||||||||||||||
| 2279 | |||||||||||||||||||||||||||||||||||||||||||
| 2280 | # pick up the type ids | ||||||||||||||||||||||||||||||||||||||||||
| 2281 | 0 | my ($type_from,@a) = $self->types_query($types); | |||||||||||||||||||||||||||||||||||||||||
| 2282 | 0 | my $query = "select ftypeid,fmethod,fsource from ftype where $type_from"; | |||||||||||||||||||||||||||||||||||||||||
| 2283 | 0 | my $sth = $dbh->prepare_delayed($query); | |||||||||||||||||||||||||||||||||||||||||
| 2284 | 0 | my (@t,$report_tag); | |||||||||||||||||||||||||||||||||||||||||
| 2285 | 0 | $sth->execute(@a); | |||||||||||||||||||||||||||||||||||||||||
| 2286 | 0 | ▶ | while (my ($t,$method,$source) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2287 | 0 | ▶ | $report_tag ||= "$method:$source"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$report_tag ||= "${method}:$source"
MC/DC0%0/1
$report_tag ||= "${method}:$source"
$report_tag
Truth table0%0/2
A
A= $report_tag
| |||||||||||||||||||||||||||||||||||||||||||
| 2288 | 0 | push @t,$t; | |||||||||||||||||||||||||||||||||||||||||
| 2289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2290 | |||||||||||||||||||||||||||||||||||||||||||
| 2291 | |||||||||||||||||||||||||||||||||||||||||||
| 2292 | 0 | my %bins; | |||||||||||||||||||||||||||||||||||||||||
| 2293 | 0 | my $sql = <<END; | |||||||||||||||||||||||||||||||||||||||||
| 2294 | SELECT fbin,fcum_count | ||||||||||||||||||||||||||||||||||||||||||
| 2295 | FROM $interval_stats_table | ||||||||||||||||||||||||||||||||||||||||||
| 2296 | WHERE ftypeid=? | ||||||||||||||||||||||||||||||||||||||||||
| 2297 | AND fref=? AND fbin >= ? | ||||||||||||||||||||||||||||||||||||||||||
| 2298 | LIMIT 1 | ||||||||||||||||||||||||||||||||||||||||||
| 2299 | END | ||||||||||||||||||||||||||||||||||||||||||
| 2300 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 2301 | 0 | ▶ | $sth = $dbh->prepare_delayed($sql) or warn $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2302 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 2303 | 0 | for my $typeid (@t) { | |||||||||||||||||||||||||||||||||||||||||
| 2304 | |||||||||||||||||||||||||||||||||||||||||||
| 2305 | 0 | ▶ | for (my $i=0;$i<@sum_bin_array;$i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2306 | |||||||||||||||||||||||||||||||||||||||||||
| 2307 | 0 | my @args = ($typeid,$seqid,$sum_bin_array[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 2308 | 0 | ▶ | $self->_print_query($sql,@args) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2309 | |||||||||||||||||||||||||||||||||||||||||||
| 2310 | 0 | ▶ | $sth->execute(@args) or $self->throw($sth->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2311 | 0 | my ($bin,$cum_count) = $sth->fetchrow_array; | |||||||||||||||||||||||||||||||||||||||||
| 2312 | 0 | push @{$bins{$typeid}},[$bin,$cum_count]; | |||||||||||||||||||||||||||||||||||||||||
| 2313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2315 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 2316 | 0 | ▶ | return unless %bins; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2317 | |||||||||||||||||||||||||||||||||||||||||||
| 2318 | 0 | my @merged_bins; | |||||||||||||||||||||||||||||||||||||||||
| 2319 | 0 | my $firstbin = int(($start-1)/$binsize); | |||||||||||||||||||||||||||||||||||||||||
| 2320 | 0 | for my $type (keys %bins) { | |||||||||||||||||||||||||||||||||||||||||
| 2321 | 0 | my $arry = $bins{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 2322 | 0 | my $last_count = $arry->[0][1]; | |||||||||||||||||||||||||||||||||||||||||
| 2323 | 0 | my $last_bin = -1; | |||||||||||||||||||||||||||||||||||||||||
| 2324 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 2325 | 0 | my $delta; | |||||||||||||||||||||||||||||||||||||||||
| 2326 | 0 | for my $b (@$arry) { | |||||||||||||||||||||||||||||||||||||||||
| 2327 | 0 | my ($bin,$count) = @$b; | |||||||||||||||||||||||||||||||||||||||||
| 2328 | 0 | ▶ | $delta = $count - $last_count if $bin > $last_bin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2329 | 0 | $merged_bins[$i++] = $delta; | |||||||||||||||||||||||||||||||||||||||||
| 2330 | 0 | $last_count = $count; | |||||||||||||||||||||||||||||||||||||||||
| 2331 | 0 | $last_bin = $bin; | |||||||||||||||||||||||||||||||||||||||||
| 2332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2334 | |||||||||||||||||||||||||||||||||||||||||||
| 2335 | 0 | ▶ | return wantarray ? (\@merged_bins,$report_tag) : \@merged_bins; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2337 | |||||||||||||||||||||||||||||||||||||||||||
| 2338 | |||||||||||||||||||||||||||||||||||||||||||
| 2339 | =head2 build_summary_statistics | ||||||||||||||||||||||||||||||||||||||||||
| 2340 | |||||||||||||||||||||||||||||||||||||||||||
| 2341 | Title : build_summary_statistics | ||||||||||||||||||||||||||||||||||||||||||
| 2342 | Usage : $db->build_summary_statistics | ||||||||||||||||||||||||||||||||||||||||||
| 2343 | Function: prepares the table needed to call feature_summary() | ||||||||||||||||||||||||||||||||||||||||||
| 2344 | Returns : nothing | ||||||||||||||||||||||||||||||||||||||||||
| 2345 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 2346 | Status : public | ||||||||||||||||||||||||||||||||||||||||||
| 2347 | |||||||||||||||||||||||||||||||||||||||||||
| 2348 | This method is used to build the summary statistics table that is used | ||||||||||||||||||||||||||||||||||||||||||
| 2349 | by the feature_summary() and coverage_array() methods. It needs to be | ||||||||||||||||||||||||||||||||||||||||||
| 2350 | called whenever the database is updated. | ||||||||||||||||||||||||||||||||||||||||||
| 2351 | |||||||||||||||||||||||||||||||||||||||||||
| 2352 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2353 | |||||||||||||||||||||||||||||||||||||||||||
| 2354 | 0 | ▶ | sub build_summary_statistics { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_summary_statistics: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 2355 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2356 | 0 | my $interval_stats_table = 'finterval_stats'; | |||||||||||||||||||||||||||||||||||||||||
| 2357 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 2358 | 0 | $dbh->begin_work; | |||||||||||||||||||||||||||||||||||||||||
| 2359 | |||||||||||||||||||||||||||||||||||||||||||
| 2360 | 0 | my $sbs = SUMMARY_BIN_SIZE; | |||||||||||||||||||||||||||||||||||||||||
| 2361 | |||||||||||||||||||||||||||||||||||||||||||
| 2362 | 0 | my $result = eval { | |||||||||||||||||||||||||||||||||||||||||
| 2363 | 0 | $self->_add_interval_stats_table; | |||||||||||||||||||||||||||||||||||||||||
| 2364 | 0 | $self->disable_keys($interval_stats_table); | |||||||||||||||||||||||||||||||||||||||||
| 2365 | 0 | $dbh->do("DELETE FROM $interval_stats_table"); | |||||||||||||||||||||||||||||||||||||||||
| 2366 | |||||||||||||||||||||||||||||||||||||||||||
| 2367 | 0 | ▶ | my $insert = $dbh->prepare(<<END) or $self->throw($dbh->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2368 | INSERT INTO $interval_stats_table | ||||||||||||||||||||||||||||||||||||||||||
| 2369 | (ftypeid,fref,fbin,fcum_count) | ||||||||||||||||||||||||||||||||||||||||||
| 2370 | VALUES (?,?,?,?) | ||||||||||||||||||||||||||||||||||||||||||
| 2371 | END | ||||||||||||||||||||||||||||||||||||||||||
| 2372 | |||||||||||||||||||||||||||||||||||||||||||
| 2373 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 2374 | |||||||||||||||||||||||||||||||||||||||||||
| 2375 | 0 | my $sql = 'select ftypeid,fref,fstart,fstop from fdata order by ftypeid,fref,fstart'; | |||||||||||||||||||||||||||||||||||||||||
| 2376 | 0 | ▶ | my $select = $dbh->prepare($sql) or $self->throw($dbh->errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2377 | |||||||||||||||||||||||||||||||||||||||||||
| 2378 | 0 | my $current_bin = -1; | |||||||||||||||||||||||||||||||||||||||||
| 2379 | 0 | my ($current_type,$current_seqid,$count); | |||||||||||||||||||||||||||||||||||||||||
| 2380 | 0 | my $cum_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 2381 | 0 | my (%residuals,$last_bin); | |||||||||||||||||||||||||||||||||||||||||
| 2382 | |||||||||||||||||||||||||||||||||||||||||||
| 2383 | 0 | ▶ | my $le = -t \*STDERR ? "\r" : "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2384 | |||||||||||||||||||||||||||||||||||||||||||
| 2385 | 0 | $select->execute; | |||||||||||||||||||||||||||||||||||||||||
| 2386 | |||||||||||||||||||||||||||||||||||||||||||
| 2387 | 0 | ▶ | while (my($typeid,$seqid,$start,$end) = $select->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2388 | 0 | ▶ | print STDERR $count," features processed$le" if ++$count % 1000 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2389 | |||||||||||||||||||||||||||||||||||||||||||
| 2390 | 0 | my $bin = int($start/$sbs); | |||||||||||||||||||||||||||||||||||||||||
| 2391 | 0 | ▶ | $current_type ||= $typeid; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$current_type ||= $typeid
MC/DC0%0/2
$current_type ||= $typeid
$current_type
$typeid
Truth table0%0/3
A ||= B
A= $current_typeB= $typeid
| |||||||||||||||||||||||||||||||||||||||||||
| 2392 | 0 | ▶ | $current_seqid ||= $seqid; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$current_seqid ||= $seqid
MC/DC0%0/2
$current_seqid ||= $seqid
$current_seqid
$seqid
Truth table0%0/3
A ||= B
A= $current_seqidB= $seqid
| |||||||||||||||||||||||||||||||||||||||||||
| 2393 | |||||||||||||||||||||||||||||||||||||||||||
| 2394 | # because the input is sorted by start, no more features will contribute to the | ||||||||||||||||||||||||||||||||||||||||||
| 2395 | # current bin so we can dispose of it | ||||||||||||||||||||||||||||||||||||||||||
| 2396 | 0 | ▶ | if ($bin != $current_bin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2397 | 0 | ▶ | if ($seqid != $current_seqid or $typeid != $current_type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$seqid != $current_seqid or $typeid != $current_type
MC/DC0%0/2
$seqid != $current_seqid or $typeid != $current_type
$seqid != $current_seqid
$typeid != $current_type
Truth table0%0/3
A or B
A= $seqid != $current_seqidB= $typeid != $current_type
| |||||||||||||||||||||||||||||||||||||||||||
| 2398 | # load all bins left over | ||||||||||||||||||||||||||||||||||||||||||
| 2399 | 0 | $self->_load_bins($insert,\%residuals,\$cum_count,$current_type,$current_seqid); | |||||||||||||||||||||||||||||||||||||||||
| 2400 | 0 | %residuals = () ; | |||||||||||||||||||||||||||||||||||||||||
| 2401 | 0 | $cum_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 2402 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 2403 | # load all up to current one | ||||||||||||||||||||||||||||||||||||||||||
| 2404 | 0 | $self->_load_bins($insert,\%residuals,\$cum_count,$current_type,$current_seqid,$current_bin); | |||||||||||||||||||||||||||||||||||||||||
| 2405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2407 | |||||||||||||||||||||||||||||||||||||||||||
| 2408 | 0 | $last_bin = $current_bin; | |||||||||||||||||||||||||||||||||||||||||
| 2409 | 0 | ($current_seqid,$current_type,$current_bin) = ($seqid,$typeid,$bin); | |||||||||||||||||||||||||||||||||||||||||
| 2410 | |||||||||||||||||||||||||||||||||||||||||||
| 2411 | # summarize across entire spanned region | ||||||||||||||||||||||||||||||||||||||||||
| 2412 | 0 | my $last_bin = int(($end-1)/$sbs); | |||||||||||||||||||||||||||||||||||||||||
| 2413 | 0 | ▶ | for (my $b=$bin;$b<=$last_bin;$b++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2414 | 0 | $residuals{$b}++; | |||||||||||||||||||||||||||||||||||||||||
| 2415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2417 | # handle tail case | ||||||||||||||||||||||||||||||||||||||||||
| 2418 | # load all bins left over | ||||||||||||||||||||||||||||||||||||||||||
| 2419 | 0 | $self->_load_bins($insert,\%residuals,\$cum_count,$current_type,$current_seqid); | |||||||||||||||||||||||||||||||||||||||||
| 2420 | 0 | $self->enable_keys($interval_stats_table); | |||||||||||||||||||||||||||||||||||||||||
| 2421 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 2422 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 2423 | |||||||||||||||||||||||||||||||||||||||||||
| 2424 | 0 | ▶ | if ($result) { $dbh->commit } else { warn "Can't build summary statistics: $@"; $dbh->rollback }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2425 | 0 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 2426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2427 | |||||||||||||||||||||||||||||||||||||||||||
| 2428 | 0 | ▶ | sub _load_bins { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_bins: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2429 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2430 | 0 | my ($insert,$residuals,$cum_count,$type,$seqid,$stop_after) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 2431 | 0 | for my $b (sort {$a<=>$b} keys %$residuals) { | |||||||||||||||||||||||||||||||||||||||||
| 2432 | 0 | ▶ | last if defined $stop_after and $b > $stop_after; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $stop_after and $b > $stop_after
MC/DC0%0/2
defined $stop_after and $b > $stop_after
defined $stop_after
$b > $stop_after
Truth table0%0/3
A and B
A= defined $stop_afterB= $b > $stop_after
| |||||||||||||||||||||||||||||||||||||||||||
| 2433 | 0 | $$cum_count += $residuals->{$b}; | |||||||||||||||||||||||||||||||||||||||||
| 2434 | 0 | my @args = ($type,$seqid,$b,$$cum_count); | |||||||||||||||||||||||||||||||||||||||||
| 2435 | 0 | ▶ | $insert->execute(@args) or warn $insert->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2436 | 0 | delete $residuals->{$b}; # no longer needed | |||||||||||||||||||||||||||||||||||||||||
| 2437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2439 | |||||||||||||||||||||||||||||||||||||||||||
| 2440 | 0 | ▶ | sub _add_interval_stats_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_interval_stats_table: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 2441 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 2442 | 0 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||||||||
| 2443 | 0 | my $create_table_stmt = $schema->{'finterval_stats'}{'table'}; | |||||||||||||||||||||||||||||||||||||||||
| 2444 | 0 | my $dbh = $self->features_db; | |||||||||||||||||||||||||||||||||||||||||
| 2445 | 0 | $dbh->do("drop table finterval_stats"); | |||||||||||||||||||||||||||||||||||||||||
| 2446 | 0 | ▶ | $dbh->do($create_table_stmt) || warn $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2448 | |||||||||||||||||||||||||||||||||||||||||||
| 2449 | 0 | ▶ | sub disable_keys { } # noop | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_keys: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2450 | 0 | ▶ | sub enable_keys { } # noop | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_keys: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2451 | |||||||||||||||||||||||||||||||||||||||||||
| 2452 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 2453 | |||||||||||||||||||||||||||||||||||||||||||
| 2454 | __END__ | ||||||||||||||||||||||||||||||||||||||||||