diff --git a/misc-scripts/xref_mapping/XrefParser/WormbaseDatabaseStableIDParser.pm b/misc-scripts/xref_mapping/XrefParser/WormbaseDatabaseStableIDParser.pm new file mode 100644 index 0000000000000000000000000000000000000000..c81e1971b887af80d0e82dbb7ecad6269f35ae52 --- /dev/null +++ b/misc-scripts/xref_mapping/XrefParser/WormbaseDatabaseStableIDParser.pm @@ -0,0 +1,58 @@ +package XrefParser::WormbaseDatabaseStableIDParser; + +# Read gene and transcript stable IDs from a WormBase-imported database and create +# xrefs and direct xrefs for them. +# Note the only things that are actually WormBase specific here are the source names +# for the wormbase_gene and wormbase_transcript sources. + +use strict; + +use XrefParser::DatabaseParser; + +use vars qw(@ISA); +@ISA = qw(XrefParser::DatabaseParser); + +sub run { + + my ($self, $dsn, $source_id, $species_id) = @_; + + my $db = $self->connect($dsn); # source db (probably core) + my $xref_db = $self->dbi(); + + my $xref_sth = $xref_db->prepare( "INSERT INTO xref (accession,label,source_id,species_id) VALUES (?,?,?,?)" ); + my $direct_xref_sth = $xref_db->prepare( "INSERT INTO direct_xref (general_xref_id,ensembl_stable_id,type,linkage_xref) VALUES (?,?,?,?)" ); + + # read stable IDs + foreach my $type ('gene', 'transcript') { + + print "Building xrefs from $type stable IDs\n"; + + my $wb_source_id = $self->get_source_id_for_source_name("wormbase_$type"); + + my $sth = $db->prepare( "SELECT stable_id FROM ${type}_stable_id" ); + $sth->execute(); + + while(my @row = $sth->fetchrow_array()) { + + my $id = $row[0]; + # add an xref & a direct xref + $xref_sth->execute($id, $id, $wb_source_id, $species_id); + my $xref_id = $xref_sth->{'mysql_insertid'}; + $direct_xref_sth->execute($xref_id, $id, $type, "Stable ID direct xref"); + + } # while fetch stable ID + + } # foreach type + +} + +sub new { + + my $self = {}; + bless $self, "XrefParser::WormbaseDatabaseStableIDParser"; + return $self; + +} + +1; +