Merge pull request #4989 from solgenomics/timestamp_fixes
[sgn.git] / bin / drone_image_frame_shift_change.pl
blobad6920660b99a6e41725515ed4fa4495da22c3ed
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 The format is .csv
22 =head1 AUTHOR
24 Nicolas Morales (nm529@cornell.edu)
26 =cut
28 use strict;
30 use Getopt::Std;
31 use Data::Dumper;
32 use Carp qw /croak/ ;
33 use Pod::Usage;
34 use Bio::Chado::Schema;
35 use CXGN::DB::InsertDBH;
36 use CXGN::DroneImagery::ImagesSearch;
38 our ($opt_H, $opt_D, $opt_i, $opt_j);
40 getopts('H:D:i:j:');
42 if (!$opt_H || !$opt_D || !$opt_i || !$opt_j) {
43 pod2usage(-verbose => 2, -message => "Must provide options -H (hostname), -D (database name), -i (input file) \n");
46 my $dbhost = $opt_H;
47 my $dbname = $opt_D;
49 my $dbh = CXGN::DB::InsertDBH->new({
50 dbhost=>$dbhost,
51 dbname=>$dbname,
52 dbargs => {AutoCommit => 1, RaiseError => 1}
53 });
55 my $schema= Bio::Chado::Schema->connect( sub { $dbh->get_actual_dbh() } );
56 $dbh->do('SET search_path TO public,sgn');
58 my $q = "UPDATE phenome.stock_image SET stock_id = ? WHERE stock_image_id = ?;";
59 my $q2 = "UPDATE metadata.md_image SET obsolete='t' WHERE image_id = ?;";
60 my $h = $schema->storage->dbh()->prepare($q);
61 my $h2 = $schema->storage->dbh()->prepare($q2);
63 open(my $F, "<", $opt_i) || die " Can't open file $opt_i\n";
64 while (my $line = <$F>) {
65 chomp $line;
66 my @row = split ',', $line;
67 my $plot_name_old = $row[0];
68 my $plot_name_new = $row[1];
70 my $old_plot_id = $schema->resultset("Stock::Stock")->find({uniquename=>$plot_name_old})->stock_id();
71 #my $new_plot_id = $schema->resultset("Stock::Stock")->find({uniquename=>$plot_name_new})->stock_id();
73 my $images_search = CXGN::DroneImagery::ImagesSearch->new({
74 bcs_schema=>$schema,
75 drone_run_project_id_list=>[$opt_j],
76 stock_id_list=>[$old_plot_id]
77 });
78 my ($result, $total_count) = $images_search->search();
80 foreach (@$result) {
81 print STDERR Dumper $_->{drone_run_band_project_name};
82 print STDERR Dumper $_->{project_image_type_name};
83 print STDERR Dumper $_->{stock_uniquename};
85 my $image_id = $_->{image_id};
86 my $stock_image_id = $_->{stock_image_id};
87 $h->execute($new_plot_id, $stock_image_id);
88 #$h2->execute($image_id);
91 close($F);
93 print STDERR "Script Complete.\n";