haplotype_distance_between_within_two_populations
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haplotype_distance_between_within_two_populations [2007/12/21 13:34] – created heidi | haplotype_distance_between_within_two_populations [2008/07/22 13:31] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 70: | Line 70: | ||
axis(2, at = c(1:b), labels=Data[(Row: | axis(2, at = c(1:b), labels=Data[(Row: | ||
box() | box() | ||
- | |||
| | ||
half <- (Row/2) + 0.5 | half <- (Row/2) + 0.5 | ||
+ | |||
lines(c(0, | lines(c(0, | ||
- | lines(c(half, | + | lines(c(half, |
- | + | ||
mtext(side = 1, at =(Row/4), line = 2, text = " | mtext(side = 1, at =(Row/4), line = 2, text = " | ||
mtext(side = 1, at =(3*Row/4), line = 2, text = " | mtext(side = 1, at =(3*Row/4), line = 2, text = " | ||
Line 81: | Line 80: | ||
mtext(side = 2, at =(3*Row/4), line = 2, text = " | mtext(side = 2, at =(3*Row/4), line = 2, text = " | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== mixed data from several populations ===== | ||
+ | * file: matrix_HapDistance_between-within_complex.r | ||
+ | * document page: 13 | ||
+ | |||
+ | \\ | ||
+ | **code:** | ||
+ | < | ||
+ | #----read haplotype list---- | ||
+ | Data <- read.table(" | ||
+ | |||
+ | Row <- nrow(Data) | ||
+ | Columns <- Row | ||
+ | |||
+ | |||
+ | #----read data row by row:---- | ||
+ | x <- 0 | ||
+ | n <- 1 | ||
+ | |||
+ | DistanceMatrix <- as.matrix(scan(" | ||
+ | what=double(0), | ||
+ | DistanceMatrix <- cbind(DistanceMatrix, | ||
+ | DistanceMatrix <- DistanceMatrix[, | ||
+ | |||
+ | |||
+ | n <- n + 1 | ||
+ | x <- x + 1 | ||
+ | |||
+ | while(n< | ||
+ | nextrow <- as.matrix(scan(" | ||
+ | | ||
+ | nextrow <- cbind(t(nextrow), | ||
+ | nextrow <- nextrow[, | ||
+ | |||
+ | DistanceMatrix <- rbind(DistanceMatrix, | ||
+ | |||
+ | n <- n + 1 | ||
+ | x <- x + 1 | ||
+ | } | ||
+ | |||
+ | #----select the data of DistanceMatrix---- | ||
+ | dimnames(DistanceMatrix) <- list(Data[, | ||
+ | |||
+ | # | ||
+ | Pop1 <- read.table(" | ||
+ | Pop1 <- as.character(Pop1[, | ||
+ | DistanceMatrixPop1 <- DistanceMatrix[Pop1, | ||
+ | |||
+ | # | ||
+ | Pop2 <- read.table(" | ||
+ | Pop2 <- as.character(Pop2[, | ||
+ | DistanceMatrixPop2 <- DistanceMatrix[Pop2, | ||
+ | |||
+ | #--between population1/ | ||
+ | #whole DistanceMatrix | ||
+ | wholeDistanceMatrix <- DistanceMatrix | ||
+ | x <- 1 | ||
+ | while(x <= ncol(wholeDistanceMatrix)){ | ||
+ | |||
+ | twholeDistanceMatrix <- t(wholeDistanceMatrix) | ||
+ | wholeDistanceMatrix[x, | ||
+ | |||
+ | x <- x + 1 | ||
+ | } | ||
+ | |||
+ | wholeDistanceMatrixBetween <- wholeDistanceMatrix[Pop2, | ||
+ | |||
+ | |||
+ | # | ||
+ | DistanceMatrixUp <- cbind(DistanceMatrixPop1, | ||
+ | DistanceMatrixLo <- cbind(wholeDistanceMatrixBetween, | ||
+ | DistanceMatrixTogether <- rbind(DistanceMatrixUp, | ||
+ | |||
+ | |||
+ | #----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)) | ||
+ | } | ||
+ | |||
+ | DistanceMatrixTogether <- rotate270.matrix(DistanceMatrixTogether) | ||
+ | |||
+ | #----draw matrix---- | ||
+ | library(fields) | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | a <- ncol(DistanceMatrixTogether) | ||
+ | b <- nrow(DistanceMatrixTogether) | ||
+ | |||
+ | x <- c(1:a) | ||
+ | y <- c(1:b) | ||
+ | |||
+ | | ||
+ | | ||
+ | contour(DistanceMatrixTogether, | ||
+ | axis(1, at = c(1:a), labels=c(Pop1, | ||
+ | axis(2, at = c(1:b), labels=c(Pop2[NROW(Pop2): | ||
+ | box() | ||
+ | lines(c(0, | ||
+ | lines(c(NROW(Pop1)+0.5, | ||
+ | mtext(side = 1, at =(Row/4), line = 2, text = " | ||
+ | mtext(side = 1, at =(3*Row/4), line = 2, text = " | ||
+ | mtext(side = 2, at =(Row/4), line = 2, text = " | ||
+ | mtext(side = 2, at =(3*Row/4), line = 2, text = " | ||
+ | </ | ||
+ | |||
+ | |||
haplotype_distance_between_within_two_populations.1198240464.txt.gz · Last modified: 2008/07/22 13:30 (external edit)