Sha256: 106f64cd19d0c5de5ae0051205e7284b2ed620a6940acab95bdd9631be07a860

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

require 'forwardable'
require 'open3'
require 'timeout'

# 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 orf)
        seqs       = setup_analysis(seq)
        sp_results = []
        seqs.each do |seq|
          sp_results << run_signalp(seq, sp_headers)
        end
        sp_results.sort_by { |h| h[:d] }.reverse[0]
      end

      private

      def run_signalp(seq, sp_headers)
        Timeout::timeout(300) do
          cmd = "echo '>seq\n#{seq}\n' | #{opt[:signalp_path]} -t euk" \
                " -f short -U 0.34 -u 0.34"
          stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
          out = stdout.gets(nil).split("\n").delete_if { |l| l[0] == '#' }
          stdin.close; stdout.close; stderr.close
          result = out[0] + ' ' + seq
          return Hash[sp_headers.map(&:to_sym).zip(result.split)]
        end
      rescue Timeout::Error
        no_results = [0,0,1,1,1,1,1,1,1,'N',1,1, seq]
        return Hash[sp_headers.map(&:to_sym).zip(no_results)]
      end

      def setup_analysis(seq)
        orfs = seq.scan(/(?=(M\w{#{opt[:min_orf_length]},}))./).flatten
        (opt[:type] == :protein || orfs.empty? || orfs.nil?) ? [seq] : orfs
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
npsearch-2.1.1 lib/npsearch/signalp.rb