X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fassemble_seq_idba;h=fcf13f866790cac67314f340ccad69a10f54df7d;hb=5de6112b70b59420b245ce636a8b2e3c90acbe00;hp=da2f4dab4d4a0b03e56bce0ee8669954f86eb24b;hpb=494dc53ebd515b1e3e9b91bbebf43059899ca4ce;p=biopieces.git diff --git a/bp_bin/assemble_seq_idba b/bp_bin/assemble_seq_idba index da2f4da..fcf13f8 100755 --- a/bp_bin/assemble_seq_idba +++ b/bp_bin/assemble_seq_idba @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -# Copyright (C) 2007-2011 Martin A. Hansen. +# 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 @@ -24,7 +24,7 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -# Assemble sequences in the stream using IDBA. +# Assemble sequences in the stream using idba hybrid. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -32,63 +32,62 @@ require 'maasha/biopieces' require 'maasha/fasta' casts = [] -casts << {:long=>'directory', :short=>'d', :type=>'dir', :mandatory=>true, :default=>nil, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'scaffold', :short=>'s', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'kmer_min', :short=>'k', :type=>'uint', :mandatory=>false, :default=>25, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'kmer_max', :short=>'K', :type=>'uint', :mandatory=>false, :default=>50, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'count_min', :short=>'c', :type=>'uint', :mandatory=>false, :default=>2, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'cover', :short=>'C', :type=>'uint', :mandatory=>false, :default=>0, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'pairs_min', :short=>'p', :type=>'uint', :mandatory=>false, :default=>5, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'prefix_len', :short=>'P', :type=>'uint', :mandatory=>false, :default=>3, :allowed=>nil, :disallowed=>nil} -casts << {:long=>'clean', :short=>'x', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'directory', :short=>'d', :type=>'dir', :mandatory=>true, :default=>nil, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'kmer_min', :short=>'k', :type=>'uint', :mandatory=>false, :default=>20, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'kmer_max', :short=>'K', :type=>'uint', :mandatory=>false, :default=>100, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'count_min', :short=>'c', :type=>'uint', :mandatory=>false, :default=>2, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'pairs_min', :short=>'p', :type=>'uint', :mandatory=>false, :default=>3, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'prefix_len', :short=>'P', :type=>'uint', :mandatory=>false, :default=>3, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'cpus', :short=>'C', :type=>'uint', :mandatory=>false, :default=>1, :allowed=>nil, :disallowed=>nil} +casts << {:long=>'clean', :short=>'X', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} -bp = Biopieces.new - -options = bp.parse(ARGV, casts) +options = Biopieces.options_parse(ARGV, casts) Dir.mkdir(options[:directory]) unless Dir.exists?(options[:directory]) -file_fasta = [options[:directory], "IDBA"].join(File::SEPARATOR) + ".fna" - -Fasta.open(file_fasta, mode="w") do |fasta_io| - bp.each_record do |record| - fasta_io.puts record - end -end - -unless File.size(file_fasta) == 0 - output = [options[:directory], "IDBA"].join(File::SEPARATOR) - - commands = [] - commands << "nice -n 19" - commands << "idba" - commands << "--read #{file_fasta}" - commands << "--output #{output}" - commands << "--scaffold" if options[:scaffold] - commands << "--mink #{options[:kmer_min]}" - commands << "--maxk #{options[:kmer_max]}" - commands << "--minCount #{options[:count_min]}" - commands << "--cover #{options[:cover]}" - commands << "--minPairs #{options[:pairs_min]}" - commands << "--prefixLength #{options[:prefix_len]}" - commands << "> /dev/null 2>&1" unless options[:verbose] - - command = commands.join(" ") - - begin - system(command) - raise "Command failed: #{command}" unless $?.success? - rescue - $stderr.puts "Command failed: #{command}" - end - - file_contig = [options[:directory], "IDBA"].join(File::SEPARATOR) + "-contig.fa" - - Fasta.open(file_contig, mode="r") do |fasta_io| - fasta_io.each do |entry| - bp.puts entry.to_bp - end - end +file_fasta = File.join(options[:directory], "IDBA-HYBRID") + ".fna" + +count = 0 + +Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| + Fasta.open(file_fasta, "w") do |fasta_io| + input.each_record do |record| + if record[:SEQ_NAME] and record[:SEQ] + seq = Seq.new_bp(record) + + fasta_io.puts seq.to_fasta + end + end + end + + unless File.size(file_fasta) == 0 + prefix = File.join(options[:directory], "IDBA-HYBRID") + + commands = [] + commands << "idba_hybrid" + commands << "--read #{file_fasta}" + commands << "--out #{prefix}" + commands << "--mink #{options[:kmer_min]}" + commands << "--maxk #{options[:kmer_max]}" + commands << "--min_count #{options[:count_min]}" + commands << "--min_pairs #{options[:pairs_min]}" + commands << "--prefix #{options[:prefix_len]}" + commands << "--num_threads #{options[:cpus]}" + commands << "> /dev/null 2>&1" unless options[:verbose] + + command = commands.join(" ") + + system(command) + raise "Command failed: #{command}" unless $?.success? + + file_contig = File.join(options[:directory], "IDBA-HYBRID", "contig.fa") + + Fasta.open(file_contig, "r") do |fasta_io| + fasta_io.each do |entry| + output.puts entry.to_bp + end + end + end end FileUtils.remove_entry_secure file_fasta