vcf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vcf.rb +60 -0
- metadata +54 -0
data/lib/vcf.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
class Vcf
|
2
|
+
public
|
3
|
+
attr_accessor :chrom, :pos, :id, :ref, :alt, :qual, :filter, :info, :format, :samples
|
4
|
+
|
5
|
+
def initialize(line=nil)
|
6
|
+
samples = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse_line(line, sample_names=nil)
|
10
|
+
f = line.split("\t", -1)
|
11
|
+
raise "VCF lines must have at least 8 fields" if f.size < 8
|
12
|
+
chrom = f[0]
|
13
|
+
pos = f[1].to_i
|
14
|
+
id = f[2]
|
15
|
+
ref = f[3]
|
16
|
+
alt = f[4]
|
17
|
+
qual = f[5].to_i
|
18
|
+
filter = f[6]
|
19
|
+
|
20
|
+
info = {}
|
21
|
+
info_vec = f[7].split(";")
|
22
|
+
info_vec.each do |x|
|
23
|
+
keyval = x.split("=", -1)
|
24
|
+
if keyval.size == 2 # If it's key=value
|
25
|
+
info[keyval[0]] = keyval[1]
|
26
|
+
else # Otherwise, it's just a flag
|
27
|
+
info[x] = ""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
samples = {}
|
32
|
+
return true if f.size == 8 # Has just upto info
|
33
|
+
raise "Can't have format with no samples" if f.size == 9
|
34
|
+
|
35
|
+
format = f[8]
|
36
|
+
|
37
|
+
sample_keys = format.split(":")
|
38
|
+
|
39
|
+
num_samples = f.size - 9 # How many fields are past the format
|
40
|
+
|
41
|
+
if sample_names == nil # Make the sample names just ["1", "2", ... , "num_samples}"
|
42
|
+
sample_names = (1..num_samples).to_a.map{|i| i.to_s}
|
43
|
+
elsif f.size != num_samples
|
44
|
+
raise "Expected #{sample_names.size} but got #{num_samples}"
|
45
|
+
end
|
46
|
+
|
47
|
+
sample_names.each_with_index do |sample_name, sample_index|
|
48
|
+
i = sample_index + 9 # index into columns (f)
|
49
|
+
sample_values = f[i].split(":")
|
50
|
+
raise "Expected number of sample values to match number of sample keys in FORMAT column" if sample_values.size != sample_keys.size
|
51
|
+
samples[sample_name] = {}
|
52
|
+
sample_keys.each_with_index {|key, value_index| samples[sample_name][k] = sample_values[value_index]}
|
53
|
+
end
|
54
|
+
|
55
|
+
return true;
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
attr_accessor :
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vcf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jesse Rodriguez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-01 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Lightweight VCF interface for ruby
|
17
|
+
email: jesserod@cs.stanford.edu
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/vcf.rb
|
26
|
+
homepage: http://rubygems.org/gems/vcf
|
27
|
+
licenses: []
|
28
|
+
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.5
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: VCF (Variant Call Format) interface for ruby
|
53
|
+
test_files: []
|
54
|
+
|