lib/npsearch/signalp.rb in npsearch-2.0.1 vs lib/npsearch/signalp.rb in npsearch-2.1.0
- old
+ new
@@ -1,25 +1,44 @@
require 'forwardable'
-require 'tempfile'
+# Top level module / namespace.
module NpSearch
# A class to hold sequence data
class Signalp
class << self
extend Forwardable
def_delegators NpSearch, :opt
def analyse_sequence(seq)
sp_headers = %w(name cmax cmax_pos ymax ymax_pos smax smax_pos smean d
- sp dmaxcut networks)
- f = Tempfile.new('signalp')
- f.write(">seq\n#{seq}")
- f.close
- s = `#{opt[:signalp_path]} -t euk -f short -U 0.3 -u 0.3 '#{f.path}' | \
- sed -n '3 p'`
- Hash[sp_headers.map(&:to_sym).zip(s.split)]
- ensure
- f.unlink
+ sp dmaxcut networks orf)
+ data = setup_analysis(seq)
+ orf_results = []
+ s = `echo "#{data[:fasta]}\n" | #{opt[:signalp_path]} -t euk \
+ -f short -U 0.34 -u 0.34`
+ sp_results = s.split("\n").delete_if { |l| l[0] == '#' }
+ sp_results.each_with_index do |line, idx|
+ line = line + ' ' + data[:seq][idx].to_s
+ orf_results << Hash[sp_headers.map(&:to_sym).zip(line.split)]
+ end
+ orf_results.sort_by { |h| h[:d] }.reverse[0]
+ end
+
+ def setup_analysis(seq)
+ if opt[:type] == :protein
+ data = { seq: [seq], fasta: ">seq\n#{seq}" }
+ else
+ orfs = seq.scan(/(?=(M\w+))./).flatten
+ orfs.unshift(seq)
+ data = { seq: orfs, fasta: create_orf_fasta(orfs) }
+ end
+ data
+ end
+
+ def create_orf_fasta(m_orf)
+ fasta = ''
+ m_orf.each_with_index { |seq, idx| fasta << ">#{idx}\n#{seq}\n" }
+ fasta
end
end
end
end