inprogress
[jalview.git] / forester / ruby / evoruby / lib / evo / tool / multi_sequence_extractor.rb
index ffabc45..a868b6a 100644 (file)
@@ -41,6 +41,10 @@ module Evoruby
     NORMALIZED_IDS_MAP_SUFFIX           = ".nim"
     PROTEINS_LIST_FILE_SEPARATOR        = "\t"
 
+    def initialize()
+      @file_to_msa = Hash.new
+      @seqs = 0
+    end
 
     def run()
 
@@ -245,6 +249,7 @@ module Evoruby
       puts basename
 
       File.open( input_file ) do | file |
+        species_counter = 1
         while line = file.gets
           line.strip!
           if !Util.is_string_empty?( line ) && !(line =~ /\s*#/ )
@@ -286,8 +291,9 @@ module Evoruby
                 print_counts( per_species_counter, log, Constants::LINE_DELIMITER )
                 per_species_counter = 0
               end
-              puts " " + current_species + " [" + my_readlink + "]"
-              log << current_species + " [" + my_readlink + "]" + Constants::LINE_DELIMITER
+              puts " " + species_counter.to_s +  ":" + current_species + " [" + my_readlink + "]"
+              log << species_counter.to_s +  ": " + current_species + " [" + my_readlink + "]" + Constants::LINE_DELIMITER
+              species_counter += 1
             end
             puts "   " + seq_name
             log << "   " + seq_name + Constants::LINE_DELIMITER
@@ -308,21 +314,6 @@ module Evoruby
               Util.fatal_error( PRG_NAME, "error: seq name \"" + seq_name + "\" not unique"  )
             end
 
-            # if current_msa.find_by_name_start( seq_name, true ).size > 0
-            #   begin
-            #     seq = current_msa.get_by_name_start( seq_name, true ).copy
-            #   rescue ArgumentError => e
-            #     Util.fatal_error( PRG_NAME, "error: " + e.to_s )
-            #   end
-            # else
-            #   # Not found, try finding by partial match.
-            #   begin
-            #     seq = current_msa.get_by_name( seq_name, true, true )
-            #   rescue ArgumentError => e
-            #     Util.fatal_error( PRG_NAME, "error: " + e.to_s )
-            #   end
-            # end
-
             normalized_id = per_species_counter.to_s( 16 ).upcase +
              "_" + current_species
 
@@ -464,8 +455,6 @@ module Evoruby
           Util.fatal_error( PRG_NAME, "error: " + e.to_s )
         end
       end
-
-
     end
 
 
@@ -537,6 +526,10 @@ module Evoruby
     end
 
     def read_fasta_file( input )
+      if @file_to_msa.has_key?( input )
+        return @file_to_msa[ input ]
+      end
+
       f = MsaFactory.new()
       msa = nil
       begin
@@ -544,6 +537,11 @@ module Evoruby
       rescue Exception => e
         Util.fatal_error( PRG_NAME, "error: " + e.to_s )
       end
+      if @seqs <= 600000
+        @file_to_msa[ input ] = msa
+        @seqs += msa.get_number_of_seqs
+        puts "   total seqs in memory: " + @seqs.to_s
+      end
       msa
     end