<commit_before>=head1 LICENSE

Copyright [2009-2015] 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

package Bio::EnsEMBL::Production::Pipeline::Xrefs::Mapping;

use strict;
use warnings;

use XrefMapper::BasicMapper;
use XrefMapper::ProcessMappings;
use XrefMapper::ProcessPrioritys;
use XrefMapper::ProcessPaired;
use XrefMapper::CoreInfo;
use XrefMapper::TestMappings;
use XrefMapper::XrefLoader;
use XrefMapper::DisplayXrefs;
use XrefMapper::CoordinateMapper;
use XrefMapper::UniParcMapper;
use XrefMapper::RNACentralMapper;
use XrefMapper::OfficialNaming;
use XrefMapper::DirectXrefs;
use XrefMapper::db;
use File::Path qw/make_path/;

use parent qw/Bio::EnsEMBL::Production::Pipeline::Common::Base/;


sub run {
  my ($self) = @_;
  my $xref_url     = $self->param_required('xref_url');
  my $species      = $self->param_required('species');
  my $base_path    = $self->param_required('base_path');
  my $source_url   = $self->param_required('source_url');

  my $parsed_url = Bio::EnsEMBL::Hive::Utils::URL::parse($xref_url);
  my $user   = $parsed_url->{'user'};
  my $pass   = $parsed_url->{'pass'};
  my $host   = $parsed_url->{'host'};
  my $port   = $parsed_url->{'port'};
  my $dbname = $parsed_url->{'dbname'};

  my $registry = 'Bio::EnsEMBL::Registry';
  my $core_adaptor = $registry->get_DBAdaptor($species, 'Core');
  my $core_dbc = $core_adaptor->dbc;
  my $core_db = XrefMapper::db->new(
    -host    => $core_dbc->host,
    -dbname  => $core_dbc->dbname,
    -port    => $core_dbc->port,
    -user    => $core_dbc->user,
    -pass    => $core_dbc->pass
  );
  $core_db->dir($base_path);
  $core_db->species($species);
  my $full_path = File::Spec->catfile($base_path, $species, 'ensembl');
  make_path($full_path);
  my $cdna_path = File::Spec->catfile($full_path, 'transcripts.fa');
  my $pep_path  = File::Spec->catfile($full_path, 'peptides.fa');
  $core_db->dna_file($cdna_path);
  $core_db->protein_file($pep_path);

  my $xref_db = XrefMapper::db->new(
    -host    => $host,
    -dbname  => $dbname,
    -port    => $port,
    -user    => $user,
    -pass    => $pass
  );

  # Look for species-specific mapper
  my $module;
  my $class = "XrefMapper/$species.pm";
  my $eval_test = eval { require $class; };
  if ($eval_test == 1) {
    $module = "XrefMapper::$species";
  } else {
    $module = "XrefMapper::BasicMapper";
  }
  my $mapper = $module->new();
  $mapper->xref($xref_db);
  $mapper->add_meta_pair("xref", $host.":".$dbname);
  $mapper->core($core_db);
  $mapper->add_meta_pair("species", $host.":".$dbname);

  my $core_info = XrefMapper::CoreInfo->new($mapper);<commit_msg>some tidying up<commit_after>=head1 LICENSE

Copyright [2009-2015] 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

package Bio::EnsEMBL::Production::Pipeline::Xrefs::Mapping;

use strict;
use warnings;

use XrefMapper::BasicMapper;
use XrefMapper::ProcessMappings;
use XrefMapper::ProcessPrioritys;
use XrefMapper::ProcessPaired;
use XrefMapper::CoreInfo;
use XrefMapper::TestMappings;
use XrefMapper::XrefLoader;
use XrefMapper::DisplayXrefs;
use XrefMapper::CoordinateMapper;
use XrefMapper::UniParcMapper;
use XrefMapper::RNACentralMapper;
use XrefMapper::OfficialNaming;
use XrefMapper::DirectXrefs;
use XrefMapper::db;

use parent qw/Bio::EnsEMBL::Production::Pipeline::Xrefs::Base/;


sub run {
  my ($self) = @_;
  my $xref_url     = $self->param_required('xref_url');
  my $species      = $self->param_required('species');
  my $base_path    = $self->param_required('base_path');
  my $source_url   = $self->param_required('source_url');

  my ($user, $pass, $host, $port, $dbname) = $self->parse_url($xref_url);

  my $registry = 'Bio::EnsEMBL::Registry';
  my $core_adaptor = $registry->get_DBAdaptor($species, 'Core');
  my $core_dbc = $core_adaptor->dbc;
  my $core_db = XrefMapper::db->new(
    -host    => $core_dbc->host,
    -dbname  => $core_dbc->dbname,
    -port    => $core_dbc->port,
    -user    => $core_dbc->user,
    -pass    => $core_dbc->pass
  );
  $core_db->dir($base_path);
  $core_db->species($species);
  my $cdna_path = $self->get_path($species, $base_path, 'transcripts.fa');
  my $pep_path = $self->get_path($species, $base_path, 'peptides.fa');
  $core_db->dna_file($cdna_path);
  $core_db->protein_file($pep_path);

  my $xref_db = XrefMapper::db->new(
    -host    => $host,
    -dbname  => $dbname,
    -port    => $port,
    -user    => $user,
    -pass    => $pass
  );

  # Look for species-specific mapper
  my $module = 'XrefMapper::BasicMapper';;
  my $class = "XrefMapper/$species.pm";
  my $eval_test = eval { require $class; };
  if (defined $eval_test) {
    $module = "XrefMapper::$species" if $eval_test == 1;
  }

  my $mapper = $module->new();
  $mapper->xref($xref_db);
  $mapper->add_meta_pair("xref", $host.":".$dbname);
  $mapper->core($core_db);
  $mapper->add_meta_pair("species", $host.":".$dbname);

  my $core_info = XrefMapper::CoreInfo->new($mapper);
{'fraction_non_alphanumeric': 0.15674138507862162, 'fraction_numerical': 0.00468384074941452, 'mean_word_length': 4.645892351274788, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5213908', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2100, 'n_words': 480}