]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/findsim_seq
changed record_scores to max_hits refactoring
[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=>7,   :allowed=>nil,           :disallowed=>"0"}
42 casts << {:long=>'query_ids',   :short=>'Q', :type=>'flag',  :mandatory=>false, :default=>nil, :allowed=>nil,           :disallowed=>nil}
43 casts << {:long=>'subject_ids', :short=>'S', :type=>'flag',  :mandatory=>false, :default=>nil, :allowed=>nil,           :disallowed=>nil}
44
45 options    = Biopieces.options_parse(ARGV, casts)
46 tmpdir     = Biopieces.mktmpdir
47 query_file = File.join(tmpdir, "query.fna")
48
49 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
50   Fasta.open(query_file, "w") do |fasta_io|
51     input.each_record do |record|
52       if record[:SEQ_NAME] and record[:SEQ]
53         entry = Seq.new_bp(record)
54
55         fasta_io.puts entry.to_fasta
56       end
57
58       output.puts record
59     end
60   end
61
62   fs = FindSim.new(options)
63   fs.load_query(query_file)
64   fs.search_db(options[:database])
65
66   fs.each do |hit|
67     output.puts hit.to_bp
68   end
69 end
70
71 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
72
73
74 __END__