From 82c1d3a1ffed9ad60f4dd7f4651f6f8c543e07e8 Mon Sep 17 00:00:00 2001
From: Ian Longden <ianl@sanger.ac.uk>
Date: Mon, 18 Oct 2004 15:11:05 +0000
Subject: [PATCH] -dumpcheck option added which will not dump out the fasta
 files if they already exist

---
 .../xref_mapping/XrefMapper/BasicMapper.pm    | 20 +++++++++++++++++++
 misc-scripts/xref_mapping/XrefMapper/db.pm    |  9 +++++++++
 misc-scripts/xref_mapping/xref_mapper.pl      | 19 ++++++------------
 3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm b/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm
index ca2754e105..2af3514976 100644
--- a/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm
+++ b/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm
@@ -224,6 +224,23 @@ sub dump_xref{
   my @lists =@{$self->get_set_lists()};
   
   my $i=0;
+  if(defined($self->dumpcheck())){
+    my $skip = 1;
+    foreach my $list (@lists){
+      if(!-e $xref->dir()."/xref_".$i."_dna.fasta"){ 
+	$skip = 0;
+      }
+      if(!-e $xref->dir()."/xref_".$i."_prot.fasta"){ 
+	$skip = 0;
+      }
+      $i++;
+    }
+    if($skip){
+      return;
+    }
+  }
+
+  $i=0;
   foreach my $list (@lists){
     print "method->".@$list[0]."\n";
     $method[$i] = shift @$list;
@@ -407,6 +424,9 @@ sub fetch_and_dump_seq{
   # store ensembl protein file name and open it
   #
   $self->ensembl_protein_file($self->dir."/".$self->species."_protein.fasta");
+  if(defined($self->dumpcheck()) and -e $self->ensembl_protein_file() and -e $self->ensembl_dna_file()){
+    return;
+  }
   open(PEP,">".$self->ensembl_protein_file()) 
     || die("Could not open dna file for writing: ".$self->ensembl_protein_file."\n");
 
diff --git a/misc-scripts/xref_mapping/XrefMapper/db.pm b/misc-scripts/xref_mapping/XrefMapper/db.pm
index 08c982caac..6b07c225ef 100644
--- a/misc-scripts/xref_mapping/XrefMapper/db.pm
+++ b/misc-scripts/xref_mapping/XrefMapper/db.pm
@@ -183,6 +183,15 @@ sub dir {
 
 }
 
+sub dumpcheck {
+  my ($self, $arg) = @_;
+  
+  (defined $arg) &&
+    ($self->{_dumpcheck} = $arg );
+  return $self->{_dumpcheck};
+}
+
+
 sub process_dir {
   my ($dir) = @_;
 
diff --git a/misc-scripts/xref_mapping/xref_mapper.pl b/misc-scripts/xref_mapping/xref_mapper.pl
index 6f3ca108bb..98a7777e19 100644
--- a/misc-scripts/xref_mapping/xref_mapper.pl
+++ b/misc-scripts/xref_mapping/xref_mapper.pl
@@ -15,10 +15,11 @@ $dir = join('/', @d);
 unshift @INC, $dir;
  
  
-my ($file, $verbose, $help);
+my ($file, $verbose, $dumpcheck, $help);
  
 GetOptions ('file=s'      => \$file,
             'verbose'     => \$verbose,
+	    'dumpcheck'    => \$dumpcheck,
             'help'        => sub { &show_help(); exit 1;} );
  
 usage("-file option is required")   if(!$file);
@@ -44,9 +45,6 @@ while( my $line = <FILE> ) {
       if($type eq "species"){
 	push @all_species, $new;
       }
-#      elsif($type eq "output"){
-#	$output = $new;
-#      }
       else{
 	$xref = $new;
       }
@@ -70,11 +68,10 @@ while( my $line = <FILE> ) {
 	$new = "XrefMapper::$module"->new();
 	$new->species($value);
       }
+      if(defined($dumpcheck) and $dumpcheck){
+	$new->dumpcheck("yes");
+      }
     }
-#    elsif($key eq "output"){
-#      $type= "output";
-#      $new = new XrefMapper::db();
-#    }
     else{
       $type= "xref";
       $new = new XrefMapper::db();
@@ -89,9 +86,6 @@ if(defined($new)){ #save last one
   if($type eq "species"){
     push @all_species, $new;
   }
-#  elsif($type eq "output"){
-#    $output= $new;
-#  }
   else{
     $xref = $new;
   }
@@ -116,9 +110,8 @@ sub usage {
   print STDERR <<EOF;
 usage:   perl xref_mapper <options>
                                                                                     
-options: -file <input_file>     input file with tab delimited 'species',
+options: -file <input_file>     input file with keyword pairs for  'species',
                                 'host', 'port', 'dbname' ,'user', 'password' and 'directory'
-                                values on each line
                           
          -verbose               print out debug statements
  
-- 
GitLab