Class: YouAndMe::DataProcessor
- Inherits:
-
Object
- Object
- YouAndMe::DataProcessor
- Defined in:
- lib/youandme/data_processor.rb
Instance Attribute Summary collapse
-
#both_rsid ⇒ Object
Returns the value of attribute both_rsid.
-
#left ⇒ Object
Returns the value of attribute left.
-
#multimarkdown_text ⇒ Object
Returns the value of attribute multimarkdown_text.
-
#right ⇒ Object
Returns the value of attribute right.
-
#rsid_diff ⇒ Object
Returns the value of attribute rsid_diff.
-
#rsid_same ⇒ Object
Returns the value of attribute rsid_same.
Instance Method Summary collapse
-
#initialize(left, right) ⇒ DataProcessor
constructor
A new instance of DataProcessor.
- #process(status = false) ⇒ Object
- #to_multimarkdown(left_file, right_file) ⇒ Object
- #write_html(path) ⇒ Object
- #write_latex(path) ⇒ Object
- #write_multimarkdown(path) ⇒ Object
Constructor Details
#initialize(left, right) ⇒ DataProcessor
Returns a new instance of DataProcessor.
19 20 21 22 23 24 25 26 |
# File 'lib/youandme/data_processor.rb', line 19 def initialize(left, right) @left = left @right = right # @rsid_same = nil # @rsid_diff = nil # @both_rsid = nil # process end |
Instance Attribute Details
#both_rsid ⇒ Object
Returns the value of attribute both_rsid.
14 15 16 |
# File 'lib/youandme/data_processor.rb', line 14 def both_rsid @both_rsid end |
#left ⇒ Object
Returns the value of attribute left.
10 11 12 |
# File 'lib/youandme/data_processor.rb', line 10 def left @left end |
#multimarkdown_text ⇒ Object
Returns the value of attribute multimarkdown_text.
16 17 18 |
# File 'lib/youandme/data_processor.rb', line 16 def multimarkdown_text @multimarkdown_text end |
#right ⇒ Object
Returns the value of attribute right.
11 12 13 |
# File 'lib/youandme/data_processor.rb', line 11 def right @right end |
#rsid_diff ⇒ Object
Returns the value of attribute rsid_diff.
13 14 15 |
# File 'lib/youandme/data_processor.rb', line 13 def rsid_diff @rsid_diff end |
#rsid_same ⇒ Object
Returns the value of attribute rsid_same.
12 13 14 |
# File 'lib/youandme/data_processor.rb', line 12 def rsid_same @rsid_same end |
Instance Method Details
#process(status = false) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/youandme/data_processor.rb', line 80 def process(status = false) puts "Creating indexes..." if status puts "\tIndexing left data..." if status @left_rsid = @left.collect do |n| n[:rsid] end @left_chromosome = @left.collect do |n| n[:chromosome] end @left_position = @left.collect do |n| n[:position] end @left_genotype = @left.collect do |n| n[:genotype] end puts "\tIndexing right data..." if status @right_rsid = @right.collect do |n| n[:rsid] end @right_chromosome = @right.collect do |n| n[:chromosome] end @right_position = @right.collect do |n| n[:position] end @right_genotype = @right.collect do |n| n[:genotype] end puts "Computing stuff..." if status puts "\tDetecting basic commonalities..." if status @both_rsid = @left_rsid & @right_rsid both_position = @left_position & @right_position puts "\tFinding dissimilar genotypes..." if status @rsid_same = [] @rsid_diff = [] @both_rsid.each do |rsid| l = left[@left_rsid.index(rsid)] r = right[@right_rsid.index(rsid)] if l[:genotype] == r[:genotype] @rsid_same << [l, r] else @rsid_diff << [l, r] end end end |
#to_multimarkdown(left_file, right_file) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/youandme/data_processor.rb', line 71 def to_multimarkdown(left_file, right_file) @left_file = left_file @right_file = right_file dir = File.dirname(File.(__FILE__)) template_file = File.join(dir, 'report.md.erb') template = ERB.new(File.read(template_file)) @multimarkdown_text = template.result(binding) end |
#write_html(path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/youandme/data_processor.rb', line 45 def write_html(path) # Write the default file first. file_path = File.join(path, "report.html") puts "\tHTML #{file_path}..." report = File.open(file_path, 'w') mmd = MultiMarkdown.new(@multimarkdown_text, :smart, :filter_html) report.write mmd.to_html report.close # Load the XSL Transform. stylesheet_doc = XML::Document.file(File.join(File.dirname(__FILE__), 'xhtml-toc.xslt')) stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet_doc) # Apply it and re-write the document. old_html = XML::Document.file(file_path) new_html = stylesheet.apply(old_html) report = File.open(file_path, 'w') report.write new_html report.close # Copy the CSS file into place. css_src = File.join(File.dirname(__FILE__), 'report.css') css_dest = File.join(path, 'report.css') FileUtils.copy(css_src, css_dest) end |
#write_latex(path) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/youandme/data_processor.rb', line 36 def write_latex(path) file_path = File.join(path, "report.ltx") puts "\tLaTeX #{file_path}..." report = File.open(file_path, 'w') mmd = MultiMarkdown.new(@multimarkdown_text) report.write mmd.to_latex report.close end |
#write_multimarkdown(path) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/youandme/data_processor.rb', line 28 def write_multimarkdown(path) file_path = File.join(path, "report.md") puts "\tMultiMarkdown #{file_path}..." report = File.open(file_path, 'w') report.write @multimarkdown_text report.close end |