From: martinahansen Date: Fri, 20 Jan 2012 14:09:51 +0000 (+0000) Subject: changed Align.muscle to file based instead of popen3 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ca8b9fa23e12c8b79a60ee0ded64a3ebbb849aad;p=biopieces.git changed Align.muscle to file based instead of popen3 git-svn-id: http://biopieces.googlecode.com/svn/trunk@1729 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/align.rb b/code_ruby/lib/maasha/align.rb index 0a56dbc..16e0d63 100755 --- a/code_ruby/lib/maasha/align.rb +++ b/code_ruby/lib/maasha/align.rb @@ -23,7 +23,7 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< require 'pp' -require 'open3' +require 'tempfile' require 'narray' require 'maasha/fasta' @@ -79,35 +79,37 @@ ROW_T = 1 ROW_C = 2 ROW_G = 3 -# Adding an initialize method to the existing Fasta class. -class Fasta - def initialize(io) - @io = io - end -end - # Class for aligning sequences. class Align # Class method to align sequences in a list of Seq objects and # return these as a new list of Seq objects. - def self.muscle(entries) - result = [] - index = {} + def self.muscle(entries, verbose = false) + file_in = Tempfile.new("input") + file_out = Tempfile.new("output") + result = [] + index = {} - Open3.popen3("muscle") do |stdin, stdout, stderr| + Fasta.open(file_in, "w") do |ios| entries.each do |entry| raise AlignError, "Duplicate sequence name: #{entry.seq_name}" if index.has_key? entry.seq_name index[entry.seq_name] = entry - stdin.puts entry.to_fasta + ios.puts entry.to_fasta end + end - stdin.close + if verbose + cmd = "muscle < #{file_in.path} > #{file_out.path}" + else + cmd = "muscle -quiet < #{file_in.path} > #{file_out.path}" + end - aligned_entries = Fasta.new(stdout) + system(cmd) + raise AlignError, "command failed: #{cmd}" unless $?.success? - aligned_entries.each do |fa_entry| + Fasta.open(file_out, "r") do |ios| + ios.each do |fa_entry| fq_entry = index[fa_entry.seq_name] fa_entry.seq.scan(/-+/) do |m|