User Tools

Site Tools


haplotype_distance_between_within_populations_and_groups

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haplotype_distance_between_within_populations_and_groups [2008/01/22 11:39] heidihaplotype_distance_between_within_populations_and_groups [2008/07/22 13:31] (current) – external edit 127.0.0.1
Line 6: Line 6:
 **code:** **code:**
 <code> <code>
-#----read data-----------------------------------------------------------+#----read data------------------------------------------------------------------
 #----read haplotype list---- #----read haplotype list----
-Data <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/ +Data <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/ListHaplotype_betweenPop.txt", skip=1)
-ListHaplotype_betweenPop.txt", skip=1)+
  
 Row <- nrow(Data) Row <- nrow(Data)
Line 19: Line 18:
 n <- 1 n <- 1
  
-DistanceMatrix <- as.matrix(scan("D:/Heidi/Master/R_Daten/ +DistanceMatrix <- as.matrix(scan("D:/Heidi/Master/R_Daten/HaplotypeDistance/ 
-HaplotypeDistance/HapDistanceMatrix_betweenPop.txt", what=double(0), skip=x, nlines=1, nmax=n))+                        HapDistanceMatrix_betweenPop.txt", what=double(0), skip=x, nlines=1, nmax=n))
 DistanceMatrix <- cbind(DistanceMatrix, matrix(NA, ncol=Columns, nrow=1)) DistanceMatrix <- cbind(DistanceMatrix, matrix(NA, ncol=Columns, nrow=1))
 DistanceMatrix <- DistanceMatrix[,1:Columns] DistanceMatrix <- DistanceMatrix[,1:Columns]
Line 28: Line 27:
  
 while(n<(Row+1)){ while(n<(Row+1)){
-  nextrow <- as.matrix(scan("D:/Heidi/Master/R_Daten/ +  nextrow <- as.matrix(scan("D:/Heidi/Master/R_Daten/HaplotypeDistance/ 
-  HaplotypeDistance/HapDistanceMatrix_betweenPop.txt",  +                       HapDistanceMatrix_betweenPop.txt", what=double(0), skip=x, nlines=1, nmax=n))
-  what=double(0), skip=x, nlines=1, nmax=n))+
   nextrow <- cbind(t(nextrow), matrix(NA, ncol=Columns, nrow=1))   nextrow <- cbind(t(nextrow), matrix(NA, ncol=Columns, nrow=1))
   nextrow <- nextrow[,1:Columns]   nextrow <- nextrow[,1:Columns]
Line 41: Line 39:
  
  
-#----select the data of DistanceMatrix-----------------------------------+#----select the data of DistanceMatrix------------------------------------------
 dimnames(DistanceMatrix) <- list(Data[,1], Data[,1]) dimnames(DistanceMatrix) <- list(Data[,1], Data[,1])
  
 #--population1: #--population1:
-Pop1 <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/ +Pop1 <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/HapDistanceMatrix_withinPop1.txt", skip=5)
-HapDistanceMatrix_withinPop1.txt", skip=5)+
 Pop1 <- as.character(Pop1[,1]) Pop1 <- as.character(Pop1[,1])
 DistanceMatrixPop1 <- DistanceMatrix[Pop1, Pop1] DistanceMatrixPop1 <- DistanceMatrix[Pop1, Pop1]
- 
  
 #--population2: #--population2:
-Pop2 <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/ +Pop2 <- read.table("D:/Heidi/Master/R_Daten/HaplotypeDistance/HapDistanceMatrix_withinPop2.txt", skip=5)
-HapDistanceMatrix_withinPop2.txt", skip=5)+
 Pop2 <- as.character(Pop2[,1]) Pop2 <- as.character(Pop2[,1])
 DistanceMatrixPop2 <- DistanceMatrix[Pop2, Pop2] DistanceMatrixPop2 <- DistanceMatrix[Pop2, Pop2]
- 
  
 #--between population1/2: #--between population1/2:
Line 65: Line 59:
  
   twholeDistanceMatrix <- t(wholeDistanceMatrix)    twholeDistanceMatrix <- t(wholeDistanceMatrix) 
-  wholeDistanceMatrix[x,(x:ncol(wholeDistanceMatrix))] <-  +  wholeDistanceMatrix[x,(x:ncol(wholeDistanceMatrix))] <- twholeDistanceMatrix[x,(x:ncol(wholeDistanceMatrix))]
-twholeDistanceMatrix[x,(x:ncol(wholeDistanceMatrix))]+
  
   x <- x + 1   x <- x + 1
Line 74: Line 67:
    
 #----together:----- #----together:-----
-DistanceMatrixUp <- cbind(DistanceMatrixPop1, matrix(NA,  +DistanceMatrixUp <- cbind(DistanceMatrixPop1, matrix(NA, ncol(DistanceMatrixPop1), nrow(DistanceMatrixPop2)))
-ncol(DistanceMatrixPop1), nrow(DistanceMatrixPop2)))+
 DistanceMatrixLo <- cbind(wholeDistanceMatrixBetween, DistanceMatrixPop2)  DistanceMatrixLo <- cbind(wholeDistanceMatrixBetween, DistanceMatrixPop2) 
 DistanceMatrixTogether <- rbind(DistanceMatrixUp, DistanceMatrixLo) DistanceMatrixTogether <- rbind(DistanceMatrixUp, DistanceMatrixLo)
Line 83: Line 75:
 Pop_together <- c(Pop1, Pop2) Pop_together <- c(Pop1, Pop2)
  
-wholeDistanceMatrixTogether <- wholeDistanceMatrix[Pop_together,  +wholeDistanceMatrixTogether <- wholeDistanceMatrix[Pop_together, Pop_together[c(length(Pop_together)):1]]
-      Pop_together[c(length(Pop_together)):1]]+
  
  
Line 103: Line 94:
  
  
-#----draw matrix--------------------------------------------------------- +#----draw matrix---------------------------------------------------------------- 
-windows()  #new graphic window+windows()  #new graphic window  
 library(fields) library(fields)
  ColorRamp <- rgb( seq(1,0,length=256),  # Red  ColorRamp <- rgb( seq(1,0,length=256),  # Red
Line 115: Line 106:
  x <- c(1:a)  x <- c(1:a)
  y <- c(1:b)  y <- c(1:b)
- +  
-png("D:/Heidi/Master/R_Graphiken/matrix_HapDistance_between-within Pop  +png("D:/Heidi/Master/R_Graphiken/matrix_HapDistance_between-within Pop and Groups.png", width = 680, height = 660) 
-and Groups.png", width = 680, height = 660) +
 op <- par(mfrow=c(2,2), oma=c(0, 0 ,3, 0)) op <- par(mfrow=c(2,2), oma=c(0, 0 ,3, 0))
  
 #----matrix one----  #----matrix one---- 
 op1 <- par(mfg=c(1,1),mar=c(0.2, 5.2, 4.2, 0.2)) op1 <- par(mfg=c(1,1),mar=c(0.2, 5.2, 4.2, 0.2))
-  image(x,y,DistanceMatrixTogether, col=ColorRamp, ylab="Group 1",  +  image(x,y,DistanceMatrixTogether, col=ColorRamp, ylab="Group 1", font.lab=2, axes = FALSE)
-font.lab=2, axes = FALSE)+
      contour(DistanceMatrixTogether, add = TRUE)      contour(DistanceMatrixTogether, add = TRUE)
-     axis(2, at = c(1:b),labels=c(Pop2[NROW(Pop2):1],Pop1[NROW(Pop1):1]),  +     axis(2, at = c(1:b), labels=c(Pop2[NROW(Pop2):1],Pop1[NROW(Pop1):1]), cex.axis=0.6, las=2)
-cex.axis=0.6, las=2)+
      box(bty="l")      box(bty="l")
                  
Line 132: Line 120:
      lines(c(NROW(Pop1)+0.5,NROW(Pop1)+0.5),c(0,NROW(Pop2)+0.5), lwd=2)      lines(c(NROW(Pop1)+0.5,NROW(Pop1)+0.5),c(0,NROW(Pop2)+0.5), lwd=2)
                  
-     mtext(side = 2, at =(3.2*Row/4), line = 2.7, text = "Population 1",  +     mtext(side = 2, at =(3.2*Row/4), line = 2.7, text = "Population 1", cex=0.7) 
-cex=0.7) +     mtext(side = 2, at =(Row/4), line = 2.7, text = "Population 2", cex=0.7)
-     mtext(side = 2, at =(Row/4), line = 2.7, text = "Population 2",  +
-cex=0.7)+
 par(op1) par(op1)
  
Line 144: Line 130:
      contour(DistanceMatrixTogether, add = TRUE)      contour(DistanceMatrixTogether, add = TRUE)
      axis(1, at = c(1:a), labels=c(Pop_together), cex.axis=0.6, las=2)      axis(1, at = c(1:a), labels=c(Pop_together), cex.axis=0.6, las=2)
-     axis(2, at = c(1:b),labels=c(Pop2[NROW(Pop2):1],Pop1[NROW(Pop1):1]),  +     axis(2, at = c(1:b), labels=c(Pop2[NROW(Pop2):1],Pop1[NROW(Pop1):1]), cex.axis=0.6, las=2)
-cex.axis=0.6, las=2)+
      box()      box()
                  
-     lines(c(0,NROW(Pop1)+ NROW(Pop2)+0.5), c(NROW(Pop2)+ 0.5,NROW(Pop2)  +     lines(c(0,NROW(Pop1)+ NROW(Pop2)+0.5),c(NROW(Pop2)+0.5,NROW(Pop2)+0.5), lwd=2) 
-+0.5), lwd=2) +     lines(c(NROW(Pop1)+0.5,NROW(Pop1)+0.5),c(0,NROW(Pop1)+ NROW(Pop2)+0.5), lwd=2)
-     lines(c(NROW(Pop1)+0.5,NROW(Pop1)+0.5),c(0,NROW(Pop1)+ NROW(Pop2)  +
-+0.5), lwd=2)+
                  
-     mtext(side = 1, at =(Row/4), line = 2.5, text = "Population 1",  +     mtext(side = 1, at =(Row/4), line = 2.5, text = "Population 1", cex=0.7) 
-cex=0.7) +     mtext(side = 1, at =(3.2*Row/4), line = 2.5, text = "Population 2", cex=0.7) 
-     mtext(side = 1, at =(3.2*Row/4), line = 2.5, text = "Population 2",  +     mtext(side = 2, at =(3.2*Row/4), line = 2.7, text = "Population 3", cex=0.7) 
-cex=0.7) +     mtext(side = 2, at =(Row/4), line = 2.7, text = "Population 4", cex=0.7)
-     mtext(side = 2, at =(3.2*Row/4), line = 2.7, text = "Population 3",  +
-cex=0.7) +
-     mtext(side = 2, at =(Row/4), line = 2.7, text = "Population 4",  +
-cex=0.7)+
 par(op2) par(op2)
  
 #----matrix three---- #----matrix three----
 op3 <- par(mfg=c(2,2), mar=c(4.2, 0.2, 0.2, 6.2)) op3 <- par(mfg=c(2,2), mar=c(4.2, 0.2, 0.2, 6.2))
-  image(x,y,DistanceMatrixTogether, col=ColorRamp, xlab="Group 2",  +  image(x,y,DistanceMatrixTogether, col=ColorRamp, xlab="Group 2", font.lab=2, axes = FALSE)
-font.lab=2, axes = FALSE)+
      contour(DistanceMatrixTogether, add = TRUE)      contour(DistanceMatrixTogether, add = TRUE)
      axis(1, at = c(1:a), labels=c(Pop1,Pop2), cex.axis=0.6, las=2)      axis(1, at = c(1:a), labels=c(Pop1,Pop2), cex.axis=0.6, las=2)
Line 174: Line 152:
      lines(c(NROW(Pop1)+0.5,NROW(Pop1)+0.5),c(0,NROW(Pop2)+0.5), lwd=2)      lines(c(NROW(Pop1)+0.5,NROW(Pop1)+0.5),c(0,NROW(Pop2)+0.5), lwd=2)
                  
-     mtext(side = 1, at =(Row/4), line = 2.5, text = "Population 3",  +     mtext(side = 1, at =(Row/4), line = 2.5, text = "Population 3", cex=0.7) 
-cex=0.7) +     mtext(side = 1, at =(3.2*Row/4), line = 2.5, text = "Population 4", cex=0.7)
-     mtext(side = 1, at =(3.2*Row/4), line = 2.5, text = "Population 4",  +
-cex=0.7)+
 par(op3) par(op3)
  
 #----legend----  #----legend---- 
-maximum <- max(DistanceMatrixTogether, wholeDistanceMatrixTogether,  +maximum <- max(DistanceMatrixTogether, wholeDistanceMatrixTogether, DistanceMatrixTogether , na.rm = TRUE)
-  DistanceMatrixTogether , na.rm = TRUE)+
  
 Legend <- seq(from=0, to=maximum, length=100) Legend <- seq(from=0, to=maximum, length=100)
Line 192: Line 167:
      box()      box()
            
-  title("haplotype distance matrix between/within populations and  +  title("haplotype distance matrix between/within populations and groups", line=0, outer=TRUE)
-  groups", line=0, outer=TRUE)+
 par(op4) par(op4)
  
haplotype_distance_between_within_populations_and_groups.1200998368.txt.gz · Last modified: 2008/07/22 13:30 (external edit)