#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 )
{
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"
);
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;
}
+
while ( $line = <$fh> )
{
+ $line =~ tr/\n\r//d;
+
if ( $line =~ /Track added by 'upload_to_ucsc' (\S+) (\S+)/) {
$record{ 'date' } = $1;
$record{ 'time' } = $2;
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";