my $self = shift;
my $target_cs_name = shift;
my $target = $self->target();
my $source = $self->source();
my $dbh = $self->dbh();
# target coord_system will have a different ID
$target_cs_name ||= "clone";
my $cs_id = $self->get_coord_system_id($target_cs_name);
$self->debug("CaenorhabditisBriggsae Specific:Transforming clones " .
"into $target_cs_name seq_regions");
#
# We don't want to make clones out of the WGS contigs, only out of
# the clones with proper embl accessions. Also for some reason the embl_offset
# is not set in the briggsae 17/18/19 databases, which means we have to deduce the
# length from the name of the contigs!
#
my $select_sth = $dbh->prepare
("SELECT cl.clone_id,
CONCAT(cl.embl_acc, '.', cl.embl_version),
ctg.name
FROM $source.clone cl, $source.contig ctg
WHERE cl.clone_id = ctg.clone_id
AND cl.embl_acc not like 'c%'
ORDER BY cl.clone_id");
$select_sth->execute();
my ($clone_id, $embl_acc, $ctg_name);
$select_sth->bind_columns(\$clone_id, \$embl_acc, \$ctg_name);
my $highest_end = undef;
my $current_clone = undef;
my $current_clone_id = undef;
my $length;
my $insert_sth = $dbh->prepare
("INSERT INTO $target.seq_region (name, coord_system_id, length) " .
"VALUES(?,?,?)");
my $tmp_insert_sth = $dbh->prepare
("INSERT INTO $target.tmp_cln_map (old_id, new_id) VALUES (?, ?)");
while ($select_sth->fetch()) {
#extract the end position of the contig
my $ctg_end;
(undef,undef,$ctg_end) = split(/\./, $ctg_name);
if(!defined($current_clone)) {
$current_clone = $embl_acc;
$current_clone_id = $clone_id;
$highest_end = $ctg_end;
}
if($current_clone ne $embl_acc) {
#started new clone, store last one
$insert_sth->execute($current_clone, $cs_id, $highest_end);
#store mapping of old -> new ids in temp table
$tmp_insert_sth->execute($current_clone_id, $insert_sth->{'mysql_insertid'});
$current_clone = $embl_acc;
$current_clone_id = $clone_id;
$highest_end = $ctg_end;
} elsif($ctg_end > $highest_end) {
#same clone, adjust end if end of contig is highest yet seen
$highest_end = $ctg_end;
}
}
#insert the last clone
$insert_sth->execute($current_clone, $cs_id, $highest_end);
$tmp_insert_sth->execute($current_clone_id, $insert_sth->{'mysql_insertid'});
$select_sth->finish();
$insert_sth->finish();
$tmp_insert_sth->finish();
return;
}