From 3339284e13bfb8875a2687ab2b5875e456da0981 Mon Sep 17 00:00:00 2001
From: martinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Date: Mon, 29 Sep 2008 03:34:22 +0000
Subject: [PATCH] tada

git-svn-id: http://biopieces.googlecode.com/svn/trunk@272 74ccb610-7750-0410-82ae-013aeee3265d
---
 code_c/Maasha/src/bipartite_scan.c | 29 +++++++++++++++++++++++------
 code_perl/Maasha/Biopieces.pm      | 11 +++++++----
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/code_c/Maasha/src/bipartite_scan.c b/code_c/Maasha/src/bipartite_scan.c
index 3646676..86f3b8a 100644
--- a/code_c/Maasha/src/bipartite_scan.c
+++ b/code_c/Maasha/src/bipartite_scan.c
@@ -33,7 +33,7 @@ uint     *count_array_new( size_t nmemb );
 void      scan_seq( char *seq, size_t seq_len, uint *count_array );
 void      rescan_seq( char *seq, size_t seq_len, uint *count_array, size_t cutoff );
 void      scan_list( list_sl *list, uint *count_array );
-void      rescan_list( list_sl *list, uint *count_array, size_t pos, size_t cutoff );
+void      rescan_list( list_sl *list, uint *count_array, size_t pos, size_t cutoff, uint *output_array );
 bitblock *bitblock_new();
 uint      blocks2motif( uchar bin1, uchar bin2, ushort dist );
 void      count_array_print( uint *count_array, size_t nmemb, size_t cutoff );
@@ -292,6 +292,9 @@ void rescan_seq( char *seq, size_t seq_len, uint *count_array, size_t cutoff )
     node_sl *new_node    = NULL;
     node_sl *old_node    = NULL;
     list_sl *list        = list_sl_new();
+    uint *output_array   = NULL;
+
+    output_array         = mem_get_zero( sizeof( uint ) * ( seq_len + 1 ) );
 
     for ( i = 0; seq[ i ]; i++ )
     {
@@ -336,7 +339,7 @@ void rescan_seq( char *seq, size_t seq_len, uint *count_array, size_t cutoff )
             {
                 // bitblock_list_print( list );   /* DEBUG */
 
-                rescan_list( list, count_array, i, cutoff );
+                rescan_list( list, count_array, i, cutoff, output_array );
 
                 mem_free( &list->first->val );
 
@@ -350,10 +353,16 @@ void rescan_seq( char *seq, size_t seq_len, uint *count_array, size_t cutoff )
     {
         // bitblock_list_print( list );  /* DEBUG */
 
-        rescan_list( list, count_array, i, cutoff );
+        rescan_list( list, count_array, i, cutoff, output_array );
     }
 
     list_sl_destroy( &list );
+
+    for ( i = 0; i < seq_len; i++ ) {
+        printf( "%zu\t%u\n", i, output_array[ i ] );
+    }
+
+    free( output_array );
 }
 
 
@@ -407,7 +416,7 @@ void scan_list( list_sl *list, uint *count_array )
 }
 
 
-void rescan_list( list_sl *list, uint *count_array, size_t pos, size_t cutoff )
+void rescan_list( list_sl *list, uint *count_array, size_t pos, size_t cutoff, uint *output_array )
 {
     /* Martin A. Hansen, September 2008 */
 
@@ -421,6 +430,7 @@ void rescan_list( list_sl *list, uint *count_array, size_t pos, size_t cutoff )
     bitblock *block1     = NULL;
     bitblock *block2     = NULL;
     int       i          = 0;
+    int       k          = 0;
     ushort    dist       = 0;
     uint      motif_bin  = 0;
     uint      j          = 0;
@@ -455,8 +465,15 @@ void rescan_list( list_sl *list, uint *count_array, size_t pos, size_t cutoff )
 
                 count = count_array[ motif_bin ];
 
-                if ( count > cutoff ) {
-                    printf( "%zu\t%u\t%u\n", pos + j, motif_bin, count );
+                if ( count > cutoff )
+                {
+                    // printf( "%zu\t%u\t%u\n", pos + j, motif_bin, count );
+
+                    for ( k = 0; k < BLOCK_SIZE_NT - 1; k++ )
+                    {
+                        output_array[ pos - j + k - BLOCK_SIZE_NT ]    += count;
+                        output_array[ pos + k - dist - BLOCK_SIZE_NT ] += count;
+                    }
                 }
             }
 
diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm
index 820005b..edaccbb 100644
--- a/code_perl/Maasha/Biopieces.pm
+++ b/code_perl/Maasha/Biopieces.pm
@@ -946,7 +946,7 @@ sub get_options
             group|g=s
             priority|p=f
             use_score|u
-            visibility|v=s
+            visibility|V=s
             color|c=s
             chunk_size|C=s
         );
@@ -955,7 +955,7 @@ sub get_options
     push @options, qw(
         stream_in|I=s
         stream_out|O=s
-        verbose
+        verbose|v
         help|?
     );
 
@@ -4477,14 +4477,17 @@ sub script_plot_phastcons_profiles
     $phastcons_file  = Maasha::Config::genome_phastcons( $options->{ "genome" } );
     $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
 
-    $index           = Maasha::UCSC::phastcons_index_retrieve( $phastcons_index );
+    $index           = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
     $fh_phastcons    = Maasha::Common::read_open( $phastcons_file );
 
     while ( $record = get_record( $in ) ) 
     {
         if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
         {
-            $scores = Maasha::UCSC::phastcons_index_lookup( $index, $fh_phastcons, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $options->{ "flank" } );
+            $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" },
+                                                                                   $record->{ "CHR_BEG" },
+                                                                                   $record->{ "CHR_END" },
+                                                                                   $options->{ "flank" } );
 
             push @{ $AoA }, [ @{ $scores } ];
         }
-- 
2.39.5