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