ribolands/syswraps.py
def sys_treekin_051(basename, ratefile,
                    treekin = 'treekin',
                    bofile = None,
                    p0 = ['1=0.5', '2=0.5'],
                    t0 = 0,
                    ti = 1.2,
                    t8 = 1e6,
                    binrates = True,
                    useplusI = False,
                    exponent = False,
                    mpack_method = None,
                    quiet = True,
                    force = False):
    """ Perform a system-call of the program ``treekin``.

    Prints the results into files and returns the respective filenames. This
    wrapper will produce two files, one from ``STDIN`` and ``STDERR`` output.

    Args:
        basename (str): Basename of output files.
        ratefile (str): Input rate matrix. 
            Fileformat as produced by ``barriers``.
        treekin (str, optional): Path to executable. Defaults to treekin.
        bofile (str, optional): Optional barriers file. Defaults to None.
        p0 ([str,...], optional): A list to specify an initial occupancy vector. 
            Defaults to: ['1=0.5', '2=0.5']
        t0 (float, optional): Start time of simulation.
        ti (float, optional): Time increment of the treekin solver.
        t8 (float, optional): Stop time for the solver.
        binrates (bool, optional): Ratefile is in binary format. 
            Defaults to True.
        useplusI (bool, optional): Use treekin method --useplusI. 
            Defaults to False.
        exponent (bool, optional): Use treekin method --exponent. 
            Defaults to False.
        mpack_method (str, optional): Set treekin parameter --mpack-method. 
            Defaults to None.
        force (bool, optional): Overwrite existing files. Defaults to False.

    Raises:
        ExecError: Program does not exist.
        SuboprocessError: Program terminated with exit code: ...

    Returns:
        [str, str]: The name of the file containing STDOUT and STDERR of
            ``treekin`` call.  
    """

    if which(treekin) is None:
        raise ExecError(treekin,
                        "treekin", 'http://www.tbi.univie.ac.at/RNA/Treekin')

    tofile = basename + '_treekin.nxy'
    tefile = basename + '_treekin.err'

    if not force and os.path.exists(tofile):
        rlog.info(f"# {tofile} <= Files exist")
        return tofile, tefile

    # Unfortunately, running treekin with a single state leads to an error that
    # is printed to STDOUT instead of STDERR. The program, exits with success.
    # That's why we catch it first:
    if binrates:
        with open(ratefile, 'rb') as rf:
            i, = unpack('i', rf.read(calcsize('i')))  # unsigned long, little-endian
        i -= 1
    else:
        with open(ratefile) as rf:
            for i, _ in enumerate(rf):
                pass
    if i == 0:
        raise SubprocessError(None, 'No transition rates found.')

    syscall = [treekin, '--method', 'I']
    if quiet:
        syscall.extend(['--quiet'])
    if useplusI:
        syscall.extend(['--useplusI'])
    if mpack_method:
        syscall.extend(['--mpack-method=' + mpack_method])
    syscall.extend(['--tinc', str(ti)])
    syscall.extend(['--t0', str(t0)])
    syscall.extend(('--t8', str(t8)))
    for p in p0:
        syscall.extend(('--p0', p))
    if bofile:
        syscall.extend(('--bar', bofile))
    if binrates:
        syscall.extend(['--bin'])
    if exponent:
        syscall.extend(['--exponent'])

    call = "cat {} | {} 2> {} > {}".format(ratefile, ' '.join(syscall), tefile, tofile)

    rlog.info(f'{call}')
    # Do the simulation (catch treekin errors)
    with open(ratefile, 'r') as rts, \
            open(tofile, 'w') as tkn, \
            open(tefile, 'w') as err:
        proc = sub.Popen(syscall, stdin = rts, stdout = tkn, stderr = err)
        proc.communicate(None)
        if proc.returncode:
            raise SubprocessError(proc.returncode, call)

    return tofile, tefile
 Perform a system-call of the program ``treekin``.

    Prints the results into files and returns the respective filenames. This
    wrapper will produce two files, one from ``STDIN`` and ``STDERR`` output.

    Args:
        basename (str): Basename of output files.
        ratefile (str): Input rate matrix. 
            Fileformat as produced by ``barriers``.
        treekin (str, optional): Path to executable. Defaults to treekin.
        bofile (str, optional): Optional barriers file. Defaults to None.
        p0 ([str,...], optional): A list to specify an initial occupancy vector. 
            Defaults to: ['1=0.5', '2=0.5']
        t0 (float, optional): Start time of simulation.
        ti (float, optional): Time increment of the treekin solver.
        t8 (float, optional): Stop time for the solver.
        binrates (bool, optional): Ratefile is in binary format. 
            Defaults to True.
        useplusI (bool, optional): Use treekin method --useplusI. 
            Defaults to False.
        exponent (bool, optional): Use treekin method --exponent. 
            Defaults to False.
        mpack_method (str, optional): Set treekin parameter --mpack-method. 
            Defaults to None.
        force (bool, optional): Overwrite existing files. Defaults to False.

    Raises:
        ExecError: Program does not exist.
        SuboprocessError: Program terminated with exit code: ...

    Returns:
        [str, str]: The name of the file containing STDOUT and STDERR of
            ``treekin`` call.  
    
Perform a system-call of the program ``treekin``.
Prints the results into files and returns the respective filenames.
Perform a system - call of the program ` ` treekin ` ` . Prints the results into files and returns the respective filenames .
def sys_treekin_051(basename, ratefile,
                    treekin = 'treekin',
                    bofile = None,
                    p0 = ['1=0.5', '2=0.5'],
                    t0 = 0,
                    ti = 1.2,
                    t8 = 1e6,
                    binrates = True,
                    useplusI = False,
                    exponent = False,
                    mpack_method = None,
                    quiet = True,
                    force = False):
    if which(treekin) is None:
        raise ExecError(treekin,
                        "treekin", 'http://www.tbi.univie.ac.at/RNA/Treekin')
    tofile = basename + '_treekin.nxy'
    tefile = basename + '_treekin.err'
    if not force and os.path.exists(tofile):
        rlog.info(f"# {tofile} <= Files exist")
        return tofile, tefile
    if binrates:
        with open(ratefile, 'rb') as rf:
            i, = unpack('i', rf.read(calcsize('i')))  
        i -= 1
    else:
        with open(ratefile) as rf:
            for i, _ in enumerate(rf):
                pass
    if i == 0:
        raise SubprocessError(None, 'No transition rates found.')
    syscall = [treekin, '--method', 'I']
    if quiet:
        syscall.extend(['--quiet'])
    if useplusI:
        syscall.extend(['--useplusI'])
    if mpack_method:
        syscall.extend(['--mpack-method=' + mpack_method])
    syscall.extend(['--tinc', str(ti)])
    syscall.extend(['--t0', str(t0)])
    syscall.extend(('--t8', str(t8)))
    for p in p0:
        syscall.extend(('--p0', p))
    if bofile:
        syscall.extend(('--bar', bofile))
    if binrates:
        syscall.extend(['--bin'])
    if exponent:
        syscall.extend(['--exponent'])
    call = "cat {} | {} 2> {} > {}".format(ratefile, ' '.join(syscall), tefile, tofile)
    rlog.info(f'{call}')
    with open(ratefile, 'r') as rts, \
            open(tofile, 'w') as tkn, \
            open(tefile, 'w') as err:
        proc = sub.Popen(syscall, stdin = rts, stdout = tkn, stderr = err)
        proc.communicate(None)
        if proc.returncode:
            raise SubprocessError(proc.returncode, call)
    return tofile, tefile
def sys_treekin_051 ( basename , ratefile , treekin = 'treekin' , bofile = None , p0 = [ '1=0.5' , '2=0.5' ] , t0 = 0 , ti = 1.2 , t8 = 1e6 , binrates = True , useplusI = False , exponent = False , mpack_method = None , quiet = True , force = False ) : if which ( treekin ) is None : raise ExecError ( treekin , "treekin" , 'http://www.tbi.univie.ac.at/RNA/Treekin' ) tofile = basename + '_treekin.nxy' tefile = basename + '_treekin.err' if not force and os . path . exists ( tofile ) : rlog . info ( f"# {tofile} <= Files exist" ) return tofile , tefile if binrates : with open ( ratefile , 'rb' ) as rf : i , = unpack ( 'i' , rf . read ( calcsize ( 'i' ) ) ) i -= 1 else : with open ( ratefile ) as rf : for i , _ in enumerate ( rf ) : pass if i == 0 : raise SubprocessError ( None , 'No transition rates found.' ) syscall = [ treekin , '--method' , 'I' ] if quiet : syscall . extend ( [ '--quiet' ] ) if useplusI : syscall . extend ( [ '--useplusI' ] ) if mpack_method : syscall . extend ( [ '--mpack-method=' + mpack_method ] ) syscall . extend ( [ '--tinc' , str ( ti ) ] ) syscall . extend ( [ '--t0' , str ( t0 ) ] ) syscall . extend ( ( '--t8' , str ( t8 ) ) ) for p in p0 : syscall . extend ( ( '--p0' , p ) ) if bofile : syscall . extend ( ( '--bar' , bofile ) ) if binrates : syscall . extend ( [ '--bin' ] ) if exponent : syscall . extend ( [ '--exponent' ] ) call = "cat {} | {} 2> {} > {}" . format ( ratefile , ' ' . join ( syscall ) , tefile , tofile ) rlog . info ( f'{call}' ) with open ( ratefile , 'r' ) as rts , open ( tofile , 'w' ) as tkn , open ( tefile , 'w' ) as err : proc = sub . Popen ( syscall , stdin = rts , stdout = tkn , stderr = err ) proc . communicate ( None ) if proc . returncode : raise SubprocessError ( proc . returncode , call ) return tofile , tefile
Perform a system-call of the program ``treekin``.
Perform a system - call of the program ` ` treekin ` ` .
""" Perform a system-call of the program ``treekin``.

    Prints the results into files and returns the respective filenames. This
    wrapper will produce two files, one from ``STDIN`` and ``STDERR`` output.

    Args:
        basename (str): Basename of output files.
        ratefile (str): Input rate matrix. 
            Fileformat as produced by ``barriers``.
        treekin (str, optional): Path to executable. Defaults to treekin.
        bofile (str, optional): Optional barriers file. Defaults to None.
        p0 ([str,...], optional): A list to specify an initial occupancy vector. 
            Defaults to: ['1=0.5', '2=0.5']
        t0 (float, optional): Start time of simulation.
        ti (float, optional): Time increment of the treekin solver.
        t8 (float, optional): Stop time for the solver.
        binrates (bool, optional): Ratefile is in binary format. 
            Defaults to True.
        useplusI (bool, optional): Use treekin method --useplusI. 
            Defaults to False.
        exponent (bool, optional): Use treekin method --exponent. 
            Defaults to False.
        mpack_method (str, optional): Set treekin parameter --mpack-method. 
            Defaults to None.
        force (bool, optional): Overwrite existing files. Defaults to False.

    Raises:
        ExecError: Program does not exist.
        SuboprocessError: Program terminated with exit code: ...

    Returns:
        [str, str]: The name of the file containing STDOUT and STDERR of
            ``treekin`` call.  
    """ # Unfortunately, running treekin with a single state leads to an error that # is printed to STDOUT instead of STDERR. The program, exits with success. # That's why we catch it first: # unsigned long, little-endian # Do the simulation (catch treekin errors)
The name of the file containing STDOUT and STDERR of
``treekin`` call.
The name of the file containing STDOUT and STDERR of ` ` treekin ` ` call .
[str, str]
Program does not exist.
Program does not exist .
ExecError
Program terminated with exit code.
Program terminated with exit code .
SuboprocessError
basename
Basename of output files.
Basename of output files .
ratefile
Input rate matrix.
Fileformat as produced by ``barriers``.
Input rate matrix . Fileformat as produced by ` ` barriers ` ` .
treekin
Path to executable. Defaults to treekin.
Path to executable . Defaults to treekin .
treekin
bofile
Optional barriers file. Defaults to None.
Optional barriers file . Defaults to None .
None
p0
A list to specify an initial occupancy vector.
A list to specify an initial occupancy vector .
t0
Start time of simulation.
Start time of simulation .
ti
Time increment of the treekin solver.
Time increment of the treekin solver .
t8
Stop time for the solver.
Stop time for the solver .
binrates
Ratefile is in binary format.
Defaults to True.
Ratefile is in binary format . Defaults to True .
useplusI
Use treekin method --useplusI.
Defaults to False.
Use treekin method -- useplusI . Defaults to False .
exponent
Use treekin method --exponent.
Defaults to False.
Use treekin method -- exponent . Defaults to False .
mpack_method
Set treekin parameter --mpack-method.
Defaults to None.
Set treekin parameter -- mpack - method . Defaults to None .
quiet
force
Overwrite existing files. Defaults to False.
Overwrite existing files . Defaults to False .
False