]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed carriage return bug in read_ucsc_config
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 11 Dec 2008 00:54:44 +0000 (00:54 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 11 Dec 2008 00:54:44 +0000 (00:54 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@353 74ccb610-7750-0410-82ae-013aeee3265d

code_c/Maasha/src/bed2fixedstep.c
code_perl/Maasha/Biopieces.pm
code_perl/Maasha/UCSC.pm

index 7c807df428289bb74a6a6cd50d9cfdd9ec51749c..f77b940b575a9073b8b4d72a298eef3e1e6ab0cb 100644 (file)
@@ -1,12 +1,9 @@
 #include "common.h"
-#include "mem.h"
-#include "list.h"
-#include "ucsc.h"
-#include "hash.h"
 #include "barray.h"
 
-#define BED_COLS    5
-#define HASH_SIZE   8
+#define BUFFER_SIZE 1024
+#define BED_CHR_MAX 16
+#define BED_QID_MAX 256
 #define BARRAY_SIZE ( 1 << 16 )
 
 
@@ -14,9 +11,9 @@ static void usage()
 {
     fprintf( stderr,
         "\n"
-        "bed2fixedstep - collapse overlapping BED entries using a score\n"
-        "based on the last number following a _ in the 'name' column.\n"
-        "if no such number is found 1 is used.\n"
+        "bed2fixedstep - collapse overlapping BED entries with only one\n"
+        "chromosome using a score based on the last number following a _\n"
+        "in the 'name' column. if no such number is found 1 is used.\n"
         "\n"
         "Usage: bed2fixedstep < <BED file(s)> > <fixedstep file>\n\n"
     );
@@ -46,66 +43,51 @@ long get_score( char *str )
 
 int main( int argc, char *argv[] )
 {
-    bed_entry *entry    = NULL;
-    hash      *chr_hash = NULL;
-    hash_elem *bucket   = NULL;
-    barray    *ba       = NULL;
-    uint       score    = 0;
-    size_t     i        = 0;
-    size_t     j        = 0;
-    char      *chr      = NULL;
-    size_t     beg      = 0;
-    size_t     end      = 0;
-    size_t     pos      = 0;
-
-    entry    = bed_entry_new( BED_COLS );
-    chr_hash = hash_new( HASH_SIZE );
+    char       buffer[ BUFFER_SIZE ];
+    char       chr[ BED_CHR_MAX ];
+    char       q_id[ BED_QID_MAX ];
+    size_t     beg   = 0;
+    size_t     end   = 0;
+    uint       score = 0;
+    size_t     pos   = 0;
+    size_t     i     = 0;
+    barray    *ba    = barray_new( BARRAY_SIZE );
 
     if ( isatty( fileno( stdin ) ) ) {
         usage();
     }
     
-    while ( ( bed_entry_get( stdin, &entry ) ) )
+    while ( fgets( buffer, sizeof( buffer ), stdin ) )
     {
-//        bed_entry_put( entry, entry->cols );
+//        printf( "BUFFER: %s\n", buffer );
 
-        ba = ( barray * ) hash_get( chr_hash, entry->chr );
-
-        if ( ba == NULL )
+        if ( sscanf( buffer, "%s\t%zu\t%zu\t%s", chr, &beg, &end, q_id ) == 4 )
         {
-            ba = barray_new( BARRAY_SIZE );
-
-            hash_add( chr_hash, entry->chr, ba );
-        }
+//            printf( "chr: %s   beg: %zu   end: %zu   q_id: %s\n", chr, beg, end, q_id );
 
-        score = ( uint ) get_score( entry->q_id );
+            score = ( uint ) get_score( q_id );
 
-        barray_interval_inc( ba, entry->chr_beg, entry->chr_end - 1, score );
+            barray_interval_inc( ba, beg, end - 1, score );
+        }
     }
 
 //    barray_print( ba );
 
-    for ( i = 0; i < chr_hash->table_size; i++ )
-    {
-        for ( bucket = chr_hash->table[ i ]; bucket != NULL; bucket = bucket->next )
-        {
-            chr = bucket->key;
-            ba  = ( barray * ) bucket->val;
-        
-            pos = 0;
+    pos = 0;
+    beg = 0;
+    end = 0;
 
-            while ( barray_interval_scan( ba, &pos, &beg, &end ) )
-            {
-//                printf( "chr: %s   pos: %zu   beg: %zu   end: %zu\n", chr, pos, beg, end );
+    while ( barray_interval_scan( ba, &pos, &beg, &end ) )
+    {
+//        printf( "chr: %s   pos: %zu   beg: %zu   end: %zu\n", chr, pos, beg, end );
 
-                printf( "fixedStep chrom=%s start=%zu step=1\n", chr, beg + 1 );
+        printf( "fixedStep chrom=%s start=%zu step=1\n", chr, beg + 1 );
 
-                for ( j = beg; j <= end; j++ ) {
-                    printf( "%u\n", ba->array[ j ] );
-                }
-            }
+        for ( i = beg; i <= end; i++ ) {
+            printf( "%u\n", ba->array[ i ] );
         }
     }
 
     return EXIT_SUCCESS;
 }
+
index 3d5d994d2127daf95985029c2dd35e0852e24518..51c25aa3449ca8c4a32ccee26a076f1b9277073a 100644 (file)
@@ -3118,8 +3118,12 @@ sub script_get_genome_seq
                     for ( $i = 0; $i < @begs; $i++ ) {
                         $seq .= substr $record->{ "SEQ" }, $begs[ $i ], $lens[ $i ];
                     }
+
+                    $record->{ "SEQ" } = $seq;
                 }
             }
+
+            $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
         }
 
         put_record( $record, $out );
@@ -6693,8 +6697,6 @@ sub clean_tmp
             $sid  = $2;
             $pid  = $3;
 
-            next if $user eq "m.hansen";
-
             if ( $user eq Maasha::Common::get_user() )
             {
                 if ( not Maasha::Common::process_running( $pid ) )
index 84663db27285ed6585c146891f3f4f75055d2ddb..557053eb483efffe1249947fba80d4930e5be39b 100644 (file)
@@ -916,6 +916,8 @@ sub ucsc_config_entry_get
 
     while ( $line = <$fh> )
     {
+        $line =~ tr/\n\r//d;
+
         if ( $line =~ /Track added by 'upload_to_ucsc' (\S+) (\S+)/) {
              $record{ 'date' } = $1;
              $record{ 'time' } = $2;
@@ -1011,12 +1013,12 @@ sub ucsc_update_config
         longLabel  => $options->{ 'long_label' },
         group      => $options->{ 'group' },
         priority   => $options->{ 'priority' },
-        useScore   => $options->{ 'use_score' },
         visibility => $options->{ 'visibility' },
         color      => $options->{ 'color' },
         type       => $type,
     );
 
+    $new_entry{ 'useScore' }        = 1             if $options->{ 'use_score' };
     $new_entry{ 'mafTrack' }        = "multiz17way" if $type eq "type bed 6 +";
     $new_entry{ 'maxHeightPixels' } = "50:50:11"    if $type eq "wig 0";