File: match-stat.rb

package info (click to toggle)
genometools 1.6.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,576 kB
  • sloc: ansic: 271,876; ruby: 29,930; python: 5,106; sh: 3,083; makefile: 1,213; perl: 219; pascal: 159; haskell: 37; sed: 5
file content (31 lines) | stat: -rwxr-xr-x 697 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/env ruby

def matchstat(filename)
  begin
  fp = File.new(filename)
rescue => err
  STDERR.puts "cannot open file #{filename}"
  exit 1
end
  countmatches = 0
  totallength = 0
  totalid = 0
  fp.readlines.uniq.each do |line|
    if line.match(/^\d/) and m = line.split(/\s/)
      len1 = m[0].to_i
      len2 = m[4].to_i
      id = m[9].to_f
      countmatches += 1
      totallength += len1 + len2
      totalid += id
    end
  end
  printf("matches: %d, totallength=%d, avg_length=%.2f, avg_id=%.2f\n", 
          countmatches,totallength,totallength.to_f/countmatches.to_f,
          totalid/countmatches.to_f)
  fp.close_read
end

ARGV.each do |filename|
  matchstat(filename)
end