def main():
    """ Interkin - folding kinetics of two interacting RNA molecules
      * call the pipeline: "RNAsubopt | barriers" in order to get tree files and
          rate matrices
      * make a reaction graph composed of uni- and bi-molecular reactions found
          in the rate matrices
      * visualize the graph using networkx or D3js
      * calculate the equilibrium distribution and see how much it differs from
          the complete cofolded ensemble
      * dump the graph in order to translate it into a ODE system using the perl
          SundialsWrapper library

      TODO: write a landscape library in order to get rid of BarMap dependency
    """
    args = get_interkin_args()

    """ Read Input & Update Arguments """
    name, inseq = ril.parse_vienna_stdin(sys.stdin)

    if args.name == '':
        args.name = name
    else:
        name = args.name

    if args.verbose:
        print "# Input: {:s} {:s} {:6.2f} kcal/mol".format(name, inseq, args.s_ener)

    if args.s_ener == 0:
        args.s_ener, args.s_maxn = ril.sys_subopt_range(inseq,
                                                        nos=args.s_maxn,
                                                        maxe=20,  # args.s_maxe,
                                                        verb=args.verbose)
        if args.verbose:
            print "# Energyrange {:.2f} computes {:d} sequences".format(
                args.s_ener, args.s_maxn)

    """ Dirty way to use RNAsubopt symmetry correction as commandline interface """
    s_options = ['|', args.spatch]
    if args.symmetry:
        s_options.append('-s')

    """ Choose the set of species for further analysis """
    # default: [A, A, AA], [A, B, AB, AA, BB], [A, B, C, AA, AB, AC, BB, BC, CC]
    # nohomo: [A, B, AB] (for debugging)
    specieslist = get_species(inseq, args.nohomo)

    """ Compute folding kinetics """
    bionly = False  # Debugging option, compute kinetics only from cofold tree
    RG, nodes = cofold_barriers(name, specieslist,
                                s_ener=args.s_ener,
                                s_maxn=args.s_maxn,
                                s_opts=s_options,
                                barriers='barriers',
                                minh=args.b_minh,
                                maxn=args.b_maxn,
                                k0=args.k0,
                                temp=37.0,
                                moves='single-base-pair',
                                gzip=True,
                                rates=True,
                                bsize=False,
                                saddle=False,
                                bionly=bionly,
                                force=args.force,
                                verb=args.verbose)

    # NOTE: Hack to check out if crnsimulator works like sundials:
    from crnsimulator import writeODElib
    import sympy

    ntv = dict()
    vtn = dict()
    oV = []
    for e, n in enumerate(filter(lambda x: nodes[x] != 0, nodes)):
        var = n[0].translate(string.maketrans("&", "_")) + '_' + str(e)
        ntv[n] = var
        vtn[var] = n
        oV.append(var)

    NLRG = nx.relabel_nodes(RG, ntv)

    oR = dict()
    ode = dict()
    for r in NLRG.nodes_iter():
        if r in vtn:
            continue
        rate = 'k' + str(len(oR.keys()))

        reactants = []
        for reac in NLRG.predecessors_iter(r):
            for i in range(NLRG.number_of_edges(reac, r)):
                reactants.append(str(reac))

        products = []
        for prod in NLRG.successors_iter(r):
            edict = NLRG.get_edge_data(r, prod)
            oR[rate] = str(edict[0]['weight'])
            for i in range(NLRG.number_of_edges(r, prod)):
                products.append(str(prod))

        for x in reactants:
            if x in ode:
                ode[x].append(['-' + rate] + reactants)
            else:
                ode[x] = [['-' + rate] + reactants]

        for x in products:
            if x in ode:
                ode[x].append([rate] + reactants)
            else:
                ode[x] = [[rate] + reactants]

    oM = []
    for dx in oV:
        sfunc = sympy.sympify(
            ' + '.join(['*'.join(map(str, xp)) for xp in ode[dx]]))
        ode[dx] = sfunc
        oM.append(sfunc)

    oM = sympy.Matrix(oM)
    oJ = None

    odefile, odename = writeODElib(
        oV, oM, jacobian=oJ, rdict=oR, filename='interkin')
    print 'Happy simulating: ODE system wrote to File:', odefile

    '''

  """ Compute equilibrium properties """
  # plot RNAcofold equilibrium properties with a given range of a0s and b0s
  # plot gradient basin equilibrium for a given range of a0s and b0s
  # => [seq&seq], [K]
  kT=0.61632077549999997
  a0s = map(lambda x: 10**-x, range(9,8,-3))
  b0s = map(lambda x: 10**-x, range(6,1,-1))

  eA =0
  eB =0
  eAA=0
  eAB=0
  eBB=0
  for (name, species) in specieslist :
    if '&' not in name: continue
    [seqA, seqB] = species.split('&')
    [nA, nB] = name.split('&')
    plotname = args.name+'_'+nA+'_'+nB
    homodimer = (seqA == seqB)

    """ if it is a homodimer, G_A = G_B and G_AB = G_AA = G_BB """
    if not homodimer :
      [G_A, G_B, G_AB, G_AA, G_BB] = conc.cofold_free_energies(species)
      print 'ref_cfold', species, nA, G_A, nB, G_B, \
          nA+nB, G_AB, nA*2, G_AA, nB*2, G_BB
      eqdata = conc.cofold_equilibrium(species, a0s, b0s)
      conc.cofold_plot(eqdata,plotname+'_cofold_plot')

      """
      [G_A, G_B, G_AB, G_AA, G_BB] = basin_free_energies(species)
      print 'ref_cfold', species, nA, G_A, nB, G_B, \
          nA+nB, G_AB, nA*2, G_AA, nB*2, G_BB
      eqdata = conc.cofold_equilibrium(species, a0s, b0s)
      """

    RNA.cvar.cut_point = len(seqA)+1
    [stmp,G_A,G_B,G_AB,waste] = RNA.co_pf_fold(seqA+seqB,None)
    K = math.e**((G_A+G_B-G_AB)/kT)
    print 'ref_bimol', species, nA, G_A, nB, G_B, nA+nB, G_AB, "K", K
    if homodimer :
      eqdata = conc.bimol_equilibrium(K, b0s, [])
      conc.homodim_plot(eqdata,plotname+'_bimol_plot')
    else :
      eqdata = conc.bimol_equilibrium(K, a0s, b0s)
      conc.bimol_plot(eqdata,plotname+'_bimol_plot')

    if not bionly :
      [G_A, G_B, G_AB] = unimolecular_basins(RG, name, species, args, nodes)
      K = math.e**((G_A+G_B-G_AB)/kT)
      print 'uitree', species, nA, G_A, nB, G_B, nA+nB, G_AB, "K", K

    [G_ApB, G_AB] = bimolecular_cofold_basins(
        RG, name, species, args, nodes, bionly)
    K = math.e**((G_ApB-G_AB)/kT)
    print 'bitree', species, nA+'+'+nB, G_ApB, nA+nB, G_AB, "K", K
    if homodimer :
      eqdata = conc.bimol_equilibrium(K, b0s, [])
      conc.homodim_plot(eqdata, plotname+'_coarse_grain_plot')
    else :
      eqdata = conc.bimol_equilibrium(K, a0s, b0s)
      [a0, b0, eA, eB, eAB] = zip(*eqdata)
      conc.bimol_plot(eqdata, plotname+'_coarse_grain_plot')

  if False : # Depricated and a bit ugly code, it is for debugging only
    """ Compare lists of gradient basin energies for fake and true dimers """
    interkin_equilibrium(specieslist, args)

  # Calculate equilibrium distribution by hand... (like for prions!)
  # use that as a start for the simulation:
  # *) calculate the concentrations of species
  # *) calculate the occupancy of an lmin at equilibrium
  # *) return the equilibrium starting population for a simulation ...
  '''

    return
def cofold_barriers(_name, species,
                    s_opts=['|', 'pylands_spatch.py'],
                    s_ener=None,
                    s_maxn=59000000,
                    barriers='barriers',
                    minh=0.001,
                    maxn=50,
                    k0=1.0,
                    temp=37.0,
                    moves='single-base-pair',
                    gzip=True,
                    rates=True,
                    bsize=False,
                    saddle=False,
                    bionly=False,
                    force=False,
                    verb=False):
    """ Simulate inter-molecular folding
    Compute folding kinetics
      returns the biggest connected component and a list of nodes
      TODO:
        *) @h**o-dimers: RNAsubopt-barriers does not correct for two-fold symmetry!
    """

    noLP = False  # MUST BE FALSE!
    circ = False  # MUST BE FALSE!
    mfile = ''

    if minh > 0.5:
        print "Warning: increasing the minh option for cofolded barriers may " + \
            "destroy the separation of monomer and dimer gradient basins!"

    RG = nx.MultiDiGraph()
    sortednodes = c.OrderedDict()
    hypercount = [0]

    for spe, seq in species:
        name = _name + "_" + spe

        if '&' in name:
            """ true dimer only run """
            name = name.translate(string.maketrans("&", "_"))

            if s_ener is None:
                myener, nos = ril.sys_subopt_range(
                    seq, nos=s_maxn, maxe=20, verb=verb)
            else:
                myener = s_ener

            if bionly is False:
                _fname = name + "_truedimers"
                s_opts.append('-d')
                sfile = ril.sys_suboptimals(_fname, seq,
                                            ener=myener, opts=s_opts, verb=verb, force=force)
                [sfile, bfile, efile, rfile, psfile] = ril.sys_barriers(_fname, seq, sfile,
                                                                        barriers=barriers, minh=minh, maxn=maxn, k0=k0, temp=temp,
                                                                        verb=verb, force=force)
                # this function modifies sortednodes and hypercount... not
                # nice!
                add_edges(
                    RG,
                    bfile,
                    rfile,
                    'uni',
                    spe,
                    seq,
                    sortednodes,
                    hypercount)
                s_opts.pop()

            _fname = name
            sfile = ril.sys_suboptimals(_fname, seq,
                                        ener=myener, opts=[], verb=verb, force=force)
            [sfile, bfile, efile, rfile, psfile] = ril.sys_barriers(_fname, seq, sfile,
                                                                    barriers=barriers, minh=minh, maxn=maxn, k0=k0, temp=temp,
                                                                    verb=verb, force=force)
            if bionly:
                add_edges(
                    RG,
                    bfile,
                    rfile,
                    'bionly',
                    spe,
                    seq,
                    sortednodes,
                    hypercount)
            else:
                add_edges(
                    RG,
                    bfile,
                    rfile,
                    'bi',
                    spe,
                    seq,
                    sortednodes,
                    hypercount)
        elif bionly:
            continue
        else:
            if s_ener is None:
                myener, nos = ril.sys_subopt_range(
                    seq, nos=s_maxn, maxe=20, verb=verb)
            else:
                myener = s_ener
            _fname = name
            sfile = ril.sys_suboptimals(_fname, seq,
                                        ener=myener, opts=[], verb=verb, force=force)
            [sfile, bfile, efile, rfile, psfile] = ril.sys_barriers(_fname, seq, sfile,
                                                                    barriers=barriers, minh=minh, maxn=maxn, k0=k0, temp=temp,
                                                                    verb=verb, force=force)
            add_edges(
                RG,
                bfile,
                rfile,
                'uni',
                spe,
                seq,
                sortednodes,
                hypercount)

        print "connected components",
        print [len(comp) for comp in
               sorted(nx.strongly_connected_components(RG), key=len, reverse=True)]

    for e, comp in enumerate(
            sorted(nx.strongly_connected_components(RG), key=len, reverse=True)):
        # print 'e', comp
        if e == 0:
            continue
        print "Discarding connected component!", len(comp)  # , comp
        for i in comp:
            sortednodes[i] = 0

    return max(nx.strongly_connected_component_subgraphs(
        RG), key=len), sortednodes
示例#3
0
def main():
  """ Interkin - folding kinetics of two interacting RNA molecules
    * call the pipeline: "RNAsubopt | barriers" in order to get tree files and
        rate matrices
    * make a reaction graph composed of uni- and bi-molecular reactions found
        in the rate matrices
    * visualize the graph using networkx or D3js
    * calculate the equilibrium distribution and see how much it differs from 
        the complete cofolded ensemble
    * dump the graph in order to translate it into a ODE system using the perl
        SundialsWrapper library

    TODO: write a landscape library in order to get rid of BarMap dependency
  """
  args = get_interkin_args()

  """ Read Input & Update Arguments """
  name, inseq = ril.parse_vienna_stdin(sys.stdin)

  if args.name == '' : 
    args.name = name
  else :
    name = args.name

  if args.verbose: 
    print "# Input: {:s} {:s} {:6.2f} kcal/mol".format(name, inseq, args.s_ener)
    
  if args.s_ener == 0 :
    args.s_ener, args.s_maxn = ril.sys_subopt_range(inseq, 
        nos=args.s_maxn, 
        maxe=20, #args.s_maxe, 
        verb=args.verbose)
    if args.verbose:
      print "# Energyrange {:.2f} computes {:d} sequences".format(
          args.s_ener, args.s_maxn)

  """ Dirty way to use RNAsubopt symmetry correction as commandline interface """
  s_options = ['|', args.spatch]
  if args.symmetry : s_options.append('-s') 

  """ Choose the set of species for further analysis """
  # default: [A, A, AA], [A, B, AB, AA, BB], [A, B, C, AA, AB, AC, BB, BC, CC] 
  # nohomo: [A, B, AB] (for debugging)
  specieslist = get_species(inseq, args.nohomo)

  """ Compute folding kinetics """
  bionly = False # Debugging option, compute kinetics only from cofold tree
  RG, nodes = cofold_barriers(name, specieslist, 
      s_ener = args.s_ener,
      s_maxn = args.s_maxn,
      s_opts = s_options,
      barriers='barriers',
      minh=args.b_minh,
      maxn=args.b_maxn,
      k0=args.k0,
      temp=37.0,
      moves='single-base-pair',
      gzip=True,
      rates=True,
      bsize=False,
      saddle=False,
      bionly=bionly,
      force=args.force,
      verb=args.verbose)

  ##### NOTE: Hack to check out if crnsimulator works like sundials:
  from crnsimulator import writeODElib
  import sympy

  ntv = dict()
  vtn = dict()
  oV = []
  for e, n in enumerate(filter(lambda x : nodes[x] != 0, nodes)):
    var = n[0].translate(string.maketrans("&", "_"))+'_'+str(e)
    ntv[n] = var
    vtn[var] = n
    oV.append(var)

  NLRG = nx.relabel_nodes(RG, ntv)

  oR = dict()
  ode = dict()
  for r in NLRG.nodes_iter() :
    if r in vtn: continue
    rate = 'k'+str(len(oR.keys()))

    reactants = []
    for reac in NLRG.predecessors_iter(r) :
      for i in range(NLRG.number_of_edges(reac, r)) :
        reactants.append(str(reac))

    products = []
    for prod in NLRG.successors_iter(r) :
      edict = NLRG.get_edge_data(r, prod)
      oR[rate] = str(edict[0]['weight'])
      for i in range(NLRG.number_of_edges(r, prod)) :
        products.append(str(prod))

    for x in reactants: 
      if x in ode :
        ode[x].append(['-'+rate] + reactants)
      else :
        ode[x]= [['-'+rate] + reactants]

    for x in products: 
      if x in ode :
        ode[x].append([rate] + reactants)
      else :
        ode[x]= [[rate] + reactants]

  oM = []
  for dx in oV :
    sfunc = sympy.sympify(' + '.join(['*'.join(map(str,xp)) for xp in ode[dx]]))
    ode[dx] = sfunc
    oM.append(sfunc)

  oM = sympy.Matrix(oM)
  oJ = None

  odefile, odename = writeODElib(oV, oM, jacobian=oJ, rdict=oR, filename='interkin')
  print 'Happy simulating: ODE system wrote to File:', odefile

  '''

  """ Compute equilibrium properties """
  # plot RNAcofold equilibrium properties with a given range of a0s and b0s
  # plot gradient basin equilibrium for a given range of a0s and b0s
  # => [seq&seq], [K]
  kT=0.61632077549999997
  a0s = map(lambda x: 10**-x, range(9,8,-3))
  b0s = map(lambda x: 10**-x, range(6,1,-1))

  eA =0
  eB =0
  eAA=0
  eAB=0
  eBB=0
  for (name, species) in specieslist :
    if '&' not in name: continue
    [seqA, seqB] = species.split('&')
    [nA, nB] = name.split('&')
    plotname = args.name+'_'+nA+'_'+nB
    homodimer = (seqA == seqB)

    """ if it is a homodimer, G_A = G_B and G_AB = G_AA = G_BB """
    if not homodimer :
      [G_A, G_B, G_AB, G_AA, G_BB] = conc.cofold_free_energies(species)
      print 'ref_cfold', species, nA, G_A, nB, G_B, \
          nA+nB, G_AB, nA*2, G_AA, nB*2, G_BB
      eqdata = conc.cofold_equilibrium(species, a0s, b0s)
      conc.cofold_plot(eqdata,plotname+'_cofold_plot')

      """
      [G_A, G_B, G_AB, G_AA, G_BB] = basin_free_energies(species)
      print 'ref_cfold', species, nA, G_A, nB, G_B, \
          nA+nB, G_AB, nA*2, G_AA, nB*2, G_BB
      eqdata = conc.cofold_equilibrium(species, a0s, b0s)
      """
    
    RNA.cvar.cut_point = len(seqA)+1
    [stmp,G_A,G_B,G_AB,waste] = RNA.co_pf_fold(seqA+seqB,None)
    K = math.e**((G_A+G_B-G_AB)/kT)
    print 'ref_bimol', species, nA, G_A, nB, G_B, nA+nB, G_AB, "K", K
    if homodimer :
      eqdata = conc.bimol_equilibrium(K, b0s, [])
      conc.homodim_plot(eqdata,plotname+'_bimol_plot')
    else :
      eqdata = conc.bimol_equilibrium(K, a0s, b0s)
      conc.bimol_plot(eqdata,plotname+'_bimol_plot')

    if not bionly :
      [G_A, G_B, G_AB] = unimolecular_basins(RG, name, species, args, nodes)
      K = math.e**((G_A+G_B-G_AB)/kT)
      print 'uitree', species, nA, G_A, nB, G_B, nA+nB, G_AB, "K", K

    [G_ApB, G_AB] = bimolecular_cofold_basins(
        RG, name, species, args, nodes, bionly)
    K = math.e**((G_ApB-G_AB)/kT)
    print 'bitree', species, nA+'+'+nB, G_ApB, nA+nB, G_AB, "K", K
    if homodimer :
      eqdata = conc.bimol_equilibrium(K, b0s, [])
      conc.homodim_plot(eqdata, plotname+'_coarse_grain_plot')
    else :
      eqdata = conc.bimol_equilibrium(K, a0s, b0s)
      [a0, b0, eA, eB, eAB] = zip(*eqdata)
      conc.bimol_plot(eqdata, plotname+'_coarse_grain_plot')
   
  if False : # Depricated and a bit ugly code, it is for debugging only
    """ Compare lists of gradient basin energies for fake and true dimers """
    interkin_equilibrium(specieslist, args)

  # Calculate equilibrium distribution by hand... (like for prions!)
  # use that as a start for the simulation: 
  # *) calculate the concentrations of species
  # *) calculate the occupancy of an lmin at equilibrium
  # *) return the equilibrium starting population for a simulation ...
  '''

  return
示例#4
0
def cofold_barriers(_name, species,
    s_opts = ['|', 'pylands_spatch.py'],
    s_ener = None,
    s_maxn = 59000000,
    barriers='barriers',
    minh=0.001,
    maxn=50,
    k0=1.0,
    temp=37.0,
    moves='single-base-pair',
    gzip=True,
    rates=True,
    bsize=False,
    saddle=False,
    bionly=False,
    force=False,
    verb=False):
  """ Simulate inter-molecular folding
  Compute folding kinetics 
    returns the biggest connected component and a list of nodes
    TODO: 
      *) @h**o-dimers: RNAsubopt-barriers does not correct for two-fold symmetry!
  """
  
  noLP=False # MUST BE FALSE!
  circ=False # MUST BE FALSE!
  mfile=''

  if minh > 0.5 :
    print "Warning: increasing the minh option for cofolded barriers may " + \
    "destroy the separation of monomer and dimer gradient basins!"

  RG = nx.MultiDiGraph()
  sortednodes = c.OrderedDict()
  hypercount  = [0]

  for spe, seq in species :
    name = _name + "_" + spe

    if '&' in name :
      """ true dimer only run """
      name = name.translate(string.maketrans("&", "_"))
      
      if s_ener is None :
        myener, nos = ril.sys_subopt_range(seq, nos=s_maxn, maxe=20, verb=verb)
      else :
        myener = s_ener

      if bionly is False :
        _fname = name + "_truedimers"
        s_opts.append('-d')
        sfile = ril.sys_suboptimals(_fname, seq, 
            ener=myener, opts=s_opts, verb=verb, force=force)
        [sfile, bfile, efile, rfile, psfile] = ril.sys_barriers(_fname, seq, sfile, 
            barriers=barriers, minh=minh, maxn=maxn, k0=k0, temp=temp, 
            verb=verb, force=force)
        # this function modifies sortednodes and hypercount... not nice!
        add_edges(RG, bfile, rfile, 'uni', spe, seq, sortednodes, hypercount)
        s_opts.pop()

      _fname = name
      sfile = ril.sys_suboptimals(_fname, seq, 
          ener=myener, opts=[], verb=verb, force=force)
      [sfile, bfile, efile, rfile, psfile] = ril.sys_barriers(_fname, seq, sfile, 
          barriers=barriers, minh=minh, maxn=maxn, k0=k0, temp=temp, 
          verb=verb, force=force)
      if bionly :
        add_edges(RG, bfile, rfile, 'bionly', spe, seq, sortednodes, hypercount)
      else :
        add_edges(RG, bfile, rfile, 'bi', spe, seq, sortednodes, hypercount)
    elif bionly :
      continue
    else :
      if s_ener is None :
        myener, nos = ril.sys_subopt_range(seq, nos=s_maxn, maxe=20, verb=verb)
      else :
        myener = s_ener
      _fname = name
      sfile = ril.sys_suboptimals(_fname, seq, 
          ener=myener, opts=[], verb=verb, force=force)
      [sfile, bfile, efile, rfile, psfile] = ril.sys_barriers(_fname, seq, sfile, 
          barriers=barriers, minh=minh, maxn=maxn, k0=k0, temp=temp, 
          verb=verb, force=force)
      add_edges(RG, bfile, rfile, 'uni', spe, seq, sortednodes, hypercount)

    print "connected components", 
    print [len(comp) for comp in 
        sorted(nx.strongly_connected_components(RG), key=len, reverse=True)]

  for e, comp in enumerate(
      sorted(nx.strongly_connected_components(RG), key=len, reverse=True)) :
    #print 'e', comp
    if e == 0 : continue
    print "Discarding connected component!", len(comp)#, comp
    for i in comp: sortednodes[i] = 0

  return max(nx.strongly_connected_component_subgraphs(RG), key=len), sortednodes
示例#5
0
def main(args):
    """ BarMap-v2.0 -- cotransriptional folding
      Dependencies: RNAsubopt, barriers, treekin

      The implementation is split into 4 steps ...
    """
    # Read Input & Update Arguments
    name, seq = ril.parse_vienna_stdin(sys.stdin)

    # One name, just to be clear ...
    (args.name, name) = (args.name, args.name) if args.name else (name, name)

    if args.stop is None:
        args.stop = len(seq)
    else:
        seq = seq[:args.stop]

    print("# Input: {:s} {:s}".format(name, seq))

    if args.s_ener is None:
        args.s_ener, args.s_maxn = ril.sys_subopt_range(seq,
                nos=args.s_maxn, maxe=args.s_maxe, verb=(args.verbose > 0))
        print("# Energyrange {:.2f} computes {:d} sequences".format(
            args.s_ener, args.s_maxn))
    elif args.verbose:
        args.s_ener, args.s_maxn = ril.sys_subopt_range(seq,
                                                        nos=0, maxe=args.s_ener, verb=False)
        print("# Energyrange {:.2f} computes {:d} sequences".format(
            args.s_ener, args.s_maxn))

    if not args.tmpdir:
        args.tmpdir = 'BarMap_' + args.name

    if not os.path.exists(args.tmpdir):
        os.makedirs(args.tmpdir)

    """# Starting with BarMap computations ... """

    while True:
        print("""# writing RNAsubopt files ... """)
        sname = "{}/{}-ener_{:.2f}".format(args.tmpdir, args.name, args.s_ener)
        #if args.circ: myfile += '_circ'
        if args.noLP:
            sname += '_noLP'
        sfiles = barmap_subopts(sname, seq, args)

        print("""# writing barriers files ... """)
        bname = "{}-minh_{}-maxn_{}-k0_{}".format(sname,
                                                  args.b_minh, args.b_maxn, args.k0)
        bfiles = barmap_barriers(bname, seq, sfiles, args)

        print("""# writing/parsing mapping information ... """)
        plist = barmap_mapping(bname, seq, args)

        print("""# simulations using treekin ... """)
        try:
            tfiles = barmap_treekin(bname, seq, bfiles, plist, args)
            break
        except LostPopulationError as e:
            if args.adaptive:
                args.s_ener += 2
                print('repeating caluclations with higher energy:', args.s_ener)
            else:
                print('caluclations failed with current suboptimal energy range:', args.s_ener)
                break
        except SubprocessError as e:
            if args.adaptive:
                args.s_ener += 2
                print('repeating caluclations with higher energy:', args.s_ener)
            else:
                print('caluclations failed with current suboptimal energy range:', args.s_ener)
                break

    if args.xmgrace or args.pyplot:
        print("""# Processing treekin results for plotting ... """)
        courses = get_plot_data(tfiles, plist, args)

        if args.xmgrace:
            grfile = plot_xmgrace(courses, plist, args)
            print("# Your results have been plotted in the file: {}".format(grfile))

        if args.pyplot:
            plotfile = plot_matplotlib(name, seq, courses, plist, args)
            print("# Your results have been plotted in the file: {}".format(plotfile))

    print("# Thank you for using BarMap b(^.^)d")
示例#6
0
def main(args):
    """ BarMap-v2.0 -- cotransriptional folding
      Dependencies: RNAsubopt, barriers, treekin

      The implementation is split into 4 steps ...
    """
    # Read Input & Update Arguments
    name, seq = ril.parse_vienna_stdin(sys.stdin)

    # One name, just to be clear ...
    (args.name, name) = (args.name, args.name) if args.name else (name, name)

    if args.stop is None:
        args.stop = len(seq)
    else:
        seq = seq[:args.stop]

    print("# Input: {:s} {:s}".format(name, seq))

    if args.pourRNA:
        args.s_ener = args.max_energy
    else:
        if args.s_ener is None:
            args.s_ener, args.s_maxn = ril.sys_subopt_range(seq,
                    nos=args.s_maxn, maxe=args.s_maxe, verb=(args.verbose > 0))
            print("# Energyrange {:.2f} computes {:d} sequences".format(
                args.s_ener, args.s_maxn))
        elif args.verbose:
            args.s_ener, args.s_maxn = ril.sys_subopt_range(seq,
                                                            nos=0, maxe=args.s_ener, verb=False)
            print("# Energyrange {:.2f} computes {:d} sequences".format(
                args.s_ener, args.s_maxn))

    if not args.tmpdir:
        args.tmpdir = 'BarMap_' + args.name

    if not os.path.exists(args.tmpdir):
        os.makedirs(args.tmpdir)

    """# Starting with BarMap computations ... """

    while True:
        bfiles = None
        plist = None

        sname = "{}/{}-ener_{:.2f}".format(args.tmpdir, args.name, args.s_ener)
        bname = "{}-minh_{}-maxn_{}-k0_{}".format(sname, args.b_minh, args.b_maxn, args.k0)
        if args.pourRNA:
            print("""# computing pourRNA... """)
            bfiles = barmap_pourRNA(bname, seq, args)
    
            print("""# writing/parsing mapping information ... """)
            plist = barmap_mapping_pourRNA(bname, seq, args)
        else:
            #if args.circ: myfile += '_circ'
            if args.noLP:
                sname += '_noLP'
            print("""# writing RNAsubopt files ... """)
            sfiles = barmap_subopts(sname, seq, args)
    
            print("""# writing barriers files ... """)
            bfiles = barmap_barriers(bname, seq, sfiles, args)
    
            print("""# writing/parsing mapping information ... """)
            plist = barmap_mapping(bname, seq, args)

        print("""# simulations using treekin ... """)
        try:
            tfiles = barmap_treekin(bname, seq, bfiles, plist, args)
            break
        except LostPopulationError as e:
            if args.adaptive:
                args.s_ener += 2
                print('repeating caluclations with higher energy:', args.s_ener)
            else:
                print('caluclations failed with current suboptimal energy range:', args.s_ener)
                exit()
        except SubprocessError as e:
            if args.adaptive:
                args.s_ener += 2
                print('repeating caluclations with higher energy:', args.s_ener)
            else:
                print('caluclations failed with current suboptimal energy range:', args.s_ener)
                exit()

    if args.xmgrace or args.pyplot:
        print("""# Processing treekin results for plotting ... """)
        courses = get_plot_data(tfiles, plist, args)

        if args.xmgrace:
            grfile = plot_xmgrace(courses, plist, args)
            print("# Your results have been plotted in the file: {}".format(grfile))

        if args.pyplot:
            plotfile = plot_matplotlib(name, seq, courses, plist, args)
            print("# Your results have been plotted in the file: {}".format(plotfile))

    print("# Thank you for using BarMap b(^.^)d")