Ejemplo n.º 1
0
def run(lagtime,
        assignments,
        symmetrize='MLE',
        input_mapping="None",
        trim=True,
        out_dir="./Data/"):

    # set the filenames for output
    FnTProb = os.path.join(out_dir, "tProb.mtx")
    FnTCounts = os.path.join(out_dir, "tCounts.mtx")
    FnMap = os.path.join(out_dir, "Mapping.dat")
    FnAss = os.path.join(out_dir, "Assignments.Fixed.h5")
    FnPops = os.path.join(out_dir, "Populations.dat")

    # make sure none are taken
    outputlist = [FnTProb, FnTCounts, FnMap, FnAss, FnPops]
    arglib.die_if_path_exists(outputlist)

    # Check for valid lag time
    assert lagtime > 0, 'Please specify a positive lag time.'

    # if given, apply mapping to assignments
    if input_mapping != "None":
        MSMLib.apply_mapping_to_assignments(assignments, input_mapping)

    n_assigns_before_trim = len(np.where(assignments.flatten() != -1)[0])

    counts = MSMLib.get_count_matrix_from_assignments(assignments,
                                                      lag_time=lagtime,
                                                      sliding_window=True)

    rev_counts, t_matrix, populations, mapping = MSMLib.build_msm(
        counts, symmetrize=symmetrize, ergodic_trimming=trim)

    if trim:
        MSMLib.apply_mapping_to_assignments(assignments, mapping)
        n_assigns_after_trim = len(np.where(assignments.flatten() != -1)[0])
        # if had input mapping, then update it
        if input_mapping != "None":
            mapping = mapping[input_mapping]
        # Print a statement showing how much data was discarded in trimming
        percent = (1.0 - float(n_assigns_after_trim) /
                   float(n_assigns_before_trim)) * 100.0
        logger.warning("Ergodic trimming discarded: %f percent of your data",
                       percent)
    else:
        logger.warning("No ergodic trimming applied")

    # Save all output
    np.savetxt(FnPops, populations)
    np.savetxt(FnMap, mapping, "%d")
    scipy.io.mmwrite(str(FnTProb), t_matrix)
    scipy.io.mmwrite(str(FnTCounts), rev_counts)
    io.saveh(FnAss, assignments)

    for output in outputlist:
        logger.info("Wrote: %s", output)

    return
Ejemplo n.º 2
0
def entry_point():
    args = parser.parse_args()

    # load args
    try:
        assignments = io.loadh(args.assignments, 'arr_0')
    except KeyError:
        assignments = io.loadh(args.assignments, 'Data')

    tProb = scipy.io.mmread(args.tProb)

    # workaround for arglib funniness?
    if args.do_minimization in ["False", "0"]:
        args.do_minimization = False
    else:
        args.do_minimization = True

    if args.algorithm == 'PCCA':
        MacroAssignmentsFn = os.path.join(args.output_dir,
                                          "MacroAssignments.h5")
        MacroMapFn = os.path.join(args.output_dir, "MacroMapping.dat")
        arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn])

        MAP, assignments = run_pcca(args.num_macrostates, assignments, tProb)

        np.savetxt(MacroMapFn, MAP, "%d")
        io.saveh(MacroAssignmentsFn, assignments)
        logger.info("Saved output to: %s, %s", MacroAssignmentsFn, MacroMapFn)

    elif args.algorithm == 'PCCA+':
        MacroAssignmentsFn = os.path.join(args.output_dir,
                                          "MacroAssignments.h5")
        MacroMapFn = os.path.join(args.output_dir, "MacroMapping.dat")
        ChiFn = os.path.join(args.output_dir, 'Chi.dat')
        AFn = os.path.join(args.output_dir, 'A.dat')

        arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn, ChiFn, AFn])

        chi, A, MAP, assignments = run_pcca_plus(
            args.num_macrostates,
            assignments,
            tProb,
            args.flux_cutoff,
            objective_function=args.objective_function,
            do_minimization=args.do_minimization)

        np.savetxt(ChiFn, chi)
        np.savetxt(AFn, A)
        np.savetxt(MacroMapFn, MAP, "%d")
        io.saveh(MacroAssignmentsFn, assignments)
        logger.info('Saved output to: %s, %s, %s, %s', ChiFn, AFn, MacroMapFn,
                    MacroAssignmentsFn)
    else:
        raise Exception()
Ejemplo n.º 3
0
def entry_point():
    args = parser.parse_args()

    # load args
    try:
        assignments = io.loadh(args.assignments, 'arr_0')
    except KeyError:
        assignments = io.loadh(args.assignments, 'Data')

    tProb = scipy.io.mmread(args.tProb)

    # workaround for arglib funniness?
    if args.do_minimization in ["False", "0"]:
        args.do_minimization = False
    else:
        args.do_minimization = True

    if args.algorithm == 'PCCA':
        MacroAssignmentsFn = os.path.join(
            args.output_dir, "MacroAssignments.h5")
        MacroMapFn = os.path.join(args.output_dir, "MacroMapping.dat")
        arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn])

        MAP, assignments = run_pcca(args.num_macrostates, assignments, tProb)

        np.savetxt(MacroMapFn, MAP, "%d")
        io.saveh(MacroAssignmentsFn, assignments)
        logger.info("Saved output to: %s, %s", MacroAssignmentsFn, MacroMapFn)

    elif args.algorithm == 'PCCA+':
        MacroAssignmentsFn = os.path.join(
            args.output_dir, "MacroAssignments.h5")
        MacroMapFn = os.path.join(args.output_dir, "MacroMapping.dat")
        ChiFn = os.path.join(args.output_dir, 'Chi.dat')
        AFn = os.path.join(args.output_dir, 'A.dat')

        arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn, ChiFn, AFn])

        chi, A, MAP, assignments = run_pcca_plus(args.num_macrostates,
                                                 assignments, tProb, args.flux_cutoff, objective_function=args.objective_function,
                                                 do_minimization=args.do_minimization)

        np.savetxt(ChiFn, chi)
        np.savetxt(AFn, A)
        np.savetxt(MacroMapFn, MAP, "%d")
        io.saveh(MacroAssignmentsFn, assignments)
        logger.info('Saved output to: %s, %s, %s, %s',
                    ChiFn, AFn, MacroMapFn, MacroAssignmentsFn)
    else:
        raise Exception()
Ejemplo n.º 4
0
def run(lagtime, assignments, symmetrize='MLE', input_mapping="None", trim=True, out_dir="./Data/"):

    # set the filenames for output
    FnTProb = os.path.join(out_dir, "tProb.mtx")
    FnTCounts = os.path.join(out_dir, "tCounts.mtx")
    FnMap = os.path.join(out_dir, "Mapping.dat")
    FnAss = os.path.join(out_dir, "Assignments.Fixed.h5")
    FnPops = os.path.join(out_dir, "Populations.dat")

    # make sure none are taken
    outputlist = [FnTProb, FnTCounts, FnMap, FnAss, FnPops]
    arglib.die_if_path_exists(outputlist)

    # Check for valid lag time
    assert lagtime > 0, 'Please specify a positive lag time.'

    # if given, apply mapping to assignments
    if input_mapping != "None":
        MSMLib.apply_mapping_to_assignments(assignments, input_mapping)

    n_assigns_before_trim = len(np.where(assignments.flatten() != -1)[0])

    counts = MSMLib.get_count_matrix_from_assignments(assignments, lag_time=lagtime, sliding_window=True)

    rev_counts, t_matrix, populations, mapping = MSMLib.build_msm(counts, symmetrize=symmetrize, ergodic_trimming=trim)

    if trim:
        MSMLib.apply_mapping_to_assignments(assignments, mapping)
        n_assigns_after_trim = len(np.where(assignments.flatten() != -1)[0])
        # if had input mapping, then update it
        if input_mapping != "None":
            mapping = mapping[input_mapping]
        # Print a statement showing how much data was discarded in trimming
        percent = (1.0 - float(n_assigns_after_trim) / float(n_assigns_before_trim)) * 100.0
        logger.warning("Ergodic trimming discarded: %f percent of your data", percent)
    else:
        logger.warning("No ergodic trimming applied")

    # Save all output
    np.savetxt(FnPops, populations)
    np.savetxt(FnMap, mapping, "%d")
    scipy.io.mmwrite(str(FnTProb), t_matrix)
    scipy.io.mmwrite(str(FnTCounts), rev_counts)
    io.saveh(FnAss, assignments)

    for output in outputlist:
        logger.info("Wrote: %s", output)

    return
Ejemplo n.º 5
0
def entry_point():
    args = parser.parse_args()

    F = np.loadtxt(args.ending).astype(int)
    U = np.loadtxt(args.starting).astype(int)
    tprob = scipy.io.mmread(args.tprob)

    # deal with case where have single start or end state
    # TJL note: this should be taken care of in library now... keeping it just
    # in case
    if F.shape == ():
        tmp = np.zeros(1, dtype=int)
        tmp[0] = int(F)
        F = tmp.copy()
    if U.shape == ():
        tmp = np.zeros(1, dtype=int)
        tmp[0] = int(U)
        U = tmp.copy()

    arglib.die_if_path_exists(args.output)
    paths, bottlenecks, fluxes = run(tprob, U, F, args.number)

    io.saveh(args.output, Paths=paths, Bottlenecks=bottlenecks, fluxes=fluxes)
    logger.info('Saved output to %s', args.output)
Ejemplo n.º 6
0
def entry_point():
    args = parser.parse_args()

    F = np.loadtxt(args.ending).astype(int)
    U = np.loadtxt(args.starting).astype(int)
    tprob = scipy.io.mmread(args.tprob)

    # deal with case where have single start or end state
    # TJL note: this should be taken care of in library now... keeping it just
    # in case
    if F.shape == ():
        tmp = np.zeros(1, dtype=int)
        tmp[0] = int(F)
        F = tmp.copy()
    if U.shape == ():
        tmp = np.zeros(1, dtype=int)
        tmp[0] = int(U)
        U = tmp.copy()

    arglib.die_if_path_exists(args.output)
    paths, bottlenecks, fluxes = run(tprob, U, F, args.number)

    io.saveh(args.output, Paths=paths, Bottlenecks=bottlenecks, fluxes=fluxes)
    logger.info('Saved output to %s', args.output)
Ejemplo n.º 7
0
def main():
    wildtype_states_fn = join(root, "wildtype_msm/Data_RMSD2_5A/Gens.h5")
    wildtype_counts = scipy.io.mmread(join(root, "wildtype_msm", "Data_RMSD2_5A/500ps_MLE/tCounts.mtx")).todense()
    lag_time = 500 * units.picoseconds

    ms = OpenMMMutantSampler(
        wildtype_counts,
        wildtype_states_fn,
        wildtype_topology_fn,
        mutant_topology_fn,
        lag_time,
        simulation=setup_simulation(),
    )

    ms.step(500)

    io.saveh(
        "sampling.h5",
        base_counts=wildtype_counts,
        samples=ms.samples,
        observed_counts=ms.counts,
        scores=ms.scores,
        bayesmutant_code_version=np.array([bayesmutant.version.full_version]),
    )
Ejemplo n.º 8
0
    # workaround for arglib funniness?
    if args.do_minimization in ["False", "0"]:
        args.do_minimization = False
    else:
        args.do_minimization = True

    if args.algorithm == 'PCCA':
        MacroAssignmentsFn = os.path.join(
            args.output_dir, "MacroAssignments.h5")
        MacroMapFn = os.path.join(args.output_dir, "MacroMapping.dat")
        arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn])

        MAP, assignments = run_pcca(args.num_macrostates, assignments, tProb)

        np.savetxt(MacroMapFn, MAP, "%d")
        io.saveh(MacroAssignmentsFn, assignments)
        logger.info("Saved output to: %s, %s", MacroAssignmentsFn, MacroMapFn)

    elif args.algorithm == 'PCCA+':
        MacroAssignmentsFn = os.path.join(
            args.output_dir, "MacroAssignments.h5")
        MacroMapFn = os.path.join(args.output_dir, "MacroMapping.dat")
        ChiFn = os.path.join(args.output_dir, 'Chi.dat')
        AFn = os.path.join(args.output_dir, 'A.dat')

        arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn, ChiFn, AFn])

        chi, A, MAP, assignments = run_pcca_plus(args.num_macrostates,
                                                 assignments, tProb, args.flux_cutoff, objective_function=args.objective_function,
                                                 do_minimization=args.do_minimization)