seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / StockBarcode.pm
blobf48d1a05dfe23e64fe8fd06c71b2590ccc798a02
2 package SGN::Controller::StockBarcode;
4 use Moose;
5 use File::Slurp;
6 use PDF::Create;
7 use Bio::Chado::Schema::Result::Stock::Stock;
8 use CXGN::Stock::StockBarcode;
9 use Data::Dumper;
10 use CXGN::Stock;
11 use SGN::Model::Cvterm;
13 BEGIN { extends "Catalyst::Controller"; }
15 # use CXGN::ZPL;
16 # Deprecated
17 # sub download_zpl_barcodes : Path('/barcode/stock/download/zpl') :Args(0) {
18 # my $self = shift;
19 # my $c = shift;
21 # my $stock_names = $c->req->param("stock_names");
22 # my $stock_names_file = $c->req->upload("stock_names_file");
24 # my $complete_list = $stock_names ."\n".$stock_names_file;
26 # $complete_list =~ s/\r//g;
28 # my @names = split /\n/, $complete_list;
30 # my @not_found;
31 # my @found;
32 # my @labels;
34 # my $schema = $c->dbic_schema('Bio::Chado::Schema');
36 # foreach my $name (@names) {
38 # # skip empty lines
39 # #
40 # if (!$name) {
41 # next;
42 # }
44 # my $stock = $schema->resultset("Stock::Stock")->find( { name=>$name });
46 # if (!$stock) {
47 # push @not_found, $name;
48 # next;
49 # }
51 # my $stock_id = $stock->stock_id();
53 # push @found, $name;
55 # # generate new zdl label
56 # #
57 # my $label = CXGN::ZPL->new();
58 # $label->start_format();
59 # $label->barcode_code128($c->config->{identifier_prefix}.$stock_id);
60 # $label->end_format();
61 # push @labels, $label;
63 # }
65 # my $dir = $c->tempfiles_subdir('zpl');
66 # my ($FH, $filename) = $c->tempfile(TEMPLATE=>"zpl/zpl-XXXXX", UNLINK=>0);
68 # foreach my $label (@labels) {
69 # print $FH $label->render();
70 # }
71 # close($FH);
73 # $c->stash->{not_found} = \@not_found;
74 # $c->stash->{found} = \@found;
75 # $c->stash->{file} = $filename;
76 # $c->stash->{filetype} = "ZPL";
77 # $c->stash->{template} = '/barcode/stock_download_result.mas';
79 # }
82 sub download_pdf_labels :Path('/barcode/stock/download/pdf') :Args(0) {
83 my ($self, $c) = @_;
85 my $stock_names = $c->req->param("stock_names");
86 my $stock_names_file = $c->req->upload("stock_names_file");
87 my $labels_per_page = $c->req->param("label_rows") || 10;
88 my $labels_per_row = $c->req->param("label_cols") || 1;
89 my $page_format = $c->req->param("page_format") || "letter";
90 my $top_margin_mm = $c->req->param("tops_margin");
91 my $left_margin_mm = $c->req->param("left_margin");
92 my $bottom_margin_mm = $c->req->param("bottom_margin");
93 my $right_margin_mm = $c->req->param("right_margin");
94 my $nursery = $c->req->param("nursery");
95 my $added_text = $c->req->param("text_margin");
96 my $barcode_type = $c->req->param("select_barcode_type");
97 my $fieldbook_barcode = $c->req->param("enable_fieldbook_2d_barcode");
98 my $cass_print_format = $c->req->param("select_print_format");
99 my $label_text_4;
100 my $type_id;
101 my $schema = $c->dbic_schema('Bio::Chado::Schema');
102 my $plot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plot', 'stock_type' )->cvterm_id();
103 my $plot_number_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plot number', 'stock_property' )->cvterm_id();
104 my $accession_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'accession', 'stock_type' )->cvterm_id();
105 my $plant_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plant', 'stock_type' )->cvterm_id();
106 my $xlabel_margin = 8;
107 # convert mm into pixels
108 print "MY TOP MARGIN: $top_margin_mm\n";
109 if ($cass_print_format eq 'NCSU') {$left_margin_mm = 10, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 10, $labels_per_row = 3, $barcode_type = "2D", $page_format = "letter"; }
110 if ($cass_print_format eq 'CASS') {$left_margin_mm = 112, $top_margin_mm = 10, $bottom_margin_mm = 13, $right_margin_mm = 10, $barcode_type = "2D", $labels_per_row = 2; }
111 if ($cass_print_format eq 'IITA-3') {$left_margin_mm = 130, $top_margin_mm = 13, $bottom_margin_mm = 11, $right_margin_mm = 10, $labels_per_row = 3, $barcode_type = "2D"; }
112 if ($cass_print_format eq 'IITA-2') {$left_margin_mm = 130, $top_margin_mm = 13, $bottom_margin_mm = 11, $right_margin_mm = 10, $labels_per_row = 2, $barcode_type = "2D"; }
113 if ($cass_print_format eq 'MUSA') {$left_margin_mm = 112, $top_margin_mm = 10, $bottom_margin_mm = 13, $barcode_type = "2D", $labels_per_row = 2; }
114 if ($cass_print_format eq '32A4') {$left_margin_mm = 17, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 8, $labels_per_row = 4, $barcode_type = "2D", $page_format = "letter"; }
115 if ($cass_print_format eq '32_unique') {$left_margin_mm = 17, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 8, $labels_per_row = 4, $barcode_type = "2D", $page_format = "letter"; }
116 if ($cass_print_format eq '20A4') {$left_margin_mm = 10, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 10, $labels_per_row = 2, $barcode_type = "2D", $page_format = "letter"; }
117 if ($cass_print_format eq 'crossing') {$left_margin_mm = 2, $top_margin_mm = 5, $bottom_margin_mm = 0, $right_margin_mm = 0, $labels_per_row = 1, $labels_per_page = 1, $barcode_type = "2D"; }
118 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } (
119 $top_margin_mm,
120 $left_margin_mm,
121 $bottom_margin_mm,
122 $right_margin_mm
125 # read file if upload
127 if ($stock_names_file) {
128 my $stock_file_contents = read_file($stock_names_file->{tempname});
129 $stock_names = $stock_names ."\n".$stock_file_contents;
132 $stock_names =~ s/\r//g;
133 my @names = split /\n/, $stock_names;
135 my @not_found;
136 my @found;
138 my ($row, $stockprop_name, $value, $fdata_block, $fdata_rep, $fdata_plot, $fdata, $accession_id, $accession_name, $parents, $tract_type_id, $label_text_5, $plot_name, $label_text_6, $musa_row_col_number, $label_text_7, $row_col_number, $label_text_8, $fdata_plot_20A4, $fdata_rep_block);
140 ## sort plot list
141 my @stocks_sorted;
142 my $stock_rs = $schema->resultset("Stock::Stock")->search(
144 uniquename => {'-in' => \@names},
145 'stockprops.type_id' => $plot_number_cvterm_id
148 join => {'stockprops'},
149 '+select' => ['stockprops.value'],
150 '+as' => ['plot_number'],
151 'order_by' => { '-asc' => 'stockprops.value::INT' }
154 while ( my $r = $stock_rs->next()){
155 my $stock_name = $r->uniquename;
156 my $stock_id = $r->stock_id;
157 my $stock_type_id = $r->type_id;
158 my $plot_number = $r->get_column('plot_number');
159 push @stocks_sorted, $stock_name
162 if (scalar(@stocks_sorted) > 0){
163 @names = @stocks_sorted;
166 foreach my $name (@names) {
168 # skip empty lines
170 if (!$name) {
171 next;
174 my $stock = $schema->resultset("Stock::Stock")->find( { uniquename=>$name });
176 if (!$stock) {
177 push @not_found, $name;
178 next;
181 my $stock_id = $stock->stock_id();
182 $type_id = $stock->type_id();
184 if ($plant_cvterm_id == $type_id){
185 my $dbh = $c->dbc->dbh();
186 my $h = $dbh->prepare("select stock_relationship.subject_id, stock.name from stock join stock_relationship on stock.stock_id=stock_relationship.subject_id where object_id=?;");
188 $h->execute($stock_id);
189 while (my($plot_of_plant_id, $plant_plot_name) = $h->fetchrow_array) {
190 $plot_name = $plant_plot_name;
192 my $dbh = $c->dbc->dbh();
193 my $h = $dbh->prepare("select name, value from cvterm inner join stockprop on cvterm.cvterm_id = stockprop.type_id where stockprop.stock_id=?;");
195 $h->execute($plot_of_plant_id);
197 my %stockprop_hash;
198 while (($stockprop_name, $value) = $h->fetchrow_array) {
199 $stockprop_hash{$stock_id}->{$stockprop_name} = $value;
202 $row = $stockprop_hash{$stock_id}->{'replicate'};
203 $fdata = "rep:".$stockprop_hash{$stock_id}->{'replicate'}.' '."blk:".$stockprop_hash{$stock_id}->{'block'}.' '."plot:".$stockprop_hash{$stock_id}->{'plot number'};
204 $fdata_block = "blk:".$stockprop_hash{$stock_id}->{'block'};
205 $fdata_rep = "rep:".$stockprop_hash{$stock_id}->{'replicate'};
206 $fdata_rep_block = "block number:".$stockprop_hash{$stock_id}->{'block'}.', '."rep number:".$stockprop_hash{$stock_id}->{'replicate'};
207 $fdata_plot = "plot:".$stockprop_hash{$stock_id}->{'plot number'};
208 $fdata_plot_20A4 = "plot number:".$stockprop_hash{$stock_id}->{'plot number'};
209 $musa_row_col_number = "row number:".$stockprop_hash{$stock_id}->{'row_number'}.', '."column number:".$stockprop_hash{$stock_id}->{'col_number'};
211 my $h_acc = $dbh->prepare("select stock.uniquename, stock.stock_id FROM stock join stock_relationship on (stock.stock_id = stock_relationship.object_id) where stock_relationship.subject_id =?;");
213 $h_acc->execute($stock_id);
214 ($accession_name, $accession_id) = $h_acc->fetchrow_array;
218 if ($plot_cvterm_id == $type_id){
219 my $dbh = $c->dbc->dbh();
220 my $h = $dbh->prepare("select name, value from cvterm inner join stockprop on cvterm.cvterm_id = stockprop.type_id where stockprop.stock_id=?;");
222 $h->execute($stock_id);
224 my %stockprop_hash;
225 while (($stockprop_name, $value) = $h->fetchrow_array) {
226 $stockprop_hash{$stock_id}->{$stockprop_name} = $value;
229 $row = $stockprop_hash{$stock_id}->{'replicate'};
230 $fdata = "rep:".$stockprop_hash{$stock_id}->{'replicate'}.' '."blk:".$stockprop_hash{$stock_id}->{'block'}.' '."plot:".$stockprop_hash{$stock_id}->{'plot number'};
231 $fdata_block = "blk:".$stockprop_hash{$stock_id}->{'block'};
232 $fdata_rep = "rep:".$stockprop_hash{$stock_id}->{'replicate'};
233 $fdata_plot = "plot:".$stockprop_hash{$stock_id}->{'plot number'};
234 $fdata_rep_block = "block number:".$stockprop_hash{$stock_id}->{'block'}.', '."rep number:".$stockprop_hash{$stock_id}->{'replicate'};
235 $fdata_plot_20A4 = "plot number:".$stockprop_hash{$stock_id}->{'plot number'};
236 $musa_row_col_number = "row number:".$stockprop_hash{$stock_id}->{'row_number'}.', '."column number:".$stockprop_hash{$stock_id}->{'col_number'};
237 $row_col_number = "rw/cl:".$stockprop_hash{$stock_id}->{'row_number'}."/".$stockprop_hash{$stock_id}->{'col_number'};
238 my $h_acc = $dbh->prepare("select stock.uniquename, stock.stock_id FROM stock join stock_relationship on (stock.stock_id = stock_relationship.object_id) where stock_relationship.subject_id =? and stock.type_id=?;");
240 $h_acc->execute($stock_id,$accession_cvterm_id);
241 ($accession_name, $accession_id) = $h_acc->fetchrow_array;
242 print STDERR "Accession name for this plot is $accession_name and id is $accession_id\n";
244 my $synonym_string;
245 if ($plot_cvterm_id == $type_id) {
246 $tract_type_id = 'plot';
247 $parents = CXGN::Stock->new ( schema => $schema, stock_id => $accession_id )->get_pedigree_string('Parents');
249 elsif ($accession_cvterm_id == $type_id){
250 $tract_type_id = 'accession';
251 $parents = CXGN::Stock->new ( schema => $schema, stock_id => $stock_id )->get_pedigree_string('Parents');
252 my $stock_synonyms = CXGN::Stock::Accession->new({ schema => $schema, stock_id => $stock_id })->synonyms();
253 $synonym_string = join ',', @$stock_synonyms;
255 elsif ($plant_cvterm_id == $type_id) {
256 $tract_type_id = 'plant';
257 $parents = CXGN::Stock->new ( schema => $schema, stock_id => $accession_id )->get_pedigree_string('Parents');
260 if ($cass_print_format eq 'crossing'){
261 push @found, [ $stock_id, $name, $accession_name, $fdata, $parents, $tract_type_id, $plot_name, $synonym_string, $musa_row_col_number, $fdata_block, $fdata_rep, $fdata_plot, $row_col_number, $fdata_plot_20A4, $fdata_rep_block];
262 }else{
263 push @found, [ $c->config->{identifier_prefix}.$stock_id, $name, $accession_name, $fdata, $parents, $tract_type_id, $plot_name, $synonym_string, $musa_row_col_number, $fdata_block, $fdata_rep, $fdata_plot, $row_col_number, $fdata_plot_20A4, $fdata_rep_block];
267 my $dir = $c->tempfiles_subdir('pdfs');
268 my ($FH, $filename) = $c->tempfile(TEMPLATE=>"pdfs/pdf-XXXXX", SUFFIX=>".pdf", UNLINK=>0);
269 print STDERR "FILENAME: $filename \n\n\n";
270 my $pdf = PDF::Create->new(filename=>$c->path_to($filename),
271 Author=>$c->config->{project_name},
272 Title=>'Labels',
273 CreationDate => [ localtime ],
274 Version=>1.2,
277 if (!$page_format) { $page_format = "Letter"; }
278 if (!$labels_per_page) { $labels_per_page = 8; }
280 my $base_page = $pdf->new_page(MediaBox=>$pdf->get_page_size($page_format));
282 my ($page_width, $page_height) = @{$pdf->get_page_size($page_format)}[2,3];
284 ## for 10 labels per page
285 my $label_height;
286 if ($cass_print_format eq '32A4'){
287 $label_height = 40;
288 print "LABEL HEIGHT: $label_height\n";
290 elsif ($cass_print_format eq '32_unique'){
291 $label_height = 40;
292 $labels_per_page = 32;
294 else {
295 if ($labels_per_page == '10'){
296 $label_height = int( (($page_height - $top_margin - $bottom_margin) / $labels_per_page) + 0.5 );
298 ## for 20 labels per page
299 elsif ($labels_per_page == '20'){
300 $label_height = int( (($page_height - $top_margin - $bottom_margin) / $labels_per_page) - 0.05 );
302 else {
303 ## for 20 labels per page
304 $label_height = int( ($page_height - $top_margin - $bottom_margin) / $labels_per_page);
308 my @pages;
309 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
310 print STDERR "Generating page $page...\n";
311 push @pages, $base_page->new_page();
314 print STDERR $cass_print_format."\n";
315 my $row_y_label_count = 1;
316 my $labels_on_page = 0;
317 my $row_count = 0;
318 my $ypos;
319 for (my $i=0; $i<@found; $i++) {
320 my $label_count = $i + 1;
321 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
322 my $label_on_page = ($label_count -1) % $labels_per_page;
324 # generate barcode
326 #####
327 my $tempfile;
328 my $plot_text = "accession: ".$found[$i]->[2]." ".$found[$i]->[3];
329 if ($barcode_type eq "1D"){
330 if ($found[$i]->[5] eq 'plot'){
331 #$tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[0], $found[$i]->[2]." ".$found[$i]->[3], 'large', 20 ]);
332 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $plot_text, 'large', 20 ]);
334 elsif ($found[$i]->[5] eq 'accession'){
335 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $found[$i]->[4], 'large', 20 ]);
337 elsif ($found[$i]->[5] eq 'plant'){
338 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $plot_text, 'large', 20 ]);
340 else {
341 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[0], $found[$i]->[1], 'large', 20 ]);
344 elsif ($barcode_type eq "2D") {
346 if ($found[$i]->[5] eq 'plot'){
347 $parents = $found[$i]->[4];
348 if ($cass_print_format eq 'crossing'){
349 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], " Accession Name: ".$found[$i]->[2]."\n".$found[$i]->[3]."\n".$found[$i]->[4]."\n".$found[$i]->[8]."\n".$added_text, $fieldbook_barcode, $cass_print_format ]);
351 else{
352 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]."\n".$found[$i]->[3]."\n".$found[$i]->[4]."\n".$found[$i]->[8]."\n".$added_text, $fieldbook_barcode ]);
355 elsif ($found[$i]->[5] eq 'accession'){
356 if ($found[$i]->[7] eq ''){
357 $found[$i]->[7] = "No synonym(s) available";
358 }else{
359 $found[$i]->[7] = "synonym(s): ".$found[$i]->[7];
361 $parents = $found[$i]->[4];
362 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[4]."\n".$added_text."\n".$found[$i]->[7], $fieldbook_barcode]);
364 elsif ($found[$i]->[5] eq 'plant'){
365 $parents = $found[$i]->[4];
366 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]."\nplot:".$found[$i]->[6]."\n".$found[$i]->[3]."\n".$found[$i]->[4]."\n".$found[$i]->[8]."\n".$added_text, $fieldbook_barcode ]);
368 else {
369 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $added_text, $fieldbook_barcode ]);
374 print STDERR "$tempfile\n";
375 my $image = $pdf->image($tempfile);
376 #print STDERR "IMAGE: ".Data::Dumper::Dumper($image);
378 # note: pdf coord system zero is lower left corner
380 print "PAGE WIDTH: $page_width\n";
381 my $final_barcode_width = ($page_width - $right_margin - $left_margin) / $labels_per_row;
382 my $scalex = $final_barcode_width / $image->{width};
383 my $scaley = $label_height / $image->{height};
385 if ($scalex < $scaley) { $scaley = $scalex; }
386 else { $scalex = $scaley; }
388 my ($year_text, $location_text, $label_boundary);
389 if ($cass_print_format eq 'NCSU'){
390 ($year_text,$location_text) = split ',', $added_text;
391 my $xlabel_margin = 18;
392 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
393 $ypos = $label_boundary - int( ($label_height - $image->{height} * $scaley) /2);
394 $final_barcode_width = ($page_width - $right_margin - $left_margin + (2 * $xlabel_margin)) / $labels_per_row;
396 elsif ($cass_print_format eq '32A4'){
397 my $label_height_8_per_page = 90;
398 $label_boundary = $page_height - ($label_on_page * $label_height_8_per_page) - $top_margin;
399 $ypos = $label_boundary - int( ($label_height_8_per_page - $image->{height} * $scaley) /2);
400 $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
402 elsif ($cass_print_format eq '32_unique'){
403 my $label_height_8_per_page = 90;
404 if ($labels_on_page == 32){
405 $row_count = 0;
406 $labels_on_page = 0;
408 if ($row_y_label_count == 1 || $row_y_label_count > $labels_per_row){
409 $label_boundary = $page_height - ($row_count * $label_height_8_per_page) - $top_margin;
410 $ypos = $label_boundary - int( ($label_height_8_per_page - $image->{height} * $scaley) /2);
411 $row_count++;
413 if ($row_y_label_count > $labels_per_row){
414 $row_y_label_count = 1;
416 print STDERR $row_y_label_count." ".$row_count." ".$ypos." ".$labels_on_page."\n";
417 $row_y_label_count++;
418 $labels_on_page++;
419 $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
421 elsif ($cass_print_format eq '20A4'){
422 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
423 $ypos = $label_boundary - int( ($label_height - $image->{height} * $scaley) /2);
424 $final_barcode_width = ($page_width - $right_margin - $left_margin + (4 * $xlabel_margin)) / $labels_per_row;
426 elsif ($cass_print_format eq 'IITA-3'){
427 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
428 $ypos = $label_boundary - int( ($label_height - $image->{height} * $scaley) /2);
429 $final_barcode_width = ($page_width - $right_margin - $left_margin) / ($labels_per_row + 1);
431 elsif ($cass_print_format eq 'IITA-2'){
432 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
433 $ypos = $label_boundary - int( ($label_height - $image->{height} * $scaley) /2);
434 $final_barcode_width = ($page_width - $right_margin - $left_margin) / ($labels_per_row + 1.5);
436 else{
437 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
438 $ypos = $label_boundary - int( ($label_height - $image->{height} * $scaley) /2);
441 if ($cass_print_format eq '32A4' || $cass_print_format eq '32_unique' || $cass_print_format eq 'NCSU' || $cass_print_format eq '20A4' || $cass_print_format eq 'crossing'){
443 else{
444 $pages[$page_nr-1]->line($page_width -100, $label_boundary, $page_width, $label_boundary);
448 # my $lebel_number = scalar($#{$found[$i]});
449 my $font = $pdf->font('BaseFont' => 'Courier-Bold');
450 if ($barcode_type eq "2D" && !$cass_print_format) {
451 foreach my $label_count (1..$labels_per_row) {
452 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width + 20;
453 my $yposition = $ypos -7;
454 my $label_text = $found[$i]->[1];
455 my $label_size = 7;
456 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
458 if ($labels_per_row == '1' ){
459 my $label_count_15_xter_plot_name = 1-1;
460 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 80.63;
461 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
462 if ($labels_per_page > 15){
463 $yposition_2 = $ypos - 10;
464 $yposition_3 = $ypos - 20;
465 $yposition_4 = $ypos - 30;
466 $yposition_5 = $ypos - 40;
467 }else{
468 $yposition_2 = $ypos - 20;
469 $yposition_3 = $ypos - 30;
470 $yposition_4 = $ypos - 40;
471 $yposition_5 = $ypos - 50;
473 my $plot_pedigree_text;
475 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
476 if ($found[$i]->[5] eq 'plot'){
477 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
478 if ($parents eq ''){
479 $label_text_4 = "No pedigree for ".$found[$i]->[2];
480 }else{
481 $label_text_4 = "pedigree: ".$parents;
484 elsif ($found[$i]->[5] eq 'accession'){
485 if ($parents eq ''){
486 $label_text_4 = "No pedigree for ".$found[$i]->[1];
487 }else{
488 $label_text_4 = "pedigree: ".$parents;
490 $label_text_5 = $found[$i]->[7];
492 elsif ($found[$i]->[5] eq 'plant'){
493 $label_text_6 = "plot:".$found[$i]->[6];
494 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
495 if ($parents eq ''){
496 $label_text_4 = "No pedigree for ".$found[$i]->[2];
497 }else{
498 $label_text_4 = "pedigree: ".$parents;
501 else{
502 $label_text_4 = '';
505 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
506 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
507 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
509 elsif ($labels_per_row > '1'){
510 if (length($label_text) <= 15){
511 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
516 if ($labels_per_row > '1'){
517 my $label_text = $found[$i]->[1];
518 if (length($label_text) > 15) {
519 my $label_count_15_xter_plot_name = 1-1;
520 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 20;
521 my $yposition = $ypos -7;
522 my $label_size = 7;
523 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
528 elsif ($cass_print_format eq 'CASS' && $barcode_type eq "2D") {
530 foreach my $label_count (1..$labels_per_row) {
531 my $label_text = $found[$i]->[1];
532 my $label_size = 7;
533 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 85;
534 my $label_count_15_xter_plot_name = 1-1;
535 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
536 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
537 if ($labels_per_page > 15){
538 $yposition_2 = $ypos - 10;
539 $yposition_3 = $ypos - 20;
540 $yposition_4 = $ypos - 30;
541 $yposition_5 = $ypos - 40;
542 }else{
543 $yposition_2 = $ypos - 20;
544 $yposition_3 = $ypos - 30;
545 $yposition_4 = $ypos - 40;
546 $yposition_5 = $ypos - 50;
548 my $plot_pedigree_text;
550 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
551 if ($found[$i]->[5] eq 'plot'){
552 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
553 if ($parents eq ''){
554 $label_text_4 = "No pedigree for ".$found[$i]->[2];
555 }else{
556 $label_text_4 = "pedigree: ".$parents;
559 elsif ($found[$i]->[5] eq 'accession'){
560 if ($parents eq ''){
561 $label_text_4 = "No pedigree for ".$found[$i]->[1];
562 }else{
563 $label_text_4 = "pedigree: ".$parents;
565 $label_text_5 = $found[$i]->[7];
567 elsif ($found[$i]->[5] eq 'plant'){
568 $label_text_6 = "plot:".$found[$i]->[6];
569 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
570 if ($parents eq ''){
571 $label_text_4 = "No pedigree for ".$found[$i]->[2];
572 }else{
573 $label_text_4 = "pedigree: ".$parents;
576 else{
577 $label_text_4 = '';
579 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
580 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
581 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
582 $pages[$page_nr-1]->image(image=>$image, xpos=>$xpos, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
586 elsif ($cass_print_format eq 'IITA-3' && $barcode_type eq "2D") {
588 foreach my $label_count (1..$labels_per_row) {
589 my $label_text = $found[$i]->[1];
590 my $label_size = 7;
591 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 80;
592 my $label_count_15_xter_plot_name = 1-1;
593 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
594 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
595 if ($labels_per_page > 15){
596 $yposition_2 = $ypos - 10;
597 $yposition_3 = $ypos - 20;
598 $yposition_4 = $ypos - 30;
599 $yposition_5 = $ypos - 40;
600 }else{
601 $yposition_2 = $ypos - 20;
602 $yposition_3 = $ypos - 30;
603 $yposition_4 = $ypos - 40;
604 $yposition_5 = $ypos - 50;
606 my $plot_pedigree_text;
608 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
609 if ($found[$i]->[5] eq 'plot'){
610 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
611 if ($parents eq ''){
612 $label_text_4 = "No pedigree for ".$found[$i]->[2];
613 }else{
614 $label_text_4 = $parents;
617 elsif ($found[$i]->[5] eq 'accession'){
618 if ($parents eq ''){
619 $label_text_4 = "No pedigree for ".$found[$i]->[1];
620 }else{
621 $label_text_4 = $parents;
623 $label_text_5 = $found[$i]->[7];
625 elsif ($found[$i]->[5] eq 'plant'){
626 $label_text_6 = "plot:".$found[$i]->[6];
627 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
628 if ($parents eq ''){
629 $label_text_4 = "No pedigree for ".$found[$i]->[2];
630 }else{
631 $label_text_4 = $parents;
634 else{
635 $label_text_4 = '';
637 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
638 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
639 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
640 $pages[$page_nr-1]->image(image=>$image, xpos=>$xpos, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
644 elsif ($cass_print_format eq 'IITA-2' && $barcode_type eq "2D") {
646 foreach my $label_count (1..$labels_per_row) {
647 my $label_text = $found[$i]->[1];
648 my $label_size = 7;
649 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 80;
650 my $label_count_15_xter_plot_name = 1-1;
651 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
652 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
653 if ($labels_per_page > 15){
654 $yposition_2 = $ypos - 10;
655 $yposition_3 = $ypos - 20;
656 $yposition_4 = $ypos - 30;
657 $yposition_5 = $ypos - 40;
658 }else{
659 $yposition_2 = $ypos - 20;
660 $yposition_3 = $ypos - 30;
661 $yposition_4 = $ypos - 40;
662 $yposition_5 = $ypos - 50;
664 my $plot_pedigree_text;
666 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
667 if ($found[$i]->[5] eq 'plot'){
668 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
669 if ($parents eq ''){
670 $label_text_4 = "No pedigree for ".$found[$i]->[2];
671 }else{
672 $label_text_4 = $parents;
675 elsif ($found[$i]->[5] eq 'accession'){
676 if ($parents eq ''){
677 $label_text_4 = "No pedigree for ".$found[$i]->[1];
678 }else{
679 $label_text_4 = $parents;
681 $label_text_5 = $found[$i]->[7];
683 elsif ($found[$i]->[5] eq 'plant'){
684 $label_text_6 = "plot:".$found[$i]->[6];
685 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
686 if ($parents eq ''){
687 $label_text_4 = "No pedigree for ".$found[$i]->[2];
688 }else{
689 $label_text_4 = $parents;
692 else{
693 $label_text_4 = '';
695 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
696 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
697 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
698 $pages[$page_nr-1]->image(image=>$image, xpos=>$xpos + 60, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
702 elsif ($cass_print_format eq 'NCSU' && $barcode_type eq "2D") {
703 foreach my $label_count (1..$labels_per_row) {
704 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
705 my $yposition = $ypos -7;
706 my $label_text = $found[$i]->[1];
707 my $label_size = 7;
708 my $label_size_stock = 12;
709 my $yposition_8 = $ypos + 2;
710 my $yposition_2 = $ypos - 10;
711 my $yposition_3 = $ypos - 20;
712 my $yposition_4 = $ypos - 30;
713 my $yposition_5 = $ypos - 40;
714 my $yposition_6 = $ypos - 50;
715 my $yposition_7 = $ypos - 60;
716 if ($found[$i]->[5] eq 'accession'){
717 $label_text_6 = $found[$i]->[1];
718 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $parents);
719 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $year_text);
720 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $location_text);
721 }else{
722 $label_text_6 = $found[$i]->[2];
723 $label_text_5 = $found[$i]->[11];
724 $label_text_4 = $found[$i]->[10];
725 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $year_text);
726 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
727 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_5);
728 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $location_text);
729 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
731 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_2, $label_text_6);
732 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 90 + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
736 elsif ($cass_print_format eq '32A4' && $barcode_type eq "2D") {
737 foreach my $label_count (1..$labels_per_row) {
738 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
739 my $yposition = $ypos -7;
740 my $label_text = $found[$i]->[1];
741 if ($found[$i]->[5] eq 'plot'){
742 $label_text = $found[$i]->[2];
744 my $label_size = 7;
745 my $label_size_stock = 10;
746 my $yposition_8 = $ypos + 2;
747 my $yposition_2 = $ypos - 10;
748 my $yposition_3 = $ypos - 20;
749 my $yposition_4 = $ypos - 30;
750 my $yposition_5 = $ypos - 40;
751 my $yposition_6 = $ypos - 50;
752 my $yposition_7 = $ypos - 60;
753 $label_text_6 = $found[$i]->[2];
754 $label_text_5 = $found[$i]->[11];
755 $label_text_4 = $found[$i]->[12];
756 $label_text_8 = $found[$i]->[10];
757 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_8, $label_text);
758 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_8);
759 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
760 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_5);
761 if ($found[$i]->[5] eq 'accession'){
762 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
763 }else{
764 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
765 #$pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
766 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
769 if ($found[$i]->[5] eq 'accession'){
770 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 20 + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
771 }else{
772 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 50 + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
778 elsif ($cass_print_format eq '32_unique' && $barcode_type eq "2D") {
779 my $xposition = $left_margin + ($row_y_label_count -2) * $final_barcode_width;
780 my $yposition = $ypos -7;
781 my $label_text = $found[$i]->[1];
782 if ($found[$i]->[5] eq 'plot'){
783 $label_text = $found[$i]->[2];
785 my $label_size = 7;
786 my $label_size_stock = 10;
787 my $yposition_8 = $ypos + 2;
788 my $yposition_2 = $ypos - 10;
789 my $yposition_3 = $ypos - 20;
790 my $yposition_4 = $ypos - 30;
791 my $yposition_5 = $ypos - 40;
792 my $yposition_6 = $ypos - 50;
793 my $yposition_7 = $ypos - 60;
794 $label_text_6 = $found[$i]->[2];
795 $label_text_5 = $found[$i]->[11];
796 $label_text_4 = $found[$i]->[12];
797 $label_text_8 = $found[$i]->[10];
798 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_8, $label_text);
799 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_8);
800 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
801 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_5);
802 if ($found[$i]->[5] eq 'accession'){
803 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
804 }else{
805 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
806 #$pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
807 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
810 if ($found[$i]->[5] eq 'accession'){
811 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 20 + ($row_y_label_count -2) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
812 }else{
813 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 50 + ($row_y_label_count -2) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
817 elsif ($cass_print_format eq '20A4' && $barcode_type eq "2D") {
818 foreach my $label_count (1..$labels_per_row) {
819 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
820 my $yposition = $ypos -7;
821 my $label_text = $found[$i]->[1];
822 my $label_size = 8;
823 my $label_size_stock = 10;
824 my $yposition_2 = $ypos - 10;
825 my $yposition_3 = $ypos - 20;
826 my $yposition_4 = $ypos - 30;
827 my $yposition_5 = $ypos - 40;
828 my $yposition_6 = $ypos - 50;
829 my $yposition_7 = $ypos - 60;
830 my $yposition_8 = $ypos - 70;
831 if ($found[$i]->[5] eq 'accession'){}
832 else{
833 $label_text_6 = "accession: ".$found[$i]->[2];
835 my $parents_20A4 = "pedigree: ".$parents;
836 $label_text_5 = $found[$i]->[14];
837 $label_text_4 = $found[$i]->[8];
838 $label_text_8 = $found[$i]->[13];
839 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
840 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_6);
841 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_5);
842 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
843 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $label_text_8);
844 if ($found[$i]->[5] eq 'accession'){
845 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $parents_20A4);
846 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $added_text);
847 }else{
848 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents_20A4);
849 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_8, $added_text);
851 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 200 + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
855 elsif ($cass_print_format eq 'crossing' && $barcode_type eq "2D") {
856 foreach my $label_count (1..$labels_per_row) {
857 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width + 20;
858 my $yposition = $ypos -7;
859 my $label_text = $found[$i]->[1];
860 my $label_size = 60;
861 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
862 $pages[$page_nr-1]->string($font, $label_size, $xposition + 30, $yposition - 595, $label_text);
867 elsif ($cass_print_format eq 'MUSA' && $barcode_type eq "2D") {
869 foreach my $label_count (1..$labels_per_row) {
870 my $label_text = $found[$i]->[1];
871 my $label_size = 7;
872 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 85;
873 my $label_count_15_xter_plot_name = 1-1;
874 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
875 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5, $yposition_6);
876 if ($labels_per_page > 15){
877 $yposition_2 = $ypos - 10;
878 $yposition_3 = $ypos - 20;
879 $yposition_4 = $ypos - 30;
880 $yposition_5 = $ypos - 40;
881 $yposition_6 = $ypos - 50;
882 }else{
883 $yposition_2 = $ypos - 20;
884 $yposition_3 = $ypos - 30;
885 $yposition_4 = $ypos - 40;
886 $yposition_5 = $ypos - 50;
887 $yposition_6 = $ypos - 60;
889 my $plot_pedigree_text;
891 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
892 if ($found[$i]->[5] eq 'plot'){
893 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
894 $label_text_6 = $found[$i]->[8];
895 if ($parents eq ''){
896 $label_text_4 = "No pedigree for ".$found[$i]->[2];
897 }else{
898 $label_text_4 = "pedigree: ".$parents;
901 elsif ($found[$i]->[5] eq 'accession'){
902 if ($parents eq ''){
903 $label_text_4 = "No pedigree for ".$found[$i]->[1];
904 }else{
905 $label_text_4 = "pedigree: ".$parents;
907 $label_text_5 = $found[$i]->[7];
909 elsif ($found[$i]->[5] eq 'plant'){
910 print "I HAVE ROW AND COL: $found[$i]->[8]\n";
911 $label_text_6 = "plot:".$found[$i]->[6];
912 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
913 $label_text_7 = $found[$i]->[8];
914 if ($parents eq ''){
915 $label_text_4 = "No pedigree for ".$found[$i]->[2];
916 }else{
917 $label_text_4 = "pedigree: ".$parents;
920 else{
921 $label_text_4 = '';
923 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
924 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
925 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
926 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $label_text_7);
927 $pages[$page_nr-1]->image(image=>$image, xpos=>$xpos, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
931 elsif ($barcode_type eq "1D") {
933 foreach my $label_count (1..$labels_per_row) {
935 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
940 $pdf->close();
942 $c->stash->{not_found} = \@not_found;
943 $c->stash->{found} = \@found;
944 $c->stash->{file} = $filename;
945 $c->stash->{filetype} = 'PDF';
946 $c->stash->{template} = '/barcode/stock_download_result.mas';
949 # plot phenotyping barcode
950 sub download_qrcode : Path('/barcode/stock/download/plot_QRcode') : Args(0) {
951 my $self = shift;
952 my $c = shift;
954 my $stock_names = $c->req->param("stock_names_2");
955 my $stock_names_file = $c->req->upload("stock_names_file_2");
956 my $added_text = $c->req->param("select_barcode_text");
957 my $labels_per_page = 7;
958 my $page_format = "letter";
959 my $labels_per_row = 1;
960 my $top_margin_mm = 12;
961 my $left_margin_mm = 70;
962 my $bottom_margin_mm = 12;
963 my $right_margin_mm = 20;
964 my $schema = $c->dbic_schema('Bio::Chado::Schema');
965 my $accession_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'accession', 'stock_type' )->cvterm_id();
966 my $plot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plot', 'stock_type' )->cvterm_id();
967 # convert mm into pixels
969 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } ($top_margin_mm,
970 $left_margin_mm,
971 $bottom_margin_mm,
972 $right_margin_mm);
974 # read file if upload
976 if ($stock_names_file) {
977 my $stock_file_contents = read_file($stock_names_file->{tempname});
978 $stock_names = $stock_names ."\n".$stock_file_contents;
981 $stock_names =~ s/\r//g;
982 my @names = split /\n/, $stock_names;
984 my @not_found;
985 my @found;
987 my ($row, $stockprop_name, $value, $fdata, $accession_id, $accession_name, $parents);
989 foreach my $name (@names) {
991 # skip empty lines
993 if (!$name) {
994 next;
997 my $stock = $schema->resultset("Stock::Stock")->find( { name=>$name });
999 if (!$stock) {
1000 push @not_found, $name;
1001 next;
1004 my $stock_id = $stock->stock_id();
1005 my $type_id = $stock->type_id();
1006 if ($type_id == $accession_cvterm_id) {
1007 print "You are using accessions\n";
1008 my $error = "used only for downloading Plot barcodes.";
1009 $c->stash->{error} = $error;
1010 $c->stash->{template} = '/barcode/stock_download_result.mas';
1011 $c->detach;
1014 my $dbh = $c->dbc->dbh();
1015 my $h = $dbh->prepare("select name, value from cvterm inner join stockprop on cvterm.cvterm_id = stockprop.type_id where stockprop.stock_id=?;");
1016 $h->execute($stock_id);
1017 my %stockprop_hash;
1018 while (($stockprop_name, $value) = $h->fetchrow_array) {
1019 $stockprop_hash{$stock_id}->{$stockprop_name} = $value;
1021 $row = $stockprop_hash{$stock_id}->{'replicate'};
1022 $fdata = "rep:".$stockprop_hash{$stock_id}->{'replicate'}.' '."block:".$stockprop_hash{$stock_id}->{'block'}.' '."plot:".$stockprop_hash{$stock_id}->{'plot number'};
1024 my $h_acc = $dbh->prepare("select stock.uniquename, stock.stock_id FROM stock join stock_relationship on (stock.stock_id = stock_relationship.object_id) where stock.type_id=? and stock_relationship.subject_id =?;");
1026 $h_acc->execute($accession_cvterm_id,$stock_id);
1027 ($accession_name, $accession_id) = $h_acc->fetchrow_array;
1029 $parents = CXGN::Stock->new ( schema => $schema, stock_id => $accession_id )->get_pedigree_string('Parents');
1031 push @found, [ $stock_id, $name, $accession_name, $fdata, $parents];
1034 my $dir = $c->tempfiles_subdir('pdfs');
1035 my ($FH, $filename) = $c->tempfile(TEMPLATE=>"pdfs/pdf-XXXXX", SUFFIX=>".pdf", UNLINK=>0);
1036 print STDERR "FILENAME: $filename \n\n\n";
1037 my $pdf = PDF::Create->new(filename=>$c->path_to($filename),
1038 Author=>$c->config->{project_name},
1039 Title=>'Labels',
1040 CreationDate => [ localtime ],
1041 Version=>1.2,
1044 my $base_page = $pdf->new_page(MediaBox=>$pdf->get_page_size($page_format));
1046 my ($page_width, $page_height) = @{$pdf->get_page_size($page_format)}[2,3];
1048 my $label_height = int( ($page_height - $top_margin - $bottom_margin) / $labels_per_page);
1050 my @pages;
1051 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
1052 print STDERR "Generating page $page...\n";
1053 push @pages, $base_page->new_page();
1056 for (my $i=0; $i<@found; $i++) {
1057 my $label_count = $i + 1;
1058 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
1059 my $label_on_page = ($label_count -1) % $labels_per_page;
1061 # generate barcode
1063 my $tempfile;
1064 if ($parents =~ /NA\/NA/) {
1065 $tempfile = $c->forward('/barcode/phenotyping_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]." ".$found[$i]->[3]." ".$added_text ]);
1067 else {
1068 $tempfile = $c->forward('/barcode/phenotyping_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]." ".$found[$i]->[3]." ".$found[$i]->[4]." ".$added_text]);
1071 print STDERR "$tempfile\n";
1072 my $image = $pdf->image($tempfile);
1073 print STDERR "IMAGE: ".Data::Dumper::Dumper($image);
1075 # note: pdf coord system zero is lower left corner
1077 my $final_barcode_width = ($page_width - $right_margin - $left_margin) / $labels_per_row;
1079 my $scalex = $final_barcode_width / $image->{width};
1080 my $scaley = $label_height / $image->{height};
1082 if ($scalex < $scaley) { $scaley = $scalex; }
1083 else { $scalex = $scaley; }
1085 my $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1087 my $ypos = $label_boundary - int( ($label_height - $image->{height} * $scaley) /2);
1089 $pages[$page_nr-1]->line($page_width -100, $label_boundary, $page_width, $label_boundary);
1091 my $font = $pdf->font('BaseFont' => 'Times-Roman');
1092 foreach my $label_count (1..$labels_per_row) {
1093 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + ($label_count -1) * $final_barcode_width, ypos=>$ypos, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
1096 my $label_text = $found[$i]->[1];
1097 my $label_text_2 = "Accession: ".$found[$i]->[2];
1098 my $label_text_3 = $found[$i]->[3];
1099 my $label_text_4 = "Pedigree: ".$found[$i]->[4];
1101 my $label_count_15_xter_plot_name = 1-1;
1102 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 118.63;
1103 my $yposition = $ypos - 30;
1104 my $yposition_2 = $ypos - 40;
1105 my $yposition_3 = $ypos - 50;
1106 my $yposition_4 = $ypos - 60;
1107 my $yposition_5 = $ypos - 70;
1108 print "My X Position: $xposition and Y Position: $ypos\n";
1109 my $label_size = 11;
1110 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
1111 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_2);
1112 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_3);
1113 if ($found[$i]->[4] =~ m/^\//){
1114 $label_text_4 = "Pedigree: No pedigree available for ".$found[$i]->[2];
1116 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
1117 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
1120 $pdf->close();
1122 $c->stash->{not_found} = \@not_found;
1123 $c->stash->{found} = \@found;
1124 $c->stash->{file} = $filename;
1125 $c->stash->{filetype} = 'PDF';
1126 $c->stash->{template} = '/barcode/stock_download_result.mas';
1131 =head2 download_trial_qrcode
1133 URL: mapped to URL /barcode/trial/download/trial_QRcode
1134 Params: project_name or project_name_file: trial names to generate barcodes for
1135 Desc: creates the barcode image, create a pdf file, returns the created
1136 barcodes on a downloadable pdf file.
1137 Ret:
1138 Side Effects:
1139 Example:
1141 =cut
1143 # Generate Trial barcode
1144 sub download_trial_qrcode : Path('/barcode/trial/download/trial_QRcode') : Args(0) {
1145 my $self = shift;
1146 my $c = shift;
1147 my $project_names = $c->req->param("trial_names_2");
1148 my $project_names_file = $c->req->upload("trial_names_file_2");
1149 my $labels_per_page = 64;
1150 my $page_format = "letter";
1151 my $labels_per_row = 4;
1152 my $top_margin_mm = 12;
1153 my $left_margin_mm = 10;
1154 my $bottom_margin_mm = 12;
1155 my $right_margin_mm = 10;
1156 my $barcode_type = "trial";
1157 my $schema = $c->dbic_schema('Bio::Chado::Schema');
1159 # convert mm into pixels
1161 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } ($top_margin_mm,
1162 $left_margin_mm,
1163 $bottom_margin_mm,
1164 $right_margin_mm);
1166 # read file if upload
1168 if ($project_names_file) {
1169 my $project_file_contents = read_file($project_names_file->{tempname});
1170 $project_names = $project_names ."\n".$project_file_contents;
1173 $project_names =~ s/\r//g;
1174 my @names = split /\n/, $project_names;
1176 my @not_found;
1177 my @found;
1178 my $project_id;
1180 foreach my $name (@names) {
1182 # skip empty lines
1184 if (!$name) {
1185 next;
1188 my $project = $schema->resultset("Project::Project")->find( { name=>$name });
1190 if (!$project) {
1191 push @not_found, $name;
1192 next;
1194 my $project_id = $project->project_id();
1195 push @found, [ $project_id, $name];
1198 my $dir = $c->tempfiles_subdir('pdfs');
1199 my ($FH, $filename) = $c->tempfile(TEMPLATE=>"pdfs/pdf-XXXXX", SUFFIX=>".pdf", UNLINK=>0);
1200 print STDERR "FILENAME: $filename \n\n\n";
1201 my $pdf = PDF::Create->new(filename=>$c->path_to($filename),
1202 Author=>$c->config->{project_name},
1203 Title=>'Labels',
1204 CreationDate => [ localtime ],
1205 Version=>1.2,
1208 my $base_page = $pdf->new_page(MediaBox=>$pdf->get_page_size($page_format));
1210 my ($page_width, $page_height) = @{$pdf->get_page_size($page_format)}[2,3];
1211 my $label_height = 40;
1213 my @pages;
1214 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
1215 print STDERR "Generating page $page...\n";
1216 push @pages, $base_page->new_page();
1219 my $row_y_label_count = 1;
1220 my $labels_on_page = 0;
1221 my $row_count = 0;
1222 my $ypos;
1223 for (my $i=0; $i<@found; $i++) {
1224 my $label_count = $i + 1;
1225 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
1226 my $label_on_page = ($label_count -1) % $labels_per_page;
1228 # generate barcode
1230 my $tempfile;
1231 $tempfile = $c->forward('/barcode/phenotyping_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $barcode_type] );
1233 print STDERR "$tempfile\n";
1234 my $image = $pdf->image($tempfile);
1235 print STDERR "IMAGE: ".Data::Dumper::Dumper($image);
1237 # note: pdf coord system zero is lower left corner
1239 my $xlabel_margin = 3.5;
1240 my $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
1242 my $scalex = $final_barcode_width / $image->{width};
1243 my $scaley = $label_height / $image->{height};
1245 if ($scalex < $scaley) { $scaley = $scalex; }
1246 else { $scalex = $scaley; }
1247 my $label_boundary;
1249 my $label_height_16_per_page = 45;
1250 my $custom_label_height = 90;
1251 if ($labels_on_page == 64){
1252 $row_count = 0;
1253 $labels_on_page = 0;
1255 if ($row_y_label_count == 1 || $row_y_label_count > $labels_per_row){
1256 $label_boundary = $page_height - ($row_count * $label_height_16_per_page) - $top_margin;
1257 $ypos = $label_boundary - int( ($custom_label_height - $image->{height} * $scaley) /2);
1258 $row_count++;
1260 if ($row_y_label_count > $labels_per_row){
1261 $row_y_label_count = 1;
1263 print STDERR $row_y_label_count." ".$row_count." ".$ypos." ".$labels_on_page."\n";
1264 $row_y_label_count++;
1265 $labels_on_page++;
1267 my $font = $pdf->font('BaseFont' => 'Times-Roman');
1268 my $label_text = $found[$i]->[1];
1269 my $label_size = 10;
1270 my $xposition = $left_margin + 5 + ($row_y_label_count -2) * $final_barcode_width;
1271 my $yposition = $ypos;
1273 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
1274 $pages[$page_nr-1]->image(image=>$image, xpos=>$left_margin + 89 + ($row_y_label_count -2) * $final_barcode_width, ypos=>$ypos + 20.5, xalign=>0, yalign=>2, xscale=>$scalex, yscale=>$scaley);
1277 $pdf->close();
1279 $c->stash->{not_found} = \@not_found;
1280 $c->stash->{found} = \@found;
1281 $c->stash->{file} = $filename;
1282 $c->stash->{filetype} = 'PDF';
1283 $c->stash->{template} = '/barcode/stock_download_result.mas';
1287 # maps the label number to a page number
1288 sub label_to_page {
1289 my $self = shift;
1290 my $labels_per_page = shift;
1291 my $label_count = shift;
1293 my $page_count = int( ($label_count -1) / $labels_per_page) +1;
1294 return $page_count;
1297 sub upload_barcode_output : Path('/breeders/phenotype/upload') :Args(0) {
1298 my ($self, $c) = @_;
1299 my $upload = $c->req->upload('phenotype_file');
1300 my @contents = split /\n/, $upload->slurp;
1301 my $basename = $upload->basename;
1302 my $tempfile = $upload->tempname; #create a tempfile with the uploaded file
1303 if (! -e $tempfile) {
1304 die "The file does not exist!\n\n";
1306 print STDERR "***Basename= $basename, tempfile = $tempfile \n\n"; ##OK
1307 my $archive_path = $c->config->{archive_path};
1309 $tempfile = $archive_path . "/" . $basename ;
1310 print STDERR "**tempfile = $tempfile \n\n"; ##OK
1311 #chack for write permissions in $archive_path !
1312 my $upload_success = $upload->copy_to($archive_path . "/" . $basename); #returns false for failure, true for success
1313 if (!$upload_success) { die "Could not upload!\n $upload_success" ; }
1314 my $sb = CXGN::Stock::StockBarcode->new( { schema=> $c->dbic_schema("Bio::Chado::Schema", 'sgn_chado') });
1315 my $identifier_prefix = $c->config->{identifier_prefix};
1316 my $db_name = $c->config->{trait_ontology_db_name};
1318 $sb->parse(\@contents, $identifier_prefix, $db_name);
1319 my $parse_errors = $sb->parse_errors;
1320 $sb->verify; #calling the verify function
1321 my $verify_errors = $sb->verify_errors;
1322 my @errors = (@$parse_errors, @$verify_errors);
1323 my $warnings = $sb->warnings;
1324 $c->stash->{tempfile} = $tempfile;
1325 $c->stash(
1326 template => '/stock/barcode/upload_confirm.mas',
1327 tempfile => $tempfile,
1328 errors => \@errors,
1329 warnings => $warnings,
1330 feedback_email => $c->config->{feedback_email},
1335 sub store_barcode_output : Path('/barcode/stock/store') :Args(0) {
1336 my ($self, $c) = @_;
1337 my $filename = $c->req->param('tempfile');
1339 my @contents = read_file($filename);
1341 my $sb = CXGN::Stock::StockBarcode->new( { schema=> $c->dbic_schema("Bio::Chado::Schema", 'sgn_chado') });
1342 my $identifier_prefix = $c->config->{identifier_prefix};
1343 my $db_name = $c->config->{trait_ontology_db_name};
1344 $sb->parse(\@contents, $identifier_prefix, $db_name);
1345 $sb->store;
1346 my $error = $sb->store_error;
1347 my $message = $sb->store_message;
1348 $c->stash(
1349 template => '/stock/barcode/confirm_store.mas',
1350 error => $error,
1351 message => $message,