lib/Bio/ToolBox/db_helper.pm

filter: Statementstmt 26.2% 200 / 763 Branchbran 12.7% 72 / 564 Conditioncond 19.1% 30 / 157 MC/DCmcdc 2.2% 2 / 91 Subroutinesub 51.1% 23 / 45 Podpod 100% 17 / 17 totaltotal 21.0% 344 / 1637 CC 366 SCAR 68.5
CC
366
Cov
20%
open_db_connection
3341.3
get_db_feature
992.0
verify_or_request_feature_types
904.4
CRAP 946.1
« lib/Bio/ToolBox/Data/file.pm ↑ Summary lib/Bio/ToolBox/db_helper/seqfasta.pm »
1 package Bio::ToolBox::db_helper;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp qw(carp cluck croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Module::Load; # for dynamic loading during runtime
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use List::Util qw(min max sum0 uniqstr);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Statistics::Lite qw(median range stddevp);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use IO::Prompt::Tiny qw(prompt);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Bio::ToolBox::db_helper::constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Bio::ToolBox::utility qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 parse_list
14 format_with_commas
15 sane_chromo_sort
16 5 );
17 5 require Exporter;
18  
19 5 our $VERSION = '2.041';
20  
21 # check values for dynamically loaded helper modules
22 # these are loaded only when needed during runtime to avoid wasting resources
23 5 my $BAM_OK = 0;
24 5 my $BIGBED_OK = 0;
25 5 my $BIGWIG_OK = 0;
26 5 my $SEQFASTA_OK = 0;
27 5 my $USEQ_OK = 0;
28 5 our $BAM_ADAPTER = undef; # preference for which bam adapter to use
29 5 our $BIG_ADAPTER = undef;
30  
31 # define reusable variables
32 5 my %TOTAL_READ_NUMBER; # for rpm calculations
33 my $PRIMARY_ID_WARNING; # for out of date primary IDs
34 5 my %OPENED_DB; # cache for some opened Bio::DB databases
35 5 my %DB_METHODS; # cache for database score methods
36  
37 # score calculators
38 my %SCORE_CALCULATOR_SUB = (
39 1 ▶ 'mean' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
40 1 my $s = shift;
41 1 ▶ return '.' unless scalar( @{$s} );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$s;} 0 1 1
42 1 ▶ return sum0( @{$s} ) / ( scalar( @{$s} ) || 1 );
Condition50%1/2
scalar @{$s;} || 1
l!l
10
MC/DC0%0/1
scalar @{$s;} || 1
scalar @{$s;}
Truth table50%1/2
A
A= scalar @{$s;}
Aresult
11
00
43 },
44 0 ▶ 'sum' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 my $s = shift;
46 0 return sum0( @{$s} );
47 },
48 3 ▶ 'median' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
49 3 my $s = shift;
50 3 ▶ return '.' unless scalar( @{$s} );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$s;} 0 3 3
51 3 return median( @{$s} );
52 },
53 0 ▶ 'min' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
54 0 my $s = shift;
55 0 ▶ return '.' unless scalar( @{$s} );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$s;} 0 0 0
56 0 return min( @{$s} );
57 },
58 0 ▶ 'max' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
59 0 my $s = shift;
60 0 ▶ return '.' unless scalar( @{$s} );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$s;} 0 0 0
61 0 return max( @{$s} );
62 },
63 1 ▶ 'count' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
64 1 my $s = shift;
65 1 return scalar( @{$s} );
66 },
67 1 ▶ 'pcount' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 1 my $s = shift;
69 1 return scalar( @{$s} );
70 },
71 1 ▶ 'ncount' => sub {
Subroutine __ANON__: called CC=2 SCAR=9.7
72  
73 # Convert names into unique counts
74 1 my $s = shift;
75 1 ▶ if ( ref( $s->[0] ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s->[0] eq 'ARRAY') { } 0 1 1
76  
77 # array of arrays, as may be collected from a positioned hash
78 # convert to a single array then count
79 0 my @scores = map { @{$_} } @{$s};
80 0 return scalar( uniqstr(@scores) );
81 }
82 else {
83 1 return scalar( uniqstr( @{$s} ) );
84 }
85 },
86 0 ▶ 'range' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
87  
88 # the range value is 'min-max'
89 0 my $s = shift;
90 0 ▶ return '.' unless scalar( @{$s} );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$s;} 0 0 0
91 0 return range( @{$s} );
92 },
93 0 ▶ 'stddev' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
94  
95 # we are using the standard deviation of the population,
96 # since these are the only scores we are considering
97 0 my $s = shift;
98 0 ▶ return '.' unless scalar( @{$s} );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$s;} 0 0 0
99 0 return stddevp( @{$s} );
100 },
101 0 ▶ 'rpm' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 confess <<NORPM;
103 The rpm methods have been deprecated due to complexity and the variable way of
104 calculating the value. Collect counts and calculate your preferred way.
105 NORPM
106 },
107 0 ▶ 'rpkm' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 0 confess <<NORPM;
109 The rpm methods have been deprecated due to complexity and the variable way of
110 calculating the value. Collect counts and calculate your preferred way.
111 NORPM
112 }
113 5 );
114  
115 # Exported names
116 5 our @ISA = qw(Exporter);
117 5 our @EXPORT_OK = qw(
118 $BAM_ADAPTER
119 $BIG_ADAPTER
120 use_bam_adapter
121 use_big_adapter
122 use_minimum_mapq
123 open_db_connection
124 get_dataset_list
125 verify_or_request_feature_types
126 check_dataset_for_rpm_support
127 get_new_feature_list
128 get_new_genome_list
129 validate_included_feature
130 get_db_feature
131 get_segment_score
132 calculate_score
133 get_chromosome_list
134 low_level_bam_coverage
135 low_level_bam_fetch
136 get_genomic_sequence
137 );
138  
139 ### Open a connection to the SeqFeature Store MySQL database
140  
141 0 ▶sub use_bam_adapter {
Subroutine use_bam_adapter: not called CC=3 SCAR=24.8
Pod documented
142 0 ▶ my $a = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
143 0 ▶ $BAM_ADAPTER = $a if $a;
Branch: 1 branch
BranchTrueFalseTotal
if $a 0 0 0
144 0 return $BAM_ADAPTER;
145 }
146  
147 0 ▶sub use_big_adapter {
Subroutine use_big_adapter: not called CC=3 SCAR=24.8
Pod documented
148 0 ▶ my $a = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
149 0 ▶ $BIG_ADAPTER = $a if $a;
Branch: 1 branch
BranchTrueFalseTotal
if $a 0 0 0
150 0 return $BIG_ADAPTER;
151 }
152  
153 0 ▶sub use_minimum_mapq {
Subroutine use_minimum_mapq: not called CC=4 SCAR=30.0
Pod documented
154 0 my $m = shift;
155 0 ▶ if ( defined $m ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m) 0 0 0
156 0 $m = int $m;
157 0 ▶ unless ( $m >= 0 and $m <= 255 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m >= 0 and $m <= 255) 0 0 0
Condition0%0/3
$m >= 0 and $m <= 255
!ll&&!rl&&r
000
MC/DC0%0/2
$m >= 0 and $m <= 255
$m >= 0 $m <= 255
Truth table0%0/3
A and B
A= $m >= 0B= $m <= 255
ABresult
0X0
100
111
158 0 carp " ERROR: requested mapping quality '$m' out of bounds (0..255).";
159 0 return;
160 }
161 0 $MAPQ = $m;
162 }
163 0 return $MAPQ;
164 }
165  
166 8 ▶sub open_db_connection {
Subroutine open_db_connection: called CC=73 SCAR=81.1
Pod documented
167 8 my $database = shift;
168 8 ▶ my $no_cache = shift || 0;
Condition50%1/2
shift() || 0
l!l
08
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
169 8 ▶ unless ($database) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($database) 0 8 8
170 0 cluck 'ERROR: no database name passed!';
171 0 return;
172 }
173  
174 # first check if it is a database reference
175 8 my $db_ref = ref $database;
176 8 ▶ if ( $db_ref =~ m/DB | big::BigWigSet/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_ref =~ /DB | big::BigWigSet/x) 2 6 8
177  
178 # the provided database is already an open database object
179 # nothing to open, return as is
180 2 return $database;
181 }
182  
183 # check to see if we have already opened it
184 6 ▶ if ( exists $OPENED_DB{$database} and not $no_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OPENED_DB{$database} and not $no_cache) 5 1 6
Condition66%2/3
exists $OPENED_DB{$database} and not $no_cache
!ll&&!rl&&r
105
MC/DC50%1/2
exists $OPENED_DB{$database} and not $no_cache
exists $OPENED_DB{$database} not $no_cache
Truth table66%2/3
A and not(B)
A= exists $OPENED_DB{$database}B= not $no_cache
ABresult
0X0
100
111
185  
186 # return the cached database connection
187 # but NOT if user explicitly requested no cached databases
188 # DO NOT reuse database objects if you have forked!!! Bad things happen
189 5 return $OPENED_DB{$database};
190 }
191  
192 # skip parsed databases
193 1 ▶ return if $database =~ /^Parsed:/; # we don't open parsed annotation files
Branch: 1 branch
BranchTrueFalseTotal
if $database =~ /^Parsed:/ 0 1 1
194  
195 # remove file prefix, just in case
196 1 $database =~ s/^file://;
197  
198 ### Attempt to open the database
199 # we go through a series of checks to determine if it is remote, local,
200 # an indexed big data file, SQLite file, etc
201 # when all else fails, try to open a SQL connection
202 1 my $db;
203 my $error;
204  
205 # check if it is a remote file
206 1 ▶ if ( $database =~ /^(?: https? | ftp)/xi ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($database =~ /^(?: https? | ftp)/xi) { } 0 1 1
elsif (-f $database) { } 1 0 1
elsif (-d $database) { } 0 0 0
207  
208 # a remote Bam database
209 0 ▶ if ( $database =~ /\.bam$/i ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($database =~ /\.bam$/i) { } 0 0 0
elsif ($database =~ /\. (?: bb | bigbed )$/xi) { } 0 0 0
elsif ($database =~ /\. (?: bw | bigwig )$/xi) { } 0 0 0
elsif ($database =~ /\.useq$/) { } 0 0 0
elsif ($database =~ /\.fa (?: sta)? $/xi) { } 0 0 0
210  
211 # open using Bam adaptor
212 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
213 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
214 0 $db = open_bam_db($database);
215 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
216 0 $error .= sprintf " ERROR: could not open remote Bam file '%s'!\n",
217 $database;
218 }
219 }
220 else {
221 0 $error .=
222 " Bam database cannot be loaded because Bio::DB::Sam or Bio::DB::HTS is not installed\n";
223 }
224 }
225  
226 # a remote BigBed database
227 elsif ( $database =~ m/\. (?: bb | bigbed )$/xi ) {
228  
229 # open using BigBed adaptor
230 0 ▶ $BIGBED_OK = _load_bigbed_helper_module() unless $BIGBED_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGBED_OK 0 0 0
231 0 ▶ if ($BIGBED_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGBED_OK) { } 0 0 0
232 0 $db = open_bigbed_db($database);
233 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
234 0 $error .=
235 sprintf " ERROR: could not open remote BigBed file '%s'!\n",
236 $database;
237 }
238 }
239 else {
240 0 $error .=
241 " BigBed database cannot be loaded because Bio::DB::Big or Bio::DB::BigBed is not installed\n";
242 }
243 }
244  
245 # a remote BigWig database
246 elsif ( $database =~ m/\. (?: bw | bigwig )$/xi ) {
247  
248 # open using BigWig adaptor
249 0 ▶ $BIGWIG_OK = _load_bigwig_helper_module() unless $BIGWIG_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
250 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
251 0 $db = open_bigwig_db($database);
252 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
253 0 $error .=
254 sprintf " ERROR: could not open remote BigWig file '%s'!\n",
255 $database;
256 }
257 }
258 else {
259 0 $error .=
260 " BigWig database cannot be loaded because Bio::DB::Big or Bio::DB::BigWig is not installed\n";
261 }
262 }
263  
264 # a remote useq file
265 elsif ( $database =~ /\.useq$/ ) {
266  
267 # uh oh! remote useq files are not supported
268 0 $error .= " ERROR: remote useq files are not supported!\n";
269 }
270  
271 # a remote fasta file???
272 elsif ( $database =~ m/\.fa (?: sta)? $/xi ) {
273  
274 # uh oh! remote fasta files are not supported
275 0 $error .= " ERROR: remote fasta files are not supported!\n";
276 }
277  
278 # a presumed remote directory, presumably of bigwig files
279 else {
280 # open using BigWigSet adaptor
281 0 ▶ $BIGWIG_OK = _load_helper_module('Bio::ToolBox::db_helper::bigwig')
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
282 unless $BIGWIG_OK;
283 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
284 0 $db = open_bigwigset_db($database);
285 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
286 0 $error .=
287 sprintf
288 " ERROR: could not open remote BigWigSet directory '%s'!\n",
289 $database;
290 }
291 }
292 else {
293 0 $error .=
294 " Presumed BigWigSet database cannot be loaded because Bio::DB::BigWigSet is not installed\n";
295 }
296 }
297  
298 }
299  
300 # a local existing file
301 elsif ( -f $database ) {
302  
303 # a Bam database
304 1 ▶ if ( $database =~ /\.bam$/i ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($database =~ /\.bam$/i) { } 0 1 1
elsif ($database =~ /\. (?: bb | bigbed )$/xi) { } 0 1 1
elsif ($database =~ /\. (?: bw | bigwig )$/xi) { } 0 1 1
elsif ($database =~ /\.useq$/i) { } 1 0 1
elsif ($database =~ /\.fa (?:sta)? (?:\.gz)? $/xi) { } 0 0 0
elsif ($database =~ /\. (?: gff3? | gff3?\.gz | db | sqlite )$/xi) { } 0 0 0
elsif ($database =~ /\.cram$/i) { } 0 0 0
305  
306 # open using appropriate bam adaptor
307 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
308 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
309 0 $db = open_bam_db($database);
310 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
311 0 $error .= sprintf " ERROR: could not open local Bam file '%s'!\n",
312 $database;
313 }
314 }
315 else {
316 0 $error .=
317 " Bam database cannot be loaded because Bio::DB::Sam or Bio::DB::HTS is not installed\n";
318 }
319 }
320  
321 # a BigBed database
322 elsif ( $database =~ /\. (?: bb | bigbed )$/xi ) {
323  
324 # open using BigBed adaptor
325 0 ▶ $BIGBED_OK = _load_bigbed_helper_module() unless $BIGBED_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGBED_OK 0 0 0
326 0 ▶ if ($BIGBED_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGBED_OK) { } 0 0 0
327 0 $db = open_bigbed_db($database);
328 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
329 0 $error .=
330 sprintf " ERROR: could not open local BigBed file '%s'!\n",
331 $database;
332 }
333 }
334 else {
335 0 $error .=
336 " BigBed database cannot be loaded because Big::DB::Big or Bio::DB::BigBed is not installed\n";
337 }
338 }
339  
340 # a BigWig database
341 elsif ( $database =~ /\. (?: bw | bigwig )$/xi ) {
342  
343 # open using BigWig adaptor
344 0 ▶ $BIGWIG_OK = _load_bigwig_helper_module() unless $BIGWIG_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
345 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
346 0 $db = open_bigwig_db($database);
347 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
348 0 $error .=
349 sprintf " ERROR: could not open local BigWig file '%s'!\n",
350 $database;
351 }
352 }
353 else {
354 0 $error .=
355 " BigWig database cannot be loaded because Big::DB::Big or Bio::DB::BigWig is not installed\n";
356 }
357 }
358  
359 # a useq database
360 elsif ( $database =~ /\.useq$/i ) {
361  
362 # open using USeq adaptor
363 1 ▶ $USEQ_OK = _load_helper_module('Bio::ToolBox::db_helper::useq')
Branch: 1 branch
BranchTrueFalseTotal
unless $USEQ_OK 1 0 1
364 unless $USEQ_OK;
365 1 ▶ if ($USEQ_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($USEQ_OK) { } 1 0 1
366 1 $db = open_useq_db($database);
367 1 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 1 1
368 0 $error .= sprintf " ERROR: could not open local useq file '%s'!\n",
369 $database;
370 }
371 }
372 else {
373 0 $error .=
374 " Useq database cannot be loaded because Bio::DB::USeq is not installed\n";
375 }
376 }
377  
378 # a Fasta File
379 elsif ( $database =~ /\.fa (?:sta)? (?:\.gz)? $/xi ) {
380  
381 # first try a modern fai indexed adapter
382 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
383 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
384 0 $db = open_indexed_fasta($database);
385 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
386 0 $error .=
387 sprintf " ERROR: could not open indexed fasta file '%s'!\n",
388 $database;
389 }
390 }
391 else {
392 # open using the old slow BioPerl Fasta adaptor
393 0 ▶ $SEQFASTA_OK = _load_helper_module('Bio::ToolBox::db_helper::seqfasta')
Branch: 1 branch
BranchTrueFalseTotal
unless $SEQFASTA_OK 0 0 0
394 unless $SEQFASTA_OK;
395 0 ▶ if ($SEQFASTA_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SEQFASTA_OK) { } 0 0 0
396 0 $db = open_fasta_db($database);
397 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
398 0 $error .= sprintf " ERROR: could not open fasta file '%s'!\n",
399 $database;
400 0 ▶ if ( -e "$database\.index" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$database.index") 0 0 0
401 0 $error .= " Try deleting $database\.index and try again\n";
402 }
403 }
404 }
405 else {
406 0 $error .=
407 " Fasta file could not be loaded because neither Bio::DB::HTS, Bio::DB::Sam, or Bio::DB::Fasta is installed\n";
408 }
409 }
410 }
411  
412 # a gff3 or sqlite database
413 elsif ( $database =~ /\. (?: gff3? | gff3?\.gz | db | sqlite )$/xi ) {
414 0 ▶ $SEQFASTA_OK = _load_helper_module('Bio::ToolBox::db_helper::seqfasta')
Branch: 1 branch
BranchTrueFalseTotal
unless $SEQFASTA_OK 0 0 0
415 unless $SEQFASTA_OK;
416 0 ▶ if ($SEQFASTA_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SEQFASTA_OK) { } 0 0 0
417 0 $db = open_store_db($database);
418 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
419 0 $error .=
420 sprintf " ERROR: could not load SeqFeature database file '%s'\n",
421 $database;
422 }
423 }
424 else {
425 0 $error .=
426 " Module Bio::DB::SeqFeature::Store is required to load GFF and database files\n";
427 }
428 }
429  
430 # a cram database
431 elsif ( $database =~ /\.cram$/i ) {
432  
433 # open using HTS bam adaptor only
434 0 ▶ $BAM_ADAPTER ||= 'hts';
Condition0%0/2
$Bio::ToolBox::db_helper::BAM_ADAPTER ||= "hts"
l!l
00
MC/DC0%0/1
$Bio::ToolBox::db_helper::BAM_ADAPTER ||= "hts"
$Bio::ToolBox::db_helper::BAM_ADAPTER
Truth table0%0/2
A
A= $Bio::ToolBox::db_helper::BAM_ADAPTER
Aresult
11
00
435 0 ▶ if ( $BAM_ADAPTER eq 'sam' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BAM_ADAPTER eq "sam") 0 0 0
436 0 $error .= " ERROR: Only HTS adapters support Cram files!\n";
437 }
438 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
439 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
440 0 $db = open_bam_db($database);
441 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
442 0 $error .= sprintf " ERROR: could not open local Cram file '%s'!\n",
443 $database;
444 }
445 }
446 else {
447 0 $error .=
448 " Cram database cannot be loaded because Bio::DB::HTS is not installed\n";
449 }
450 }
451  
452 # something unrecognized?
453 else {
454 0 $error .=
455 " ERROR! Cannot identify database type based on extension for $database!\n";
456 }
457 }
458  
459 # a directory, presumably of bigwig files
460 elsif ( -d $database ) {
461  
462 # try opening using the BigWigSet adaptor
463 0 ▶ $BIGWIG_OK = _load_bigwig_helper_module() unless $BIGWIG_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
464 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
465 0 $db = open_bigwigset_db($database);
466 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
467 0 $error .=
468 sprintf " ERROR: could not open local BigWigSet directory '%s'!\n",
469 $database;
470 0 $error .= " Does directory contain bigWig .bw files?\n";
471 }
472 }
473 else {
474 0 $error .=
475 " Presumed BigWigSet database cannot be loaded because Bio::DB::Big or Bio::DB::BigWigSet is not installed\n";
476 }
477  
478 # try opening with the Fasta adaptor
479 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
480 0 ▶ $SEQFASTA_OK = _load_helper_module('Bio::ToolBox::db_helper::seqfasta')
Branch: 1 branch
BranchTrueFalseTotal
unless $SEQFASTA_OK 0 0 0
481 unless $SEQFASTA_OK;
482 0 ▶ if ($SEQFASTA_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SEQFASTA_OK) { } 0 0 0
483 0 $db = open_fasta_db($database);
484 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
485 0 $error .= " ERROR: could not open fasta directory '$database'!\n";
486 0 $error .=
487 " Does directory contain fasta files? If it contains a directory.index file,\n try deleting it and try again.\n";
488 }
489 }
490 else {
491 0 $error .=
492 " Module Bio::DB::Fasta is required to open presumed fasta directory\n";
493 }
494 }
495 }
496  
497 # otherwise assume the name of a SeqFeature::Store database in the configuration
498 else {
499 # attempt to open using information from the configuration
500 # using default connection information as necessary
501 0 ▶ $SEQFASTA_OK = _load_helper_module('Bio::ToolBox::db_helper::seqfasta')
Branch: 1 branch
BranchTrueFalseTotal
unless $SEQFASTA_OK 0 0 0
502 unless $SEQFASTA_OK;
503 0 ▶ if ($SEQFASTA_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SEQFASTA_OK) { } 0 0 0
504 0 $db = open_store_db($database);
505 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
506 0 $error .= " unable to open relational database named '$database'\n";
507 }
508 }
509 else {
510 0 $error .=
511 " Module Bio::DB::SeqFeature::Store is required to connect to databases\n";
512 }
513 }
514  
515 # conditional return
516 1 ▶ if ($db) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db) { } 1 0 1
517  
518 # cache the opened connection for use later
519 1 ▶ $OPENED_DB{$database} = $db unless $no_cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_cache 1 0 1
520  
521 # return as appropriate either both object and name or just object
522 1 return $db;
523 }
524 else {
525 0 print STDERR $error;
526 0 return;
527 }
528 }
529  
530 ### Retrieve a database name from an db object
531 0 ▶sub get_db_name {
Subroutine get_db_name: not called CC=6 SCAR=37.4
Pod documented
532 0 my $db = shift;
533 0 ▶ return unless $db;
Branch: 1 branch
BranchTrueFalseTotal
unless $db 0 0 0
534 0 my $db_ref = ref $db;
535 0 ▶ return $db unless $db_ref; # presumption that non-object is just a database name
Branch: 1 branch
BranchTrueFalseTotal
unless $db_ref 0 0 0
536 0 my $db_name;
537 0 ▶ if ( $db_ref =~ /^Bio::DB::SeqFeature::Store/x ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($db_ref =~ /^Bio::DB::SeqFeature::Store/x) { } 0 0 0
elsif ($db_ref eq 'Bio::DB::Sam') { } 0 0 0
elsif ($db_ref eq 'Bio::DB::HTS') { } 0 0 0
538  
539 # a SeqFeature database, using any DBI adapter
540 0 $db_name = $db->{'dbh'}->{'name'};
541  
542 # dig through the object internals to identify the original
543 # name of the database
544 # this should be relatively well documented through DBI
545 # but could break in the future since it's not official API
546 }
547 elsif ( $db_ref eq 'Bio::DB::Sam' ) {
548  
549 # a Samtools Bam database
550 # old versions <=1.39 don't have the bam_path method, so it's easier
551 # to explicitly grab it from the object internals
552 0 $db_name = $db->{bam_path};
553 }
554 elsif ( $db_ref eq 'Bio::DB::HTS' ) {
555  
556 # a HTSlib Bam database
557 0 $db_name = $db->hts_path;
558 }
559  
560 # determining the database name from other sources is
561 # either not possible or not easy, so won't bother unless
562 # there is a really really good need
563 0 return $db_name;
564 }
565  
566 ### Retrieve a list of the microrarray data sets from the db
567 0 ▶sub get_dataset_list {
Subroutine get_dataset_list: not called CC=12 SCAR=50.5
Pod documented
568  
569 0 my $database = shift;
570 0 my $use_all_features = shift;
571  
572 # Open a db connection
573 0 my $db = open_db_connection($database);
574 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
575 0 carp 'ERROR: no database connected!';
576 0 return;
577 }
578 0 my $db_ref = ref $db;
579  
580 # process the database types, according to the type of database
581 0 my @types;
582  
583 # a SeqFeature database
584 0 ▶ if ( $db_ref =~ /^Bio::DB::SeqFeature::Store/x ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($db_ref =~ /^Bio::DB::SeqFeature::Store/x) { } 0 0 0
elsif ($db_ref =~ /BigWigSet/i) { } 0 0 0
585  
586 # collect the database types,
587 # sort first by source, then by method
588 @types = (
589 0 map { $_->[2] }
590 0 ▶ sort { ( $a->[0] cmp $b->[0] ) or ( $a->[1] cmp $b->[1] ) }
Condition0%0/3
$Bio::ToolBox::db_helper::a->[0] cmp $Bio::ToolBox::db_helper::b->[0] || $Bio::ToolBox::db_helper::a->[1] cmp $Bio::ToolBox::db_helper::b->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$Bio::ToolBox::db_helper::a->[0] cmp $Bio::ToolBox::db_helper::b->[0] || $Bio::ToolBox::db_helper::a->[1] cmp $Bio::ToolBox::db_helper::b->[1]
$Bio::ToolBox::db_helper::a->[0] cmp $Bio::ToolBox::db_helper::b->[0] $Bio::ToolBox::db_helper::a->[1] cmp $Bio::ToolBox::db_helper::b->[1]
Truth table0%0/3
A || B
A= $Bio::ToolBox::db_helper::a->[0] cmp $Bio::ToolBox::db_helper::b->[0]B= $Bio::ToolBox::db_helper::a->[1] cmp $Bio::ToolBox::db_helper::b->[1]
ABresult
1X1
011
000
591 0 map { [ $_->source, $_->method, $_ ] } ( $db->types )
592 );
593 }
594  
595 # a BigWigSet database
596 elsif ( $db_ref =~ /BigWigSet/i ) {
597  
598 # get the metadata
599 0 my $metadata = $db->metadata;
600  
601 # collect
602 0 foreach my $file ( keys %{$metadata} ) {
603  
604 # get the type for each file
605 0 my ( $primary, $type, $name );
606  
607 # get the appropriate tags
608 0 foreach my $attribute ( keys %{ $metadata->{$file} } ) {
609 0 ▶ if ( $attribute =~ m/^type/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($attribute =~ /^type/i) { } 0 0 0
elsif ($attribute =~ /name/i) { } 0 0 0
elsif ($attribute =~ /^primary_tag | method$/xi) { } 0 0 0
610 0 $type = $metadata->{$file}{$attribute};
611 }
612 elsif ( $attribute =~ m/name/i ) {
613 0 $name = $metadata->{$file}{$attribute};
614 }
615 elsif ( $attribute =~ m/^primary_tag | method$/xi ) {
616 0 $primary = $metadata->{$file}{$attribute};
617 }
618 }
619  
620 # store the type
621 0 ▶ push @types, $type || $primary || $name;
Condition0%0/6
$type || $primary || $name
l!l&&r!l&&!r
000
$type or $primary
l!l&&r!l&&!r
000
MC/DC0%0/3
$type || $primary || $name
$type $primary $name
Truth table0%0/4
A or B || C
A= $typeB= $primaryC= $name
ABCresult
1XX1
01X1
0011
0000
622 }
623  
624 # sort the types in alphabetical order
625 # and discard duplicate types - which may occur with stranded entries
626 0 @types = uniqstr( sort { $a cmp $b } @types );
627 }
628  
629 # some other database
630 else {
631 0 carp "ERROR: no dataset lists for database type $db_ref!";
632 }
633  
634 # finish
635 0 return @types;
636 }
637  
638 ### Process and verify a dataset
639 1 ▶sub verify_or_request_feature_types {
Subroutine verify_or_request_feature_types: called CC=45 SCAR=68.1
Pod documented
640  
641 # Retrieve passed values
642 1 my %args = @_; # the passed argument values as a hash reference
643  
644 # Check for single option
645 1 ▶ $args{'single'} ||= 0;
Condition50%1/2
$args{"single"} ||= 0
l!l
01
MC/DC0%0/1
$args{"single"} ||= 0
$args{"single"}
Truth table50%1/2
A
A= $args{"single"}
Aresult
11
00
646  
647 # Collect the datasets
648 1 my @datasets;
649 1 ▶ $args{'feature'} ||= undef;
Condition50%1/2
$args{"feature"} ||= undef
l!l
10
MC/DC0%0/1
$args{"feature"} ||= undef
$args{"feature"}
Truth table50%1/2
A
A= $args{"feature"}
Aresult
11
00
650 1 ▶ if ( ref( $args{'feature'} ) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args{'feature'} eq 'ARRAY') { } 0 1 1
elsif (defined $args{'feature'}) { } 1 0 1
651  
652 # an anonymous array of datasets
653 0 @datasets = @{ $args{'feature'} };
654 }
655 elsif ( defined $args{'feature'} ) {
656 1 push @datasets, $args{'feature'};
657 }
658  
659 # else it is null and @datasets remains empty, prompting user input
660  
661 # feature limits
662 # this is a regex to limit the feature types presented to the user
663 # otherwise everything in the database is presented to the user
664 1 ▶ my $limit = $args{'limit'} ||= undef;
Condition50%1/2
$args{"limit"} ||= undef
l!l
01
MC/DC0%0/1
$args{"limit"} ||= undef
$args{"limit"}
Truth table50%1/2
A
A= $args{"limit"}
Aresult
11
00
665  
666 # Open database object and collect features
667 1 ▶ $args{'db'} ||= undef;
Condition50%1/2
$args{"db"} ||= undef
l!l
10
MC/DC0%0/1
$args{"db"} ||= undef
$args{"db"}
Truth table50%1/2
A
A= $args{"db"}
Aresult
11
00
668 1 ▶ my $db = $args{'db'} ? open_db_connection( $args{'db'} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'db'} ? : 1 0 1
669  
670 # Initialize main output arrays
671 1 my @good_datasets;
672 my @bad_datasets;
673 1 my %db_features; # hash for features found in the database, use when needed
674  
675 # Check provided datasets
676 1 ▶ if (@datasets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@datasets) { } 1 0 1
677  
678 # check for multiple comma-delimited datasets
679 1 my @list_to_check;
680 1 foreach my $item (@datasets) {
681 1 ▶ if ( $item =~ /,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /,/) { } 0 1 1
682  
683 # this one has a comma, therefore it has more than dataset
684 0 push @list_to_check, split( /,/, $item );
685 }
686 else {
687 # a singleton
688 1 push @list_to_check, $item;
689 }
690 }
691  
692 # now verify the datasets
693 1 foreach my $dataset (@list_to_check) {
694  
695 # check for a remote file
696 1 ▶ if ( $dataset =~ m/^(?: http | ftp) .+ \. (?: bam | bw | bb) $/xi ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dataset =~ /^(?: http | ftp) .+ \. (?: bam | bw | bb) $/xi) { } 0 1 1
elsif ($dataset =~ /\. (?: bam | bw | bigwig | bb | bigbed | useq)$/xi) { } 1 0 1
697  
698 # a remote file
699 # assume it is good, no verification here though
700 # it will either work or won't work
701 0 push @good_datasets, $dataset;
702 }
703  
704 # a local file
705 elsif ( $dataset =~ m/\. (?: bam | bw | bigwig | bb | bigbed | useq)$/xi ) {
706  
707 # presume we have a local indexed data file
708  
709 # user may have requested two or more files to be merged
710 # these should be combined with an ampersand
711 # check each one
712 1 my @files;
713 1 foreach my $file ( split /\&/, $dataset ) {
714 1 ▶ if ( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) { } 1 0 1
715  
716 # file exists
717 1 push @files, "file:$file";
718 }
719 else {
720 # file doesn't exist! can't use this set of files
721 0 @files = ();
722 0 last;
723 }
724 }
725 1 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 1 0 1
726 1 push @good_datasets, join( '&', @files );
727 }
728 else {
729 0 push @bad_datasets, $dataset;
730 }
731 }
732  
733 # a feature type in a database
734 else {
735 # must be a database feature type
736  
737 # check for database features hash
738 0 ▶ unless (%db_features) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%db_features) 0 0 0
739 0 ▶ if ($db) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db) { } 0 0 0
740  
741 # collect the database features as needed
742 # I want both method:source and method in the hash
743 0 foreach my $type ( get_dataset_list($db) ) {
744 0 my ( $method, $source ) = split /:/, $type;
745 0 ▶ if ($source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source) { } 0 0 0
746 0 $db_features{$type} = 1;
747 0 $db_features{$method} = 1;
748 }
749 else {
750 0 $db_features{$type} = 1;
751 }
752 }
753  
754 # verify
755 0 ▶ unless (%db_features) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%db_features) 0 0 0
756 0 carp
757 'ERROR: provided database has no feature types to verify dataset(s) against!';
758 0 return;
759 }
760 }
761 else {
762 # we need a database
763 0 carp 'ERROR: unable to verify dataset without database';
764 0 return;
765 }
766 }
767  
768 # validate the given dataset
769 # user may have requested two or more features to be merged
770 # these should be combined with an ampersand
771 # check each one
772 0 my $check = 0;
773 0 foreach my $d ( split /&/, $dataset ) {
774  
775 # validate this dataset
776 0 ▶ if ( exists $db_features{$d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $db_features{$d}) { } 0 0 0
777 0 $check++;
778 }
779 else {
780 # at least one of these is not good, fail check
781 0 $check = 0;
782 0 last;
783 }
784 }
785  
786 # report the verification
787 0 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) { } 0 0 0
788 0 push @good_datasets, $dataset;
789 }
790 else {
791 0 push @bad_datasets, $dataset;
792 }
793 }
794 }
795 }
796  
797 # User must select datasets
798 else {
799 # dataset not specified
800 # present the dataset list to the user and get an answer
801  
802 # get the dataset list
803 0 ▶ if ($db) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db) { } 0 0 0
804  
805 # collect the database features as needed
806 0 my $i = 1;
807 0 foreach my $type ( get_dataset_list($db) ) {
808 0 ▶ if ($limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit) 0 0 0
809 0 my ( $p, $s ) = split /:/, $type; # split into primary_tag and source
810 # only keep those types that match our limiter
811 0 ▶ next unless $p =~ /$limit/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ /$limit/i 0 0 0
812 }
813 0 $db_features{$i} = $type;
814 0 $i++;
815 }
816  
817 # verify
818 0 ▶ unless (%db_features) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%db_features) 0 0 0
819 0 carp 'ERROR: provided database has no feature types to collect!';
820 0 return;
821 }
822 }
823 else {
824 # we need a database
825 0 carp 'ERROR: no database provided from which to collect features!';
826 0 return;
827 }
828  
829 # present the list
830 0 print "\n These are the available data sets in the database:\n";
831 0 foreach ( sort { $a <=> $b } keys %db_features ) {
832  
833 # print out the list of microarray data sets
834 0 print " $_\t$db_features{$_}\n";
835 }
836  
837 # set a generic prompt as necessary
838 0 ▶ $args{'prompt'} ||= undef;
Condition0%0/2
$args{"prompt"} ||= undef
l!l
00
MC/DC0%0/1
$args{"prompt"} ||= undef
$args{"prompt"}
Truth table0%0/2
A
A= $args{"prompt"}
Aresult
11
00
839 0 ▶ if ( not defined $args{'prompt'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"prompt"}) 0 0 0
840 0 ▶ if ( $args{'single'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'single'}) { } 0 0 0
841 0 $args{'prompt'} = ' Enter one number for the data set or feature ';
842 }
843 else {
844 0 $args{'prompt'} =
845 ' Enter the number(s) or range of the data set(s) or feature(s) ';
846 }
847 }
848  
849 # get answer from the user
850 0 my $answer = prompt( $args{'prompt'} );
851 0 my @answer_list = parse_list($answer);
852  
853 # take the first one if requested
854 0 ▶ if ( $args{'single'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"single"}) 0 0 0
855 0 ▶ unless ( scalar @answer_list == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @answer_list == 1) 0 0 0
856 0 splice( @answer_list, 1 );
857 }
858 }
859  
860 # verify the answer list
861 0 foreach my $answer (@answer_list) {
862  
863 # check for merged datasets
864 0 ▶ if ( $answer =~ /&/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer =~ /&/) { } 0 0 0
865  
866 # a merged dataset
867 0 my @list = split /&/, $answer;
868 0 my $check = 1;
869  
870 # check all are good
871 0 foreach (@list) {
872 0 ▶ unless ( exists $db_features{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $db_features{$_}) 0 0 0
873 0 $check = 0;
874 }
875 }
876  
877 # if all are good
878 0 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) { } 0 0 0
879 0 push @good_datasets, join( '&', map { $db_features{$_} } @list );
880 }
881 else {
882 0 push @bad_datasets, $answer;
883 }
884 }
885  
886 else {
887 # a single dataset
888 # check if it is good
889  
890 0 ▶ if ( exists $db_features{$answer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $db_features{$answer}) { } 0 0 0
891 0 push @good_datasets, $db_features{$answer};
892 }
893 else {
894 0 push @bad_datasets, $db_features{$answer};
895 }
896 }
897 }
898 }
899  
900 # Print bad results
901 1 ▶ if (@bad_datasets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad_datasets) 0 1 1
902 0 print " The following datasets could not be verified:\n";
903 0 foreach (@bad_datasets) {
904 0 print " $_\n";
905 }
906 }
907  
908 # Return good results
909 1 ▶ if ( $args{'single'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'single'}) { } 0 1 1
910 0 return $good_datasets[0];
911 }
912 else {
913 1 return @good_datasets;
914 }
915 }
916  
917 ### Process and verify a dataset
918 0 ▶sub check_dataset_for_rpm_support {
Subroutine check_dataset_for_rpm_support: not called CC=12 SCAR=50.5
Pod documented
919  
920 # get passed dataset and databases
921 0 my $dataset = shift;
922 0 my $cpu = shift;
923  
924 # Calculate the total number of reads
925 0 my $rpm_read_sum;
926  
927 0 ▶ if ( exists $TOTAL_READ_NUMBER{$dataset} ) {
Branch: 4 branches
BranchTrueFalseTotal
if (exists $TOTAL_READ_NUMBER{$dataset}) { } 0 0 0
elsif ($dataset =~ /\.bam$/) { } 0 0 0
elsif ($dataset =~ /\.cram$/) { } 0 0 0
elsif ($dataset =~ /\.bb$/) { } 0 0 0
928  
929 # this dataset has already been summed
930 # no need to do it again
931 0 return $TOTAL_READ_NUMBER{$dataset};
932 }
933  
934 elsif ( $dataset =~ /\.bam$/ ) {
935  
936 # a bam file dataset
937  
938 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
939 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
940  
941 # adapter was loaded ok
942 # sum the number of reads in the dataset
943 0 $rpm_read_sum = sum_total_bam_alignments( $dataset, $cpu );
944 }
945 else {
946 0 carp
947 'ERROR: Bam support is not available! Is Bio::DB::Sam or Bio::DB::HTS installed?';
948 0 return;
949 }
950 }
951  
952 elsif ( $dataset =~ /\.cram$/ ) {
953  
954 # a cram file dataset
955  
956 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
957 0 ▶ if ( $BAM_OK and lc $BAM_ADAPTER eq 'hts' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK and lc $Bio::ToolBox::db_helper::BAM_ADAPTER eq 'hts') { } 0 0 0
Condition0%0/3
$BAM_OK and lc $Bio::ToolBox::db_helper::BAM_ADAPTER eq "hts"
!ll&&!rl&&r
000
MC/DC0%0/2
$BAM_OK and lc $Bio::ToolBox::db_helper::BAM_ADAPTER eq "hts"
$BAM_OK lc $Bio::ToolBox::db_helper::BAM_ADAPTER eq "hts"
Truth table0%0/3
A and B
A= $BAM_OKB= lc $Bio::ToolBox::db_helper::BAM_ADAPTER eq "hts"
ABresult
0X0
100
111
958  
959 # adapter was loaded ok
960 # sum the number of reads in the dataset
961 0 $rpm_read_sum = sum_total_bam_alignments( $dataset, $cpu );
962 }
963 else {
964 0 carp 'ERROR: Cram support requires Bio::DB::HTS to be installed';
965 0 return;
966 }
967 }
968  
969 elsif ( $dataset =~ /\.bb$/ ) {
970  
971 # a bigbed file dataset
972  
973 0 ▶ $BIGBED_OK = _load_helper_module('Bio::ToolBox::db_helper::bigbed')
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGBED_OK 0 0 0
974 unless $BIGBED_OK;
975 0 ▶ if ($BIGBED_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGBED_OK) { } 0 0 0
976  
977 # Bio::ToolBox::db_helper::bigbed was loaded ok
978 # sum the number of features in the dataset
979 0 $rpm_read_sum = sum_total_bigbed_features($dataset);
980 }
981 else {
982 0 carp 'ERROR: BigBed support is not available! Is Bio::DB::BigBed installed?';
983 0 return;
984 }
985 }
986  
987 else {
988 # some other non-supported dataset
989 0 return;
990 }
991  
992 # return the sum value if we've made it this far
993 0 $TOTAL_READ_NUMBER{$dataset} = $rpm_read_sum;
994 0 return $rpm_read_sum;
995 }
996  
997 ### Generate a new list of features
998 0 ▶sub get_new_feature_list {
Subroutine get_new_feature_list: not called CC=16 SCAR=56.1
Pod documented
999  
1000 # Retrieve passed values
1001 0 my %args = @_; # the passed argument values
1002  
1003 # check data object
1004 0 ▶ my $data = $args{data} || undef;
Condition0%0/2
$args{'data'} || undef
l!l
00
MC/DC0%0/1
$args{'data'} || undef
$args{'data'}
Truth table0%0/2
A
A= $args{'data'}
Aresult
11
00
1005 0 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 0 0
1006 0 confess q(FATAL: must pass a 'data' key and Bio::ToolBox::Data object!);
1007 0 return;
1008 }
1009 0 ▶ unless ( ref($data) eq 'Bio::ToolBox::Data' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "Bio::ToolBox::Data") 0 0 0
1010 0 confess 'FATAL: must pass a Bio::ToolBox::Data object!';
1011 0 return;
1012 }
1013  
1014 # Open a db connection
1015 0 ▶ $args{'db'} ||= undef;
Condition0%0/2
$args{"db"} ||= undef
l!l
00
MC/DC0%0/1
$args{"db"} ||= undef
$args{"db"}
Truth table0%0/2
A
A= $args{"db"}
Aresult
11
00
1016 0 my $db = open_db_connection( $args{'db'} );
1017 0 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
1018 0 carp 'ERROR: no database connected!';
1019 0 return;
1020 }
1021  
1022 # Verify a SeqFeature::Store database
1023 0 my $db_ref = ref $db;
1024 0 ▶ unless ( $db_ref =~ m/^Bio::DB::SeqFeature::Store/x ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db_ref =~ /^Bio::DB::SeqFeature::Store/x) 0 0 0
1025 0 carp "ERROR: Database type $db_ref doesn't support generating feature lists!";
1026 0 return;
1027 }
1028  
1029 # Features to search for
1030 0 ▶ my $searchFeature = $args{'feature'} || $args{'features'} || undef;
Condition0%0/5
$args{'feature'} || $args{'features'} || undef
l!l
00
$args{"feature"} or $args{"features"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'feature'} || $args{'features'} || undef
$args{"feature"} $args{"features"}
Truth table0%0/3
A or B
A= $args{"feature"}B= $args{"features"}
ABresult
1X1
011
000
1031 0 ▶ unless ($searchFeature) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($searchFeature) 0 0 0
1032 0 carp 'ERROR: no search feature types passed!';
1033 0 return;
1034 }
1035 0 my @classes = split /,/, $searchFeature; # it may or may not be a list
1036  
1037 # chromosomes to skip
1038 0 ▶ my $chr_exclude = $args{'chrskip'} || undef;
Condition0%0/2
$args{'chrskip'} || undef
l!l
00
MC/DC0%0/1
$args{'chrskip'} || undef
$args{'chrskip'}
Truth table0%0/2
A
A= $args{'chrskip'}
Aresult
11
00
1039  
1040 # Add table columns
1041 0 my $pid_i = $data->add_column('Primary_ID');
1042 0 my $name_i = $data->add_column('Name');
1043 0 my $type_i = $data->add_column('Type');
1044  
1045 # Set up the database iterator
1046 0 print " Searching for $searchFeature features\n";
1047 0 ▶ my $iterator =
Branch: 1 branch
BranchTrueFalseTotal
scalar @classes ? : 0 0 0
1048 $db->get_seq_stream( -types => scalar @classes ? \@classes : $searchFeature, );
1049 0 ▶ unless ($iterator) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iterator) 0 0 0
1050  
1051 # there should be some features found in the database
1052 0 carp 'ERROR: could not get feature iterator for database';
1053 0 return;
1054 }
1055  
1056 # Walk through the collected features
1057 0 my $total_count = 0; # total found features
1058 0 ▶ while ( my $feature = $iterator->next_seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $feature = $iterator->next_seq) 0 0 0
1059 0 $total_count++;
1060  
1061 # skip genes from excluded chromosomes
1062 0 ▶ next if ( defined $chr_exclude and $feature->seq_id =~ $chr_exclude );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $feature->seq_id =~ /$chr_exclude/ 0 0 0
Condition0%0/3
defined $chr_exclude and $feature->seq_id =~ /$chr_exclude/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $feature->seq_id =~ /$chr_exclude/
defined $chr_exclude $feature->seq_id =~ /$chr_exclude/
Truth table0%0/3
A and B
A= defined $chr_excludeB= $feature->seq_id =~ /$chr_exclude/
ABresult
0X0
100
111
1063  
1064 # Record the feature information
1065 # in the B::DB::SF::S database, the primary_ID is a number unique to the
1066 # the specific database, and is not portable between databases
1067 0 $data->add_row(
1068 [ $feature->primary_id, $feature->display_name, $feature->type, ] );
1069 }
1070  
1071 # print result of search
1072 0 printf " Found %s features in the database\n", format_with_commas($total_count);
1073 0 printf " Kept %s features.\n", format_with_commas( $data->last_row );
1074  
1075 # return the new data structure
1076 0 return 1;
1077 }
1078  
1079 ### Generate a new list genomic windows
1080 1 ▶sub get_new_genome_list {
Subroutine get_new_genome_list: called CC=23 SCAR=42.6
Pod documented
1081  
1082 # Collect the passed arguments
1083 1 my %args = @_;
1084  
1085 # check data object
1086 1 ▶ my $data = $args{data} || undef;
Condition50%1/2
$args{'data'} || undef
l!l
10
MC/DC0%0/1
$args{'data'} || undef
$args{'data'}
Truth table50%1/2
A
A= $args{'data'}
Aresult
11
00
1087 1 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 1 1
1088 0 confess q(FATAL: must pass a 'data' key and Bio::ToolBox::Data object!);
1089 }
1090 1 ▶ unless ( ref($data) eq 'Bio::ToolBox::Data' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "Bio::ToolBox::Data") 0 1 1
1091 0 confess 'FATAL: must pass a Bio::ToolBox::Data object!';
1092 }
1093  
1094 # Open a db connection
1095 1 ▶ $args{'db'} ||= undef;
Condition50%1/2
$args{"db"} ||= undef
l!l
10
MC/DC0%0/1
$args{"db"} ||= undef
$args{"db"}
Truth table50%1/2
A
A= $args{"db"}
Aresult
11
00
1096 1 my $db = open_db_connection( $args{'db'} );
1097 1 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 1 1
1098 0 carp 'ERROR: no database connected!';
1099 0 return;
1100 }
1101  
1102 # Determine win and step sizes
1103 1 ▶ $args{'win'} ||= 500; # hard coded default size
Condition50%1/2
$args{"win"} ||= 500
l!l
10
MC/DC0%0/1
$args{"win"} ||= 500
$args{"win"}
Truth table50%1/2
A
A= $args{"win"}
Aresult
11
00
1104 1 ▶ $args{'step'} ||= $args{'win'};
Condition33%1/3
$args{"step"} ||= $args{"win"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"step"} ||= $args{"win"}
$args{"step"} $args{"win"}
Truth table33%1/3
A ||= B
A= $args{"step"}B= $args{"win"}
ABresult
1X1
011
000
1105  
1106 # Prepare data structures
1107 1 my $chr_i = $data->add_column('Chromosome');
1108 1 my $start_i = $data->add_column('Start');
1109 1 my $stop_i = $data->add_column('Stop');
1110 1 $data->metadata( $start_i, 'win', $args{'win'} );
1111 1 $data->metadata( $start_i, 'step', $args{'step'} );
1112  
1113 # Collect the chromosomes
1114 1 ▶ my $chr_exclude = $args{'skip'} || $args{'chrskip'} || undef;
Condition40%2/5
$args{'skip'} || $args{'chrskip'} || undef
l!l
01
$args{"skip"} or $args{"chrskip"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args{'skip'} || $args{'chrskip'} || undef
$args{"skip"} $args{"chrskip"}
Truth table33%1/3
A or B
A= $args{"skip"}B= $args{"chrskip"}
ABresult
1X1
011
000
1115 1 my @chromosomes = get_chromosome_list( $db, $chr_exclude );
1116 1 ▶ unless (@chromosomes) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@chromosomes) 0 1 1
1117 0 carp 'ERROR: no sequence IDs were found in the database!';
1118 0 return;
1119 }
1120  
1121 # Load exclusion intervals
1122 1 my %exclusion_tree;
1123 1 ▶ $args{exclude} ||= $args{blacklist} || undef;
Condition40%2/5
$args{"exclude"} ||= $args{"blacklist"} || undef
l!l&&r!l&&!r
001
$args{'blacklist'} || undef
l!l
01
MC/DC0%0/2
$args{"exclude"} ||= $args{"blacklist"} || undef
$args{"exclude"} $args{'blacklist'}
Truth table33%1/3
A ||= B
A= $args{"exclude"}B= $args{'blacklist'}
ABresult
1X1
011
000
1124 1 ▶ if ( exists $args{exclude} and defined $args{exclude} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"exclude"} and defined $args{"exclude"}) 0 1 1
Condition33%1/3
exists $args{"exclude"} and defined $args{"exclude"}
!ll&&!rl&&r
010
MC/DC0%0/2
exists $args{"exclude"} and defined $args{"exclude"}
exists $args{"exclude"} defined $args{"exclude"}
Truth table33%1/3
A and B
A= exists $args{"exclude"}B= defined $args{"exclude"}
ABresult
0X0
100
111
1125 0 ▶ if ( ref( $args{exclude} ) eq 'Bio::ToolBox::Data' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{'exclude'} eq 'Bio::ToolBox::Data') { } 0 0 0
1126 0 ▶ if ( _load_helper_module('Set::IntervalTree') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_load_helper_module('Set::IntervalTree')) { } 0 0 0
1127  
1128 # iterate through the data object of intervals
1129 # prepare an Interval Tree for each chromosome
1130 # and load the exclusion interval into it
1131 $args{exclude}->iterate(
1132 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1133 0 my $row = shift;
1134 0 ▶ unless ( exists $exclusion_tree{ $row->seq_id } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $exclusion_tree{$row->seq_id}) 0 0 0
1135 0 $exclusion_tree{ $row->seq_id } =
1136 Set::IntervalTree->new();
1137 }
1138 0 $exclusion_tree{ $row->seq_id }
1139 ->insert( 1, $row->start - 1, $row->end );
1140 }
1141 0 );
1142 }
1143 else {
1144 0 carp
1145 'ERROR: Set::IntervalTree must be installed to use exclusion intervals!';
1146 }
1147 }
1148 else {
1149 0 carp 'ERROR: Exclusion data must be a Bio::ToolBox::Data object!';
1150 }
1151 }
1152  
1153 # Collect the genomic windows
1154 1 print " Generating $args{win} bp windows in $args{step} bp increments\n";
1155 1 foreach (@chromosomes) {
1156  
1157 # name and length as sub-array in each element
1158 1 my ( $chr, $length ) = @{$_};
1159 1 ▶ my $Tree = $exclusion_tree{$chr} || undef;
Condition50%1/2
$exclusion_tree{$chr} || undef
l!l
01
MC/DC0%0/1
$exclusion_tree{$chr} || undef
$exclusion_tree{$chr}
Truth table50%1/2
A
A= $exclusion_tree{$chr}
Aresult
11
00
1160  
1161 # iterate through chromosome
1162 1 ▶ for ( my $start = 1; $start <= $length; $start += $args{step} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start <= $length) 122 1 123
1163 122 my $end = $start + $args{win} - 1;
1164 122 ▶ if ( $end > $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end > $length) 1 121 122
1165  
1166 # fix end to the length of the chromosome
1167 1 $end = $length;
1168 }
1169  
1170 # skip if excluded
1171 0 ▶ next if ( $Tree and scalar( @{ $Tree->fetch( $start - 1, $end ) } ) >= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $Tree and scalar @{$Tree->fetch($start - 1, $end);} >= 1 0 122 122
Condition33%1/3
$Tree and scalar @{$Tree->fetch($start - 1, $end);} >= 1
!ll&&!rl&&r
12200
MC/DC0%0/2
$Tree and scalar @{$Tree->fetch($start - 1, $end);} >= 1
$Tree scalar @{$Tree->fetch($start - 1, $end);} >= 1
Truth table33%1/3
A and B
A= $TreeB= scalar @{$Tree->fetch($start - 1, $end);} >= 1
ABresult
0X0
100
111
1172 122 $data->add_row( [ $chr, $start, $end ] );
1173 }
1174 }
1175 1 printf " Kept %d windows.\n", $data->number_rows;
1176  
1177 # Return the data structure
1178 1 return 1;
1179 }
1180  
1181 0 ▶sub get_db_feature {
Subroutine get_db_feature: not called CC=31 SCAR=69.0
Pod documented
1182 0 my %args = @_;
1183  
1184 # Open a db connection
1185 0 ▶ $args{db} ||= undef;
Condition0%0/2
$args{"db"} ||= undef
l!l
00
MC/DC0%0/1
$args{"db"} ||= undef
$args{"db"}
Truth table0%0/2
A
A= $args{"db"}
Aresult
11
00
1186 0 ▶ unless ( $args{db} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"db"}) 0 0 0
1187 0 croak 'FATAL: no database provided for getting a feature!';
1188 }
1189 0 my $db = open_db_connection( $args{db} );
1190 0 my $db_ref = ref $db;
1191  
1192 # check for values and internal nulls
1193 0 ▶ $args{'id'} ||= undef;
Condition0%0/2
$args{"id"} ||= undef
l!l
00
MC/DC0%0/1
$args{"id"} ||= undef
$args{"id"}
Truth table0%0/2
A
A= $args{"id"}
Aresult
11
00
1194 0 ▶ $args{'name'} ||= undef;
Condition0%0/2
$args{"name"} ||= undef
l!l
00
MC/DC0%0/1
$args{"name"} ||= undef
$args{"name"}
Truth table0%0/2
A
A= $args{"name"}
Aresult
11
00
1195 0 ▶ $args{'type'} ||= undef;
Condition0%0/2
$args{"type"} ||= undef
l!l
00
MC/DC0%0/1
$args{"type"} ||= undef
$args{"type"}
Truth table0%0/2
A
A= $args{"type"}
Aresult
11
00
1196 0 ▶ undef $args{'name'} if $args{'name'} eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $args{"name"} eq "." 0 0 0
1197 0 ▶ undef $args{'id'} if $args{'id'} eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $args{"id"} eq "." 0 0 0
1198 0 ▶ undef $args{'type'} if $args{'type'} eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $args{"type"} eq "." 0 0 0
1199  
1200 # quick method for feature retrieval
1201 0 ▶ if ( defined $args{'id'} and $db->can('fetch') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"id"} and $db->can("fetch")) 0 0 0
Condition0%0/3
defined $args{"id"} and $db->can("fetch")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"id"} and $db->can("fetch")
defined $args{"id"} $db->can("fetch")
Truth table0%0/3
A and B
A= defined $args{"id"}B= $db->can("fetch")
ABresult
0X0
100
111
1202  
1203 # we have a unique primary_id to identify the feature
1204 # usually this pulls out the feature directly
1205 0 ▶ my $feature = $db->fetch( $args{'id'} ) || undef;
Condition0%0/2
$db->fetch($args{'id'}) || undef
l!l
00
MC/DC0%0/1
$db->fetch($args{'id'}) || undef
$db->fetch($args{'id'})
Truth table0%0/2
A
A= $db->fetch($args{'id'})
Aresult
11
00
1206  
1207 # check that the feature we pulled out is what we want
1208 0 ▶ my $check = $feature ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$feature ? : 0 0 0
1209 0 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) 0 0 0
1210 $check = 0
1211 0 ▶ if ( defined $args{'name'} and $feature->display_name ne $args{'name'} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"name"} and $feature->display_name ne $args{"name"} 0 0 0
Condition0%0/3
defined $args{"name"} and $feature->display_name ne $args{"name"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"name"} and $feature->display_name ne $args{"name"}
defined $args{"name"} $feature->display_name ne $args{"name"}
Truth table0%0/3
A and B
A= defined $args{"name"}B= $feature->display_name ne $args{"name"}
ABresult
0X0
100
111
1212 0 ▶ $check = 0 if ( defined $args{'type'} and $feature->type ne $args{'type'} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"type"} and $feature->type ne $args{"type"} 0 0 0
Condition0%0/3
defined $args{"type"} and $feature->type ne $args{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"type"} and $feature->type ne $args{"type"}
defined $args{"type"} $feature->type ne $args{"type"}
Truth table0%0/3
A and B
A= defined $args{"type"}B= $feature->type ne $args{"type"}
ABresult
0X0
100
111
1213 }
1214  
1215 # return if things match up as best we can tell
1216 0 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) { } 0 0 0
1217 0 return $feature;
1218 }
1219 else {
1220 # the primary_ids are out of date
1221 0 ▶ unless ($PRIMARY_ID_WARNING) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PRIMARY_ID_WARNING) 0 0 0
1222 0 print STDERR
1223 "CAUTION: Some primary IDs in Input file appear to be out of date\n";
1224 0 $PRIMARY_ID_WARNING++;
1225 }
1226 }
1227 }
1228  
1229 # otherwise use name and type
1230 return
1231 0 ▶ unless $args{'name'}; # otherwise db will return all features! Not what we want!
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"name"} 0 0 0
1232 my @features = $db->features(
1233 -name => $args{'name'}, # we assume this name will be unique
1234 -aliases => 0,
1235 0 -type => $args{'type'},
1236 );
1237  
1238 # if none are found
1239 0 ▶ unless (@features) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@features) 0 0 0
1240  
1241 # try again with aliases enabled
1242 @features = $db->features(
1243 -name => $args{'name'},
1244 -aliases => 1,
1245 0 -type => $args{'type'},
1246 );
1247 }
1248 0 ▶ unless ( @features and $args{'name'} =~ /[;,\|]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@features and $args{"name"} =~ /[;,\|]/) 0 0 0
Condition0%0/3
@features and $args{"name"} =~ /[;,\|]/
!ll&&!rl&&r
000
MC/DC0%0/2
@features and $args{"name"} =~ /[;,\|]/
@features $args{"name"} =~ /[;,\|]/
Truth table0%0/3
A and B
A= @featuresB= $args{"name"} =~ /[;,\|]/
ABresult
0X0
100
111
1249  
1250 # I used to append aliases to the end of the name in old versions of biotoolbox
1251 # crazy, I know, but just in case this happened, let's try breaking them apart
1252 0 my $name2 = ( split( /\s* [;,\|] \s*/x, $args{'name'} ) )[0];
1253  
1254 # multiple names present using common delimiters ;,|
1255 # take the first name only, assume others are aliases that we don't need
1256 @features = $db->features(
1257 -name => $name2,
1258 -aliases => 1,
1259 0 -type => $args{'type'},
1260 );
1261 }
1262  
1263 # check the number of features returned
1264 0 ▶ if ( scalar @features > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @features > 1) { } 0 0 0
elsif (not @features) { } 0 0 0
1265  
1266 # there should only be one feature found
1267 # if more are returned, there's redundant or duplicated data in the db
1268  
1269 # first check whether addition of aliases may improve accuracy
1270 0 ▶ if ( $args{'name'} =~ /;/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"} =~ /;/) 0 0 0
1271  
1272 # we have presumed aliases in the name value
1273 0 my $check = $args{'name'};
1274 0 $check =~ s/\s*;\s*/;/g; # strip spaces just in case
1275  
1276 # check each feature and try to match name and aliases
1277 0 my @candidates;
1278 0 foreach my $f (@features) {
1279 0 my $f_name =
1280 join( ';', $f->display_name, ( $f->get_tag_values('Alias') ) );
1281 0 ▶ if ( $check eq $f_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq $f_name) 0 0 0
1282  
1283 # found one
1284 0 push @candidates, $f;
1285 }
1286 }
1287  
1288 0 ▶ if ( scalar @candidates == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @candidates == 1) { } 0 0 0
elsif (scalar @candidates > 1) { } 0 0 0
1289  
1290 # we found it!
1291 0 return shift @candidates;
1292 }
1293 elsif ( scalar @candidates > 1 ) {
1294  
1295 # hopefully we've improved a little bit?
1296 0 @features = @candidates;
1297 }
1298 }
1299  
1300 # warn the user, this should be fixed
1301 printf " Found %s %s features named '%s' in the database! Using first one.\n",
1302 0 scalar(@features), $args{'type'}, $args{'name'};
1303 }
1304 elsif ( !@features ) {
1305 printf " Found no %s features named '%s' in the database!\n", $args{'type'},
1306 0 $args{'name'};
1307 0 return;
1308 }
1309  
1310 # done
1311 0 return shift @features;
1312 }
1313  
1314 ### Get a dataset score for a single region
1315 12 ▶sub get_segment_score {
Subroutine get_segment_score: called CC=11 SCAR=29.1
Pod documented
1316  
1317 # parameters passed as an array
1318 # we will be passing this array on as a reference to the appropriate
1319 # imported helper subroutine
1320 # chromosome, start, stop, strand, strandedness, method, return type, db, dataset
1321 12 ▶ confess 'FATAL: incorrect number of parameters passed!' unless scalar @_ == 9;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ == 9 0 12 12
1322  
1323 # check the database
1324 12 ▶ $_[DB] = open_db_connection( $_[DB] ) if ( $_[DB] and not ref( $_[DB] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $_[7] and not ref $_[7] 3 9 12
Condition66%2/3
$_[7] and not ref $_[7]
!ll&&!rl&&r
093
MC/DC50%1/2
$_[7] and not ref $_[7]
$_[7] not ref $_[7]
Truth table66%2/3
A and not(B)
A= $_[7]B= not ref $_[7]
ABresult
0X0
100
111
1325  
1326 # check for combined datasets
1327 12 ▶ if ( $_[DATA] =~ /&/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[8] =~ /&/) 0 12 12
1328 0 push @_, ( split /&/, pop @_ );
1329 }
1330  
1331 # determine method
1332 # yes, we're only checking the first dataset, but they should all
1333 # be the same type
1334 12 ▶ my $db_method = $DB_METHODS{ $_[METH] }{ $_[RETT] }{ $_[DB] || '.' }{ $_[DATA] }
Condition60%3/5
$DB_METHODS{$_[5]}{$_[6]}{$_[7] or '.'}{$_[8]} || _lookup_db_method(\@_)
l!l&&r!l&&!r
390
$_[7] || '.'
l!l
120
MC/DC0%0/2
$DB_METHODS{$_[5]}{$_[6]}{$_[7] or '.'}{$_[8]} || _lookup_db_method(\@_)
$DB_METHODS{$_[5]}{$_[6]}{$_[7] or '.'}{$_[8]} _lookup_db_method(\@_)
MC/DC0%0/1
$_[7] || '.'
$_[7]
Truth table66%2/3
A || B
A= $DB_METHODS{$_[5]}{$_[6]}{$_[7] or '.'}{$_[8]}B= _lookup_db_method(\@_)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $_[7]
Aresult
11
00
1335 || _lookup_db_method( \@_ );
1336  
1337 # return type values
1338 # 0 = calculate score
1339 # 1 = score array
1340 # 2 = hash position scores
1341 # immediately return calculated score if appropriate
1342 12 ▶ if ( $_[RETT] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[6] > 0) { } 5 7 12
1343  
1344 # immediately return either indexed hash or array of scores
1345 5 return &{$db_method}( \@_ );
1346 }
1347 else {
1348 # calculate a score
1349 7 my $scores = &{$db_method}( \@_ );
1350  
1351 # this might be an array reference of scores that need to be combined
1352 # or it could be a single scalar score which just needs to be returned
1353 7 ▶ if ( ref($scores) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $scores eq 'ARRAY') { } 7 0 7
1354 7 return calculate_score( $_[METH], $scores );
1355 }
1356 else {
1357 0 ▶ if ( not defined $scores ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $scores) 0 0 0
1358 0 ▶ return 0 if $_[METH] =~ /count|sum/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[5] =~ /count|sum/ 0 0 0
1359 0 return '.';
1360 }
1361 0 return $scores;
1362 }
1363 }
1364 }
1365  
1366 7 ▶sub calculate_score {
Subroutine calculate_score: called CC=3 SCAR=11.8
Pod documented
1367 7 my ( $method, $scores ) = @_;
1368 7 ▶ $scores ||= []; # just in case
Condition50%1/2
$scores ||= []
l!l
70
MC/DC0%0/1
$scores ||= []
$scores
Truth table50%1/2
A
A= $scores
Aresult
11
00
1369 7 ▶ if ( exists $SCORE_CALCULATOR_SUB{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SCORE_CALCULATOR_SUB{$method}) { } 7 0 7
1370 7 return &{ $SCORE_CALCULATOR_SUB{$method} }($scores);
1371 }
1372 else {
1373 0 confess "FATAL: unrecognized method '$method'!";
1374 }
1375 }
1376  
1377 2 ▶sub get_chromosome_list {
Subroutine get_chromosome_list: called CC=40 SCAR=64.3
Pod documented
1378  
1379 # options
1380 2 my $database = shift;
1381 2 ▶ my $chr_exclude = shift || undef;
Condition50%1/2
shift() || undef
l!l
02
MC/DC0%0/1
shift() || undef
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1382  
1383 # Open a db connection
1384 2 my $db = open_db_connection($database);
1385 2 ▶ unless ($db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 2 2
1386 0 carp 'ERROR: no database connected!';
1387 0 return;
1388 }
1389  
1390 # Check for BigWigSet database
1391 # these need to be handled a little differently
1392 2 ▶ if ( ref($db) =~ /BigWigSet/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($db) =~ /BigWigSet/) 0 2 2
1393  
1394 # BigWigSet databases are the only databases that don't
1395 # support the seq_ids method
1396 # instead we have to look at one of the bigwigs in the set
1397 0 my $bw_file = ( $db->bigwigs )[0];
1398 0 $db = open_db_connection($bw_file);
1399 }
1400  
1401 # Collect chromosome lengths
1402 # we want to maintain the original order of the chromosomes so we
1403 # won't be putting it into a hash
1404 # instead an array of arrays
1405 2 my @chrom_lengths;
1406  
1407 # Database specific approaches to collecting chromosomes
1408 # I used to have one generic approach, but idiosyncrasies and potential
1409 # bugs make me use different approaches for better consistency
1410 2 my $type = ref $db;
1411  
1412 # SeqFeature::Store
1413 2 ▶ if ( $type =~ m/^Bio::DB::SeqFeature::Store/x ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($type =~ /^Bio::DB::SeqFeature::Store/x) { } 0 2 2
elsif ($type eq 'Bio::DB::Big::File') { } 0 2 2
elsif ($type eq 'Bio::DB::BigWig' or $type eq 'Bio::DB::BigBed') { } 0 2 2
elsif ($type eq 'Bio::DB::Sam' or $type eq 'Bio::DB::HTS') { } 0 2 2
elsif ($type eq 'Bio::DB::HTS::Faidx') { } 0 2 2
elsif ($type eq 'Bio::DB::Fasta') { } 0 2 2
elsif ($db->can('seq_ids')) { } 2 0 2
1414 0 for my $chr ( $db->seq_ids ) {
1415  
1416 # check for excluded chromosomes
1417 0 ▶ next if ( defined $chr_exclude and $chr =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $chr =~ /$chr_exclude/xi 0 0 0
Condition0%0/3
defined $chr_exclude and $chr =~ /$chr_exclude/xi
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $chr =~ /$chr_exclude/xi
defined $chr_exclude $chr =~ /$chr_exclude/xi
Truth table0%0/3
A and B
A= defined $chr_excludeB= $chr =~ /$chr_exclude/xi
ABresult
0X0
100
111
1418  
1419 # get chromosome size
1420 0 my ($seqf) = $db->get_features_by_name($chr);
1421 0 ▶ my $length = $seqf ? $seqf->length : 0;
Branch: 1 branch
BranchTrueFalseTotal
$seqf ? : 0 0 0
1422  
1423 # store
1424 0 push @chrom_lengths, [ $chr, $length ];
1425 }
1426 }
1427  
1428 # libBigWig Bigfile, including both bigWig and bigBed
1429 elsif ( $type eq 'Bio::DB::Big::File' ) {
1430  
1431 # this doesn't follow the typical BioPerl convention
1432 # it's a hash, so randomly sorted!!!!! Never will be in same order as file!!!!
1433 0 my $chroms = $db->chroms();
1434  
1435 0 my @list;
1436 0 foreach ( values %{$chroms} ) {
1437  
1438 # check for excluded chromosomes
1439 0 ▶ next if ( defined $chr_exclude and $_->{name} =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $_->{"name"} =~ /$chr_exclude/xi 0 0 0
Condition0%0/3
defined $chr_exclude and $_->{"name"} =~ /$chr_exclude/xi
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $_->{"name"} =~ /$chr_exclude/xi
defined $chr_exclude $_->{"name"} =~ /$chr_exclude/xi
Truth table0%0/3
A and B
A= defined $chr_excludeB= $_->{"name"} =~ /$chr_exclude/xi
ABresult
0X0
100
111
1440 0 push @list, [ $_->{name}, $_->{length} ];
1441 }
1442  
1443 # sort consistently by a sane system
1444 0 @chrom_lengths = sane_chromo_sort(@list);
1445 }
1446  
1447 # UCSC kent Bigfile
1448 ▶ elsif ( $type eq 'Bio::DB::BigWig' or $type eq 'Bio::DB::BigBed' ) {
Condition33%1/3
$type eq "Bio::DB::BigWig" or $type eq "Bio::DB::BigBed"
l!l&&r!l&&!r
002
MC/DC0%0/2
$type eq "Bio::DB::BigWig" or $type eq "Bio::DB::BigBed"
$type eq "Bio::DB::BigWig" $type eq "Bio::DB::BigBed"
Truth table33%1/3
A or B
A= $type eq "Bio::DB::BigWig"B= $type eq "Bio::DB::BigBed"
ABresult
1X1
011
000
1449 0 foreach my $chr ( $db->seq_ids ) {
1450  
1451 # check for excluded chromosomes
1452 0 ▶ next if ( defined $chr_exclude and $chr =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $chr =~ /$chr_exclude/xi 0 0 0
Condition0%0/3
defined $chr_exclude and $chr =~ /$chr_exclude/xi
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $chr =~ /$chr_exclude/xi
defined $chr_exclude $chr =~ /$chr_exclude/xi
Truth table0%0/3
A and B
A= defined $chr_excludeB= $chr =~ /$chr_exclude/xi
ABresult
0X0
100
111
1453  
1454 # get chromosome size
1455 0 my $length = $db->length($chr);
1456  
1457 # store
1458 0 push @chrom_lengths, [ $chr, $length ];
1459 }
1460 }
1461  
1462 # Samtools Bam
1463 ▶ elsif ( $type eq 'Bio::DB::Sam' or $type eq 'Bio::DB::HTS' ) {
Condition33%1/3
$type eq "Bio::DB::Sam" or $type eq "Bio::DB::HTS"
l!l&&r!l&&!r
002
MC/DC0%0/2
$type eq "Bio::DB::Sam" or $type eq "Bio::DB::HTS"
$type eq "Bio::DB::Sam" $type eq "Bio::DB::HTS"
Truth table33%1/3
A or B
A= $type eq "Bio::DB::Sam"B= $type eq "Bio::DB::HTS"
ABresult
1X1
011
000
1464 0 for my $tid ( 0 .. $db->n_targets - 1 ) {
1465  
1466 # each chromosome is internally represented in the bam file as
1467 # a numeric target identifier
1468 # we can easily convert this to an actual sequence name
1469 # we will force the conversion to go one chromosome at a time
1470  
1471 # sequence info
1472 0 my $chr = $db->target_name($tid);
1473 0 my $length = $db->target_len($tid);
1474  
1475 # check for excluded chromosomes
1476 0 ▶ next if ( defined $chr_exclude and $chr =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $chr =~ /$chr_exclude/xi 0 0 0
Condition0%0/3
defined $chr_exclude and $chr =~ /$chr_exclude/xi
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $chr =~ /$chr_exclude/xi
defined $chr_exclude $chr =~ /$chr_exclude/xi
Truth table0%0/3
A and B
A= defined $chr_excludeB= $chr =~ /$chr_exclude/xi
ABresult
0X0
100
111
1477  
1478 # store
1479 0 push @chrom_lengths, [ $chr, $length ];
1480 }
1481 }
1482  
1483 # Fast through modern HTS fai index
1484 elsif ( $type eq 'Bio::DB::HTS::Faidx' ) {
1485 0 for my $chr ( $db->get_all_sequence_ids ) {
1486  
1487 # check for excluded
1488 0 ▶ next if ( defined $chr_exclude and $chr =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $chr =~ /$chr_exclude/xi 0 0 0
Condition0%0/3
defined $chr_exclude and $chr =~ /$chr_exclude/xi
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $chr =~ /$chr_exclude/xi
defined $chr_exclude $chr =~ /$chr_exclude/xi
Truth table0%0/3
A and B
A= defined $chr_excludeB= $chr =~ /$chr_exclude/xi
ABresult
0X0
100
111
1489  
1490 # get length and store it
1491 0 my $length = $db->length($chr);
1492 0 push @chrom_lengths, [ $chr, $length ];
1493 }
1494 }
1495  
1496 # Fasta through old BioPerl adapter
1497 elsif ( $type eq 'Bio::DB::Fasta' ) {
1498 0 for my $chr ( $db->get_all_ids ) {
1499  
1500 # check for excluded chromosomes
1501 0 ▶ next if ( defined $chr_exclude and $chr =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $chr =~ /$chr_exclude/xi 0 0 0
Condition0%0/3
defined $chr_exclude and $chr =~ /$chr_exclude/xi
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chr_exclude and $chr =~ /$chr_exclude/xi
defined $chr_exclude $chr =~ /$chr_exclude/xi
Truth table0%0/3
A and B
A= defined $chr_excludeB= $chr =~ /$chr_exclude/xi
ABresult
0X0
100
111
1502  
1503 # get chromosome size
1504 0 my $seq = $db->get_Seq_by_id($chr);
1505 0 ▶ my $length = $seq ? $seq->length : 0;
Branch: 1 branch
BranchTrueFalseTotal
$seq ? : 0 0 0
1506  
1507 # store
1508 0 push @chrom_lengths, [ $chr, $length ];
1509 }
1510 }
1511  
1512 # other Bioperl adapter?????
1513 elsif ( $db->can('seq_ids') ) {
1514 2 foreach my $chr ( $db->seq_ids ) {
1515  
1516 # check for excluded chromosomes
1517 2 ▶ next if ( defined $chr_exclude and $chr =~ m/$chr_exclude/xi );
Branch: 1 branch
BranchTrueFalseTotal
if defined $chr_exclude and $chr =~ /$chr_exclude/xi 0 2 2
Condition33%1/3
defined $chr_exclude and $chr =~ /$chr_exclude/xi
!ll&&!rl&&r
200
MC/DC0%0/2
defined $chr_exclude and $chr =~ /$chr_exclude/xi
defined $chr_exclude $chr =~ /$chr_exclude/xi
Truth table33%1/3
A and B
A= defined $chr_excludeB= $chr =~ /$chr_exclude/xi
ABresult
0X0
100
111
1518  
1519 # generate a segment representing the chromosome
1520 # due to fuzzy name matching, we may get more than one back
1521 2 my @segments = $db->segment($chr);
1522  
1523 # need to find the right one
1524 2 my $segment;
1525 2 ▶ while (@segments) {
Branch: 1 branch
BranchTrueFalseTotal
if (@segments) 2 0 2
1526 2 $segment = shift @segments;
1527 2 ▶ last if $segment->seq_id eq $chr;
Branch: 1 branch
BranchTrueFalseTotal
if $segment->seq_id eq $chr 2 0 2
1528 }
1529  
1530 # check segment
1531 2 ▶ unless ($segment) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($segment) 0 2 2
1532 0 print STDERR "ERROR: No genome segment for seq_id $chr!!?? skipping\n";
1533 0 next;
1534 }
1535  
1536 # get the chromosome length
1537 2 my $length = $segment->length;
1538  
1539 # store
1540 2 push @chrom_lengths, [ $chr, $length ];
1541 }
1542 }
1543  
1544 else {
1545 0 carp
1546 "ERROR: Unable to identify chromosomes in database type '$type'. Try using a different database file or adapter";
1547 0 return;
1548 }
1549  
1550 # Return
1551 2 ▶ unless (@chrom_lengths) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@chrom_lengths) 0 2 2
1552 0 carp 'ERROR: no chromosome sequences identified in database!';
1553 0 return;
1554 }
1555 2 return @chrom_lengths;
1556 }
1557  
1558 0 ▶sub low_level_bam_fetch {
Subroutine low_level_bam_fetch: not called CC=13 SCAR=52.0
Pod documented
1559 0 ▶ confess 'FATAL: incorrect number of parameters passed!' unless scalar @_ == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ == 6 0 0 0
1560 0 my ( $sam, $tid, $start, $stop, $callback, $data ) = @_;
1561  
1562 # the low level fetch returns an undocumented code that is essentially useless
1563 # all real data is in the $data reference
1564 # so we silently fail here too if something doesn't look right, and $data is unaltered
1565 0 ▶ return unless defined $sam;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sam 0 0 0
1566 0 ▶ return unless defined $tid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tid 0 0 0
1567 0 ▶ return unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
1568 0 ▶ return unless defined $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stop 0 0 0
1569 0 ▶ return unless ref($callback) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 0 0
1570  
1571 # run the the low level bam fetch based on which adapter is being used
1572 0 ▶ unless ($BAM_ADAPTER) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Bio::ToolBox::db_helper::BAM_ADAPTER) 0 0 0
1573 0 ▶ $BAM_ADAPTER = ref($sam) =~ /hts/i ? 'hts' : 'sam';
Branch: 1 branch
BranchTrueFalseTotal
ref($sam) =~ /hts/i ? : 0 0 0
1574 }
1575 0 ▶ if ( $BAM_ADAPTER eq 'hts' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BAM_ADAPTER eq 'hts') { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BAM_ADAPTER eq 'sam') { } 0 0 0
1576  
1577 # using Bio::DB::HTS
1578 0 my $index = $sam->hts_index;
1579 0 ▶ return unless $index;
Branch: 1 branch
BranchTrueFalseTotal
unless $index 0 0 0
1580 0 return $index->fetch( $sam->hts_file, $tid, $start, $stop, $callback, $data );
1581 }
1582 elsif ( $BAM_ADAPTER eq 'sam' ) {
1583  
1584 # using Bio::DB::Sam
1585 0 my $index = $sam->bam_index;
1586 0 ▶ return unless $index;
Branch: 1 branch
BranchTrueFalseTotal
unless $index 0 0 0
1587 0 return $index->fetch( $sam->bam, $tid, $start, $stop, $callback, $data );
1588 }
1589 else {
1590 0 confess 'FATAL: no bam adapter loaded!';
1591 }
1592 }
1593  
1594 0 ▶sub low_level_bam_coverage {
Subroutine low_level_bam_coverage: not called CC=12 SCAR=50.5
Pod documented
1595 0 ▶ confess 'FATAL: incorrect number of parameters passed!' unless scalar @_ == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ == 4 0 0 0
1596 0 my ( $sam, $tid, $start, $stop ) = @_;
1597  
1598 # silently fail here too if something doesn't look right
1599 0 ▶ return unless defined $sam;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sam 0 0 0
1600 0 ▶ return unless defined $tid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tid 0 0 0
1601 0 ▶ return unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
1602 0 ▶ return unless defined $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stop 0 0 0
1603  
1604 # run the the low level bam coverage based on which adapter is being used
1605 0 ▶ unless ($BAM_ADAPTER) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Bio::ToolBox::db_helper::BAM_ADAPTER) 0 0 0
1606 0 ▶ $BAM_ADAPTER = ref($sam) =~ /hts/i ? 'hts' : 'sam';
Branch: 1 branch
BranchTrueFalseTotal
ref($sam) =~ /hts/i ? : 0 0 0
1607 }
1608 0 ▶ if ( $BAM_ADAPTER eq 'hts' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BAM_ADAPTER eq 'hts') { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BAM_ADAPTER eq 'sam') { } 0 0 0
1609  
1610 # using Bio::DB::HTS
1611 0 my $index = $sam->hts_index;
1612 0 ▶ return unless $index;
Branch: 1 branch
BranchTrueFalseTotal
unless $index 0 0 0
1613 0 return $index->coverage( $sam->hts_file, $tid, $start, $stop );
1614 }
1615 elsif ( $BAM_ADAPTER eq 'sam' ) {
1616  
1617 # using Bio::DB::Sam
1618 0 my $index = $sam->bam_index;
1619 0 ▶ return unless $index;
Branch: 1 branch
BranchTrueFalseTotal
unless $index 0 0 0
1620 0 return $index->coverage( $sam->bam, $tid, $start, $stop );
1621 }
1622 else {
1623 0 confess 'FATAL: no bam adapter loaded!';
1624 }
1625 }
1626  
1627 0 ▶sub get_genomic_sequence {
Subroutine get_genomic_sequence: not called CC=6 SCAR=37.4
Pod documented
1628 0 ▶ confess 'FATAL: incorrect number of parameters passed!' unless scalar @_ == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ == 4 0 0 0
1629 0 my ( $db, $chrom, $start, $stop ) = @_;
1630  
1631 # check database
1632 0 my $type = ref $db;
1633 0 ▶ $db = open_db_connection($db) if not $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
1634  
1635 # return sequence based on the type of database adapter we're using
1636 0 ▶ if ( $type eq 'Bio::DB::HTS::Faidx' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'Bio::DB::HTS::Faidx') { } 0 0 0
elsif ($type eq 'Bio::DB::Sam::Fai') { } 0 0 0
elsif ($db->can('seq')) { } 0 0 0
1637 0 return $db->get_sequence_no_length("$chrom:$start-$stop");
1638 }
1639 elsif ( $type eq 'Bio::DB::Sam::Fai' ) {
1640 0 return $db->fetch("$chrom:$start-$stop");
1641 }
1642 elsif ( $db->can('seq') ) {
1643  
1644 # BioPerl database including Bio::DB::Fasta and Bio::DB::SeqFeature::Store
1645 0 return $db->seq( $chrom, $start, $stop );
1646 }
1647 else {
1648 0 confess "FATAL: unsupported database $type for collecting genomic sequence!";
1649 }
1650 }
1651  
1652 ### Internal subroutine to retrieve the scores from an established region object
1653 9 ▶sub _lookup_db_method {
Subroutine _lookup_db_method: called CC=37 SCAR=67.1
1654  
1655 # parameters passed as an array reference
1656 9 my $param = shift;
1657  
1658 # determine the appropriate score method
1659 9 my $score_method;
1660 9 ▶ if ( $param->[DATA] =~ m/^(?: file | http | ftp )/x ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($param->[8] =~ /^(?: file | http | ftp )/x) { } 9 0 9
elsif ($param->[7] and ref($param->[7]) =~ /BigWigSet/) { } 0 0 0
elsif ($param->[7] and ref($param->[7]) =~ /^Bio::DB/) { } 0 0 0
1661  
1662 # collect the data according to file type
1663  
1664 # BigWig Data file
1665 9 ▶ if ( $param->[DATA] =~ m/\. (?: bw | bigwig )$/xi ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($param->[8] =~ /\. (?: bw | bigwig )$/xi) { } 0 9 9
elsif ($param->[8] =~ /\. (?: bb | bigbed )$/xi) { } 0 9 9
elsif ($param->[8] =~ /\.bam$/i) { } 0 9 9
elsif ($param->[8] =~ /\.useq$/i) { } 9 0 9
1666  
1667 # file is in bigwig format
1668 # get the dataset scores using Bio::ToolBox::db_helper::bigwig
1669 # this uses either Bio::DB::BigWig or Bio::DB::Big
1670  
1671 # check that we have bigwig support
1672 0 ▶ $BIGWIG_OK = _load_bigwig_helper_module() unless $BIGWIG_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
1673 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
1674 0 ▶ if ( $param->[RETT] == 2 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($param->[6] == 2) { } 0 0 0
elsif ($param->[6] == 1) { } 0 0 0
elsif ($param->[5] =~ /(?: min | max | mean )/x) { } 0 0 0
elsif ($param->[5] =~ /sum|count/) { } 0 0 0
1675 0 $score_method = \&collect_bigwig_position_scores;
1676 }
1677 elsif ( $param->[RETT] == 1 ) {
1678 0 $score_method = \&collect_bigwig_scores;
1679 }
1680 elsif ( $param->[METH] =~ m/(?: min | max | mean )/x ) {
1681 0 $score_method = \&collect_bigwig_score;
1682 }
1683 elsif ( $param->[METH] =~ m/sum|count/ ) {
1684  
1685 # difference between ucsc and libBigWig libraries
1686 0 ▶ $score_method =
Branch: 1 branch
BranchTrueFalseTotal
$Bio::ToolBox::db_helper::BIG_ADAPTER eq 'ucsc' ? : 0 0 0
1687 $BIG_ADAPTER eq 'ucsc'
1688 ? \&collect_bigwig_score
1689 : \&collect_bigwig_scores;
1690 }
1691 else {
1692 0 $score_method = \&collect_bigwig_scores;
1693 }
1694 }
1695 else {
1696 0 croak
1697 'FATAL: BigWig support is not enabled! Is Bio::DB::Big or Bio::DB::BigFile installed?';
1698 }
1699 }
1700  
1701 # BigBed Data file
1702 elsif ( $param->[DATA] =~ m/\. (?: bb | bigbed )$/xi ) {
1703  
1704 # data is in bigbed format
1705 # get the dataset scores using Bio::ToolBox::db_helper::bigbed
1706 # this uses either Bio::DB::BigBed or Bio::DB::Big
1707  
1708 # check that we have bigbed support
1709 0 ▶ $BIGBED_OK = _load_bigbed_helper_module() unless $BIGBED_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGBED_OK 0 0 0
1710 0 ▶ if ($BIGBED_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGBED_OK) { } 0 0 0
1711 0 ▶ if ( $param->[RETT] == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->[6] == 2) { } 0 0 0
1712 0 $score_method = \&collect_bigbed_position_scores;
1713 }
1714 else {
1715 0 $score_method = \&collect_bigbed_scores;
1716 }
1717 }
1718 else {
1719 0 croak
1720 'FATAL: BigBed support is not enabled! Is Bio::DB::Big or Bio::DB::BigFile installed?';
1721 }
1722 }
1723  
1724 # BAM data file
1725 elsif ( $param->[DATA] =~ /\.bam$/i ) {
1726  
1727 # data is in bam format
1728 # get the dataset scores using Bio::ToolBox::db_helper::bam
1729 # this uses the Bio::DB::Sam or Bio::DB::HTS adaptor
1730  
1731 # check that we have Bam support
1732 0 ▶ _load_bam_helper_module() unless $BAM_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BAM_OK 0 0 0
1733 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
1734 0 $score_method = \&collect_bam_scores;
1735 }
1736 else {
1737 0 croak
1738 'FATAL: Bam support is not enabled! Is Bio::DB::HTS or Bio::DB::Sam installed?';
1739 }
1740 }
1741  
1742 # USeq Data file
1743 elsif ( $param->[DATA] =~ /\.useq$/i ) {
1744  
1745 # data is in useq format
1746 # get the dataset scores using Bio::ToolBox::db_helper::useq
1747 # this uses the Bio::DB::USeq adaptor
1748  
1749 # check that we have bigbed support
1750 9 ▶ $USEQ_OK = _load_helper_module('Bio::ToolBox::db_helper::useq')
Branch: 1 branch
BranchTrueFalseTotal
unless $USEQ_OK 0 9 9
1751 unless $USEQ_OK;
1752 9 ▶ if ($USEQ_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($USEQ_OK) { } 9 0 9
1753 9 ▶ if ( $param->[RETT] == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->[6] == 2) { } 4 5 9
1754 4 $score_method = \&collect_useq_position_scores;
1755 }
1756 else {
1757 5 $score_method = \&collect_useq_scores;
1758 }
1759 }
1760 else {
1761 0 croak 'FATAL: USeq support is not enabled! Is Bio::DB::USeq installed?';
1762 }
1763 }
1764  
1765 # Unsupported Data file
1766 else {
1767 0 confess sprintf "FATAL Unsupported or unrecognized file type for file '%s'!",
1768 $param->[DATA];
1769 }
1770 }
1771  
1772 ### BigWigSet database
1773 ▶ elsif ( $param->[DB] and ref( $param->[DB] ) =~ m/BigWigSet/ ) {
Condition0%0/3
$param->[7] and ref($param->[7]) =~ /BigWigSet/
!ll&&!rl&&r
000
MC/DC0%0/2
$param->[7] and ref($param->[7]) =~ /BigWigSet/
$param->[7] ref($param->[7]) =~ /BigWigSet/
Truth table0%0/3
A and B
A= $param->[7]B= ref($param->[7]) =~ /BigWigSet/
ABresult
0X0
100
111
1774  
1775 # calling features from a BigWigSet database object
1776 # this uses either Bio::DB::BigWig or Bio::DB::Big
1777  
1778 # check that we have bigwig support
1779 # duh! we should, we probably opened the stupid database!
1780 0 ▶ $BIGWIG_OK = _load_bigwig_helper_module() unless $BIGWIG_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
1781 0 ▶ croak
Branch: 1 branch
BranchTrueFalseTotal
unless $BIGWIG_OK 0 0 0
1782 'FATAL: BigWigSet support is not enabled! Is Bio::DB::Big or Bio::DB::BigFile installed?'
1783 unless $BIGWIG_OK;
1784  
1785 # the data collection depends on the method
1786 0 ▶ if ( $param->[RETT] == 2 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($param->[6] == 2) { } 0 0 0
elsif ($param->[6] == 1) { } 0 0 0
elsif ($param->[5] =~ /(?: min | max | mean | sum | count )/x) { } 0 0 0
1787 0 $score_method = \&collect_bigwigset_position_scores;
1788 }
1789 elsif ( $param->[RETT] == 1 ) {
1790 0 $score_method = \&collect_bigwigset_scores;
1791 }
1792 elsif ( $param->[METH] =~ m/(?: min | max | mean | sum | count )/x ) {
1793  
1794 # difference between ucsc and libBigWig libraries
1795 # the ucsc library works with summaries and we can handle multiple of these
1796 # but the big adapter doesn't
1797 0 ▶ $score_method =
Branch: 1 branch
BranchTrueFalseTotal
$Bio::ToolBox::db_helper::BIG_ADAPTER eq 'ucsc' ? : 0 0 0
1798 $BIG_ADAPTER eq 'ucsc'
1799 ? \&collect_bigwigset_score
1800 : \&collect_bigwigset_scores;
1801 }
1802 else {
1803 0 $score_method = \&collect_bigwigset_scores;
1804 }
1805 }
1806  
1807 ### BioPerl style database
1808 ▶ elsif ( $param->[DB] and ref( $param->[DB] ) =~ m/^Bio::DB/ ) {
Condition0%0/3
$param->[7] and ref($param->[7]) =~ /^Bio::DB/
!ll&&!rl&&r
000
MC/DC0%0/2
$param->[7] and ref($param->[7]) =~ /^Bio::DB/
$param->[7] ref($param->[7]) =~ /^Bio::DB/
Truth table0%0/3
A and B
A= $param->[7]B= ref($param->[7]) =~ /^Bio::DB/
ABresult
0X0
100
111
1809  
1810 # a BioPerl style database, including Bio::DB::SeqFeature::Store
1811 # most or all Bio::DB databases support generic get_seq_stream() methods
1812 # that return seqfeature objects, which we can use in a generic sense
1813  
1814 # check that we have support
1815 # duh! we should, we probably opened the stupid database!
1816 0 ▶ $SEQFASTA_OK = _load_helper_module('Bio::ToolBox::db_helper::seqfasta')
Branch: 1 branch
BranchTrueFalseTotal
unless $SEQFASTA_OK 0 0 0
1817 unless $SEQFASTA_OK;
1818 0 ▶ if ($SEQFASTA_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SEQFASTA_OK) { } 0 0 0
1819  
1820 # get the dataset scores using Bio::ToolBox::db_helper::seqfasta
1821 # check that we support methods
1822 0 ▶ unless ( $param->[DB]->can('get_seq_stream') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->[7]->can("get_seq_stream")) 0 0 0
1823 0 confess sprintf
1824 "FATAL: unsupported database! cannot use %s as it does not support get_seq_stream method or equivalent",
1825 ref( $param->[DB] );
1826 }
1827 0 $score_method = \&collect_store_scores;
1828 }
1829 else {
1830 0 croak
1831 'FATAL: SeqFeature Store support is not enabled! Is BioPerl and Bio::DB::SeqFeature::Store properly installed?';
1832 }
1833 }
1834  
1835 ### Some other database?
1836 else {
1837 0 ▶ confess 'FATAL: no recognizeable dataset provided!' unless $param->[DATA];
Branch: 1 branch
BranchTrueFalseTotal
unless $param->[8] 0 0 0
1838 0 ▶ confess 'FATAL: no database passed!' unless $param->[DB];
Branch: 1 branch
BranchTrueFalseTotal
unless $param->[7] 0 0 0
1839 confess sprintf "FATAL: something went wrong! parameters: %s", join ', ',
1840 0 @{$param};
1841 }
1842  
1843 ### Cache and return the results
1844 $DB_METHODS{ $param->[METH] }{ $param->[RETT] }{ $param->[DB]
1845 9 ▶ || '.' }{ $param->[DATA] } = $score_method;
Condition50%1/2
$param->[7] || '.'
l!l
90
MC/DC0%0/1
$param->[7] || '.'
$param->[7]
Truth table50%1/2
A
A= $param->[7]
Aresult
11
00
1846 9 return $score_method;
1847 }
1848  
1849 1 ▶sub _load_helper_module {
Subroutine _load_helper_module: called CC=1 SCAR=0.0
1850 1 my $class = shift;
1851 1 my $success = 0;
1852 1 eval {
1853 # using Module::Load to dynamically load modules and import default functions
1854 1 autoload $class;
1855 1 $success = 1;
1856 };
1857 1 return $success;
1858 }
1859  
1860 0 ▶sub _load_bam_helper_module {
Subroutine _load_bam_helper_module: not called CC=9 SCAR=45.0
1861 0 ▶ if ($BAM_ADAPTER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BAM_ADAPTER) { } 0 0 0
1862 0 ▶ if ( $BAM_ADAPTER =~ /sam/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BAM_ADAPTER =~ /sam/i) { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BAM_ADAPTER =~ /hts/i) { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BAM_ADAPTER =~ /none/i) { } 0 0 0
1863 0 $BAM_OK = _load_helper_module('Bio::ToolBox::db_helper::bam');
1864 0 $BAM_ADAPTER = 'sam'; # for internal consistency
1865 }
1866 elsif ( $BAM_ADAPTER =~ /hts/i ) {
1867 0 $BAM_OK = _load_helper_module('Bio::ToolBox::db_helper::hts');
1868 0 $BAM_ADAPTER = 'hts'; # for internal consistency
1869 }
1870 elsif ( $BAM_ADAPTER =~ /none/i ) {
1871 0 return 0; # basically for testing purposes, don't use a module
1872 }
1873 0 ▶ if ( not $BAM_OK and $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $BAM_OK and $Bio::ToolBox::db_helper::EVAL_ERROR) 0 0 0
Condition0%0/3
not $BAM_OK and $Bio::ToolBox::db_helper::EVAL_ERROR
!ll&&!rl&&r
000
MC/DC0%0/2
not $BAM_OK and $Bio::ToolBox::db_helper::EVAL_ERROR
not $BAM_OK $Bio::ToolBox::db_helper::EVAL_ERROR
Truth table0%0/3
not(A) and B
A= not $BAM_OKB= $Bio::ToolBox::db_helper::EVAL_ERROR
ABresult
0X0
100
111
1874 0 carp "ERROR: $EVAL_ERROR";
1875 }
1876 }
1877 else {
1878 # try hts first, then sam
1879 # be sure to set BAM_ADAPTER upon success
1880 0 eval { $BAM_OK = _load_helper_module('Bio::ToolBox::db_helper::hts'); };
1881 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
1882 0 $BAM_ADAPTER = 'hts';
1883 }
1884 else {
1885 0 $BAM_OK = _load_helper_module('Bio::ToolBox::db_helper::bam');
1886 0 ▶ if ($BAM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BAM_OK) { } 0 0 0
1887 0 $BAM_ADAPTER = 'sam';
1888 }
1889 else {
1890 0 carp "ERROR: Neither Bio::DB::HTS or Bio::DB::Sam are installed";
1891 }
1892 }
1893 }
1894 0 return $BAM_OK;
1895 }
1896  
1897 0 ▶sub _load_bigwig_helper_module {
Subroutine _load_bigwig_helper_module: not called CC=9 SCAR=45.0
1898 0 ▶ if ($BIG_ADAPTER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BIG_ADAPTER) { } 0 0 0
1899 0 ▶ if ( $BIG_ADAPTER =~ m/ucsc|kent/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BIG_ADAPTER =~ /ucsc|kent/i) { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BIG_ADAPTER =~ /big/i) { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BIG_ADAPTER =~ /none/i) { } 0 0 0
1900 0 $BIGWIG_OK = _load_helper_module('Bio::ToolBox::db_helper::bigwig');
1901 0 $BIG_ADAPTER = 'ucsc'; # for internal consistency
1902 }
1903 elsif ( $BIG_ADAPTER =~ m/big/i ) {
1904 0 $BIGWIG_OK = _load_helper_module('Bio::ToolBox::db_helper::big');
1905 0 $BIGBED_OK = $BIGWIG_OK; # bigbed too!
1906 0 $BIG_ADAPTER = 'big'; # for internal consistency
1907 }
1908 elsif ( $BIG_ADAPTER =~ /none/i ) {
1909 0 return 0; # basically for testing purposes, don't use a module
1910 }
1911 0 ▶ if ( not $BIGWIG_OK and $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $BIGWIG_OK and $Bio::ToolBox::db_helper::EVAL_ERROR) 0 0 0
Condition0%0/3
not $BIGWIG_OK and $Bio::ToolBox::db_helper::EVAL_ERROR
!ll&&!rl&&r
000
MC/DC0%0/2
not $BIGWIG_OK and $Bio::ToolBox::db_helper::EVAL_ERROR
not $BIGWIG_OK $Bio::ToolBox::db_helper::EVAL_ERROR
Truth table0%0/3
not(A) and B
A= not $BIGWIG_OKB= $Bio::ToolBox::db_helper::EVAL_ERROR
ABresult
0X0
100
111
1912 0 carp "ERROR: $EVAL_ERROR";
1913 }
1914 }
1915 else {
1916 # we have to try each one out
1917 # try the modern big adapter first
1918 0 $BIGWIG_OK = _load_helper_module('Bio::ToolBox::db_helper::big');
1919 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
1920 0 $BIGBED_OK = $BIGWIG_OK; # bigbed too!
1921 0 $BIG_ADAPTER = 'big';
1922 }
1923 else {
1924 0 $BIGWIG_OK = _load_helper_module('Bio::ToolBox::db_helper::bigwig');
1925 0 ▶ if ($BIGWIG_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGWIG_OK) { } 0 0 0
1926 0 $BIG_ADAPTER = 'ucsc';
1927 }
1928 else {
1929 0 carp
1930 "ERROR: Neither Bio::DB::Big, Bio::DB::BigWig, or Bio::DB::BigBed are installed";
1931 }
1932 }
1933 }
1934 0 return $BIGWIG_OK;
1935 }
1936  
1937 0 ▶sub _load_bigbed_helper_module {
Subroutine _load_bigbed_helper_module: not called CC=9 SCAR=45.0
1938 0 ▶ if ($BIG_ADAPTER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BIG_ADAPTER) { } 0 0 0
1939 0 ▶ if ( $BIG_ADAPTER =~ m/ucsc|kent/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Bio::ToolBox::db_helper::BIG_ADAPTER =~ /ucsc|kent/i) { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BIG_ADAPTER =~ /big/i) { } 0 0 0
elsif ($Bio::ToolBox::db_helper::BIG_ADAPTER =~ /none/i) { } 0 0 0
1940 0 $BIGBED_OK = _load_helper_module('Bio::ToolBox::db_helper::bigbed');
1941 0 $BIG_ADAPTER = 'ucsc'; # for internal consistency
1942 }
1943 elsif ( $BIG_ADAPTER =~ m/big/i ) {
1944 0 $BIGBED_OK = _load_helper_module('Bio::ToolBox::db_helper::big');
1945 0 $BIGWIG_OK = $BIGBED_OK; # bigwig too!
1946 0 $BIG_ADAPTER = 'big'; # for internal consistency
1947 }
1948 elsif ( $BIG_ADAPTER =~ /none/i ) {
1949 0 return 0; # basically for testing purposes, don't use a module
1950 }
1951 0 ▶ if ( not $BIGBED_OK and $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $BIGBED_OK and $Bio::ToolBox::db_helper::EVAL_ERROR) 0 0 0
Condition0%0/3
not $BIGBED_OK and $Bio::ToolBox::db_helper::EVAL_ERROR
!ll&&!rl&&r
000
MC/DC0%0/2
not $BIGBED_OK and $Bio::ToolBox::db_helper::EVAL_ERROR
not $BIGBED_OK $Bio::ToolBox::db_helper::EVAL_ERROR
Truth table0%0/3
not(A) and B
A= not $BIGBED_OKB= $Bio::ToolBox::db_helper::EVAL_ERROR
ABresult
0X0
100
111
1952 0 carp "ERROR: $EVAL_ERROR";
1953 }
1954 }
1955 else {
1956 # we have to try each one out
1957 # try the modern big adapter first
1958 0 $BIGBED_OK = _load_helper_module('Bio::ToolBox::db_helper::big');
1959 0 ▶ if ($BIGBED_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGBED_OK) { } 0 0 0
1960 0 $BIGWIG_OK = $BIGBED_OK; # bigwig too!
1961 0 $BIG_ADAPTER = 'big';
1962 }
1963 else {
1964 0 $BIGBED_OK = _load_helper_module('Bio::ToolBox::db_helper::bigbed');
1965 0 ▶ if ($BIGBED_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BIGBED_OK) { } 0 0 0
1966 0 $BIG_ADAPTER = 'ucsc';
1967 }
1968 else {
1969 0 carp
1970 "ERROR: Neither Bio::DB::Big, Bio::DB::BigWig, or Bio::DB::BigBed are installed";
1971 }
1972 }
1973 }
1974 0 return $BIGBED_OK;
1975 }
1976  
1977 5 1;
1978  
1979 __END__
« lib/Bio/ToolBox/Data/file.pm ↑ Summary lib/Bio/ToolBox/db_helper/seqfasta.pm »