inprogress
[jalview.git] / forester / ruby / evoruby / lib / evo / tool / phylogenies_decorator.rb
index 953f924..6668877 100644 (file)
@@ -30,8 +30,8 @@ module Evoruby
     #DECORATOR_OPTIONS_DOMAINS = '-r=1'
     DECORATOR_OPTIONS_DOMAINS = '-p -t'
     IDS_MAPFILE_SUFFIX        = '.nim'
-    DOMAINS_MAPFILE_SUFFIX    = '.dff'
-    SLEEP_TIME                = 0.1
+    DOMAINS_MAPFILE_SUFFIX    = '_hmmscan_10.dff'
+    SLEEP_TIME                = 0.05
     REMOVE_NI                 = true
     TMP_FILE_1                  = '___PD1___'
     TMP_FILE_2                  = '___PD2___'
@@ -40,10 +40,10 @@ module Evoruby
     JAVA_HOME                 = ENV[Constants::JAVA_HOME_ENV_VARIABLE]
 
     PRG_NAME       = "phylogenies_decorator"
-    PRG_DATE       = "2012.10.11"
+    PRG_DATE       = "2013.11.15"
     PRG_DESC       = "decoration of phylogenies with sequence/species names and domain architectures"
     PRG_VERSION    = "1.02"
-    COPYRIGHT      = "2012 Christian M Zmasek"
+    COPYRIGHT      = "2013 Christian M Zmasek"
     CONTACT        = "phylosoft@gmail.com"
     WWW            = "https://sites.google.com/site/cmzmasek/home/software/forester"
 
@@ -101,32 +101,9 @@ module Evoruby
         Util.fatal_error( PRG_NAME, 'logfile [' + LOG_FILE + '] already exists' )
       end
 
-      allowed_opts = Array.new
-      allowed_opts.push( IDS_ONLY_OPTION )
-      allowed_opts.push( DOMAINS_ONLY_OPTION )
-
-      disallowed = cla.validate_allowed_options_as_str( allowed_opts )
-      if ( disallowed.length > 0 )
-        Util.fatal_error( PRG_NAME, "unknown option(s): " + disallowed )
-      end
-
-      ids_only = false
-      domains_only = false
-
       in_suffix = cla.get_file_name( 0 )
       out_suffix = cla.get_file_name( 1 )
 
-      if cla.is_option_set?( IDS_ONLY_OPTION )
-        ids_only = true
-      end
-      if cla.is_option_set?( DOMAINS_ONLY_OPTION )
-        domains_only = true
-      end
-
-      if ( ids_only && domains_only )
-        Util.fatal_error( PRG_NAME, 'attempt to use ids only and domains only at the same time' )
-      end
-
       log = String.new
 
       now = DateTime.now
@@ -189,6 +166,10 @@ module Evoruby
           log << counter.to_s + ': ' + phylogeny_file + ' -> ' +  outfile + NL
 
           phylogeny_id = get_id( phylogeny_file )
+          puts
+
+          Util.print_message( PRG_NAME, "id: " + phylogeny_id )
+          log << "id: " + phylogeny_id + NL
 
           ids_mapfile_name = nil
           domains_mapfile_name = nil
@@ -198,7 +179,6 @@ module Evoruby
           domains_mapfile_name = get_file( files, phylogeny_id, DOMAINS_MAPFILE_SUFFIX )
           seqs_file_name = get_seq_file( files, phylogeny_id )
 
-
           begin
             Util.check_file_for_readability( domains_mapfile_name )
           rescue ArgumentError
@@ -259,39 +239,29 @@ module Evoruby
 
 
     def get_id( phylogeny_file_name )
-      phylogeny_file_name =~ /^([^_]+)/
+      phylogeny_file_name =~ /^(.+?)__/
       $1
     end
 
     def get_file( files_in_dir, phylogeny_id, suffix_pattern )
       matching_files = Array.new
-      matching_suffix_files = Array.new
+
       files_in_dir.each { | file |
 
         if ( !File.directory?( file ) &&
              file !~ /^\./ &&
              file !~ /^00/ &&
-             file =~ /^#{phylogeny_id}.*#{suffix_pattern}$/ )
+             file =~ /^#{phylogeny_id}#{suffix_pattern}$/ )
           matching_files << file
         end
-        if ( !File.directory?( file ) &&
-             file !~ /^\./ &&
-             file !~ /^00/ &&
-             file =~ /#{suffix_pattern}$/ )
-          matching_suffix_files << file
-        end
       }
-      if matching_files.length < 1 && matching_suffix_files.length == 1
-        return matching_suffix_files[ 0 ]
-      end
-
-      if matching_files.length < 1 && matching_suffix_files.length < 1
+      if matching_files.length < 1
         Util.fatal_error( PRG_NAME, 'no file matching [' + phylogeny_id +
-           '_] [' + suffix_pattern + '] present in current directory' )
+           + suffix_pattern + '] present in current directory' )
       end
       if matching_files.length > 1
         Util.fatal_error( PRG_NAME, 'more than one file matching [' + phylogeny_id +
-           '_] [' + suffix_pattern + '] present in current directory' )
+           + suffix_pattern + '] present in current directory' )
       end
       matching_files[ 0 ]
     end
@@ -304,17 +274,16 @@ module Evoruby
         if ( !File.directory?( file ) &&
              file !~ /^\./ &&
              file !~ /^00/ &&
-             file =~ /^#{phylogeny_id}.+\d$/ )
+             ( file =~ /^#{phylogeny_id}__.+\d$/ || file =~ /^#{phylogeny_id}__.*\.fasta$/ ) )
           matching_files << file
         end
-
       }
 
       if matching_files.length < 1
-        Util.fatal_error( PRG_NAME, 'no seq file matching [' + phylogeny_id + '] present in current directory' )
+        Util.fatal_error( PRG_NAME, 'no seq file matching [' + phylogeny_id + '__] present in current directory' )
       end
       if matching_files.length > 1
-        Util.fatal_error( PRG_NAME, 'more than one seq file matching [' + phylogeny_id + '] present in current directory' )
+        Util.fatal_error( PRG_NAME, 'more than one seq file matching [' + phylogeny_id + '__] present in current directory' )
       end
       matching_files[ 0 ]
     end