#!/usr/bin/env python

#Copyright (C) 2013 by Glenn Hickey
#
#Released under the MIT license, see LICENSE.txt
import sys
import os
import argparse

from pybedtools import BedTool, Interval

"""
Remove everything past the first | in the name column
"""

def main(argv=None):
    if argv is None:
        argv = sys.argv

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description="Cut names off at first |")
    parser.add_argument("inBed", help="bed with ltr results to process")
    parser.add_argument("outBed", help="bed to write output to.")

    args = parser.parse_args()
    assert os.path.exists(args.inBed)
    outFile = open(args.outBed, "w")

    for interval in BedTool(args.inBed).sort():
        interval.name = interval.name[:interval.name.find("|")]
        outFile.write(str(interval))

    outFile.close()
        
if __name__ == "__main__":
    sys.exit(main())

@@ -221,16 +221,22 @@
  first %7C
+ and /
  in the 
@@ -466,16 +466,25 @@
  first %7C
+ and or /
 %22)%0A    p
@@ -837,16 +837,80 @@
 d(%22%7C%22)%5D%0A
+        interval.name = interval.name%5B:interval.name.find(%22/%22)%5D%0A
         

add / filter