]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/assemble_seq_idba
removed name option from asseble_seq_idba
[biopieces.git] / bp_bin / assemble_seq_idba
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2007-2011 Martin A. Hansen.
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
22
23 # This program is part of the Biopieces framework (www.biopieces.org).
24
25 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26
27 # Assemble sequences in the stream using IDBA.
28
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30
31 require 'biopieces'
32 require 'fasta'
33
34 casts = []
35 casts << {:long=>'directory',  :short=>'d', :type=>'dir',    :mandatory=>true,  :default=>nil, :allowed=>nil, :disallowed=>nil}
36 casts << {:long=>'scaffold',   :short=>'s', :type=>'flag',   :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
37 casts << {:long=>'kmer_min',   :short=>'k', :type=>'uint',   :mandatory=>false, :default=>25,  :allowed=>nil, :disallowed=>nil}
38 casts << {:long=>'kmer_max',   :short=>'K', :type=>'uint',   :mandatory=>false, :default=>50,  :allowed=>nil, :disallowed=>nil}
39 casts << {:long=>'count_min',  :short=>'c', :type=>'uint',   :mandatory=>false, :default=>2,   :allowed=>nil, :disallowed=>nil}
40 casts << {:long=>'cover',      :short=>'C', :type=>'uint',   :mandatory=>false, :default=>0,   :allowed=>nil, :disallowed=>nil}
41 casts << {:long=>'pairs_min',  :short=>'p', :type=>'uint',   :mandatory=>false, :default=>5,   :allowed=>nil, :disallowed=>nil}
42 casts << {:long=>'prefix_len', :short=>'P', :type=>'uint',   :mandatory=>false, :default=>3,   :allowed=>nil, :disallowed=>nil}
43 casts << {:long=>'clean',      :short=>'x', :type=>'flag',   :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
44
45 bp = Biopieces.new
46
47 options = bp.parse(ARGV, casts)
48
49 Dir.mkdir(options[:directory]) unless Dir.exists?(options[:directory])
50
51 file_fasta = [options[:directory], "IDBA"].join(File::SEPARATOR) + ".fna"
52
53 Fasta.open(file_fasta, mode="w") do |fasta_io|
54   bp.each_record do |record|
55     fasta_io.puts record
56   end
57 end
58
59 unless File.size(file_fasta) == 0
60   output = [options[:directory], "IDBA"].join(File::SEPARATOR)
61
62   commands = []
63   commands << "nice -n 19"
64   commands << "idba"
65   commands << "--read #{file_fasta}"
66   commands << "--output #{output}"
67   commands << "--scaffold" if options[:scaffold]
68   commands << "--mink #{options[:kmer_min]}"
69   commands << "--maxk #{options[:kmer_max]}"
70   commands << "--minCount #{options[:count_min]}"
71   commands << "--cover #{options[:cover]}"
72   commands << "--minPairs #{options[:pairs_min]}"
73   commands << "--prefixLength #{options[:prefix_len]}"
74   commands << "> /dev/null 2>&1" unless options[:verbose]
75
76   command = commands.join(" ")
77
78   begin
79     system(command)
80     raise "Command failed: #{command}" unless $?.success?
81   rescue
82     $stderr.puts "Command failed: #{command}"
83   end
84
85   file_contig = [options[:directory], "IDBA"].join(File::SEPARATOR) + "-contig.fa"
86
87   Fasta.open(file_contig, mode="r") do |fasta_io|
88     fasta_io.each do |entry|
89       bp.puts entry.to_bp
90     end
91   end
92 end
93
94 FileUtils.remove_entry_secure options[:directory] if options[:clean]
95
96
97 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
98
99
100 __END__