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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
36 use vars qw( @ISA @EXPORT );
38 @ISA = qw( Exporter );
55 # 012345678901234567890
56 # --------------------- S.aur complete genome
57 # -===__===- TAG_000001
60 # S_ID = 'S.aur complete genome'
67 # ALIGN => 0:A>T,3:G>C
73 # 'S.aur complete genome' 3 12 'TAG_000001' 1 + 31 2 1,6 3,3
76 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
81 my ( $fh, # file handle
86 my ( $line, @fields, %entry );
88 while ( $line = <$fh> )
92 next if $line =~ /^$|^#/;
94 @fields = split /\t/, $line;
96 Maasha::Common::error( qq( BAD kiss entry: $line) ) if not @fields == 11;
98 $entry{ 'S_ID' } = $fields[ S_ID ];
99 $entry{ 'S_BEG' } = $fields[ S_BEG ];
100 $entry{ 'S_END' } = $fields[ S_END ];
101 $entry{ 'Q_ID' } = $fields[ Q_ID ];
102 $entry{ 'SCORE' } = $fields[ SCORE ];
103 $entry{ 'STRAND' } = $fields[ STRAND ];
104 $entry{ 'HITS' } = $fields[ HITS ];
105 $entry{ 'ALIGN' } = $fields[ ALIGN ];
106 $entry{ 'BLOCK_COUNT' } = $fields[ BLOCK_COUNT ];
107 $entry{ 'BLOCK_BEGS' } = $fields[ BLOCK_BEGS ];
108 $entry{ 'BLOCK_LENS' } = $fields[ BLOCK_LENS ];
110 return wantarray ? %entry : \%entry;
117 my ( $entry, # KISS entry to output
118 $fh, # file handle - OPTIONAL
127 $fields[ S_ID ] = $entry->{ 'S_ID' };
128 $fields[ S_BEG ] = $entry->{ 'S_BEG' };
129 $fields[ S_END ] = $entry->{ 'S_END' };
130 $fields[ Q_ID ] = $entry->{ 'Q_ID' };
131 $fields[ SCORE ] = $entry->{ 'SCORE' };
132 $fields[ STRAND ] = $entry->{ 'STRAND' };
133 $fields[ HITS ] = $entry->{ 'HITS' };
134 $fields[ ALIGN ] = $entry->{ 'ALIGN' };
135 $fields[ BLOCK_COUNT ] = $entry->{ 'BLOCK_COUNT' };
136 $fields[ BLOCK_BEGS ] = $entry->{ 'BLOCK_BEGS' };
137 $fields[ BLOCK_LENS ] = $entry->{ 'BLOCK_LENS' };
139 print $fh join( "\t", @fields ), "\n";
145 my ( $dbh, # Database handle
147 $s_beg, # Subject begin
148 $s_end, # Subject end
151 my ( $sql, $entries );
153 $sql = "SELECT * FROM $table WHERE S_BEG >= $s_beg AND S_END <= $s_end";
155 $entries = Maasha::SQL::query_hashref_list( $dbh, $sql );
157 return wantarray ? @{ $entries } : $entries;
163 my ( $entry, # KISS entry
166 return wantarray ? %{ $entry } : $entry;
172 my ( $record, # Biopiece record
175 $record->{ 'HITS' } ||= ".";
176 $record->{ 'BLOCK_COUNT' } ||= ".";
177 $record->{ 'BLOCK_BEGS' } ||= ".";
178 $record->{ 'BLOCK_LENS' } ||= ".";
179 $record->{ 'ALIGN' } ||= $record->{ 'DESCRIPTOR' } || ".";
181 return wantarray ? %{ $record } : $record;
185 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<