class Neurohmmer::Output
A class that holds methods related to Output
Public Class Methods
format_seqs_for_html(hmm_results)
click to toggle source
# File lib/neurohmmer/output.rb, line 37 def format_seqs_for_html(hmm_results) results = {} hmm_results.each do |query, hits| next if hits.length == 0 results[query] = [] hits.each do |hit| html_seq = format_html_seq(hit[:seq], hit[:flatseq]) results[query] << { id: hit[:id], seq: html_seq } end end results end
to_fasta(hmm_results)
click to toggle source
# File lib/neurohmmer/output.rb, line 14 def to_fasta(hmm_results) File.open(conf[:fasta_output], 'w') do |file| hmm_results.each do |query, hits| next if hits.length == 0 file.puts # a blank line file.puts '# ' + query hits.each do |hit| file.puts '>' + hit[:id] file.puts hit[:seq] end end end end
to_html(hmm_results)
click to toggle source
# File lib/neurohmmer/output.rb, line 28 def to_html(hmm_results) @html_results = format_seqs_for_html(hmm_results) template_path = File.expand_path('../../../template/contents.slim', __FILE__) contents_temp = File.read(template_path) html_content = Slim::Template.new { contents_temp }.render(self) File.open(conf[:html_output], 'w') { |f| f.puts html_content } end
Private Class Methods
add_signalp_formatting(seq, sp_cut_off)
click to toggle source
# File lib/neurohmmer/output.rb, line 72 def add_signalp_formatting(seq, sp_cut_off) s1 = seq[0, sp_cut_off] if s1 =~ /^</ s = seq.gsub(/^<span class=hsp>/, '<span class=sp_hsp>') return s.insert(sp_cut_off + 19, '</span><span class=hsp>') elsif s1 =~ /<span class=hsp>/ s = s1.gsub(/<span class=hsp>/, '</span><span class=sp_hsp>') + seq[sp_cut_off..-1] return s.insert(0, '<span class=sp>') .insert(sp_cut_off + 41, '</span><span class=hsp>') elsif s1 =~ /</ s = s1.gsub(/<.*?$/, '</span><span class=sp_hsp>') + seq[sp_cut_off..-1].gsub(/^.*?>/, '') return s.insert(0, '<span class=sp>') .insert(sp_cut_off + 41, '</span><span class=hsp>') else return seq.insert(0, '<span class=sp>').insert(sp_cut_off + 15, '</span>') end end
format_html_seq(seq, flatseq)
click to toggle source
# File lib/neurohmmer/output.rb, line 52 def format_html_seq(seq, flatseq) seq.gsub!("\n", '') signalp_output = Signalp.analyse_sequence(seq) if opt[:type] == :protein flatseq.each do |hsp| seq.gsub!(/#{hsp.gsub('-', '')}/i, '<span class=hsp>\0</span>') end seq = format_signal_peptide(seq, signalp_output) seq.gsub(/KR|KK|RR/i, '<span class=clv>\0</span>') .gsub(/(K|R)<span class=hsp>(K|R)/i, '<span class=clv>\1</span>' \ '<span class=clv_i>\2</span><span class=hsp>') .gsub('<span class=clv>R</span><span class=clv_i>K</span><span' \ ' class=hsp>', 'R<span class=hsp>K') .gsub(/G<span class=clv>/, '<span class=gly>G</span><span class=clv>') end
format_signal_peptide(seq, sp)
click to toggle source
# File lib/neurohmmer/output.rb, line 67 def format_signal_peptide(seq, sp) return seq if opt[:type] == :genetic || sp[:sp] == 'N' add_signalp_formatting(seq, sp[:ymax_pos].to_i - 1) end