my $old_adaptor = shift;
my $new_adaptor = shift;
my $feature_type = shift;
my $chr = shift;
my $new_va = shift;
$support->log_stamped("fetching $feature_type mappings for chromosome $chr\n",1);
#get all genes on the chromosome from the old database
my $old_slice = $old_sa->fetch_by_region('chromosome', $chr, undef, undef,
undef, $support->param('altassembly'));
# get a slice on the old assembly from the new database
my $newdb_oldasm_chr = $new_sa->fetch_by_region('chromosome', $chr, undef, undef,
undef, $support->param('altassembly'));
my @old_features = @{$old_adaptor->fetch_all_by_Slice($old_slice)};
foreach my $old_feature (@old_features) {
my $feature_name;
if ($feature_type eq 'gene') {
$feature_name = $old_feature->stable_id;
} elsif ($feature_type eq 'SNP') {
$feature_name = $old_feature->variation_name;
}
$support->log_verbose("$feature_type $feature_name location in old db: " . $old_feature->start . ":" . $old_feature->end . ":" . $old_feature->strand . " chromosome $chr\n",1);
if ($old_feature->length == 0) {
next;
}
-start => $old_feature->start,
-end => $old_feature->end,
-strand => $old_feature->strand,
-seq_region_name => $chr,
-seq_region_length => $old_feature->length,
-adaptor => $new_sa);
my $mapping_start = $newdb_oldasm_chr->
end;
my ($mapping_end, $mapping_length, $mapping_strands, $mapping_chrs, $mapping);
($mapping_start, $mapping_end, $mapping_length, $mapping_strands,$mapping_chrs, $mapping) =
map_slice($newdb_old_asm_slice, $mapping_start);
#get the feature from the new db
my $new_feature;
if ($feature_type eq 'gene') {
$new_feature = $new_adaptor->fetch_by_stable_id($feature_name);
} elsif ($feature_type eq 'SNP') {
my $variation = $new_va->fetch_by_name($feature_name);
if ($variation) {
my @new_features = @{$new_adaptor->fetch_all_by_Variation($variation)};
foreach my $vf (@new_features) {
if ($vf->allele_string eq $old_feature->allele_string) {
$new_feature = $vf;
}
}
}
}
my $new_feature_found = 0;
my ($new_chr,$new_start,$new_end,$new_length,$new_strand);
if (defined($new_feature) ) {
$new_chr = $new_feature->slice->seq_region_name;
$new_start = $new_feature->start;
$new_end = $new_feature->end;
$new_strand = $new_feature->strand;
$new_length = $new_feature->end - $new_feature->start + 1;
$new_feature_found = 1;
$support->log_verbose("$feature_type $feature_name found in the new db; location:$new_start:$new_end:$new_strand chromosome $new_chr\n",1);
} else {
$support->log_verbose("$feature_type $feature_name not found in the new db; can't compare $feature_type location to mapped location\n",1);
}
#store mapping in the db
if ( !$support->param('dry_run') ) {
$sth->execute($feature_type,$feature_name,$support->param('altassembly'),$chr,$old_feature->start, $old_feature->end, $old_feature->end - $old_feature->start + 1, $old_feature->strand, $new_feature_found, $new_chr, $new_start, $new_end,$new_length, $new_strand, $support->param('assembly'), $mapping, $mapping_start, $mapping_end, $mapping_length, $mapping_strands, $mapping_chrs );
}
}
}