blib/lib/Bio/Graphics/Browser2/DataLoader/bigwig.pm untested

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 23 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 127 CC 8 SCAR 30.0
CC
8
Cov
0%
finish_load
42.0
load
12.0
new
2.0
CRAP 20.0
1 package Bio::Graphics::Browser2::DataLoader::bigwig;
2  
3 # $Id$
4 use strict;
5 use base 'Bio::Graphics::Browser2::DataLoader';
6 use Bio::DB::BigWig;
7 use File::Basename 'basename','dirname';
8  
9 sub load {
10 my $self = shift;
11 my ($initial_lines,$fh) = @_;
12  
13 $self->flag_busy(1);
14 eval {
15 $self->open_conf;
16 $self->set_status('starting load');
17
18 mkdir $self->sources_path or die $!;
19 $self->{bigwig} = File::Spec->catfile($self->sources_path,$self->track_name);
20 my $source_file = IO::File->new($self->{bigwig},'>');
21  
22 warn "sourcefile=$self->{bigwig}";
23  
24 $self->start_load;
25  
26 $self->set_status('load data');
27 my $bytes_loaded = 0;
28 foreach (@$initial_lines) {
29 $source_file->print($_);
30 $bytes_loaded += length $_;
31 }
32  
33 my $buffer;
34 while ((my $bytes = read($fh,$buffer,8192) > 0)) {
35 $source_file->print($buffer);
36 $bytes_loaded += length $ buffer;
37 $self->set_status("loaded $bytes_loaded bytes") if $bytes++ % 10000;
38 }
39 $source_file->close();
40  
41 $self->finish_load;
42 $self->close_conf;
43 $self->set_processing_complete;
44 };
45  
46 $self->flag_busy(0);
47 die $@ if $@;
48 return $self->tracks;
49 }
50  
51 sub finish_load {
52 my $self = shift;
53  
54 my $loadid = $self->loadid;
55  
56 $self->set_status('creating configuration');
57 my $conf = $self->conf_fh;
58 my $dbid = $self->new_track_label;
59 my $bigwig = $self->{bigwig} or die "no bigwig file defined";
60 print $conf <<END;
61 [$dbid:database]
62 db_adaptor = Bio::DB::BigWig
63 db_args = -bigwig '$bigwig'
64  
65 END
66 ;
67 print $conf "#>>>>>>>>>> cut here <<<<<<<<\n";
68 my $options = {description=>''};
69 $options->{name} ||= $self->track_name;
70 $options->{visibility} ||= 'full';
71 $options->{maxHeightPixels} ||= $options->{visibility} eq 'full' ? 50 : 20;
72 $options->{autoScale} ||= 'off';
73 my @options;
74 push @options,"database = $dbid";
75 push @options,"feature = summary";
76 push @options,"key = $options->{name}";
77 push @options,'glyph = '. ($options->{visibility} eq 'pack'
78 ? 'wiggle_density'
79 : 'wiggle_whiskers' );
80 push @options,'autoscale = '.($options->{autoScale} eq 'on'
81 ? 'local'
82 : 'chromosome');
83 if (exists $options->{viewLimits} &&
84 (my ($low,$hi) = split ':',$options->{viewLimits})) {
85 push @options,"min_score = $low";
86 push @options,"max_score = $hi";
87 }
88  
89 if (exists $options->{maxHeightPixels} &&
90 (my ($max,$default,$min) = split ':',$options->{maxHeightPixels})) {
91 $default ||= $max;
92 push @options,"height = $default";
93 }
94 push @options,"description = $options->{description}";
95 my $config_lines = join "\n",@options;
96 print $conf <<END;
97 [$dbid]
98 $config_lines
99  
100 END
101 }
102  
103 sub new {
104 my $class = shift;
105 my $self = $class->SUPER::new(@_);
106 $self->{default_track_name} = 'track000';
107 $self;
108 }
109  
110 sub default_track_name {
111 my $self = shift;
112 return $self->{default_track_name}++;
113 }
114  
115 1;