my$sql='select tsi.stable_id, x.display_label from xref x, object_xref ox , transcript_stable_id tsi, external_db e where e.external_db_id = x.external_db_id and x.xref_id = ox.xref_id and tsi.transcript_id = ox.ensembl_id and e.db_name like ?';
# need to get label and derscriptions fro primary acc.
#
my$hgnc_sql='select tsi.stable_id, x.dbprimary_acc from xref x, object_xref ox , transcript_stable_id tsi, gene g, external_db e, transcript t where t.gene_id = g.gene_id and g.gene_id = ox.ensembl_id and tsi.transcript_id = t.transcript_id and e.external_db_id = x.external_db_id and x.xref_id = ox.xref_id and ox.ensembl_object_type = "Gene" and e.db_name like "MGI"';
my%mgi_to_label;
my%mgi_to_desc;
my%mgi_syn;
my$sth=$self->dbi()->prepare("SELECT x.accession, x.label, x.description from xref x, source s where x.source_id = s.source_id and s.name like 'MGI' and s.priority_description like 'descriptions'");
print"We have ".scalar(%ott_to_enst)." ott to enst entries\n"if($verbose);
$sth=$dbi2->prepare($hgnc_sql);
$sth->execute()orcroak($dbi2->errstr());
$sth=$self->dbi()->prepare("SELECT sy.synonym, x.accession from xref x, source s, synonym sy where sy.xref_id = x.xref_id and x.source_id = s.source_id and s.name like 'MGI' and s.priority_description like 'descriptions'");
$sth->execute()orcroak($self->dbi()->errstr());
while(my@row=$sth->fetchrow_array()){
$mgi_syn{$row[0]}=$row[1];
$ott_to_hgnc{$row[0]}=$row[1];
}
$sth->finish;
print"We have ".scalar(%ott_to_hgnc)." ott to mgi entries\n"if($verbose);
my$line_count=0;
my$xref_count=0;
# becouse the direct mapping have no descriptions etc
# we have to steal these fromt he previous HGNC parser.
# This is why the order states this is after the other one.
# maybe 1091,1092 is not right maybe should use name = HGNC and priority = 30r4 ??
my%label;
my%version;
my%description;
my$core_sql='select tsi.stable_id, x.dbprimary_acc from transcript_stable_id tsi, transcript t, object_xref ox, xref x, external_db e where tsi.transcript_id = t.transcript_id and ox.ensembl_id = t.transcript_id and ox.ensembl_object_type = "Transcript" and ox.xref_id = x.xref_id and x.external_db_id = e.external_db_id and e.db_name like "%OTTT"';
my$dbi=$self->dbi();
my%ott_to_enst;
my$sql="insert into synonym (xref_id, synonym) values (?, ?)";
#get the source ids for HGNC refseq, entrezgene and unitprot
$sql='select source_id, priority_description from source where name like "MGI"';
$sth=$dbi->prepare($sql);
$sth=$dbi2->prepare($core_sql);
$sth->execute()orcroak($dbi2->errstr());
while(my@row=$sth->fetchrow_array()){
$ott_to_enst{$row[1]}=$row[0];
$sth->execute();
my($hgnc_source_id,$desc);
$sth->bind_columns(\$hgnc_source_id,\$desc);
my@arr;
while($sth->fetch()){
push@arr,$hgnc_source_id;
}
$sth->finish;
#
# get the enst->ensg mappings.
#
my%enst_to_ensg;
$sth=$dbi2->prepare("select gsi.stable_id, tsi.stable_id from transcript t, gene_stable_id gsi, transcript_stable_id tsi where tsi.transcript_id = t.transcript_id and t.gene_id = gsi.gene_id");
$sth->execute()orcroak($dbi2->errstr());
while(my@row=$sth->fetchrow_array()){
$enst_to_ensg{$row[1]}=$row[0];
$sql="select accession, label, version, description from xref where source_id in (".join(", ",@arr).")";