From 9cfb7134c6b8be5623e0fbd8dba4a60c19b23063 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Fri, 29 Aug 2008 00:50:16 +0000 Subject: [PATCH] fixed UCSC::get_psl_entry git-svn-id: http://biopieces.googlecode.com/svn/trunk@229 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/Biopieces.pm | 8 ++--- code_perl/Maasha/UCSC.pm | 58 ++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 328bc96..5280748 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -1328,7 +1328,7 @@ sub script_read_psl # Returns nothing. - my ( $record, @files, $file, $entries, $entry, $num ); + my ( $record, $file, $data_in, $num ); while ( $record = get_record( $in ) ) { put_record( $record, $out ); @@ -1338,11 +1338,11 @@ sub script_read_psl foreach $file ( @{ $options->{ "files" } } ) { - $entries = Maasha::UCSC::psl_get_entries( $file ); + $data_in = Maasha::Common::read_open( $file ); - foreach $entry ( @{ $entries } ) + while ( $record = Maasha::UCSC::psl_get_entry( $data_in ) ) { - put_record( $entry, $out ); + put_record( $record, $out ); goto NUM if $options->{ "num" } and $num == $options->{ "num" }; diff --git a/code_perl/Maasha/UCSC.pm b/code_perl/Maasha/UCSC.pm index 1521742..4f272fd 100644 --- a/code_perl/Maasha/UCSC.pm +++ b/code_perl/Maasha/UCSC.pm @@ -599,11 +599,67 @@ CREATE TABLE $table ( # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PSL format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +sub psl_get_entry +{ + # Martin A. Hansen, August 2008. + + # Reads PSL next entry from a PSL file and returns a record. + + my ( $fh, # file handle of PSL filefull path to PSL file + ) = @_; + + # Returns hashref. + + my ( $line, @fields, %record ); + + while ( $line = <$fh> ) + { + chomp $line; + + @fields = split "\t", $line; + + if ( scalar @fields == 21 ) + { + %record = ( + REC_TYPE => "PSL", + MATCHES => $fields[ 0 ], + MISMATCHES => $fields[ 1 ], + REPMATCHES => $fields[ 2 ], + NCOUNT => $fields[ 3 ], + QNUMINSERT => $fields[ 4 ], + QBASEINSERT => $fields[ 5 ], + SNUMINSERT => $fields[ 6 ], + SBASEINSERT => $fields[ 7 ], + STRAND => $fields[ 8 ], + Q_ID => $fields[ 9 ], + Q_LEN => $fields[ 10 ], + Q_BEG => $fields[ 11 ], + Q_END => $fields[ 12 ] - 1, + S_ID => $fields[ 13 ], + S_LEN => $fields[ 14 ], + S_BEG => $fields[ 15 ], + S_END => $fields[ 16 ] - 1, + BLOCKCOUNT => $fields[ 17 ], + BLOCKSIZES => $fields[ 18 ], + Q_BEGS => $fields[ 19 ], + S_BEGS => $fields[ 20 ], + ); + + $record{ "SCORE" } = $record{ "MATCHES" } + int( $record{ "REPMATCHES" } / 2 ) - $record{ "MISMATCHES" } - $record{ "QNUMINSERT" } - $record{ "SNUMINSERT" }; + + return wantarray ? %record : \%record; + } + } + + return undef; +} + + sub psl_get_entries { # Martin A. Hansen, February 2008. - # Reads PSL entries and returns a record. + # Reads PSL entries and returns a list of records. my ( $path, # full path to PSL file ) = @_; -- 2.39.5