population_average_pairwise_difference
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| population_average_pairwise_difference [2008/01/28 11:40] – created heidi | population_average_pairwise_difference [2008/07/22 13:31] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | * file: lines_Mismatch.r | + | * file: matrix_PairwiseDifferences.r |
| - | * document page: 1 | + | * document page: 33 |
| \\ | \\ | ||
| **code:** | **code:** | ||
| < | < | ||
| + | #----read data------------------------------------------------------------------ | ||
| + | Data <- read.table(" | ||
| + | skip=10, row.names=1) | ||
| + | DataMatrix <- as.matrix(Data) | ||
| + | # | ||
| + | n <- 2 | ||
| + | x <- 1 | ||
| + | |||
| + | UnderMatrix <- matrix(NA, ncol=ncol(DataMatrix), | ||
| + | |||
| + | while(n< | ||
| + | nextrow <- DataMatrix[n, | ||
| + | nextrow <- cbind(t(nextrow), | ||
| + | | ||
| + | UnderMatrix <- rbind(UnderMatrix, | ||
| + | | ||
| + | n <- n+1 | ||
| + | x <- x+1 | ||
| + | } | ||
| + | |||
| + | |||
| + | # | ||
| + | n <- 2 | ||
| + | x <- 1 | ||
| + | |||
| + | UpperMatrix <- matrix(NA, ncol=x, nrow=1) | ||
| + | UpperMatrix <- cbind(UpperMatrix, | ||
| + | |||
| + | n <- n+1 | ||
| + | x <- x+1 | ||
| + | while(n< | ||
| + | nextrow <- matrix(NA, ncol=x, nrow=1) | ||
| + | nextrow <- cbind(nextrow, | ||
| + | | ||
| + | UpperMatrix <- rbind(UpperMatrix, | ||
| + | | ||
| + | n <- n+1 | ||
| + | x <- x+1 | ||
| + | } | ||
| + | UpperMatrix <- rbind(UpperMatrix, | ||
| + | |||
| + | |||
| + | # | ||
| + | n <- 1 | ||
| + | |||
| + | DiagonalMatrix <- DataMatrix[n, | ||
| + | DiagonalMatrix <- cbind(DiagonalMatrix, | ||
| + | |||
| + | n <- n+1 | ||
| + | x <- 1 | ||
| + | while(n< | ||
| + | nextrow <- matrix(NA, ncol=x, nrow=1) | ||
| + | nextrow <- cbind(nextrow, | ||
| + | nextrow <- cbind(nextrow, | ||
| + | | ||
| + | DiagonalMatrix <- rbind(DiagonalMatrix, | ||
| + | | ||
| + | n <- n+1 | ||
| + | x <- x+1 | ||
| + | } | ||
| + | |||
| + | |||
| + | # | ||
| + | a <- ncol(DataMatrix) | ||
| + | b <- nrow(DataMatrix) | ||
| + | |||
| + | x <- c(1:a) | ||
| + | y <- c(1:b) | ||
| + | |||
| + | ColorRamp <- rgb( seq(1, | ||
| + | | ||
| + | | ||
| + | |||
| + | ColorRamp2 <- rgb( seq(1, | ||
| + | | ||
| + | | ||
| + | |||
| + | ColorRamp3 <- rgb( seq(1, | ||
| + | | ||
| + | | ||
| + | |||
| + | #----Mirror matrix (left-right)---- | ||
| + | mirror.matrix <- function(x) { | ||
| + | xx <- as.data.frame(x); | ||
| + | xx <- rev(xx); | ||
| + | xx <- as.matrix(xx); | ||
| + | xx; | ||
| + | } | ||
| + | |||
| + | #----Rotate matrix 270 clockworks---- | ||
| + | rotate270.matrix <- function(x) { | ||
| + | mirror.matrix(t(x)) | ||
| + | } | ||
| + | |||
| + | UnderMatrix <- rotate270.matrix(UnderMatrix) | ||
| + | UpperMatrix <- rotate270.matrix(UpperMatrix) | ||
| + | DiagonalMatrix <- rotate270.matrix(DiagonalMatrix) | ||
| + | |||
| + | |||
| + | #-----draw matrix--------------------------------------------------------------- | ||
| + | # | ||
| + | |||
| + | #----devide plot region in 4 parts---- | ||
| + | def.par <- par(no.readonly = TRUE) # save default, for resetting... | ||
| + | layout(rbind(c(1, | ||
| + | | ||
| + | | ||
| + | |||
| + | #-----draw matrixe plot---- | ||
| + | op <- par(mar=c(7.1, | ||
| + | image(x,y, UnderMatrix, | ||
| + | image(x,y, UpperMatrix, | ||
| + | image(x,y, DiagonalMatrix, | ||
| + | | ||
| + | | ||
| + | box() | ||
| + | | ||
| + | | ||
| + | | ||
| + | par(op) | ||
| + | |||
| + | |||
| + | #----draw legends---- | ||
| + | #--upper legend-- | ||
| + | op2 <- par(mar=c(0.6, | ||
| + | UpperLegend <- seq(from=0, to=max(UpperMatrix, | ||
| + | UpperLegend <- as.matrix(UpperLegend) | ||
| + | |||
| + | image(y=UpperLegend, | ||
| + | | ||
| + | | ||
| + | between populations (PiXY)", | ||
| + | box() | ||
| + | par(op2) | ||
| + | |||
| + | #--diagonal legend-- | ||
| + | op3 <- par(mar=c(2.1, | ||
| + | DiagonalLegend <- seq(from=0, to=max(DiagonalMatrix, | ||
| + | DiagonalLegend <- as.matrix(DiagonalLegend) | ||
| + | |||
| + | image(y=DiagonalLegend, | ||
| + | | ||
| + | | ||
| + | differences within population (PiX)", | ||
| + | box() | ||
| + | par(op3) | ||
| + | |||
| + | #--under legend-- | ||
| + | op4 <- par(mar=c(3.6, | ||
| + | UnderLegend <- seq(from=0, to=max(UnderMatrix, | ||
| + | UnderLegend <- as.matrix(UnderLegend) | ||
| + | |||
| + | image(y=UnderLegend, | ||
| + | | ||
| + | | ||
| + | difference(PiXY-(PiX+PiY)/ | ||
| + | box() | ||
| + | par(op4) | ||
| + | |||
| + | #dev.off() | ||
| + | par(def.par) | ||
| + | </ | ||
population_average_pairwise_difference.1201516848.txt.gz · Last modified: 2008/07/22 13:30 (external edit)