-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance_of_line
68 lines (55 loc) · 1.4 KB
/
distance_of_line
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
#!/usr/bin/env ruby
require 'spreadsheet'
require 'csv'
usage =<<EOF
#{$0} txt m x0 fS sS csv
------------------------------------------------------
* txt :: text_file
* m :: sloop
* x0 :: where is pos on y-axis
* fS :: position in txt 1.Sample
* sS :: position in txt 2.Sample
* csv :: out_file
------------------------------------------------------
- VERSION 4/5/2013 -----------------------------------
------------------------------------------------------
by khayer
EOF
if ARGV.length != 5
puts usage
exit
end
# y = mx + x0
# y - x0 = mx
# y - mx -x0 = 0
# (y)
# X3,Y3 is searched
def dist(x,y)
upper = (-$m*x+1*y-$x0).abs
lower = Math.sqrt($m*$m+1).to_f
upper / lower
end
#def calculate_y(x)
# $m * x + $x0
#end
text_file = ARGV[0]
$m = ARGV[1].to_f
$x0 = ARGV[2].to_f
first_sample_position = ARGV[3].to_i
second_sample_position = ARGV[4].to_i
out_file = CSV.open(ARGV[5],"w")
out_file.write
File.open(text_file).each do |line|
next unless line =~ /^NM/
line.chomp!
fields = line.split("\t")
x3 = fields[first_sample_position].to_f
#puts x3
y3 = fields[second_sample_position].to_f
#puts y3
#x1 = 1.0
#y1 = calculate_y(x1)
#x2 = 40.0
#y2 = calculate_y(x2)
puts "#{fields[0]}\t#{fields[1]}\t#{dist(x3,y3)}\t#{x3}\t#{y3}"
end