在处理 DNA 时,我们经常需要三角形 p 距离矩阵,它包含序列对之间不同位点的比例。因此:
- AGGTT
- AGCTA
- AGGTA
产量:
1 2
2 0.4
3 0.2 0.2
p 距离计算在某些 R 包中可用,但假设我需要使用数字代码 (-1,0,1,2),而不是字母 (C,T,A,G)。如何从“my.matrix”生成三角 p 距离矩阵?
# Define DNA matrix dimensions
bp = 5 # DNA matrix length
n = 3 # DNA matrix height
# Build Binary Matrices
purine <- matrix(sample(0:1,(bp*n),replace=TRUE,prob=c(0.5,0.5)),n,bp)
ketone <- matrix(sample(0:1,(bp*n),replace=TRUE,prob=c(0.5,0.5)),n,bp)
strong <- 1-(abs(purine-ketone))
my.matrix <- (purine*strong-ketone)+(purine*ketone-strong)+purine+ketone
my.matrix