Class: Bio::Spoctopus::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/appl/octopus.rb

Constant Summary collapse

TMP_SEQUENCE_NAME =
'wrapperSeq'
BLOCTOPUS_DEFAULT_PATH =
'BLOCTOPUS.sh'
SPOCTOPUS_DEFAULT_PATH =
'SPOCTOPUS.sh'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bloctopus_executableObject

The path to the BLOCTOPUS executable, by default BLOCTOPUS_DEFAULT_PATH



13
14
15
# File 'lib/bio/appl/octopus.rb', line 13

def bloctopus_executable
  @bloctopus_executable
end

#spoctopus_executableObject

The path to the SPOCTOPUS executable, by default SPOCTOPUS_DEFAULT_PATH



16
17
18
# File 'lib/bio/appl/octopus.rb', line 16

def spoctopus_executable
  @spoctopus_executable
end

Instance Method Details

#calculate(sequence, blast_database_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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