lib/neurohmmer/output.rb in neurohmmer-0.1.0 vs lib/neurohmmer/output.rb in neurohmmer-0.1.1
- old
+ new
@@ -1,20 +1,22 @@
-require 'slim'
require 'forwardable'
+require 'slim'
+require 'neurohmmer/signalp'
+
# Top level module / namespace.
module Neurohmmer
# A class that holds methods related to Output
class Output
class <<self
extend Forwardable
- def_delegators Neurohmmer, :conf
+ def_delegators Neurohmmer, :opt, :conf
def to_html(hmm_results)
@html_results = format_seqs_for_html(hmm_results)
- template_path = File.expand_path(File.join(__FILE__, '../../../',
- 'template/contents.slim'))
+ 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
@@ -33,18 +35,46 @@
private
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
+
+ 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
+
+ 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(/^\w+?>/,'')
+ 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
end
end
end