my ( $dbh_read, $dbh_write, $dbtype, $speciesOffset ) = @_;
#print "DbType : $dbtype speciesOffset : $speciesOffset\n";
my @stable_id_objects = keys %{ $group_objects{$dbtype} || {} };
foreach my $object_name (@stable_id_objects) {
my $object = lc($object_name);
my $select_sql;
if ( $object_name =~ /([A-Za-z]+)Archive/ ) {
my $object = lc($1);
#Note: Archive is not needed by ensemblgenomes as the stable_id_event is not populated
#It is needed by ensembl. For the time being, we have to assume that the coord_system holds only one species with id of 1
#In future ensembl also might need to support multiple databases
my $species_id = 1;
$select_sql =
"SELECT DISTINCT old_stable_id, $species_id + $speciesOffset, '$dbtype', '$object' \
FROM stable_id_event
WHERE old_stable_id IS NOT NULL
AND type = '$object'
AND old_stable_id NOT IN (SELECT stable_id FROM $object)";
$select_sql = $test ? $select_sql . " limit 10" : $select_sql;
my $is_archive = 1;
my $rows_inserted =
build_insert_sql( $select_sql, $dbh_read, $dbh_write, $is_archive );
}
elsif ( $object_name =~ / RNAProduct | Translation /x ) {
my $sth = $dbh_read->prepare("SELECT COUNT(*) FROM $object");
$sth->execute();
my ($count) = $sth->fetchrow_array;
if ($count) {
if ( $dbtype eq 'core' ) {
$select_sql =
"SELECT DISTINCT o.stable_id, cs.species_id + $speciesOffset, '$dbtype', '$object_name' \
FROM $object o \
LEFT JOIN transcript t USING (transcript_id) \
LEFT JOIN seq_region sr USING(seq_region_id) \
LEFT JOIN coord_system cs USING(coord_system_id) \
WHERE o.stable_id IS NOT NULL";
$select_sql = $test ? $select_sql . " limit 10" : $select_sql;
}
elsif ( $dbtype eq 'otherfeatures' ) {
$select_sql =
"SELECT DISTINCT tl.stable_id, cs.species_id + $speciesOffset, '$dbtype', '$object_name' \
FROM translation tl \
LEFT JOIN transcript t USING (transcript_id) \
LEFT JOIN analysis a USING (analysis_id) \
LEFT JOIN seq_region sr USING(seq_region_id) \
LEFT JOIN coord_system cs USING(coord_system_id) \
WHERE logic_name like 'RefSeq_%' OR logic_name like 'CCDS_%'";
$select_sql = $test ? $select_sql . " limit 10" : $select_sql;
}
}
}
else {
my $sth = $dbh_read->prepare("SELECT COUNT(*) FROM $object");
$sth->execute();
my ($count) = $sth->fetchrow_array;
if ($count) {
if ( $dbtype eq 'core' ) {
$select_sql =
"SELECT DISTINCT o.stable_id, cs.species_id + $speciesOffset, '$dbtype', '$object_name' \
FROM $object o \
LEFT JOIN seq_region sr USING(seq_region_id) \
LEFT JOIN coord_system cs USING(coord_system_id) \
WHERE o.stable_id is not NULL";
$select_sql = $test ? $select_sql . " limit 10" : $select_sql;
my $rows_inserted =
}
elsif ( $dbtype eq 'otherfeatures' ) {
$select_sql =
"SELECT DISTINCT o.stable_id, cs.species_id + $speciesOffset, '$dbtype', '$object_name' \
FROM $object o \
LEFT JOIN analysis a USING (analysis_id) \
LEFT JOIN seq_region sr USING(seq_region_id) \
LEFT JOIN coord_system cs USING(coord_system_id) \
WHERE logic_name like 'RefSeq_%' OR logic_name like 'CCDS_%'";
$select_sql = $test ? $select_sql . " limit 10" : $select_sql;
}
}
}
}
}