]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_c/Maasha/src/lib/ucsc.c
bed_sort created
[biopieces.git] / code_c / Maasha / src / lib / ucsc.c
index 6fab258dbb79e881eac2f49328340e31e0066e2d..bdb722a85b3ce98d713adb85d8ad97ca0e1ec9b2 100644 (file)
@@ -97,7 +97,7 @@ bed_entry *bed_entry_get( FILE *fp, int cols )
         {
             sscanf(
                     buffer,
-                    "%s\t%u\t%u\t%s\t%u",
+                    "%s\t%u\t%u\t%s\t%i",
                     entry->chr, 
                     &entry->chr_beg, 
                     &entry->chr_end,
@@ -112,7 +112,7 @@ bed_entry *bed_entry_get( FILE *fp, int cols )
         {
             sscanf(
                     buffer,
-                    "%s\t%u\t%u\t%s\t%u\t%c",
+                    "%s\t%u\t%u\t%s\t%i\t%c",
                     entry->chr, 
                     &entry->chr_beg, 
                     &entry->chr_end,
@@ -128,7 +128,7 @@ bed_entry *bed_entry_get( FILE *fp, int cols )
         {
             sscanf(
                     buffer,
-                    "%s\t%u\t%u\t%s\t%u\t%c\t%u\t%u\t%s\t%u\t%s\t%s",
+                    "%s\t%u\t%u\t%s\t%i\t%c\t%u\t%u\t%s\t%u\t%s\t%s",
                     entry->chr, 
                     &entry->chr_beg, 
                     &entry->chr_end,
@@ -215,7 +215,7 @@ void bed_entry_put( bed_entry *entry, int cols )
     else if ( cols == 5 )
     {
         printf(
-            "%s\t%u\t%u\t%s\t%u\n",
+            "%s\t%u\t%u\t%s\t%i\n",
             entry->chr,
             entry->chr_beg,
             entry->chr_end,
@@ -226,7 +226,7 @@ void bed_entry_put( bed_entry *entry, int cols )
     else if ( cols == 6 )
     {
         printf(
-            "%s\t%u\t%u\t%s\t%u\t%c\n",
+            "%s\t%u\t%u\t%s\t%i\t%c\n",
             entry->chr,
             entry->chr_beg,
             entry->chr_end,
@@ -238,7 +238,7 @@ void bed_entry_put( bed_entry *entry, int cols )
     else if ( cols == 12 )
     {
         printf(
-            "%s\t%u\t%u\t%s\t%u\t%c\t%u\t%u\t%s\t%u\t%s\t%s\n",
+            "%s\t%u\t%u\t%s\t%i\t%c\t%u\t%u\t%s\t%u\t%s\t%s\n",
             entry->chr,
             entry->chr_beg,
             entry->chr_end,
@@ -272,7 +272,7 @@ void bed_entries_put( list_sl *entries, int cols )
 }
 
 
-int cmp_bed3_entries_sort( const void *a, const void *b )
+int cmp_bed_sort_beg( const void *a, const void *b )
 {
     node_sl *a_node = *( ( node_sl ** ) a );
     node_sl *b_node = *( ( node_sl ** ) b );
@@ -280,10 +280,66 @@ int cmp_bed3_entries_sort( const void *a, const void *b )
     bed_entry *a_entry = ( bed_entry * ) a_node->val;
     bed_entry *b_entry = ( bed_entry * ) b_node->val;
 
-    if ( a_entry->chr_end < b_entry->chr_end ) {
+    if ( a_entry->chr_beg < b_entry->chr_beg ) {
+        return -1;
+    } else if ( a_entry->chr_beg > b_entry->chr_beg ) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+
+int cmp_bed_sort_chr_beg( const void *a, const void *b )
+{
+    node_sl *a_node = *( ( node_sl ** ) a );
+    node_sl *b_node = *( ( node_sl ** ) b );
+
+    bed_entry *a_entry = ( bed_entry * ) a_node->val;
+    bed_entry *b_entry = ( bed_entry * ) b_node->val;
+
+    int diff = 0;
+
+    diff = strcmp( a_entry->chr, b_entry->chr );
+
+    if ( diff < 0 ) {
+        return -1;
+    } else if ( diff > 0 ) {
+        return 1;
+    } else if ( a_entry->chr_beg < b_entry->chr_beg ) {
+        return -1;
+    } else if ( a_entry->chr_beg > b_entry->chr_beg ) {
         return 1;
-    } else if ( a_entry->chr_end > b_entry->chr_end ) {
+    } else {
+        return 0;
+    }
+}
+
+
+int cmp_bed_sort_chr_strand_beg( const void *a, const void *b )
+{
+    node_sl *a_node = *( ( node_sl ** ) a );
+    node_sl *b_node = *( ( node_sl ** ) b );
+
+    bed_entry *a_entry = ( bed_entry * ) a_node->val;
+    bed_entry *b_entry = ( bed_entry * ) b_node->val;
+
+    int diff = 0;
+
+    diff = strcmp( a_entry->chr, b_entry->chr );
+
+    if ( diff < 0 ) {
         return -1;
+    } else if ( diff > 0 ) {
+        return 1;
+    } else if ( a_entry->strand < b_entry->strand ) {
+        return -1;
+    } else if ( a_entry->strand > b_entry->strand ) {
+        return 1;
+    } else if ( a_entry->chr_beg < b_entry->chr_beg ) {
+        return -1;
+    } else if ( a_entry->chr_beg > b_entry->chr_beg ) {
+        return 1;
     } else {
         return 0;
     }