<commit_before>=head1 LICENSE

Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.

  Questions may also be sent to the Ensembl help desk at
  <http://www.ensembl.org/Help/Contact>.


=head1 NAME

Bio::EnsEMBL::DBSQL::Funcgen::RegulatoryBuildAdaptor

=cut

package Bio::EnsEMBL::Funcgen::DBSQL::ReadFileExperimentalConfigurationAdaptor;

use strict;
use warnings;
use Bio::EnsEMBL::Utils::Exception qw( throw warning );
use DBI qw(:sql_types);

use base 'Bio::EnsEMBL::DBSQL::BaseAdaptor';

sub _tables {
  return (
    ['read_file_experimental_configuration', 'rfec'  ],
  );
}

sub _columns {
  my $self = shift;
  
  return qw(
      rfec.read_file_experimental_configuration_id
      rfec.read_file_id
      rfec.experiment_id
      rfec.technical_replicate
      rfec.biological_replicate
  );
}

sub _default_where_clause {
  return '';
}

sub fetch_all_by_read_file_id {
  my $self = shift;
  my $read_file_id = shift;

  my $constraint = "rfec.read_file_id = ?";
  $self->bind_param_generic_fetch($read_file_id, SQL_INTEGER);
  
  my $object_list = $self->generic_fetch($constraint);
  
  if (!$object_list || @$object_list==0) {
    return;
  }
  return $object_list;
}

sub fetch_all_by_experiment_id {
  my $self = shift;
  my $experiment_id = shift;

  my $constraint = "rfec.experiment_id = ?";
  $self->bind_param_generic_fetch($experiment_id, SQL_INTEGER);
  
  my $object_list = $self->generic_fetch($constraint);
  
  if (!$object_list || @$object_list==0) {
    return;
  }
  return $object_list;
}

sub fetch_all_by_Experiment {
  my $self = shift;
  my $experiment = shift;
  my $experiment_id = $experiment->dbID;
  return $self->fetch_all_by_experiment_id($experiment_id);
}

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

  my(
    $sth_fetched_dbID,
    $sth_fetched_read_file_id,
    $sth_fetched_technical_replicate,
    $sth_fetched_biological_replicate,
    $sth_fetched_experiment_id,
  );
  
  $sth->bind_columns (
    \$sth_fetched_dbID,
    \$sth_fetched_read_file_id,
    \$sth_fetched_experiment_id,
    \$sth_fetched_technical_replicate,
    \$sth_fetched_biological_replicate,
  );
  
  use Bio::EnsEMBL::Funcgen::ReadFileExperimentalConfiguration;
  
  my $experiment_adaptor = $self->db->get_ExperimentAdaptor();
  my $read_file_adaptor  = $self->db->get_ReadFileAdaptor();
  
  my @return_object_list;
  
  ROW: while ( $sth->fetch() ) {
  
    my $experiment = $experiment_adaptor->fetch_by_dbID($sth_fetched_experiment_id);
    my $read_file  = $read_file_adaptor->fetch_by_dbID($sth_fetched_read_file_id);

    my $current_object = Bio::EnsEMBL::Funcgen::ReadFileExperimentalConfiguration->new(
      -db                   => $self->db,
      -dbID                 => $sth_fetched_dbID,
      -read_file            => $read_file,
      -technical_replicate  => $sth_fetched_technical_replicate,
      -biological_replicate => $sth_fetched_biological_replicate,
      -experiment           => $experiment,
    );
    push @return_object_list, $current_object;
  }
  return \@return_object_list;
}

sub store {
  my ($self, @object) = @_;
  
  my $sth_store_object = $self->prepare("
    INSERT INTO read_file_experimental_configuration (
      read_file_id,
      experiment_id,
      biological_replicate,
      technical_replicate
    ) VALUES (?, ?, ?, ?)"
  );
  
  my $read_file_adaptor = $self->db->get_ReadFileAdaptor;
  
  foreach my $current_object (@object) {

    my $read_file    = $current_object->get_ReadFile;
    my $read_file_id = $read_file->dbID;
    
    if (! defined $read_file_id) {
    
      # If is has no id, then it hasn't been stored yet.
      #
      $read_file_adaptor->store($read_file);
      
      # Now it should have an id.
      $read_file_id = $read_file->dbID;
    }
    
    my $experiment = $current_object->get_Experiment;
    my $experiment_id = undef;
    
    if (! defined $experiment) {
      throw("Experiment must be set!")
    }
    
    $experiment_id = $experiment->dbID;
    
    $sth_store_object->bind_param( 1, $read_file_id,                         SQL_INTEGER);
    $sth_store_object->bind_param( 2, $experiment_id,                        SQL_INTEGER);
    $sth_store_object->bind_param( 3, $current_object->biological_replicate, SQL_INTEGER);
    $sth_store_object->bind_param( 4, $current_object->technical_replicate,  SQL_INTEGER);
    
    $sth_store_object->execute;
    $current_object->dbID( $self->last_insert_id );
  }
  return;
}

1;<commit_msg>ReadFileExperimentalConfigurationAdaptor: Switched to GenericAdaptor base<commit_after>=head1 LICENSE

Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.

  Questions may also be sent to the Ensembl help desk at
  <http://www.ensembl.org/Help/Contact>.


=head1 NAME

Bio::EnsEMBL::Funcgen::DBSQL::ReadFileExperimentalConfigurationAdaptor

=cut

package Bio::EnsEMBL::Funcgen::DBSQL::ReadFileExperimentalConfigurationAdaptor;

use strict;
use base 'Bio::EnsEMBL::Funcgen::DBSQL::GenericAdaptor';

sub object_class {
  return 'Bio::EnsEMBL::Funcgen::ReadFileExperimentalConfiguration';
}

sub _tables {
  return (
    ['read_file_experimental_configuration', 'rfec'  ],
  );
}

sub fetch_all_by_read_file_id {

  my $self = shift;
  my $read_file_id = shift;
  
  my $reads = $self->fetch_all(
    "read_file_id = " . $read_file_id
  );
  return $reads;
}

sub fetch_all_by_experiment_id {

  my $self          = shift;
  my $experiment_id = shift;
  
  my $read_file_experimental_configuration_list = $self->fetch_all(
    "experiment_id = " . $experiment_id
  );
  return $read_file_experimental_configuration_list;
}

sub fetch_all_by_Experiment {
  my $self = shift;
  my $experiment = shift;
  my $experiment_id = $experiment->dbID;
  return $self->fetch_all_by_experiment_id($experiment_id);
}

sub fetch_all_technical_replicates_by_Experiment_and_biological_replicate_number {
  my $self = shift;
  my $experiment                  = shift;
  my $biological_replicate_number = shift;
  
  my $experiment_id = $experiment->dbID;
  
  my $read_file_experimental_configuration_list = $self->fetch_all(
    "experiment_id = $experiment_id"
    . " and biological_replicate = $biological_replicate_number"
  );
  
  return $read_file_experimental_configuration_list;
}

=head2 fetch_all_biological_replicate_numbers_from_Experiment

  Convenience method

=cut
sub fetch_all_biological_replicate_numbers_from_Experiment {

  my $self       = shift;
  my $experiment = shift;
  
  my $experiment_id = $experiment->dbID;

  my @biological_replicate_numbers;

  $self->sql_helper->execute_no_return(
    -SQL          => '
      select 
        distinct biological_replicate 
      from 
        read_file_experimental_configuration 
      where 
        experiment_id = ? 
      order by 
        biological_replicate
    ',
    -PARAMS       => [ $experiment_id ],
    -USE_HASHREFS => 1,
    -CALLBACK     => sub {
        my $row = shift;
        my $biological_replicate = $row->{biological_replicate};
        push @biological_replicate_numbers, $biological_replicate;
        return;
      },
  );
  return \@biological_replicate_numbers;
}

sub count_biological_replicates_from_Experiment {

    my $self = shift;
    my $experiment = shift;
    
    my $biological_replicate_to_counts = $self->count_all(
        "experiment_id = " . $experiment->dbID,
        [ 'biological_replicate' ]
    );
    my @biological_replicates = keys %$biological_replicate_to_counts;
    return scalar @biological_replicates;
}

sub count_technical_replicates_from_Experiment {

    my $self = shift;
    my $experiment = shift;
    
    my $technical_replicate_to_counts = $self->count_all(
        "experiment_id = " . $experiment->dbID,
        [ 'technical_replicate' ]
    );
    my @technical_replicates = keys %$technical_replicate_to_counts;
    return scalar @technical_replicates;
}

1;
{'fraction_non_alphanumeric': 0.09900883430295195, 'fraction_numerical': 0.004309416074121957, 'mean_word_length': 3.69549822964087, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5566065', 'n_tokens_mistral': 3271, 'n_tokens_neox': 3132, 'n_words': 659}