added test
[sgn.git] / bin / drone_image_frame_shift_change.pl
blob78450f92107a7cbc6276195e8b7a358b05650105
1 #!/usr/bin/perl
3 =head1
5 drone_image_frame_shift_change.pl
7 =head1 SYNOPSIS
9 load_locations.pl -H [dbhost] -D [dbname] -i [infile] -j [drone run id]
11 =head1 COMMAND-LINE OPTIONS
12 ARGUMENTS
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)
18 =head1 DESCRIPTION
20 =head1 AUTHOR
22 Nicolas Morales (nm529@cornell.edu)
24 =cut
26 use strict;
28 use Getopt::Std;
29 use Data::Dumper;
30 use Carp qw /croak/ ;
31 use Pod::Usage;
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);
39 getopts('H:D:i: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");
45 my $dbhost = $opt_H;
46 my $dbname = $opt_D;
47 my $parser = Spreadsheet::ParseExcel->new();
48 my $excel_obj = $parser->parse($opt_i);
50 my $dbh = CXGN::DB::InsertDBH->new({
51 dbhost=>$dbhost,
52 dbname=>$dbname,
53 dbargs => {AutoCommit => 1, RaiseError => 1}
54 });
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>) {
66 chomp $line;
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({
75 bcs_schema=>$schema,
76 drone_run_project_id_list=>[$opt_j],
77 stock_id_list=>[$old_plot_id]
78 });
79 my ($result, $total_count) = $images_search->search();
81 foreach (@$result) {
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);
92 close($F);
94 print STDERR "Script Complete.\n";