$vdb = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);
$db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
# tell the variation database where core database information can be
# be found
$vdb->dnadb($db);
$va = $vdb->get_VariationAdaptor();
$vfa = $vdb->get_VariationFeatureAdaptor();
$sa = $db->get_SliceAdaptor();
# Get a VariationFeature by its internal identifier
$vf = $va->fetch_by_dbID(145);
# get all VariationFeatures in a region
$slice = $sa->fetch_by_region('chromosome', 'X', 1e6, 2e6);
foreach $vf (@{$vfa->fetch_all_by_Slice($slice)}) {
print $vf->start(), '-', $vf->end(), ' ', $vf->allele_string(), "\n";
}
# fetch all genome hits for a particular variation
$v = $va->fetch_by_name('rs56');
foreach $vf (@{$vfa->fetch_all_by_Variation($v)}) {
print $vf->seq_region_name(), $vf->seq_region_start(), '-',
$vf->seq_region_end(),"\n";
}
This adaptor provides database connectivity for VariationFeature objects.
Genomic locations of variations can be obtained from the database using this
adaptor. See the base class BaseFeatureAdaptor for more information.
sub _objs_from_sth
{ my ($self, $sth, $mapper, $dest_slice) = @_;
my $sa = $self->db()->dnadb()->get_SliceAdaptor();
my @features;
my %slice_hash;
my %sr_name_hash;
my %sr_cs_hash;
my ($variation_feature_id, $seq_region_id, $seq_region_start,
$seq_region_end, $seq_region_strand, $variation_id,
$allele_string, $variation_name, $map_weight, $source_name, $validation_status, $consequence_type );
$sth->bind_columns(\$variation_feature_id,\$ seq_region_id,\$
seq_region_start,\$ seq_region_end,\$ seq_region_strand,\$
variation_id,\$ allele_string,\$ variation_name,\$
map_weight,\$ source_name,\$ validation_status,\$ consequence_type);
my $asm_cs;
my $cmp_cs;
my $asm_cs_vers;
my $asm_cs_name;
my $cmp_cs_vers;
my $cmp_cs_name;
if($mapper) {
$asm_cs = $mapper->assembled_CoordSystem();
$cmp_cs = $mapper->component_CoordSystem();
$asm_cs_name = $asm_cs->name();
$asm_cs_vers = $asm_cs->version();
$cmp_cs_name = $cmp_cs->name();
$cmp_cs_vers = $cmp_cs->version();
}
my $dest_slice_start;
my $dest_slice_end;
my $dest_slice_strand;
my $dest_slice_length;
if($dest_slice) {
$dest_slice_start = $dest_slice->start();
$dest_slice_end = $dest_slice->end();
$dest_slice_strand = $dest_slice->strand();
$dest_slice_length = $dest_slice->length();
}
FEATURE: while($sth->fetch()) {
my $slice = $slice_hash{"ID:".$seq_region_id};
if(!$slice) {
$slice = $sa->fetch_by_seq_region_id($seq_region_id);
$slice_hash{"ID:".$seq_region_id} = $slice;
$sr_name_hash{$seq_region_id} = $slice->seq_region_name();
$sr_cs_hash{$seq_region_id} = $slice->coord_system();
}
if($mapper) {
my $sr_name = $sr_name_hash{$seq_region_id};
my $sr_cs = $sr_cs_hash{$seq_region_id};
($sr_name,$seq_region_start,$seq_region_end,$seq_region_strand) =
$mapper->fastmap($sr_name, $seq_region_start, $seq_region_end,
$seq_region_strand, $sr_cs);
next FEATURE if(!defined($sr_name));
if($asm_cs == $sr_cs || ($cmp_cs != $sr_cs && $asm_cs->equals($sr_cs))) {
$slice = $slice_hash{"NAME:$sr_name:$cmp_cs_name:$cmp_cs_vers"} ||=
$sa->fetch_by_region($cmp_cs_name, $sr_name,undef, undef, undef,
$cmp_cs_vers);
} else {
$slice = $slice_hash{"NAME:$sr_name:$asm_cs_name:$asm_cs_vers"} ||=
$sa->fetch_by_region($asm_cs_name, $sr_name, undef, undef, undef,
$asm_cs_vers);
}
}
if($dest_slice) {
if($dest_slice_start != 1 || $dest_slice_strand != 1) {
if($dest_slice_strand == 1) {
$seq_region_start = $seq_region_start - $dest_slice_start + 1;
$seq_region_end = $seq_region_end - $dest_slice_start + 1;
} else {
my $tmp_seq_region_start = $seq_region_start;
$seq_region_start = $dest_slice_end - $seq_region_end + 1;
$seq_region_end = $dest_slice_end - $tmp_seq_region_start + 1;
$seq_region_strand *= -1;
}
if($seq_region_end < 1 || $seq_region_start > $dest_slice_length) {
next FEATURE;
}
}
$slice = $dest_slice;
}
$validation_status = 0 if (!defined $validation_status);
my @states = split(',',$validation_status);
my @types = split(',',$consequence_type);
push @features, $self->_create_feature_fast('Bio::EnsEMBL::Variation::VariationFeature',
{'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'slice' => $slice,
'allele_string' => $allele_string,
'variation_name' => $variation_name,
'adaptor' => $self,
'dbID' => $variation_feature_id,
'map_weight' => $map_weight,
'source' => $source_name,
'validation_code' =>\@ states,
'consequence_type' =>\@ types || 'INTERGENIC',
'_variation_id' => $variation_id});
}
return\@ features; } |