$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);
$vga = $vdb->get_VariationGroupAdaptor();
$vgfa = $vdb->get_VariationGroupFeatureAdaptor();
$sa = $db->get_SliceAdaptor();
# Get a VariationFeature by its internal identifier
$vgf = $vgfa->fetch_by_dbID(145);
# get all VariationFeatures in a region
$slice = $sa->fetch_by_region('chromosome', 'X', 1e6, 2e6);
foreach $vgf (@{$vgfa->fetch_all_by_Slice($slice)}) {
print $vgf->start(), '-', $vgf->end(), ' ', $vgf->allele_string(), "\n";
}
# fetch all genome hits for a particular variation group
$vg = $vga->fetch_by_name('PERLEGEN:B000002');
foreach $vgf (@{$vgfa->fetch_all_by_VariationGroup($vg)}) {
print $vgf->seq_region_name(), $vgf->seq_region_start(), '-',
$vgf->seq_region_end(),"\n";
}
This adaptor provides database connectivity for VariationGroupFeature objects.
Genomic locations of VariationGroups can be obtained from the variation
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_group_feature_id, $seq_region_id, $seq_region_start,
$seq_region_end, $seq_region_strand, $variation_group_id,
$variation_group_name );
$sth->bind_columns(\$variation_group_feature_id,\$ seq_region_id,\$
seq_region_start,\$ seq_region_end,\$ seq_region_strand,\$
variation_group_id,\$ variation_group_name);
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;
}
push @features, Bio::EnsEMBL::Variation::VariationGroupFeature->new
(-start => $seq_region_start,
-end => $seq_region_end,
-strand => $seq_region_strand,
-slice => $slice,
-variation_group_name => $variation_group_name,
-variation_group_id => $variation_group_id,
-adaptor => $self,
-dbID => $variation_group_feature_id);
}
return\@ features; } |