]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/findsim_seq
fixed seq qual length check
[biopieces.git] / bp_bin / findsim_seq
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2007-2012 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 # Find similar sequences between query sequences from the stream and a database.
28
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30
31 require 'pp'
32 require 'maasha/biopieces'
33 require 'maasha/fasta'
34 require 'maasha/findsim'
35
36 casts = []
37 casts << {:long=>'database',      :short=>'d', :type=>'file!', :mandatory=>true,  :default=>nil, :allowed=>nil,           :disallowed=>nil}
38 casts << {:long=>'kmer',          :short=>'k', :type=>'uint',  :mandatory=>false, :default=>8,   :allowed=>"4,5,6,7,8,9", :disallowed=>nil}
39 casts << {:long=>'step',          :short=>'s', :type=>'uint',  :mandatory=>false, :default=>1,   :allowed=>nil,           :disallowed=>"0"}
40 casts << {:long=>'min_score',     :short=>'m', :type=>'float', :mandatory=>false, :default=>0.5, :allowed=>nil,           :disallowed=>nil}
41 casts << {:long=>'max_hits',      :short=>'h', :type=>'uint',  :mandatory=>false, :default=>20,  :allowed=>nil,           :disallowed=>"0"}
42 casts << {:long=>'max_diversity', :short=>'M', :type=>'float', :mandatory=>false, :default=>nil, :allowed=>nil,           :disallowed=>nil}
43 casts << {:long=>'query_ids',     :short=>'Q', :type=>'flag',  :mandatory=>false, :default=>nil, :allowed=>nil,           :disallowed=>nil}
44 casts << {:long=>'subject_ids',   :short=>'S', :type=>'flag',  :mandatory=>false, :default=>nil, :allowed=>nil,           :disallowed=>nil}
45 casts << {:long=>'realign',       :short=>'r', :type=>'flag',  :mandatory=>false, :default=>nil, :allowed=>nil,           :disallowed=>nil}
46
47 options    = Biopieces.options_parse(ARGV, casts)
48 tmpdir     = Biopieces.mktmpdir
49 query_file = File.join(tmpdir, "query.fna")
50
51 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
52   Fasta.open(query_file, "w") do |fasta_io|
53     input.each_record do |record|
54       if record[:SEQ_NAME] and record[:SEQ]
55         entry = Seq.new_bp(record)
56
57         fasta_io.puts entry.to_fasta
58       end
59
60       output.puts record
61     end
62   end
63
64   fs = FindSim.new(options)
65   fs.load_query(query_file)
66   fs.search_db(options[:database])
67
68   fs.each do |hit|
69     output.puts hit.to_bp
70   end
71 end
72
73 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
74
75
76 __END__