1 package SGN
::Controller
::Locus
;
5 SGN::Controller::Locus - Catalyst controller for the locus page
6 (replacing the old cgi script)
11 use namespace
::autoclean
;
13 use URI
::FromHash
'uri';
15 use CXGN
::Phenome
::Locus
;
16 use CXGN
::Phenome
::Schema
;
17 use CXGN
::Tools
::Organism
;
18 use CXGN
::Phenome
::Locus
::LinkageGroup
;
20 BEGIN { extends
'Catalyst::Controller' }
21 with
'Catalyst::Component::ApplicationAttribute';
26 isa
=> 'DBIx::Class::Schema',
32 sub locus_search
: Path
('/search/locus') Args
(0) {
35 my ($organism_names_ref, $organism_ids_ref)=CXGN
::Tools
::Organism
::get_existing_organisms
( $c->dbc->dbh);
37 unshift @
$organism_names_ref, '';
38 unshift @
$organism_ids_ref, '';
41 for my $id ( @
$organism_ids_ref ) {
42 push( @organism_ref, [$id, $organism_names_ref->[$index]] );
45 my $lg_names_ref = CXGN
::Phenome
::Locus
::LinkageGroup
::get_all_lgs
( $c->dbc->dbh );
47 template
=> '/search/loci.mas',
48 organism_ref
=> \
@organism_ref,
49 lg_names_ref
=> $lg_names_ref,
56 shift->_app->dbic_schema( 'CXGN::Phenome::Schema' )
62 Public path: /locus/0/new
66 Chained off of L</get_locus> below.
70 sub new_locus
: Chained
('get_locus') PathPart
('new') Args
(0) {
71 my ( $self, $c ) = @_;
73 template
=> '/locus/index.mas',
78 locus
=> $c->stash->{locus
},
79 schema
=> $self->schema,
85 sub view_by_name
: Path
('/locus/view/') Args
(0) {
89 my $symbol = $c->req->param("symbol");
90 my $locusname = $c->req->param("locus");
91 my $species = $c->req->param("species");
95 if ($symbol && $species) {
96 $locus = $c->stash->{locus
} = CXGN
::Phenome
::Locus
->new_with_symbol_and_species($c->dbc->dbh, $symbol, $species);
100 $locus = $c->stash->{locus
} = CXGN
::Phenome
::Locus
->new_with_locusname($c->dbc->dbh, $locusname);
103 if (defined($locus->get_locus_id())) {
104 my $locus_id = $locus->get_locus_id();
105 $c->stash->{locus
} = $locus;
106 $c->detach("/locus/view/", [ $locus_id] ); #("/locus/$locus_id/view");
109 $c->stash->{template
} = 'generic_message.mas';
110 $c->stash->{message
} = "No locus was found for the identifier provided ($symbol $locusname $species).";
111 # forward to search page ?
120 Public path: /locus/<locus_id>/view
122 View a locus detail page.
124 Chained off of L</get_locus> below.
128 sub view_locus
: Chained
('get_locus') PathPart
('view') Args
(0) {
129 my ( $self, $c, $action) = @_;
130 my $locus = $c->stash->{locus
};
132 $c->forward('get_locus_extended_info');
135 my $logged_user = $c->user;
136 my $person_id = $logged_user->get_object->get_sp_person_id if $logged_user;
137 my $curator = $logged_user->check_roles('curator') if $logged_user;
138 my $submitter = $logged_user->check_roles('submitter') if $logged_user;
139 my $sequencer = $logged_user->check_roles('sequencer') if $logged_user;
140 my $dbh = $c->dbc->dbh;
142 my $trait_db_name => $c->get_conf('trait_ontology_db_name');
145 ###Check if a locus page can be printed###
146 my $locus_id = $locus ?
$locus->get_locus_id : undef ;
148 print STDERR
"LOCUS_ID: $locus_id ACTION: $action\n\n";
150 # print message if locus_id is not valid
151 unless ( ( $locus_id =~ m
/^\d+$/ ) || ($action eq 'new' && !$locus_id) ) {
152 $c->throw_404( "No locus exists for that identifier." );
154 unless ( $locus || !$locus_id && $action && $action eq 'new' ) {
155 $c->throw_404( "No locus exists for that identifier." );
158 # print message if the locus is obsolete
159 my $obsolete = $locus->get_obsolete();
160 if ( $obsolete eq 't' && !$curator ) {
161 $c->throw(is_client_error
=> 0,
162 title
=> 'Obsolete locus',
163 message
=> "Locus $locus_id is obsolete!",
164 developer_message
=> 'only curators can see obsolete loci',
165 notify
=> 0, #< does not send an error email
170 # print message if locus_id does not exist
171 if ( !$locus && $action ne 'new' && $action ne 'store' ) {
172 $c->throw_404('No locus exists for this identifier');
177 my $owner_ids = $c->stash->{owner_ids
} || [] ;
178 if ( $locus && ($curator || $person_id && ( grep /^$person_id$/, @
$owner_ids ) ) ) {
181 my $dbxrefs = $locus->get_dbxrefs;
182 my $image_ids = $locus->get_figure_ids;
183 my $cview_tmp_dir = $c->tempfiles_subdir('cview');
187 # 4. look up xrefs for all of them
188 map $c->feature_xrefs( $_, { exclude
=> 'locuspages' } ),
189 # 3. plus primary locus name
190 $locus->get_locus_name,
191 # 2. list of locus alias strings
192 map $_->get_locus_alias,
193 # 1. list of locus alias objects
194 $locus->get_locus_aliases( 'f', 'f' );
196 my ($feature, $src_feature) = $locus->get_src_feature;
199 template
=> '/locus/index.mas',
202 locus_id
=> $locus_id ,
204 submitter
=> $submitter,
205 sequencer
=> $sequencer,
206 person_id
=> $person_id,
207 user
=> $logged_user,
210 is_owner
=> $is_owner,
211 owners
=> $owner_ids,
213 cview_tmp_dir
=> $cview_tmp_dir,
214 cview_basepath
=> $c->get_conf('basepath'),
215 image_ids
=> $image_ids,
216 xrefs
=> \
@locus_xrefs,
217 trait_db_name
=> $trait_db_name,
219 src_feature
=> $src_feature,
221 locus_add_uri
=> $c->uri_for( '/ajax/locus/associate_locus' )->relative(),
222 cvterm_add_uri
=> $c->uri_for( '/ajax/locus/associate_ontology')->relative(),
223 assign_owner_uri
=> $c->uri_for( '/ajax/locus/assign_owner' )->relative(),
228 =head1 PRIVATE ACTIONS
232 Chain root for fetching a locus object to operate on.
234 Path part: /locus/<locus_id>
238 sub get_locus
: Chained
('/') PathPart
('locus') CaptureArgs
(1) {
239 my ($self, $c, $locus_id) = @_;
241 my $identifier_type = $c->stash->{identifier_type
}
242 || $locus_id =~ /[^-\d]/ ?
'locus' : 'locus_id';
244 if( $identifier_type eq 'locus_id' ) {
245 if ( $locus_id == 0 ) {
246 $c->stash->{locus
} = CXGN
::Phenome
::Locus
->new($c->dbc->dbh);
248 } elsif ( $locus_id < 0 ) {
249 $c->throw_client_error( public_message
=> 'Locus ID must be a positive integer.' );
252 #remove version numbers from locus name locus123.1.2
253 while ( $locus_id =~ m/.*\.\d+/ ) {
254 $locus_id =~ s/(.*)(\.\d+)/$1/ ;
257 my $matching_loci = $self->schema->resultset('Locus')->search(
259 $identifier_type => $locus_id,
263 if( $matching_loci->count > 1 ) {
264 $c->throw_client_error( public_message
=> 'Multiple matching loci' );
267 my ( $locus ) = $matching_loci->all
268 or $c->throw_404( "Locus not found" );
269 my $found_locus_id = $locus->locus_id;
271 $c->stash->{locus
} = CXGN
::Phenome
::Locus
->new($c->dbc->dbh, $found_locus_id);
280 sub get_locus_owner_ids
: Private
{
281 my ( $self, $c ) = @_;
282 my $locus = $c->stash->{locus
};
283 my @owner_ids = $locus ?
$locus->get_owners : ();
284 $c->stash->{owner_ids
} = \
@owner_ids;
287 sub get_locus_owner_objects
: Private
{
288 my ( $self, $c ) = @_;
289 my $locus = $c->stash->{locus
};
290 my $owner_objects = $locus ?
$locus->get_owners(1) : ();
291 $c->stash->{owner_objects
} = $owner_objects;
294 sub get_locus_extended_info
: Private
{
295 my ( $self, $c ) = @_;
296 $c->forward('get_locus_owner_ids');
301 #add the locus_dbxrefs to the stash.
302 sub get_locus_dbxrefs
: Private
{
303 my ( $self, $c ) = @_;
304 my $locus = $c->stash->{locus
};
305 my $locus_dbxrefs = $locus->get_dbxrefs;
306 $c->stash->{locus_dbxrefs
} = $locus_dbxrefs;
309 __PACKAGE__
->meta->make_immutable;