aboutsummaryrefslogtreecommitdiff
path: root/src/filter_average_binding.py
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-03-25 16:33:36 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2014-03-25 16:33:36 -0400
commit06fa848b90982ddcd4308bb88d70a0d5f11f785b (patch)
tree472f8e8675a3b01060159bcf24cd1b2c35fb5d9e /src/filter_average_binding.py
parent55d58f92e388bbed44963565c5073c444ffa60b2 (diff)
add average binding filter
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)
+