Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / bin / transfer_genome_project_info.pl
blobf0dde968b4aff212aa791baf5682c62db17d888d
4 #### {"genome_project_funding_agencies":"TraitGenetics Inc.","genome_project_contact_person":"Martin Ganal, ganal@traitgenetics.de","genome_project_sequencing_center":"TraitGenetics","genome_project_dates":"2012","genome_project_genbank_link":"","genome_project_url":"traitgenetics.com","genome_project_sequenced_accessions":"Ailsa Craig"}
6 use strict;
8 use Getopt::Std;
9 use Data::Dumper;
10 use Pod::Usage;
11 use Bio::Chado::Schema;
12 use CXGN::DB::InsertDBH;
13 use JSON::Any;
15 our ($opt_H, $opt_D, $opt_i);
17 getopts('H:D:i:');
19 if (!$opt_H || !$opt_D ) {
20 pod2usage(-verbose => 2, -message => "Must provide options -H (hostname), -D (database name), -i (input file) \n");
23 my $dbhost = $opt_H;
24 my $dbname = $opt_D;
26 my $dbh = CXGN::DB::InsertDBH->new({
27 dbhost=>$dbhost,
28 dbname=>$dbname,
29 dbargs => {AutoCommit => 1, RaiseError => 1}
30 });
32 my $schema= Bio::Chado::Schema->connect( sub { $dbh->get_actual_dbh() });
34 my $q = "SELECT organismprop_id, organism_id, type_id, value from organismprop where type_id=(SELECT cvterm_id FROM cvterm where name='organism_sequencing_metadata')";
36 my $h = $dbh->prepare($q);
37 $h->execute();
39 while (my ($organismprop_id, $organism_id, $type_id, $value)= $h->fetchrow_array()) {
40 my $data = JSON::Any->decode($value);
42 my $row = $schema->resultset("Stock::Stock")->find( { organism_id => $organism_id, uniquename => $data->{genome_project_sequenced_accessions} });
44 if ($row) {
45 print STDERR "accession $data->{genome_project_sequenced_accessions} FOUND in database!!!!\n";
46 my $si = CXGN::Stock::SequencingInfo->new( { schema => $schema });
48 $si->funded_by($data->{genome_project_funding_agencies});
49 $si->contact_email($data->{genome_project_contact_person});
50 $si->organization($data->{genome_project_sequencing_center});
51 $si->sequencing_year($data->{genome_project_dates});
52 $si->genbank_accession($data->{genome_project_genbank_link});
53 $si->website($data->{genome_project_url});
54 $si->stock_id($row->stock_id());
55 $si->store();
58 else {
59 print sTDERR "accession $data->{genome_project_sequenced_accessions} ***NOT*** FOUND in database!!!!\n";