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

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 8 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 132 CC 16 SCAR 48.2
CC
16
Cov
0%
finish_load
210.0
load_line
12.0
Loader
2.0
CRAP 124.6
1 package Bio::Graphics::Browser2::DataLoader::bed;
2  
3 # $Id$
4  
5 use strict;
6 use Bio::DB::SeqFeature::Store;
7 use Carp 'croak';
8 use File::Basename 'basename';
9 use base 'Bio::Graphics::Browser2::DataLoader::generic';
10  
11 use constant TOO_SMALL_FOR_SUMMARY_MODE => 10000; # don't go into summary mode
12 my @COLORS = qw(blue red orange brown mauve peach
13 green cyan black yellow cyan papayawhip coral);
14  
15 sub Loader {
16 return 'Bio::DB::SeqFeature::Store::BedLoader';
17 }
18  
19 sub load_line {
20 my $self = shift;
21 my $line = shift;
22 my $prefix = $self->strip_prefix;
23  
24 chomp $line;
25 push @{$self->{conflines}},$line if $line =~ /^track/;
26 $line =~ s/^$prefix// if $prefix;
27 $self->loader->load_line($line);
28 }
29  
30 sub finish_load {
31 my $self = shift;
32  
33 my $line_count = shift;
34  
35 $self->set_status('creating database');
36 $self->loader->finish_load();
37  
38 my $db = $self->loader->store;
39 my $conf = $self->conf_fh;
40 my $trackname = $self->track_name;
41 my $dsn = $self->dsn;
42 my $backend = $self->backend;
43  
44 $self->write_gff3($db,$dsn) if $backend eq 'memory';
45  
46 my $loadid = $self->loadid;
47 my $summary = $line_count < TOO_SMALL_FOR_SUMMARY_MODE ? 'show summary = 0' : '';
48 eval {
49 $self->set_status('calculating summary statistics');
50 $self->loader->build_summary;
51 } unless $line_count < TOO_SMALL_FOR_SUMMARY_MODE;
52 warn $@ if $@;
53  
54 $self->set_status('creating configuration');
55  
56 my @lines = @{$self->{conflines}}; # correspond to a track line in the bed file
57 for (my $trackno=0; $trackno<@lines; $trackno++) {
58 my %options = $self->loader->parse_track_line($lines[$trackno]);
59  
60 # Hacky special case for a remote BigWig track
61 next unless $options{type} eq 'bigWig'&& $options{bigDataUrl};
62 my $dbid = "$loadid.$trackno";
63 print $conf <<END;
64 [$dbid:database]
65 db_adaptor = Bio::DB::BigWig
66 db_args = -bigwig $options{bigDataUrl}
67 search options = none
68  
69 END
70 }
71  
72 print $conf <<END;
73 [$loadid:database]
74 db_adaptor = Bio::DB::SeqFeature::Store
75 db_args = -adaptor $backend
76 -dsn $dsn
77  
78 #>>>>>>>>>> cut here <<<<<<<<
79 END
80 ;
81  
82  
83 unless (@lines) {
84 my $track_label = $self->new_track_label;
85 my $track_name = $self->track_name;
86 my $key = $track_name;
87 my $bgcolor = $COLORS[rand @COLORS];
88 my $glyph = 'gene';
89 my @types = $self->loader->loaded_types;
90 my $category = $self->category;
91 print $conf <<END;
92 [$track_label]
93 database = $loadid
94 category = $category
95 glyph = $glyph
96 feature = @types
97 key = $key
98 decorate_introns = 1
99 thin_utr = 1
100 utr_color= $bgcolor
101 fgcolor = $bgcolor
102 bgcolor = $bgcolor
103 $summary
104  
105 END
106 ;
107 }
108  
109 for (my $trackno=0; $trackno<@lines; $trackno++) {
110 my %options = $self->loader->parse_track_line($lines[$trackno]);
111 my $track_label = $self->new_track_label;
112 my $track_name = $self->track_name;
113 my $key = $options{name};
114 my $description= $options{description};
115 my $glyph = 'gene';
116 $options{visibility} ||= 'pack';
117 my $bump = $options{visibility} eq 'dense' ? 0
118 : $options{visibility} eq 'pack' ? 1
119 : $options{visibility} eq 'full' ? 2
120 : 1;
121 my $bgcolor = $options{itemRGB} ? 'featureRGB'
122 :$options{useScore} ? 'featureScore'
123 :$options{color} ? "rgb($options{color})"
124 :$COLORS[rand @COLORS];
125  
126 # Hacky special case for a remote BigWig track
127 if ($options{type} eq 'bigWig'&& $options{bigDataUrl}) {
128 my $dbid = "$loadid.$trackno";
129 print $conf <<END;
130 [$track_label]
131 database = $dbid
132 feature = summary
133 glyph = wiggle_whiskers
134 max_color = lightgrey
135 min_color = lightgrey
136 mean_color = black
137 stdev_color = grey
138 stdev_color_neg = grey
139 height = 50
140 citation = $description
141 key = $key
142  
143 END
144 } else { # conventional BED database
145 print $conf <<END;
146 [$track_label]
147 database = $loadid
148 category = My Tracks:Uploaded Tracks:$track_name
149 glyph = $glyph
150 feature = mRNA:$key region:$key
151 key = $key
152 citation = $description
153 decorate_introns = 1
154 thin_utr = 1
155 utr_color = $bgcolor
156 fgcolor = $bgcolor
157 bump = $bump
158 bgcolor = $bgcolor
159 $summary
160  
161 END
162 }
163 }
164 }
165  
166  
167 1;