DECORATOR_OPTIONS_SEQ_NAMES = '-p -t -mp -or'
DECORATOR_OPTIONS_DOMAINS = '-p -t'
- IDS_MAPFILE_SUFFIX = '.nim'
DOMAINS_MAPFILE_SUFFIX = '.dff'
SLEEP_TIME = 0.01
REMOVE_NI = true
domains_mapfile_name = nil
seqs_file_name = nil
- ids_mapfile_name = get_file( files, phylogeny_id, IDS_MAPFILE_SUFFIX )
+ ids_mapfile_name = get_file( ".", phylogeny_id, Constants::ID_MAP_FILE_SUFFIX )
begin
Util.check_file_for_readability( ids_mapfile_name )
log << "Ids mapfile: " + ids_mapfile_name + NL
unless no_seqs_files
- seqs_file_name = get_seq_file( files, phylogeny_id )
+ seqs_file_name = get_file( ".", phylogeny_id, Constants::ID_NORMALIZED_FASTA_FILE_SUFFIX )
begin
Util.check_file_for_readability( seqs_file_name )
rescue IOError
end
unless no_domains
- domains_mapfile_name = get_file( files, phylogeny_id, DOMAINS_MAPFILE_SUFFIX )
+ domains_mapfile_name = get_file( ".", phylogeny_id, Constants::DOMAINS_TO_FORESTER_OUTFILE_SUFFIX )
begin
Util.check_file_for_readability( domains_mapfile_name )
rescue IOError
end
def get_id( phylogeny_file_name )
- if phylogeny_file_name =~ /^(.+?_DA)_/
- return $1
- elsif phylogeny_file_name =~ /^(.+?)_/
- return $1
- end
- nil
+ return phylogeny_file_name
+ #if phylogeny_file_name =~ /^(.+?_DA)_/
+ # return $1
+ #elsif phylogeny_file_name =~ /^(.+?)_/
+ # return $1
+ #end
+ #nil
end
def get_file( files_in_dir, phylogeny_id, suffix_pattern )
- matching_files = Util.get_matching_files( files_in_dir, phylogeny_id, suffix_pattern )
- if matching_files.length < 1
- Util.fatal_error( PRG_NAME, 'no file matching [' + phylogeny_id +
- '...' + 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' )
- end
- matching_files[ 0 ]
+ Util.get_matching_file( files_in_dir, phylogeny_id, suffix_pattern )
+ # matching_files = Util.get_matching_files( files_in_dir, phylogeny_id, suffix_pattern )
+ # if matching_files.length < 1
+ # Util.fatal_error( PRG_NAME, 'no file matching [' + phylogeny_id +
+ # '...' + 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' )
+ # end
+ # matching_files[ 0 ]
end
def get_seq_file( files_in_dir, phylogeny_id )
# Copyright:: Copyright (C) 2017 Christian M. Zmasek
# License:: GNU Lesser General Public License (LGPL)
#
-# Last modified: 2017/02/07
+# Last modified: 2017/04/27
require 'lib/evo/util/constants'
matching_files
end
+ def Util.get_matching_file( dir_name, prefix, suffix )
+ unless Dir.exist? dir_name
+ raise IOError, "directory [#{dir_name}] does not exist"
+ end
+
+ all_files = Dir.entries(dir_name)
+
+ if ( all_files.size <= 2 )
+ raise IOError, "directory [#{dir_name}] is empty"
+ end
+ matching_files = Array.new
+ all_files.each { | file |
+ if (( !File.directory?( file )) && (file.end_with? suffix))
+ matching_files << file
+ end
+ }
+
+ if ( matching_files.size == 0 )
+ raise IOError, "no files ending with \"" + suffix + "\" found in [" + dir_name + "]"
+ end
+ my_prefix = prefix
+ done = false
+ more_than_one = false
+ the_one = nil;
+
+ loop do
+ puts my_prefix #TODO remove me
+ matches = 0
+ matching_files.each { | file |
+ if file.start_with?( my_prefix )
+ matches += 1
+ if matches > 1
+ the_one = nil
+ break
+ end
+ the_one = file
+ end
+ }
+ if matches > 1
+ more_than_one = true
+ done = true
+ end
+ if matches == 1
+ done = true
+ else
+ if my_prefix.length <= 1
+ raise IOError, "no file matching \"" + removeFileExtension( prefix )
+ + "\" and ending with \"" + suffix + "\" found in [" + dir_name + "]"
+ end
+ my_prefix = my_prefix[ 0 ... ( my_prefix.length - 1 ) ]
+
+ end
+ break if done
+ end
+
+ if more_than_one
+ raise IOError, "multiple files matching \"" + prefix +
+ "\" and ending with \"" + suffix + "\" found in [" + dir_name + "]"
+ elsif the_one != nil
+ else
+ raise IOError, "no file matching \"" + prefix + "\" and ending with \"" +
+ suffix + "\" found in [" + dir_name + "]"
+ end
+ the_one
+ end
+
def Util.normalize_seq_name( name, length, exception_if_too_long = false )
if name.length > length
if exception_if_too_long