Calculating distance matrix of RNA-seq data
0
0
Entering edit mode
5.2 years ago
fi1d18 ★ 4.2k

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

MAST2     WWC2  PHYHIPL   R3HDM2

dim(control)
   26 2603

   26 2603
library(dtw)

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


Dynamic-Time-Warping R time-series • 2.3k views
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,.

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) {
+     alignment <- dtw(control[i],control[j])
+     distance[i, j] <- alignmentdistance + } + } Error in distance[i, j] <- alignmentdistance :
> 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 }}
> 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)
+   return(dtw(a,b,distance.only=TRUE)$normalizedDistance) + } > View(dtwOmitNA) > pr_DB$set_entry(FUN = dtwOmitNA, names = c("dtwOmitNA"))
> d<-dist(dataset, method = "dtwOmitNA")

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.

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)

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.