+void bed_entries_destroy( list_sl **entries_ppt )
+{
+ /* Martin A. Hansen, September 2008 */
+
+ /* Free memory for all BED entries and list nodes. */
+
+ list_sl *entries = *entries_ppt;
+ node_sl *node = NULL;
+ node_sl *next = NULL;
+
+ next = entries->first;
+
+ while ( next != NULL )
+ {
+ node = next;
+
+ bed_entry_destroy( ( bed_entry * ) node->val );
+
+ next = node->next;
+
+ mem_free( &node );
+ }
+
+ mem_free( &entries );
+
+ *entries_ppt = NULL;
+}
+
+
+void bed_file_sort_beg( char *path, int cols )
+{
+ /* Martin A. Hansen, September 2008 */
+
+ /* Given a path to a BED file, read the given number of cols */
+ /* according to the begin position. The result is written to stdout. */
+
+ list_sl *entries = NULL;
+
+ entries = bed_entries_get( path, cols );
+
+ list_sl_sort( &entries, cmp_bed_sort_beg );
+
+ bed_entries_put( entries, cols );
+
+ bed_entries_destroy( &entries );
+}
+
+
+void bed_file_sort_strand_beg( char *path, int cols )
+{
+ /* Martin A. Hansen, September 2008 */
+
+ /* Given a path to a BED file, read the given number of cols */
+ /* according to the strand AND begin position. The result is written to stdout. */
+
+ assert( cols >= 6 );
+
+ list_sl *entries = NULL;
+
+ entries = bed_entries_get( path, cols );
+
+ list_sl_sort( &entries, cmp_bed_sort_strand_beg );
+
+ bed_entries_put( entries, cols );
+
+ bed_entries_destroy( &entries );
+}
+
+
+void bed_file_sort_chr_beg( char *path, int cols )
+{
+ /* Martin A. Hansen, September 2008 */
+
+ /* Given a path to a BED file, read the given number of cols */
+ /* according to the chromosome AND begin position. The result is written to stdout. */
+
+ list_sl *entries = NULL;
+
+ entries = bed_entries_get( path, cols );
+
+ list_sl_sort( &entries, cmp_bed_sort_chr_beg );
+
+ bed_entries_put( entries, cols );
+
+ bed_entries_destroy( &entries );
+}
+
+
+void bed_file_sort_chr_strand_beg( char *path, int cols )
+{
+ /* Martin A. Hansen, September 2008 */
+
+ /* Given a path to a BED file, read the given number of cols */
+ /* according to the chromosome AND strand AND begin position. The result is written to stdout. */
+
+ assert( cols >= 6 );
+
+ list_sl *entries = NULL;
+
+ entries = bed_entries_get( path, cols );
+
+ list_sl_sort( &entries, cmp_bed_sort_chr_strand_beg );
+
+ bed_entries_put( entries, cols );
+
+ bed_entries_destroy( &entries );
+}
+
+