class GeneValidator::GVArgValidation

TODO: If a tabular file is provided, ensure that a tabular file has the

right number of columns

TODO: assert_if_ruby_version_is_supported A class to validate the arguments passed to the Validation Class

Public Class Methods

command?(command) click to toggle source

Return `true` if the given command exists and is executable.

# File lib/genevalidator/arg_validation.rb, line 33
def command?(command)
  system("which #{command} > /dev/null 2>&1")
end
validate_args() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 17
def validate_args
  @opt = opt
  assert_file_present('input file', opt[:input_fasta_file])
  assert_input_file_probably_fasta
  assert_input_sequence
  assert_BLAST_output_files

  assert_validations_arg
  check_num_threads

  export_bin_dirs unless @opt[:bin].nil?
  Blast.validate(opt) unless @opt[:test]
  assert_mafft_installation
end

Private Class Methods

add_to_path(bin_dir) click to toggle source

Checks if dir is in $PATH and if not, it adds the dir to the $PATH.

# File lib/genevalidator/arg_validation.rb, line 115
def add_to_path(bin_dir)
  return unless bin_dir
  return if ENV['PATH'].split(':').include?(bin_dir)
  ENV['PATH'] = "#{bin_dir}:#{ENV['PATH']}"
end
assert_BLAST_output_files() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 60
def assert_BLAST_output_files
  return unless @opt[:blast_xml_file] || @opt[:blast_tabular_file]
  if @opt[:blast_xml_file]
    assert_file_present('BLAST XML file', @opt[:blast_xml_file])
  elsif @opt[:blast_tabular_file]
    assert_file_present('BLAST tabular file', @opt[:blast_tabular_file])
    assert_tabular_options_exists
  end
end
assert_dir_present(desc, file, exit_code = 1)
Alias for: assert_file_present
assert_file_present(desc, file, exit_code = 1) click to toggle source
# File lib/genevalidator/arg_validation.rb, line 84
def assert_file_present(desc, file, exit_code = 1)
  return if file && File.exist?(File.expand_path(file))
  warn "*** Error: Couldn't find the #{desc}: #{file}."
  exit exit_code
end
Also aliased as: assert_dir_present
assert_input_file_probably_fasta() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 78
def assert_input_file_probably_fasta
  File.open(@opt[:input_fasta_file], 'r') do |file_stream|
    file_stream.readline[0] == '>'
  end
end
assert_input_sequence() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 92
def assert_input_sequence
  fasta_content = IO.binread(@opt[:input_fasta_file])
  type = BlastUtils.type_of_sequences(fasta_content)
  return if %i[nucleotide protein].include? type
  warn '*** Error: The input files does not contain just protein'
  warn '    or nucleotide data.'
  warn '    Please correct this and try again.'
  exit 1
end
assert_mafft_installation() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 121
def assert_mafft_installation
  return if command?('mafft')
  warn '*** Could not find Mafft binaries.'
  warn '    Ignoring error and continuing - Please note that' \
               ' some validations may be skipped.'
  warn # a blank line
end
assert_tabular_options_exists() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 70
def assert_tabular_options_exists
  return if @opt[:blast_tabular_options]
  warn '*** Error: BLAST tabular options (-o) have not been set.'
  warn '    Please set the "-o" option with the custom format'
  warn '    used in the BLAST -outfmt argument'
  exit 1
end
assert_validations_arg() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 39
def assert_validations_arg
  validations = %w[lenc lenr frame merge dup orf align]
  if @opt[:validations]
    val = @opt[:validations].collect { |v| v.strip.downcase }
    validations = val unless val.include? 'all'
  end
  @opt[:validations] = validations
end
check_num_threads() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 48
def check_num_threads
  @opt[:num_threads] = Integer(@opt[:num_threads])
  unless @opt[:num_threads].positive?
    warn 'Number of threads can not be lower than 0'
    warn 'Setting number of threads to 1'
    @opt[:num_threads] = 1
  end
  return unless @opt[:num_threads] > 256
  warn "Number of threads set at #{@opt[:num_threads]} is" \
               ' unusually high.'
end
export_bin_dirs() click to toggle source
# File lib/genevalidator/arg_validation.rb, line 102
def export_bin_dirs
  @opt[:bin].each do |bin|
    bin = File.expand_path(bin)
    if File.exist?(bin) && File.directory?(bin)
      add_to_path(bin)
    else
      warn '*** The following bin directory does not exist:'
      warn "    #{bin}"
    end
  end
end