Example #1
0
def plot_compare(args):

    cwd = os.getcwd()
    subdir = args.subdir
    os.chdir(subdir)

    FRETfile = args.trace
    FRETr = np.loadtxt(FRETfile)

    # Load full experimental transition matrix
    TMfile = args.TMfile
    T_matrix = np.loadtxt(TMfile)

    # Calculate and unflatten transition matrix
    tmatrix = tmcalc.get_T_matrix(FRETr,
                                  spacing=args.spacing,
                                  framestep=args.fstep)
    if tmcalc.check_matrix(tmatrix):
        tmatrix = tmcalc.unflatten_matrix(tmatrix)

    # Calculate experimental matrix
    bin_size = np.size(tmatrix)**0.5
    spacing = 0.1
    lower_ran = spacing * (np.floor(10 * np.min(FRETr)))
    upper_ran = spacing * (np.ceil(10 * np.max(FRETr)))
    ran_size = (lower_ran, upper_ran)
    tmatrix_exp = xtm.tmatrix_exp_calc(T_matrix, bin_size, ran_size, spacing)
    if tmcalc.check_matrix(tmatrix_exp):
        tmatrix_exp = tmcalc.unflatten_matrix(tmatrix_exp)

    # Difference matrix
    diff_matrix = tmatrix - tmatrix_exp
    diff_squared = np.mean(np.abs(diff_matrix))
    print "Average absolute difference is: "
    print diff_squared

    # Generate plots
    if "color" in args.plot_type:
        ptm.plot_matrix(tmatrix, "Simulated Transition Matrix", 0, 0.5)
        ptm.plot_matrix(tmatrix_exp, "Experimental Transition Matrix", 0, 0.5)
        ptm.plot_matrix(diff_matrix,
                        "Transition Probability Differences",
                        -0.5,
                        0.5,
                        diff=True)
    if "spy" in args.plot_type:
        ptm.spy_matrix(tmatrix, "Non-zero entries, simulated")
        ptm.spy_matrix(tmatrix_exp, "Non-zero entries, experimental")
        ptm.spy_matrix(diff_matrix, "Non-zero entries, difference")
Example #2
0
def plot_single_matrix(args):

    cwd = os.getcwd()
    subdir = args.subdir

    os.chdir(subdir)

    FRETfile = args.trace
    FRETr = np.loadtxt(FRETfile)

    # Calculate transition matrix
    tmatrix = tmcalc.get_T_matrix(FRETr,
                                  spacing=args.spacing,
                                  framestep=args.fstep)

    # Unflatten matrix if necessary
    if tmcalc.check_matrix(tmatrix):
        tmatrix = tmcalc.unflatten_matrix(tmatrix)

    # Plot matrix
    if "color" in args.plot_type:
        diff = False
        ptm.plot_matrix(tmatrix, "Transition Matrix", 0, 0.5, diff)
    if "spy" in args.plot_type:
        ptm.spy_matrix(tmatrix, "Non-Zero Transitions")
def plot_compare(args):
    
    cwd = os.getcwd()
    subdir = args.subdir
    os.chdir(subdir)
    
    FRETfile = args.trace
    FRETr = np.loadtxt(FRETfile)
    
    # Load full experimental transition matrix
    TMfile = args.TMfile
    T_matrix = np.loadtxt(TMfile)
    
    # Calculate and unflatten transition matrix
    tmatrix = tmcalc.get_T_matrix(FRETr, spacing=args.spacing, framestep=args.fstep)
    if tmcalc.check_matrix(tmatrix):
        tmatrix = tmcalc.unflatten_matrix(tmatrix)
    
    # Calculate experimental matrix
    bin_size = np.size(tmatrix)**0.5
    spacing=0.1
    lower_ran = spacing*(np.floor(10*np.min(FRETr)))
    upper_ran = spacing*(np.ceil(10*np.max(FRETr)))
    ran_size = (lower_ran, upper_ran)
    tmatrix_exp = xtm.tmatrix_exp_calc(T_matrix, bin_size, ran_size, spacing)
    if tmcalc.check_matrix(tmatrix_exp):
        tmatrix_exp = tmcalc.unflatten_matrix(tmatrix_exp)
    
    # Difference matrix
    diff_matrix = tmatrix - tmatrix_exp
    diff_squared = np.mean(np.abs(diff_matrix))
    print "Average absolute difference is: "
    print diff_squared
    
    # Generate plots
    if "color" in args.plot_type:
        ptm.plot_matrix(tmatrix, "Simulated Transition Matrix", 0, 0.5)
        ptm.plot_matrix(tmatrix_exp, "Experimental Transition Matrix", 0, 0.5)
        ptm.plot_matrix(diff_matrix, "Transition Probability Differences", -0.5, 0.5, diff=True)
    if "spy" in args.plot_type:
        ptm.spy_matrix(tmatrix, "Non-zero entries, simulated")
        ptm.spy_matrix(tmatrix_exp, "Non-zero entries, experimental")
        ptm.spy_matrix(diff_matrix, "Non-zero entries, difference")
Example #4
0
def plot_double(args):
    # Plot two matrices along with a difference matrix

    if args.iter != None:
        import os
        subdir = args.subdir
        iter = args.iter
        file_location = "%s/iteration_%d" % (subdir, iter)
        os.chdir(file_location)
        print os.getcwd()

    ##ASSUMES SIMULATED MATRIX FED FIRST
    (sim_file, exp_file) = args.tmatrix

    sim_matrix = np.loadtxt(sim_file)
    exp_matrix = np.loadtxt(exp_file)

    if check_matrix(sim_matrix):
        sim_matrix = unflatten_matrix(sim_matrix)
    if check_matrix(exp_matrix):
        exp_matrix = unflatten_matrix(exp_matrix)

    # Subtract matrices to determine difference matrix
    diff_matrix = sim_matrix - exp_matrix

    ##PRINT AVERAGE ABSOLUTE DIFFERENCE
    print "Average absolute difference is: "
    print np.mean(np.abs(diff_matrix))

    if "color" in args.plot_type:
        plot_matrix(sim_matrix, "Simulated Transition Matrix", 0, 0.5)
        plot_matrix(exp_matrix, "Experimental Transition Matrix", 0, 0.5)
        plot_matrix(diff_matrix,
                    "Transition Probability Differences",
                    -0.5,
                    0.5,
                    diff=True)
    if "spy" in args.plot_type:
        spy_matrix(sim_matrix, "Non-zero entries, simulated")
        spy_matrix(exp_matrix, "Non-zero entries, experimental")
        spy_matrix(diff_matrix, "Non-zero entries, difference")

    return
Example #5
0
def plot_double(args):
    # Plot two matrices along with a difference matrix

    if args.iter != None:
        import os

        subdir = args.subdir
        iter = args.iter
        file_location = "%s/iteration_%d" % (subdir, iter)
        os.chdir(file_location)
        print os.getcwd()

    ##ASSUMES SIMULATED MATRIX FED FIRST
    (sim_file, exp_file) = args.tmatrix

    sim_matrix = np.loadtxt(sim_file)
    exp_matrix = np.loadtxt(exp_file)

    if check_matrix(sim_matrix):
        sim_matrix = unflatten_matrix(sim_matrix)
    if check_matrix(exp_matrix):
        exp_matrix = unflatten_matrix(exp_matrix)

    # Subtract matrices to determine difference matrix
    diff_matrix = sim_matrix - exp_matrix

    ##PRINT AVERAGE ABSOLUTE DIFFERENCE
    print "Average absolute difference is: "
    print np.mean(np.abs(diff_matrix))

    if "color" in args.plot_type:
        plot_matrix(sim_matrix, "Simulated Transition Matrix", 0, 0.5)
        plot_matrix(exp_matrix, "Experimental Transition Matrix", 0, 0.5)
        plot_matrix(diff_matrix, "Transition Probability Differences", -0.5, 0.5, diff=True)
    if "spy" in args.plot_type:
        spy_matrix(sim_matrix, "Non-zero entries, simulated")
        spy_matrix(exp_matrix, "Non-zero entries, experimental")
        spy_matrix(diff_matrix, "Non-zero entries, difference")

    return
def plot_all(args):
    
    cwd = os.getcwd()
    subdir = args.subdir
    os.chdir("%s/%s"%(cwd, subdir))
    
    if args.compare:
        T_matrix_1 = np.loadtxt(args.files[0])
        if check_matrix(T_matrix_1):
            T_matrix_1 = unflatten_matrix(T_matrix_1)
        bins_1, avg_j_1 = find_avg_transition(T_matrix_1)
        
        T_matrix_2 = np.loadtxt(args.files[1])
        if check_matrix(T_matrix_2):
            T_matrix_2 = unflatten_matrix(T_matrix_2)
        bins_2, avg_j_2 = find_avg_transition(T_matrix_2)
        labels = args.labels
        plot_compare(bins_1, avg_j_1, bins_2, avg_j_2, labels)
    else:
        T_matrix = np.loadtxt(args.files[0])
        if check_matrix(T_matrix):
            T_matrix = unflatten_matrix(T_matrix)        
        bins, avg_j = find_avg_transition(T_matrix)
        plot_single_vec(bins, avg_j)
Example #7
0
def plot_difference_matrix(args):

    subdir = args.subdir

    cwd = os.getcwd()

    os.chdir("%s/%s" % (cwd, subdir[0]))
    T_matrix_1 = np.loadtxt(args.files[0])
    if check_matrix(T_matrix_1):
        T_matrix_1 = unflatten_matrix(T_matrix_1)

    os.chdir(cwd)

    os.chdir("%s/%s" % (cwd, subdir[1]))
    T_matrix_2 = np.loadtxt(args.files[1])
    if check_matrix(T_matrix_2):
        T_matrix_2 = unflatten_matrix(T_matrix_2)

    os.chdir(cwd)

    c_direc = "%s/tmatrix_compare" % (cwd)

    if not os.path.isdir(c_direc):
        os.mkdir(c_direc)

    os.chdir(c_direc)

    diff_matrix = T_matrix_1 - T_matrix_2

    if args.iter != None:
        iter = args.iter
        title = "Transition Differences Iter %d and %d" % (iter[0], iter[1])
    else:
        title = "Transition Differences"

    ptm.plot_matrix(diff_matrix, title, -0.5, 0.5, diff=True)
def plot_difference_matrix(args):

    subdir = args.subdir

    cwd = os.getcwd()

    os.chdir("%s/%s"%(cwd,subdir[0]))
    T_matrix_1 = np.loadtxt(args.files[0])
    if check_matrix(T_matrix_1):
        T_matrix_1 = unflatten_matrix(T_matrix_1)

    os.chdir(cwd)

    os.chdir("%s/%s"%(cwd,subdir[1]))
    T_matrix_2 = np.loadtxt(args.files[1])
    if check_matrix(T_matrix_2):
        T_matrix_2 = unflatten_matrix(T_matrix_2)

    os.chdir(cwd)

    c_direc = "%s/tmatrix_compare"%(cwd)
    
    if not os.path.isdir(c_direc):
        os.mkdir(c_direc)
    
    os.chdir(c_direc)
    
    diff_matrix = T_matrix_1 - T_matrix_2
    
    if args.iter != None:
        iter = args.iter
        title = "Transition Differences Iter %d and %d"%(iter[0], iter[1])
    else:
        title = "Transition Differences"
    
    ptm.plot_matrix(diff_matrix, title, -0.5, 0.5, diff=True)
Example #9
0
def plot_single(args):
    # Plot a single matrix

    matrix_file = args.tmatrix

    T_matrix = np.loadtxt(matrix_file)

    if check_matrix(T_matrix):
        T_matrix = unflatten_matrix(T_matrix)

    if "color" in args.plot_type:
        plot_matrix(T_matrix, "Transition Matrix", 0, 0.5)
    if "spy" in args.plot_type:
        spy_matrix(T_matrix, "Non-Zero Transitions")

    return
Example #10
0
def plot_single(args):
    # Plot a single matrix

    matrix_file = args.tmatrix

    T_matrix = np.loadtxt(matrix_file)

    if check_matrix(T_matrix):
        T_matrix = unflatten_matrix(T_matrix)

    if "color" in args.plot_type:
        plot_matrix(T_matrix, "Transition Matrix", 0, 0.5)
    if "spy" in args.plot_type:
        spy_matrix(T_matrix, "Non-Zero Transitions")

    return
Example #11
0
def plot_single_matrix(args):
    
    cwd = os.getcwd()
    subdir = args.subdir

    os.chdir(subdir)
    
    FRETfile = args.trace
    FRETr = np.loadtxt(FRETfile)
    
    # Calculate transition matrix
    tmatrix = tmcalc.get_T_matrix(FRETr, spacing=args.spacing, framestep=args.fstep)
    
    # Unflatten matrix if necessary
    if tmcalc.check_matrix(tmatrix):
        tmatrix = tmcalc.unflatten_matrix(tmatrix)

    # Plot matrix
    if "color" in args.plot_type:
        diff = False
        ptm.plot_matrix(tmatrix, "Transition Matrix", 0, 0.5, diff)
    if "spy" in args.plot_type:
        ptm.spy_matrix(tmatrix, "Non-Zero Transitions")