Class: BioVcf::VcfHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-vcf/vcfheader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVcfHeader

Returns a new instance of VcfHeader.



22
23
24
# File 'lib/bio-vcf/vcfheader.rb', line 22

def initialize
  @lines = []
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



20
21
22
# File 'lib/bio-vcf/vcfheader.rb', line 20

def lines
  @lines
end

Instance Method Details

#add(line) ⇒ Object



26
27
28
# File 'lib/bio-vcf/vcfheader.rb', line 26

def add line
  @lines << line.strip
end

#column_namesObject



44
45
46
# File 'lib/bio-vcf/vcfheader.rb', line 44

def column_names
  @column_names ||= VcfHeaderParser::get_column_names(@lines)
end

#columnsObject



48
49
50
# File 'lib/bio-vcf/vcfheader.rb', line 48

def columns
  @column ||= column_names.size
end

#num_samplesObject



74
75
76
# File 'lib/bio-vcf/vcfheader.rb', line 74

def num_samples
  @num_samples ||= ( samples == nil ? 0 : samples.size )
end

#printable_header_line(fields) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/bio-vcf/vcfheader.rb', line 52

def printable_header_line(fields)
  fields.map { | field |
    if field == '#samples'
      samples
    else
      field
    end
  }.join("\t")
end

#sample_indexObject



78
79
80
81
82
83
84
# File 'lib/bio-vcf/vcfheader.rb', line 78

def sample_index
  return @sample_index if @sample_index
  index = {}
  samples.each_with_index { |k,i| index[k] = i+9 ; index[k.downcase] = i+9 }
  @sample_index = index
  index
end

#samplesObject



62
63
64
65
66
67
68
# File 'lib/bio-vcf/vcfheader.rb', line 62

def samples
  @samples ||= if column_names.size > 8
                 column_names[9..-1]
               else
                 []
               end
end

#samples_index_arrayObject



70
71
72
# File 'lib/bio-vcf/vcfheader.rb', line 70

def samples_index_array
  @all_samples_index ||= column_names[9..-1].fill{|i| i}
end

#tag(h) ⇒ Object

Add a key value list to the header



31
32
33
34
35
36
37
38
# File 'lib/bio-vcf/vcfheader.rb', line 31

def tag h
  h2 = h.dup
  [:show_help,:skip_header,:verbose,:quiet,:debug].each { |key| h2.delete(key) }
  info = h2.map { |k,v| k.to_s.capitalize+'='+'"'+v.to_s+'"' }.join(',')
  line = '##BioVcf=<'+info+'>'
  @lines.insert(-2,line)
  line
end

#versionObject



40
41
42
# File 'lib/bio-vcf/vcfheader.rb', line 40

def version
  @version ||= lines[0].scan(/##fileformat=VCFv(\d+\.\d+)/)[0][0]
end