Skip to content
Snippets Groups Projects
Commit 8753ad8b authored by Andreas Kusalananda Kähäri's avatar Andreas Kusalananda Kähäri
Browse files

Add code to parse and store synonyms from the OBO file.

Also only get term definitions from within "...".
parent 39877f97
No related branches found
No related tags found
No related merge requests found
......@@ -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+): (.+)$/)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment