File: repfind-cmp.rb

package info (click to toggle)
genometools 1.6.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 50,412 kB
  • sloc: ansic: 271,241; ruby: 30,339; python: 4,880; sh: 3,193; makefile: 1,194; perl: 219; pascal: 159; haskell: 37; sed: 5
file content (69 lines) | stat: -rwxr-xr-x 1,611 bytes parent folder | download | duplicates (9)
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
66
67
68
69
#!/usr/bin/env ruby

if ARGV.length != 2
  STDERR.puts "Usage: #{$0} <newformat> <oldformat>"
  exit 1
end

newformat=ARGV[0]
oldformat=ARGV[1]

def filename2lines(filename)
begin
  fp = File.new(filename)
rescue => error
  STDERR.puts "#{$0}: cannot open \"#{filename}\": #{error}"
  exit 1
end
  return fp.readlines
end

def comparecol(linenum,ao,idxo,an,idxn)
  if idxo >= ao.length
    STDERR.puts "idx0 = #{idx0} is too large"
    exit 1
  end
  if idxn >= an.length
    STDERR.puts "idxn = #{idxn} is too large"
    exit 1
  end
  if ao[idxo] != an[idxn]
    STDERR.puts "line #{linenum}: ao[#{idxo}] = #{ao[idxo]} != #{an[idxn]} = " +
                "an[#{idxn}]"
    exit 1
  end
end 

lines_oldformat = filename2lines(oldformat)
lines_newformat = filename2lines(newformat)

if lines_oldformat.length != lines_newformat.length
  STDERR.puts "files of different sizes"
  exit 1
end

0.upto(lines_oldformat.length-1) do |linenum|
  ao = lines_oldformat[linenum].chomp.split(/ /)
  an = lines_newformat[linenum].chomp.split(/ /)
  if ao.length == an.length
    0.upto(ao.length-1) do |colnum|
      if ao[colnum] != an[colnum]
        STDERR.puts "line #{linenum}: old=#{ao[colnum]} != #{an[colnum]}=new"
        exit 1
      end 
    end
  else
    comparecol(linenum,ao,0,an,0)
    comparecol(linenum,ao,1,an,2)
    comparecol(linenum,ao,0,an,4)
    if ao.length == 3
      comparecol(linenum,ao,2,an,6)
    elsif ao.length == 4
      comparecol(linenum,ao,3,an,6)
    else
      STDERR.puts "either 3 or 4 columns expected"
      exit 1
    end
  end
end
puts "#{lines_oldformat.length} lines checked"