/* Structure that will hold one tetra nucleotide block. */
struct _bitblock
{
- uchar bin; /* Tetra nucleotide encoded binary. */
+ uchar bin; /* Tetra nucleotide binary encoded. */
bool hasN; /* Flag indicating any N's in the block. */
};
void scan_list( list_sl *list, uint *count_array );
bitblock *bitblock_new();
uint blocks2motif( uchar bin1, uchar bin2, ushort dist );
+int cmp_uint_desc( const void *a, const void *b );
void count_array_print( uint *count_array );
void motif_print( uint motif, uint count );
void bitblock_list_print( list_sl *list );
static void test_bitblock_print();
static void test_bitblock_list_print();
static void test_scan_seq();
+static void test_array_sort();
static void test_blocks2motif();
int main( int argc, char *argv[] )
{
+ run_tests();
+
if ( argc == 1 ) {
print_usage();
}
- run_tests();
run_scan( argc, argv );
return EXIT_SUCCESS;
fprintf( stderr, "done.\n" );
}
+ fprintf( stderr, "Sorting motifs: ... " );
+
+ qsort( count_array, COUNT_ARRAY_SIZE, sizeof( uint ), cmp_uint_desc );
+
+ fprintf( stderr, "done.\n" );
+
fprintf( stderr, "Printing motifs: ... " );
count_array_print( count_array );
}
+int cmp_uint_desc( const void *a, const void *b )
+{
+ /* Martin A. Hansen, September 2008 */
+
+ /* Compare function for qsort of an array of unsigned ints */
+ /* to be sorted in descending order. */
+
+ const uint *uint_a = ( const uint *) a;
+ const uint *uint_b = ( const uint *) b;
+
+ return *uint_b - *uint_a;
+}
+
+
void count_array_print( uint *count_array )
{
/* Martin A. Hansen, Seqptember 2008. */
test_bitblock_print();
test_bitblock_list_print();
test_scan_seq();
+ test_array_sort();
test_blocks2motif();
fprintf( stderr, "All tests OK\n" );
}
+void test_array_sort()
+{
+ fprintf( stderr, " Running test_array_sort ... " );
+
+ uint array[] = { 4, 234, 23, 43, 12, 23, 1, 34 };
+ int array_size = sizeof( array ) / sizeof( uint );
+ int i = 0;
+
+ for ( i = 0; i < array_size; i ++ ) {
+// printf( "elem: %i\n", array[ i ] );
+ }
+
+ qsort( array, array_size, sizeof( uint ), cmp_uint_desc );
+
+ for ( i = 0; i < array_size; i ++ ) {
+// printf( "elem: %i\n", array[ i ] );
+ }
+
+ assert( array[ 0 ] == 234 ); /* 234 first in sorted array */
+ assert( array[ array_size - 1 ] == 1 ); /* 1 last in sorted array */
+
+ fprintf( stderr, "done.\n" );
+}
+
+
static void test_blocks2motif()
{
fprintf( stderr, " Running test_blocks2motif ... " );