]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/NCBI.pm
migrating read_ tools
[biopieces.git] / code_perl / Maasha / NCBI.pm
index e6b7407e90031004cc875592ec31c2b9e532d631..a94dc4a88550236db861eb83630198ed6240e36c 100644 (file)
@@ -155,7 +155,7 @@ sub soft_parse
                 @fields = split "\t", $lines[ $c ];
 
                 $id_hash{ $fields[ $key_hash{ "ID" } ] } = $fields[ $key_hash{ "SEQUENCE" } ];
-            
+
                 $c++;
             }
 
@@ -233,8 +233,8 @@ sub soft_index_file
 
     $first = 1;
 
-    $i = 0;
-    $c = 0;
+    $i      = 0;
+    $c      = 0;
 
     while ( $line = <$fh> )
     {
@@ -242,11 +242,14 @@ sub soft_index_file
 
         if ( $line =~ /^\^/ )
         {
-            push @index, [ $line, $i ];
+            push @index, {
+                SECTION  => $line, 
+                LINE_BEG => $i,
+            };
 
             if ( not $first )
             {
-                push @{ $index[ $c - 1 ] }, $i - 1;
+                $index[ $c - 1 ]{ "LINE_END" } = $i - 1;
             }
             else
             {
@@ -259,7 +262,7 @@ sub soft_index_file
         $i++; 
     }
 
-    push @{ $index[ $c - 1 ] }, $i - 1;
+    $index[ $c - 1 ]{ "LINE_END" } = $i - 1;
 
     close $fh;
 
@@ -271,7 +274,7 @@ sub soft_get_platform
 {
     # Martin A. Hansen, June 2008.
 
-    # Given a filehandle to a SOFT file parses the platform table
+    # Given a filehandle to a SOFT file parses all the platform tables
     # which is returned.
 
     my ( $fh,    # filehandle
@@ -314,7 +317,7 @@ sub soft_get_platform
             {
                 @fields = split "\t", $lines[ $c ];
 
-                $id_hash{ $fields[ $key_hash{ "ID" } ] } = $fields[ $key_hash{ "SEQUENCE" } ];
+                $id_hash{ $fields[ $key_hash{ "ID" } ] } = $fields[ $key_hash{ "SEQUENCE" } ] || $fields[ $key_hash{ "ID" } ];
             
                 $c++;
             }
@@ -333,16 +336,17 @@ sub soft_get_sample
 {
     # Martin A. Hansen, June 2008.
 
-    # Given a filehandle to a SOFT file parses the platform table
-    # which is returned.
+    # Given a filehandle to a SOFT file and a platform table 
+    # parses sample records which are returned.
 
-    my ( $fh,         # filehandle
-         $plat_table,  # hashref with platform tables
-         $beg,        # line number where sample table begin
-         $end,        # line number where sample table end
+    my ( $fh,           # filehandle
+         $plat_table,   # hashref with platform table
+         $beg,          # line number where sample table begin
+         $end,          # line number where sample table end
+         $skip,         # flag indicating that this sample table should not be parsed.
        ) = @_;
 
-    # Returns hashref
+    # Returns list of hashref
 
     my ( $line, @lines, $i, $c, $platform_id, @fields, %key_hash, $num, $sample_id, $sample_title, $id, $seq, $count, @records, $record );
 
@@ -350,15 +354,22 @@ sub soft_get_sample
 
     while ( $line = <$fh> )
     {
-        chomp $line;
+        if ( not $skip )
+        {
+            chomp $line;
+
+            push @lines, $line if $i >= $beg;
+        }
 
-        push @lines, $line if $i >= $beg;
-    
         last if $i == $end;
 
         $i++;
     }
 
+    if ( $skip ) {
+        return wantarray ? () : [];
+    }
+
     $i = 0;
 
     $num = 1;