aboutsummaryrefslogtreecommitdiff
path: root/src/filter_average_binding.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/filter_average_binding.py')
-rw-r--r--src/filter_average_binding.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/filter_average_binding.py b/src/filter_average_binding.py
new file mode 100644
index 0000000..d250c98
--- /dev/null
+++ b/src/filter_average_binding.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+import sys
+import os
+
+debug = os.environ.get("debug", False)
+
+from subprocess import Popen
+from subprocess import PIPE
+
+def get_length(fn):
+
+ cmd = 'grep "^>" ' + fn + " -v | tr -d '\\n' | wc -c"
+
+ if debug:
+ print "loading sequence end points"
+ print "executing: " + cmd
+
+ points_fh = Popen(cmd, stdout=PIPE, shell=True)
+
+ return int(points_fh.stdout.readline())
+
+if len(sys.argv) < 2:
+ print "filter_average_binding.py foreground.fa binding_distance"
+ exit()
+
+foreground = sys.argv[1]
+distance = int(sys.argv[2])
+
+genome_length = get_length(foreground)
+
+for line in sys.stdin:
+ (mer, count) = line.split()
+ if (genome_length / int(count)) < distance:
+ sys.stdout.write(line)
+