my $self = shift;
my $source = $self->source();
my $target = $self->target();
my $dbh = $self->dbh();
#
# Turn all of the contents of the contig table into 'chunks' and
# give them arbitrary names like chunk1, chunk2. Keep old internal
# ids for conveneience.
#
$self->debug("DanioRerio Specific: creating chunk seq_regions");
my $sth = $dbh->prepare
("INSERT INTO $target.seq_region (seq_region_id, name, coord_system_id, " .
" length) ".
"SELECT ctg.contig_id, concat('chunk', ctg.contig_id), " .
" cs.coord_system_id, ctg.length " .
"FROM $source.contig ctg, $target.coord_system cs " .
"WHERE cs.name = 'chunk'");
$sth->execute();
$sth->finish();
my $insert_sth = $dbh->prepare
("INSERT INTO $target.seq_region (name, coord_system_id, length) " .
"VALUES (?,?,?)");
my $tmp_chr_insert_sth = $dbh->prepare
("INSERT INTO $target.tmp_chr_map (old_id, new_id) VALUES (?, ?)");
my $tmp_supercontig_insert_sth = $dbh->prepare
("INSERT INTO $target.tmp_superctg_map (name, new_id) VALUES (?,?)");
my $tmp_clone_insert_sth = $dbh->prepare
("INSERT INTO $target.tmp_cln_map (old_id, new_id) VALUES (?,?)");
#
# create a temporary table to hold the ids of all 'toplevel'
# seq_regions. Keep the old chromosome_id, and the new seq_region_id
#
$dbh->do
("CREATE TEMPORARY TABLE $target.tmp_toplevel_map " .
"(old_id INT, new_id INT, INDEX new_idx(new_id), INDEX old_idx(old_id))");
my $tmp_toplevel_insert_sth = $dbh->prepare
("INSERT INTO $target.tmp_toplevel_map (old_id, new_id) VALUES (?,?)");
#
# Turn real clones into clones
#
$self->debug("DanioRerio Specific: creating clone seq_regions");
my $select_sth = $dbh->prepare
("SELECT ctg.contig_id, ctg.name, ctg.length " .
"FROM $source.contig ctg " .
"WHERE ctg.name not like 'ctg%' and ctg.name not like 'NA%'");
my $cs_id = $self->get_coord_system_id('clone');
$select_sth->execute();
my ($old_id, $name, $length);
$select_sth->bind_columns(\$old_id, \$name, \$length);
while ($select_sth->fetch()) {
#insert into seq_region table
$insert_sth->execute($name, $cs_id, $length);
#copy old/new mapping into temporary table
$tmp_clone_insert_sth->execute($old_id, $insert_sth->{'mysql_insertid'});
}
$select_sth->finish();
#
# Turn real chromosomes into chromosomes
#
$self->debug("DanioRerio Specific: creating chromosome seq_regions");
$select_sth = $dbh->prepare
("SELECT chr.chromosome_id, chr.name, chr.length " .
"FROM $source.chromosome chr " .
"WHERE length(chr.name) <= 2");
$cs_id = $self->get_coord_system_id('chromosome');
$select_sth->execute();
$select_sth->bind_columns(\$old_id, \$name, \$length);
my %chr_id_added;
while ($select_sth->fetch()) {
#insert into seq_region table
$insert_sth->execute($name, $cs_id, $length);
#copy old/new mapping into temporary table
my $new_id = $insert_sth->{'mysql_insertid'};
$tmp_chr_insert_sth->execute($old_id, $new_id);
$tmp_toplevel_insert_sth->execute($old_id, $new_id);
$chr_id_added{$old_id} = 1;
}
$select_sth->finish();
#
# Turn supercontigs into supercontigs
#
$self->debug("DanioRerio Specific: creating supercontig seq_regions");
$select_sth = $dbh->prepare
("SELECT a.chromosome_id, a.superctg_name, " .
" MAX(a.chr_end) - MIN(a.chr_start) + 1 " .
"FROM $source.assembly a, $target.coord_system cs " .
"GROUP BY a.superctg_name");
$select_sth->execute();
$select_sth->bind_columns(\$old_id, \$name, \$length);
$cs_id = $self->get_coord_system_id('supercontig');
while ($select_sth->fetch()) {
#insert into seq_region table
$insert_sth->execute($name, $cs_id, $length);
#copy old/new mapping into temporary table
my $new_id = $insert_sth->{'mysql_insertid'};
$tmp_supercontig_insert_sth->execute($name,$new_id);
if(!$chr_id_added{$old_id}) {
$chr_id_added{$old_id} = 1;
$tmp_toplevel_insert_sth->execute($old_id, $new_id);
}
}
$select_sth->finish();
$tmp_chr_insert_sth->finish();
$tmp_supercontig_insert_sth->finish();
$tmp_clone_insert_sth->finish();
$tmp_toplevel_insert_sth->finish();
$insert_sth->finish();
}