# Main program for getting pseudo-binary ECI in ternary system # # Written by k-fleak # # Last Update 2007/01/12 include Math #require "#{ENV["HOME"]}/myRuby/parseECI.rb" require "./parseECI.rb" class GetPseudoBinaryECI def initialize(filename, *cluster) eciFile = ParseECI.new(filename) @eci = eciFile.getMultiECI @cluster = cluster.flatten calcConvertMatrix start end private def calcConvertMatrix @cMat = Array.new m1 = [3.0/8.0, 3.0*sqrt(3.0)/8.0 , 9.0/8.0] m2 = [3.0/8.0, -3.0*sqrt(3.0)/8.0 , 9.0/8.0] m3 = [3.0/2.0, 0.0 , 0.0 ] @cMat.push(m1) @cMat.push(m2) @cMat.push(m3) end def calcPseudoBinaryECI(eciOrig) wMat = Array.new # w[0] = wAB, w[1] = wBC, w[2] = wAC wMat[0] = eciOrig[0].to_f * @cMat[0][0] + eciOrig[1].to_f * @cMat[0][1] + eciOrig[2].to_f * @cMat[0][2] wMat[1] = eciOrig[0].to_f * @cMat[1][0] + eciOrig[1].to_f * @cMat[1][1] + eciOrig[2].to_f * @cMat[1][2] wMat[2] = eciOrig[0].to_f * @cMat[2][0] + eciOrig[1].to_f * @cMat[2][1] + eciOrig[2].to_f * @cMat[2][2] return wMat end def start print "\n" print sprintf("%5s %15.12s %15.12s %15.12s","#" , "wAB", "wBC", "wCA") print "\n" @cluster.each do |cluster| eciOrig = @eci[cluster.to_i].flatten if eciOrig.size == 3 then wMat = calcPseudoBinaryECI(eciOrig) print sprintf("%5s %15.12s %15.12s %15.12s", cluster.to_i, wMat[0], wMat[1], wMat[2]) print "\n" end end end end gp = GetPseudoBinaryECI.new(ARGV[0], ARGV[1..(ARGV.size - 1)])