''' This program is meant to take the Trace files outputted from ebFRET and determine the FRET efficiency (Viterbi_Mean) of each state in a given HMM before the state transitions to another state. The program also determines how long each FRET state lasts for, so you can correlate FRET efficiency with the lifetime of the state. ''' ################################################################### # 2 state HMM ################################################################### library(tidyverse) #Define global variables path_var <- r"(F:\Backup Plus (Backup)\Analysis\ebFRET_Analysis_5.7.2022\NearCognate_CoInjection_25nMTC_VariableeEF2\Subsequent Sampling Events\ebFRET\Trace Files)" file_name <- "2stateHMM_NearCognate_25nMTC_2.5uMeEF2_T1_to_T2_CKH_Filtered_Traces.dat" setwd(path_var) time_interval <- 0.04 #Time interval in seconds #Load in the Full Report Trace outputs from ebFRET file_location <- paste(path_var, file_name, sep = "\\") TypeAll_traces_2states_ebFRET <- read.table(file_location, quote="\"", comment.char="") #Name the columns for each dataframe colnames(TypeAll_traces_2states_ebFRET) <- c("Trace", "Donor", "Acceptor", "FRET", "Viterbi_State", "Viterbi_Mean") #Subset the dataframe to include only Viterbi_State and Viterbi_Mean columns test <- TypeAll_traces_2states_ebFRET[, 4:5] #Get FRET Efficiencies for each state State1_FRET <- test %>% filter(Viterbi_State == 1) State2_FRET <- test %>% filter(Viterbi_State == 2) #Remove values that are higher than 1 or less than 0 State1_FRET <- State1_FRET %>% filter(FRET >= 0) State1_FRET <- State1_FRET %>% filter(FRET <= 1) State2_FRET <- State2_FRET %>% filter(FRET >= 0) State2_FRET <- State2_FRET %>% filter(FRET <= 1) hist(State1_FRET$FRET, breaks = 30, xlim=c(0,1)) #Baseline FRET (background) hist(State2_FRET$FRET, breaks = 30, xlim=c(0,1)) #FRET for each sampling event write.table(State2_FRET, "test3.txt", row.names = FALSE, col.names = FALSE)