1 /* Martin Asser Hansen (mail@maasha.dk) Copyright (C) 2008 - All right reserved */
3 #define BED_BUFFER 2048
5 #define BED_QID_MAX 256
6 #define BED_ITEMRGB_MAX 16
7 #define BED_BLOCKSIZES_MAX 256
8 #define BED_QBEGS_MAX 256
10 /* Structure of a BED entry with the 12 BED elements. */
11 /* http://genome.ucsc.edu/FAQ/FAQformat#format1 */
14 int cols; /* Number of BED elements used. */
15 char *chr; /* Chromosome name. */
16 uint chr_beg; /* Chromosome begin position. */
17 uint chr_end; /* Chromosome end position. */
18 char *q_id; /* Query ID. */
19 int score; /* Score. */
20 char strand; /* Strand. */
21 uint thick_beg; /* Begin position of thick drawing. */
22 uint thick_end; /* End position of thick drawing. */
23 char *itemrgb; /* RGB color (255,255,255).*/
24 uint blockcount; /* Number of blocks (exons). */
25 char *blocksizes; /* Comma separated string of blocks sizes. */
26 char *q_begs; /* Comma separated string of block begins. */
29 typedef struct _bed_entry bed_entry;
31 /* Returns a new BED entry with memory allocated for */
32 /* a given number of columns. */
33 bed_entry *bed_entry_new( const int cols );
35 /* Free memory for a BED entry. */
36 void bed_entry_destroy( bed_entry *entry );
38 /* Get next BED entry of a given number of columns from a file pointer. */
39 bed_entry *bed_entry_get( FILE *fp, const int cols );
41 /* Get a singly linked list with all BED entries (of a given number of coluns */
42 /* from a specified file. */
43 list_sl *bed_entries_get( char *path, const int cols );
45 /* Output a given number of columns from a BED entry to stdout. */
46 void bed_entry_put( bed_entry *entry, int cols );
48 /* Output a given number of columns from all BED entries */
49 /* in a singly linked list. */
50 void bed_entries_put( list_sl *entries, int cols );
52 /* Free memory for all BED entries and list nodes. */
53 void bed_entries_destroy( list_sl **entries_ppt );
55 /* Given a path to a BED file, read the given number of cols */
56 /* according to the begin position. The result is written to stdout. */
57 void bed_file_sort_beg( char *path, int cols );
59 /* Given a path to a BED file, read the given number of cols */
60 /* according to the strand AND begin position. The result is written to stdout. */
61 void bed_file_sort_strand_beg( char *path, int cols );
63 /* Given a path to a BED file, read the given number of cols */
64 /* according to the chromosome AND begin position. The result is written to stdout. */
65 void bed_file_sort_chr_beg( char *path, int cols );
67 /* Given a path to a BED file, read the given number of cols */
68 /* according to the chromosome AND strand AND begin position. The result is written to stdout. */
69 void bed_file_sort_chr_strand_beg( char *path, int cols );
71 /* Compare function for sorting a singly linked list of BED entries */
72 /* according to begin position. */
73 int cmp_bed_sort_beg( const void *a, const void *b );
75 /* Compare function for sorting a singly linked list of BED entries */
76 /* according to strand AND begin position. */
77 int cmp_bed_sort_strand_beg( const void *a, const void *b );
79 /* Compare function for sorting a singly linked list of BED entries */
80 /* according to chromosome name AND begin position. */
81 int cmp_bed_sort_chr_beg( const void *a, const void *b );
83 /* Compare function for sorting a singly linked list of BED entries */
84 /* according to chromosome name AND strand AND begin position. */
85 int cmp_bed_sort_chr_strand_beg( const void *a, const void *b );