-
Notifications
You must be signed in to change notification settings - Fork 5
/
parseSTAP
executable file
·52 lines (46 loc) · 1.05 KB
/
parseSTAP
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
#!/usr/bin/env ruby
require 'ostruct'
require 'optparse'
opt = OpenStruct.new
ARGV.options {|opts|
opts.banner << " tab-file"
#opts.on(nil, "--report", "run apisReport when done") {|t| opt.report = t}
begin
opts.parse!
rescue
STDERR.puts $!.message
STDERR.puts opts
exit(1)
end
if (ARGV.size != 1)
STDERR.puts opts
exit(1)
end
}
csv, rest = ARGV
sumTax = [Hash.new, Hash.new, Hash.new, Hash.new, Hash.new, Hash.new]
lvTax = ["Kingdom", "Phylum", "Class", "Order", "Family", "Genus"]
total = 0
File.new(csv).each {|line|
fields = line.chomp.split("\t")
if (fields[3] =~/TREE2/)
tax = fields[3]
else
tax = fields[2]
end
levels = tax.split("|")
0.upto(4) {|i|
tax = levels[i + 1]
tax = "Unclassified" if tax.nil?
sumTax[i][tax] = 0 if sumTax[i][tax].nil?
sumTax[i][tax] += 1
}
total += 1
}
0.upto(4) {|i|
printf("%s:\n", lvTax[i])
sumTax[i].keys.sort {|x, y| sumTax[i][y] <=> sumTax[i][x]}.each {|key|
printf("%5.1f%% %s\n", sumTax[i][key]*100.0/total, key)
}
printf("\n")
}