]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/Matrix.pm
added bwa_seq
[biopieces.git] / code_perl / Maasha / Matrix.pm
index ed90a25ab943d7171e00aef0bbd1c3337be1ac17..5d340f3a668c9553b0ec652da4429c98afa5202e 100644 (file)
@@ -181,12 +181,60 @@ sub matrix_flip
         }
     }
 
-    $matrix = $AoA;
+    @{ $matrix } = @{ $AoA };
 
     return wantarray ? @{ $matrix } : $matrix;
 }
 
 
+sub matrix_deflate_rows
+{
+    # Martin A. Hansen, September 2009.
+
+    # Reduces the number of elements in all rows,
+    # by collectiong elements in buckets that are
+    # averaged.
+
+    my ( $matrix,   # AoA data structure
+         $new_size
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $row );
+
+    foreach $row ( @{ $matrix } ) {
+        list_deflate( $row, $new_size );
+    }
+}
+
+
+sub matrix_deflate_cols
+{
+    # Martin A. Hansen, September 2009.
+
+    # Reduces the number of elements in all columns,
+    # by collectiong elements in buckets that are
+    # averaged.
+
+    my ( $matrix,   # AoA data structure
+         $new_size
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $col );
+
+    matrix_flip( $matrix );
+
+    foreach $col ( @{ $matrix } ) {
+        list_deflate( $col, $new_size );
+    }
+
+    matrix_flip( $matrix );
+}
+
+
 sub matrix_rotate_right
 {
     # Martin A. Hansen, April 2007
@@ -443,7 +491,7 @@ sub col_get
 
 sub cols_get
 {
-    # Martin A. Hansen, April 2007
+    # Martin A. Hansen, April 2007.
 
     # returns a range of requested columns from a given matrix
 
@@ -913,8 +961,8 @@ sub list_deflate
     # Defaltes a list of values to a specified size 
     # and at the same time average the values.
 
-    my ( $list,
-         $new_size,
+    my ( $list,       # list to deflate
+         $new_size,   # new number of elements in list
        ) = @_;
 
     # Returns nothing.
@@ -928,8 +976,6 @@ sub list_deflate
     $bucket_size  = int( $old_size / $new_size );
     $bucket_rest  = $old_size - ( $new_size * $bucket_size );
 
-    print STDERR "old_size: $old_size    new_size: $new_size   bucket_size: $bucket_size   bucket_rest: $bucket_rest\n";
-
     $i = 0;
 
     while ( $i < $new_size )