<commit_before>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2019] 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 XrefParser::DBASSParser;

use strict;
use warnings;

use DBI;
use Carp;

use parent qw( XrefParser::BaseParser );

# This parser will read direct xrefs from a simple comma-delimited file downloaded from the DBASS database.
# The columns of the file should be the following:
#
# 1)    DBASS Gene ID
# 2)    DBASS Gene Name
# 3)    Ensembl Gene ID


sub run {
  my ( $self, $ref_arg ) = @_;
  my $source_id  = $ref_arg->{source_id};
  my $species_id = $ref_arg->{species_id};
  my $files      = $ref_arg->{files};
  my $verbose    = $ref_arg->{verbose};
  my $dbi        = $ref_arg->{dbi};
  $dbi = $self->dbi unless defined $dbi;

  if ( ( !defined $source_id ) or
       ( !defined $species_id ) or
       ( !defined $files ) )
  {
    croak "Need to pass source_id, species_id and files as pairs";
  }
  $verbose |= 0;

  my $filename = @{$files}[0];

  my $file_io = $self->get_filehandle($filename);
  if ( !defined($file_io) ) {
    return 1;
  }

  my $parsed_count = 0;

  $file_io->getline();

  while ( defined( my $line = $file_io->getline() ) ) {

    $line =~ s/\s*$//x;
    # csv format can come with quoted columns, remove them
    $line =~ s/"//gx;

    my ( $dbass_gene_id, $dbass_gene_name, $ensembl_id ) =
      split( /,/x, $line );

    if ( !defined($dbass_gene_id) || !defined($ensembl_id) ) {
      printf STDERR ( "Line %d contains  has less than two columns.\n",
                      1 + $parsed_count );
      print STDERR ("The parsing failed\n");
      return 1;
    }

    my $first_gene_name = $dbass_gene_name;
    my $second_gene_name;

    if ( $dbass_gene_name =~ /.\/./x ) {
      ( $first_gene_name, $second_gene_name ) =
        split( /\//x, $dbass_gene_name );
    }

    if ( $dbass_gene_name =~ /(.*)\((.*)\)/x ) {
      $first_gene_name  = $1;
      $second_gene_name = $2;
#      print $first_gene_name, "\n", $second_gene_name, "\n" if($verbose);
    }

    my $label       = $first_gene_name;
    my $type        = 'gene';
    my $version     = '1';
    my $synonym     = $second_gene_name;

    ++$parsed_count;

    my $xref_id =
      $self->get_xref( $dbass_gene_id, $source_id, $species_id, $dbi );

    if ( !defined($xref_id) || $xref_id eq '' ) {
      $xref_id = $self->add_xref(
                                  { acc        => $dbass_gene_id,
                                    version    => $version,
                                    label      => $label,
                                    desc       => undef,
                                    source_id  => $source_id,
                                    dbi        => $dbi,
                                    species_id => $species_id,
                                    info_type  => "DIRECT" } );
    }

    $self->add_direct_xref( $xref_id, $ensembl_id, $type, undef, $dbi );

    if ( defined($synonym) ) {
      $self->add_synonym( $xref_id, $synonym, $dbi );
    }

  } ## end while ( defined( my $line...))

  printf( "%d direct xrefs succesfully parsed\n", $parsed_count )
    if ($verbose);

  $file_io->close();

  return 0;
} ## end sub run


1;
<commit_msg>DBASSParser: fix error message<commit_after>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2019] 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 XrefParser::DBASSParser;

use strict;
use warnings;

use DBI;
use Carp;

use parent qw( XrefParser::BaseParser );

# This parser will read direct xrefs from a simple comma-delimited file downloaded from the DBASS database.
# The columns of the file should be the following:
#
# 1)    DBASS Gene ID
# 2)    DBASS Gene Name
# 3)    Ensembl Gene ID


sub run {
  my ( $self, $ref_arg ) = @_;
  my $source_id  = $ref_arg->{source_id};
  my $species_id = $ref_arg->{species_id};
  my $files      = $ref_arg->{files};
  my $verbose    = $ref_arg->{verbose};
  my $dbi        = $ref_arg->{dbi};
  $dbi = $self->dbi unless defined $dbi;

  if ( ( !defined $source_id ) or
       ( !defined $species_id ) or
       ( !defined $files ) )
  {
    croak "Need to pass source_id, species_id and files as pairs";
  }
  $verbose |= 0;

  my $filename = @{$files}[0];

  my $file_io = $self->get_filehandle($filename);
  if ( !defined($file_io) ) {
    return 1;
  }

  my $parsed_count = 0;

  $file_io->getline();

  while ( defined( my $line = $file_io->getline() ) ) {

    $line =~ s/\s*$//x;
    # csv format can come with quoted columns, remove them
    $line =~ s/"//gx;

    my ( $dbass_gene_id, $dbass_gene_name, $ensembl_id ) =
      split( /,/x, $line );

    if ( !defined($dbass_gene_id) || !defined($ensembl_id) ) {
      printf STDERR ( "Line %d has fewer than three columns.\n",
                      1 + $parsed_count );
      print STDERR ("The parsing failed\n");
      return 1;
    }

    my $first_gene_name = $dbass_gene_name;
    my $second_gene_name;

    if ( $dbass_gene_name =~ /.\/./x ) {
      ( $first_gene_name, $second_gene_name ) =
        split( /\//x, $dbass_gene_name );
    }

    if ( $dbass_gene_name =~ /(.*)\((.*)\)/x ) {
      $first_gene_name  = $1;
      $second_gene_name = $2;
#      print $first_gene_name, "\n", $second_gene_name, "\n" if($verbose);
    }

    my $label       = $first_gene_name;
    my $type        = 'gene';
    my $version     = '1';
    my $synonym     = $second_gene_name;

    ++$parsed_count;

    my $xref_id =
      $self->get_xref( $dbass_gene_id, $source_id, $species_id, $dbi );

    if ( !defined($xref_id) || $xref_id eq '' ) {
      $xref_id = $self->add_xref(
                                  { acc        => $dbass_gene_id,
                                    version    => $version,
                                    label      => $label,
                                    desc       => undef,
                                    source_id  => $source_id,
                                    dbi        => $dbi,
                                    species_id => $species_id,
                                    info_type  => "DIRECT" } );
    }

    $self->add_direct_xref( $xref_id, $ensembl_id, $type, undef, $dbi );

    if ( defined($synonym) ) {
      $self->add_synonym( $xref_id, $synonym, $dbi );
    }

  } ## end while ( defined( my $line...))

  printf( "%d direct xrefs succesfully parsed\n", $parsed_count )
    if ($verbose);

  $file_io->close();

  return 0;
} ## end sub run


1;

{'fraction_non_alphanumeric': 0.12888482632541134, 'fraction_numerical': 0.009140767824497258, 'mean_word_length': 2.204602510460251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2269262', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2515, 'n_words': 714}