From a19840ceca873b37c1d75c6fd243a5b9fc3bb64b Mon Sep 17 00:00:00 2001 From: martinahansen Date: Thu, 11 Dec 2008 00:54:44 +0000 Subject: [PATCH] fixed carriage return bug in read_ucsc_config git-svn-id: http://biopieces.googlecode.com/svn/trunk@353 74ccb610-7750-0410-82ae-013aeee3265d --- code_c/Maasha/src/bed2fixedstep.c | 82 ++++++++++++------------------- code_perl/Maasha/Biopieces.pm | 6 ++- code_perl/Maasha/UCSC.pm | 4 +- 3 files changed, 39 insertions(+), 53 deletions(-) diff --git a/code_c/Maasha/src/bed2fixedstep.c b/code_c/Maasha/src/bed2fixedstep.c index 7c807df..f77b940 100644 --- a/code_c/Maasha/src/bed2fixedstep.c +++ b/code_c/Maasha/src/bed2fixedstep.c @@ -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 < > \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; } + diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 3d5d994..51c25aa 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -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 ) ) diff --git a/code_perl/Maasha/UCSC.pm b/code_perl/Maasha/UCSC.pm index 84663db..557053e 100644 --- a/code_perl/Maasha/UCSC.pm +++ b/code_perl/Maasha/UCSC.pm @@ -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"; -- 2.39.2