]> git.donarmstrong.com Git - biopieces.git/commitdiff
added hmmer_seq biopiece
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 2 May 2012 17:57:20 +0000 (17:57 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 2 May 2012 17:57:20 +0000 (17:57 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1814 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/hmmer_seq [new file with mode: 0755]

diff --git a/bp_bin/hmmer_seq b/bp_bin/hmmer_seq
new file mode 100755 (executable)
index 0000000..4cb9fa2
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/env ruby
+
+# Copyright (C) 2007-2012 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This program is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# HMMER search sequences in the stream against a specified database.
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+require 'pp'
+require 'maasha/biopieces'
+require 'maasha/fasta'
+
+class Hmmer
+  def initialize(output_file, options)
+    @output_file = output_file
+    @options     = options
+    @command     = []
+  end
+
+  def search_db(query_file)
+    @command << "hmmsearch"
+    @command << "--tblout #{@output_file}"
+    @command << "--cpu #{@options[:cpus]}"
+    @command << @options[:database]
+    @command << query_file
+
+    execute
+  end
+
+  def each
+    File.open(@output_file, "r") do |ios|
+      ios.each_line do |line|
+        puts "line->#{line}"
+      end
+    end
+  end
+
+  private
+
+  # Method to execute a command using a system() call.
+  # The command is composed of bits from the @command variable.
+  def execute
+    @command.unshift "nice -n 19"
+    @command << "> /dev/null 2>&1" unless @options[:verbose]
+
+    command = @command.join(" ")
+    $stderr.puts "Running command: #{command}" if @options[:verbose]
+    system(command)
+    raise "Command failed: #{command}" unless $?.success?
+
+    @command = []
+  end
+end
+
+casts = []
+casts << {:long=>'database', :short=>'d', :type=>'file!', :mandatory=>true,  :default=>nil, :allowed=>nil, :disallowed=>nil}
+casts << {:long=>'cpus',     :short=>'c', :type=>'uint',  :mandatory=>false, :default=>1,   :allowed=>nil, :disallowed=>"0"}
+
+options     = Biopieces.options_parse(ARGV, casts)
+tmpdir      = Biopieces.mktmpdir
+output_file = File.join(tmpdir, "output.tab")
+query_file  = File.join(tmpdir, "query.fna")
+
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+  Fasta.open(query_file, "w") do |fasta_io|
+    input.each_record do |record|
+      if record[:SEQ_NAME] and record[:SEQ]
+        entry = Seq.new_bp(record)
+
+        fasta_io.puts entry.to_fasta
+      end
+
+      output.puts record
+    end
+  end
+
+  hm = Hmmer.new(output_file, options)
+  hm.search_db(query_file)
+
+  hm.each do |hit|
+    output.puts hit.to_bp
+  end
+end
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__