<commit_before>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2018] 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.

=cut


=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>.

=cut

=head1 NAME

Bio::EnsEMBL::Variation::DBSQL::MotifFeatureVariationAdaptor

=head1 SYNOPSIS
    my $reg = 'Bio::EnsEMBL::Registry';
  
    $reg->load_registry_from_db(-host => 'ensembldb.ensembl.org',-user => 'anonymous');
  
    my $mfa  = $reg->get_adaptor('human', 'funcgen', 'MotifFeature');
    my $va   = $reg->get_adaptor('human', 'variation', 'Variation');
    my $vfa  = $reg->get_adaptor('human', 'variation', 'VariationFeature');
    my $mfva = $reg->get_adaptor('human','variation','MotifFeatureVariation');

    # fetch MotifFeature by dbID
    my $mf_dbID = 928174;
    my $mf      = $mfa->fetch_by_dbID($mf_dbID);

    # fetch all MotifFeatureVariations falling in the MotifFeature
    my $mfvs = $mfva->fetch_all_by_MotifFeatures([$mf]);

    # fetch by VariationFeatures
    my $variation_name = 'rs191666497';
    my $v              = $va->fetch_by_name($variation_name);
    my $vfs            = $vfa->fetch_all_by_Variation($v);
    
    # fetch all MotifFeatureVariations for the list of VariationFeatures
    $mfvs = $mfva->fetch_all_by_VariationFeatures($vfs);
     
=head1 DESCRIPTION

This adaptor allows you to fetch MotifFeatureVariation objects either by the MotifFeature
the associated VariationFeature falls in, or by VariationFeature directly. Storing
MotifFeatureVariation objects in a variation schema database is also supported. In the
database there will be a separate row for each alternative allele of a MotifFeatureVariation, 
but the methods here will fetch all alleles associated with the MotifFeatureVariation
at once.

=cut

use strict;
use warnings;

package Bio::EnsEMBL::Variation::DBSQL::MotifFeatureVariationAdaptor;

use Bio::EnsEMBL::Variation::MotifFeatureVariation;
use Bio::EnsEMBL::Variation::MotifFeatureVariationAllele;
use Bio::EnsEMBL::Utils::Exception qw(throw warning);
use Bio::EnsEMBL::Variation::Utils::Constants qw(%OVERLAP_CONSEQUENCES);
use Bio::EnsEMBL::Variation::Utils::VariationEffect qw(overlap);

use base qw(Bio::EnsEMBL::Variation::DBSQL::VariationFeatureOverlapAdaptor);

=head2 store

  Arg [1]    : Bio::EnsEMBL::Variation::MotifFeatureVariation $mfv
  Description: Store the MotifFeatureVariation in the database
  Status     : At risk

=cut

sub store {
    my ($self, $mfv) = @_;
    my $dbh = $self->dbc->db_handle;
    my $sth = $dbh->prepare_cached(q{
        INSERT DELAYED INTO motif_feature_variation (
            variation_feature_id,
            feature_stable_id,
            motif_feature_id,
            allele_string,
            somatic,
            consequence_types,
            motif_name,
            motif_start,
            motif_end,
            motif_score_delta,
            in_informative_position
        ) VALUES (?,?,?,?,?,?,?,?,?,?,?)
    });

    for my $allele (@{ $mfv->get_all_alternate_MotifFeatureVariationAlleles }) {
        $sth->execute(
            $mfv->variation_feature->dbID,
            $mfv->feature->stable_id,
            $mfv->feature->dbID,
            $allele->allele_string,
            $mfv->variation_feature->is_somatic,
            (join ',', map { $_->SO_term } @{ $allele->get_all_OverlapConsequences }),
            $mfv->feature->stable_id,
            $allele->motif_start,
            $allele->motif_end,
            $allele->motif_score_delta,
            $allele->in_informative_position,<commit_msg>use binding_matrix stable_id as motif_name<commit_after>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2018] 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.

=cut


=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>.

=cut

=head1 NAME

Bio::EnsEMBL::Variation::DBSQL::MotifFeatureVariationAdaptor

=head1 SYNOPSIS
    my $reg = 'Bio::EnsEMBL::Registry';
  
    $reg->load_registry_from_db(-host => 'ensembldb.ensembl.org',-user => 'anonymous');
  
    my $mfa  = $reg->get_adaptor('human', 'funcgen', 'MotifFeature');
    my $va   = $reg->get_adaptor('human', 'variation', 'Variation');
    my $vfa  = $reg->get_adaptor('human', 'variation', 'VariationFeature');
    my $mfva = $reg->get_adaptor('human','variation','MotifFeatureVariation');

    # fetch MotifFeature by dbID
    my $mf_dbID = 928174;
    my $mf      = $mfa->fetch_by_dbID($mf_dbID);

    # fetch all MotifFeatureVariations falling in the MotifFeature
    my $mfvs = $mfva->fetch_all_by_MotifFeatures([$mf]);

    # fetch by VariationFeatures
    my $variation_name = 'rs191666497';
    my $v              = $va->fetch_by_name($variation_name);
    my $vfs            = $vfa->fetch_all_by_Variation($v);
    
    # fetch all MotifFeatureVariations for the list of VariationFeatures
    $mfvs = $mfva->fetch_all_by_VariationFeatures($vfs);
     
=head1 DESCRIPTION

This adaptor allows you to fetch MotifFeatureVariation objects either by the MotifFeature
the associated VariationFeature falls in, or by VariationFeature directly. Storing
MotifFeatureVariation objects in a variation schema database is also supported. In the
database there will be a separate row for each alternative allele of a MotifFeatureVariation, 
but the methods here will fetch all alleles associated with the MotifFeatureVariation
at once.

=cut

use strict;
use warnings;

package Bio::EnsEMBL::Variation::DBSQL::MotifFeatureVariationAdaptor;

use Bio::EnsEMBL::Variation::MotifFeatureVariation;
use Bio::EnsEMBL::Variation::MotifFeatureVariationAllele;
use Bio::EnsEMBL::Utils::Exception qw(throw warning);
use Bio::EnsEMBL::Variation::Utils::Constants qw(%OVERLAP_CONSEQUENCES);
use Bio::EnsEMBL::Variation::Utils::VariationEffect qw(overlap);

use base qw(Bio::EnsEMBL::Variation::DBSQL::VariationFeatureOverlapAdaptor);

=head2 store

  Arg [1]    : Bio::EnsEMBL::Variation::MotifFeatureVariation $mfv
  Description: Store the MotifFeatureVariation in the database
  Status     : At risk

=cut

sub store {
    my ($self, $mfv) = @_;
    my $dbh = $self->dbc->db_handle;
    my $sth = $dbh->prepare_cached(q{
        INSERT DELAYED INTO motif_feature_variation (
            variation_feature_id,
            feature_stable_id,
            motif_feature_id,
            allele_string,
            somatic,
            consequence_types,
            motif_name,
            motif_start,
            motif_end,
            motif_score_delta,
            in_informative_position
        ) VALUES (?,?,?,?,?,?,?,?,?,?,?)
    });

    for my $allele (@{ $mfv->get_all_alternate_MotifFeatureVariationAlleles }) {
        $sth->execute(
            $mfv->variation_feature->dbID,
            $mfv->feature->stable_id,
            $mfv->feature->dbID,
            $allele->allele_string,
            $mfv->variation_feature->is_somatic,
            (join ',', map { $_->SO_term } @{ $allele->get_all_OverlapConsequences }),
            $mfv->feature->binding_matrix->stable_id,
            $allele->motif_start,
            $allele->motif_end,
            $allele->motif_score_delta,
            $allele->in_informative_position,
{'fraction_non_alphanumeric': 0.10489913544668587, 'fraction_numerical': 0.00968299711815562, 'mean_word_length': 3.6545064377682404, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 76, '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': '3140605', 'n_tokens_mistral': 2858, 'n_tokens_neox': 2698, 'n_words': 697}