4 use CXGN
::DB
::InsertDBH
;
7 use CXGN
::Phenome
::Locus
;
8 use Bio
::Chado
::Schema
;
11 with
'MooseX::Runnable';
12 with
'MooseX::Getopt';
17 traits
=> ['NoGetopt'],
27 documentation
=> 'required, database host',
35 documentation
=> 'required, database name',
44 documentation
=> 'required, input directory name with TomDel files',
56 'Test run. Rollback the transaction.',
60 my ($self,$name) = @_;
62 my $dbh = CXGN
::DB
::InsertDBH
->new(
64 dbname
=>$self->dbname,
65 dbhost
=> $self->dbhost,
69 #$dbh->{AutoCommit} = 1;
71 my $schema= Bio
::Chado
::Schema
->connect( sub { $dbh } , { on_connect_do
=> ['SET search_path TO public;'] }
73 my $dirname = $self->dirname;
75 my @files = glob "$dirname/*.pdf";
77 my $db = $schema->resultset("General::Db")->find_or_create( {
79 urlprefix
=> 'https://',
80 url
=> 'solgenomics.net/ftp/TomDel-0.1/',
83 foreach my $file (@files) {
85 my $filename = basename
($file);
87 my ($clean_filename, $ext) = split(/\.pdf/ , $filename);
88 my ($gene_model, $chr, $position) = split (/_/ , $clean_filename ) ;
89 #Solyc01g005000.2_SL2.50ch01_14034.pdf
90 #chromosome: SL2.50ch08, position: 1734498, link to genotype frequencies in tomato populations
91 my $sgn_locusname = $gene_model;
92 if ($gene_model =~ m/Solyc.*/) {
93 my ($tomato_locus_name, $version) = split (/\./ , $gene_model ) ;
94 $sgn_locusname = $tomato_locus_name;
95 print STDERR
"Found tomato locus $sgn_locusname, $chr, $position\n";
97 my $locus = CXGN
::Phenome
::Locus
->new_with_locusname($dbh, $sgn_locusname);
98 my $locus_id = $locus->get_locus_id;
100 if ($locus->get_obsolete eq 't') {
101 print STDERR
"Locus $gene_model is obsolete. Skipping. \n";
105 print STDERR
"No locus exists for ID $gene_model.\n";
108 #add the link via dbxref
109 #print STDERR "ADDING dbxref \n";
110 my $dbxref = $db->find_or_create_related('dbxrefs' , {
111 accession
=> $filename,
112 description
=> "chromosome $chr, position: $position",
114 #chromosome: SL2.50ch08, position: 1734498, link to genotype frequencies in tomato populations
115 my $dbxref_id = $dbxref->dbxref_id();
116 my $dbxref_object = CXGN
::Chado
::Dbxref
->new($dbh, $dbxref_id);
117 $locus->add_locus_dbxref($dbxref_object,
119 $locus->get_sp_person_id);
121 print STDERR
"Added TomDel link dbxref_id=$dbxref_id , locus_id = $locus_id\n ";
123 print STDERR
"Added $counter locus_dbxref links \n";
125 print "Trial mode! rolling back \n";