-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.R
74 lines (60 loc) · 2.53 KB
/
test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
library(tidyverse)
library(abf2load)
library(vcfunc)
index <- read_csv("vcfunc example/sample data file index.csv")
N = c(1:20)
selected <- select.samples(dataindex = index,
oocyteNo = N,
gene = "A2",
buffer = "50N")
nselected <- nrow(selected)
#We keep abf_raw as a backup so we can easily restore
abf_raw <- abf2.load_in_folder(folder = "vcfunc example/sample data/",
filename_list = unlist(selected[, "FileName"]))
abf_list <- abf_raw
abf_title <- unlist(selected[, "FileName"])
#Plot all loaded abf files
#Could be slow depending on how large the list is, note that title_list is optional
PlotAll_IVChannel(abf_list, title_list = abf_title)
#Alternatively, plot individual channel side by side
PlotAll_Channel(abf_list, 1)
PlotAll_Channel(abf_list, 2)
#Remove unwanted episodes
abf_list[[2]] <- AbfRemoveEpisode(abf_list[[2]], 11)
#Restore to original state
abf_list[[2]] <- abf_raw[[2]]
#Find sampling intervals, one-step
intv_list <- FindAllSamplingInterval(abf_list)
#Check the result
PlotAll_IVChannelWithIntv(abf_list, intv_list, title_list = abf_title)
#Alternatively, plot individual channel side by side
PlotAll_ChannelWithIntv(abf_list, intv_list, 1)
PlotAll_ChannelWithIntv(abf_list, intv_list, 2)
#You can also do this for individual abf data
intv1 <- FindSamplingInterval(abf_list[[1]])
#Sampling interval is fixed size, however, you can dynamically (and automatically) expand
#by simply give a maximum interval expansion rate
intv2 <- FindSamplingInterval(abf_list[[1]], max_interval_expansion_rate = 12)
#compare the results
Plot_IVChannelWithIntv(abf_list[[1]], intv1)
Plot_IVChannelWithIntv(abf_list[[1]], intv2)
#There is a small change to intervals, now they're stored in a list for clearer manipulation
#Manually change interval for 2nd abf
sample_id <- 2
intv_start <- 6200
intv_length <- 150
#You can call a function to do this
intv_list <- ChangeInterval(intv_list, sample_id, intv_start, intv_length)
#Or do it manually
intv_list[[sample_id]][1] <- intv_start
intv_list[[sample_id]][2] <- intv_start + intv_length -1
#Processing data
#Get a data.frame of mean current
df_mean_current <- AllSamples_CurrentMeans(abf_list, intv_list)
#Get a data.frame of mean voltage
df_mean_voltage <- AllSamples_VoltageMeans(abf_list, intv_list)
#Or preferably, just get a summary one-step
df_summary <- AllSamples_IVSummary(abf_list, intv_list)
View(df_summary)
#result quick peek
qplot(x = df_summary$Voltage, y = df_summary$Current) + geom_smooth()