]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/find_orphans
created find_orphans Biopiece
[biopieces.git] / bp_bin / find_orphans
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2007-2013 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 # Identify paired end orphan in records with sequence data.
28
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30
31 require 'maasha/biopieces'
32 require 'pp'
33
34 options = Biopieces.options_parse(ARGV)
35
36 class Illumina
37   def self.name_match?(name1, name2)
38
39     if name1[-2] == '/'
40       name1[0 .. -3 ] == name2[0 .. -3]                # Solexa and Illumina <= 1.5 version names
41     else
42       name1.split(" ").first == name2.split(" ").first # Illumina > 1.5 version names
43     end
44   end
45 end
46
47 records = []
48
49 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
50   input.each_record do |record|
51     records << record
52
53     if records.size == 2
54       if Illumina.name_match?(records.first[:SEQ_NAME], records.last[:SEQ_NAME])
55         records.first[:TYPE] = "paired"
56         records.last[:TYPE]  = "paired"
57
58         output.puts records.first
59         output.puts records.last
60
61         records = []
62       else
63         records.first[:TYPE] = "orphan"
64         output.puts records.first
65
66         records.shift
67       end
68     end
69   end
70
71   records.each do |record|
72     record[:TYPE] = "orphan"
73     output.puts record
74   end
75 end
76
77
78 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
79
80
81 __END__