Merge branch 'master' of mus.cacr.caltech.edu:htsworkflow
[htsworkflow.git] / scripts / htsw-elandseq
diff --git a/scripts/htsw-elandseq b/scripts/htsw-elandseq
new file mode 100755 (executable)
index 0000000..6a5178c
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+import optparse
+import os
+import sys
+
+from htsworkflow.pipelines.eland import extract_eland_sequence
+
+def make_parser():
+  usage = "usage: %prog [options] infile [outfile]"
+
+  parser = optparse.OptionParser(usage)
+  parser.add_option("-e", "--extract", dest="slice",
+    default=":",
+    help="provide a python slice operator to select a portion of an eland file")
+  return parser
+
+def main(argv):
+  parser = make_parser()
+
+  (opt, args) = parser.parse_args(argv)
+
+  if len(args) not in (0, 1, 2):
+    parser.error('incorrect number of arguments')
+
+  # get our slice coordinates
+  start, end = opt.slice.split(':')
+  if len(start) > 0:
+    start = int(start)
+  else:
+    start = None
+  if len(end) > 0:
+    end = int(end)
+  else:
+    end = None
+
+  # open infile
+  if len(args) > 0:
+    instream = open(args[0],'r')
+  else:
+    instream = sys.stdin
+
+  if len(args) > 1:
+    outstream = open(args[1],'w')
+  else:
+    outstream = sys.stdout
+
+  extract_eland_sequence(instream, outstream, start, end)
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
+