bix 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/bix.rb +1 -0
- data/lib/bix/plink.rb +89 -0
- metadata +3 -2
data/lib/bix.rb
CHANGED
data/lib/bix/plink.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Bix
|
4
|
+
# Reads a tfam file, extracting a list of the individual names
|
5
|
+
def self.read_tfam(io_or_fn)
|
6
|
+
io = io_or_fn.instance_of?(String) ? File.new(io_or_fn) : io
|
7
|
+
|
8
|
+
inds = []
|
9
|
+
|
10
|
+
for line in io
|
11
|
+
line.chomp!
|
12
|
+
next if line[0] == '#'
|
13
|
+
f = line.split(/\t| /)
|
14
|
+
inds << f[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
return inds
|
18
|
+
end
|
19
|
+
|
20
|
+
# Reads a tped file. Produces a hash of ind_name => [haplotype 1, haplotype 2].
|
21
|
+
# ind_list specifies ind_names, if nil, ind names are just 0,1,2...
|
22
|
+
# as_array indicates whether haps will be output as strings or arrays
|
23
|
+
def self.read_tped(io_or_fn, ind_list=nil, as_array=false)
|
24
|
+
io = io_or_fn.instance_of?(String) ? File.new(io_or_fn) : io
|
25
|
+
|
26
|
+
ind_map = nil
|
27
|
+
|
28
|
+
for line in io
|
29
|
+
line.chomp!
|
30
|
+
next if line[0] == '#'
|
31
|
+
f = line.split(/ |\t/)
|
32
|
+
|
33
|
+
if !ind_map
|
34
|
+
ind_map = {}
|
35
|
+
# Initialize ind_map first
|
36
|
+
if ind_list
|
37
|
+
for i in 0...ind_list.size
|
38
|
+
ind_map[ind_list[i]] = i
|
39
|
+
end
|
40
|
+
else
|
41
|
+
((f.size-4)/2).times do |ind_idx|
|
42
|
+
ind_map[ind_idx] = ind_idx
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Initialize haps object
|
47
|
+
haps = {} # name => [hap1_vec, hap2_vec]
|
48
|
+
for name, ind_idx in ind_map
|
49
|
+
if as_array
|
50
|
+
haps[name] = [[], []]
|
51
|
+
else
|
52
|
+
haps[name] = ["", ""]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
for name, ind_idx in ind_map
|
59
|
+
haps[name][0] << f[4 + 2 * ind_idx + 0]
|
60
|
+
haps[name][1] << f[4 + 2 * ind_idx + 1]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
return haps
|
65
|
+
end
|
66
|
+
|
67
|
+
# Reads a frq file, producing a list of hashes with the keys
|
68
|
+
# :chr, :snp, :a1, :a2, :maf, :nchrobs
|
69
|
+
def self.read_frq(io_or_fn)
|
70
|
+
io = io_or_fn.instance_of?(String) ? File.new(io_or_fn) : io
|
71
|
+
io.gets # header
|
72
|
+
res = []
|
73
|
+
for line in io
|
74
|
+
f = line.chomp.split
|
75
|
+
h = {}
|
76
|
+
h[:chr] = f[0]
|
77
|
+
h[:snp] = f[1]
|
78
|
+
h[:a1] = f[2]
|
79
|
+
h[:a2] = f[3]
|
80
|
+
h[:maf] = f[4].to_f
|
81
|
+
h[:nchrobs] = f[5].to_i
|
82
|
+
|
83
|
+
res << h
|
84
|
+
end
|
85
|
+
|
86
|
+
return res
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jesse Rodriguez
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-11 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: swak
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/bix.rb
|
58
58
|
- lib/bix/fasta.rb
|
59
59
|
- lib/bix/fastq.rb
|
60
|
+
- lib/bix/plink.rb
|
60
61
|
- lib/bix/blast.rb
|
61
62
|
- lib/bix/gtf.rb
|
62
63
|
homepage: https://github.com/jesserod/bixruby
|