ribolands/pathfinder.py
def main():
    import sys
    import argparse
    """ A wrapper for ViennaRNA findpath functions. """
    parser = argparse.ArgumentParser()
    parser.add_argument("-v", "--verbose", action='count', default = 0,
            help = "Verbose output, e.g. the folding pathway. (-vv increases verbosity.)")
    #parser.add_argument("-w","--search-width", type = int, default = None, 
    #        help = "Adjust upper bound for findpath search.")
    #parser.add_argument("-m","--max-energy", type = float, default = None,
    #        help = "Specify upper bound for barrier energy (kcal/mol).")
    #parser.add_argument("--split", action = "store_true",
    #        help = "Split findpath into subproblems, if possible.")
    parser.add_argument("--minh", type = int, default = None,
            metavar = '<int>',
            help = "Set a minimum barrier height for path flooding.")
    parser.add_argument("-e", "--elementary-moves", action = "store_true",
            help = "Elementary base-pair moves only.")
    parse_model_details(parser)
    args = parser.parse_args()

    # Parsing RNAsubopt-like file.
    seq = None
    ndata = dict()
    for e, line in enumerate(sys.stdin):
        if e == 0:
            seq = line.split()[0]
            continue
        l = line.split()
        if l[0]:
            en = int(round(float(l[1])*100)) if len(l) > 1 else None
            ndata[l[0]] = {'energy': en}
        else:
            print(f'Troubles with input line {e+1} {line=}')

    # Set model details.
    md = RNA.md()
    md.temperature = args.temp
    md.dangles = args.dangles
    md.special_hp = not args.noTetra
    md.logML = 0
    md.noGU = args.noGU
    md.noGUclosure = args.noClosingGU

    #print(seq)
    #fc = RNA.fold_compound(seq, md)
    #for ss in ndata:
    #    if ndata[ss]['energy'] is None:
    #        ndata[ss]['energy'] = int(round(fc.eval_structure(ss) * 100))
    #    print(ss, ndata[ss]['energy'])

    # Get the guide graph for all inputs:
    print(f'Guide graph construction with {len(ndata)} structures.')
    gnodes, gedges = get_guide_graph(seq, md, ndata)

    if len(gnodes):
        print('Some important structures have been included automatically:')
        for gn in gnodes:
            print(gn[0], gn[1])
            ndata[gn[0]] = {'energy': gn[1]}

    if args.elementary_moves: # Do you want to have a base-pair neighborhood only?
        print('Using elementary moves only.')
        edata = dict()
        for (x, y) in gedges:
            if get_bpd_cache(x, y) == 1:
                edata[(x,y)] = {'saddle_energy': max(ndata[x]['energy'], 
                                                     ndata[y]['energy'])}
            else:
                edata[(x,y)] = {'saddle_energy': None}
    else:
        print('Neighborhood flooding ...')
        ndata, edata = neighborhood_flooding((seq, md), ndata, gedges, minh = args.minh)

    if args.minh:
        print(f'Top down coarse graining with {args.minh=} ({len(ndata)=}, {len(edata)=}).')
        edata = {k: v for k, v in edata.items() if v['saddle_energy'] is not None}
        cgn, cge, cgm = top_down_coarse_graining(ndata, edata, minh = args.minh)
    else:
        print(f'No coarse graining.')
        cgn, cge, cgm = ndata, edata, {n:[] for n in ndata}
    print('Total hidden nodes:', sum(len(cgm[n]) for n in cgn))
    print_barfile(seq, cgn, cge, cgm)
 A wrapper for ViennaRNA findpath functions. 
A wrapper for ViennaRNA findpath functions.
A wrapper for ViennaRNA findpath functions .
def main():
    import sys
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("-v", "--verbose", action='count', default = 0,
            help = "Verbose output, e.g. the folding pathway. (-vv increases verbosity.)")
    parser.add_argument("--minh", type = int, default = None,
            metavar = '<int>',
            help = "Set a minimum barrier height for path flooding.")
    parser.add_argument("-e", "--elementary-moves", action = "store_true",
            help = "Elementary base-pair moves only.")
    parse_model_details(parser)
    args = parser.parse_args()
    seq = None
    ndata = dict()
    for e, line in enumerate(sys.stdin):
        if e == 0:
            seq = line.split()[0]
            continue
        l = line.split()
        if l[0]:
            en = int(round(float(l[1])*100)) if len(l) > 1 else None
            ndata[l[0]] = {'energy': en}
        else:
            print(f'Troubles with input line {e+1} {line=}')
    md = RNA.md()
    md.temperature = args.temp
    md.dangles = args.dangles
    md.special_hp = not args.noTetra
    md.logML = 0
    md.noGU = args.noGU
    md.noGUclosure = args.noClosingGU
    print(f'Guide graph construction with {len(ndata)} structures.')
    gnodes, gedges = get_guide_graph(seq, md, ndata)
    if len(gnodes):
        print('Some important structures have been included automatically:')
        for gn in gnodes:
            print(gn[0], gn[1])
            ndata[gn[0]] = {'energy': gn[1]}
    if args.elementary_moves: 
        print('Using elementary moves only.')
        edata = dict()
        for (x, y) in gedges:
            if get_bpd_cache(x, y) == 1:
                edata[(x,y)] = {'saddle_energy': max(ndata[x]['energy'], 
                                                     ndata[y]['energy'])}
            else:
                edata[(x,y)] = {'saddle_energy': None}
    else:
        print('Neighborhood flooding ...')
        ndata, edata = neighborhood_flooding((seq, md), ndata, gedges, minh = args.minh)
    if args.minh:
        print(f'Top down coarse graining with {args.minh=} ({len(ndata)=}, {len(edata)=}).')
        edata = {k: v for k, v in edata.items() if v['saddle_energy'] is not None}
        cgn, cge, cgm = top_down_coarse_graining(ndata, edata, minh = args.minh)
    else:
        print(f'No coarse graining.')
        cgn, cge, cgm = ndata, edata, {n:[] for n in ndata}
    print('Total hidden nodes:', sum(len(cgm[n]) for n in cgn))
    print_barfile(seq, cgn, cge, cgm)
def main ( ) : import sys import argparse parser = argparse . ArgumentParser ( ) parser . add_argument ( "-v" , "--verbose" , action = 'count' , default = 0 , help = "Verbose output, e.g. the folding pathway. (-vv increases verbosity.)" ) parser . add_argument ( "--minh" , type = int , default = None , metavar = '<int>' , help = "Set a minimum barrier height for path flooding." ) parser . add_argument ( "-e" , "--elementary-moves" , action = "store_true" , help = "Elementary base-pair moves only." ) parse_model_details ( parser ) args = parser . parse_args ( ) seq = None ndata = dict ( ) for e , line in enumerate ( sys . stdin ) : if e == 0 : seq = line . split ( ) [ 0 ] continue l = line . split ( ) if l [ 0 ] : en = int ( round ( float ( l [ 1 ] ) * 100 ) ) if len ( l ) > 1 else None ndata [ l [ 0 ] ] = { 'energy' : en } else : print ( f'Troubles with input line {e+1} {line=}' ) md = RNA . md ( ) md . temperature = args . temp md . dangles = args . dangles md . special_hp = not args . noTetra md . logML = 0 md . noGU = args . noGU md . noGUclosure = args . noClosingGU print ( f'Guide graph construction with {len(ndata)} structures.' ) gnodes , gedges = get_guide_graph ( seq , md , ndata ) if len ( gnodes ) : print ( 'Some important structures have been included automatically:' ) for gn in gnodes : print ( gn [ 0 ] , gn [ 1 ] ) ndata [ gn [ 0 ] ] = { 'energy' : gn [ 1 ] } if args . elementary_moves : print ( 'Using elementary moves only.' ) edata = dict ( ) for ( x , y ) in gedges : if get_bpd_cache ( x , y ) == 1 : edata [ ( x , y ) ] = { 'saddle_energy' : max ( ndata [ x ] [ 'energy' ] , ndata [ y ] [ 'energy' ] ) } else : edata [ ( x , y ) ] = { 'saddle_energy' : None } else : print ( 'Neighborhood flooding ...' ) ndata , edata = neighborhood_flooding ( ( seq , md ) , ndata , gedges , minh = args . minh ) if args . minh : print ( f'Top down coarse graining with {args.minh=} ({len(ndata)=}, {len(edata)=}).' ) edata = { k : v for k , v in edata . items ( ) if v [ 'saddle_energy' ] is not None } cgn , cge , cgm = top_down_coarse_graining ( ndata , edata , minh = args . minh ) else : print ( f'No coarse graining.' ) cgn , cge , cgm = ndata , edata , { n : [ ] for n in ndata } print ( 'Total hidden nodes:' , sum ( len ( cgm [ n ] ) for n in cgn ) ) print_barfile ( seq , cgn , cge , cgm )
A wrapper for ViennaRNA findpath functions.
A wrapper for ViennaRNA findpath functions .
""" A wrapper for ViennaRNA findpath functions. """ #parser.add_argument("-w","--search-width", type = int, default = None,  #        help = "Adjust upper bound for findpath search.") #parser.add_argument("-m","--max-energy", type = float, default = None, #        help = "Specify upper bound for barrier energy (kcal/mol).") #parser.add_argument("--split", action = "store_true", #        help = "Split findpath into subproblems, if possible.") # Parsing RNAsubopt-like file. # Set model details. #print(seq) #fc = RNA.fold_compound(seq, md) #for ss in ndata: #    if ndata[ss]['energy'] is None: #        ndata[ss]['energy'] = int(round(fc.eval_structure(ss) * 100)) #    print(ss, ndata[ss]['energy']) # Get the guide graph for all inputs: # Do you want to have a base-pair neighborhood only?