<commit_before>use strict;
use warnings;
 
use Getopt::Long;
use Cwd;
 
use vars qw(@INC);
 
#effectively add this directory to the PERL5LIB automatically
my $dir = cwd() . '/' . __FILE__;
my @d = split(/\//, $dir);
pop(@d);
$dir = join('/', @d);
unshift @INC, $dir;
 
 
my ($file, $verbose, $help);
 
GetOptions ('file=s'      => \$file,
            'verbose'     => \$verbose,
            'help'        => sub { &show_help(); exit 1;} );
 
usage("-file option is required")   if(!$file);
usage() if($help);
 
open(FILE, $file) or die("Could not open input file '$file'");
 
my  @all_species;
my $xref;
my $new=undef;
my $type;
while( my $line = <FILE> ) {
  chomp($line);
  next if $line =~ /^#/;
  next if !$line;

  print $line."\n";
  my ($key, $value) = split("=",$line);

  if($key eq "species" || $key eq "xref"){
    if(defined($new)){ #save old one
      if($type eq "species"){
	push @all_species, $new;
      }
      else{
	$xref = $new;
      }
      $new = undef;
    }
    if($key eq "species"){
      $type = "species";
      eval "require XrefMapper::$value";
      my $module;
      if($@) {
	warn("Could not require mapper module XrefMapper::$value\n" .
	     "Using XrefMapper::BasicMapper instead:\n$@");
	require XrefMapper::BasicMapper;
	$module = "BasicMapper";
      }
      else{
	$module = $value;
      }
      {
	no strict 'refs';
	$new = "XrefMapper::$module"->new();
	$new->species($value);
      }
    }
    else{
      my $module = "db";
      use XrefMapper::db;
      $type= "xref";
      $new = new XrefMapper::db();
    }
  }
  else{
    $new->$key($value);
  }
}

if(defined($new)){ #save last one
  if($type eq "species"){
    push @all_species, $new;
  }
  else{
    $xref = $new;
  }
  $new = undef;
}

for my $species ( @all_species ) {
  $species->dump_seqs($xref);
  $species->run_matching($xref);
  $species->store();
}

 
print STDERR "*** All finished ***\n";
 
sub usage {
  my $msg = shift;
 
  print STDERR "$msg\n\n" if($msg);
  print STDERR <<EOF;
usage:   perl xref_mapper <options>
                                                                                    
options: -file <input_file>     input file with tab delimited 'species',
                                'host', 'port', 'dbname' ,'user', 'password' and 'directory'
                                values on each line
                          
         -verbose               print out debug statements
 <commit_msg>pass xref to method xref and no longer pass it as an argument in other methods<commit_after>use strict;
use warnings;
 
use Getopt::Long;
use Cwd;
use XrefMapper::db;
 
use vars qw(@INC);
 
#effectively add this directory to the PERL5LIB automatically
my $dir = cwd() . '/' . __FILE__;
my @d = split(/\//, $dir);
pop(@d);
$dir = join('/', @d);
unshift @INC, $dir;
 
 
my ($file, $verbose, $help);
 
GetOptions ('file=s'      => \$file,
            'verbose'     => \$verbose,
            'help'        => sub { &show_help(); exit 1;} );
 
usage("-file option is required")   if(!$file);
usage() if($help);
 
open(FILE, $file) or die("Could not open input file '$file'");
 
my  @all_species;
my $xref;
#my $output=undef;
my $new=undef;
my $type;
while( my $line = <FILE> ) {
  chomp($line);
  next if $line =~ /^#/;
  next if !$line;

  print $line."\n";
  my ($key, $value) = split("=",$line);

  if($key eq "species" || $key eq "xref"){
    if(defined($new)){ #save old one
      if($type eq "species"){
	push @all_species, $new;
      }
#      elsif($type eq "output"){
#	$output = $new;
#      }
      else{
	$xref = $new;
      }
      $new = undef;
    }
    if($key eq "species"){
      $type = "species";
      eval "require XrefMapper::$value";
      my $module;
      if($@) {
	warn("Could not require mapper module XrefMapper::$value\n" .
	     "Using XrefMapper::BasicMapper instead:\n$@");
	require XrefMapper::BasicMapper;
	$module = "BasicMapper";
      }
      else{
	$module = $value;
      }
      {
	no strict 'refs';
	$new = "XrefMapper::$module"->new();
	$new->species($value);
      }
    }
#    elsif($key eq "output"){
#      $type= "output";
#      $new = new XrefMapper::db();
#    }
    else{
      $type= "xref";
      $new = new XrefMapper::db();
    }
  }
  else{
    $new->$key($value);
  }
}

if(defined($new)){ #save last one
  if($type eq "species"){
    push @all_species, $new;
  }
#  elsif($type eq "output"){
#    $output= $new;
#  }
  else{
    $xref = $new;
  }
  $new = undef;
}

for my $species ( @all_species ) {
  $species->xref($xref);
#  $species->output($output);
  $species->dump_seqs();
  $species->run_matching();
  $species->store();
}

 
print STDERR "*** All finished ***\n";
 
sub usage {
  my $msg = shift;
 
  print STDERR "$msg\n\n" if($msg);
  print STDERR <<EOF;
usage:   perl xref_mapper <options>
                                                                                    
options: -file <input_file>     input file with tab delimited 'species',
                                'host', 'port', 'dbname' ,'user', 'password' and 'directory'
                                values on each line
                          
         -verbose               print out debug statements
 
{'fraction_non_alphanumeric': 0.17839922854387658, 'fraction_numerical': 0.0007714561234329798, 'mean_word_length': 2.166056166056166, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5311949', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1787, 'n_words': 482}