<commit_before>#
# Ensembl module for Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor
#
# Copyright (c) 2004 Ensembl
#
# You may distribute this module under the same terms as perl itself
#
#

=head1 NAME

Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor

=head1 SYNOPSIS

  $db = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);

  $va = $db->get_VariationAdaptor();
  $vga = $db->get_VariationGroupAdaptor();
  $pa = $db->get_PopulationAdaptor();

  # Get a Variation by its internal identifier
  $var = $va->fetch_by_dbID(145);

  # fetch a variation by its name
  $var = $va->fetch_by_name('rs100');


  # fetch all variations from a population
  $pop = $pa->fetch_by_name('PACIFIC');
  @vars = {$va->fetch_all_by_Population($pop)};

=head1 DESCRIPTION

This adaptor provides database connectivity for Variation objects.
Variations (SNPs, etc.) may be retrieved from the Ensembl variation database by
several means using this module.

=head1 AUTHOR - <NAME>

=head1 CONTACT

Post questions to the Ensembl development list <EMAIL>

=head1 METHODS

=cut

use strict;
use warnings;

package Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor;

use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use Bio::EnsEMBL::Utils::Exception qw(throw warning);

use Bio::EnsEMBL::Variation::Variation;
use Bio::EnsEMBL::Variation::Allele;

our @ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');


=head2 fetch_by_dbID

  Arg [1]    : int $dbID
  Example    : $var = $var_adaptor->fetch_by_dbID(5526);
  Description: Retrieves a Variation object via its internal identifier.
               If no such variation exists undef is returned.
  Returntype : Bio::EnsEMBL::Variation::Variation
  Exceptions : throw if dbID arg is not defined
  Caller     : general, IndividualAdaptor

=cut

sub fetch_by_dbID {
  my $self = shift;
  my $dbID = shift;

  throw('dbID argument expected') if(!defined($dbID));

  my $sth = $self->prepare
    (q{SELECT v.variation_id, v.name, v.validation_status, s1.name, v.ancestral_allele,
              a.allele_id, a.allele, a.frequency, a.sample_id, vs.moltype,
              vs.name, s2.name
       FROM   variation v, source s1, allele a LEFT JOIN 
                variation_synonym vs on v.variation_id = vs.variation_id 
              LEFT JOIN source s2 on  vs.source_id = s2.source_id
       WHERE  v.variation_id = a.variation_id
       AND    v.source_id = s1.source_id
       AND    v.variation_id = ?});
  $sth->bind_param(1,$dbID,SQL_INTEGER);
  $sth->execute();

  my $result = $self->_objs_from_sth($sth);
  $sth->finish();
  return undef if(!@$result);

  return $result->[0];
}



=head2 fetch_by_name

  Arg [1]    : string $name
  Example    : $var = $var_adaptor->fetch_by_name('rs1453','dbSNP');
  Description: Retrieves a population object via its name
  Returntype : Bio::EnsEMBL::Variation::Variation
  Exceptions : throw if name argument is not defined
  Caller     : general

=cut

sub fetch_by_name {
  my $self = shift;
  my $name = shift;
  my $source = shift;

  throw('name argument expected') if(!defined($name));
  my $extra_sql;

  if ( defined $source ) {
    $extra_sql = qq(AND    s1.name = ?);
  }

  my $sth = $self->prepare
    (qq{SELECT v.variation_id, v.name, v.validation_status, s1.name, v.ancestral_allele,<commit_msg>*** empty log message ***<commit_after>#
# Ensembl module for Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor
#
# Copyright (c) 2004 Ensembl
#
# You may distribute this module under the same terms as perl itself
#
#

=head1 NAME

Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor

=head1 SYNOPSIS

  $db = Bio::EnsEMBL::Variation::DBSQL::DBAdaptor->new(...);

  $va = $db->get_VariationAdaptor();
  $vga = $db->get_VariationGroupAdaptor();
  $pa = $db->get_PopulationAdaptor();

  # Get a Variation by its internal identifier
  $var = $va->fetch_by_dbID(145);

  # fetch a variation by its name
  $var = $va->fetch_by_name('rs100');


  # fetch all variations from a population
  $pop = $pa->fetch_by_name('PACIFIC');
  @vars = {$va->fetch_all_by_Population($pop)};

=head1 DESCRIPTION

This adaptor provides database connectivity for Variation objects.
Variations (SNPs, etc.) may be retrieved from the Ensembl variation database by
several means using this module.

=head1 AUTHOR - <NAME>

=head1 CONTACT

Post questions to the Ensembl development list <EMAIL>

=head1 METHODS

=cut

use strict;
use warnings;

package Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor;

use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use Bio::EnsEMBL::Utils::Exception qw(throw warning);

use Bio::EnsEMBL::Variation::Variation;
use Bio::EnsEMBL::Variation::Allele;

our @ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');


=head2 fetch_by_dbID

  Arg [1]    : int $dbID
  Example    : $var = $var_adaptor->fetch_by_dbID(5526);
  Description: Retrieves a Variation object via its internal identifier.
               If no such variation exists undef is returned.
  Returntype : Bio::EnsEMBL::Variation::Variation
  Exceptions : throw if dbID arg is not defined
  Caller     : general, IndividualAdaptor

=cut

sub fetch_by_dbID {
  my $self = shift;
  my $dbID = shift;

  throw('dbID argument expected') if(!defined($dbID));

  my $sth = $self->prepare
    (q{SELECT v.variation_id, v.name, v.validation_status, s1.name, v.ancestral_allele,
              a.allele_id, a.allele, a.frequency, a.sample_id, vs.moltype,
              vs.name, s2.name
       FROM   variation v, source s1, allele a LEFT JOIN 
                variation_synonym vs on v.variation_id = vs.variation_id 
              LEFT JOIN source s2 on  vs.source_id = s2.source_id
       WHERE  v.variation_id = a.variation_id
       AND    v.source_id = s1.source_id
       AND    v.variation_id = ?});
  $sth->bind_param(1,$dbID,SQL_INTEGER);
  $sth->execute();

  my $result = $self->_objs_from_sth($sth);
  $sth->finish();
  return undef if(!@$result);

  return $result->[0];
}



=head2 fetch_by_name

  Arg [1]    : string $name
  Example    : $var = $var_adaptor->fetch_by_name('rs1453','dbSNP');
  Description: Retrieves a population object via its name
  Returntype : Bio::EnsEMBL::Variation::Variation
  Exceptions : throw if name argument is not defined
  Caller     : general

=cut

sub fetch_by_name {
  my $self = shift;
  my $name = shift;
  my $source = shift;

  throw('name argument expected') if(!defined($name));
  my $extra_sql = "";

  if ( defined $source ) {
    $extra_sql = qq(AND    s1.name = ?);
  }

  my $sth = $self->prepare
    (qq{SELECT v.variation_id, v.name, v.validation_status, s1.name, v.ancestral_allele,
{'fraction_non_alphanumeric': 0.1257832798410515, 'fraction_numerical': 0.011615466911202812, 'mean_word_length': 3.858203414996288, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5008430', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2323, 'n_words': 589}