<commit_before>#
# BioPerl module for Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor
#
# Cared for by <NAME> <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor - Adaptor for DnaAlignFeatures

=head1 SYNOPSIS

    $dafa = $dbadaptor->get_DnaAlignFeatureAdaptor();

    @feature_array = $dafa->fetch_by_Contig($contig);

    $dafa->store(@feature_array);

=head1 DESCRIPTION


This is an adaptor for DNA features on DNA sequence. Like other
feature getting adaptors it has a number of fetch_ functions and a
store function. This adaptor inherits most of its functionality from
its BaseAlignFeatureAdaptor superclass.


=head1 AUTHOR - <NAME>

Email <EMAIL>

Describe contact details here

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor;
use vars qw(@ISA);
use strict;

# Object preamble - inherits from Bio::EnsEMBL::Root

use Bio::EnsEMBL::DnaDnaAlignFeature;
use Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;

@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor);


=head2 _tablename

  Args       : none
  Example    : $tablename = $self->_tablename 
  Description: PROTECTED implementation of the abstract method inherited from
               BaseFeatureAdaptor.  Returns the name of the table 
               DnaAlignFeatures are created from.
  Returntype : string
  Exceptions : none
  Caller     : Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor::generic_fetch

=cut

sub _tablename {
  my $self = shift;

  return "dna_align_feature";
}


=head2 _columns

  Args       : none
  Example    : @columns = $self->_columns
  Description: PROTECTED implementation of abstract superclass method.  
               Returns a list of columns that are needed for object creation.
  Returntype : list of strings
  Exceptions : none
  Caller     : Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor::generic_fetch

=cut

sub _columns {
  my $self = shift;

  #warning, implementation of _objs_from_sth method depends on order of list
  return qw(dna_align_feature_id contig_id analysis_id contig_start 
	    contig_end contig_strand hit_start hit_end hit_name hit_strand
	    cigar_line evalue perc_ident score);
}


=head2 store

  Arg [1]    : int $contig_id 
               the id of the contig to be stored in the database
  Arg [2]    : list of Bio::EnsEMBL::DnaAlignFeatures @sf
               the features to store in the database
  Example    : $dna_align_feature_adaptor->store($contig_id, @features);
  Description: Stores a list of DnaAlignFeatures in the database
  Returntype : none
  Exceptions : thrown if $contig_id is not an int, or if any of the
               features in the database are not storable 
  Caller     : ?

=cut

sub store {
  my ($self, @sf) = @_;
  my $tablename = $self->_tablename();
  
  if( scalar(@sf) == 0 ) {
    $self->throw("Must call store with sequence features");
  }
  
  my $sth = $self->prepare("
     INSERT INTO $tablename (contig_id, contig_start, contig_end,
                             contig_strand, hit_start, hit_end,
                             hit_strand, hit_name, cigar_line,
                             analysis_id, score, evalue, perc_ident) 
     VALUES (?,?,?,?,?,?,?,?,?,?,?, ?, ?)");

  foreach my $sf ( @sf ) {
    if( !ref $sf || !$sf->isa("Bio::EnsEMBL::DnaDnaAlignFeature") ) {
      $self->throw("feature must be a Bio::EnsEMBL::DnaDnaAlignFeature," 
		    . " not a [$sf]");
    }
    
    my $contig = $sf->entire_seq();
    unless(defined $contig && $contig->isa("Bio::EnsEMBL::RawContig")) {
      $self->throw("A contig must be attached to the features to be " .
		   "stored via the attach seq method\n");
    }

    if( !defined $sf->analysis ) {
      $self->throw("Cannot store sequence features without analysis");
    }

    if( !defined $sf->analysis->dbID ) {
      # maybe we should throw here. 
      # Shouldn't we always have an analysis from the database?
      $self->throw("I think we should always have an analysis object which " .
		 "has originated from the database. No dbID, not putting in!");
    }

    $sth->execute( $contig->dbID(), $sf->start, $sf->end, $sf->strand,
		   $sf->hstart, $sf->hend, $sf->hstrand, $sf->hseqname,
		   $sf->cigar_string, $sf->analysis->dbID, $sf->score, 
		   $sf->p_value, $sf->percent_id);
    $sf->dbID($sth->{'mysql_insertid'});
  }
}


=head2 _objs_from_sth

  Arg [1]    : DBI statement handle $sth
               an exectuted DBI statement handle generated by selecting 
               the columns specified by _columns() from the table specified 
               by _table()
  Example    : @dna_dna_align_feats = $self->_obj_from_hashref
  Description: PROTECTED implementation of superclass abstract method. 
               Creates DnaDnaAlignFeature objects from a DBI hashref
  Returntype : listref of Bio::EnsEMBL::DnaDnaAlignFeatures
  Exceptions : none
  Caller     : Bio::EnsEMBL::BaseFeatureAdaptor::generic_fetch

=cut

sub _objs_from_sth {
  my ($self, $sth, $mapper, $slice) = @_;

  my ($dna_align_feature_id, $contig_id, $analysis_id, $contig_start, 
      $contig_end, $contig_strand, $hit_start, $hit_end, $hit_name, 
      $hit_strand, $cigar_line, $evalue, $perc_ident, $score);
  
  my $rca = $self->db()->get_RawContigAdaptor();
  my $aa = $self->db()->get_AnalysisAdaptor();
  
  my ($analysis, $contig);
  my @features;

  my %a_hash;

  my ($row, $row_cache);

  my $row_cache = $sth->fetchall_arrayref();

  if($slice) {
    my ($chr, $start, $end, $strand);
    my $slice_start = $slice->chr_start() - 1;
    my $slice_name = $slice->name();
    
    while($row = shift @$row_cache) {
      ($dna_align_feature_id, $contig_id, $analysis_id, $contig_start, 
       $contig_end, $contig_strand, $hit_start, $hit_end, $hit_name, 
       $hit_strand, $cigar_line, $evalue, $perc_ident, $score) = @$row;

      $analysis = $a_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id);
      
      ($chr, $start, $end, $strand) = 
	$mapper->fast_to_assembly($contig_id, $contig_start, 
				  $contig_end, $contig_strand);
      
      unless(defined $start) {
	next;
      }

      push @features, Bio::EnsEMBL::DnaDnaAlignFeature->new_fast(
                    {'_gsf_tag_hash'  =>  {},
		     '_gsf_sub_array' =>  [],
		     '_parse_h'       =>  {},
		     '_analysis'      =>  $analysis,
		     '_gsf_start'     =>  $start - $slice_start,
		     '_gsf_end'       =>  $end - $slice_start,
		     '_gsf_strand'    =>  $strand,
		     '_gsf_score'     =>  $score,<commit_msg>Removing a my declaration that was masking an earlier declaration in the same scope.<commit_after>#
# BioPerl module for Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor
#
# Cared for by <NAME> <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor - Adaptor for DnaAlignFeatures

=head1 SYNOPSIS

    $dafa = $dbadaptor->get_DnaAlignFeatureAdaptor();

    @feature_array = $dafa->fetch_by_Contig($contig);

    $dafa->store(@feature_array);

=head1 DESCRIPTION


This is an adaptor for DNA features on DNA sequence. Like other
feature getting adaptors it has a number of fetch_ functions and a
store function. This adaptor inherits most of its functionality from
its BaseAlignFeatureAdaptor superclass.


=head1 AUTHOR - <NAME>

Email <EMAIL>

Describe contact details here

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor;
use vars qw(@ISA);
use strict;

# Object preamble - inherits from Bio::EnsEMBL::Root

use Bio::EnsEMBL::DnaDnaAlignFeature;
use Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;

@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor);


=head2 _tablename

  Args       : none
  Example    : $tablename = $self->_tablename 
  Description: PROTECTED implementation of the abstract method inherited from
               BaseFeatureAdaptor.  Returns the name of the table 
               DnaAlignFeatures are created from.
  Returntype : string
  Exceptions : none
  Caller     : Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor::generic_fetch

=cut

sub _tablename {
  my $self = shift;

  return "dna_align_feature";
}


=head2 _columns

  Args       : none
  Example    : @columns = $self->_columns
  Description: PROTECTED implementation of abstract superclass method.  
               Returns a list of columns that are needed for object creation.
  Returntype : list of strings
  Exceptions : none
  Caller     : Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor::generic_fetch

=cut

sub _columns {
  my $self = shift;

  #warning, implementation of _objs_from_sth method depends on order of list
  return qw(dna_align_feature_id contig_id analysis_id contig_start 
	    contig_end contig_strand hit_start hit_end hit_name hit_strand
	    cigar_line evalue perc_ident score);
}


=head2 store

  Arg [1]    : int $contig_id 
               the id of the contig to be stored in the database
  Arg [2]    : list of Bio::EnsEMBL::DnaAlignFeatures @sf
               the features to store in the database
  Example    : $dna_align_feature_adaptor->store($contig_id, @features);
  Description: Stores a list of DnaAlignFeatures in the database
  Returntype : none
  Exceptions : thrown if $contig_id is not an int, or if any of the
               features in the database are not storable 
  Caller     : ?

=cut

sub store {
  my ($self, @sf) = @_;
  my $tablename = $self->_tablename();
  
  if( scalar(@sf) == 0 ) {
    $self->throw("Must call store with sequence features");
  }
  
  my $sth = $self->prepare("
     INSERT INTO $tablename (contig_id, contig_start, contig_end,
                             contig_strand, hit_start, hit_end,
                             hit_strand, hit_name, cigar_line,
                             analysis_id, score, evalue, perc_ident) 
     VALUES (?,?,?,?,?,?,?,?,?,?,?, ?, ?)");

  foreach my $sf ( @sf ) {
    if( !ref $sf || !$sf->isa("Bio::EnsEMBL::DnaDnaAlignFeature") ) {
      $self->throw("feature must be a Bio::EnsEMBL::DnaDnaAlignFeature," 
		    . " not a [$sf]");
    }
    
    my $contig = $sf->entire_seq();
    unless(defined $contig && $contig->isa("Bio::EnsEMBL::RawContig")) {
      $self->throw("A contig must be attached to the features to be " .
		   "stored via the attach seq method\n");
    }

    if( !defined $sf->analysis ) {
      $self->throw("Cannot store sequence features without analysis");
    }

    if( !defined $sf->analysis->dbID ) {
      # maybe we should throw here. 
      # Shouldn't we always have an analysis from the database?
      $self->throw("I think we should always have an analysis object which " .
		 "has originated from the database. No dbID, not putting in!");
    }

    $sth->execute( $contig->dbID(), $sf->start, $sf->end, $sf->strand,
		   $sf->hstart, $sf->hend, $sf->hstrand, $sf->hseqname,
		   $sf->cigar_string, $sf->analysis->dbID, $sf->score, 
		   $sf->p_value, $sf->percent_id);
    $sf->dbID($sth->{'mysql_insertid'});
  }
}


=head2 _objs_from_sth

  Arg [1]    : DBI statement handle $sth
               an exectuted DBI statement handle generated by selecting 
               the columns specified by _columns() from the table specified 
               by _table()
  Example    : @dna_dna_align_feats = $self->_obj_from_hashref
  Description: PROTECTED implementation of superclass abstract method. 
               Creates DnaDnaAlignFeature objects from a DBI hashref
  Returntype : listref of Bio::EnsEMBL::DnaDnaAlignFeatures
  Exceptions : none
  Caller     : Bio::EnsEMBL::BaseFeatureAdaptor::generic_fetch

=cut

sub _objs_from_sth {
  my ($self, $sth, $mapper, $slice) = @_;

  my ($dna_align_feature_id, $contig_id, $analysis_id, $contig_start, 
      $contig_end, $contig_strand, $hit_start, $hit_end, $hit_name, 
      $hit_strand, $cigar_line, $evalue, $perc_ident, $score);
  
  my $rca = $self->db()->get_RawContigAdaptor();
  my $aa = $self->db()->get_AnalysisAdaptor();
  
  my ($analysis, $contig);
  my @features;

  my %a_hash;

  my ($row, $row_cache);

  $row_cache = $sth->fetchall_arrayref();

  if($slice) {
    my ($chr, $start, $end, $strand);
    my $slice_start = $slice->chr_start() - 1;
    my $slice_name = $slice->name();
    
    while($row = shift @$row_cache) {
      ($dna_align_feature_id, $contig_id, $analysis_id, $contig_start, 
       $contig_end, $contig_strand, $hit_start, $hit_end, $hit_name, 
       $hit_strand, $cigar_line, $evalue, $perc_ident, $score) = @$row;

      $analysis = $a_hash{$analysis_id} ||= $aa->fetch_by_dbID($analysis_id);
      
      ($chr, $start, $end, $strand) = 
	$mapper->fast_to_assembly($contig_id, $contig_start, 
				  $contig_end, $contig_strand);
      
      unless(defined $start) {
	next;
      }

      push @features, Bio::EnsEMBL::DnaDnaAlignFeature->new_fast(
                    {'_gsf_tag_hash'  =>  {},
		     '_gsf_sub_array' =>  [],
		     '_parse_h'       =>  {},
		     '_analysis'      =>  $analysis,
		     '_gsf_start'     =>  $start - $slice_start,
		     '_gsf_end'       =>  $end - $slice_start,
		     '_gsf_strand'    =>  $strand,
		     '_gsf_score'     =>  $score,
{'fraction_non_alphanumeric': 0.11899837494460039, 'fraction_numerical': 0.002068252326783868, 'mean_word_length': 3.160725261216964, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 125, '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': '6883248', 'n_tokens_mistral': 4815, 'n_tokens_neox': 4523, 'n_words': 1209}