add a db stats page.
[sgn.git] / lib / SGN / Controller / Feature.pm
blobe237aebcc598f521ae0c9bdb52fdcc7e922f5e31
1 package SGN::Controller::Feature;
3 =head1 NAME
5 SGN::Controller::Feature - Catalyst controller for pages dealing with
6 Chado (i.e. Bio::Chado::Schema) features
8 =cut
10 use Moose;
11 use namespace::autoclean;
12 use SGN::View::Feature qw / feature_types feature_organisms / ;
14 BEGIN { extends 'Catalyst::Controller' }
16 has 'schema' => (
17 is => 'rw',
18 isa => 'DBIx::Class::Schema',
19 lazy_build => 1,
21 sub _build_schema {
22 shift->_app->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' )
25 has 'default_page_size' => (
26 is => 'ro',
27 default => 20,
31 =head1 PUBLIC ACTIONS
33 =cut
36 # deprecated old paths are now redirects
37 sub view_by_name :Path('/feature/view/name') Path('/feature/view/id') Args(1) {
38 my ( $self, $c, $id ) = @_;
39 $c->res->redirect("/feature/$id/details",301);
42 #######################################
44 sub feature_details :PathPart('details') :Chained('get_feature') Args(0) {
45 my ( $self, $c ) = @_;
47 $c->forward('get_type_specific_data')
48 && $c->forward('choose_view');
51 sub choose_view :Private {
52 my ( $self, $c ) = @_;
53 my $feature = $c->stash->{feature};
54 my $type_name = lc $feature->type->name;
55 my $template = "/feature/types/default.mas";
57 $c->stash->{feature} = $feature;
58 $c->stash->{featurelocs} = $feature->featureloc_features;
60 # look up site xrefs for this feature
61 my @xrefs = map $c->feature_xrefs( $_, { exclude => 'featurepages' } ),
62 ( $feature->name, $feature->synonyms->get_column('name')->all );
63 unless( @xrefs ) {
64 @xrefs = map {
65 $c->feature_xrefs( $_->srcfeature->name.':'.($_->fmin+1).'..'.$_->fmax, { exclude => 'featurepages' } )
67 #$c->stash->{featurelocs}->all
68 $c->stash->{featurelocs}->search({locgroup => 0,},)->all
70 $c->stash->{xrefs} = \@xrefs;
72 if ($c->view('Mason')->component_exists("/feature/types/$type_name.mas")) {
73 $template = "/feature/types/$type_name.mas";
74 $c->stash->{type} = $type_name;
76 $c->stash->{template} = $template;
78 return 1;
81 sub get_feature : Chained('/') CaptureArgs(1) PathPart('feature') {
82 my ($self, $c, $id ) = @_;
84 $c->stash->{blast_url} = '/tools/blast';
86 my $identifier_type = $c->stash->{identifier_type}
87 || $id =~ /[^-\d]/ ? 'name' : 'feature_id';
89 if( $identifier_type eq 'feature_id' ) {
90 $id > 0
91 or $c->throw_client_error( public_message => 'Feature ID must be a positive integer.' );
94 #debug mode
95 #$c->dbic_schema('Bio::Chado::Schema','sgn_chado')->storage->debug(1);
97 my $matching_features =
98 $c->dbic_schema('Bio::Chado::Schema','sgn_chado')
99 ->resultset('Sequence::Feature')
100 ->search(
101 #{ 'me.'.$identifier_type => $id },
102 { 'me.'.$identifier_type => $id, 'featureloc_features.locgroup' => 0 },
103 { prefetch => [ 'organism', 'type', 'featureloc_features' ] },
106 if( $matching_features->count > 1 ) {
107 $c->throw_client_error( public_message => 'Multiple matching features' );
110 my ( $feature ) = $matching_features->all;
111 $c->stash->{feature} = $feature
112 or $c->throw_404( "Feature not found" );
114 return 1;
117 sub get_type_specific_data :Private {
118 my ( $self, $c ) = @_;
120 my $type_name = $c->stash->{feature}->type->name;
122 # look for an action with private path /feature/types/<type>/get_specific_data
123 my $action = $c->get_action( 'get_specific_data', $self->action_namespace."/types/$type_name" );
124 if( $action ) {
125 $c->forward( $action ) or return;
128 return 1;