def grass(args):
    """
    %prog grass coge_master_table.txt james.txt

    Validate SynFind pan-grass set against James. This set can be generated:

    https://genomevolution.org/r/fhak
    """
    p = OptionParser(grass._doc__)
    p.set_verbose()
    opts, args = p.parse_args(args)

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

    master, james = args

    fp = open(master)
    next(fp)
    master_store = defaultdict(set)
    for row in fp:
        atoms = row.split()
        s = set()
        for x in atoms[1:6]:
            m = x.split(",")
            s |= set(m)
        if '-' in s:
            s.remove('-')

        a = atoms[1]
        master_store[a] |= set(s)

    fp = open(james)
    next(fp)
    james_store = {}
    tandems = set()
    for row in fp:
        atoms = row.split()
        s = set()
        Os = set()
        for x in atoms[:-1]:
            m = x.split("||")
            if m[0].startswith("Os"):
                Os |= set(m)
            if m[0].startswith("http"):
                continue
            if m[0].startswith("chr"):
                m = ["proxy"]
            if "||" in x:
                tandems |= set(m)
            s |= set(m)

        for x in Os:
            james_store[x] = s

    jaccards = []
    corr_jaccards = []
    perfect_matches = 0
    corr_perfect_matches = 0
    for k, v in james_store.items():
        if k not in master_store:
            continue
        m = master_store[k]
        jaccard = len(v & m) * 100 / len(v | m)
        jaccards.append(jaccard)
        diff = (v ^ m ) - tandems
        corr_jaccard = 100 - len(diff) * 100 / len(v | m)
        corr_jaccards.append(corr_jaccard)
        if opts.verbose:
            print(k)
            print(v)
            print(m)
            print(diff)
            print(jaccard)
        if jaccard > 99:
            perfect_matches += 1
        if corr_jaccard > 99:
            corr_perfect_matches += 1

    logging.debug("Perfect matches: {0}".format(perfect_matches))
    logging.debug("Perfect matches (corrected): {0}".format(corr_perfect_matches))
    print("Jaccards:", SummaryStats(jaccards))
    print("Corrected Jaccards:", SummaryStats(corr_jaccards))
def grass ( args ) : p = OptionParser ( grass . _doc__ ) p . set_verbose ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) master , james = args fp = open ( master ) next ( fp ) master_store = defaultdict ( set ) for row in fp : atoms = row . split ( ) s = set ( ) for x in atoms [ 1 : 6 ] : m = x . split ( "," ) s |= set ( m ) if '-' in s : s . remove ( '-' ) a = atoms [ 1 ] master_store [ a ] |= set ( s ) fp = open ( james ) next ( fp ) james_store = { } tandems = set ( ) for row in fp : atoms = row . split ( ) s = set ( ) Os = set ( ) for x in atoms [ : - 1 ] : m = x . split ( "||" ) if m [ 0 ] . startswith ( "Os" ) : Os |= set ( m ) if m [ 0 ] . startswith ( "http" ) : continue if m [ 0 ] . startswith ( "chr" ) : m = [ "proxy" ] if "||" in x : tandems |= set ( m ) s |= set ( m ) for x in Os : james_store [ x ] = s jaccards = [ ] corr_jaccards = [ ] perfect_matches = 0 corr_perfect_matches = 0 for k , v in james_store . items ( ) : if k not in master_store : continue m = master_store [ k ] jaccard = len ( v & m ) * 100 / len ( v | m ) jaccards . append ( jaccard ) diff = ( v ^ m ) - tandems corr_jaccard = 100 - len ( diff ) * 100 / len ( v | m ) corr_jaccards . append ( corr_jaccard ) if opts . verbose : print ( k ) print ( v ) print ( m ) print ( diff ) print ( jaccard ) if jaccard > 99 : perfect_matches += 1 if corr_jaccard > 99 : corr_perfect_matches += 1 logging . debug ( "Perfect matches: {0}" . format ( perfect_matches ) ) logging . debug ( "Perfect matches (corrected): {0}" . format ( corr_perfect_matches ) ) print ( "Jaccards:" , SummaryStats ( jaccards ) ) print ( "Corrected Jaccards:" , SummaryStats ( corr_jaccards ) )
%prog grass coge_master_table.txt james.txt

    Validate SynFind pan-grass set against James. This set can be generated:

    https://genomevolution.org/r/fhak