fst_matrix
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| fst_matrix [2007/12/21 13:49] – heidi | fst_matrix [2008/07/22 13:31] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 25: | Line 25: | ||
| ylab=" | ylab=" | ||
| </ | </ | ||
| + | |||
| ===== rad data from a HTML file ===== | ===== rad data from a HTML file ===== | ||
| Line 113: | Line 114: | ||
| box() | box() | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ===== read data from a XML file ===== | ||
| + | * file: Node auslesen_matrix_PairwiseFst.r | ||
| + | * document page: 20 | ||
| + | |||
| + | \\ | ||
| + | **code:** | ||
| + | < | ||
| + | #----open XML package------------------------------------------------- | ||
| + | library(XML) | ||
| + | |||
| + | #----read data between an XML tag------------------------------------- | ||
| + | filename = " | ||
| + | tag = "// | ||
| + | doc = xmlTreeParse(filename, | ||
| + | ch = getNodeSet(doc, | ||
| + | |||
| + | subDoc = xmlDoc(ch[[1]]) | ||
| + | tagData <- xpathApply(subDoc, | ||
| + | free(subDoc) | ||
| + | # | ||
| + | |||
| + | # | ||
| + | #----split string---- | ||
| + | tagData2 <- as.character(tagData) | ||
| + | |||
| + | tagData3 <- strsplit(tagData2, | ||
| + | tagMatrix <- as.matrix(as.data.frame(tagData3)) | ||
| + | tagMatrix <- tagMatrix[4: | ||
| + | Data <- strsplit(tagMatrix, | ||
| + | |||
| + | #----to string matrix---- | ||
| + | Row <- length(Data) | ||
| + | |||
| + | Matrix <- as.matrix(as.data.frame(Data[1])) | ||
| + | Matrix <- rbind(Matrix, | ||
| + | |||
| + | for(n in 2:(Row)){ | ||
| + | nextrow <- as.matrix(as.data.frame(Data[n])) | ||
| + | nextrow <- rbind(nextrow, | ||
| + | Matrix <- cbind(Matrix, | ||
| + | } | ||
| + | Matrix <- Matrix[5: | ||
| + | |||
| + | #----to numeric matrix---- | ||
| + | numericList <- as.numeric(Matrix[, | ||
| + | numericMatrix <- t(as.matrix(numericList)) | ||
| + | |||
| + | for(n in 2:(Row)){ | ||
| + | numericList <- as.numeric(Matrix[, | ||
| + | numericMatrix <- rbind(numericMatrix, | ||
| + | } | ||
| + | numericMatrix | ||
| + | |||
| + | # numericTable <- as.table(numericMatrix) | ||
| + | # numericTable | ||
| + | |||
| + | DistanceMatrix <- numericMatrix | ||
| + | |||
| + | #----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)) | ||
| + | } | ||
| + | |||
| + | DistanceMatrix <- rotate270.matrix(DistanceMatrix) | ||
| + | |||
| + | #----draw matrix plot---- | ||
| + | library(fields) | ||
| + | |||
| + | a <- ncol(DistanceMatrix) | ||
| + | b <- nrow(DistanceMatrix) | ||
| + | x <- c(1:a) | ||
| + | y <- c(1:b) | ||
| + | |||
| + | ColorRamp <- rgb( seq(1, | ||
| + | | ||
| + | | ||
| + | |||
| + | image.plot(x, | ||
| + | xlab=" | ||
| + | legend.mar=4.3, | ||
| + | contour(DistanceMatrix, | ||
| + | axis(1, at = c(1: | ||
| + | axis(2, at = c(1:b), labels=c(b: | ||
| + | box() | ||
| + | </ | ||
| + | |||
| + | ===== move legend ===== | ||
| + | * file: matrix_PairwiseFst.r | ||
| + | * document page: 22 | ||
| + | |||
| + | \\ | ||
| + | **code:** | ||
| + | < | ||
| + | #----read data-------------------------------------------------------------- | ||
| + | read.table(" | ||
| + | header=TRUE, | ||
| + | as.matrix.data.frame(Data) -> Matrix | ||
| + | |||
| + | a <- ncol(Matrix) | ||
| + | b <- nrow(Matrix) | ||
| + | |||
| + | x <- c(1:a) | ||
| + | y <- c(1:b) | ||
| + | |||
| + | #----draw plot-------------------------------------------------------------- | ||
| + | library(fields) | ||
| + | ColorRamp <- rgb( seq(1, | ||
| + | seq(1, | ||
| + | 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)) | ||
| + | } | ||
| + | |||
| + | Matrix <- rotate270.matrix(Matrix) | ||
| + | |||
| + | #----draw matrix plot---- | ||
| + | image.plot(x, | ||
| + | xlab=" | ||
| + | cex=1.0, side=4, line=2), axes = FALSE) | ||
| + | contour(Matrix, | ||
| + | axis(1, at = c(1:a)) | ||
| + | axis(2, at = c(1:b), labels=c(b: | ||
| + | box() | ||
| + | </ | ||
| + | |||
fst_matrix.1198241343.txt.gz · Last modified: 2008/07/22 13:30 (external edit)