brapi allelematrix call pagination fix
[sgn.git] / lib / SGN / Feature / GBrowse.pm
blob7e8088953fd60c9dddf2ec2be74b26becb9a363a
1 =head1 NAME
3 SGN::Feature::GBrowse - site feature object to provide GBrowse integration
5 =cut
7 package SGN::Feature::GBrowse;
8 use Moose;
9 use namespace::autoclean;
11 extends 'SGN::Feature';
13 use Moose::Util::TypeConstraints;
14 use MooseX::Types::Path::Class qw | Dir File |;
15 use MooseX::Types::URI 'Uri';
16 use HTML::Mason::Interp;
18 { my $pi = subtype as 'ArrayRef';
19 coerce $pi,
20 from 'Value',
21 via { [$_] };
23 has 'perl_inc' => ( documentation => 'arrayref of paths to set in PERL5LIB if running in fastcgi or cgi mode',
24 is => 'ro',
25 isa => $pi,
26 default => sub { [] },
27 coerce => 1,
31 has '+description' => (
32 default => 'Genome browser',
35 has 'conf_dir' => ( documentation => 'directory where GBrowse will look for its conf files',
36 is => 'ro',
37 isa => Dir,
38 coerce => 1,
39 lazy_build => 1,
40 ); sub _build_conf_dir { my $self = shift; $self->tmpdir->subdir( 'rendered_conf' ) }
42 has 'conf_template_dir' => ( documentation => <<'EOD',
43 directory for configuration templates, which will be rendered on a one-to-one basis into $self->conf_dir during setup()
44 EOD
45 is => 'ro',
46 isa => Dir,
47 coerce => 1,
48 lazy_build => 1,
49 ); sub _build_conf_template_dir { shift->path_to('conf','templates') }
51 has 'static_url' => ( documentation => 'URL base for GBrowse static files',
52 is => 'ro',
53 isa => 'Str',
54 required => 1,
57 has 'static_dir' => (
58 is => 'ro',
59 isa => Dir,
60 coerce => 1,
61 required => 1,
64 has 'cgi_url' => (
65 is => 'ro',
66 isa => Uri,
67 required => 1,
68 coerce => 1,
70 has 'cgi_bin' => (
71 is => 'ro',
72 isa => Dir,
73 coerce => 1,
74 required => 1,
77 has 'tmp_dir' => (
78 is => 'ro',
79 isa => Dir,
80 coerce => 1,
81 required => 1,
84 has 'run_mode' => (
85 is => 'ro',
86 isa => 'Str',
87 required => 1,
91 # default database connection info used by gbrowse
92 has 'default_db_host' => (
93 is => 'ro',
94 isa => 'Str',
95 lazy_build => 1,
96 ); sub _build_default_db_host {
97 my $dsn = shift->context->dbc_profile->{dsn};
98 return unless $dsn =~ /host=([^;]+)/;
99 return $1;
101 has 'default_db_user' => (
102 is => 'ro',
103 isa => 'Str',
104 lazy_build => 1,
105 ); sub _build_default_db_user {
106 shift->context->dbc_profile->{user};
108 has 'default_db_password' => (
109 is => 'ro',
110 isa => 'Str',
111 lazy_build => 1,
112 ); sub _build_default_db_password {
113 shift->context->dbc_profile->{password};
117 sub local_inc {
118 'local @INC = ( '.join(', ',map "'$_'",@INC).' );';
122 # assembles a URI linking to gbrowse.
123 sub link_uri {
124 my ( $self, $conf_name, $params ) = @_;
126 my $uri = URI->new($self->cgi_url."/$conf_name/");
127 $uri->query_form( %$params );
128 return $uri;
132 after setup => sub {
133 my ( $self, $c ) = @_;
134 $self->render_all_configs;
137 sub xrefs {
138 my ( $self, $q ) = @_;
139 return unless defined $q;
141 # go through each data source and give it a crack at it
142 return map $_->xrefs($q), $self->data_sources;
145 sub data_sources {
146 die 'data_sources not yet implemented for gbrowse 1.x';
150 # for each .mas file in the $self->conf_template_dir directory, run
151 # templating on it and put the output in $self->conf_dir under the
152 # same filename, without the ending .mas
153 sub render_all_configs {
154 my $self = shift;
156 # all .mas files in the conf_template_dir
157 my @template_files;
158 $self->conf_template_dir->recurse(
159 callback => sub {
160 my ($child) = @_;
161 return if $child->is_dir || $child !~ /\.mas$/ || $child =~ /^#/ || $child =~ /~$/;
162 push @template_files, $child;
165 foreach my $template_file (@template_files) {
167 # assemble our target filename, which is the same file name
168 # (minus the .mas), in the $self->conf_dir directory
169 my $render_target_relative = $template_file->relative( $self->conf_template_dir );
170 $render_target_relative =~ s/\.mas$//;
171 my $render_target = $self->conf_dir->file( $render_target_relative );
173 $render_target->dir->mkpath;
174 $self->render_config_template( $template_file => $render_target );
177 # also symlink other things in the conf dir into there
178 for my $conf_thing ( $self->conf_template_dir->parent->children ) {
179 my $link_target = $self->conf_dir->file( $conf_thing->relative( $conf_thing->parent ) );
180 unlink $link_target;
181 symlink $conf_thing, $link_target
182 or die "$! linking $conf_thing -> $link_target";
186 sub render_config_template {
187 my ( $self, $template_file, $render_target ) = @_;
189 # render the template into the target file
190 # my $outbuf;
191 # my $mason = HTML::Mason::Interp
192 # ->new( allow_globals => [qw[ $c $feature ]],
193 # autohandler_name => '',
194 # comp_root => [['conf_templates', $self->conf_template_dir->stringify ]],
195 # out_method => \$outbuf,
196 # );
197 # $mason->set_global( '$c' => $self->context );
198 # $mason->set_global( '$feature' => $self );
200 # $mason->exec( '/'.$template_file->relative( $self->conf_template_dir) ); #< mason's default search path is current working directory
202 # $render_target->openw->print( $outbuf );
205 # # returns a string of apache configuration to be included during
206 # # startup. will be part of plugin role
207 # sub apache_conf {
208 # my ( $self ) = @_;
209 # my $dir = $self->static_dir;
210 # my $conf = $self->conf_dir;
211 # my $cgibin = $self->cgi_bin;
212 # my $tmp = $self->tmp_dir;
213 # my $cgiroot = basename($cgibin);
214 # my $perl5lib = $self->added_to_INC;
215 # my $inc = $perl5lib ? "SetEnv PERL5LIB \"$perl5lib\"" : '';
216 # my $fcgi_inc = $perl5lib ? "-initial-env PERL5LIB=$perl5lib" : '';
217 # my $fcgid_inc = $perl5lib ? "DefaultInitEnv PERL5LIB $perl5lib" : '';
218 # my $modperl_inc = $inc ? "Perl$inc" : '';
219 # my $url_base = $self->url_base;
221 # my %runmode_conf = (
222 # modperl => <<"",
223 # Alias /$url_base "$cgibin"
224 # <Location /mgb2>
225 # SetHandler perl-script
226 # PerlResponseHandler ModPerl::Registry
227 # PerlOptions +ParseHeaders
228 # PerlSetEnv GBROWSE_CONF "$conf"
229 # $modperl_inc
230 # </Location>
232 # fcgi => <<"",
233 # Alias /$url_base "$cgibin"
234 # <Location /fgb2>
235 # SetHandler fcgid-script
236 # Options ExecCGI
237 # </Location>
238 # DefaultInitEnv GBROWSE_CONF $conf
239 # $fcgid_inc
241 # fastcgi => <<"",
242 # Alias /$url_base "$cgibin"
243 # <Location /fgb2>
244 # SetHandler fastcgi-script
245 # Options ExecCGI
246 # </Location>
247 # FastCgiConfig $fcgi_inc -initial-env GBROWSE_CONF=$conf
249 # cgi => <<"",
250 # ScriptAlias "/$url_base" "$cgibin"
251 # <Directory "$cgibin">
252 # $inc
253 # SetEnv GBROWSE_CONF "$conf"
254 # </Directory>
256 # );
258 # my $runmode_conf = $runmode_conf{ $self->run_mode }
259 # or confess "invalid run mode '".$self->run_mode."'";
261 # return <<EOC;
262 # Alias "/$url_base/static/i/" "$tmp/images/"
263 # Alias "/$url_base/static" "$dir"
265 # <Directory "$dir">
266 # Options -Indexes -MultiViews +FollowSymLinks
267 # </Directory>
269 # $runmode_conf
270 # EOC
273 __PACKAGE__->meta->make_immutable;