-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfileTools.rb
More file actions
52 lines (40 loc) · 784 Bytes
/
Copy pathfileTools.rb
File metadata and controls
52 lines (40 loc) · 784 Bytes
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
def tabRead(filename,header=false)
f = File.open(filename)
if header==true
f.gets
end
f.each{|line|
unless line.nil?
yield line.chomp.split(/\t/)
end
}
f.close()
end
def csvRead(filename,header=false)
f = File.open(filename)
if header==true
f.gets
end
f.each{|line|
unless line.nil?
yield line.chomp.split(/,/).collect{|x| x.strip}
end
}
f.close()
end
def getHeader(filename)
f = File.open(filename)
return f.gets.chomp.split(/\t/)
end
require 'Matrix'
def readMatrix(file)
colHeader = getHeader(file)
colHeader.delete_at(0)
rowHeader = []
matrix = []
tabRead(file,header=true){|arr|
rowHeader << arr.delete_at(0)
matrix << arr
}
return Matrix.new(matrix,colHeader,rowHeader)
end