3 SGN::Controller::AJAX::Genefamily::Manual - a REST controller class to provide the
4 backend for objects linked with manual curated gene family (a phenome locusgroup)
8 Add new locus members to an existing gene family
12 Naama Menda <nm249@cornell.edu>
17 package SGN
::Controller
::AJAX
::Genefamily
::Manual
;
21 use List
::MoreUtils qw
/any /;
23 use CXGN
::Phenome
::Schema
;
24 use CXGN
::Chado
::Publication
;
26 use CXGN
::Page
::FormattingHelpers qw
/ info_table_html html_alternate_show /;
28 BEGIN { extends
'Catalyst::Controller::REST' }
31 default => 'application/json',
33 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
37 sub display_locusgroup_members
: Chained
('/genefamily/manual/get_genefamily') :PathPart
('members') : ActionClass
('REST') { }
39 sub display_locusgroup_members_GET
{
43 my $locusgroup = $c->stash->{genefamily
};
44 my $members = $locusgroup->get_cxgn_members;
45 foreach my $locus_id (keys %$members) {
46 my $locus = $members->{$locus_id}->{locus
};
47 my $locus_name = $locus->get_locus_name;
48 my $common_name = $locus->get_common_name;
49 my $evidence = $members->{$locus_id}->{evidence
};
50 my $ref = $members->{$locus_id}->{reference
};
51 no warnings
'uninitialized';
52 $data{$common_name} .= qq|<a href
="/locus/$locus_id/view">$locus_name</a
> ($evidence. $ref)<br
/>| ;
54 foreach my $common_name (sort keys %data) {
55 $html .= info_table_html
( $common_name => $data{$common_name},
59 $hashref->{html
} = $html;
60 $c->stash->{rest
} = $hashref;
64 sub add_member
:Path
('/ajax/genefamily/manual/add') :ActionClass
('REST') {}
66 sub add_member_GET
:Args
(0) {
68 $c->stash->{rest
} = { error
=> "Nothing here, it's a GET.." } ;
71 sub add_member_POST
:Args
(0) {
72 my ( $self, $c ) = @_;
73 my $locusgroup_id = $c->req->param('locusgroup_id');
74 my $locus_input = $c->req->param('locus') ;
75 my $evidence_id = $c->req->param('evidence_id') ;
76 my $reference_id = $c->req->param('reference_id') ||
77 CXGN
::Chado
::Publication
::get_curator_ref
($c->dbc->dbh);
79 $self->status_bad_request($c, message
=> 'need locus input param' );
82 my ($locus_name, $locus_symbol, $locus_id) = split (/\|/ ,$locus_input);
83 my $phenome_schema = $c->dbic_schema('CXGN::Phenome::Schema');
84 my $locus = $phenome_schema
86 ->find({ locus_id
=> $locus_id, {} } );
88 $c->stash->{rest
} = { error
=> "no locus found for id '$locus_id' " };
91 my $locusgroup = $phenome_schema->resultset("Locusgroup")->find({locusgroup_id
=> $locusgroup_id } ) ;
93 $c->stash->{rest
} = { error
=> 'Must be logged in for associating loci! ' };
96 if ( any
{ $_ eq 'curator' || $_ eq 'submitter' || $_ eq 'sequencer' } $c->user->roles() ) {
97 # if this fails, it will throw an acception and will (probably rightly) be counted as a server error
98 my $user_id = $c->user->get_object->get_sp_person_id;
99 if ($locusgroup && $locus_id) {
101 my $locusgroup_member = $phenome_schema->resultset("LocusgroupMember")->find_or_create( {
102 locusgroup_id
=> $locusgroup_id,
103 locus_id
=> $locus_id,
104 sp_person_id
=> $user_id,
105 evidence_id
=> $evidence_id,
106 reference_id
=> $reference_id,
108 $c->stash->{rest
} = ['success'];
109 # need to update the loci div!!
112 $c->stash->{rest
} = { error
=> "Failed: $_" };
116 $c->stash->{rest
} = { error
=> 'need both valid locusgroup_id and locus_id for adding the locusgroup member! ' };
119 $c->stash->{rest
} = { error
=> 'No privileges for adding new locus to the locusgroup. You must have an sgn submitter account. Please contact sgn-feedback@solgenomics.net for upgrading your user account. ' };