User Tools

Site Tools


haplotype_distance

haplotype distance

  • file: matrix_HapDistanceMatrix.r
  • document page: 5


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), row.names=1)
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)
 
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" )

rotated and more labels

  • file: matrix_HapDistanceMatrix.r
  • document page: 8


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()
haplotype_distance.txt · Last modified: 2008/07/22 13:31 by 127.0.0.1