class Bio::Spoctopus::Wrapper

Constants

BLOCTOPUS_DEFAULT_PATH
SPOCTOPUS_DEFAULT_PATH
TMP_SEQUENCE_NAME

Attributes

bloctopus_executable[RW]

The path to the BLOCTOPUS executable, by default BLOCTOPUS_DEFAULT_PATH

spoctopus_executable[RW]

The path to the SPOCTOPUS executable, by default SPOCTOPUS_DEFAULT_PATH

Public Instance Methods

calculate(sequence, blast_database_path) click to toggle source
# File lib/bio/appl/octopus.rb, line 18
def calculate(sequence, blast_database_path)
  # Remove stop codons, as these mess things up for the predictor
  sequence.gsub!('*','')

  rio(:tempdir) do |d| # Do all the work in a temporary directory
    FileUtils.cd(d.to_s) do
    
      # Create the input files
      # * the names file (in base directory)
      # * the fasta file with the sequence in it (in fasta directory)
      # * output file directory

      names = File.open('names','w')
      names.puts TMP_SEQUENCE_NAME
      names.close

      Dir.mkdir 'fasta'
      fastafile = File.open("fasta/#{TMP_SEQUENCE_NAME}.fa", 'w')
      fastafile.puts '>wrapperSeq'
      fastafile.puts "#{sequence}"
      fastafile.close

      Dir.mkdir 'tmd'

      # First, run BLOCTOPUS to create the profiles
      #
      # ben@ben:~/bioinfo/spoctopus$ ./BLOCTOPUS.sh /tmp/spoctopus/names /tmp/spoctopus/fa
      # /tmp/spoctopus/tmd blastall blastpgp`
      # /blastdb/UniProt15/uniprot_sprot.fasta makemat -P
      #
      Tempfile.open('octopuserr') do |err|
        result = system [
          @bloctopus_executable.nil? ? BLOCTOPUS_DEFAULT_PATH : @bloctopus_executable,
          "#{Dir.pwd}/names",
          "#{Dir.pwd}/fasta",
          "#{Dir.pwd}/tmd",
          'blastall',
          'blastpgp',
          "'#{blast_database_path}'",
          'makemat',
          '-P',
          '>/dev/null', # SPOCTOPUS doesn't understand the concept of STDERR
          "2>#{err.path}"
        ].join(' ')

        if !result
          raise Exception, "Running BLOCTOPUS program failed. $? was #{$?.inspect}. Has it been installed properly? STDERR: #{File.open(err.path).read}"
        end
      end

      # Now run SPOCTOPUS to do the actual prediction of SP and TMD,
      # given the profile.
      # ./SPOCTOPUS.sh /tmp/spoctopus/names
      # /tmp/spoctopus/tmd/PSSM_PRF_FILES/
      # /tmp/spoctopus/tmd/RAW_PRF_FILES/
      # /tmp/spoctopus/tmd/
      Tempfile.open('octopuserr') do |err|
        result = system [
          @spoctopus_executable.nil? ? SPOCTOPUS_DEFAULT_PATH : @soctopus_executable,
          "#{Dir.pwd}/names",
          "#{Dir.pwd}/tmd/PSSM_PRF_FILES/",
          "#{Dir.pwd}/tmd/RAW_PRF_FILES/",
          "#{Dir.pwd}/tmd/",
          '>/dev/null', # SPOCTOPUS doesn't understand the concept of STDERR
          "2>#{err.path}"
        ].join(' ')

        if !result
          raise Exception, "Running SPOCTOPUS program failed. $? was #{$?.inspect}. Has it been installed properly? STDERR: #{File.open(err.path).read}"
        end
      end
      
      return Result.create_from_output(File.open("tmd/#{TMP_SEQUENCE_NAME}.top").read)
    end
  end
end