Commits

Tao Liu committed c498360

Add script to split MACS2 output into quantiles.

Comments (0)

Files changed (2)

Scripts/quantile.py

+#!/usr/bin/env python
+# Time-stamp: <2011-06-30 23:42:21 Tao Liu>
+
+import os
+import sys
+from operator import itemgetter
+# ------------------------------------
+# Main function
+# ------------------------------------
+def main():
+    if len(sys.argv) < 4:
+        sys.stderr.write("need x paras: %s <number of groups> <column of score> <peak.bed>\n" % sys.argv[0])
+        sys.exit(1)
+
+    ng = int(sys.argv[1])
+    col = int(sys.argv[2])-1
+    fhd = open(sys.argv[3],"r")
+
+    peaks = []
+
+    for i in fhd:
+        score = float(i.rstrip().split()[col])
+        peaks.append((score,i))
+
+    total_n = len(peaks)
+
+    each_g = round(float(total_n)/ng,0)
+
+    index_g = 1
+
+    peaks = sorted(peaks,key=itemgetter(0))
+
+    ofhd = open(sys.argv[3]+"."+str(index_g),"w")
+
+    m = 0
+    for (s,i) in peaks:
+        if m < each_g:
+            ofhd.write(i)
+            m+=1
+        else:
+            ofhd.close()
+            index_g += 1
+            ofhd = open(sys.argv[3]+"."+str(index_g),"w")
+            ofhd.write(i)
+            m = 1
+    ofhd.close()
+if __name__ == '__main__':
+    main()
                    'Scripts/strand_bed_bigwig_profile.py',
                    'Scripts/strand_bed_bigwig_dump.py',
                    'Scripts/batch_convert_ids.py',
-                   'Scripts/pqtable_stat.py'
+                   'Scripts/pqtable_stat.py',
+                   'Scripts/quantile.py'
 #                   'Scripts/hmm_conception.py',
                    ],