Class: Bio::NCBI::Dbsnp::Bitfield
- Inherits:
-
Object
- Object
- Bio::NCBI::Dbsnp::Bitfield
- Defined in:
- lib/bio/ncbi/dbsnp/bitfield.rb
Instance Attribute Summary collapse
-
#byte_stream ⇒ Object
readonly
Returns the value of attribute byte_stream.
Class Method Summary collapse
Instance Method Summary collapse
-
#allele_frequency ⇒ Object
field F4.
- #field(fnum) ⇒ Object
-
#gene_function ⇒ Object
field F2.
-
#genotype ⇒ Object
field F5.
-
#initialize(byte_stream) ⇒ Bitfield
constructor
A new instance of Bitfield.
-
#mapping ⇒ Object
field F3.
-
#phenotype ⇒ Object
field F7.
-
#quality_check ⇒ Object
field F9.
-
#resource_link ⇒ Object
field F1.
-
#validation ⇒ Object
field F6.
-
#variation_class ⇒ Object
field F8.
-
#version ⇒ Object
field F0.
Constructor Details
#initialize(byte_stream) ⇒ Bitfield
Returns a new instance of Bitfield.
6 7 8 9 10 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 6 def initialize(byte_stream) @byte_stream = byte_stream ver = version raise "Unsupported bitfield version (ver.#{ver})" unless ver == 5 end |
Instance Attribute Details
#byte_stream ⇒ Object (readonly)
Returns the value of attribute byte_stream.
12 13 14 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 12 def byte_stream @byte_stream end |
Class Method Details
.parse(bitfield_str) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 14 def self.parse(bitfield_str) byte_stream = Array.new bitfield_str.tr("_","").chars.each_slice(2) do |byte_str| byte_stream << Integer("0x#{byte_str.join("")}") end self.new(byte_stream) end |
Instance Method Details
#allele_frequency ⇒ Object
field F4
98 99 100 101 102 103 104 105 106 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 98 def allele_frequency fld = field(4) res = Array.new res << :mutation if bit? fld, 0b1000 res << :validated if bit? fld, 0b0100 res << :maf_gt5_each_and_all_populations if bit? fld, 0b0010 res << :maf_gt5_in_1plus_populations if bit? fld, 0b0001 res end |
#field(fnum) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 22 def field(fnum) case fnum when 0 byte_stream[0] when 1 (byte_stream[2] << 8) + byte_stream[1] when 2 (byte_stream[4] << 8) + byte_stream[3] else byte_stream[fnum + 2] end end |
#gene_function ⇒ Object
field F2
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 63 def gene_function fld = field(2) res = Array.new res << :stop_loss if bit? fld, 0b10_0000_0000_0000 res << :non_synonymous_frameshift if bit? fld, 0b01_0000_0000_0000 res << :non_synonymous_missense if bit? fld, 0b00_1000_0000_0000 res << :stop_gain if bit? fld, 0b00_0100_0000_0000 res << :reference if bit? fld, 0b00_0010_0000_0000 res << :synonymous if bit? fld, 0b00_0001_0000_0000 res << :utr_3p if bit? fld, 0b00_0000_1000_0000 res << :utr_5p if bit? fld, 0b00_0000_0100_0000 res << :acceptor_splice_site if bit? fld, 0b00_0000_0010_0000 res << :donor_splice_site if bit? fld, 0b00_0000_0001_0000 res << :intron if bit? fld, 0b00_0000_0000_1000 res << :gene_region_3p if bit? fld, 0b00_0000_0000_0100 res << :gene_region_5p if bit? fld, 0b00_0000_0000_0010 res << :gene_segment if bit? fld, 0b00_0000_0000_0001 res end |
#genotype ⇒ Object
field F5
109 110 111 112 113 114 115 116 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 109 def genotype fld = field(5) res = Array.new res << :high_density if bit? fld, 0b0100 res << :haplotype_tagging_set if bit? fld, 0b0010 res << :available if bit? fld, 0b0001 res end |
#mapping ⇒ Object
field F3
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 84 def mapping fld = field(3) res = Array.new res << :other_snp if bit? fld, 0b1_0000 res << :assembly_conflict if bit? fld, 0b0_1000 res << :assembly_specific if bit? fld, 0b0_0100 res << :weight3 if bit? fld, 0b0_0011 res << :weight2 if bit? fld, 0b0_0010 res << :weight1 if bit? fld, 0b0_0001 res << :unmapped if (fld & 0b0000_0011) == 0 res end |
#phenotype ⇒ Object
field F7
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 133 def phenotype fld = field(7) res = Array.new res << :mesh_disease if bit? fld, 0b1000_0000 res << :clinical_diagnosis if bit? fld, 0b0100_0000 res << :transciption_factor if bit? fld, 0b0010_0000 res << :locus_specific_database if bit? fld, 0b0001_0000 res << :dbgap_p_valued if bit? fld, 0b0000_1000 res << :dbgap_lod if bit? fld, 0b0000_0100 res << :tpa_gwas_page if bit? fld, 0b0000_0010 res << :omim_omia if bit? fld, 0b0000_0001 res end |
#quality_check ⇒ Object
field F9
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 172 def quality_check fld = field(9) res = Array.new res << :suspect if bit? fld, 0b00_0000_0100_0000 res << :somatic if bit? fld, 0b00_0000_0010_0000 res << :reference_allele_missing if bit? fld, 0b00_0000_0001_0000 res << :withdrawn_by_submitter if bit? fld, 0b00_0000_0000_1000 res << :no_allele_overlap if bit? fld, 0b00_0000_0000_0100 res << :strain_specific_fiexed_defference if bit? fld, 0b00_0000_0000_0010 res << :genotype_conflict if bit? fld, 0b00_0000_0000_0001 res end |
#resource_link ⇒ Object
field F1
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 41 def resource_link fld = field(1) res = Array.new res << :clinical if bit? fld, 0b100_0000_0000_0000 res << :precious if bit? fld, 0b010_0000_0000_0000 res << :provisional_tpa if bit? fld, 0b001_0000_0000_0000 res << :pubmed_central_article if bit? fld, 0b000_1000_0000_0000 res << :short_read_archive if bit? fld, 0b000_0100_0000_0000 res << :organism_dblink if bit? fld, 0b000_0010_0000_0000 res << :mgc_clone if bit? fld, 0b000_0001_0000_0000 res << :trace_archive if bit? fld, 0b000_0000_1000_0000 res << :assemby_archive if bit? fld, 0b000_0000_0100_0000 res << :entrez_geo if bit? fld, 0b000_0000_0010_0000 res << :peobe_db if bit? fld, 0b000_0000_0001_0000 res << :entrez_gene if bit? fld, 0b000_0000_0000_1000 res << :entrez_sts if bit? fld, 0b000_0000_0000_0100 res << :threed_structure if bit? fld, 0b000_0000_0000_0010 res << :submitter_link_out if bit? fld, 0b000_0000_0000_0001 res end |
#validation ⇒ Object
field F6
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 119 def validation fld = field(6) res = Array.new res << :tgp_2010_production if bit? fld, 0b100_0000 res << :tgp_validated if bit? fld, 0b010_0000 res << :tgp_2010_pilot if bit? fld, 0b001_0000 res << :tgp_2009_phase1 if bit? fld, 0b000_1000 res << :phase_3_genotyped if bit? fld, 0b000_0100 res << :phase_2_genotyped if bit? fld, 0b000_0010 res << :phase_1_genotyped if bit? fld, 0b000_0001 res end |
#variation_class ⇒ Object
field F8
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 148 def variation_class case (field(8) & 0b0000_1111) when 0b0001 :snp when 0b0010 :dips when 0b0011 :heterozygous when 0b0100 :microsatellite when 0b0101 :named_variation when 0b0110 :novariation when 0b0111 :mixed_class when 0b1000 :multibase_polymorphism else raise "Should not happen! Check bitfield verison." end end |
#version ⇒ Object
field F0
36 37 38 |
# File 'lib/bio/ncbi/dbsnp/bitfield.rb', line 36 def version field(0) & 0b0000_1111 end |