User Tools

Site Tools


haplotype_distance

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
haplotype_distance [2007/12/21 12:13] – created heidihaplotype_distance [2008/07/22 13:31] (current) – external edit 127.0.0.1
Line 47: Line 47:
   image.plot(x,y,DistanceMatrix, col=ColorRamp, main="Inter-haplotypic   image.plot(x,y,DistanceMatrix, col=ColorRamp, main="Inter-haplotypic
               distance matrix", xlab="Haplotype", ylab="Haplotype" )               distance matrix", xlab="Haplotype", ylab="Haplotype" )
 +</code>
 +
 +
 +===== rotated and more labels =====
 +  * file: matrix_HapDistanceMatrix.r
 +  * document page: 8
 +
 +\\
 +**code:**
 +<code>
 +Data <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/HapDistanceMatrix_mt.txt", skip=1)
 +
 +Columns <- ncol(Data ) + 1
 +Row <- nrow(Data)
 +
 +x <- 3
 +n <- 1
 +
 +DistanceMatrix <- as.matrix(scan("D:/Heidi/Master/R_Daten/HaplotypeDistance/HapDistanceMatrix_mt.txt",
 +                                  what=double(0), skip=x, nlines=1, nmax=n))
 +DistanceMatrix <- cbind(DistanceMatrix, matrix(NA, ncol=(Columns-n), nrow=1))
 +DistanceMatrix <- DistanceMatrix[,2:Columns]
 +
 +n <- n + 1
 +x <- x + 1
 + 
 +while(n<(Row+1)){ 
 +  nextrow <- as.matrix(scan("D:/Heidi/Master/R_Daten/HaplotypeDistance/HapDistanceMatrix_mt.txt",
 +                             what=double(0), skip=x, nlines=1, nmax=n))
 +  nextrow <- cbind(t(nextrow), matrix(NA, ncol=(Columns-n), nrow=1))
 +  nextrow <- nextrow[,2:Columns]
 +
 +  DistanceMatrix <- rbind(DistanceMatrix, nextrow)
 +
 +  n <- n + 1
 +  x <- x + 1   
 +}
 + 
 +a <- ncol(DistanceMatrix)
 +b <- nrow(DistanceMatrix)
 +
 +x <- c(1:a)
 +y <- c(1:b)
 +
 +# 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)
 + 
 +
 +library(fields)
 + ColorRamp <- rgb( seq(1,0,length=256),  # Red
 +                   seq(1,0,length=256),  # Green
 +                   seq(1,1,length=256))  # Blue
 +
 + image.plot(x,y,DistanceMatrix, col=ColorRamp, main="Inter-haplotypic distance matrix",
 +            xlab="Haplotype", ylab="Haplotype", axes = FALSE)
 +        contour(DistanceMatrix, add = TRUE)
 +        axis(1, at = c(1:a),cex.axis=0.7)
 +        axis(2, at = c(1:b), labels=c(b:1),cex.axis=0.7)
 +        box()
 </code> </code>
  
haplotype_distance.1198235627.txt.gz · Last modified: 2008/07/22 13:30 (external edit)