Merge branch 'master' into topic/phen_stderr
[sgn.git] / bin / transfer_genome_project_info.pl
blobfa5133011c9a327016b37e0350d28473606a956d
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;
14 use CXGN::Stock::SequencingInfo;
16 our ($opt_H, $opt_D);
18 getopts('H:D:');
20 if (!$opt_H || !$opt_D ) {
21 pod2usage(-verbose => 2, -message => "Must provide options -H (hostname), -D (database name), -i (input file) \n");
24 my $dbhost = $opt_H;
25 my $dbname = $opt_D;
27 my $dbh = CXGN::DB::InsertDBH->new({
28 dbhost=>$dbhost,
29 dbname=>$dbname,
30 dbargs => {AutoCommit => 1, RaiseError => 1}
31 });
33 my $schema= Bio::Chado::Schema->connect( sub { $dbh->get_actual_dbh() });
35 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')";
37 my $h = $dbh->prepare($q);
38 $h->execute();
40 while (my ($organismprop_id, $organism_id, $type_id, $value)= $h->fetchrow_array()) {
41 my $data = JSON::Any->decode($value);
43 my $row = $schema->resultset("Stock::Stock")->find( { organism_id => $organism_id, uniquename => $data->{genome_project_sequenced_accessions} });
45 if ($row) {
46 print STDERR "accession $data->{genome_project_sequenced_accessions} FOUND in database!!!!\n";
47 my $si = CXGN::Stock::SequencingInfo->new( { schema => $schema });
49 $si->funded_by($data->{genome_project_funding_agencies});
50 $si->contact_email($data->{genome_project_contact_person});
51 $si->organization($data->{genome_project_sequencing_center});
52 $si->sequencing_year($data->{genome_project_dates});
53 $si->genbank_accession($data->{genome_project_genbank_link});
54 $si->website($data->{genome_project_url});
55 $si->stock_id($row->stock_id());
56 $si->store();
59 else {
60 print STDERR "accession $data->{genome_project_sequenced_accessions} ***NOT*** FOUND in database!!!!\n";