Module: Cytogenetics::BandReader

Included in:
Chromosome
Defined in:
lib/cytogenetics/utils/band_reader.rb

Instance Method Summary collapse

Instance Method Details

#bands(chr, file) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/cytogenetics/utils/band_reader.rb', line 8

def bands(chr, file)
  file = File.open(file, 'r') unless file.is_a? File
  bands = read_file(file)
  bds = bands[chr]
  bds.uniq!
  return bds
end

#read_file(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cytogenetics/utils/band_reader.rb', line 16

def read_file(file)
  band_by_chr = {}
  file.each_line do |line|
    line.chomp!
    next if line.start_with?"#"
    line.match(/^(\d+|X|Y)([p|q].*)/)
    c = $1; b = $2
    band_by_chr[c] = Array.new unless band_by_chr.has_key? c
    band_by_chr[c] << "#{c}#{b}"
    band_by_chr[c] << "#{c}#{$1}" if b.match(/([p|q]\d+)\.\d+/)
  end
  return band_by_chr
end