Calculating distance matrix of RNA-seq data
0
0
Entering edit mode
6.1 years ago
zizigolu ★ 4.3k

Hi,

I have two matrices of normalized read counts for control and treatment in a time series day1 to day26. I want to calculate distance matrix by Dynamic Time Wrapping but seems too complicated. I did so; who can help for more clarification please? Thanks a lot

head(control[,1:4])
               MAST2     WWC2  PHYHIPL   R3HDM2
Control_D1  6.591024 5.695156 3.388652 5.756384
Control_D10 8.043454 5.365221 6.859768 6.936970
Control_D11 7.731590 4.868267 6.919972 6.931073
Control_D12 8.129948 5.105528 6.627016 7.090268
Control_D13 7.690863 4.729501 6.824746 6.904610
Control_D14 8.101723 5.334501 6.868990 7.115883

head(lead[,1:4])
              MAST2     WWC2  PHYHIPL   R3HDM2
Lead30_D1  6.418423 5.610699 3.734425 5.778046
Lead30_D10 7.918360 4.295191 6.559294 6.780952
Lead30_D11 7.807142 4.294722 6.599187 6.716040
Lead30_D12 7.856720 4.432136 6.572337 6.848483
Lead30_D13 7.827311 4.204738 6.607107 6.784094
Lead30_D14 7.848760 4.458451 6.581216 6.943003

dim(control)
[1]   26 2603

dim(lead)
[1]   26 2603
library(dtw)

Control=dist(control,method="DTW");

Lead=dist(lead,method="DTW");
Dynamic-Time-Warping R time-series • 2.7k views
ADD COMMENT
0
Entering edit mode

Question is unclear. What package are we using, method="DTW" ? Also, maybe irrelevant, the row ordering is 1, 10, 11, not 1,2,3,.

ADD REPLY
0
Entering edit mode

Thank you,

library(dtw)

I want to calculate distance matrix of my time series, I can't figure out how do that

> for(i in control) {
+   for(j in lead) {
+     alignment <- dtw(control[i],control[j])
+     distance[i, j] <- alignment$distance
+   }
+ }
Error in distance[i, j] <- alignment$distance : 
  object 'distance' not found
> for (i in control) { 
+   for (j in lead) { 
+     result[i,j] <- dtw( dist(x[,,i],x[,,j]), distance.only=T )$normalizedDistance }}
Error in x[, , j] : incorrect number of dimensions
> for (i in 1:N) { 
+   for (j in 1:N) { 
+     result[i,j] <- dtw( dist(control[,,i],lead[,,j]), distance.only=T )$normalizedDistance }}
Error: object 'N' not found
> for (i in row.names(control)) { 
+   for (j in row.names(lead)) { 
+     result[i,j] <- dtw( dist(control[,,i],lead[,,j]), distance.only=T )$normalizedDistance }}
Error in lead[, , j] : incorrect number of dimensions
> for (i in row.names(control)) { 
+   for (j in row.names(lead)) { 
+     result[i,j] <- dtw( dist(x[,,i],x[,,j]), distance.only=T )$normalizedDistance }}
Error in x[, , j] : incorrect number of dimensions
> dtwOmitNA <-function (x,y)
+ {
+   a<-na.omit(control)
+   b<-na.omit(lead)
+   return(dtw(a,b,distance.only=TRUE)$normalizedDistance)
+ }
> View(dtwOmitNA)
> pr_DB$set_entry(FUN = dtwOmitNA, names = c("dtwOmitNA"))
> d<-dist(dataset, method = "dtwOmitNA") 
Error in is.data.frame(x) : object 'dataset' not found
ADD REPLY
1
Entering edit mode

You can't assign elements to a matrix that you haven't pre-allocated. You can't index with more dimensions than your array has, e.g. if it's a matrix, you can only have two indices. I think part of the problem is that you don't know how to program in R.
Also, read the dtw() doc to figure out what the arguments to the function should be.

And avoid duplicating your question, either keep the discussion in the previous thread or in the new question but not both.

ADD REPLY
0
Entering edit mode

The dist function doesn't have a dtw method! If you are trying to use the "Distance matrix computation" function from the stats package see here: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/dist.html

You probabely need something like this:

library(stats)
dist(your matrix, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)
ADD REPLY
0
Entering edit mode

The OP is trying to compute a dynamic time warping distance as offered in the dtw package. An "almost" answer can be found in my comments in the other post.

ADD REPLY

Login before adding your answer.

Traffic: 2646 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6