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

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 80 CC 3 SCAR 16.1
CC
3
Cov
0%
load
12.0
new
2.0
default_track_name
2.0
CRAP 5.0
1 package Bio::Graphics::Browser2::DataLoader::bigbed;
2  
3 # $Id$
4 use strict;
5 use base 'Bio::Graphics::Browser2::DataLoader';
6 use Bio::DB::BigBed;
7 use File::Basename 'basename','dirname';
8 my @COLORS = qw(blue red orange brown mauve peach
9 green cyan yellow coral);
10  
11 sub new {
12 my $class = shift;
13 my $self = $class->SUPER::new(@_);
14 $self->{default_track_name} = 'track000';
15 $self;
16 }
17  
18 sub default_track_name {
19 my $self = shift;
20 return $self->{default_track_name}++;
21 }
22  
23 sub load {
24 my $self = shift;
25 my ($initial_lines,$fh) = @_;
26  
27 $self->flag_busy(1);
28 eval {
29 $self->open_conf;
30 $self->set_status('starting load');
31
32 mkdir $self->sources_path or die $!;
33 $self->{bigbed} = File::Spec->catfile($self->sources_path,$self->track_name);
34 my $source_file = IO::File->new($self->{bigbed},'>');
35  
36 warn "sourcefile=$self->{bigbed}";
37  
38 $self->start_load;
39  
40 $self->set_status('load data');
41 my $bytes_loaded = 0;
42 foreach (@$initial_lines) {
43 $source_file->print($_);
44 $bytes_loaded += length $_;
45 }
46  
47 my $buffer;
48 while ((my $bytes = read($fh,$buffer,8192) > 0)) {
49 $source_file->print($buffer);
50 $bytes_loaded += length $ buffer;
51 $self->set_status("loaded $bytes_loaded bytes") if $bytes++ % 10000;
52 }
53 $source_file->close();
54  
55 $self->finish_load;
56 $self->close_conf;
57 $self->set_processing_complete;
58 };
59  
60 $self->flag_busy(0);
61 die $@ if $@;
62 return $self->tracks;
63 }
64  
65 sub finish_load {
66 my $self = shift;
67  
68 my $loadid = $self->loadid;
69  
70 $self->set_status('creating configuration');
71 my $conf = $self->conf_fh;
72 my $dbid = $self->new_track_label;
73 my $bigbed = $self->{bigbed} or die "no bigbed file defined";
74 print $conf <<END;
75 [$dbid:database]
76 db_adaptor = Bio::DB::BigBed
77 db_args = -bigbed '$bigbed'
78  
79 END
80 ;
81 print $conf "#>>>>>>>>>> cut here <<<<<<<<\n";
82 my $color = $COLORS[rand @COLORS];
83 my $name = $self->track_name;
84
85 print $conf <<END
86 [$dbid]
87 database = $dbid
88 feature = region
89 glyph = segments
90 label density = 50
91 feature_limit = 500
92 bump = fast
93 stranded = 1
94 height = 4
95 bgcolor = $color
96 fgcolor = $color
97 key = $name segments
98 description =
99  
100 [$dbid\_coverage]
101 database = $dbid
102 feature = summary
103 glyph = wiggle_whiskers
104 fgcolor = black
105 height = 50
106 autoscale = chromosome
107 key = $name coverage
108 description =
109  
110 END
111 ;
112 # We are defining two separate tracks rather than using semantic zoom
113 # because of the flexible nature of the bigBed format. It can be used
114 # as a Bam substitute where coverage is the best glyph, or it can be used
115 # for sparse intervals of interest where segments is the best glyph.
116 # Onus is on the user to select the most appropriate one.
117 }
118  
119 1;