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 );
56 # 012345678901234567890
57 # --------------------- S.aur complete genome
58 # -===__===- TAG_000001
61 # S_ID = 'S.aur complete genome'
68 # ALIGN => 0:A>T,3:G>C
75 # 'S.aur complete genome' 3 12 'TAG_000001' 1 + 31 2 1,6 3,3 1,1
78 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
83 my ( $fh, # file handle
88 my ( $line, @fields, %entry );
90 while ( $line = <$fh> )
94 next if $line =~ /^$|^#/;
96 @fields = split /\t/, $line;
98 Maasha::Common::error( qq( BAD kiss entry: $line) ) if not @fields == 12;
100 $entry{ 'S_ID' } = $fields[ S_ID ];
101 $entry{ 'S_BEG' } = $fields[ S_BEG ];
102 $entry{ 'S_END' } = $fields[ S_END ];
103 $entry{ 'Q_ID' } = $fields[ Q_ID ];
104 $entry{ 'SCORE' } = $fields[ SCORE ];
105 $entry{ 'STRAND' } = $fields[ STRAND ];
106 $entry{ 'HITS' } = $fields[ HITS ];
107 $entry{ 'ALIGN' } = $fields[ ALIGN ];
108 $entry{ 'BLOCK_COUNT' } = $fields[ BLOCK_COUNT ];
109 $entry{ 'BLOCK_BEGS' } = $fields[ BLOCK_BEGS ];
110 $entry{ 'BLOCK_LENS' } = $fields[ BLOCK_LENS ];
111 $entry{ 'BLOCK_TYPE' } = $fields[ BLOCK_TYPE ];
113 return wantarray ? %entry : \%entry;
120 my ( $entry, # KISS entry to output
121 $fh, # file handle - OPTIONAL
130 $fields[ S_ID ] = $entry->{ 'S_ID' };
131 $fields[ S_BEG ] = $entry->{ 'S_BEG' };
132 $fields[ S_END ] = $entry->{ 'S_END' };
133 $fields[ Q_ID ] = $entry->{ 'Q_ID' };
134 $fields[ SCORE ] = $entry->{ 'SCORE' };
135 $fields[ STRAND ] = $entry->{ 'STRAND' };
136 $fields[ HITS ] = $entry->{ 'HITS' };
137 $fields[ ALIGN ] = $entry->{ 'ALIGN' };
138 $fields[ BLOCK_COUNT ] = $entry->{ 'BLOCK_COUNT' };
139 $fields[ BLOCK_BEGS ] = $entry->{ 'BLOCK_BEGS' };
140 $fields[ BLOCK_LENS ] = $entry->{ 'BLOCK_LENS' };
141 $fields[ BLOCK_TYPE ] = $entry->{ 'BLOCK_TYPE' };
143 print $fh join( "\t", @fields ), "\n";
149 my ( $dbh, # Database handle
151 $s_beg, # Subject begin
152 $s_end, # Subject end
155 my ( $sql, $entries );
157 $sql = "SELECT * FROM $table WHERE S_BEG >= $s_beg AND S_END <= $s_end";
159 $entries = Maasha::SQL::query_hashref_list( $dbh, $sql );
161 return wantarray ? @{ $entries } : $entries;
167 my ( $entry, # KISS entry
170 return wantarray ? %{ $entry } : $entry;
176 my ( $record, # Biopiece record
179 $record->{ 'HITS' } ||= ".";
180 $record->{ 'BLOCK_COUNT' } ||= ".";
181 $record->{ 'BLOCK_BEGS' } ||= ".";
182 $record->{ 'BLOCK_LENS' } ||= ".";
183 $record->{ 'BLOCK_TYPE' } ||= ".";
184 $record->{ 'ALIGN' } ||= $record->{ 'DESCRIPTOR' } || ".";
186 return wantarray ? %{ $record } : $record;
190 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<