3 # Copyright (C) 2007-2011 Martin A. Hansen.
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.
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.
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.
19 # http://www.gnu.org/copyleft/gpl.html
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23 # This program is part of the Biopieces framework (www.biopieces.org).
25 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27 # Find MID tags in sequences in the stream.
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 require 'maasha/biopieces'
210 def initialize(mid_hash, pos, size, max_mismatches)
214 @max_mismatches = max_mismatches
219 tag = seq[@pos ... @pos + @size].upcase.to_sym
221 if @mid_hash.has_key? tag
222 return MID.new(tag, @mid_hash[tag], @pos, @size, hamming_dist)
223 elsif @max_mismatches > 0
224 @mid_hash.each_pair do |mid, mid_name|
225 hamming_dist = tag.to_s.hamming_distance(mid.to_s)
227 if hamming_dist <= @max_mismatches
228 return MID.new(mid, @mid_hash[mid], @pos, @size, hamming_dist)
238 # Class to hold a MID object.
240 attr_accessor :tag, :name, :pos, :len, :mismatches
242 def initialize(tag, name, pos, len, mismatches)
247 @mismatches = mismatches
253 hash[:MID_NAME] = @name
254 hash[:MID_POS] = @pos
255 hash[:MID_LEN] = @len
256 hash[:MID_MISMATCHES] = @mismatches
266 casts << {:long=>'pos', :short=>'p', :type=>'uint', :mandatory=>false, :default=>0, :allowed=>nil, :disallowed=>nil}
267 casts << {:long=>'mismatches', :short=>'m', :type=>'uint', :mandatory=>false, :default=>0, :allowed=>"0,1,2", :disallowed=>nil}
268 casts << {:long=>'gsmids', :short=>'g', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
269 casts << {:long=>'rlmids', :short=>'r', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
271 options = Biopieces.options_parse(ARGV, casts)
273 raise "Can't remove only GSMIDs and only RLMIDs simultaniously." if options[:rlmids] and options[:gsmids]
276 mismatches = options[:mismatches]
278 gsfinder = MIDfinder.new(GSMID_HASH, options[:pos], GS_SIZE, options[:mismatches])
279 rlfinder = MIDfinder.new(RLMID_HASH, options[:pos], RL_SIZE, options[:mismatches])
281 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
282 input.each_record do |record|
283 if record.has_key? :SEQ
286 mid = gsfinder.find_mid(record[:SEQ])
287 elsif options[:rlmids]
288 mid = rlfinder.find_mid(record[:SEQ])
290 mid = gsfinder.find_mid(record[:SEQ]) || rlfinder.find_mid(record[:SEQ])
294 record.merge!(mid.to_hash)
296 record[:SEQ] = record[:SEQ][mid.start .. -1]
297 record[:SCORES] = record[:SCORES][mid.start .. -1] if record[:SCORES]
298 record[:SEQ_LEN] = record[:SEQ].length
307 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<