2 package SGN
::Controller
::StockBarcode
;
7 use Bio
::Chado
::Schema
::Result
::Stock
::Stock
;
8 use CXGN
::Stock
::StockBarcode
;
11 use SGN
::Model
::Cvterm
;
13 BEGIN { extends
"Catalyst::Controller"; }
17 # sub download_zpl_barcodes : Path('/barcode/stock/download/zpl') :Args(0) {
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;
34 # my $schema = $c->dbic_schema('Bio::Chado::Schema');
36 # foreach my $name (@names) {
44 # my $stock = $schema->resultset("Stock::Stock")->find( { name=>$name });
47 # push @not_found, $name;
51 # my $stock_id = $stock->stock_id();
55 # # generate new zdl label
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;
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();
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';
82 sub download_pdf_labels
:Path
('/barcode/stock/download/pdf') :Args
(0) {
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");
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 } (
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;
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);
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) {
174 my $stock = $schema->resultset("Stock::Stock")->find( { uniquename
=>$name });
177 push @not_found, $name;
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);
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);
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";
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];
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
},
273 CreationDate
=> [ localtime ],
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
286 if ($cass_print_format eq '32A4'){
288 print "LABEL HEIGHT: $label_height\n";
290 elsif ($cass_print_format eq '32_unique'){
292 $labels_per_page = 32;
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 );
303 ## for 20 labels per page
304 $label_height = int( ($page_height - $top_margin - $bottom_margin) / $labels_per_page);
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;
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;
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 ]);
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 ]);
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";
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 ]);
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){
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);
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++;
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);
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'){
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];
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;
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];
479 $label_text_4 = "No pedigree for ".$found[$i]->[2];
481 $label_text_4 = "pedigree: ".$parents;
484 elsif ($found[$i]->[5] eq 'accession'){
486 $label_text_4 = "No pedigree for ".$found[$i]->[1];
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];
496 $label_text_4 = "No pedigree for ".$found[$i]->[2];
498 $label_text_4 = "pedigree: ".$parents;
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;
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];
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;
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];
554 $label_text_4 = "No pedigree for ".$found[$i]->[2];
556 $label_text_4 = "pedigree: ".$parents;
559 elsif ($found[$i]->[5] eq 'accession'){
561 $label_text_4 = "No pedigree for ".$found[$i]->[1];
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];
571 $label_text_4 = "No pedigree for ".$found[$i]->[2];
573 $label_text_4 = "pedigree: ".$parents;
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];
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;
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];
612 $label_text_4 = "No pedigree for ".$found[$i]->[2];
614 $label_text_4 = $parents;
617 elsif ($found[$i]->[5] eq 'accession'){
619 $label_text_4 = "No pedigree for ".$found[$i]->[1];
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];
629 $label_text_4 = "No pedigree for ".$found[$i]->[2];
631 $label_text_4 = $parents;
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];
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;
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];
670 $label_text_4 = "No pedigree for ".$found[$i]->[2];
672 $label_text_4 = $parents;
675 elsif ($found[$i]->[5] eq 'accession'){
677 $label_text_4 = "No pedigree for ".$found[$i]->[1];
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];
687 $label_text_4 = "No pedigree for ".$found[$i]->[2];
689 $label_text_4 = $parents;
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];
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);
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];
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);
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);
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];
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);
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);
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];
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'){}
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);
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];
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];
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;
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];
896 $label_text_4 = "No pedigree for ".$found[$i]->[2];
898 $label_text_4 = "pedigree: ".$parents;
901 elsif ($found[$i]->[5] eq 'accession'){
903 $label_text_4 = "No pedigree for ".$found[$i]->[1];
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];
915 $label_text_4 = "No pedigree for ".$found[$i]->[2];
917 $label_text_4 = "pedigree: ".$parents;
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);
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) {
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,
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;
987 my ($row, $stockprop_name, $value, $fdata, $accession_id, $accession_name, $parents);
989 foreach my $name (@names) {
997 my $stock = $schema->resultset("Stock::Stock")->find( { name
=>$name });
1000 push @not_found, $name;
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';
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);
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
},
1040 CreationDate
=> [ localtime ],
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);
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;
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 ]);
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);
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.
1143 # Generate Trial barcode
1144 sub download_trial_qrcode
: Path
('/barcode/trial/download/trial_QRcode') : Args
(0) {
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,
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;
1180 foreach my $name (@names) {
1188 my $project = $schema->resultset("Project::Project")->find( { name
=>$name });
1191 push @not_found, $name;
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
},
1204 CreationDate
=> [ localtime ],
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;
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;
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;
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; }
1249 my $label_height_16_per_page = 45;
1250 my $custom_label_height = 90;
1251 if ($labels_on_page == 64){
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);
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++;
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);
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
1290 my $labels_per_page = shift;
1291 my $label_count = shift;
1293 my $page_count = int( ($label_count -1) / $labels_per_page) +1;
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;
1326 template
=> '/stock/barcode/upload_confirm.mas',
1327 tempfile
=> $tempfile,
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);
1346 my $error = $sb->store_error;
1347 my $message = $sb->store_message;
1349 template
=> '/stock/barcode/confirm_store.mas',
1351 message
=> $message,