1 package Maasha::KISS::IO;
3 # Copyright (C) 2009 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
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Routines for parsing and emitting KISS records.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
35 use vars qw( @ISA @EXPORT );
37 @ISA = qw( Exporter );
54 # 012345678901234567890
55 # --------------------- S.aur complete genome
56 # -===__===- TAG_000001
59 # S_ID = 'S.aur complete genome'
66 # ALIGN => 0:A>T,3:G>C
72 # 'S.aur complete genome' 3 12 'TAG_000001' 1 + 31 2 1,6 3,3
75 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
80 my ( $fh, # file handle
85 my ( $line, @fields, %entry );
87 while ( $line = <$fh> )
91 next if $line =~ /^$|^#/;
93 @fields = split /\t/, $line;
95 Maasha::Common::error( qq( BAD kiss entry: $line) ) if not @fields == 11;
97 $entry{ 'S_ID' } = $fields[ S_ID ];
98 $entry{ 'S_BEG' } = $fields[ S_BEG ];
99 $entry{ 'S_END' } = $fields[ S_END ];
100 $entry{ 'Q_ID' } = $fields[ Q_ID ];
101 $entry{ 'SCORE' } = $fields[ SCORE ];
102 $entry{ 'STRAND' } = $fields[ STRAND ];
103 $entry{ 'HITS' } = $fields[ HITS ];
104 $entry{ 'ALIGN' } = $fields[ ALIGN ];
105 $entry{ 'BLOCK_COUNT' } = $fields[ BLOCK_COUNT ];
106 $entry{ 'BLOCK_BEGS' } = $fields[ BLOCK_BEGS ];
107 $entry{ 'BLOCK_LENS' } = $fields[ BLOCK_LENS ];
109 return wantarray ? %entry : \%entry;
116 my ( $entry, # KISS entry to output
117 $fh, # file handle - OPTIONAL
126 $fields[ S_ID ] = $entry->{ 'S_ID' };
127 $fields[ S_BEG ] = $entry->{ 'S_BEG' };
128 $fields[ S_END ] = $entry->{ 'S_END' };
129 $fields[ Q_ID ] = $entry->{ 'Q_ID' };
130 $fields[ SCORE ] = $entry->{ 'SCORE' };
131 $fields[ STRAND ] = $entry->{ 'STRAND' };
132 $fields[ HITS ] = $entry->{ 'HITS' };
133 $fields[ ALIGN ] = $entry->{ 'ALIGN' };
134 $fields[ BLOCK_COUNT ] = $entry->{ 'BLOCK_COUNT' };
135 $fields[ BLOCK_BEGS ] = $entry->{ 'BLOCK_BEGS' };
136 $fields[ BLOCK_LENS ] = $entry->{ 'BLOCK_LENS' };
138 print $fh join( "\t", @fields ), "\n";
144 my ( $entry, # KISS entry
147 return wantarray ? %{ $entry } : $entry;
153 my ( $record, # Biopiece record
156 $record->{ 'HITS' } ||= ".";
157 $record->{ 'BLOCK_COUNT' } ||= ".";
158 $record->{ 'BLOCK_BEGS' } ||= ".";
159 $record->{ 'BLOCK_LENS' } ||= ".";
160 $record->{ 'ALIGN' } ||= $record->{ 'DESCRIPTOR' } || ".";
162 return wantarray ? %{ $record } : $record;
166 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<