# connect to variation database
$vdb = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);
# connect to core database
$db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
# tell the variation database where to obtain core database data
$vdb->dnadb($db);
$trva = $vdb->get_TranscriptVariationAdaptor();
$vfa = $vdb->get_VariationFeatureAdaptor();
$tra = $db->get_TranscriptAdaptor();
# retrieve a TranscriptVariation by its internal identifier
$trv = $tra->fetch_by_dbID(552);
print $trv->transcript()->stable_id(), ' ',
$trv->variation_feature()->variation_name(), ' ',
$trv->consequence_type(), "\n";
# retrieve all TranscriptVariations associated with a Transcript
$tr = $tra->fetch_by_stable_id('ENST00000278995');
foreach $trv (@{$trva->fetch_all_by_Transcripts([$tr])}) {
print $trv->variation_feature->variation_name(), ' ', $trv->consequence_type(), "\n";
}
# retrieve all TranscriptVariations associated with a VariationFeature
$vf = $vfa->fetch_by_dbID(99123);
foreach $trv (@{$trva->fetch_all_by_VariationFeatures($vf)}) {
print $trva->transcript->stable_id(), ' ', $trva->consequence_type(), "\n";
}
This adaptor provides database connectivity for TranscriptVariation objects.
TranscriptVariations which represent an association between a variation and
a Transcript may be retrieved from the Ensembl variation database via several
means using this module.
sub _columns
{ return qw (tv.transcript_variation_id tv.transcript_id
tv.variation_feature_id tv.cdna_start tv.cdna_end
tv.translation_start tv.translation_end
tv.peptide_allele_string tv.consequence_type
);
}
1; } |
sub _objs_from_sth
{ my $self = shift;
my $sth = shift;
my ($trv_id, $tr_id, $vf_id, $cdna_start, $cdna_end, $tl_start, $tl_end,
$pep_allele, $consequence_type);
$sth->bind_columns(\$trv_id,\$ tr_id,\$ vf_id,\$ cdna_start,\$ cdna_end,\$
tl_start,\$ tl_end,\$ pep_allele,\$ consequence_type);
my %tr_hash;
my %vf_hash;
my @results;
while($sth->fetch()) {
my @consequences = split /,/,$consequence_type;
my $trv = Bio::EnsEMBL::Variation::TranscriptVariation->new_fast
( { 'dbID' => $trv_id,
'adaptor' => $self,
'cdna_start' => $cdna_start,
'cdna_end' => $cdna_end,
'translation_start' => $tl_start,
'translation_end' => $tl_end,
'pep_allele_string' => $pep_allele,
'consequence_type' =>\@ consequences} );
$trv->{'_vf_id'} = $vf_id; $trv->{'_transcript_id'} = $tr_id; push @results, $trv;
}
return\@ results; } |
sub fetch_all_by_Transcripts
{ my $self = shift;
my $transcript_ref = shift;
if (ref($transcript_ref) ne 'ARRAY' or ! $transcript_ref->[0]->isa('Bio::EnsEMBL::Transcript')){
throw('Array Bio::EnsEMBL::Transcript expected');
}
my %tr_by_id;
foreach my $tr (@{$transcript_ref}) {
if (!$tr->isa('Bio::EnsEMBL::Transcript')){
throw('Bio::EnsEMBL::Transcript is expected');
}
$tr_by_id{$tr->dbID()} = $tr;
}
my $instr = join (",", keys( %tr_by_id));
my $transcript_variations = $self->generic_fetch( "tv.transcript_id in ( $instr )");
for my $tv (@{$transcript_variations}){
$tv->{'transcript'} = $tr_by_id{$tv->{'_transcript_id'}};
delete $tv->{'_transcript_id'}; }
return $transcript_variations; } |
sub fetch_all_by_VariationFeatures
{ my $self = shift;
my $vf_ref = shift;
if(ref($vf_ref) ne 'ARRAY') {
throw('Array Bio::EnsEMBL::Variation::VariationFeature expected');
}
my %vf_by_id;
%vf_by_id = map {$_->dbID(), $_ } @$vf_ref;
my $instr = join (",",keys( %vf_by_id));
my $tvs = $self->generic_fetch( "tv.variation_feature_id in ( $instr )" );
for my $tv ( @$tvs ) {
$vf_by_id{ $tv->{'_vf_id'} }->add_TranscriptVariation( $tv );
delete $tv->{'_vf_id'}; }
return $tvs;
}
} |