-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoef_vari.rb
executable file
·65 lines (47 loc) · 1.79 KB
/
coef_vari.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
#! /usr/bin/env ruby
require 'optparse'
require 'descriptive_statistics'
#################################################################################################
## INPUT PARSING
#################################################################################################
options = {}
optparse = OptionParser.new do |opts|
options[:table] = nil
opts.on( '-t', '--table PATH', 'Input table') do |table|
options[:table] = table
end
options[:max_coef_var] = 10
opts.on( '-c', '--max_coef_var INTEGER', 'Maximum coefficient of variation (default 10)' ) do |max_coef_var|
options[:max_coef_var] = max_coef_var.to_i
end
# Set a banner, displayed at the top of the help screen.
opts.banner = "Usage: #{__FILE__} -f table_path -c max_coef_var \n\n"
# This displays the help screen
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end # End opts
# parse options and remove from ARGV
optparse.parse!
#################################################################################################
if options[:table].nil?
puts 'Input table not defined'
Process.exit
end
array = []
File.open(options[:table]).each do |line|
line.chomp!
fields = line.split("\t")
gene_name = fields.shift
fields.map!{|col| col.to_i}
coef_var = 100 * fields.standard_deviation / fields.mean
if coef_var <= options[:max_coef_var]
row_array = [gene_name, coef_var, fields.mean].concat(fields)
array << row_array
end
end
array.sort!{|ar1, ar2| ar1[1] <=> ar2[1] }
array.each do |row|
puts "#{row[0]}\t#{sprintf('%.2f',row[1])}\t#{sprintf('%.1f',row[2])}\t#{row[3..row.length-1].join("\t")}"
end