2 package SGN
::Controller
::AJAX
::GenotypingTrial
;
7 use CXGN
::Trial
::TrialDesign
;
9 use List
::MoreUtils qw
/any /;
10 use CXGN
::People
::Person
;
12 use CXGN
::Genotype
::Protocol
;
13 use CXGN
::Genotype
::CreatePlateOrder
;
14 use CXGN
::Genotype
::StoreGenotypingProject
;
16 BEGIN { extends
'Catalyst::Controller::REST' }
19 default => 'application/json',
21 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
24 sub generate_genotype_trial
: Path
('/ajax/breeders/generategenotypetrial') ActionClass
('REST') {}
25 sub generate_genotype_trial_POST
: Args
(0) {
29 if (!($c->user()->check_roles('curator') || $c->user()->check_roles('submitter'))) {
30 $c->stash->{rest
} = { error
=> 'You do not have the required privileges to create a genotyping plate.' };
34 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
35 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);
36 my $plate_info = decode_json
$c->req->param("plate_data");
37 #print STDERR Dumper $plate_info;
39 if ( !$plate_info->{elements
} || !$plate_info->{genotyping_facility_submit
} || !$plate_info->{genotyping_project_id
} || !$plate_info->{name
} || !$plate_info->{sample_type
} || !$plate_info->{plate_format
} ) {
40 $c->stash->{rest
} = { error
=> "Please provide all parameters in the plate information section" };
44 my $genotyping_project_id = $plate_info->{genotyping_project_id
};
45 my $trial = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $genotyping_project_id });
46 my $genotyping_facility = $trial->get_genotyping_facility();
48 if ( $genotyping_facility eq 'igd' && $plate_info->{genotyping_facility_submit
} eq 'yes' && $plate_info->{blank_well
} eq ''){
49 $c->stash->{rest
} = { error
=> "To submit to Cornell IGD you need to provide the blank well!" };
53 my $td = CXGN
::Trial
::TrialDesign
->new( { schema
=> $schema });
55 $td->set_stock_list($plate_info->{elements
});
56 $td->set_block_size($plate_info->{plate_format
});
57 $td->set_blank($plate_info->{blank_well
});
58 $td->set_trial_name($plate_info->{name
});
59 $td->set_design_type("genotyping_plate");
62 $td->calculate_design();
66 $c->stash->{rest
} = { error
=> "Design failed. Error: $@" };
67 print STDERR
"Design failed because of $@\n";
71 my $design = $td->get_design();
73 if (exists($design->{error
})) {
74 $c->stash->{rest
} = $design;
78 #Add common answers from form to all wells
79 foreach (values %$design){
80 $_->{concentration
} = $plate_info->{well_concentration
};
81 $_->{volume
} = $plate_info->{well_volume
};
82 $_->{tissue_type
} = $plate_info->{well_tissue
};
83 $_->{dna_person
} = $plate_info->{well_dna_person
};
84 $_->{extraction
} = $plate_info->{well_extraction
};
85 $_->{acquisition_date
} = $plate_info->{well_date
};
86 $_->{notes
} = $plate_info->{well_notes
};
87 $_->{ncbi_taxonomy_id
} = $plate_info->{ncbi_taxonomy_id
};
89 #print STDERR Dumper($design);
91 $c->stash->{rest
} = {success
=> 1, design
=>$design};
95 sub parse_genotype_trial_file
: Path
('/ajax/breeders/parsegenotypetrial') : ActionClass
('REST') { }
96 sub parse_genotype_trial_file_POST
: Args
(0) {
99 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
100 my $chado_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado', $sp_person_id);
101 my $metadata_schema = $c->dbic_schema("CXGN::Metadata::Schema", undef, $sp_person_id);
102 my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema", undef, $sp_person_id);
103 my $dbh = $c->dbc->dbh;
104 my $genotyping_plate_name = $c->req->param('genotyping_trial_name');
105 my $upload_xls = $c->req->upload('genotyping_trial_layout_upload');
106 my $upload_coordinate = $c->req->upload('genotyping_trial_layout_upload_coordinate');
107 my $upload_coordinate_custom = $c->req->upload('genotyping_trial_layout_upload_coordinate_template');
108 my $facility_identifiers= $c->req->param('upload_include_facility_identifiers');
109 my $include_facility_identifiers;
110 if ($facility_identifiers){
111 $include_facility_identifiers = 1;
115 if ($upload_xls && $upload_coordinate){
116 $c->stash->{rest
} = {error
=> "Do not upload both XLS and Coordinate file at the same time!" };
119 if ($upload_xls && $upload_coordinate_custom){
120 $c->stash->{rest
} = {error
=> "Do not upload both XLS and Custom Coordinate file at the same time!" };
123 if ($upload_coordinate && $upload_coordinate_custom){
124 $c->stash->{rest
} = {error
=> "Do not upload both Coordinate file and Custom Coordinate file at the same time!" };
127 if (!$upload_xls && !$upload_coordinate && !$upload_coordinate_custom){
128 $c->stash->{rest
} = {error
=> "You must upload a genotyping plate file!" };
131 if (!$genotyping_plate_name){
132 $c->stash->{rest
} = {error
=> 'Genotyping plate id must be given!'};
140 $upload = $upload_xls;
141 $upload_type = 'GenotypeTrialXLS';
143 if ($upload_coordinate){
144 $upload = $upload_coordinate;
145 $upload_type = 'GenotypeTrialCoordinate';
147 if ($upload_coordinate_custom){
148 $upload = $upload_coordinate_custom;
149 $upload_type = 'GenotypeTrialCoordinateTemplate';
151 my $upload_original_name = $upload->filename();
152 my $upload_tempfile = $upload->tempname;
153 my $subdirectory = "genotyping_trial_upload";
154 my $archived_filename_with_path;
161 my $time = DateTime
->now();
162 my $timestamp = $time->ymd()."_".$time->hms();
165 if ($upload_original_name =~ /\s/ || $upload_original_name =~ /\// || $upload_original_name =~ /\\/ ) {
166 print STDERR
"File name must not have spaces or slashes.\n";
167 $c->stash->{rest
} = {error
=> "Uploaded file name must not contain spaces or slashes." };
174 my $session_id = $c->req->param("sgn_session_id");
177 my $dbh = $c->dbc->dbh;
178 my @user_info = CXGN
::Login
->new($dbh)->query_from_cookie($session_id);
180 $c->stash->{rest
} = {error
=>'You must be logged in to upload genotyping plate!'};
183 $user_id = $user_info[0];
184 $user_role = $user_info[1];
185 my $p = CXGN
::People
::Person
->new($dbh, $user_id);
186 $user_name = $p->get_username;
189 $c->stash->{rest
} = {error
=>'You must be logged in to upload a genotyping plate!'};
192 $user_id = $c->user()->get_object()->get_sp_person_id();
193 $user_name = $c->user()->get_object()->get_username();
194 $user_role = $c->user->get_object->get_user_type();
197 if ($user_role ne 'curator' && $user_role ne 'submitter') {
198 $c->stash->{rest
} = {error
=> "You have insufficient privileges to upload a genotyping plate." };
202 ## Store uploaded temporary file in archive
203 my $uploader = CXGN
::UploadFile
->new({
204 tempfile
=> $upload_tempfile,
205 subdirectory
=> $subdirectory,
206 archive_path
=> $c->config->{archive_path
},
207 archive_filename
=> $upload_original_name,
208 timestamp
=> $timestamp,
210 user_role
=> $user_role
212 $archived_filename_with_path = $uploader->archive();
213 $md5 = $uploader->get_md5($archived_filename_with_path);
214 if (!$archived_filename_with_path) {
215 $c->stash->{rest
} = {error
=> "Could not save file $upload_original_name in archive",};
218 unlink $upload_tempfile;
220 #Parse of Coordinate Template formatted file requires the plate name to be passed, so that a unique sample name can be created by concatenating the plate name to the well position.
222 genotyping_plate_id
=> $genotyping_plate_name
225 #parse uploaded file with appropriate plugin
226 $parser = CXGN
::Trial
::ParseUpload
->new(chado_schema
=> $chado_schema, filename
=> $archived_filename_with_path, facility_identifiers_included
=> $include_facility_identifiers);
227 $parser->load_plugin($upload_type);
228 $parsed_data = $parser->parse(\
%parse_args);
231 my $return_error = '';
233 if (! $parser->has_parse_errors() ){
234 $return_error = "Could not get parsing errors";
235 $c->stash->{rest
} = {error_string
=> $return_error,};
238 $parse_errors = $parser->get_parse_errors();
239 #print STDERR Dumper $parse_errors;
240 foreach my $error_string (@
{$parse_errors->{'error_messages'}}){
241 $return_error=$return_error.$error_string."<br>";
245 $c->stash->{rest
} = {error_string
=> $return_error, missing_accessions
=> $parse_errors->{'missing_accessions'}};
248 #print STDERR Dumper $parsed_data;
250 #Turn parased data into same format as generate_genotype_trial above
252 foreach (sort keys %$parsed_data){
253 my $val = $parsed_data->{$_};
254 $design{$val->{well
}} = {
255 plot_name
=> $val->{sample_id
},
256 stock_name
=> $val->{source_stock_uniquename
},
257 plot_number
=> $val->{well
},
258 row_number
=> $val->{row
},
259 col_number
=> $val->{column
},
260 is_blank
=> $val->{is_blank
},
261 concentration
=> $val->{concentration
},
262 volume
=> $val->{volume
},
263 tissue_type
=> $val->{tissue_type
},
264 dna_person
=> $val->{dna_person
},
265 extraction
=> $val->{extraction
},
266 acquisition_date
=> $val->{date
},
267 notes
=> $val->{notes
},
268 ncbi_taxonomy_id
=> $val->{ncbi_taxonomy_id
},
269 facility_identifier
=> $val->{facility_identifier
}
273 $c->stash->{rest
} = {success
=> "1", design
=>\
%design};
276 sub store_genotype_trial
: Path
('/ajax/breeders/storegenotypetrial') ActionClass
('REST') {}
277 sub store_genotype_trial_POST
: Args
(0) {
284 my $session_id = $c->req->param("sgn_session_id");
287 my $dbh = $c->dbc->dbh;
288 my @user_info = CXGN
::Login
->new($dbh)->query_from_cookie($session_id);
290 $c->stash->{rest
} = {error
=>'You must be logged in to upload genotyping plate!'};
293 $user_id = $user_info[0];
294 $user_role = $user_info[1];
295 my $p = CXGN
::People
::Person
->new($dbh, $user_id);
296 $user_name = $p->get_username;
299 $c->stash->{rest
} = {error
=>'You must be logged in to upload a genotyping plate!'};
302 $user_id = $c->user()->get_object()->get_sp_person_id();
303 $user_name = $c->user()->get_object()->get_username();
304 $user_role = $c->user->get_object->get_user_type();
307 if ($user_role ne 'curator' && $user_role ne 'submitter') {
308 $c->stash->{rest
} = {error
=> "You have insufficient privileges to upload a genotyping plate." };
312 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
313 my $plate_info = decode_json
$c->req->param("plate_data");
314 # print STDERR "PLATE INFO =".Dumper($plate_info)."\n";
316 if ( !$plate_info->{design
} || !$plate_info->{genotyping_facility_submit
} || !$plate_info->{genotyping_project_id
} || !$plate_info->{name
} || !$plate_info->{sample_type
} || !$plate_info->{plate_format
} ) {
317 $c->stash->{rest
} = { error
=> "Please provide all parameters in the plate information section" };
321 my $field_nd_experiment_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_layout', 'experiment_type')->cvterm_id();
322 my $tissue_sample_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'tissue_sample', 'stock_type')->cvterm_id;
323 my $plant_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plant', 'stock_type')->cvterm_id;
324 my $plot_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot', 'stock_type')->cvterm_id;
325 my %source_stock_names;
326 foreach (values %{$plate_info->{design
}}){
327 $source_stock_names{$_->{stock_name
}}++;
329 my @source_stock_names = keys %source_stock_names;
331 #If plots or plants or tissue samples are provided as the source, we can get the field trial and use it to save the link between genotyping plate and field trial directly.
333 my $plant_rs = $schema->resultset('Stock::Stock')->search({'me.uniquename' => {-in => \
@source_stock_names}, 'me.type_id' => {-in => [$plot_cvterm_id, $plant_cvterm_id, $tissue_sample_cvterm_id]}, 'nd_experiment_stocks.type_id'=>$field_nd_experiment_type_id, 'nd_experiment.type_id'=>$field_nd_experiment_type_id}, {'join' => {'nd_experiment_stocks' => {'nd_experiment' => 'nd_experiment_projects'}}, '+select'=>['nd_experiment_projects.project_id'], '+as'=>['trial_id']});
334 while(my $r=$plant_rs->next){
335 $field_trial_ids{$r->get_column('trial_id')}++;
337 my @field_trial_ids = keys %field_trial_ids;
338 #print STDERR Dumper \@field_trial_ids;
341 my $genotyping_project_id = $plate_info->{genotyping_project_id
};
342 my $trial = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $genotyping_project_id });
343 my $location_data = $trial->get_location();
344 my $location_id = $location_data->[0];
345 my $location_name = $location_data->[1];
348 my $plate_description = $plate_info->{description
};
349 if ($plate_description) {
350 $description = $plate_description;
352 $description = $trial->get_description();
355 my $program_object = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $schema });
356 my $breeding_program_data = $program_object->get_breeding_programs_by_trial($genotyping_project_id);
357 my $breeding_program_id = $breeding_program_data->[0]->[0];
358 my $breeding_program_name = $breeding_program_data->[0]->[1];
359 my $genotyping_facility = $trial->get_genotyping_facility();
360 my $plate_year = $trial->get_year();
362 print STDERR
"Creating the genotyping plate...\n";
367 my $ct = CXGN
::Trial
::TrialCreate
->new( {
368 chado_schema
=> $schema,
369 dbh
=> $c->dbc->dbh(),
370 owner_id
=> $user_id,
371 operator
=> $user_name,
372 trial_year
=> $plate_year,
373 trial_location
=> $location_name,
374 program
=> $breeding_program_name,
375 trial_description
=> $description,
376 design_type
=> 'genotyping_plate',
377 design
=> $plate_info->{design
},
378 trial_name
=> $plate_info->{name
},
380 genotyping_user_id
=> $user_id,
381 genotyping_project_id
=> $genotyping_project_id,
382 genotyping_facility_submitted
=> $plate_info->{genotyping_facility_submit
},
383 genotyping_facility
=> $genotyping_facility,
384 genotyping_plate_format
=> $plate_info->{plate_format
},
385 genotyping_plate_sample_type
=> $plate_info->{sample_type
},
386 genotyping_trial_from_field_trial
=> \
@field_trial_ids,
389 $message = $ct->save_trial();
393 $schema->txn_do($coderef);
395 print STDERR
"Transaction Error: $_\n";
396 $c->stash->{rest
} = {error
=> "Error saving genotyping plate in the database: $_"};
401 if ($message->{'error'}) {
402 $error = $message->{'error'};
405 $c->stash->{rest
} = {error
=> "Error saving genotyping plate in the database: $error"};
408 #print STDERR Dumper(%message);
410 my $dbh = $c->dbc->dbh();
411 my $bs = CXGN
::BreederSearch
->new( { dbh
=>$dbh, dbname
=>$c->config->{dbname
}, } );
412 my $refresh = $bs->refresh_matviews($c->config->{dbhost
}, $c->config->{dbname
}, $c->config->{dbuser
}, $c->config->{dbpass
}, 'stockprop', 'concurrent', $c->config->{basepath
});
414 my $saved_layout = CXGN
::Trial
::TrialLayout
->new({schema
=> $schema, trial_id
=> $message->{trial_id
}, experiment_type
=>'genotyping_layout'});
415 my $saved_design = $saved_layout->get_design();
416 #print STDERR Dumper $saved_design;
419 foreach (values %$saved_design){
420 push @brapi_samples, {
421 sampleDbId
=> $_->{plot_id
},
422 sampleName
=> $_->{plot_name
},
423 well
=> $_->{plot_number
},
424 row
=> $_->{row_number
},
425 column
=> $_->{col_number
},
426 concentration
=> $_->{concentration
},
427 volume
=> $_->{volume
},
428 tissueType
=> $_->{tissue_type
},
430 sourceName
=> 'NCBI',
431 taxonId
=> $_->{ncbi_taxonomy_id
}
436 my $brapi_plate_data = {
437 vendorProjectDbId
=> $plate_info->{project_name
},
438 clientPlateDbId
=> $message->{trial_id
},
439 clientPlateName
=> $plate_info->{name
},
440 plateFormat
=> $plate_info->{plate_format
},
441 sampleType
=> $plate_info->{sample_type
},
442 samples
=> \
@brapi_samples
445 $c->stash->{rest
} = {
446 message
=> "Successfully stored the genotyping plate.",
447 trial_id
=> $message->{trial_id
},
448 plate_data
=> $brapi_plate_data
452 sub get_genotypingserver_credentials
: Path
('/ajax/breeders/genotyping_credentials') Args
(0) {
456 if ($c->user && ($c->user->check_roles("submitter") || $c->user->check_roles("curator"))) {
457 $c->stash->{rest
} = {
458 host
=> $c->config->{genotyping_server_host
},
459 username
=> $c->config->{genotyping_server_username
},
460 password
=> $c->config->{genotyping_server_password
},
461 token
=> $c->config->{genotyping_server_token
},
465 $c->stash->{rest
} = {
466 error
=> "Insufficient privileges for this operation."
471 sub get_genotyping_data_projects
: Path
('/ajax/genotyping_data/projects') : ActionClass
('REST') { }
473 sub get_genotyping_data_projects_GET
: Args
(0) {
476 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
477 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado', $sp_person_id);
478 my $checkbox_select_name = $c->req->param('select_checkbox_name');
480 my $trial_search = CXGN
::Trial
::Search
->new({
481 bcs_schema
=>$bcs_schema,
482 trial_design_list
=>['genotype_data_project', 'pcr_genotype_data_project']
484 my ($data, $total_count) = $trial_search->search();
488 if ($checkbox_select_name){
489 push @res, "<input type='checkbox' name='$checkbox_select_name' value='$_->{trial_id}'>";
492 "<a href=\"/breeders_toolbox/trial/$_->{trial_id}\">$_->{trial_name}</a>",
494 "<a href=\"/breeders/program/$_->{breeding_program_id}\">$_->{breeding_program_name}</a>",
497 $_->{genotyping_facility
}
501 #print STDERR Dumper \@result;
503 $c->stash->{rest
} = { data
=> \
@result };
506 sub get_genotyping_data_protocols
: Path
('/ajax/genotyping_data/protocols') : ActionClass
('REST') { }
508 sub get_genotyping_data_protocols_GET
: Args
(0) {
511 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
512 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado', $sp_person_id);
513 my $checkbox_select_name = $c->req->param('select_checkbox_name');
514 # my @protocol_list = $c->req->param('protocol_ids') ? split ',', $c->req->param('protocol_ids') : ();
515 # my @accession_list = $c->req->param('accession_ids') ? split ',', $c->req->param('accession_ids') : ();
516 # my @tissue_sample_list = $c->req->param('tissue_sample_ids') ? split ',', $c->req->param('tissue_sample_ids') : ();
517 # my @genotyping_data_project_list = $c->req->param('genotyping_data_project_ids') ? split ',', $c->req->param('genotyping_data_project_ids') : ();
521 my $data = CXGN
::Genotype
::Protocol
::list_simple
($bcs_schema);
525 if ($checkbox_select_name){
526 push @res, "<input type='checkbox' name='$checkbox_select_name' value='$_->{protocol_id}'>";
528 my $num_markers = $_->{marker_count
};
530 foreach (@
{$_->{header_information_lines
}}){
534 my $description = join '<br/>', @trimmed;
536 "<a href=\"/breeders_toolbox/protocol/$_->{protocol_id}\">$_->{protocol_name}</a>",
539 $_->{protocol_description
},
540 $_->{reference_genome_name
},
542 $_->{sample_observation_unit_type_name
},
547 #print STDERR Dumper \@result;
549 $c->stash->{rest
} = { data
=> \
@result };
552 sub create_plate_order
: Path
('/ajax/breeders/createplateorder') ActionClass
('REST') {}
553 sub create_plate_order_POST
: Args
(0) {
557 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
558 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);
559 my $plate_info = decode_json
$c->req->param("order_info");
561 my $plate_id = $plate_info->{plate_id
};
562 my $client_id = $plate_info->{client_id
};
563 my $service_id_list = $plate_info->{service_ids
};
564 my $facility_id = $plate_info->{facility_id
};
565 my $organism_name = $plate_info->{organism_name
};
566 my $add_requirements = $plate_info->{requeriments
};
568 print STDERR Dumper
$plate_info;
570 my $submit_samples = CXGN
::Genotype
::CreatePlateOrder
->new({
572 client_id
=>$client_id,
573 service_id_list
=>$service_id_list,
574 plate_id
=> $plate_id,
575 facility_id
=> $facility_id,
576 requeriments
=> $add_requirements,
577 organism_name
=> $organism_name
579 # my $errors = $submit_samples->validate();
580 my $order = $submit_samples->create();
585 $c->stash->{rest
} = {
586 message
=> "Successfully order created.",
587 trial_id
=> $plate_id,
593 sub store_plate_order
: Path
('/ajax/breeders/storeplateorder') ActionClass
('REST') {}
594 sub store_plate_order_POST
: Args
(0) {
598 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
599 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);
600 my $order_info = decode_json
$c->req->param("order");
602 my $plate_id = $c->req->param("plate_id");
603 my $order_id = $order_info->{orderId
} || undef;
604 my $submission_id = $order_info->{submissionId
} || undef;
605 my $shipment = $order_info->{shipmentForms
};
607 my $genotyping_trial;
609 if ($plate_id && $order_id) {
610 $genotyping_trial = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $plate_id });
611 $genotyping_trial->set_genotyping_vendor_order_id(encode_json
$order_info);
612 $message = "Successfully stored.";
613 } elsif ($plate_id && $submission_id) {
614 $genotyping_trial = CXGN
::Trial
->new( { bcs_schema
=> $schema, trial_id
=> $plate_id });
615 $genotyping_trial->set_genotyping_vendor_submission_id(encode_json
$order_info);
616 $message = "Successfully stored.";
618 my $error = "There was an error trying to store submission order";
619 $c->stash->{rest
} = {
624 $c->stash->{rest
} = {
626 order_id
=> $order_id
632 sub set_project_for_genotyping_plate
: Path
('/ajax/breeders/set_project_for_genotyping_plate') ActionClass
('REST') {}
633 sub set_project_for_genotyping_plate_POST
: Args
(0) {
636 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
637 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);
638 my $genotyping_project_id = $c->req->param("genotyping_project_id");
639 my $genotyping_plate_ids = decode_json
$c->req->param("genotyping_plate_ids");
641 if (!($c->user()->check_roles('curator') || $c->user()->check_roles('submitter'))) {
642 $c->stash->{rest
} = { error
=> 'You do not have the required privileges to move genotyping plates to this project.' };
646 my $genotyping_project_obj = CXGN
::Genotype
::GenotypingProject
->new({
647 bcs_schema
=> $schema,
648 project_id
=> $genotyping_project_id,
649 new_genotyping_plate_list
=> $genotyping_plate_ids
652 my $errors = $genotyping_project_obj->validate_relationship();
653 if (scalar(@
{$errors->{error_messages
}}) > 0){
654 my $error_string = join ', ', @
{$errors->{error_messages
}};
655 $c->stash->{rest
} = { error
=> "Error: $error_string and this project are associated with different genotyping facilities."};
659 $genotyping_project_obj->set_project_for_genotyping_plate();
661 if (!$genotyping_project_obj->set_project_for_genotyping_plate()){
662 $c->stash->{rest
} = {error
=> "Error adding genotyping plate to this project",};
666 $c->stash->{rest
} = { success
=> 1};