From 8753ad8b27140489a36699ed58ae78e02bf4b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?= <ak4@sanger.ac.uk> Date: Wed, 9 Feb 2011 14:48:04 +0000 Subject: [PATCH] Add code to parse and store synonyms from the OBO file. Also only get term definitions from within "...". --- .../ontology/scripts/load_OBO_file.pl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/misc-scripts/ontology/scripts/load_OBO_file.pl b/misc-scripts/ontology/scripts/load_OBO_file.pl index 6dfb25e45a..048f1a00ae 100755 --- a/misc-scripts/ontology/scripts/load_OBO_file.pl +++ b/misc-scripts/ontology/scripts/load_OBO_file.pl @@ -135,14 +135,17 @@ sub write_term { print("Writing to 'term' table...\n"); - $dbh->do("LOCK TABLE term WRITE"); + $dbh->do("LOCK TABLE term, synonym WRITE"); my $statement = "INSERT INTO term " . "(ontology_id, subsets, accession, name, definition) " . "VALUES (?,?,?,?,?)"; - my $sth = $dbh->prepare($statement); + my $syn_stmt = "INSERT INTO synonym (term_id, name) VALUES (?,?)"; + + my $sth = $dbh->prepare($statement); + my $syn_sth = $dbh->prepare($syn_stmt); my $id; my $count = 0; @@ -181,6 +184,13 @@ sub write_term { } $term->{'id'} = $id; + foreach my $syn ( @{ $term->{'synonyms'} } ) { + $syn_sth->bind_param( 1, $id, SQL_INTEGER ); + $syn_sth->bind_param( 2, $syn, SQL_VARCHAR ); + + $syn_sth->execute(); + } + ++$count; } ## end foreach my $accession ( sort...) alarm(0); @@ -432,7 +442,7 @@ EOT } elsif ( $type eq 'namespace' ) { $term{'namespace'} = $data; } elsif ( $type eq 'def' ) { - $term{'definition'} = $data; + ( $term{'definition'} ) = ( $data =~ /^"(.*)"/ ); } elsif ( $type eq 'is_a' ) { my ($parent_acc) = $data =~ /(\S+)/; push( @{ $term{'parents'}{'is_a'} }, $parent_acc ); @@ -443,6 +453,9 @@ EOT if ( $data eq 'true' ) { $state = 'clear' } } elsif ( $type eq 'subset' ) { push( @{ $term{'subsets'} }, $data ); + } elsif ( $type eq 'synonym' ) { + my ($synonym) = ( $data =~ /^"(.*)"/ ); + push( @{ $term{'synonyms'} }, $synonym ); } } ## end elsif ( $line =~ /^(\w+): (.+)$/) -- GitLab