can download plant phenotype data in the same way as plot phenotype data
[sgn.git] / lib / SGN / Feature / GBrowse2.pm
blobd170be6484519b4237874330feb7dc34f5c09b2a
1 =head1 NAME
3 SGN::Feature::GBrowse2 - subclass of L<SGN::Feature::GBrowse> that tweaks the apache conf for GBrowse 2
5 =cut
7 package SGN::Feature::GBrowse2;
8 use Moose;
9 use namespace::autoclean;
10 extends 'SGN::Feature::GBrowse';
11 use Class::Load ':all';
12 use Bio::Graphics::FeatureFile;
14 has '_data_sources' => (
15 is => 'ro',
16 isa => 'HashRef',
17 traits => ['Hash'],
18 lazy_build => 1,
19 handles => {
20 data_sources => 'values',
21 data_source => 'get',
23 ); sub _build__data_sources {
24 my $self = shift;
26 unless( $self->config_master ) {
27 warn __PACKAGE__.': no master config found, skipping data sources configuration';
28 return {};
31 my $ds_class = __PACKAGE__.'::DataSource';
32 Class::Load::load_class( $ds_class );
34 my %sources;
35 foreach my $type ( $self->config_master->configured_types ) {
37 # absolutify the path from the config file
38 my $path = $self->config_master->setting( $type => 'path' )
39 or die "no path configured for [$type] in ".$self->config_master."\n";
40 $path = Path::Class::File->new( $path );
41 unless( $path->is_absolute ) {
42 $path = $self->conf_dir->file( $path );
45 $sources{$type} = $ds_class->new(
46 ( map {
47 $_ => $self->config_master->setting( $type => $_ )
48 } $self->config_master->setting( $type )
50 name => $type,
51 path => $path,
52 gbrowse => $self,
56 return \%sources;
59 has 'config_master' => (
60 is => 'ro',
61 lazy_build => 1,
62 ); sub _build_config_master {
64 my $master_file = shift->conf_dir->file('GBrowse.conf');
65 unless( -f $master_file ) {
66 warn __PACKAGE__.": master conf file $master_file not found";
67 return;
70 my $ff = Bio::Graphics::FeatureFile->new( -file => "$master_file" );
71 $ff->safe( 1 ); #< mark the file as safe, so we can use code refs
72 return $ff;
75 sub fpc_data_sources {
76 return
77 sort { my ($ad,$bd) = map $_->description =~ m|(20\d\d)|,$a,$b; $bd <=> $ad }
78 grep $_->description =~ /FPC/i,
79 shift->data_sources;
82 # returns a string of apache configuration to be included during
83 # startup. will be part of plugin role
84 around apache_conf => sub {
85 my ( $orig, $self ) = @_;
87 my $upstream_conf = $self->$orig();
89 my $static_dir = $self->static_dir;
90 my $static_url = $self->static_url;
92 my $conf = $self->conf_dir;
93 my $cgibin = $self->cgi_bin;
94 my $inc = $self->perl_inc;
95 my $fcgi_inc = @$inc ? "DefaultInitEnv PERL5LIB \"".join(':',@$inc).'"' : '';
96 my $cgi_inc = @$inc ? "SetEnv PERL5LIB ".join(':',@$inc) : '';
97 my $cgi_url = $self->cgi_url;
98 my $tmp = $self->tmp_dir;
100 my %runmode_conf = (
101 # modperl => <<"",
102 # Alias /$url_base "$cgibin"
103 # <Location /mgb2>
104 # SetHandler perl-script
105 # PerlResponseHandler ModPerl::Registry
106 # PerlOptions +ParseHeaders
107 # PerlSetEnv GBROWSE_CONF "$conf"
108 # </Location>
110 fcgi => <<"",
111 Alias $cgi_url "$cgibin"
112 <Location $cgi_url>
113 SetHandler fcgid-script
114 Options ExecCGI
115 </Location>
116 DefaultInitEnv GBROWSE_CONF "$conf"
117 BusyTimeout 360
118 IPCCommTimeout 300
119 MaxRequestLen 20971520
120 $fcgi_inc
122 cgi => <<"",
123 ScriptAlias $cgi_url "$cgibin"
124 <Directory "$cgibin">
125 $cgi_inc
126 SetEnv GBROWSE_CONF "$conf"
127 Order allow,deny
128 Allow from all
129 </Directory>
133 my $runmode_conf = $runmode_conf{ $self->run_mode }
134 or confess "invalid run mode '".$self->run_mode."'";
136 return $upstream_conf.<<EOC;
137 Alias "$static_url/i/" "$tmp/images/"
138 Alias "$static_url" "$static_dir"
140 <Location "$static_url">
141 SetHandler default-handler\n"
142 </Location>
143 <Directory "$static_dir">
144 Options -Indexes -MultiViews +FollowSymLinks
145 Order allow,deny
146 Allow from all
147 </Directory>
149 $runmode_conf