Class: BioVcf::VcfHeader
- Inherits:
-
Object
- Object
- BioVcf::VcfHeader
- Defined in:
- lib/bio-vcf/vcfheader.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #add(line) ⇒ Object
- #column_names ⇒ Object
- #columns ⇒ Object
-
#initialize ⇒ VcfHeader
constructor
A new instance of VcfHeader.
- #num_samples ⇒ Object
- #printable_header_line(fields) ⇒ Object
- #sample_index ⇒ Object
- #samples ⇒ Object
- #samples_index_array ⇒ Object
-
#tag(h) ⇒ Object
Add a key value list to the header.
- #version ⇒ Object
Constructor Details
#initialize ⇒ VcfHeader
Returns a new instance of VcfHeader.
22 23 24 |
# File 'lib/bio-vcf/vcfheader.rb', line 22 def initialize @lines = [] end |
Instance Attribute Details
#lines ⇒ Object (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_names ⇒ Object
44 45 46 |
# File 'lib/bio-vcf/vcfheader.rb', line 44 def column_names @column_names ||= VcfHeaderParser::get_column_names(@lines) end |
#columns ⇒ Object
48 49 50 |
# File 'lib/bio-vcf/vcfheader.rb', line 48 def columns @column ||= column_names.size end |
#num_samples ⇒ Object
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_index ⇒ Object
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 |
#samples ⇒ Object
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_array ⇒ Object
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 |
#version ⇒ Object
40 41 42 |
# File 'lib/bio-vcf/vcfheader.rb', line 40 def version @version ||= lines[0].scan(/##fileformat=VCFv(\d+\.\d+)/)[0][0] end |