]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed UCSC::get_psl_entry
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 29 Aug 2008 00:50:16 +0000 (00:50 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 29 Aug 2008 00:50:16 +0000 (00:50 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@229 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/Biopieces.pm
code_perl/Maasha/UCSC.pm

index 328bc9685aa6121fb83312bcf8d7545dc8b395fb..5280748a5f572a77d3a860314edf2431c7674d9a 100644 (file)
@@ -1328,7 +1328,7 @@ sub script_read_psl
 
     # Returns nothing.
 
 
     # Returns nothing.
 
-    my ( $record, @files, $file, $entries, $entry, $num );
+    my ( $record, $file, $data_in, $num );
 
     while ( $record = get_record( $in ) ) {
         put_record( $record, $out );
 
     while ( $record = get_record( $in ) ) {
         put_record( $record, $out );
@@ -1338,11 +1338,11 @@ sub script_read_psl
 
     foreach $file ( @{ $options->{ "files" } } )
     {
 
     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" };
 
 
             goto NUM if $options->{ "num" } and $num == $options->{ "num" };
 
index 1521742e09c741f8a17086bbab16bf4dc08fe319..4f272fd25e61dad91d47205f0d62870dc6b1bbc3 100644 (file)
@@ -599,11 +599,67 @@ CREATE TABLE $table (
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PSL format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.
 
 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
        ) = @_;
 
     my ( $path,   # full path to PSL file
        ) = @_;