Merge branch 'master' into topic/transformation_tool
[sgn.git] / bin / update_blast_names.pl
blob8031431e243c4388ad7c8a13450753d5f1faa2f5
1 #!/usr/bin/perl
3 use Getopt::Std;
4 use Bio::Chado::Schema;
5 use CXGN::DB::InsertDBH;
6 use Data::Dumper;
7 use File::Slurp qw | read_file |;
9 use vars qw | $opt_H $opt_D $opt_f |;
11 getopts('H:D:f:');
13 my $dbh = CXGN::DB::InsertDBH->new( {
14 dbhost => $opt_H,
15 dbname => $opt_D,
16 } );
18 my $file = $opt_f;
19 my @lines = read_file($file);
21 my $schema = Bio::Chado::Schema->connect( sub { $dbh->get_actual_dbh() } );
23 eval {
24 foreach my $l (@lines) {
26 chomp($l);
27 $l =~ s/\r//g;
29 my ($old_name, $transcript_name, $species, $abbr) = split /\t/, $l;
31 my $q = "SELECT blast_db_id FROM sgn.blast_db WHERE title=?";
33 my $h = $dbh->prepare($q);
34 $h->execute($old_name);
36 while (my ($blast_db_id) = $h->fetchrow_array()) {
37 print STDERR "Found $old_name ($blast_db_id).\n";
38 my $q2 = "UPDATE sgn.blast_db set title=? where blast_db_id=?";
39 my $new_name = "$species ($abbr)";
40 my $h2 = $dbh->prepare($q2);
41 $h2->execute($new_name, $blast_db_id);
42 print STDERR "Stored new name $new_name\n";
47 if ($@) {
48 print STDERR "An error occurred. Rolling everything back. ($@)\n";
49 $dbh->rollback();
52 else {
53 print STDERR "Done. Committing...\n";
54 $dbh->commit();