Class: Qu::Seqcluster::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/qu/seqcluster/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



26
27
28
# File 'lib/qu/seqcluster/options.rb', line 26

def initialize(argv)
  @opts = parse_opts(argv)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



24
25
26
# File 'lib/qu/seqcluster/options.rb', line 24

def opts
  @opts
end

Instance Method Details

#parse_opts(argv) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/qu/seqcluster/options.rb', line 31

def parse_opts(argv)

  options = Seqcluster::default_options

  OptionParser.new do |opts|
    opts.banner = "#{PROGRAM} [#{VERSION}]: Cluster DNA/RNA based on k-mer algorithm
Usage: #{PROGRAM} -i seq.fasta -k 9 -c 0.9"

    opts.separator ""
    opts.separator "Required options:"
    opts.separator ""

    opts.on('-i', '--in File', String, 'Input sequence file in fasta format.') do |value|
      if File.directory?(value)
        $stderr.puts "Error: #{value} is a direcotry."
        exit
      end

      unless File.exists?(value)
        $stderr.puts "Error: #{value} is not exists."
        exit
      end
      options.in = value
    end

    opts.separator ""
    opts.separator "Optional options:"
    opts.separator ""

    opts.on('-k', '--kvalue Integer', Integer, "K value, default is #{options.kvalue}.") do |value|
      options.kvalue = value
    end

    opts.on("-o", "--out File", String, "Output file name for storing the results, default is screen.") do |value|
      options.out = File.open(value, 'w')
    end

    opts.on('-c', '--cutoff Float', Float, "Cutoff value for the similarity for cluster, default is #{options.cutoff}.") do |value|
      options.cutoff = value
    end

    opts.separator ""
    opts.separator ""

    opts.on("-h", "--help", "Show this message and quit") do
      puts opts
      exit
    end

    opts.on("-v", "--version", "Show version") do
      puts "#{PROGRAM} #{VERSION}"
      exit
    end

    opts.separator ""
    opts.separator "Author: Wubin Qu <[email protected]>"
    opts.separator ""

    begin
      argv = ["-h"] if argv.empty?
      opts.parse!(argv)
    rescue OptionParser::ParseError => e
      $stderr.puts e.message, "\n", opts
      exit
    end

    if options.in.nil?
      $stderr.puts "Error: option -i required."
      exit
    end
  end
  return options
end