1 /* Martin Asser Hansen (mail@maasha.dk) Copyright (C) 2008 - All right reserved */
7 #define BITS_IN_BYTE 8 /* number of bits in one byte. */
8 #define BLOCK_SPACE_MAX 64 /* maximum space between two blocks. */
9 #define BLOCK_MASK ( ( BLOCK_SPACE_MAX << 1 ) - 1 ) /* mask for printing block space. */
11 /* Function declarations. */
12 void run_decode( int argc, char *argv[] );
14 void motif_print( uint motif, uint count );
17 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MAIN <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
20 int main( int argc, char *argv[] )
26 run_decode( argc, argv );
32 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
37 /* Martin A. Hansen, September 2008 */
39 /* Print usage and exit. */
42 "Usage: bipartite_decode <bipartite file(s)> > result.tab\n"
49 void run_decode( int argc, char *argv[] )
51 /* Martin A. Hansen, September 2008 */
53 /* For each file in argv decode the file of */
54 /* bipartite motifs and output the motifs */
55 /* and their count. */
62 for ( i = 1; i < argc; i++ )
64 fp = read_open( argv[ i ] );
66 while ( fscanf( fp, "%u\t%u\n", &motif, &count ) )
68 assert( ferror( fp ) == 0 );
70 motif_print( motif, count );
82 void motif_print( uint motif, uint count )
84 /* Martin A. Hansen, September 2008 */
86 /* Converts a binary encoded bipartite motif */
87 /* into DNA and output the motif, distance and */
88 /* count seperated by tabs: */
89 /* BLOCK1 \t BLOCK2 \t DIST \t COUNT */
94 uint motif_cpy = motif;
96 dist = ( ushort ) motif & BLOCK_MASK;
98 motif >>= sizeof( uchar ) * BITS_IN_BYTE;
100 bin2 = ( uchar ) motif;
102 motif >>= sizeof( uchar ) * BITS_IN_BYTE;
104 bin1 = ( uchar ) motif;
106 printf( "%u\t%s\t%s\t%d\t%d\n", motif_cpy, bin2dna[ bin1 ], bin2dna[ bin2 ], dist, count );
110 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */