4 use JSON
; #< used for encoding our return data as JSON, for use by the
9 use CXGN
::Metadata
; #< bac project associations are in the metadatadatabase
11 use CXGN
::Scrap
::AjaxPage
;
13 use CXGN
::People
::BACStatusLog
;
16 use CXGN
::Tools
::List qw
/str_in/;
17 use CXGN
::Page
::FormattingHelpers qw
/info_table_html columnar_table_html/;
19 use CXGN
::Genomic
::Clone
;
20 use CXGN
::Cview
::MapOverviews
::ProjectStats
;
22 use CatalystX
::GlobalContext
'$c';
24 our $page = CXGN
::Scrap
::AjaxPage
->new('text/html');
25 our $dbh = CXGN
::DB
::Connection
->new();
27 $page->send_http_header;
30 set_ver_int_read
=> sub { set_val_flag
('int_read') },
31 set_ver_bac_end
=> sub { set_val_flag
('bac_end') },
32 qclonehtml
=> \
&query_bac_infotable
,
33 qclonejson
=> \
&query_bac_json
,
34 qcloneperl
=> \
&query_bac_perl
,
37 my ($opname) = $page->get_encoded_arguments('action');
38 no strict
'refs'; #< using symbolic refs for sub names
39 $opname =~ /[^a-z_]/ and die "invalid op name '$opname'";
40 $ops{$opname} ||= \
&{"$opname"};
41 $ops{$opname} or die 'unknown operation';
42 print $ops{$opname}->();
45 ######## END OF MAIN SCRIPT
47 ######## OPERATIONS SUBS #############
50 my $person = get_valid_person
();
53 my ($id) = $page->get_encoded_arguments('val');
54 if($id && $id ne 'none') {
55 $id += 0; #< enforce numeric
56 str_in
($id,$person->get_projects_associated_with_person)
57 or die 'you do not have permission to make that assignment';
62 $clone->il_mapping_project_id($id,$person->get_sp_person_id);
63 return query_bac_json
($clone);
67 my ($argname,$funcname) = @_;
69 my $person = get_valid_person
();
72 my ($id) = $page->get_encoded_arguments('val');
73 if($id && $id ne 'none') {
79 $clone->il_mapping_data({bin_id
=>$id},$person->get_sp_person_id);
80 return query_bac_json
($clone);
84 my ($argname,$funcname) = @_;
86 my $person = get_valid_person
();
89 my ($chr) = $page->get_encoded_arguments('val');
96 $clone->il_mapping_data({chr =>$chr},$person->get_sp_person_id);
97 return query_bac_json
($clone);
101 my ($argname,$funcname) = @_;
103 my $person = get_valid_person
();
106 my ($notes) = $page->get_encoded_arguments('val');
109 $clone->il_mapping_data({notes
=> $notes},$person->get_sp_person_id);
110 return query_bac_json
($clone);
118 my $person = get_valid_person
();
119 my ($proj_id) = $page->get_encoded_arguments('val');
124 $proj_id += 0; #< enforce numeric
125 $person->is_person_associated_with_project($proj_id)
126 or die "not authorized to assign a clone to that project\n";
128 my $current_proj = metadata
()->get_project_associated_with_bac($clone->clone_id);
130 !$current_proj or $person->is_person_associated_with_project($current_proj)
131 or die "not authorized to take a bac away from that chromosome project\n";
133 metadata
()->attribute_bac_to_project($clone->clone_id,$proj_id);
134 return query_bac_json
($clone);
139 my $person = get_valid_person
();
140 my ($stat) = $page->get_encoded_arguments('val');
142 my $current_proj = metadata
()->get_project_associated_with_bac($clone->clone_id);
144 $person->is_person_associated_with_project($current_proj)
145 or die "not authorized to change seq status for that bac\n";
147 bac_status_log
()->change_status( bac
=> $clone->clone_id,
148 person
=> $person->get_sp_person_id,
151 return query_bac_json
($clone);
156 my $person = get_valid_person
();
157 my ($stat) = $page->get_encoded_arguments('val');
159 my $current_proj = metadata
()->get_project_associated_with_bac($clone->clone_id);
161 $person->is_person_associated_with_project($current_proj)
162 or die "not authorized to change genbank status for that bac\n";
164 bac_status_log
()->change_status( bac
=> $clone->clone_id,
165 person
=> $person->get_sp_person_id,
166 genbank_status
=> $stat,
168 return query_bac_json
($clone);
174 my $person = get_valid_person
();
176 my ($stat) = $page->get_encoded_arguments('val');
178 $clone->verification_flags(person
=> $person, $flagname => $stat ?
1 : 0);
179 return query_bac_json
($clone);
182 sub query_bac_infotable
{
183 my $clone = shift() || clone
();
184 my $info = $clone->reg_info_hashref;
185 return info_table_html
( __multicol
=> 2,
187 'Assigned to project' => $info->{il_proj
}{disp
},
188 'Mapped to IL segment' => $info->{il_bin
}{disp
},
193 my $clone = shift() || clone
();
194 return to_json
( $clone->reg_info_hashref );
198 my $clone = shift() || clone
();
199 local $Data::Dumper
::Terse
= 1;
200 return Dumper
$clone->reg_info_hashref;
203 sub project_stats_img_html
{
205 # force re-calculation of the image/stats
206 my $map_overview = CXGN
::Cview
::MapOverviews
::ProjectStats
->new(
209 basepath
=> $c->get_conf('basepath'),
210 tempfiles_subdir
=> $c->tempfiles_subdir('cview'),
211 progress_data
=> bac_status_log
()->bac_by_bac_progress_statistics,
214 $map_overview->render_map();
215 my $map_overview_html = $map_overview->get_image_html();
217 # also generate a smaller version of the image that is
218 # used on the homepage.
220 $map_overview->create_mini_overview;
222 return $map_overview_html;
226 ############ UTILITY SUBS #############
227 # these subs are used by the main operations subs above
231 #did we get a clone_id argument? if so, lookup from that
232 my ($id) = $page->get_encoded_arguments('clone_id');
235 my $c = CXGN
::Genomic
::Clone
->retrieve($id)
236 or die 'could not retrieve clone from id';
240 my ($name) = $page->get_encoded_arguments('clone_name');
241 #otherwise, did we get a clone_name arg? if so, lookup from that
243 my $c = CXGN
::Genomic
::Clone
->retrieve_from_clone_name($name)
244 or die 'could not retrieve clone from name';
248 die 'must provide either clone ID (clone_id argument) or clone name (clone_name argument)';
251 sub get_valid_person
{
252 my $person_id = CXGN
::Login
->new($dbh)->has_session
253 or die 'you must log in to access this page';
254 my $person = CXGN
::People
::Person
->new($dbh, $person_id);
256 str_in
($person->get_user_type,qw
/sequencer curator/)
257 or die 'you do not have permission to make that assignment';
263 our $metadata ||= CXGN
::Metadata
->new(); # metadata object
267 our $bac_status_log ||= CXGN
::People
::BACStatusLog
->new($dbh); # bac ... status ... object