Skip to content
Snippets Groups Projects
Commit 120922f1 authored by Monika Komorowska's avatar Monika Komorowska
Browse files

changes related to stable_id merge

parent 46999f24
No related branches found
No related tags found
No related merge requests found
......@@ -50,13 +50,12 @@ my $vega_dba = Bio::EnsEMBL::DBSQL::DBAdaptor->new(-host => $vhost||'ens-staging
#
my $sql =(<<EOS);
select aa.alt_allele_id, gsi.stable_id, x2.display_label
from alt_allele aa, gene_stable_id gsi, xref x1, gene g
select aa.alt_allele_id, g.stable_id, x2.display_label
from alt_allele aa, gene g, xref x1
left join object_xref ox on g.gene_id = ox.ensembl_id
left join xref x2 on ox.xref_id = x2.xref_id
left join external_db edb on x2.external_db_id = edb.external_db_id
where aa.gene_id = gsi.gene_id
and gsi.gene_id = g.gene_id
where aa.gene_id = g.gene_id
and g.display_xref_id = x1.xref_id
and ox.ensembl_object_type = 'Gene'
and edb.db_name = 'ENSG';
......@@ -130,7 +129,7 @@ my $core_dba = Bio::EnsEMBL::DBSQL::DBAdaptor->new(-host => $chost||'ens-staging
my %stable_id_to_gene_id;
$sth = $core_dba->dbc->prepare("Select stable_id, gene_id from gene_stable_id");
$sth = $core_dba->dbc->prepare("Select stable_id, gene_id from gene");
$sth->execute;
my ($gene_id);
$sth->bind_columns(\$core_stable_id, \$gene_id);
......@@ -242,7 +241,7 @@ print "Added $alt_id_count alt_allele ids for $count genes\n";
#
# useful sql to look at sanity check problems
#
#select gsi.stable_id,g.seq_region_start, g.seq_region_end, s.name, x.display_label from gene g, seq_region s, gene_stable_id gsi, alt_allele aa, xref x where g.display_xref_id = x.xref_id and gsi.gene_id = g.gene_id and g.gene_id = aa.gene_id and g.seq_region_id = s.seq_region_id and aa.alt_allele_id =37;
#select g.stable_id,g.seq_region_start, g.seq_region_end, s.name, x.display_label from gene g, seq_region s, alt_allele aa, xref x where g.display_xref_id = x.xref_id and g.gene_id = aa.gene_id and g.seq_region_id = s.seq_region_id and aa.alt_allele_id =37;
......@@ -257,7 +256,7 @@ exit;
## LRG SQL. How to fit this in?
##select ox.ensembl_id, gsi.gene_id from xref x, object_xref ox, external_db e, gene_stable_id gsi where x.xref_id = ox.xref_id and e.external_db_id = x.external_db_id and e.db_name like "Ens_Hs_gene" and ox.ensembl_object_type = "Gene" and x.display_label = gsi.stable_id ;
##select ox.ensembl_id, g.gene_id from xref x, object_xref ox, external_db e, gene g where x.xref_id = ox.xref_id and e.external_db_id = x.external_db_id and e.db_name like "Ens_Hs_gene" and ox.ensembl_object_type = "Gene" and x.display_label = g.stable_id ;
......@@ -266,13 +265,13 @@ exit;
##
#$sql =(<<LRG);
#SELECT ox.ensembl_id, gsi.gene_id
# FROM xref x, object_xref ox, external_db e, gene_stable_id gsi
#SELECT ox.ensembl_id, g.gene_id
# FROM xref x, object_xref ox, external_db e, gene g
# WHERE x.xref_id = ox.xref_id AND
# e.external_db_id = x.external_db_id AND
# e.db_name like "Ens_Hs_gene" AND
# ox.ensembl_object_type = "Gene" AND
# x.display_label = gsi.stable_id
# x.display_label = g.stable_id
#LRG
#$sth = $core_dba->dbc->prepare($sql);
......
......@@ -66,7 +66,7 @@ my %stable_id_to_dbid; # use for gene,transcripts and exons
foreach my $type (qw(gene transcript exon)){
my $sth = $dbi->prepare("SELECT ".$type."_id, stable_id FROM ".$type."_stable_id");
my $sth = $dbi->prepare("SELECT ".$type."_id, stable_id FROM ".$type);
$sth->execute;
my ($stable_id, $dbid);
$sth->bind_columns(\$dbid, \$stable_id);
......
......@@ -46,7 +46,6 @@ my $dbi =
|| die "Can't connect to database\n";
foreach my $type (@types) {
my $table = $type . "_stable_id";
my $sth;
# Get starting stable ID, either specified or current max.
......@@ -77,18 +76,17 @@ foreach my $type (@types) {
# get a list of objects that don't currently have stable IDs assigned
# and assign new ones, incrementing & preserving formatting as we go
my $sql =
"SELECT $type.${type}_id "
"SELECT ${type}_id "
. "FROM $type "
. "LEFT JOIN $table sid ON $type.${type}_id=sid.${type}_id "
. "WHERE sid.stable_id IS NULL";
. "WHERE stable_id IS NULL";
$sth = $dbi->prepare($sql);
$sth->execute();
while ( my @row = $sth->fetchrow_array() ) {
( $new_stable_id, my $nis ) =
@{ increment_stable_id( $new_stable_id, $type ) };
print( "INSERT INTO $table "
. "VALUES($row[0],\'$nis\',1,\'$ts\',\'$ts\');\n" );
print( "UPDATE $type SET stable_id = \'$nis\', version = 1, created_date = \'$ts\', modified_date = \'$ts\'"
. " WHERE ${type}_id = $row[0];\n" );
}
} ## end foreach my $type (@types)
......@@ -154,19 +152,17 @@ sub get_max_stable_id_from_gene_archive {
sub get_highest_stable_id {
my ( $dbi, $type ) = @_;
my $sid = $type . "_stable_id";
my ( $highest_from_current, $highest_from_archive );
# Get highest stable ID from the relevant table.
my $sth = $dbi->prepare("SELECT MAX(stable_id) FROM $sid");
my $sth = $dbi->prepare("SELECT MAX(stable_id) FROM $type");
$sth->execute();
if ( my @row = $sth->fetchrow_array() ) {
$highest_from_current = $row[0];
} else {
die("Can't get max $type stable ID from $sid\n");
die("Can't get max $type stable ID from $type\n");
}
if ( length($highest_from_current) == 0 ) {
......@@ -181,8 +177,7 @@ sub get_highest_stable_id {
if ( length($highest_from_current) == 0 ) {
print( "\n"
. "WARNING:\n"
. "No exon_stable_id for exon found "
. "(exon_stable_id_table empty)\n"
. "No stable_id for exon found \n"
. "I got no prefix to generate new stable_ids for type $type!!! "
. "- I'll try to use gene_archive now\n" );
......@@ -196,8 +191,8 @@ sub get_highest_stable_id {
$prefix =~ s/G$//g;
} else {
die( "ERROR: "
. "No entries in table exon_stable_id and "
. "table gene_archive found\n"
. "No entries in table exon and "
. "gene_archive tables found\n"
. "Don't know which species prefix to use for species.\n" );
$highest_from_current = sprintf( "%s%011d", $prefix, 0 );
......
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