From: <nm...@us...> - 2012-01-24 19:16:31
|
Revision: 25253 http://gmod.svn.sourceforge.net/gmod/?rev=25253&view=rev Author: nm249 Date: 2012-01-24 19:16:18 +0000 (Tue, 24 Jan 2012) Log Message: ----------- no need for dbh. Autocommit should be on, and use schema transaction Modified Paths: -------------- schema/trunk/chado/bin/gmod_load_cvterms.pl Modified: schema/trunk/chado/bin/gmod_load_cvterms.pl =================================================================== --- schema/trunk/chado/bin/gmod_load_cvterms.pl 2011-12-01 19:46:55 UTC (rev 25252) +++ schema/trunk/chado/bin/gmod_load_cvterms.pl 2012-01-24 19:16:18 UTC (rev 25253) @@ -156,6 +156,7 @@ use Bio::GMOD::DB::Config; use Bio::Chado::Schema; +use Try::Tiny; our ($opt_d, $opt_h, $opt_H, $opt_F, $opt_n, $opt_D, $opt_v, $opt_t, $opt_u, $opt_o, $opt_p, $opt_r, $opt_g, $opt_s); @@ -203,12 +204,10 @@ $dsn .= ";host=$dbhost"; $dsn .= ";port=$port"; -my $schema= Bio::Chado::Schema->connect($dsn, $user, $pass||'', { AutoCommit=>0 }); +my $schema= Bio::Chado::Schema->connect($dsn, $user, $pass||''); -my $dbh=$schema->storage->dbh(); +if (!$schema) { die "No schema is avaiable! \n"; } -if (!$schema || !$dbh) { die "No schema or dbh is avaiable! \n"; } - ####################### my $error = 0; # keep track of input errors (in command line switches). @@ -251,42 +250,43 @@ push @onts, $ont; } message("Default namespace is " . $default_ont->name . " \n" , 1); + my $default_cv= $schema->resultset('Cv::Cv')->find_or_create( { name => $default_ont->name } , { key => 'cv_c1' }, ); foreach my $new_ont(@onts) { - my $new_ont_name=$new_ont->name(); - message("....found namespace '$new_ont_name' \n", 1); + my $coderef = sub { + my $new_ont_name=$new_ont->name(); + message("....found namespace '$new_ont_name' \n", 1); - if ($opt_n && ( $opt_n ne $new_ont_name) ) { - message ("$opt_n: skipping to next ontology..\n",1); - next (); - } - my $rel_cv; - #check if relationship ontology is already loaded: - if ($new_ont_name ne 'relationship') { - $rel_cv= $schema->resultset("Cv::Cv")->find_or_create( { name => 'relationship' } , { key => 'cv_c1' }, ); - my @rel= $schema->resultset("Cv::Cvterm")->search( - { cv_id => $rel_cv->get_column('cv_id'), - is_relationshiptype => 1, - }); - if (!@rel) { - warn "Relationship ontology must be loaded first!!\n" ; - exit(0); + if ($opt_n && ( $opt_n ne $new_ont_name) ) { + message ("$opt_n: skipping to next ontology..\n",1); + next (); } - } - ####add Typedef parsing to obo.pm!### - ####store a new cv if the ontology namespace does not exist - my $cv= $schema->resultset('Cv::Cv')->find_or_create( { name => $new_ont_name } , { key => 'cv_c1' }, ); + my $rel_cv; + #check if relationship ontology is already loaded: + if ($new_ont_name ne 'relationship') { + $rel_cv= $schema->resultset("Cv::Cv")->find_or_create( { name => 'relationship' } , { key => 'cv_c1' }, ); + my @rel= $schema->resultset("Cv::Cvterm")->search( + { cv_id => $rel_cv->get_column('cv_id'), + is_relationshiptype => 1, + }); + if (!@rel) { + warn "Relationship ontology must be loaded first!!\n" ; + exit(0); + } + } + ####add Typedef parsing to obo.pm!### + ####store a new cv if the ontology namespace does not exist + my $cv= $schema->resultset('Cv::Cv')->find_or_create( { name => $new_ont_name } , { key => 'cv_c1' }, ); - print STDERR "cv_id = ".($cv->get_column('cv_id') )."\n"; - print STDERR "Updating an ontology in the database...\n"; - my $db_ont = $cv; - my $ontology_name=$db_ont->get_column('name'); - message("Ontology name: ".($db_ont->name())."\n", 1); - my %file_relationships = (); # relationships currently defined in the file - my %db_relationships = (); - - eval { + print STDERR "cv_id = ".($cv->get_column('cv_id') )."\n"; + print STDERR "Updating an ontology in the database...\n"; + my $db_ont = $cv; + my $ontology_name=$db_ont->get_column('name'); + message("Ontology name: ".($db_ont->name())."\n", 1); + my %file_relationships = (); # relationships currently defined in the file + my %db_relationships = (); + ###### my $db = $schema->resultset("General::Db")->find_or_create( { name => $opt_s }, { key => 'db_c1' }, ); @@ -395,7 +395,7 @@ $db_index{$k}->set_column(name => $name ); $db_index{$k}->set_column( definition => $file_index{$k}->definition() ); $db_index{$k}->set_column(is_obsolete => $file_index{$k}->is_obsolete() ); - + #changing the name of obsolete terms to "$name (obsolete $db:$accession)" #to avoid violating the cvterm unique constaint (name, cv_id, is_obsolete) if ($db_index{$k}->is_obsolete() ) { @@ -476,9 +476,9 @@ my %file_secondary_ids = (); foreach my $i ($file_index{$k}->get_secondary_ids()) { + $i = substr($i, 0, 255); #dbxref.accession is varchar(255) maybe it needs to be text? $file_secondary_ids{uc($i)}=1; message("adding secondary id $i to the database...\n"); - $db_index{$k}->add_secondary_dbxref($i); } ######### @@ -638,7 +638,7 @@ print STDERR "\n"; ##################################### my $r_count = 0; - RELATIONSHIP: foreach my $r (keys(%file_relationships)) { + RELATIONSHIP: foreach my $r (keys(%file_relationships)) { $r_count++; if (!exists($db_relationships{$r})) { if ($opt_v) { print STDERR "Novel relationship: $r\n"; } @@ -737,25 +737,23 @@ ); } } - } + } message($ontology_name." : ". scalar(@novel_relationships)." novel relationships among ".(scalar(keys(%file_relationships)))." were found and stored.\n", 1); - }; - if ($@ || ($opt_t)) { - message( "Either running as trial mode (-t) or AN ERROR OCCURRED: $@\n",1); - $dbh->rollback(); - exit(0); - } - else { + if ($opt_t) { + die "TEST RUN! rolling back\n"; + } + }; + + try { + $schema->txn_do($coderef); message("Committing! \n If you are using cvtermpath you should now run gmod_make_cvtermpath.pl . See the perldoc for more info. \n\n", 1); - $dbh->commit(); + } catch { + # Transaction failed + die "An error occured! Rolling back! " . $_ . "\n"; } } -print STDERR "Done.\n"; - - - sub recursive_children { my $ont = shift; my $node = shift; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nm...@us...> - 2012-03-09 18:51:18
|
Revision: 25257 http://gmod.svn.sourceforge.net/gmod/?rev=25257&view=rev Author: nm249 Date: 2012-03-09 18:51:04 +0000 (Fri, 09 Mar 2012) Log Message: ----------- disabling loading of cross-ontologies relationships. Temporary solution for loading PO which has cross references among anatomy and growth stages terms Modified Paths: -------------- schema/trunk/chado/bin/gmod_load_cvterms.pl Modified: schema/trunk/chado/bin/gmod_load_cvterms.pl =================================================================== --- schema/trunk/chado/bin/gmod_load_cvterms.pl 2012-03-06 18:54:12 UTC (rev 25256) +++ schema/trunk/chado/bin/gmod_load_cvterms.pl 2012-03-09 18:51:04 UTC (rev 25257) @@ -690,7 +690,7 @@ next RELATIONSHIP; } ############################################ - push @novel_relationships, $r; + push @novel_relationships, $r; my $predicate_term_name = $file_relationships{$r}->predicate_term()->name(); my $predicate_term; @@ -729,7 +729,11 @@ } if (!$opt_t) { message("Storing relationship $r. type cv_id=" . $predicate_term->cv_id() ."\n" ,1); - my $new_rel = $schema->resultset('Cv::CvtermRelationship')->create( + if ( $subject_term->cv_id != $object_term->cv_id ) { + message("Wait! subjcet term has cv namespace " . $subject_term->cv->name . " which is different from the namespace of the object term (" . $object_term->cv->name . "). Cross referencing relationships across namespaces is not supported (yet.. ) SKIPPING this relationship! \n"); + next RELATIONSHIP; + } + my $new_rel = $schema->resultset('Cv::CvtermRelationship')->create( { subject_id => $subject_term->cvterm_id(), object_id => $object_term->cvterm_id(), type_id => $predicate_term->cvterm_id(), @@ -744,14 +748,14 @@ die "TEST RUN! rolling back\n"; } }; - + try { $schema->txn_do($coderef); message("Committing! \n If you are using cvtermpath you should now run gmod_make_cvtermpath.pl . See the perldoc for more info. \n\n", 1); } catch { # Transaction failed die "An error occured! Rolling back! " . $_ . "\n"; - } + }; } sub recursive_children { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nm...@us...> - 2012-07-24 19:15:02
|
Revision: 25267 http://gmod.svn.sourceforge.net/gmod/?rev=25267&view=rev Author: nm249 Date: 2012-07-24 19:07:50 +0000 (Tue, 24 Jul 2012) Log Message: ----------- messed up secondary dbxrefs are causing loading failure Modified Paths: -------------- schema/trunk/chado/bin/gmod_load_cvterms.pl Modified: schema/trunk/chado/bin/gmod_load_cvterms.pl =================================================================== --- schema/trunk/chado/bin/gmod_load_cvterms.pl 2012-06-12 11:36:58 UTC (rev 25266) +++ schema/trunk/chado/bin/gmod_load_cvterms.pl 2012-07-24 19:07:50 UTC (rev 25267) @@ -572,6 +572,7 @@ $new_term->add_secondary_dbxref($i); } foreach my $r ($novel_terms{$k}->get_dbxrefs() ) { #store definition's dbxrefs in cvterm_dbxref + if (!$r->database || !$r->primary_id) { next; } # skip def. dbxrefs without both db_name and accession my $def_dbxref= $r->database() . ':' . $r->primary_id(); message("adding definition dbxref $def_dbxref to cvterm_dbxref\n"); $new_term->add_secondary_dbxref($def_dbxref, 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nm...@us...> - 2013-07-16 17:49:36
|
Revision: 25289 http://sourceforge.net/p/gmod/svn/25289 Author: nm249 Date: 2013-07-16 17:49:23 +0000 (Tue, 16 Jul 2013) Log Message: ----------- dbxref accession is varchar 255 Modified Paths: -------------- schema/trunk/chado/bin/gmod_load_cvterms.pl Modified: schema/trunk/chado/bin/gmod_load_cvterms.pl =================================================================== --- schema/trunk/chado/bin/gmod_load_cvterms.pl 2013-05-29 17:04:46 UTC (rev 25288) +++ schema/trunk/chado/bin/gmod_load_cvterms.pl 2013-07-16 17:49:23 UTC (rev 25289) @@ -491,7 +491,8 @@ my $def_dbxref = $dblink->database() . ':' . $dblink->primary_id(); $file_def_dbxrefs{uc($def_dbxref)}=1; message("adding definition dbxref $def_dbxref to cvterm_dbxref\n"); - $db_index{$k}->add_secondary_dbxref($def_dbxref, 1); + $def_dbxref = substr($def_dbxref, 0, 255); + $db_index{$k}->add_secondary_dbxref($def_dbxref, 1); } } } @@ -568,12 +569,13 @@ foreach my $i ($novel_terms{$k}->get_secondary_ids()) { #store secondary ids in cvterm_dbxref message("adding secondary dbxref '$i' to cvterm_dbxref\n"); - + $i = substr($i, 0, 255); $new_term->add_secondary_dbxref($i); } foreach my $r ($novel_terms{$k}->get_dbxrefs() ) { #store definition's dbxrefs in cvterm_dbxref if (!$r->database || !$r->primary_id) { next; } # skip def. dbxrefs without both db_name and accession my $def_dbxref= $r->database() . ':' . $r->primary_id(); + $def_dbxref = substr($def_dbxref, 0, 255); message("adding definition dbxref $def_dbxref to cvterm_dbxref\n"); $new_term->add_secondary_dbxref($def_dbxref, 1); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |