def removecontains(args):
    """
    %prog removecontains 4-unitigger/best.contains asm.gkpStore

    Remove contained reads from gkpStore. This will improve assembly contiguity
    without sacrificing accuracy, when using bogart unitigger.
    """
    p = OptionParser(removecontains.__doc__)
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    contains, gkpStore = args

    s = set()
    fp = open(contains)
    for row in fp:
        if row[0] == '#':
            continue
        iid = int(row.split()[0])
        s.add(iid)

    cmd = "gatekeeper -dumpfragments -lastfragiid {}".format(gkpStore)
    gkpmsg = popen(cmd).read()
    last_iid = int(gkpmsg.strip().split()[-1])

    ndeleted = 0
    editfile = "delete.edit"
    fw = open(editfile, "w")
    for iid in xrange(1, last_iid + 1):
        if iid in s:
            print("frg iid {0} isdeleted 1".format(iid), file=fw)
            ndeleted += 1

    fw.close()
    assert len(s) == ndeleted
    logging.debug("A total of {0} contained reads flagged as deleted."\
                  .format(ndeleted))
    print("Now you can run:", file=sys.stderr)
    print("$ gatekeeper --edit {0} {1}".format(editfile, gkpStore), file=sys.stderr)
def removecontains ( args ) : p = OptionParser ( removecontains . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) contains , gkpStore = args s = set ( ) fp = open ( contains ) for row in fp : if row [ 0 ] == '#' : continue iid = int ( row . split ( ) [ 0 ] ) s . add ( iid ) cmd = "gatekeeper -dumpfragments -lastfragiid {}" . format ( gkpStore ) gkpmsg = popen ( cmd ) . read ( ) last_iid = int ( gkpmsg . strip ( ) . split ( ) [ - 1 ] ) ndeleted = 0 editfile = "delete.edit" fw = open ( editfile , "w" ) for iid in xrange ( 1 , last_iid + 1 ) : if iid in s : print ( "frg iid {0} isdeleted 1" . format ( iid ) , file = fw ) ndeleted += 1 fw . close ( ) assert len ( s ) == ndeleted logging . debug ( "A total of {0} contained reads flagged as deleted." . format ( ndeleted ) ) print ( "Now you can run:" , file = sys . stderr ) print ( "$ gatekeeper --edit {0} {1}" . format ( editfile , gkpStore ) , file = sys . stderr )
%prog removecontains 4-unitigger/best.contains asm.gkpStore

    Remove contained reads from gkpStore. This will improve assembly contiguity
    without sacrificing accuracy, when using bogart unitigger.