ruby-band 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile +30 -0
  3. data/Gemfile.lock +119 -0
  4. data/Jarfile +9 -0
  5. data/Jarfile.lock +10 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +321 -0
  8. data/README.rdoc +70 -0
  9. data/Rakefile +66 -0
  10. data/VERSION +1 -0
  11. data/band_server/client.rb +35 -0
  12. data/band_server/client_alt.rb +35 -0
  13. data/band_server/first_dataset.csv +15 -0
  14. data/band_server/second_dataset.csv +15 -0
  15. data/band_server/simple_server.rb +90 -0
  16. data/band_server/third_dataset.csv +15 -0
  17. data/band_server/uploads/first_dataset.csv +15 -0
  18. data/band_server/uploads/second_dataset.csv +15 -0
  19. data/band_server/uploads/third_dataset.csv +15 -0
  20. data/bin/ruby-band +83 -0
  21. data/ext/mkrf_conf.rb +74 -0
  22. data/features/create_dataset.feature +12 -0
  23. data/features/step_definitions/create_dataset.rb +39 -0
  24. data/features/step_definitions/weka_classifiers.rb +43 -0
  25. data/features/step_definitions/weka_clustering.rb +34 -0
  26. data/features/step_definitions/weka_filters.rb +32 -0
  27. data/features/step_definitions/weka_parsers.rb +46 -0
  28. data/features/step_definitions/weka_pipeline.rb +41 -0
  29. data/features/support/env.rb +3 -0
  30. data/features/weka_classifiers.feature +16 -0
  31. data/features/weka_clustering.feature +15 -0
  32. data/features/weka_filters.feature +12 -0
  33. data/features/weka_parsers.feature +18 -0
  34. data/features/weka_pipeline.feature +14 -0
  35. data/lib/ruby-band.rb +12 -0
  36. data/lib/ruby-band/apache.rb +2 -0
  37. data/lib/ruby-band/apache/stat/correlation.rb +42 -0
  38. data/lib/ruby-band/apache/stat/inference.rb +151 -0
  39. data/lib/ruby-band/apache/stat/regression.rb +22 -0
  40. data/lib/ruby-band/core.rb +6 -0
  41. data/lib/ruby-band/core/parser/parser.rb +27 -0
  42. data/lib/ruby-band/core/type/apache_matrices.rb +35 -0
  43. data/lib/ruby-band/core/type/attribute.rb +53 -0
  44. data/lib/ruby-band/core/type/instance.rb +10 -0
  45. data/lib/ruby-band/core/type/instances.rb +361 -0
  46. data/lib/ruby-band/core/type/utils.rb +31 -0
  47. data/lib/ruby-band/weka.rb +14 -0
  48. data/lib/ruby-band/weka/attribute_selection/attribute_selection_utils.rb +20 -0
  49. data/lib/ruby-band/weka/attribute_selection/evaluators.rb +58 -0
  50. data/lib/ruby-band/weka/attribute_selection/search.rb +52 -0
  51. data/lib/ruby-band/weka/classifiers/bayes/bayes.rb +86 -0
  52. data/lib/ruby-band/weka/classifiers/bayes/bayes_utils.rb +82 -0
  53. data/lib/ruby-band/weka/classifiers/evaluation.rb +13 -0
  54. data/lib/ruby-band/weka/classifiers/functions/functions.rb +177 -0
  55. data/lib/ruby-band/weka/classifiers/functions/functions_utils.rb +78 -0
  56. data/lib/ruby-band/weka/classifiers/lazy/lazy.rb +86 -0
  57. data/lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb +83 -0
  58. data/lib/ruby-band/weka/classifiers/mi/mi.rb +191 -0
  59. data/lib/ruby-band/weka/classifiers/mi/mi_utils.rb +80 -0
  60. data/lib/ruby-band/weka/classifiers/rules/rules.rb +190 -0
  61. data/lib/ruby-band/weka/classifiers/rules/rules_utils.rb +81 -0
  62. data/lib/ruby-band/weka/classifiers/trees/trees.rb +110 -0
  63. data/lib/ruby-band/weka/classifiers/trees/trees_utils.rb +85 -0
  64. data/lib/ruby-band/weka/clusterers/clusterers.rb +99 -0
  65. data/lib/ruby-band/weka/clusterers/clusterers_utils.rb +86 -0
  66. data/lib/ruby-band/weka/db/DatabaseUtils_mysql +280 -0
  67. data/lib/ruby-band/weka/db/DatabaseUtils_postgresql +594 -0
  68. data/lib/ruby-band/weka/db/db.rb +74 -0
  69. data/lib/ruby-band/weka/filters/supervised/attribute/attribute.rb +55 -0
  70. data/lib/ruby-band/weka/filters/supervised/instance/instance.rb +17 -0
  71. data/lib/ruby-band/weka/filters/supervised/supervised_utils.rb +38 -0
  72. data/lib/ruby-band/weka/filters/unsupervised/attribute/attribute.rb +90 -0
  73. data/lib/ruby-band/weka/filters/unsupervised/instance/instance.rb +48 -0
  74. data/lib/ruby-band/weka/filters/unsupervised/unsupervised_utils.rb +38 -0
  75. data/resources/ReutersGrain-test.arff +611 -0
  76. data/resources/ReutersGrain-train.arff +1561 -0
  77. data/resources/weather.csv +15 -0
  78. data/resources/weather.numeric.arff +23 -0
  79. data/ruby-band.gemspec +178 -0
  80. data/spec/ruby-band_spec.rb +7 -0
  81. data/spec/spec_helper.rb +12 -0
  82. data/test/helper.rb +18 -0
  83. data/test/test_apacheCorrelation.rb +22 -0
  84. data/test/test_apacheInference.rb +46 -0
  85. data/test/test_ruby-band.rb +9 -0
  86. metadata +426 -0
@@ -0,0 +1,70 @@
1
+ = ruby-band
2
+
3
+ Data mining and machine learning algorithms for Ruby
4
+
5
+ == Installation
6
+
7
+ Install the 'jbundle' gem for JRuby before trying to install the
8
+ 'ruby-band' gem. Maven is also required for .jars automatic download and
9
+ installation. On Ubuntu/Debian Maven should already be installed and on OSX
10
+ system you can get it from Brew
11
+
12
+ If you want to use 'ruby-band' APIs without installing the gem you need to run
13
+ command 'rake -T' once before requiring the gem in your script (this is
14
+ necessary for jbundler to download the '.jar' files and subsequently set the
15
+ Java classpath). Otherwise use:
16
+
17
+ gem install ruby-band
18
+
19
+ == Description
20
+
21
+ ruby-band was created by Alberto Arrigoni as part of Google’s Summer of Code 2013. It is part of SciRuby.
22
+
23
+ == Usage
24
+
25
+ For a short tutorial on ruby-band functions and capabilities please visit our wiki section here on Github
26
+
27
+ == Developers
28
+
29
+ To use the library
30
+
31
+ require 'ruby-band'
32
+
33
+ The API doc is online. For more code examples see also the test files in
34
+ the source tree.
35
+
36
+ == Project home page
37
+
38
+ Information on the source tree, documentation, issues and how to contribute, see
39
+
40
+ http://github.com/arrigonialberto86/ruby-band
41
+
42
+ The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
43
+
44
+ == Contributing to ruby-band
45
+
46
+ ruby-band is part of SciRuby, a collaborative effort to bring scientific computation to Ruby. If you want to help, please do so!
47
+
48
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
49
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
50
+ * Fork the project.
51
+ * Start a feature/bugfix branch.
52
+ * Commit and push until you are happy with your contribution.
53
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. Cucumber tests (stored in the 'features' folder) are a great way to draft
54
+ tutorial sections along with tests.
55
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
56
+
57
+
58
+ == Cite
59
+
60
+ If you use this software, please cite one of
61
+
62
+ * [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
63
+ * [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
64
+
65
+
66
+ == License
67
+
68
+ Copyright (c) 2010–13, The Ruby Science Foundation.
69
+ All rights reserved. See LICENSE.txt for further details.
70
+
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ require 'jbundler'
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `jruby -S bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ruby-band"
18
+ gem.homepage = "http://github.com/arrigonialberto86/ruby-band"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Data mining algorithms for JRuby}
21
+ gem.description = %Q{Data mining and machine learning algorithms for JRuby }
22
+ gem.email = "arrigonialberto86@gmail.com"
23
+ gem.authors = ["arrigonialberto86"]
24
+ gem.extensions = ["ext/mkrf_conf.rb"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'cucumber/rake/task'
30
+ Cucumber::Rake::Task.new(:features)
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ # test.pattern = 'test/**/test_*.rb'
36
+ test.test_files = FileList['test/test_*.rb']
37
+ test.verbose = true
38
+ end
39
+
40
+ task :test => [] do
41
+ begin
42
+ Rake::Task[:test].invoke
43
+ rescue
44
+ end
45
+ Rake::Task[:features].invoke
46
+ end
47
+
48
+ #require 'rcov/rcovtask'
49
+ #Rcov::RcovTask.new do |test|
50
+ # test.libs << 'test'
51
+ # test.pattern = 'test/**/test_*.rb'
52
+ # test.verbose = true
53
+ # test.rcov_opts << '--exclude "gems/*"'
54
+ #end
55
+
56
+ task :default => :test
57
+
58
+ require 'rdoc/task'
59
+ Rake::RDocTask.new do |rdoc|
60
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
61
+
62
+ rdoc.rdoc_dir = 'rdoc'
63
+ rdoc.title = "ruby-band #{version}"
64
+ rdoc.rdoc_files.include('README*')
65
+ rdoc.rdoc_files.include('lib/**/*.rb')
66
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.11
@@ -0,0 +1,35 @@
1
+ require 'rest_client'
2
+ require 'uri'
3
+
4
+ address = 'http://localhost:4567/'
5
+
6
+ response_old = RestClient.post "#{address}create_dataset", { 'first' => { 'dataset' => File.new('first_dataset.csv'),'dataset_name' => 'dataset_1'},
7
+ 'second' => {'dataset' => File.new('second_dataset.csv'),'dataset_name' => 'dataset_2'} }
8
+
9
+
10
+ puts 'List of the parsed datasets:'
11
+ response_list = RestClient.get "#{address}datasets", :cookies => response_old.cookies
12
+ puts response_list
13
+
14
+ # use filter on the training dataset
15
+ RestClient.get "#{address}filter?filter_name=Filter::Unsupervised::Attribute::Discretize&&filter_options=-K_3&&dataset_in=dataset_1&&dataset_out=filtered_training_set",:cookies => response_old.cookies
16
+
17
+ puts 'List of the datasets + the filtered training set'
18
+ response_list = RestClient.get "#{address}datasets", :cookies => response_old.cookies
19
+ puts response_list
20
+
21
+ puts 'Print a single dataset:'
22
+ puts RestClient.get "#{address}datasets/dataset_1", :cookies => response_old.cookies
23
+
24
+
25
+ puts 'Train a classifier on the dataset_1:'
26
+ puts RestClient.get "#{address}train_classifier?classifier_name=Classifier::Bayes::NaiveBayes&&classifier_options=-K&&dataset_in=dataset_1&&model_name=naive_classifier&&class_index=0",:cookies => response_old.cookies
27
+
28
+ puts 'List all the trained classifiers:'
29
+ puts RestClient.get "#{address}classifiers", :cookies => response_old.cookies
30
+
31
+ puts 'Show classifier statistics:'
32
+ puts RestClient.get "#{address}classifiers/naive_classifier", :cookies => response_old.cookies
33
+
34
+ puts 'Crossvalidate the classifier:'
35
+ puts RestClient.get "#{address}crossvalidate_classifier?model_name=naive_classifier&&fold=5", :cookies => response_old.cookies
@@ -0,0 +1,35 @@
1
+ require 'rest_client'
2
+ require 'uri'
3
+
4
+ address = 'http://localhost:4567/'
5
+
6
+ response_old = RestClient.post "#{address}create_dataset", { 'first' => { 'dataset' => File.new('first_dataset.csv'),'dataset_name' => 'dataset_1'},
7
+ #'second' => {'dataset' => File.new('second_dataset.csv'),'dataset_name' => 'dataset_2'},
8
+ 'third' => {'dataset' => File.new('third_dataset.csv'),'dataset_name' => 'dataset_3'} }
9
+
10
+ puts 'List of the parsed datasets:'
11
+ response_list = RestClient.get "#{address}datasets", :cookies => response_old.cookies
12
+ puts response_list
13
+
14
+ # use filter on the training dataset
15
+ RestClient.get "#{address}filter?filter_name=Filter::Unsupervised::Attribute::Discretize&&filter_options=-K_3&&dataset_in=dataset_1&&dataset_out=filtered_training_set",:cookies => response_old.cookies
16
+
17
+ puts 'List of the datasets + the filtered training set'
18
+ response_list = RestClient.get "#{address}datasets", :cookies => response_old.cookies
19
+ puts response_list
20
+
21
+ puts 'Print a single dataset:'
22
+ puts RestClient.get "#{address}datasets/dataset_1", :cookies => response_old.cookies
23
+
24
+
25
+ puts 'Train a classifier on the dataset_1:'
26
+ puts RestClient.get "#{address}train_classifier?classifier_name=Classifier::Bayes::NaiveBayes&&classifier_options=-K&&dataset_in=dataset_1&&model_name=naive_classifier&&class_index=0",:cookies => response_old.cookies
27
+
28
+ puts 'List all the trained classifiers:'
29
+ puts RestClient.get "#{address}classifiers", :cookies => response_old.cookies
30
+
31
+ puts 'Show classifier statistics:'
32
+ puts RestClient.get "#{address}classifiers/naive_classifier", :cookies => response_old.cookies
33
+
34
+ puts 'Crossvalidate the classifier:'
35
+ puts RestClient.get "#{address}crossvalidate_classifier?model_name=naive_classifier&&fold=5", :cookies => response_old.cookies
@@ -0,0 +1,15 @@
1
+ outlook,temperature,humidity,windy,play
2
+ sunny,85,85,FALSE,no
3
+ sunny,80,90,TRUE,no
4
+ overcast,83,86,FALSE,yes
5
+ rainy,70,96,FALSE,yes
6
+ rainy,68,80,FALSE,yes
7
+ rainy,65,70,TRUE,no
8
+ overcast,64,65,TRUE,yes
9
+ sunny,72,95,FALSE,no
10
+ sunny,69,70,FALSE,yes
11
+ rainy,75,80,FALSE,yes
12
+ sunny,75,70,TRUE,yes
13
+ overcast,72,90,TRUE,yes
14
+ overcast,81,75,FALSE,yes
15
+ rainy,71,91,TRUE,no
@@ -0,0 +1,15 @@
1
+ outlook,temperature,humidity,windy,play
2
+ sunny,85,85,FALSE,no
3
+ sunny,80,90,TRUE,no
4
+ overcast,83,86,FALSE,yes
5
+ rainy,70,96,FALSE,yes
6
+ rainy,68,80,FALSE,yes
7
+ rainy,65,70,TRUE,no
8
+ overcast,64,65,TRUE,yes
9
+ sunny,72,95,FALSE,no
10
+ sunny,69,70,FALSE,yes
11
+ rainy,75,80,FALSE,yes
12
+ sunny,75,70,TRUE,yes
13
+ overcast,72,90,TRUE,yes
14
+ overcast,81,75,FALSE,yes
15
+ rainy,71,91,TRUE,no
@@ -0,0 +1,90 @@
1
+ #### This simple example server should run on JRuby, while the client can be run
2
+ ### either on Ruby or JRuby
3
+
4
+
5
+ require 'sinatra/base'
6
+ require 'ruby-band'
7
+ require 'JSON'
8
+
9
+ class Trial < Sinatra::Base
10
+ use Rack::Session::Pool
11
+
12
+ get '/datasets' do
13
+ session[:datasets].keys.join(",\t")
14
+ end
15
+ get '/classifiers' do
16
+ session[:classifiers].keys.join(",\t")
17
+ end
18
+
19
+ # return a dataset using Json format
20
+ get '/datasets/:dataset_in' do
21
+ # force session to start by writing in the Hash ## ODDDDD
22
+ session[:init] = true
23
+ session[:datasets][params[:dataset_in]].to_json_format
24
+ end
25
+
26
+ get '/classifiers/:classifier_in' do
27
+ session[:init] = true
28
+ session[:classifiers][params[:classifier_in]]
29
+ end
30
+
31
+ get '/summary/:dataset_in' do
32
+ session[:init] = true
33
+ dataset_in = session[:datasets][params[:dataset_in]]
34
+ return dataset_in.summary[0].to_s,dataset_in.summary[1].to_s
35
+ end
36
+
37
+ post "/create_dataset" do
38
+ params.each_key do |key|
39
+ File.open('uploads/' + params[key]['dataset'][:filename], "w") do |f|
40
+ f.write(params[key]['dataset'][:tempfile].read)
41
+ end
42
+ session[:datasets] ||= Hash.new
43
+ session[:classifiers] ||= Hash.new
44
+ session[:datasets][params[key]['dataset_name']] = Core::Parser::parse_CSV('uploads/' + params[key]['dataset'][:filename])
45
+ end
46
+ return "The dataset was successfully created!"
47
+ end
48
+
49
+ get '/filter' do
50
+ session[:init] = true
51
+ $dataset_in = session[:datasets][params[:dataset_in]]
52
+ filter = eval("Weka::#{params[:filter_name]}.new")
53
+ $params = params
54
+ filter.set do
55
+ filter_options $params[:filter_options].split("_").join(" ")
56
+ data $dataset_in
57
+ end
58
+ filtered_data = filter.use
59
+ session[:datasets][params[:dataset_out]] = filtered_data
60
+ end
61
+
62
+ get '/train_classifier' do
63
+ session[:init] = true
64
+ @dataset_in = session[:datasets][params[:dataset_in]]
65
+ classifier = eval("Weka::#{params[:classifier_name]}.new")
66
+ classifier.set_options params[:classifier_options].split("_").join(" ") if params[:classifier_options]
67
+ @dataset_in.setClassIndex(params[:class_index].to_i)
68
+ classifier.set_data @dataset_in
69
+ classifier.build_classifier(@dataset_in)
70
+ session[:classifiers][params[:model_name]] = classifier
71
+ classifier.to_s
72
+ end
73
+
74
+ get '/crossvalidate_classifier' do
75
+ session[:init] = true
76
+ classifier = session[:classifiers][params[:model_name]]
77
+ fold = params[:fold].to_i
78
+ eval = Weka::Classifier::Evaluation.new classifier.instance_eval("@dataset")
79
+ eval.crossValidateModel(classifier.class.new, classifier.instance_eval("@dataset"), fold.to_java(:int), Random.new(1))
80
+ eval.summary
81
+ end
82
+
83
+ post '/clear' do
84
+ session.clear
85
+ puts "Session is now cleared"
86
+ end
87
+
88
+ end
89
+
90
+ Trial.run!
@@ -0,0 +1,15 @@
1
+ outlook,temperature,humidity,windy,play
2
+ sunny,85,85,FALSE,no
3
+ sunny,80,90,TRUE,no
4
+ overcast,83,86,FALSE,yes
5
+ rainy,70,96,FALSE,yes
6
+ rainy,68,80,FALSE,yes
7
+ rainy,65,70,TRUE,no
8
+ overcast,64,65,TRUE,yes
9
+ sunny,72,95,FALSE,no
10
+ sunny,69,70,FALSE,yes
11
+ rainy,75,80,FALSE,yes
12
+ sunny,75,70,TRUE,yes
13
+ overcast,72,90,TRUE,yes
14
+ overcast,81,75,FALSE,yes
15
+ rainy,71,91,TRUE,no
@@ -0,0 +1,15 @@
1
+ outlook,temperature,humidity,windy,play
2
+ sunny,85,85,FALSE,no
3
+ sunny,80,90,TRUE,no
4
+ overcast,83,86,FALSE,yes
5
+ rainy,70,96,FALSE,yes
6
+ rainy,68,80,FALSE,yes
7
+ rainy,65,70,TRUE,no
8
+ overcast,64,65,TRUE,yes
9
+ sunny,72,95,FALSE,no
10
+ sunny,69,70,FALSE,yes
11
+ rainy,75,80,FALSE,yes
12
+ sunny,75,70,TRUE,yes
13
+ overcast,72,90,TRUE,yes
14
+ overcast,81,75,FALSE,yes
15
+ rainy,71,91,TRUE,no
@@ -0,0 +1,15 @@
1
+ outlook,temperature,humidity,windy,play
2
+ sunny,85,85,FALSE,no
3
+ sunny,80,90,TRUE,no
4
+ overcast,83,86,FALSE,yes
5
+ rainy,70,96,FALSE,yes
6
+ rainy,68,80,FALSE,yes
7
+ rainy,65,70,TRUE,no
8
+ overcast,64,65,TRUE,yes
9
+ sunny,72,95,FALSE,no
10
+ sunny,69,70,FALSE,yes
11
+ rainy,75,80,FALSE,yes
12
+ sunny,75,70,TRUE,yes
13
+ overcast,72,90,TRUE,yes
14
+ overcast,81,75,FALSE,yes
15
+ rainy,71,91,TRUE,no
@@ -0,0 +1,15 @@
1
+ outlook,temperature,humidity,windy,play
2
+ sunny,85,85,FALSE,no
3
+ sunny,80,90,TRUE,no
4
+ overcast,83,86,FALSE,yes
5
+ rainy,70,96,FALSE,yes
6
+ rainy,68,80,FALSE,yes
7
+ rainy,65,70,TRUE,no
8
+ overcast,64,65,TRUE,yes
9
+ sunny,72,95,FALSE,no
10
+ sunny,69,70,FALSE,yes
11
+ rainy,75,80,FALSE,yes
12
+ sunny,75,70,TRUE,yes
13
+ overcast,72,90,TRUE,yes
14
+ overcast,81,75,FALSE,yes
15
+ rainy,71,91,TRUE,no
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # BioRuby ruby-band Plugin RubyBand
4
+ # Author:: arrigonialberto86
5
+ # Copyright:: 2013
6
+
7
+ USAGE = "Describe ruby-band"
8
+
9
+ gempath = File.dirname(File.dirname(__FILE__))
10
+ $: << File.join(gempath,'lib')
11
+
12
+ VERSION_FILENAME=File.join(gempath,'VERSION')
13
+ version = File.new(VERSION_FILENAME).read.chomp
14
+
15
+ # print banner
16
+ print "ruby-band #{version} by arrigonialberto86 2013\n"
17
+
18
+ if ARGV.size == 0
19
+ print USAGE
20
+ end
21
+
22
+ require 'ruby-band'
23
+ require 'optparse'
24
+
25
+ # Uncomment when using the bio-logger
26
+ # require 'bio-logger'
27
+ # Bio::Log::CLI.logger('stderr')
28
+ # Bio::Log::CLI.trace('info')
29
+
30
+ options = {:example_switch=>false,:show_help=>false}
31
+ opts = OptionParser.new do |o|
32
+ o.banner = "Usage: #{File.basename($0)} [options] reponame\ne.g. #{File.basename($0)} the-perfect-gem"
33
+
34
+ o.on('--example_parameter [EXAMPLE_PARAMETER]', 'TODO: put a description for the PARAMETER') do |example_parameter|
35
+ # TODO: your logic here, below an example
36
+ options[:example_parameter] = 'this is a parameter'
37
+ end
38
+
39
+ o.separator ""
40
+ o.on("--switch-example", 'TODO: put a description for the SWITCH') do
41
+ # TODO: your logic here, below an example
42
+ self[:example_switch] = true
43
+ end
44
+
45
+ # Uncomment the following when using the bio-logger
46
+ # o.separator ""
47
+ # o.on("--logger filename",String,"Log to file (default stderr)") do | name |
48
+ # Bio::Log::CLI.logger(name)
49
+ # end
50
+ #
51
+ # o.on("--trace options",String,"Set log level (default INFO, see bio-logger)") do | s |
52
+ # Bio::Log::CLI.trace(s)
53
+ # end
54
+ #
55
+ # o.on("-q", "--quiet", "Run quietly") do |q|
56
+ # Bio::Log::CLI.trace('error')
57
+ # end
58
+ #
59
+ # o.on("-v", "--verbose", "Run verbosely") do |v|
60
+ # Bio::Log::CLI.trace('info')
61
+ # end
62
+ #
63
+ # o.on("--debug", "Show debug messages") do |v|
64
+ # Bio::Log::CLI.trace('debug')
65
+ # end
66
+
67
+ o.separator ""
68
+ o.on_tail('-h', '--help', 'display this help and exit') do
69
+ options[:show_help] = true
70
+ end
71
+ end
72
+
73
+ begin
74
+ opts.parse!(ARGV)
75
+
76
+ # Uncomment the following when using the bio-logger
77
+ # Bio::Log::CLI.configure('ruby-band')
78
+
79
+ # TODO: your code here
80
+ # use options for your logic
81
+ rescue OptionParser::InvalidOption => e
82
+ options[:invalid_argument] = e.message
83
+ end