<commit_before>=head1 LICENSE

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

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor

=head1 DESCRIPTION

Base adaptor for Member objects.  This adaptor cannot be used directly.

=head1 INHERITANCE TREE

  Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor
  +- Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor

=head1 AUTHORSHIP

Ensembl Team. Individual contributions can be found in the GIT log.

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with an underscore (_)

=cut


package Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor;

use strict; 
use warnings;


use Bio::EnsEMBL::Utils::Scalar qw(:all);
use Bio::EnsEMBL::Utils::Argument qw(rearrange);
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);

use Bio::EnsEMBL::Compara::Utils::Scalar qw(:assert);

use DBI qw(:sql_types);

use base qw(Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor);




#
# GLOBAL METHODS
#
#####################


=head2 fetch_by_stable_id

  Arg [1]    : string $stable_id
  Example    : my $member = $ma->fetch_by_stable_id("O93279");
  Description: Fetches the member corresponding to this $stable_id.
               This method accepts versionned stable IDs, such as ENSG00000157764.12
  Returntype : Bio::EnsEMBL::Compara::Member object
  Exceptions : throws if $stable_id is undef
  Caller     : 

=cut

sub fetch_by_stable_id {
    my ($self, $stable_id) = @_;

    throw("MemberAdaptor::fetch_by_stable_id() must have an stable_id") unless $stable_id;

    my $constraint = 'm.stable_id = ?';
    $self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
    my $m = $self->generic_fetch_one($constraint);
    return $m if $m;

    my $vindex = rindex($stable_id, '.');
    $constraint = 'm.stable_id = ? AND m.version = ?';
    $self->bind_param_generic_fetch(substr($stable_id,0,$vindex), SQL_VARCHAR);
    $self->bind_param_generic_fetch(substr($stable_id,$vindex+1), SQL_INTEGER);
    return $self->generic_fetch_one($constraint);
}


=head2 fetch_all_by_stable_id_list

  Arg [1]    : arrayref of string $stable_id
  Example    : my $members = $ma->fetch_all_by_stable_id_list(["O93279", "O62806"]);
  Description: Fetches the members corresponding to all the $stable_id.
               This method des *not* accept versionned stable IDs (e.g. ENSG00000157764.12)
  Returntype : arrayref Bio::EnsEMBL::Compara::Member object
  Caller     : 

=cut

sub fetch_all_by_stable_id_list {
    my ($self, $stable_ids) = @_;

    # Core's method does all the type-checks for us
    return $self->SUPER::_uncached_fetch_all_by_id_list($stable_ids, undef, 'stable_id', 0);
}


=head2 fetch_all_by_source

  Arg [1]    : string $source_name
  Example    : my $members = $ma->fetch_all_by_source(
                   "Uniprot/SWISSPROT");<commit_msg>bugfix: don't break if the member is (genuinely) not found<commit_after>=head1 LICENSE

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

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor

=head1 DESCRIPTION

Base adaptor for Member objects.  This adaptor cannot be used directly.

=head1 INHERITANCE TREE

  Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor
  +- Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor

=head1 AUTHORSHIP

Ensembl Team. Individual contributions can be found in the GIT log.

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with an underscore (_)

=cut


package Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor;

use strict; 
use warnings;

use Scalar::Util qw(looks_like_number);

use Bio::EnsEMBL::Utils::Scalar qw(:all);
use Bio::EnsEMBL::Utils::Argument qw(rearrange);
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);

use Bio::EnsEMBL::Compara::Utils::Scalar qw(:assert);

use DBI qw(:sql_types);

use base qw(Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor);




#
# GLOBAL METHODS
#
#####################


=head2 fetch_by_stable_id

  Arg [1]    : string $stable_id
  Example    : my $member = $ma->fetch_by_stable_id("O93279");
  Description: Fetches the member corresponding to this $stable_id.
               This method accepts versionned stable IDs, such as ENSG00000157764.12
  Returntype : Bio::EnsEMBL::Compara::Member object
  Exceptions : throws if $stable_id is undef
  Caller     : 

=cut

sub fetch_by_stable_id {
    my ($self, $stable_id) = @_;

    throw("MemberAdaptor::fetch_by_stable_id() must have an stable_id") unless $stable_id;

    my $constraint = 'm.stable_id = ?';
    $self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
    my $m = $self->generic_fetch_one($constraint);
    return $m if $m;

    my $vindex = rindex($stable_id, '.');
    return undef if $vindex <= 0;  # bail out if there is no dot, or if the string starts with a dot (since that would make the stable_id part empty)
    my $version = substr($stable_id,$vindex+1);
    if (looks_like_number($version)) {  # to avoid DBI complains
        $constraint = 'm.stable_id = ? AND m.version = ?';
        $self->bind_param_generic_fetch(substr($stable_id,0,$vindex), SQL_VARCHAR);
        $self->bind_param_generic_fetch($version, SQL_INTEGER);
        return $self->generic_fetch_one($constraint);
    } else {
        return undef;
    }
}


=head2 fetch_all_by_stable_id_list

  Arg [1]    : arrayref of string $stable_id
  Example    : my $members = $ma->fetch_all_by_stable_id_list(["O93279", "O62806"]);
  Description: Fetches the members corresponding to all the $stable_id.
               This method des *not* accept versionned stable IDs (e.g. ENSG00000157764.12)
  Returntype : arrayref Bio::EnsEMBL::Compara::Member object
  Caller     : 

=cut

sub fetch_all_by_stable_id_list {
    my ($self, $stable_ids) = @_;

    # Core's method does all the type-checks for us
    return $self->SUPER::_uncached_fetch_all_by_id_list($stable_ids, undef, 'stable_id', 0);
}


=head2 fetch_all_by_source

  Arg [1]    : string $source_name
  Example    : my $members = $ma->fetch_all_by_source(
                   "Uniprot/SWISSPROT");
{'fraction_non_alphanumeric': 0.10728358967840346, 'fraction_numerical': 0.019702554976484047, 'mean_word_length': 4.407560137457045, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 25, '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': '2645574', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2544, 'n_words': 753}