-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaverage_control.rb
More file actions
49 lines (41 loc) · 881 Bytes
/
Copy pathaverage_control.rb
File metadata and controls
49 lines (41 loc) · 881 Bytes
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
require 'csv'
def check_args
file = ARGV[0]
unless File.exist?(file)
puts "[ERROR] Can't read file. File path = #{file}"
exit 1
end
end
check_args
file = ARGV[0]
srr_control_start = ARGV[1].to_i
srr_control_end = ARGV[2].to_i
file1 = File.new('average_control.tsv', 'w')
file1 << "\t"
file1 << "average_control"
file1 << "\n"
arr = []
count = 0
CSV.foreach(file, col_sep: "\t", headers: false) do |row|
if count == 0
count += 1
next
end
file1 << row[0]
file1 << "\t"
row.each_with_index do |sample, i|
if i == srr_control_start
arr << sample
srr_control_start += 1
if srr_control_start == srr_control_end + 1
arr2 = arr.map(&:to_f)
ave = arr2.sum.fdiv(arr.length)
file1 << ave
file1 << "\n"
srr_control_start = ARGV[1].to_i
break
end
end
end
arr = []
end