clean
[sgn.git] / lib / SGN / Controller / Feature.pm
blobb6923d4f464b8fc724a84127fe4275756ff1a2b5
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;
13 BEGIN { extends 'Catalyst::Controller' }
15 =head1 PUBLIC ACTIONS
17 =cut
19 # deprecated old paths are now redirects
20 sub view_by_name :Path('/feature/view/name') Path('/feature/view/id') Args(1) {
21 my ( $self, $c, $id ) = @_;
22 $c->res->redirect("/feature/$id/details",301);
25 #######################################
27 sub feature_details :PathPart('details') :Chained('get_feature') Args(0) {
28 my ( $self, $c ) = @_;
30 $c->forward('get_type_specific_data')
31 && $c->forward('choose_view');
34 sub choose_view :Private {
35 my ( $self, $c ) = @_;
36 my $feature = $c->stash->{feature};
37 my $type_name = lc $feature->type->name;
38 my $template = "/feature/types/default.mas";
40 $c->stash->{feature} = $feature;
41 $c->stash->{featurelocs} = $feature->featureloc_features;
43 # look up site xrefs for this feature
44 my @xrefs = map $c->feature_xrefs( $_, { exclude => 'featurepages' } ),
45 ( $feature->name, $feature->synonyms->get_column('name')->all );
46 unless( @xrefs ) {
47 @xrefs = map {
48 $c->feature_xrefs( $_->srcfeature->name.':'.($_->fmin+1).'..'.$_->fmax, { exclude => 'featurepages' } )
50 #$c->stash->{featurelocs}->all
51 $c->stash->{featurelocs}->search({locgroup => 0,},)->all
53 $c->stash->{xrefs} = \@xrefs;
55 if ($c->view('Mason')->component_exists("/feature/types/$type_name.mas")) {
56 $template = "/feature/types/$type_name.mas";
57 $c->stash->{type} = $type_name;
59 $c->stash->{template} = $template;
61 return 1;
64 sub get_feature : Chained('/') CaptureArgs(1) PathPart('feature') {
65 my ($self, $c, $id ) = @_;
67 $c->stash->{blast_url} = '/tools/blast';
69 my $identifier_type = $c->stash->{identifier_type}
70 || $id =~ /[^-\d]/ ? 'name' : 'feature_id';
72 if( $identifier_type eq 'feature_id' ) {
73 $id > 0
74 or $c->throw_client_error( public_message => 'Feature ID must be a positive integer.' );
77 #debug mode
78 #$c->dbic_schema('Bio::Chado::Schema','sgn_chado')->storage->debug(1);
80 my $matching_features =
81 $c->dbic_schema('Bio::Chado::Schema','sgn_chado')
82 ->resultset('Sequence::Feature')
83 ->search(
84 #{ 'me.'.$identifier_type => $id },
85 { 'me.'.$identifier_type => $id, 'featureloc_features.locgroup' => 0 },
86 { prefetch => [ 'organism', 'type', 'featureloc_features' ] },
89 if( $matching_features->count > 1 ) {
90 $c->throw_client_error( public_message => 'Multiple matching features' );
93 my ( $feature ) = $matching_features->all;
94 $c->stash->{feature} = $feature
95 or $c->throw_404( "Feature not found" );
97 return 1;
100 sub get_type_specific_data :Private {
101 my ( $self, $c ) = @_;
103 my $type_name = $c->stash->{feature}->type->name;
105 # look for an action with private path /feature/types/<type>/get_specific_data
106 my $action = $c->get_action( 'get_specific_data', $self->action_namespace."/types/$type_name" );
107 if( $action ) {
108 $c->forward( $action ) or return;
111 return 1;