-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.R
172 lines (132 loc) · 5.92 KB
/
demo.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#In this R script we will generate some demo data using the Sinus function and then we will
#the functions in the function.R script to do multiple dtw alignment, local alignment and
#circular alignment
#We will generate a sinus sequence of 1.3 frequencies length and subset portions of the sequence
#of different length that have some overlap between them
#representation of the data
y <- round(sin(seq(from = 0, to = 2.5*pi, length.out = 420)), digits = 5)
t <- c(1:420)
plot(t, y)
#subset of the data
#we will make 10 subsets of the data that span the whole length and have different lengths in
#the overlap between them
fractionsList <- list(s1 = c(1:120),
s2 = c(80:140),
s3 = c(110:210),
s4 = c(160:250),
s5 = c(230:320),
s6 = c(290:420),
s7 = c(270:390),
s8 = c(310:400),
s9 = c(300:420),
s10 = c(300:420))
#create dataframes of the portions and put them in a list
dataList <- lapply(X = fractionsList, function(x){
return(data.frame(t = c(1:length(x)), y = y[x]))
})
#test some univariate alignments
#LEFT ---------
profile <- pairwiseUnivariateAlignment(df1 = dataList[[1]],
df2 = dataList[[2]],
dataColumns = c(2, 2),
showDistPlot = F)
#visual representation of the alignment
require(ggplot2)
require(gridExtra)
pp <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[4])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Unified sequences')
p1 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[3])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Sequence1')
p2 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[2])) +
geom_point() +
coord_cartesian(ylim = c(-1,1))+
ggtitle('Sequence2')
plotList <- list(pp, p2, p1)
gridplot <- grid.arrange(grobs = plotList, ncol = 1, as.table = FALSE)
#RIGHT ---------
profile <- pairwiseUnivariateAlignment(df1 = dataList[[3]],
df2 = dataList[[2]],
dataColumns = c(2, 2),
showDistPlot = T)
#visual representation of the alignment
require(ggplot2)
require(gridExtra)
pp <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[4])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Unified sequences')
p1 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[3])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Sequence1')
p2 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[2])) +
geom_point() +
coord_cartesian(ylim = c(-1,1))+
ggtitle('Sequence2')
plotList <- list(pp, p2, p1)
gridplot <- grid.arrange(grobs = plotList, ncol = 1, as.table = FALSE)
#LOCAL ---------
profile <- pairwiseUnivariateAlignment(df1 = dataList[[7]],
df2 = dataList[[8]],
dataColumns = c(2, 2),
showDistPlot = T)
#visual representation of the alignment
require(ggplot2)
require(gridExtra)
pp <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[4])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Unified sequences')
p1 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[3])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Sequence1')
p2 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[2])) +
geom_point() +
coord_cartesian(ylim = c(-1,1))+
ggtitle('Sequence2')
plotList <- list(pp, p2, p1)
gridplot <- grid.arrange(grobs = plotList, ncol = 1, as.table = FALSE)
#GLOBAL ---------
profile <- pairwiseUnivariateAlignment(df1 = dataList[[9]],
df2 = dataList[[10]],
dataColumns = c(2, 2),
showDistPlot = T)
#visual representation of the alignment
require(ggplot2)
require(gridExtra)
pp <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[4])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Unified sequences')
p1 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[3])) +
geom_point() +
coord_cartesian(ylim = c(-1,1)) +
ggtitle('Sequence1')
p2 <- ggplot(data = profile, aes_string(x = names(profile)[1], y = names(profile)[2])) +
geom_point() +
coord_cartesian(ylim = c(-1,1))+
ggtitle('Sequence2')
plotList <- list(pp, p2, p1)
gridplot <- grid.arrange(grobs = plotList, ncol = 1, as.table = FALSE)
plot(gridplot)
#next we will make a profile from doing a progressive pair-wise alignment of all the portions
profileDf <- multiUnivariateAlignmentProfile(dfList = dataList, dataColumns = c(2,2), showDendrogram = F, showAlignmentPlot = T)
ggplot(data = profileDf, aes(x = time, y = uni)) +
geom_point() +
coord_cartesian(ylim = c(-1,1))
#circularization of the profile ------------------------
#since we know that our data is a loop over time. We will use the next function to reduce it to a single frequency
circularDf <- circularizeUnivariateSequence(sequenceDf = profileDf, dataColumn = 4)
ggplot(data = circularDf, aes(x = time, y = uni)) +
geom_point() +
coord_cartesian(ylim = c(-1,1))
#rotate the circularized sequence so that it starts at 0
circularDf <- rotateSequence(circularDf = circularDf, newstart = 29)
ggplot(data = circularDf, aes(x = time, y = uni)) +
geom_point() +
coord_cartesian(ylim = c(-1,1))