# Get patient distances for the first 2 patients in the Miller 2015 dataset.
data("Miller2015")
data_mx = Miller2015[-c(1,grep("x - ", rownames(Miller2015))),
grep("IEM",colnames(Miller2015))]
data_mx = apply(data_mx[,c(1,2)], c(1,2), as.numeric)
# Look at the top 5 metabolites for each patient.
kmx=5
# Build your results ("res") list object to store patient distances at
# different size k's.
res = list()
t = list(dir=matrix(NA, nrow=ncol(data_mx), ncol=ncol(data_mx)))
rownames(t$dir) = colnames(data_mx)
colnames(t$dir) = colnames(data_mx)
for (i in seq_len(kmx)) { res[[i]] = t }
for (pt in seq_len(ncol(data_mx))) {
print(pt)
ptID=colnames(data_mx)[pt]
for (pt2 in pt:ncol(data_mx)) {
ptID2=colnames(data_mx)[pt2]
tmp=stat.getDirSim(ptID,ptID2,kmx,data_mx)
for (k in seq_len(kmx)) {
res[[k]]$dir[ptID, ptID2]=tmp[k]
res[[k]]$dir[ptID2, ptID]=tmp[k]
}
}
}
Run the code above in your browser using DataLab