Class: Ytilib::Bismark

Inherits:
Document
  • Object
show all
Defined in:
lib/sequence_logo/ytilib/bismark.rb

Instance Method Summary collapse

Constructor Details

#initialize(source = nil, add_dtd = false) ⇒ Bismark

Returns a new instance of Bismark.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sequence_logo/ytilib/bismark.rb', line 9

def initialize(source = nil, add_dtd = false)
  dtd = add_dtd ? "<!DOCTYPE smallbismark SYSTEM 'smallbismark.dtd'>#{$/}" : ""
  source == nil ? super("<?xml version='1.0' encoding='UTF-8'?>#{$/}#{dtd}") : super(source)
  super(IO.read(source)) if source != nil && root == nil
  if source == nil
    self.add_element("smallbismark")
    # xmlns breaks XPath for a REXML library under Linux, strange, indeed
    # self.add_element("smallbismark", {"xmlns" => "http://bioinform.imb.ac.ru/smallBiSMark/smallbismark.dtd"})
    self.root.add_element("comment", {"name" => "WARNING"}).add_text("This is a draft version of small-BiSMark. Specification is the subject to change!")
  end
end

Instance Method Details

#get_pm(xpath) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sequence_logo/ytilib/bismark.rb', line 29

def get_pm(xpath)
  pwmnode = self.elements[xpath]
  pm = PM.new_pm(pwmnode.attribute("length").value.to_i)
  toi = pwmnode.name == "PCM"
  pwmnode.elements.each("pm-column") { |c|
    position = c.attribute("position").value.to_i - 1
    weights = [c.elements["a"].get_text.value.strip.to_f, 
              c.elements["c"].get_text.value.strip.to_f, 
              c.elements["g"].get_text.value.strip.to_f, 
              c.elements["t"].get_text.value.strip.to_f]
    weights.collect { |w| w.to_i } if toi
    pm['A'][position], pm['C'][position], pm['G'][position], pm['T'][position] = weights[0], weights[1], weights[2], weights[3]
  }
  return pm
end

#getXMLObject Also known as: get_xml



21
22
23
24
25
26
# File 'lib/sequence_logo/ytilib/bismark.rb', line 21

def getXML
  beautify
  s = ""; write(s, 1, true)
  s.rstrip!
  return s
end