3 # Copyright (C) 2007-2012 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 # Order records with pair end sequence data.
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 require 'maasha/biopieces'
38 options = Biopieces.options_parse(ARGV)
40 tmpdir = Biopieces.mktmpdir
42 tmpfile = File.join(tmpdir, "data.gdbm")
44 db = GDBM.new(tmpfile)
46 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
47 input.each_record do |record|
49 db[record[:SEQ_NAME]] = Marshal.dump(record)
57 db.keys.each do |seq_name|
58 next if skip[seq_name]
61 when /^(.+)\/(\d)$/ # Illumina 1.5
65 when /^(.+) (\d):/ # Illumina 1.8
70 $stderr.puts "WARNING: Unmatched sequence name: #{record[:SEQ_NAME]}"
73 pair2 = (pair == 1) ? 2 : 1
76 seq_name2 = "#{name}/#{pair2}"
78 seq_name2 = seq_name.sub(/^(.+) \d:/, "#{$1} #{pair2}:")
81 record1 = Marshal.load(db[seq_name])
82 record2 = db[seq_name2]
83 record2 = Marshal.load(record2) unless record2.nil?
86 record1[:ORDER] = "orphan#{pair}"
89 record1[:ORDER] = "paired"
90 record2[:ORDER] = "paired"
95 skip[seq_name2] = true
102 FileUtils.remove_entry_secure(tmpfile, true)
104 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<