GFF/Adaptor/dbi/pg.pm

filter: Statementstmt 10.7% 44 / 411 Branchbran 0.0% 0 / 148 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 46 Subroutinesub 28.5% 14 / 49 Podpod 51.5% 17 / 33 totaltotal 9.7% 75 / 766 CC 108 SCAR 46.9
CC
108
Cov
7%
load_gff_line
342.0
_delete
240.0
get_dna
182.0
CRAP 108.9
« GFF/Aggregator/alignment.pm ↑ Summary GFF/Adaptor/dbi.pm »
1 package Bio::DB::GFF::Adaptor::dbi::pg;
2 2 $Bio::DB::GFF::Adaptor::dbi::pg::VERSION = '1.7.4';
3 =head1 NAME
4  
5 Bio::DB::GFF::Adaptor::dbi::pg -- Database adaptor for a specific postgres schema
6  
7 =head1 NOTES
8  
9 SQL commands that need to be executed before this adaptor will work:
10  
11 CREATE DATABASE <dbname>;
12  
13 Also, select permission needs to be granted for each table in the
14 database to the owner of the httpd process (usually 'nobody', but
15 for some RedHat systems it is 'apache') if this adaptor is to be used
16 with the Generic Genome Browser (gbrowse):
17  
18 CREATE USER nobody;
19 GRANT SELECT ON TABLE fmeta TO nobody;
20 GRANT SELECT ON TABLE fgroup TO nobody;
21 GRANT SELECT ON TABLE fdata TO nobody;
22 GRANT SELECT ON TABLE fattribute_to_feature TO nobody;
23 GRANT SELECT ON TABLE fdna TO nobody;
24 GRANT SELECT ON TABLE fattribute TO nobody;
25 GRANT SELECT ON TABLE ftype TO nobody;
26  
27 =head2 Optimizing the database
28  
29 PostgreSQL generally requires some tuning before you get very good
30 performance for large databases. For general information on tuning
31 a PostgreSQL server, see http://www.varlena.com/GeneralBits/Tidbits/perf.html
32 Of particular importance is executing VACUUM FULL ANALYZE whenever
33 you change the database.
34  
35 Additionally, for a GFF database, there are a few items you can tune.
36 For each automatic class in your GBrowse conf file, there will be one
37 or two searches done when searching for a feature. If there are lots
38 of features, these search can take several seconds. To speed these searches,
39 do two things:
40  
41 =over
42  
43 =item 1
44  
45 Set 'enable_seqscan = false' in your postgresql.conf file (and restart
46 your server).
47  
48 =item 2
49  
50 Create 'partial' indexes for each automatic class, doing this for the
51 example class 'Allele':
52  
53 CREATE INDEX partial_allele_gclass ON
54 fgroup (lower('gname')) WHERE gclass='Allele';
55  
56 And be sure to run VACUUM FULL ANALYZE after creating the indexes.
57  
58 =back
59  
60 =cut
61  
62 # a simple postgres adaptor
63 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 2 ▶use Bio::DB::GFF::Util::Binning;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 2 ▶use Bio::DB::GFF::Util::Rearrange; # for rearrange()
Subroutine BEGIN: called CC=1 SCAR=0.0
66 2 ▶use base qw(Bio::DB::GFF::Adaptor::dbi);
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 2 ▶use constant MAX_SEGMENT => 100_000_000; # the largest a segment can get
Subroutine BEGIN: called CC=1 SCAR=0.0
69 2 ▶use constant DEFAULT_CHUNK => 2000;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 2 ▶use constant GETSEQCOORDS =><<END;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 SELECT fref,
73 COALESCE(gclass,'Sequence'),
74 min(fstart),
75 max(fstop),
76 fstrand,
77 gname
78 FROM fdata,fgroup
79 WHERE lower(fgroup.gname) = lower(?)
80 AND fgroup.gclass=?
81 AND fgroup.gid=fdata.gid
82 GROUP BY fref,fstrand,gclass,gname
83 END
84 ;
85  
86 2 ▶use constant GETALIASCOORDS =><<END;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 SELECT fref,
88 COALESCE(gclass,'Sequence'),
89 min(fstart),
90 max(fstop),
91 fstrand,
92 gname
93 FROM fdata,fgroup,fattribute,fattribute_to_feature
94 WHERE lower(fattribute_to_feature.fattribute_value)=lower(?)
95 AND fgroup.gclass=?
96 AND fgroup.gid=fdata.gid
97 AND fattribute.fattribute_name='Alias'
98 AND fattribute_to_feature.fattribute_id=fattribute.fattribute_id
99 AND fattribute_to_feature.fid=fdata.fid
100 GROUP BY fref,fstrand,gclass,gname
101 END
102 ;
103  
104 2 ▶use constant GETALIASLIKE =><<END;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 SELECT fref,
106 COALESCE(gclass,'Sequence'),
107 min(fstart),
108 max(fstop),
109 fstrand,
110 gname
111 FROM fdata,fgroup,fattribute,fattribute_to_feature
112 WHERE lower(fattribute_to_feature.fattribute_value) LIKE lower(?)
113 AND fgroup.gclass=?
114 AND fgroup.gid=fdata.gid
115 AND fattribute.fattribute_name='Alias'
116 AND fattribute_to_feature.fattribute_id=fattribute.fattribute_id
117 AND fattribute_to_feature.fid=fdata.fid
118 GROUP BY fref,fstrand,gname
119 END
120 ;
121  
122  
123 2 ▶use constant GETFORCEDSEQCOORDS =><<END;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 SELECT fref,
125 COALESCE(gclass,'Sequence'),
126 min(fstart),
127 max(fstop),
128 fstrand
129 FROM fdata,fgroup
130 WHERE lower(fgroup.gname) = lower(?)
131 AND fgroup.gclass=?
132 AND lower(fdata.fref) = lower(?)
133 AND fgroup.gid=fdata.gid
134 GROUP BY fref,fstrand,gclass
135 END
136 ;
137  
138 2 ▶use constant FULLTEXTWILDCARD => <<END;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 SELECT distinct gclass,gname,fattribute_value
140 FROM fgroup,fattribute_to_feature,fdata
141 WHERE fgroup.gid=fdata.gid
142 AND fdata.fid=fattribute_to_feature.fid
143 AND lower(fattribute_to_feature.fattribute_value) LIKE lower(?)
144 END
145 ;
146  
147 ########################
148 # moved from mysqlopt.pm
149 ########################
150  
151 # this is the largest that any reference sequence can be (100 megabases)
152 2 ▶use constant MAX_BIN => 100_000_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
153  
154 # this is the smallest bin (1 K)
155 2 ▶use constant MIN_BIN => 1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
156  
157 # size of range over which it is faster to force mysql to use the range for indexing
158 2 ▶use constant STRAIGHT_JOIN_LIMIT => 200_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 ##############################################################################
161  
162 =head1 DESCRIPTION
163  
164 This adaptor implements a specific postgres database schema that is
165 compatible with Bio::DB::GFF. It inherits from
166 Bio::DB::GFF::Adaptor::dbi, which itself inherits from Bio::DB::GFF.
167  
168 The schema uses several tables:
169  
170 =over 4
171  
172 =item fdata
173  
174 This is the feature data table. Its columns are:
175  
176 fid feature ID (integer)
177 fref reference sequence name (string)
178 fstart start position relative to reference (integer)
179 fstop stop position relative to reference (integer)
180 ftypeid feature type ID (integer)
181 fscore feature score (float); may be null
182 fstrand strand; one of "+" or "-"; may be null
183 fphase phase; one of 0, 1 or 2; may be null
184 gid group ID (integer)
185 ftarget_start for similarity features, the target start position (integer)
186 ftarget_stop for similarity features, the target stop position (integer)
187  
188 Note that it would be desirable to normalize the reference sequence
189 name, since there are usually many features that share the same
190 reference feature. However, in the current schema, query performance
191 suffers dramatically when this additional join is added.
192  
193 =item fgroup
194  
195 This is the group table. There is one row for each group. Columns:
196  
197 gid the group ID (integer)
198 gclass the class of the group (string)
199 gname the name of the group (string)
200  
201 The group table serves multiple purposes. As you might expect, it is
202 used to cluster features that logically belong together, such as the
203 multiple exons of the same transcript. It is also used to assign a
204 name and class to a singleton feature. Finally, the group table is
205 used to identify the target of a similarity hit. This is consistent
206 with the way in which the group field is used in the GFF version 2
207 format.
208  
209 The fgroup.gid field joins with the fdata.gid field.
210  
211 Examples:
212  
213 sql> select * from fgroup where gname='sjj_2L52.1';
214 +-------+-------------+------------+
215 | gid | gclass | gname |
216 +-------+-------------+------------+
217 | 69736 | PCR_product | sjj_2L52.1 |
218 +-------+-------------+------------+
219 1 row in set (0.70 sec)
220  
221 sql> select fref,fstart,fstop from fdata,fgroup
222 where gclass='PCR_product' and gname = 'sjj_2L52.1'
223 and fdata.gid=fgroup.gid;
224 +---------------+--------+-------+
225 | fref | fstart | fstop |
226 +---------------+--------+-------+
227 | CHROMOSOME_II | 1586 | 2355 |
228 +---------------+--------+-------+
229 1 row in set (0.03 sec)
230  
231 =item ftype
232  
233 This table contains the feature types, one per row. Columns are:
234  
235 ftypeid the feature type ID (integer)
236 fmethod the feature type method name (string)
237 fsource the feature type source name (string)
238  
239 The ftype.ftypeid field joins with the fdata.ftypeid field. Example:
240  
241 sql> select fref,fstart,fstop,fmethod,fsource from fdata,fgroup,ftype
242 where gclass='PCR_product'
243 and gname = 'sjj_2L52.1'
244 and fdata.gid=fgroup.gid
245 and fdata.ftypeid=ftype.ftypeid;
246 +---------------+--------+-------+-------------+-----------+
247 | fref | fstart | fstop | fmethod | fsource |
248 +---------------+--------+-------+-------------+-----------+
249 | CHROMOSOME_II | 1586 | 2355 | PCR_product | GenePairs |
250 +---------------+--------+-------+-------------+-----------+
251 1 row in set (0.08 sec)
252  
253 =item fdna
254  
255 This table holds the raw DNA of the reference sequences. It has three
256 columns:
257  
258 fref reference sequence name (string)
259 foffset offset of this sequence
260 fdna the DNA sequence (longblob)
261  
262 To overcome problems loading large blobs, DNA is automatically
263 fragmented into multiple segments when loading, and the position of
264 each segment is stored in foffset. The fragment size is controlled by
265 the -clump_size argument during initialization.
266  
267 =item fattribute_to_feature
268  
269 This table holds "attributes", which are tag/value pairs stuffed into
270 the GFF line. The first tag/value pair is treated as the group, and
271 anything else is treated as an attribute (weird, huh?).
272  
273 CHR_I assembly_tag Finished 2032 2036 . + . Note "Right: cTel33B"
274 CHR_I assembly_tag Polymorphism 668 668 . + . Note "A->C in cTel33B"
275  
276 The columns of this table are:
277  
278 fid feature ID (integer)
279 fattribute_id ID of the attribute (integer)
280 fattribute_value text of the attribute (text)
281  
282 The fdata.fid column joins with fattribute_to_feature.fid.
283  
284 =item fattribute
285  
286 This table holds the normalized names of the attributes. Fields are:
287  
288 fattribute_id ID of the attribute (integer)
289 fattribute_name Name of the attribute (varchar)
290  
291 =back
292  
293 =head2 Data Loading Methods
294  
295 In addition to implementing the abstract SQL-generating methods of
296 Bio::DB::GFF::Adaptor::dbi, this module also implements the data
297 loading functionality of Bio::DB::GFF.
298  
299 =cut
300  
301  
302 =head2 new
303  
304 Title : new
305 Usage : $db = Bio::DB::GFF->new(@args)
306 Function: create a new adaptor
307 Returns : a Bio::DB::GFF object
308 Args : see below
309 Status : Public
310  
311 The new constructor is identical to the "dbi" adaptor's new() method,
312 except that the prefix "dbi:pg" is added to the database DSN identifier
313 automatically if it is not there already.
314  
315 Argument Description
316 -------- -----------
317  
318 -dsn the DBI data source, e.g. 'dbi:Pg:dbname=:ens0040' or "ens0040"
319  
320 -user username for authentication
321  
322 -pass the password for authentication
323  
324 =cut
325  
326 #'
327  
328 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
329 0 my $class = shift;
330 0 my ($dsn,$other) = rearrange([
331 [qw(FEATUREDB DB DSN)],
332 ],@_);
333 0 ▶ $dsn = "dbi:Pg:dbname=$dsn" if !ref($dsn) && $dsn !~ /^(dbi|DBI):/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dsn or $dsn =~ /^(dbi|DBI):/ 0 0 0
Condition0%0/3
ref $dsn or $dsn =~ /^(dbi|DBI):/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $dsn or $dsn =~ /^(dbi|DBI):/
ref $dsn $dsn =~ /^(dbi|DBI):/
Truth table0%0/3
A or B
A= ref $dsnB= $dsn =~ /^(dbi|DBI):/
ABresult
1X1
011
000
334 0 my $self = $class->SUPER::new(-dsn=>$dsn,%$other);
335 0 $self;
336 }
337  
338 =head2 schema
339  
340 Title : schema
341 Usage : $schema = $db->schema
342 Function: return the CREATE script for the schema
343 Returns : a list of CREATE statemetns
344 Args : none
345 Status : protected
346  
347 This method returns a list containing the various CREATE statements
348 needed to initialize the database tables.
349  
350 =cut
351  
352 0 ▶sub schema {
Subroutine schema: not called CC=1 SCAR=6.9
Pod documented
353 0 my %schema = (
354 fdata =>{
355 table=> q{
356 CREATE TABLE "fdata" (
357 "fid" serial NOT NULL,
358 "fref" character varying(100) DEFAULT '' NOT NULL,
359 "fstart" integer DEFAULT '0' NOT NULL,
360 "fstop" integer DEFAULT '0' NOT NULL,
361 "fbin" double precision DEFAULT '0.000000' NOT NULL,
362 "ftypeid" integer DEFAULT '0' NOT NULL,
363 "fscore" double precision DEFAULT NULL,
364 "fstrand" character varying(3) DEFAULT NULL,
365 "fphase" character varying(3) DEFAULT NULL,
366 "gid" integer DEFAULT '0' NOT NULL,
367 "ftarget_start" integer DEFAULT NULL,
368 "ftarget_stop" integer DEFAULT NULL,
369 CONSTRAINT chk_fdata_fstrand CHECK (fstrand IN ('+','-')),
370 CONSTRAINT chk_fdata_fphase CHECK (fphase IN ('0','1','2')),
371 CONSTRAINT pk_fdata PRIMARY KEY (fid)
372 )
373 }, # fdata table
374  
375 #CONSTRAINT fref_fdata UNIQUE (fref, fbin, fstart, fstop, ftypeid, gid)
376 # fdata_fref_idx => q{ CREATE UNIQUE INDEX fdata_fref_idx ON fdata (fref,fbin,fstart,fstop,ftypeid,gid)},
377  
378 index=>{
379 fdata_fref_idx => q{
380 CREATE INDEX fdata_fref_idx ON fdata (fref,fbin,fstart,fstop,ftypeid,gid)
381 },
382  
383 fdata_ftypeid_idx => q{
384 CREATE INDEX fdata_ftypeid_idx ON fdata (ftypeid)
385 },
386  
387 fdata_gid_idx => q{
388 CREATE INDEX fdata_gid_idx ON fdata (gid)
389 }
390 }, # fdata indexes
391  
392 }, # fdata
393  
394  
395  
396 fgroup => {
397 table => q{
398 CREATE TABLE "fgroup" (
399 "gid" serial NOT NULL,
400 "gclass" character varying(100) DEFAULT NULL,
401 "gname" character varying(100) DEFAULT NULL,
402 CONSTRAINT pk_fgroup PRIMARY KEY (gid)
403 )
404 }, # fgroup table
405  
406 index => {
407 fgroup_gclass_idx => q{
408 CREATE UNIQUE INDEX fgroup_gclass_idx ON fgroup (gclass,gname)
409 },
410 fgroup_gname_idx => q{
411 CREATE INDEX fgroup_gname_idx ON fgroup(gname)
412 },
413 fgroup_lower_gname_idx => q{
414 CREATE INDEX fgroup_lower_gname_idx ON fgroup (lower(gname))
415 },
416 }, # fgroup indexes
417  
418 }, # fgroup
419  
420 ftype => {
421 table => q{
422 CREATE TABLE "ftype" (
423 "ftypeid" serial NOT NULL,
424 "fmethod" character varying(100) DEFAULT '' NOT NULL,
425 "fsource" character varying(100) DEFAULT NULL,
426 CONSTRAINT pk_ftype PRIMARY KEY (ftypeid),
427 CONSTRAINT ftype_ftype UNIQUE (fmethod, fsource)
428 )
429 }, # ftype table
430  
431 index => {
432 ftype_fmethod_idx => q{
433 CREATE INDEX ftype_fmethod_idx ON ftype (fmethod)
434 },
435  
436 ftype_fsource_idx => q{
437 CREATE INDEX ftype_fsource_idx ON ftype (fsource)
438 },
439
440 ftype_ftype_idx => q{
441 CREATE UNIQUE INDEX ftype_ftype_idx ON ftype (fmethod,fsource)
442 }
443 }, # ftype indexes
444  
445 }, # ftype
446  
447  
448 fdna => {
449 table => q{
450 CREATE TABLE "fdna" (
451 "fref" character varying(100) DEFAULT '' NOT NULL,
452 "foffset" integer DEFAULT '0' NOT NULL,
453 "fdna" bytea,
454 CONSTRAINT pk_fdna PRIMARY KEY (fref, foffset)
455 )
456 } #fdna table
457 }, #fdna
458  
459 fmeta => {
460 table => q{
461 CREATE TABLE "fmeta" (
462 "fname" character varying(255) DEFAULT '' NOT NULL,
463 "fvalue" character varying(255) DEFAULT '' NOT NULL,
464 CONSTRAINT pk_fmeta PRIMARY KEY (fname)
465 )
466 } # fmeta table
467 }, # fmeta
468  
469  
470 fattribute => {
471 table => q{
472 CREATE TABLE "fattribute" (
473 "fattribute_id" serial NOT NULL,
474 "fattribute_name" character varying(255) DEFAULT '' NOT NULL,
475 CONSTRAINT pk_fattribute PRIMARY KEY (fattribute_id)
476 )
477 }, # fattribute table
478  
479 }, # fattribute
480  
481 fattribute_to_feature => {
482 table => q{
483 CREATE TABLE "fattribute_to_feature" (
484 "fid" integer DEFAULT '0' NOT NULL,
485 "fattribute_id" integer DEFAULT '0' NOT NULL,
486 "fattribute_value" text
487 )
488 }, # fattribute_to_feature table
489  
490 index => {
491 fattribute_to_feature_fid => q{
492 CREATE INDEX fattribute_to_feature_fid ON fattribute_to_feature (fid,fattribute_id)
493 },
494 fattribute_txt_idx => q{
495 CREATE INDEX fattribute_txt_idx ON fattribute_to_feature (fattribute_value)
496 },
497 fattribute_lower_idx => q{
498 CREATE INDEX fattribute_lower_idx ON fattribute_to_feature (lower(fattribute_value))
499 },
500 } # fattribute_to_feature indexes
501 }, # fattribute_to_feature
502  
503 finterval_stats => {
504 table=> q{
505 CREATE TABLE "finterval_stats" (
506 "ftypeid" integer DEFAULT '0' NOT NULL,
507 "fref" character varying(100) DEFAULT '' NOT NULL,
508 "fbin" integer DEFAULT '0' NOT NULL,
509 "fcum_count" integer DEFAULT '0' NOT NULL,
510 CONSTRAINT pk_finterval_stats PRIMARY KEY (ftypeid,fref,fbin)
511 )
512 } # finterval_stats table
513 },# finterval_stats
514  
515  
516  
517  
518 );
519 0 return \%schema;
520 }
521  
522  
523 =head2 setup_load
524  
525 Title : setup_load
526 Usage : $db->setup_load
527 Function: called before load_gff_line()
528 Returns : void
529 Args : none
530 Status : protected
531  
532 This method performs schema-specific initialization prior to loading a
533 set of GFF records. It prepares a set of DBI statement handlers to be
534 used in loading the data.
535  
536 =cut
537  
538 0 ▶sub setup_load {
Subroutine setup_load: not called CC=2 SCAR=17.9
Pod documented
539 0 my $self = shift;
540 0 my $schema = $self->schema;
541  
542 0 my $dbh = $self->features_db;
543  
544 0 ▶ if ($self->lock_on_load) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lock_on_load) 0 0 0
545 0 my @tables = map { "$_ WRITE"} $self->tables;
546 0 my $tables = join ', ',@tables;
547 0 $dbh->do("LOCK TABLES $tables");
548 }
549  
550 0 my $lookup_type = $dbh->prepare_delayed('SELECT ftypeid FROM ftype WHERE fmethod=? AND fsource=?');
551 0 my $insert_type = $dbh->prepare_delayed('INSERT INTO ftype (fmethod,fsource) VALUES (?,?)');
552 0 my $insertid_type = $dbh->prepare_delayed("SELECT currval('ftype_ftypeid_seq')");
553  
554 0 my $lookup_group = $dbh->prepare_delayed('SELECT gid FROM fgroup WHERE lower(gname)=lower(?) AND gclass=?');
555 0 my $insert_group = $dbh->prepare_delayed('INSERT INTO fgroup (gname,gclass) VALUES (?,?)');
556 0 my $insertid_group = $dbh->prepare_delayed("SELECT currval('fgroup_gid_seq')");
557  
558 0 my $lookup_attribute = $dbh->prepare_delayed('SELECT fattribute_id FROM fattribute WHERE fattribute_name=?');
559 0 my $insert_attribute = $dbh->prepare_delayed('INSERT INTO fattribute (fattribute_name) VALUES (?)');
560 0 my $insertid_attribute = $dbh->prepare_delayed("SELECT currval('fattribute_fattribute_id_seq')");
561  
562 0 my $insert_attribute_value = $dbh->prepare_delayed('INSERT INTO fattribute_to_feature (fid,fattribute_id,fattribute_value) VALUES (?,?,?)');
563  
564 0 my $insert_data = $dbh->prepare_delayed(<<END);
565 INSERT INTO fdata (fref,fstart,fstop,fbin,ftypeid,fscore,
566 fstrand,fphase,gid,ftarget_start,ftarget_stop)
567 VALUES(?,?,?,?,?,?,?,?,?,?,?)
568 END
569 ;
570 0 my $delete_existing_data = $dbh->prepare_delayed('DELETE FROM fdata WHERE fref=? AND fstart=? AND fstop=? AND fbin=? AND ftypeid=? AND GID=?');
571 0 my $insertid_data = $dbh->prepare_delayed("SELECT currval('fdata_fid_seq')");
572  
573 0 $self->{load_stuff}{sth}{lookup_ftype} = $lookup_type;
574 0 $self->{load_stuff}{sth}{insert_ftype} = $insert_type;
575 0 $self->{load_stuff}{sth}{insertid_ftype} = $insertid_type;
576 0 $self->{load_stuff}{sth}{lookup_fgroup} = $lookup_group;
577 0 $self->{load_stuff}{sth}{insert_fgroup} = $insert_group;
578 0 $self->{load_stuff}{sth}{insertid_fgroup} = $insertid_group;
579 0 $self->{load_stuff}{sth}{insertid_fdata} = $insertid_data;
580 0 $self->{load_stuff}{sth}{insert_fdata} = $insert_data;
581 0 $self->{load_stuff}{sth}{delete_existing_fdata} = $delete_existing_data;
582 0 $self->{load_stuff}{sth}{lookup_fattribute} = $lookup_attribute;
583 0 $self->{load_stuff}{sth}{insert_fattribute} = $insert_attribute;
584 0 $self->{load_stuff}{sth}{insertid_fattribute} = $insertid_attribute;
585 0 $self->{load_stuff}{sth}{insert_fattribute_value} = $insert_attribute_value;
586 0 $self->{load_stuff}{types} = {};
587 0 $self->{load_stuff}{groups} = {};
588 0 $self->{load_stuff}{counter} = 0;
589 }
590  
591 =head2 load_gff_line
592  
593 Title : load_gff_line
594 Usage : $db->load_gff_line($fields)
595 Function: called to load one parsed line of GFF
596 Returns : true if successfully inserted
597 Args : hashref containing GFF fields
598 Status : protected
599  
600 This method is called once per line of the GFF and passed a series of
601 parsed data items that are stored into the hashref $fields. The keys are:
602  
603 ref reference sequence
604 source annotation source
605 method annotation method
606 start annotation start
607 stop annotation stop
608 score annotation score (may be undef)
609 strand annotation strand (may be undef)
610 phase annotation phase (may be undef)
611 group_class class of annotation's group (may be undef)
612 group_name ID of annotation's group (may be undef)
613 target_start start of target of a similarity hit
614 target_stop stop of target of a similarity hit
615 attributes array reference of attributes, each of which is a [tag=>value] array ref
616  
617 =cut
618  
619 0 ▶sub load_gff_line {
Subroutine load_gff_line: not called CC=18 SCAR=58.3
Pod documented
620 0 my $self = shift;
621 0 my $gff = shift;
622
623 0 ▶ if (defined $gff->{phase}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $gff->{"phase"}) 0 0 0
624 0 chomp($gff->{phase});
625 0 ▶ undef($gff->{phase}) if $gff->{phase} eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $gff->{"phase"} eq "." 0 0 0
626 }
627  
628 0 ▶ if (defined $gff->{strand} && $gff->{strand} eq '.'){undef($gff->{strand})};
Branch: 1 branch
BranchTrueFalseTotal
if (defined $gff->{"strand"} and $gff->{"strand"} eq ".") 0 0 0
Condition0%0/3
defined $gff->{"strand"} and $gff->{"strand"} eq "."
!ll&&!rl&&r
000
MC/DC0%0/2
defined $gff->{"strand"} and $gff->{"strand"} eq "."
defined $gff->{"strand"} $gff->{"strand"} eq "."
Truth table0%0/3
A and B
A= defined $gff->{"strand"}B= $gff->{"strand"} eq "."
ABresult
0X0
100
111
629 0 ▶ if (defined $gff->{score} && $gff->{score} eq '.'){undef($gff->{score})};
Branch: 1 branch
BranchTrueFalseTotal
if (defined $gff->{"score"} and $gff->{"score"} eq ".") 0 0 0
Condition0%0/3
defined $gff->{"score"} and $gff->{"score"} eq "."
!ll&&!rl&&r
000
MC/DC0%0/2
defined $gff->{"score"} and $gff->{"score"} eq "."
defined $gff->{"score"} $gff->{"score"} eq "."
Truth table0%0/3
A and B
A= defined $gff->{"score"}B= $gff->{"score"} eq "."
ABresult
0X0
100
111
630  
631 0 my $s = $self->{load_stuff};
632 0 my $dbh = $self->features_db;
633 0 local $dbh->{PrintError} = 0;
634  
635 0 ▶ defined(my $typeid = $self->get_table_id('ftype', $gff->{method} => $gff->{source})) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $typeid = $self->get_table_id("ftype", $gff->{"method"}, $gff->{"source"})) or return 0 0 0
636 0 ▶ defined(my $groupid = $self->get_table_id('fgroup',$gff->{gname} => $gff->{gclass})) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $groupid = $self->get_table_id("fgroup", $gff->{"gname"}, $gff->{"gclass"})) or return 0 0 0
637  
638 0 my $bin = bin($gff->{start},$gff->{stop},$self->min_bin);
639 my $result = $s->{sth}{insert_fdata}->execute($gff->{ref},
640 $gff->{start},$gff->{stop},$bin,
641 $typeid,
642 $gff->{score},$gff->{strand},$gff->{phase},
643 $groupid,
644 0 $gff->{tstart},$gff->{tstop});
645  
646 0 ▶ warn $dbh->errstr,"\n" and print "ref=",$gff->{ref}," start=",$gff->{start}," stop=",$gff->{stop}," bin=",$bin," typeid=",$typeid," groupid=",$groupid,"\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
Condition0%0/8
$result || warn($dbh->errstr, "\n") && print('ref=', $gff->{'ref'}, ' start=', $gff->{'start'}, ' stop=', $gff->{'stop'}, ' bin=', $bin, ' typeid=', $typeid, ' groupid=', $groupid, "\n") && (return)
l!l&&r!l&&!r
000
warn $dbh->errstr, "\n" and print "ref=", $gff->{"ref"}, " start=", $gff->{"start"}, " stop=", $gff->{"stop"}, " bin=", $bin, " typeid=", $typeid, " groupid=", $groupid, "\n" and return
!ll
00
warn $dbh->errstr, "\n" and print "ref=", $gff->{"ref"}, " start=", $gff->{"start"}, " stop=", $gff->{"stop"}, " bin=", $bin, " typeid=", $typeid, " groupid=", $groupid, "\n"
!ll&&!rl&&r
000
MC/DC0%0/3
$result || warn($dbh->errstr, "\n") && print('ref=', $gff->{'ref'}, ' start=', $gff->{'start'}, ' stop=', $gff->{'stop'}, ' bin=', $bin, ' typeid=', $typeid, ' groupid=', $groupid, "\n") && (return)
$result warn $dbh->errstr, "\n" print "ref=", $gff->{"ref"}, " start=", $gff->{"start"}, " stop=", $gff->{"stop"}, " bin=", $bin, " typeid=", $typeid, " groupid=", $groupid, "\n"
Truth table0%0/4
A || B and C
A= $resultB= warn $dbh->errstr, "\n"C= print "ref=", $gff->{"ref"}, " start=", $gff->{"start"}, " stop=", $gff->{"stop"}, " bin=", $bin, " typeid=", $typeid, " groupid=", $groupid, "\n"
ABCresult
1XX1
0111
00X0
0100
647 and return unless $result;
648
649 my $fid = $self->insertid($s->{sth},'fdata')
650 0 ▶ || $self->get_feature_id($gff->{ref},$gff->{start},$gff->{stop},$typeid,$groupid);
Condition0%0/3
$self->insertid($s->{'sth'}, 'fdata') || $self->get_feature_id($gff->{'ref'}, $gff->{'start'}, $gff->{'stop'}, $typeid, $groupid)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->insertid($s->{'sth'}, 'fdata') || $self->get_feature_id($gff->{'ref'}, $gff->{'start'}, $gff->{'stop'}, $typeid, $groupid)
$self->insertid($s->{'sth'}, 'fdata') $self->get_feature_id($gff->{'ref'}, $gff->{'start'}, $gff->{'stop'}, $typeid, $groupid)
Truth table0%0/3
A || B
A= $self->insertid($s->{'sth'}, 'fdata')B= $self->get_feature_id($gff->{'ref'}, $gff->{'start'}, $gff->{'stop'}, $typeid, $groupid)
ABresult
1X1
011
000
651
652 # insert attributes
653 0 foreach (@{$gff->{attributes}}) {
654 0 ▶ defined(my $attribute_id = $self->get_table_id('fattribute',$_->[0])) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $attribute_id = $self->get_table_id("fattribute", $_->[0])) or return 0 0 0
655 0 $s->{sth}{insert_fattribute_value}->execute($fid,$attribute_id,$_->[1]);
656 }
657  
658 0 ▶ if ( (++$s->{counter} % 1000) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$s->{"counter"} % 1000 == 0) 0 0 0
659 0 print STDERR "$s->{counter} records loaded...";
660 0 ▶ print STDERR -t STDOUT && !$ENV{EMACS} ? "\r" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
-t STDOUT && !$ENV{'EMACS'} ? : 0 0 0
Condition0%0/3
-t STDOUT and not $ENV{"EMACS"}
!ll&&!rl&&r
000
MC/DC0%0/2
-t STDOUT and not $ENV{"EMACS"}
-t STDOUT not $ENV{"EMACS"}
Truth table0%0/3
A and not(B)
A= -t STDOUTB= not $ENV{"EMACS"}
ABresult
0X0
100
111
661 }
662  
663 0 $fid;
664 }
665  
666  
667 0 ▶sub insertid {
Subroutine insertid: not called CC=2 SCAR=17.9
Pod undocumented
668 0 my $self = shift;
669 0 my $sth = shift ;
670 0 my $table = shift;
671  
672 0 my $insert_id;
673 0 ▶ if ($sth->{"insertid_$table"}->execute()){
Branch: 1 branch
BranchTrueFalseTotal
if ($$sth{"insertid_$table"}->execute) { } 0 0 0
674 0 $insert_id = ($sth->{"insertid_$table"}->fetchrow_array)[0];
675 }
676 else{
677 0 warn "No CURRVAL for SEQUENCE of table $table ",$sth->errstr,"\n";
678 0 return;
679 }
680 0 return $insert_id;
681 }
682  
683  
684 =head2 get_table_id
685  
686 Title : get_table_id
687 Usage : $integer = $db->get_table_id($table,@ids)
688 Function: get the ID of a group or type
689 Returns : an integer ID or undef
690 Args : none
691 Status : private
692  
693 This internal method is called by load_gff_line to look up the integer
694 ID of an existing feature type or group. The arguments are the name
695 of the table, and two string identifiers. For feature types, the
696 identifiers are the method and source. For groups, the identifiers
697 are group name and class.
698  
699 This method requires that a statement handler named I<lookup_$table>,
700 have been created previously by setup_load(). It is here to overcome
701 deficiencies in mysql's INSERT syntax.
702  
703 =cut
704  
705 #'
706 # get the object ID from a named table
707 0 ▶sub get_table_id {
Subroutine get_table_id: not called CC=5 SCAR=34.0
Pod documented
708 0 my $self = shift;
709 0 my $table = shift;
710 0 my @ids = @_;
711  
712 # irritating warning for null id
713 0 my $id_key;
714 {
715 0 local $^W=0;
716 0 $id_key = join ':',@ids;
717 }
718  
719 0 my $s = $self->{load_stuff};
720 0 my $sth = $s->{sth};
721 0 my $dbh = $self->features_db;
722  
723 0 ▶ unless (defined($s->{$table}{$id_key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s->{$table}{$id_key}) 0 0 0
724 0 $sth->{"lookup_$table"}->execute(@ids);
725 0 my @result = $sth->{"lookup_$table"}->fetchrow_array;
726 0 ▶ if (@result > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result > 0) { } 0 0 0
727 0 $s->{$table}{$id_key} = $result[0];
728 } else {
729 $sth->{"insert_$table"}->execute(@ids)
730 0 ▶ && ($s->{$table}{$id_key} = $self->insertid($sth,$table));
Branch: 1 branch
BranchTrueFalseTotal
$$sth{"insert_$table"}->execute(@ids) and $s->{$table}{$id_key} = $self->insertid($sth, $table) 0 0 0
731 #&& ($s->{$table}{$id_key} = $self->insertid($sth->{"insertid_$table"}));
732 #&& ($s->{$table}{$id_key} = $sth->{"insert_$table"}->insertid);
733 }
734 }
735  
736 0 my $id = $s->{$table}{$id_key};
737 0 ▶ unless (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id) 0 0 0
738 0 warn "No $table id for $id_key ",$dbh->errstr," Record skipped.\n";
739 0 return;
740 }
741 0 $id;
742 }
743  
744  
745 #sub insertid {
746 # my $self = shift;
747 # my $insertid_sth = shift ;
748 # my $insert_id;
749 # if ($insertid_sth->execute){
750 # $insert_id = ($insertid_sth->fetchrow_array)[0];
751 # }
752 # else{
753 # warn "No CURRVAL for SEQUENCE ",$insertid_sth->errstr,"\n";
754 # return;
755 # }
756 # return $insert_id;
757 #}
758  
759 0 ▶sub insert_sequence {
Subroutine insert_sequence: not called CC=3 SCAR=24.8
Pod undocumented
760 0 my $self = shift;
761 0 my($id,$offset,$seq) = @_;
762 my $sth = $self->{_insert_sequence}
763 0 ▶ ||= $self->dbh->prepare_delayed('insert into fdna values (?,?,?)');
Condition0%0/3
$self->{"_insert_sequence"} ||= $self->dbh->prepare_delayed("insert into fdna values (?,?,?)")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_insert_sequence"} ||= $self->dbh->prepare_delayed("insert into fdna values (?,?,?)")
$self->{"_insert_sequence"} $self->dbh->prepare_delayed("insert into fdna values (?,?,?)")
Truth table0%0/3
A ||= B
A= $self->{"_insert_sequence"}B= $self->dbh->prepare_delayed("insert into fdna values (?,?,?)")
ABresult
1X1
011
000
764 0 ▶ $sth->execute($id,$offset,$seq) or $self->throw($sth->errstr);
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute($id, $offset, $seq) or $self->throw($sth->errstr) 0 0 0
765 }
766  
767 =head2 range_query
768  
769 Title : range_query
770 Usage : $db->range_query($range_type,$refseq,$refclass,$start,$stop,$types,$order_by_group,$attributes,$binsize)
771 Function: create statement handle for range/overlap queries
772 Returns : a DBI statement handle
773 Args : see below
774 Status : Protected
775  
776 This method constructs the statement handle for this module's central
777 query: given a range and/or a list of feature types, fetch their GFF
778 records. It overrides a method in dbi.pm so that the overlaps query
779 can write SQL optimized for Postgres. Specifically, instead of writing
780 the bin related section as a set of ORs, each bin piece is place in
781 a separate select and then they are UNIONed together. This subroutine
782 requires several replacements for other subroutines in dbi.pm. In this
783 module, they are named the same as those in dbi.pm but prefixed with
784 "pg_".
785  
786 The positional arguments are as follows:
787  
788 Argument Description
789  
790 $isrange A flag indicating that this is a range.
791 query. Otherwise an overlap query is
792 assumed.
793  
794 $refseq The reference sequence name (undef if no range).
795  
796 $refclass The reference sequence class (undef if no range).
797  
798 $start The start of the range (undef if none).
799  
800 $stop The stop of the range (undef if none).
801  
802 $types Array ref containing zero or feature types in the
803 format [method,source].
804  
805 $order_by_group A flag indicating that statement handler should group
806 the features by group id (handy for iterative fetches)
807  
808 $attributes A hash containing select attributes.
809  
810 $binsize A bin size for generating tables of feature density.
811  
812 =cut
813  
814 0 ▶sub range_query {
Subroutine range_query: not called CC=9 SCAR=45.0
Pod documented
815 0 my $self = shift;
816 0 my($rangetype,$refseq,$class,$start,$stop,$types,$sparse,$order_by_group,$attributes,$bin) = @_;
817  
818 0 my $dbh = $self->features_db;
819  
820 # my @bin_parts = split /\n\s+OR/, $self->bin_query($start,$stop);
821 # warn "bin_part: @bin_parts\n";
822  
823 0 my %a = (refseq=>$refseq,class=>$class,start=>$start,stop=>$stop,types=>$types,attributes=>$attributes,bin_width=>$bin);
824 0 my ($query, @args, $order_by);
825  
826 0 ▶ if ($rangetype ne 'overlaps') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rangetype ne 'overlaps') { } 0 0 0
827  
828 0 my $select = $self->make_features_select_part(\%a);
829 0 my $from = $self->make_features_from_part($sparse,\%a);
830 0 my $join = $self->make_features_join_part(\%a);
831 0 my $where;
832 0 ($where,@args) = $self->make_features_by_range_where_part($rangetype,\%a);
833 0 my ($group_by,@more_args) = $self->make_features_group_by_part(\%a);
834 0 ▶ $order_by = $self->make_features_order_by_part(\%a) if $order_by_group;
Branch: 1 branch
BranchTrueFalseTotal
if $order_by_group 0 0 0
835  
836 0 $query = "SELECT $select FROM $from WHERE $join";
837 0 ▶ $query .= " AND $where" if $where;
Branch: 1 branch
BranchTrueFalseTotal
if $where 0 0 0
838  
839 0 ▶ if ($group_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group_by) 0 0 0
840 0 $query .= " GROUP BY $group_by";
841 0 push @args,@more_args;
842 }
843  
844 } else { # most common case: overlaps query
845  
846 0 my @bin_parts = split /\s*OR/, $self->bin_query($start,$stop);
847 0 my $select = $self->make_features_select_part(\%a);
848 0 my $from = $self->make_features_from_part($sparse,\%a);
849 0 my $join = $self->make_features_join_part(\%a);
850 0 my $where;
851 0 ($where,@args) = $self->pg_make_features_by_range_where_part($rangetype,\%a);
852 0 my ($group_by,@more_args)= $self->make_features_group_by_part(\%a);
853 0 ▶ $order_by = $self->pg_make_features_order_by_part(\%a) if $order_by_group;
Branch: 1 branch
BranchTrueFalseTotal
if $order_by_group 0 0 0
854  
855 0 my @temp_args;
856 my @query_pieces;
857 0 foreach my $bin (@bin_parts) {
858 0 my $temp_query = "SELECT $select FROM $from WHERE $join AND $where AND $bin\n";
859 0 push @temp_args, @args;
860  
861 0 ▶ if ($group_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group_by) 0 0 0
862 0 $temp_query .= " GROUP BY $group_by";
863 0 push @temp_args,@more_args;
864 }
865  
866 0 push @query_pieces, $temp_query;
867 }
868
869 0 @args = @temp_args;
870 0 $query = join("UNION\n", @query_pieces);
871  
872 }
873  
874 0 ▶ $query .= " ORDER BY $order_by" if $order_by;
Branch: 1 branch
BranchTrueFalseTotal
if $order_by 0 0 0
875  
876 0 $self->dbh->do('set enable_seqscan=off');
877 0 my $sth = $self->dbh->do_query($query,@args);
878 0 $sth;
879 }
880  
881 0 ▶sub pg_make_features_by_range_where_part {
Subroutine pg_make_features_by_range_where_part: not called CC=12 SCAR=50.5
Pod undocumented
882 0 my $self = shift;
883 0 my ($rangetype,$options) = @_;
884  
885 0 ▶ return unless $rangetype eq 'overlaps';
Branch: 1 branch
BranchTrueFalseTotal
unless $rangetype eq "overlaps" 0 0 0
886  
887 0 ▶ $options ||= {};
Condition0%0/2
$options ||= {}
l!l
00
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
Aresult
11
00
888 my ($refseq,$class,$start,$stop,$types,$attributes) =
889 0 @{$options}{qw(refseq class start stop types attributes)};
890  
891 0 my (@query,@args);
892  
893 0 ▶ if ($refseq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refseq) 0 0 0
894 0 my ($q,@a) = $self->refseq_query($refseq,$class);
895 0 push @query,$q;
896 0 push @args,@a;
897 }
898  
899 0 ▶ if (defined $start or defined $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start or defined $stop) 0 0 0
Condition0%0/3
defined $start or defined $stop
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
900 0 ▶ $start = 0 unless defined($start);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
901 0 ▶ $stop = MAX_SEGMENT unless defined($stop);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stop 0 0 0
902  
903 0 my ($range_query,@range_args) = $self->pg_overlap_query($start,$stop);
904  
905 0 push @query,$range_query;
906 0 push @args,@range_args;
907 }
908  
909 0 ▶ if (defined $types && @$types) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $types and @$types) 0 0 0
Condition0%0/3
defined $types and @$types
!ll&&!rl&&r
000
MC/DC0%0/2
defined $types and @$types
defined $types @$types
Truth table0%0/3
A and B
A= defined $typesB= @$types
ABresult
0X0
100
111
910 0 my ($type_query,@type_args) = $self->types_query($types);
911 0 push @query,$type_query;
912 0 push @args,@type_args;
913 }
914  
915 0 ▶ if ($attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes) 0 0 0
916 0 my ($attribute_query,@attribute_args) = $self->make_features_by_attribute_where_part($attributes);
917 0 push @query,"($attribute_query)";
918 0 push @args,@attribute_args;
919 }
920  
921 0 my $query = join "AND",@query;
922 0 ▶ return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
923 }
924  
925 0 ▶sub pg_overlap_query {
Subroutine pg_overlap_query: not called CC=2 SCAR=17.9
Pod undocumented
926 0 my $self = shift;
927 0 my ($start,$stop) = @_;
928  
929 0 my ($iq,@iargs) = $self->overlap_query_nobin($start,$stop);
930 0 my $query = "\n$iq\n";
931 0 my @args = @iargs;
932  
933 0 ▶ return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
934 }
935  
936 0 ▶sub pg_make_features_order_by_part {
Subroutine pg_make_features_order_by_part: not called CC=2 SCAR=17.9
Pod undocumented
937 0 my $self = shift;
938 0 ▶ my $options = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
939 0 return "gname";
940 }
941  
942 =head2 search_notes
943  
944 This PostgreSQL adaptor does not implement the search notes method
945 because it can be very slow (although the code for the method is
946 contained in this method but commented out).
947 There is, however, a PostgreSQL adaptor that does implement it in
948 a more efficient way: L<Bio::DB::GFF::Adaptor::dbi::pg_fts>,
949 which inherits from this adaptor and uses the optional PostgreSQL
950 module TSearch2 for full text indexing. See that adaptor's
951 documentation for more information.
952  
953 See also L<Bio::DB::GFF>
954  
955 Title : search_notes
956 Usage : @search_results = $db->search_notes("full text search string",$limit)
957 Function: Search the notes for a text string, using mysql full-text search
958 Returns : array of results
959 Args : full text search string, and an optional row limit
960 Status : public
961  
962 This is a replacement for the mysql-specific method. Given a search string, it
963 performs a ILIKE search of the notes table and returns an array of results.
964 Each row of the returned array is a arrayref containing the following fields:
965  
966 column 1 A Bio::DB::GFF::Featname object, suitable for passing to segment()
967 column 2 The text of the note
968 column 3 A relevance score.
969  
970 Note that for large databases this can be very slow and may result in
971 time out or 500-cgi errors. If this is happening on a regular basis,
972 you should look into using L<Bio::DB::GFF::Adaptor::dbi::pg_fts> which
973 implements the TSearch2 full text indexing scheme.
974  
975 =cut
976  
977 0 ▶sub search_notes{
Subroutine search_notes: not called CC=1 SCAR=0.0
Pod documented
978 # my $self = shift;
979 # my ($search_string,$limit) = @_;
980 #
981 # $search_string =~ tr/*/%/s;
982 # $search_string = '%'.$search_string unless $search_string =~ /^\%/;
983 # $search_string = $search_string.'%' unless $search_string =~ /\%$/;
984 # warn "search_string:$search_string";
985 # my $query = FULLTEXTWILDCARD;
986 # $query .= " limit $limit" if defined $limit;
987 # my $sth = $self->dbh->do_query($query,$search_string);
988 #
989 # my @results;
990 # while (my ($class,$name,$note) = $sth->fetchrow_array) {
991 #
992 # next unless $class && $name; # sorry, ignore NULL objects
993 # my $featname = Bio::DB::GFF::Featname->new($class=>$name);
994 #
995 # push @results,[$featname,$note,0]; #gbrowse expects a score, but
996 # #pg doesn't give one, thus the 0
997 # }
998 # warn @results;
999 #
1000 # return @results;
1001 }
1002  
1003  
1004 =head2 make_meta_set_query
1005  
1006 Title : make_meta_set_query
1007 Usage : $sql = $db->make_meta_set_query
1008 Function: return SQL fragment for setting a meta parameter
1009 Returns : SQL fragment
1010 Args : none
1011 Status : public
1012  
1013 By default this does nothing; meta parameters are not stored or
1014 retrieved.
1015  
1016 =cut
1017  
1018 0 ▶sub make_meta_set_query {
Subroutine make_meta_set_query: not called CC=1 SCAR=6.9
Pod documented
1019 0 return 'INSERT INTO fmeta VALUES (?,?)';
1020 }
1021  
1022 0 ▶sub make_classes_query {
Subroutine make_classes_query: not called CC=1 SCAR=6.9
Pod documented
1023 0 my $self = shift;
1024 0 return 'SELECT DISTINCT gclass FROM fgroup WHERE NOT gclass IS NULL';
1025 }
1026  
1027  
1028 0 ▶sub chunk_size {
Subroutine chunk_size: not called CC=2 SCAR=17.9
Pod undocumented
1029 0 my $self = shift;
1030 0 ▶ $self->meta('chunk_size') || DEFAULT_CHUNK;
Branch: 1 branch
BranchTrueFalseTotal
$self->meta("chunk_size") or 2000 0 0 0
1031 }
1032  
1033 0 ▶sub getseqcoords_query {
Subroutine getseqcoords_query: not called CC=1 SCAR=6.9
Pod undocumented
1034 0 my $self = shift;
1035 0 return GETSEQCOORDS ;
1036 }
1037  
1038 0 ▶sub getaliascoords_query{
Subroutine getaliascoords_query: not called CC=1 SCAR=6.9
Pod undocumented
1039 0 my $self = shift;
1040 0 return GETALIASCOORDS ;
1041 }
1042  
1043  
1044 0 ▶sub getforcedseqcoords_query{
Subroutine getforcedseqcoords_query: not called CC=1 SCAR=6.9
Pod undocumented
1045 0 my $self = shift;
1046 0 return GETFORCEDSEQCOORDS ;
1047 }
1048  
1049  
1050 0 ▶sub getaliaslike_query{
Subroutine getaliaslike_query: not called CC=1 SCAR=6.9
Pod undocumented
1051 0 my $self = shift;
1052 0 return GETALIASLIKE ;
1053 }
1054  
1055  
1056 0 ▶sub make_features_select_part {
Subroutine make_features_select_part: not called CC=5 SCAR=34.0
Pod documented
1057 0 my $self = shift;
1058 0 ▶ my $options = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1059 0 my $s;
1060 0 ▶ if (my $b = $options->{bin_width}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $options->{'bin_width'}) { } 0 0 0
1061  
1062 0 $s = <<END;
1063 fref,
1064 1+$b*floor(fstart/$b) as fstart,
1065 $b*(1+floor(fstart/$b)) as fstop,
1066 CASE WHEN fsource IS NULL THEN fmethod
1067 ELSE fmethod||':'||fsource,
1068 'bin',
1069 count(*) as fscore,
1070 '.','.','bin',
1071 CASE WHEN fsource IS NULL THEN fref||':'||fmethod
1072 ELSE fref||':'||fmethod||':'||fsource,
1073 NULL,NULL,NULL,NULL
1074 END
1075 ;
1076 } else {
1077 0 $s = <<END;
1078 fref,fstart,fstop,fsource,fmethod,fscore,fstrand,fphase,gclass,fgroup.gname,ftarget_start,ftarget_stop,fdata.fid,fdata.gid
1079 END
1080 ;
1081 }
1082 0 ▶ $s .= ",count(fdata.fid)" if $options->{attributes} && keys %{$options->{attributes}}>1;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"attributes"} and keys %{$$options{"attributes"};} > 1 0 0 0
Condition0%0/3
$options->{"attributes"} and keys %{$$options{"attributes"};} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"attributes"} and keys %{$$options{"attributes"};} > 1
$options->{"attributes"} keys %{$$options{"attributes"};} > 1
Truth table0%0/3
A and B
A= $options->{"attributes"}B= keys %{$$options{"attributes"};} > 1
ABresult
0X0
100
111
1083 0 $s;
1084 }
1085  
1086 0 ▶sub make_features_from_part_bkup {
Subroutine make_features_from_part_bkup: not called CC=3 SCAR=24.8
Pod undocumented
1087 0 my $self = shift;
1088 0 my $sparse = shift;
1089 0 ▶ my $options = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1090 #my $index = $sparse ? ' USE INDEX(ftypeid)': '';
1091 0 my $index = '';
1092 0 ▶ return $options->{attributes} ? "fdata${index},ftype,fgroup,fattribute,fattribute_to_feature\n"
Branch: 1 branch
BranchTrueFalseTotal
$options->{'attributes'} ? : 0 0 0
1093 : "fdata${index},ftype,fgroup\n";
1094 }
1095  
1096  
1097 ####################################
1098 # moved from mysqlopt.pm
1099 ###################################
1100 # meta values
1101 0 ▶sub default_meta_values {
Subroutine default_meta_values: not called CC=1 SCAR=6.9
Pod documented
1102 0 my $self = shift;
1103 0 my @values = $self->SUPER::default_meta_values;
1104 return (
1105 0 @values,
1106 max_bin => MAX_BIN,
1107 min_bin => MIN_BIN,
1108 straight_join_limit => STRAIGHT_JOIN_LIMIT,
1109 );
1110 }
1111  
1112 0 ▶sub min_bin {
Subroutine min_bin: not called CC=2 SCAR=17.9
Pod undocumented
1113 0 my $self = shift;
1114 0 ▶ return $self->meta('min_bin') || MIN_BIN;
Condition0%0/2
$self->meta('min_bin') || 1000
l!l
00
MC/DC0%0/1
$self->meta('min_bin') || 1000
$self->meta('min_bin')
Truth table0%0/2
A
A= $self->meta('min_bin')
Aresult
11
00
1115 }
1116 0 ▶sub max_bin {
Subroutine max_bin: not called CC=2 SCAR=17.9
Pod undocumented
1117 0 my $self = shift;
1118 0 ▶ return $self->meta('max_bin') || MAX_BIN;
Condition0%0/2
$self->meta('max_bin') || 100000000
l!l
00
MC/DC0%0/1
$self->meta('max_bin') || 100000000
$self->meta('max_bin')
Truth table0%0/2
A
A= $self->meta('max_bin')
Aresult
11
00
1119 }
1120 0 ▶sub straight_join_limit {
Subroutine straight_join_limit: not called CC=2 SCAR=17.9
Pod undocumented
1121 0 my $self = shift;
1122 0 ▶ return $self->meta('straight_join_limit') || STRAIGHT_JOIN_LIMIT;
Condition0%0/2
$self->meta('straight_join_limit') || 200000
l!l
00
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')
Aresult
11
00
1123 }
1124  
1125  
1126 0 ▶sub _feature_by_name {
Subroutine _feature_by_name: not called CC=7 SCAR=40.3
1127 0 my $self = shift;
1128 0 my ($class,$name,$location,$callback) = @_;
1129 0 ▶ $callback || $self->throw('must provide a callback argument');
Branch: 1 branch
BranchTrueFalseTotal
$callback or $self->throw("must provide a callback argument") 0 0 0
1130  
1131 0 ▶ my @bin_parts = split /\s*OR/, $self->bin_query($location->[1],$location->[2]) if $location;
Branch: 1 branch
BranchTrueFalseTotal
if $location 0 0 0
1132 0 my $select = $self->make_features_select_part;
1133 0 my $from = $self->make_features_from_part(undef,{sparse_groups=>1});
1134 0 my ($where,@args) = $self->make_features_by_name_where_part($class,$name);
1135 0 my $join = $self->make_features_join_part;
1136 0 ▶ my $range = $self->pg_make_features_by_range_where_part('overlaps',
Branch: 1 branch
BranchTrueFalseTotal
if $location 0 0 0
1137 {refseq=>$location->[0],
1138 class =>'',
1139 start=>$location->[1],
1140 stop =>$location->[2]}) if $location;
1141  
1142 0 my @temp_args;
1143 my @query_pieces;
1144 0 my $query;
1145 0 ▶ if (@bin_parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bin_parts) { } 0 0 0
1146 0 foreach my $bin (@bin_parts) {
1147 0 my $temp_query = "SELECT $select FROM $from WHERE $join AND $where AND $range AND $bin\n";
1148 0 push @temp_args, @args;
1149 0 push @query_pieces, $temp_query;
1150 }
1151  
1152 0 @args = @temp_args;
1153 0 $query = join("UNION\n", @query_pieces);
1154  
1155 } else {
1156 0 $query = "SELECT $select FROM $from WHERE $where AND $join";
1157 }
1158  
1159 0 my $sth = $self->dbh->do_query($query,@args);
1160  
1161 0 my $count = 0;
1162 0 ▶ while (my @row = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@row) = $sth->fetchrow_array) 0 0 0
1163 0 $callback->(@row);
1164 0 $count++;
1165 }
1166 0 $sth->finish;
1167 0 return $count;
1168 }
1169  
1170 0 ▶sub update_sequences {
Subroutine update_sequences: not called CC=1 SCAR=6.9
Pod undocumented
1171 0 my $self = shift;
1172 0 my $dbh = $self->features_db;
1173
1174 0 $dbh->do("SELECT setval('public.fdata_fid_seq', max(fid)+1) FROM fdata");
1175 0 $dbh->do("SELECT setval('public.fattribute_fattribute_id_seq', max(fattribute_id)+1) FROM fattribute");
1176 0 $dbh->do("SELECT setval('public.fgroup_gid_seq', max(gid)+1) FROM fgroup");
1177 0 $dbh->do("SELECT setval('public.ftype_ftypeid_seq', max(ftypeid)+1) FROM ftype");
1178  
1179 0 1;
1180 }
1181  
1182 =head2 make_features_by_name_where_part
1183  
1184 Title : make_features_by_name_where_part
1185 Usage : $db->make_features_by_name_where_part
1186 Function: Overrides a function in Bio::DB::GFF::Adaptor::dbi to insure
1187 that searches will be case insensitive. It creates the SQL
1188 fragment needed to select a feature by its group name & class
1189 Returns : a SQL fragment and bind arguments
1190 Args : see below
1191 Status : Protected
1192  
1193 =cut
1194  
1195 0 ▶sub make_features_by_name_where_part {
Subroutine make_features_by_name_where_part: not called CC=2 SCAR=17.9
Pod documented
1196 0 my $self = shift;
1197 0 my ($class,$name) = @_;
1198  
1199 0 ▶ if ($name !~ /\*/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $name =~ /\*/) { } 0 0 0
1200 #allows utilization of an index on lower(gname)
1201 0 return ("fgroup.gclass=? AND lower(fgroup.gname) = lower(?)",$class,$name);
1202 }
1203 else {
1204 0 $name =~ tr/*/%/;
1205 0 return ("fgroup.gclass=? AND lower(fgroup.gname) LIKE lower(?)",$class,$name);
1206 }
1207 }
1208  
1209 #
1210 # Methods from dbi.pm that need to be overridden to make
1211 # searching for fref case insensitive
1212 #
1213 #
1214 0 ▶sub get_dna {
Subroutine get_dna: not called CC=13 SCAR=52.0
Pod documented
1215 0 my $self = shift;
1216 0 my ($ref,$start,$stop,$class) = @_;
1217  
1218 0 my ($offset_start,$offset_stop);
1219  
1220 0 my $has_start = defined $start;
1221 0 my $has_stop = defined $stop;
1222  
1223 0 my $reversed;
1224 0 ▶ if ($has_start && $has_stop && $start > $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_start and $has_stop and $start > $stop) 0 0 0
Condition0%0/6
$has_start and $has_stop and $start > $stop
!ll&&!rl&&r
000
$has_start and $has_stop
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
1225 0 $reversed++;
1226 0 ($start,$stop) = ($stop,$start);
1227 }
1228  
1229 # turn start and stop into 0-based offsets
1230 0 my $cs = $self->dna_chunk_size;
1231 0 $start -= 1; $stop -= 1;
1232 0 $offset_start = int($start/$cs)*$cs;
1233 0 $offset_stop = int($stop/$cs)*$cs;
1234  
1235 0 my $sth;
1236 # special case, get it all
1237 0 ▶ if (!($has_start || $has_stop)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $has_start || $has_stop) { } 0 0 0
elsif (not $has_stop) { } 0 0 0
Condition0%0/3
$has_start || $has_stop
l!l&&r!l&&!r
000
MC/DC0%0/2
$has_start || $has_stop
$has_start $has_stop
Truth table0%0/3
A || B
A= $has_startB= $has_stop
ABresult
1X1
011
000
1238 0 $sth = $self->dbh->do_query('select fdna,foffset from fdna where lower(fref)=lower(?) order by foffset',$ref);
1239 }
1240  
1241 elsif (!$has_stop) {
1242 0 $sth = $self->dbh->do_query('select fdna,foffset from fdna where lower(fref)=lower(?) and foffset>=? order by foffset',
1243 $ref,$offset_start);
1244 }
1245  
1246 else { # both start and stop defined
1247 0 $sth = $self->dbh->do_query('select fdna,foffset from fdna where lower(fref)=lower(?) and foffset>=? and foffset<=? order by foffset',
1248 $ref,$offset_start,$offset_stop);
1249 }
1250  
1251 0 my $dna = '';
1252 0 ▶ while (my($frag,$offset) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
1253 0 ▶ substr($frag,0,$start-$offset) = '' if $has_start && $start > $offset;
Branch: 1 branch
BranchTrueFalseTotal
if $has_start and $start > $offset 0 0 0
Condition0%0/3
$has_start and $start > $offset
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
1254 0 $dna .= $frag;
1255 }
1256 0 ▶ substr($dna,$stop-$start+1) = '' if $has_stop && $stop-$start+1 < length($dna);
Branch: 1 branch
BranchTrueFalseTotal
if $has_stop and $stop - $start + 1 < length $dna 0 0 0
Condition0%0/3
$has_stop and $stop - $start + 1 < length $dna
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
1257 0 ▶ if ($reversed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reversed) 0 0 0
1258 0 $dna = reverse $dna;
1259 0 $dna =~ tr/gatcGATC/ctagCTAG/;
1260 }
1261  
1262 0 $sth->finish;
1263 0 $dna;
1264 }
1265  
1266  
1267 0 ▶sub refseq_query {
Subroutine refseq_query: not called CC=2 SCAR=17.9
Pod documented
1268 0 my $self = shift;
1269 0 my ($refseq,$refclass) = @_;
1270 0 my $query = "lower(fdata.fref)=lower(?)";
1271 0 ▶ return wantarray ? ($query,$refseq) : $self->dbh->dbi_quote($query,$refseq);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1272 }
1273  
1274 0 ▶sub make_types_where_part {
Subroutine make_types_where_part: not called CC=10 SCAR=47.0
Pod documented
1275 0 my $self = shift;
1276 0 my ($srcseq,$start,$stop,$want_count,$typelist) = @_;
1277 0 my (@query,@args);
1278 0 ▶ if (defined($srcseq)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $srcseq) 0 0 0
1279 0 push @query,'lower(fdata.fref)=lower(?)';
1280 0 push @args,$srcseq;
1281 0 ▶ if (defined $start or defined $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start or defined $stop) 0 0 0
Condition0%0/3
defined $start or defined $stop
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
1282 0 ▶ $start = 1 unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
1283 0 ▶ $stop = MAX_SEGMENT unless defined $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stop 0 0 0
1284 0 my ($q,@a) = $self->overlap_query($start,$stop);
1285 0 push @query,"($q)";
1286 0 push @args,@a;
1287 }
1288 }
1289 0 ▶ if (defined $typelist && @$typelist) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $typelist and @$typelist) 0 0 0
Condition0%0/3
defined $typelist and @$typelist
!ll&&!rl&&r
000
MC/DC0%0/2
defined $typelist and @$typelist
defined $typelist @$typelist
Truth table0%0/3
A and B
A= defined $typelistB= @$typelist
ABresult
0X0
100
111
1290 0 my ($q,@a) = $self->types_query($typelist);
1291 0 push @query,($q);
1292 0 push @args,@a;
1293 }
1294 0 ▶ my $query = @query ? join(' AND ',@query) : '1=1';
Branch: 1 branch
BranchTrueFalseTotal
@query ? : 0 0 0
1295 0 ▶ return wantarray ? ($query,@args) : $self->dbh->dbi_quote($query,@args);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1296 }
1297  
1298 0 ▶sub get_feature_id {
Subroutine get_feature_id: not called CC=4 SCAR=30.0
Pod documented
1299 0 my $self = shift;
1300 0 my ($ref,$start,$stop,$typeid,$groupid) = @_;
1301 0 my $s = $self->{load_stuff};
1302 0 ▶ unless ($s->{get_feature_id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s->{"get_feature_id"}) 0 0 0
1303 0 my $dbh = $self->features_db;
1304 $s->{get_feature_id} =
1305 0 $dbh->prepare_delayed('SELECT fid FROM fdata WHERE lower(fref)=lower(?) AND fstart=? AND fstop=? AND ftypeid=? AND gid=?');
1306 }
1307 0 ▶ my $sth = $s->{get_feature_id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $s->{"get_feature_id"} or return 0 0 0
1308 0 ▶ $sth->execute($ref,$start,$stop,$typeid,$groupid) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute($ref, $start, $stop, $typeid, $groupid) or return 0 0 0
1309 0 my ($fid) = $sth->fetchrow_array;
1310 0 return $fid;
1311 }
1312  
1313 0 ▶sub _delete {
Subroutine _delete: not called CC=15 SCAR=54.8
1314 0 my $self = shift;
1315 0 my $delete_spec = shift;
1316 0 ▶ my $ranges = $delete_spec->{segments} || [];
Condition0%0/2
$delete_spec->{'segments'} || []
l!l
00
MC/DC0%0/1
$delete_spec->{'segments'} || []
$delete_spec->{'segments'}
Truth table0%0/2
A
A= $delete_spec->{'segments'}
Aresult
11
00
1317 0 ▶ my $types = $delete_spec->{types} || [];
Condition0%0/2
$delete_spec->{'types'} || []
l!l
00
MC/DC0%0/1
$delete_spec->{'types'} || []
$delete_spec->{'types'}
Truth table0%0/2
A
A= $delete_spec->{'types'}
Aresult
11
00
1318 0 my $force = $delete_spec->{force};
1319 0 my $range_type = $delete_spec->{range_type};
1320 0 my $dbh = $self->features_db;
1321  
1322 0 my $query = 'delete from fdata';
1323 0 my @where;
1324  
1325 my @range_part;
1326 0 for my $segment (@$ranges) {
1327 0 my $ref = $dbh->quote($segment->abs_ref);
1328 0 my $start = $segment->abs_start;
1329 0 my $stop = $segment->abs_stop;
1330 0 ▶ my $range = $range_type eq 'overlaps' ? $self->overlap_query($start,$stop)
Branch: 3 branches
BranchTrueFalseTotal
$range_type eq 'overlaps' ? : 0 0 0
$range_type eq 'contains' ? : 0 0 0
$range_type eq 'contained_in' ? : 0 0 0
1331 : $range_type eq 'contains' ? $self->contains_query($start,$stop)
1332 : $range_type eq 'contained_in' ? $self->contained_in_query($start,$stop)
1333 : $self->throw("Invalid range type '$range_type'");
1334 0 push @range_part,"(lower(fref)=lower($ref) AND $range)";
1335 }
1336 0 ▶ push @where,'('. join(' OR ',@range_part).')' if @range_part;
Branch: 1 branch
BranchTrueFalseTotal
if @range_part 0 0 0
1337  
1338 # get all the types
1339 0 ▶ if (@$types) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$types) 0 0 0
1340 0 my $types_where = $self->types_query($types);
1341 0 my $types_query = "select ftypeid from ftype where $types_where";
1342 0 my $result = $dbh->selectall_arrayref($types_query);
1343 0 my @typeids = map {$_->[0]} @$result;
1344 0 my $typelist = join ',',map{$dbh->quote($_)} @typeids;
1345 0 ▶ $typelist ||= "0"; # don't cause DBI to die with invalid SQL when
Condition0%0/2
$typelist ||= 0
l!l
00
MC/DC0%0/1
$typelist ||= 0
$typelist
Truth table0%0/2
A
A= $typelist
Aresult
11
00
1346 # unknown feature types were requested.
1347 0 push @where,"(ftypeid in ($typelist))";
1348 }
1349 0 ▶ $self->throw("This operation would delete all feature data and -force not specified")
Branch: 1 branch
BranchTrueFalseTotal
unless @where or $force 0 0 0
Condition0%0/3
@where or $force
l!l&&r!l&&!r
000
MC/DC0%0/2
@where or $force
@where $force
Truth table0%0/3
A or B
A= @whereB= $force
ABresult
1X1
011
000
1350 unless @where || $force;
1351 0 ▶ $query .= " where ".join(' and ',@where) if @where;
Branch: 1 branch
BranchTrueFalseTotal
if @where 0 0 0
1352 0 ▶ warn "$query\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
1353 0 my $result = $dbh->do($query);
1354 0 ▶ defined $result or $self->throw($dbh->errstr);
Branch: 1 branch
BranchTrueFalseTotal
defined $result or $self->throw($dbh->errstr) 0 0 0
1355 0 $result;
1356 }
1357  
1358 0 ▶sub make_abscoord_query {
Subroutine make_abscoord_query: not called CC=3 SCAR=24.8
Pod documented
1359 0 my $self = shift;
1360 0 my ($name,$class,$refseq) = @_;
1361 #my $query = GETSEQCOORDS;
1362 0 my $query = $self->getseqcoords_query();
1363 0 my $getforcedseqcoords = $self->getforcedseqcoords_query() ;
1364 0 ▶ if ($name =~ /\*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\*/) 0 0 0
1365 0 $name =~ s/%/\\%/g;
1366 0 $name =~ s/_/\\_/g;
1367 0 $name =~ tr/*/%/;
1368 0 $query =~ s/gname\) = lower/gname) LIKE lower/;
1369 }
1370 0 ▶ defined $refseq
Branch: 1 branch
BranchTrueFalseTotal
defined $refseq ? : 0 0 0
1371 ? $self->dbh->do_query($getforcedseqcoords,$name,$class,$refseq)
1372 : $self->dbh->do_query($query,$name,$class);
1373 }
1374  
1375 0 ▶sub make_aliasabscoord_query {
Subroutine make_aliasabscoord_query: not called CC=2 SCAR=17.9
Pod undocumented
1376 0 my $self = shift;
1377 0 my ($name,$class) = @_;
1378 #my $query = GETALIASCOORDS;
1379 0 my $query = $self->getaliascoords_query();
1380 0 ▶ if ($name =~ /\*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\*/) 0 0 0
1381 0 $name =~ s/%/\\%/g;
1382 0 $name =~ s/_/\\_/g;
1383 0 $name =~ tr/*/%/;
1384 0 $query =~ s/gname\) = lower/gname) LIKE lower/;
1385 }
1386 0 $self->dbh->do_query($query,$name,$class);
1387 }
1388  
1389  
1390 2 1;
« GFF/Aggregator/alignment.pm ↑ Summary GFF/Adaptor/dbi.pm »