Exemple #1
0
// general
template<typename T> inline
void add(size_t N, T *Z, const T *X, const T *Y)
{
	add_T(N, Z, X, Y);
}
Exemple #2
0
void rescan_seq( char *seq, size_t seq_len, uint *count_array, size_t cutoff )
{
    /* Martin A. Hansen, September 2008 */

    /* Run a sliding window over a given sequence. The window */
    /* consists of a list where new blocks of 4 nucleotides */
    /* are pushed onto one end while at the same time old */
    /* blocks are popped from the other end. The number of */
    /* in the list is determined by the maximum seperator. */
    /* Everytime we have a full window, the window is scanned */
    /* for motifs. */
 
    bitblock *block      = NULL;
    size_t    b_count    = 0;
    ushort    n_count    = 0;
    size_t    i          = 0;
    uchar     bin        = 0;
    bool      first_node = TRUE;
    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++ )
    {
        bin <<= BITS_IN_NT;

        switch( seq[ i ] )
        {
            case 'A': case 'a': add_A( bin ); break;
            case 'T': case 't': add_T( bin ); break;
            case 'C': case 'c': add_C( bin ); break;
            case 'G': case 'g': add_G( bin ); break;
            default: n_count = BLOCK_SIZE_NT; break;
        }

        if ( i > BLOCK_SIZE_NT - 2 )
        {
            b_count++;

            block      = bitblock_new();
            block->bin = bin;

            if ( n_count > 0 )
            {
                 block->hasN = TRUE;
                 n_count--;
            }

            new_node      = node_sl_new();
            new_node->val = block;

            if ( first_node ) {
                list_sl_add_beg( &list, &new_node );
            } else {
                list_sl_add_after( &old_node, &new_node );
            }

            old_node = new_node;

            first_node = FALSE;

            if ( b_count > BLOCK_SPACE_MAX + BLOCK_SIZE_NT )
            {
                // bitblock_list_print( list );   /* DEBUG */

                rescan_list( list, count_array, i, cutoff, output_array );

                mem_free( &list->first->val );

                list_sl_remove_beg( &list );
            }
        }
    }

    /* if the list is shorter than BLOCK_SPACE_MAX + BLOCK_SIZE_NT */
    if ( b_count <= BLOCK_SPACE_MAX + BLOCK_SIZE_NT )
    {
        // bitblock_list_print( list );  /* DEBUG */

        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 );
}