5 drone_image_frame_shift_change.pl
9 load_locations.pl -H [dbhost] -D [dbname] -i [infile] -j [drone run id]
11 =head1 COMMAND-LINE OPTIONS
13 -H host name (required) e.g. "localhost"
14 -D database name (required) e.g. "cxgn_cassava"
15 -i path to infile (required)
16 -j drone run project id (required)
22 Nicolas Morales (nm529@cornell.edu)
32 use Spreadsheet
::ParseExcel
;
33 use Bio
::Chado
::Schema
;
34 use CXGN
::DB
::InsertDBH
;
35 use CXGN
::DroneImagery
::ImagesSearch
;
37 our ($opt_H, $opt_D, $opt_i, $opt_j);
41 if (!$opt_H || !$opt_D || !$opt_i || !$opt_j) {
42 pod2usage
(-verbose
=> 2, -message
=> "Must provide options -H (hostname), -D (database name), -i (input file) \n");
47 my $parser = Spreadsheet
::ParseExcel
->new();
48 my $excel_obj = $parser->parse($opt_i);
50 my $dbh = CXGN
::DB
::InsertDBH
->new({
53 dbargs
=> {AutoCommit
=> 1, RaiseError
=> 1}
56 my $schema= Bio
::Chado
::Schema
->connect( sub { $dbh->get_actual_dbh() } );
57 $dbh->do('SET search_path TO public,sgn');
59 my $q = "UPDATE phenome.stock_image SET stock_id = ? WHERE stock_image_id = ?;";
60 my $q2 = "UPDATE metadata.md_image SET obsolete='t' WHERE image_id = ?;";
61 my $h = $schema->storage->dbh()->prepare($q);
62 my $h2 = $schema->storage->dbh()->prepare($q2);
64 open(my $F, "<", $opt_i) || die " Can't open file $opt_i\n";
65 while (my $line = <$F>) {
67 my @row = split ',', $line;
68 my $plot_name_old = $row[0];
69 my $plot_name_new = $row[1];
71 my $old_plot_id = $schema->resultset("Stock::Stock")->find({uniquename
=>$plot_name_old})->stock_id();
72 #my $new_plot_id = $schema->resultset("Stock::Stock")->find({uniquename=>$plot_name_new})->stock_id();
74 my $images_search = CXGN
::DroneImagery
::ImagesSearch
->new({
76 drone_run_project_id_list
=>[$opt_j],
77 stock_id_list
=>[$old_plot_id]
79 my ($result, $total_count) = $images_search->search();
82 print STDERR Dumper
$_->{drone_run_band_project_name
};
83 print STDERR Dumper
$_->{project_image_type_name
};
84 print STDERR Dumper
$_->{stock_uniquename
};
86 my $image_id = $_->{image_id
};
87 my $stock_image_id = $_->{stock_image_id
};
88 $h->execute($new_plot_id, $stock_image_id);
89 #$h2->execute($image_id);
94 print STDERR
"Script Complete.\n";