[Rcolony-commits] r77 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 22 19:52:09 CET 2012


Author: jonesor
Date: 2012-11-22 19:52:09 +0100 (Thu, 22 Nov 2012)
New Revision: 77

Modified:
   pkg/R/build.colony.input.R
Log:
Fixed bug in build.colony.input and reformatted.

Modified: pkg/R/build.colony.input.R
===================================================================
--- pkg/R/build.colony.input.R	2012-11-20 15:09:03 UTC (rev 76)
+++ pkg/R/build.colony.input.R	2012-11-22 18:52:09 UTC (rev 77)
@@ -1,58 +1,59 @@
-build.colony.input<-function(wd=getwd(),name="Colony2.DAT",delim=""){
+build.colony.input <- function(wd=getwd(), name = "Colony2.DAT", delim = ""){
   
-  # wd = getwd()
-  # name = "Colony2.DAT"  
-  colonyfile<-NULL
+#   wd = getwd()
+#  name = "Colony2.DAT"
+# delim = ""
+   
+  colonyfile = NULL
   
   cat("This function will construct a Colony input file.\nPLEASE REFER TO THE HELP FILE ?build.colony.input.\n\n")
-  cat(paste("It will be called",name,"and be placed in",wd,"...\n\n\n"))
+  cat(paste("It will be called", name, "and be placed in", wd, "...\n\n\n"))
   
   #Functions used here
-  is.whole <- function(a) { floor(a)==a }
+  is.whole <- function(a) {floor(a) == a}
   
-  
   #######################################################
   #  ! C, Dataset name, Length<51
   #######################################################
   
-  while(length(colonyfile$datasetname)==0){
+  while(length(colonyfile$datasetname) == 0){
     cat("Enter dataset name (must be <51 characters).\n\n\n")
-    colonyfile$datasetname<-scan(n=1,what="character")
-    write(paste(colonyfile$datasetname,"! C, Dataset name, Length<51"),name,append=FALSE)
+    colonyfile$datasetname = scan(n = 1, what = "character")
+    write(paste(colonyfile$datasetname, "! C, Dataset name, Length<51"), name, append = FALSE)
   }
   
   #######################################################
   #  ! C, Main output file name, Length<21
   #######################################################
-  while(length(colonyfile$outfile)==0){
+  while(length(colonyfile$outfile) == 0){
     cat("Enter main output file name (must be <21 characters).\n\n\n")
-    colonyfile$outfile<-scan(n=1,what="character")
-    write(paste(colonyfile$outfile,"! C, Main output file name, Length<21"),name,append=TRUE)
+    colonyfile$outfile = scan(n = 1, what = "character")
+    write(paste(colonyfile$outfile, "! C, Main output file name, Length<21"), name, append = TRUE)
   }
   
   #######################################################
   #  ! C, Note to the project
   #######################################################
   
-  while(length(colonyfile$note)==0){
+  while(length(colonyfile$note) == 0){
     cat("Enter one sentence to describe your dataset (no carriage returns!).\n\n\n")
-    colonyfile$note<-scan(n=1,what="character")
+    colonyfile$note = scan(n = 1, what = "character")
   }
   
   #######################################################
   #  ! I, Number of offspring in the sample
   #######################################################
-  while(length(colonyfile$n.offspring)==0){
+  while(length(colonyfile$n.offspring) == 0){
     cat("Enter number of offspring in the sample.\n\n\n")
-    colonyfile$n.offspring<-as.numeric(scan(n=1,what="integer"))
-    write(paste(colonyfile$n.offspring,"! I, Number of offspring in the sample"),name,append=TRUE)
+    colonyfile$n.offspring = as.numeric(scan(n = 1, what = "integer"))
+    write(paste(colonyfile$n.offspring, "! I, Number of offspring in the sample"), name, append = TRUE)
     
-    if(length(colonyfile$n.offspring)!=0){
+    if(length(colonyfile$n.offspring) != 0){
       #Whole number warning 
-      if(is.whole(colonyfile$n.offspring)==FALSE){
+      if(is.whole(colonyfile$n.offspring) == FALSE){
         flush.console()
-        colonyfile<-colonyfile[which(names(colonyfile)!="n.offspring")]
-        ;warning("The number of offspring must be a whole number!\n",immediate.=TRUE)
+        colonyfile = colonyfile[which(names(colonyfile) != "n.offspring")]
+        warning("The number of offspring must be a whole number!\n", immediate. = TRUE)
       }
     }
   }
@@ -61,17 +62,17 @@
   #######################################################
   #  ! I, Number of loci
   #######################################################
-  while(length(colonyfile$n.loci)==0){
+  while(length(colonyfile$n.loci) == 0){
     cat("Enter number of loci.\n\n\n")
-    colonyfile$n.loci<-as.numeric(scan(n=1,what="integer"))
-    write(paste(colonyfile$n.loci,"! I, Number of loci"),name,append=TRUE)
+    colonyfile$n.loci = as.numeric(scan(n = 1, what = "integer"))
+    write(paste(colonyfile$n.loci, "! I, Number of loci"), name, append = TRUE)
     
-    if(length(colonyfile$n.loci)!=0){
+    if(length(colonyfile$n.loci) != 0){
       #Whole number warning 
-      if(is.whole(colonyfile$n.loci)==FALSE){
+      if(is.whole(colonyfile$n.loci) == FALSE){
         flush.console()
-        colonyfile<-colonyfile[which(names(colonyfile)!="n.loci")]
-        ;warning("The number of loci must be a whole number!\n",immediate.=TRUE)
+        colonyfile = colonyfile[which(names(colonyfile) != "n.loci")]
+        warning("The number of loci must be a whole number!\n", immediate. = TRUE)
       }
     }
   }
@@ -79,18 +80,19 @@
   #######################################################
   #  ! I, Seed for random number generator
   #######################################################
-  while(length(colonyfile$rseed)==0){
+  while(length(colonyfile$rseed) == 0){
     cat("Enter seed for random number generator.\n\n\n")
-    colonyfile$rseed<-as.numeric(scan(n=1,what="integer"))
-    write(paste(colonyfile$rseed,"! I, Seed for random number generator"),name,append=TRUE)
+    colonyfile$rseed = as.numeric(scan(n = 1, what = "integer"))
+    write(paste(colonyfile$rseed, "! I, Seed for random number generator"), name, append = TRUE)
   }
   
   #######################################################
   #  ! B, 0/1=Not updating/updating allele frequency
   #######################################################
   cat("Should allele frequency be updated?\n\n\n")
-  switch(menu(c("Not updating allele frequency", "Updating allele frequency")) + 1, cat("Nothing done\n\n\n"), colonyfile$updateallelefreq<-0, colonyfile$updateallelefreq<-1)
-  write(paste(colonyfile$updateallelefreq,"! B, 0/1=Not updating/updating allele frequency"),name,append=TRUE)
+  switch(menu(c("Not updating allele frequency", "Updating allele frequency")) + 1, 
+         cat("Nothing done\n\n\n"), colonyfile$updateallelefreq <- 0, colonyfile$updateallelefreq <- 1)
+  write(paste(colonyfile$updateallelefreq, "! B, 0/1=Not updating/updating allele frequency"), name, append = TRUE)
   
   
   #######################################################
@@ -98,112 +100,106 @@
   #######################################################
   cat("What kind of species is it?\nSee help for definitions.\n\n")
   switch(menu(c("Dioecious species", "Monoecious species")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$diomonoecy<-2, colonyfile$diomonoecy<-1)
-  write(paste(colonyfile$diomonoecy,"! 2/1=Dioecious/Monoecious"),name,append=TRUE)
+         cat("Nothing done\n\n\n"), colonyfile$diomonoecy <- 2, colonyfile$diomonoecy <- 1)
+  write(paste(colonyfile$diomonoecy, "! 2/1=Dioecious/Monoecious"), name, append = TRUE)
   
   #######################################################
   #  ! B, 0/1=Diploid species/HaploDiploid species
   #######################################################
   cat("What kind of species is it?\nSee help for definitions.\n\n")
   switch(menu(c("Diploid species", "HaploDiploid species")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$ploidy<-0, colonyfile$ploidy<-1)
-  write(paste(colonyfile$ploidy,"! B, 0/1=Diploid species/HaploDiploid species"),name,append=TRUE)
+         cat("Nothing done\n\n\n"), colonyfile$ploidy <- 0, colonyfile$ploidy <- 1)
+  write(paste(colonyfile$ploidy, "! B, 0/1=Diploid species/HaploDiploid species"), name, append = TRUE)
   
   #######################################################
   #  ! B, 0/1=Polygamy/Monogamy for males & females
   #######################################################
   cat("Are males monogamous or polygamous?\nSee help for definitions.\n\n")
   switch(menu(c("Males monogamous", "Males polygamous")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$malepolygamy<-1, colonyfile$malepolygamy<-0)
+         cat("Nothing done\n\n\n"), colonyfile$malepolygamy <- 1, colonyfile$malepolygamy <- 0)
   
   cat("Are females monogamous or polygamous?\nSee help for definitions.\n\n")
   switch(menu(c("Females monogamous", "Females polygamous")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$femalepolygamy<-1, colonyfile$femalepolygamy<-0)
-  write(paste(colonyfile$malepolygamy,colonyfile$femalepolygamy,"! B, 0/1=Polygamy/Monogamy for males & females"),name,append=TRUE)
+         cat("Nothing done\n\n\n"), colonyfile$femalepolygamy <- 1, colonyfile$femalepolygamy <- 0)
+  write(paste(colonyfile$malepolygamy, colonyfile$femalepolygamy, "! B, 0/1=Polygamy/Monogamy for males & females"), name, append = TRUE)
   
   #######################################################
-  #  ! B,R,R : Use sibship prior, Y/N=1/0. If Yes, give mean paternal, maternal sibship size
+  #  ! B, R, R : Use sibship prior, Y/N=1/0. If Yes, give mean paternal, maternal sibship size
   #######################################################
   cat("Use sibship prior?\n\n\n")
   switch(menu(c("Yes", "No")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$sibship.prior<-1, colonyfile$sibship.prior<-0)
+         cat("Nothing done\n\n\n"), colonyfile$sibship.prior <- 1, colonyfile$sibship.prior <- 0)
   
   if(colonyfile$sibship.prior==0){
-    colonyfile$sibship.prior.paternal<-0
-    colonyfile$sibship.prior.maternal<-0
-    write(paste(colonyfile$sibship.prior,colonyfile$sibship.prior.paternal,colonyfile$sibship.prior.maternal,"! B,R,R : Use sibship prior, Y/N=1/0. If Yes, give mean paternal, maternal sibship size"),name,append=TRUE)
-  }else{
+    colonyfile$sibship.prior.paternal = 0
+    colonyfile$sibship.prior.maternal = 0
+    write(paste(colonyfile$sibship.prior, colonyfile$sibship.prior.paternal, colonyfile$sibship.prior.maternal, "! B, R, R : Use sibship prior, Y/N=1/0. If Yes, give mean paternal, maternal sibship size"), name, append = TRUE)
+    }else{
+      while(length(colonyfile$sibship.prior.paternal) == 0){
+        cat("Enter the paternal sibship size (number of sibships).\n\n\n")
+        colonyfile$sibship.prior.paternal = as.numeric(scan(n = 1, what = "integer"))
+      }
     
-    while(length(colonyfile$sibship.prior.paternal)==0){
-      cat("Enter the paternal sibship size (number of sibships).\n\n\n")
-      colonyfile$sibship.prior.paternal<-as.numeric(scan(n=1,what="integer"))}
-    
-    while(length(colonyfile$sibship.prior.maternal)==0){
+    while(length(colonyfile$sibship.prior.maternal) == 0){
       cat("Enter the maternal sibship size (number of sibships).\n\n\n")
-      colonyfile$sibship.prior.maternal<-as.numeric(scan(n=1,what="integer"))}
-    write(paste(colonyfile$sibship.prior,colonyfile$sibship.prior.paternal,colonyfile$sibship.prior.maternal,"! B,R,R : Use sibship prior, Y/N=1/0. If Yes, give mean paternal, maternal sibship size"),name,append=TRUE)
-  }
+      colonyfile$sibship.prior.maternal = as.numeric(scan(n = 1, what = "integer"))
+    }
+      write(paste(colonyfile$sibship.prior, colonyfile$sibship.prior.paternal, colonyfile$sibship.prior.maternal, "! B, R, R : Use sibship prior, Y/N=1/0. If Yes, give mean paternal, maternal sibship size"), name, append = TRUE)
+    }
   
   #######################################################
   #  ! B, 0/1=Unknown/Known population allele frequency
   #######################################################
   cat("Unknown/Known population allele frequency?\n\n\n")
   switch(menu(c("Unknown", "Known")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$knownAFreq<-0, colonyfile$knownAFreq<-1)
+         cat("Nothing done\n\n\n"), colonyfile$knownAFreq <- 0, colonyfile$knownAFreq <- 1)
   
-  write(paste(colonyfile$knownAFreq,"! B, 0/1=Unknown/Known population allele frequency\n"),name,append=TRUE)
+  write(paste(colonyfile$knownAFreq, "! B, 0/1=Unknown/Known population allele frequency\n"), name, append = TRUE)
   
-  if(colonyfile$knownAFreq==1){
-    while(length(colonyfile$AlleleFreqPATH)==0){ 
+  if(colonyfile$knownAFreq == 1){
+    while(length(colonyfile$AlleleFreqPATH) == 0){
       cat("Select the ALLELE FREQUENCY file.\n\n\n")
       Sys.sleep(.2)
       flush.console()
-      colonyfile$AlleleFreqPATH<-file.choose()
-  
-      colonyfile$allele.frequency<-read.table(colonyfile$AlleleFreqPATH,header=FALSE,colClasses=c("character"),sep=delim,fill=TRUE,flush=TRUE,na.string="",col.names=1:max(count.fields(colonyfile$AlleleFreqPATH)))
+      colonyfile$AlleleFreqPATH = file.choose()
+      colonyfile$allele.frequency = read.table(colonyfile$AlleleFreqPATH, header = FALSE, colClasses = c("character"), sep = delim, fill = TRUE, flush = TRUE, na.string = "", col.names = 1:max(count.fields(colonyfile$AlleleFreqPATH)))
       flush.console()
     }
     
+    x = count.fields(colonyfile$AlleleFreqPATH)[seq(2, length(count.fields(colonyfile$AlleleFreqPATH)), 2)]
+    x = paste(paste(x, collapse = " "), "!Number of alleles per locus", collapse=" ")
     
-    
-    x<-count.fields(colonyfile$AlleleFreqPATH)[seq(2,length(count.fields(colonyfile$AlleleFreqPATH)),2)]
-    x<-paste(paste(x,collapse=" "),"!Number of alleles per locus",collapse=" ")
-    
-    write.table(x,name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE,na="")
-    write.table(colonyfile$allele.frequency,name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE,na="")
-    write("\n",name,append=TRUE)
-    
+    write.table(x, name, append = TRUE, quote = FALSE, row.names = FALSE, col.names = FALSE, na="")
+    write.table(colonyfile$allele.frequency, name, append = TRUE, quote = FALSE, row.names = FALSE, col.names = FALSE, na = "")
+    write("\n", name, append = TRUE)
   }
   
-  
-  
-  
-  
   #######################################################
   #  ! I, Number of runs
   #######################################################
-  while(length(colonyfile$n.runs)==0){
+  while(length(colonyfile$n.runs) == 0){
     cat("Number of runs.\n\n\n")
-    colonyfile$n.runs<-as.numeric(scan(n=1,what="integer"))
-    write(paste(colonyfile$n.runs,"! I, Number of runs"),name,append=TRUE)
+    colonyfile$n.runs = as.numeric(scan(n = 1, what = "integer"))
+    write(paste(colonyfile$n.runs, "! I, Number of runs"), name, append = TRUE)
     
-    if(length(colonyfile$n.runs)!=0){
-      #Whole number warning 
-      if(is.whole(colonyfile$n.runs)==FALSE){
+    if(length(colonyfile$n.runs) != 0){
+      #Whole number warning
+      if(is.whole(colonyfile$n.runs) == FALSE){
         flush.console()
-        colonyfile<-colonyfile[which(names(colonyfile)!="n.runs")]
-        ;warning("The number of runs must be a whole number!\n",immediate.=TRUE)}}
-    
+        colonyfile = colonyfile[which(names(colonyfile) != "n.runs")]
+        warning("The number of runs must be a whole number!\n", immediate. = TRUE)
+      }
+    }
   }
   
   #######################################################
   #  ! I, Length of Run (1, 2, 3) = (Short, Medium, Long)
   #######################################################
-  while(length(colonyfile$runlength)==0){
+  while(length(colonyfile$runlength) == 0){
     cat("Length of run?\n\n\n")
-    switch(menu(c("Short", "Medium","Long")) + 1,
-           cat("Nothing done\n\n\n"), colonyfile$runlength<-1, colonyfile$runlength<-2, colonyfile$runlength<-3)
-    write(paste(colonyfile$runlength,"! I, Length of Run (1, 2, 3) = (Short, Medium, Long)"),name,append=TRUE)
+    switch(menu(c("Short", "Medium", "Long")) + 1,
+           cat("Nothing done\n\n\n"), colonyfile$runlength <- 1, colonyfile$runlength <- 2, colonyfile$runlength <- 3)
+    write(paste(colonyfile$runlength, "! I, Length of Run (1, 2, 3) = (Short, Medium, Long)"), name, append = TRUE)
   }
   
   #######################################################
@@ -211,16 +207,16 @@
   #######################################################
   cat("Monitor method by Iterate/Time in second?\n\n\n")
   switch(menu(c("Monitor by iterate", "Monitor by time in seconds")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$monitortype<-0, colonyfile$monitortype<-1)
-  write(paste(colonyfile$monitortype,"! B, 0/1=Monitor method by Iterate#/Time in second"),name,append=TRUE)
+         cat("Nothing done\n\n\n"), colonyfile$monitortype <- 0, colonyfile$monitortype <- 1)
+  write(paste(colonyfile$monitortype, "! B, 0/1=Monitor method by Iterate#/Time in second"), name, append = TRUE)
   
   #######################################################
   #  ! I, Monitor interval in Iterate#/Seconds
   #######################################################
-  while(length(colonyfile$interval)==0){
+  while(length(colonyfile$interval) == 0){
     cat("Monitor interval (in iterate number or seconds) depending on how you have chosen to monitor progress.\n\n\n")
-    colonyfile$interval<-as.numeric(scan(n=1,what="integer"))
-    write(paste(format(colonyfile$interval,scientific=F),"! I, Monitor interval in Iterate#/Seconds"),name,append=TRUE)
+    colonyfile$interval = as.numeric(scan(n = 1, what = "integer"))
+    write(paste(format(colonyfile$interval, scientific = FALSE), "! I, Monitor interval in Iterate#/Seconds"), name, append = TRUE)
   }
   
   #######################################################
@@ -228,27 +224,26 @@
   #######################################################
   cat("What platform is this to be executed on?\n\n\n")
   switch(menu(c("Microsoft Windows system", "Other system (e.g. Mac/Unix)")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$sys<-1, colonyfile$sys<-0)
-  write(paste(colonyfile$sys,"! B, 0/1=Other platform/Windows execution"),name,append=TRUE)
+         cat("Nothing done\n\n\n"), colonyfile$sys <- 1, colonyfile$sys <- 0)
+  write(paste(colonyfile$sys, "! B, 0/1=Other platform/Windows execution"), name, append = TRUE)
   
   #######################################################
   #  ! 1/0=Full-likelihood/pair-likelihood score method
   #######################################################
   cat("Which likelihood method should be used?\n\n\n")
   switch(menu(c("Full likelihood", "Pairwise likelihood")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$likelihood.method<-1, colonyfile$likelihood.method<-0)
-  write(paste(colonyfile$likelihood.method,"! 1/0=Full-likelihood/pair-likelihood score method"),name,append=TRUE)
+         cat("Nothing done\n\n\n"), colonyfile$likelihood.method <- 1, colonyfile$likelihood.method <- 0)
+  write(paste(colonyfile$likelihood.method, "! 1/0=Full-likelihood/pairwise-likelihood score method"), name, append = TRUE)
   
   #######################################################
   #  ! 1/2/3=low/medium/high precision
   #######################################################
   cat("What level of precision should be used?\n\n\n")
-  switch(menu(c("Low", "Medium","High")) + 1,
-         cat("Nothing done\n\n\n"), colonyfile$precision<-1, colonyfile$precision<-2, colonyfile$precision<-3)
-  write(paste(colonyfile$precision,"! 1/2/3=low/medium/high precision"),name,append=TRUE)
+  switch(menu(c("Low", "Medium", "High")) + 1,
+         cat("Nothing done\n\n\n"), colonyfile$precision <- 1, colonyfile$precision <- 2, colonyfile$precision <- 3)
+  write(paste(colonyfile$precision, "! 1/2/3=low/medium/high precision"), name, append = TRUE)
+  write("\n", name, append = TRUE)
   
-  write("\n",name,append=TRUE)
-  
   #######################################################
   #Marker file import
   #######################################################
@@ -256,25 +251,24 @@
   #Give the path to the marker types and error rate file. This should be a file with a number of columns equal to the number of markers used.
   #There should be 4 rows, 1) marker ID, 2) marker type, 3) marker specific allelic dropout rate, 4) marker specific other typing error rate.
   
-  while(length(colonyfile$MarkerPATH)==0){
-    cat("Provide the path to the Marker Types and Error Rate file.\n\n\n");Sys.sleep(.5)
+  while(length(colonyfile$MarkerPATH) == 0){
+    cat("Provide the path to the Marker Types and Error Rate file.\n\n\n")
+    Sys.sleep(.5)
     flush.console()
-    colonyfile$MarkerPATH<-file.choose()
-    
-    
-    colonyfile$Markers<-read.table(colonyfile$MarkerPATH,header=FALSE,colClasses=c("character"),sep=delim) 
-    
+    colonyfile$MarkerPATH = file.choose()
+    colonyfile$Markers = read.table(colonyfile$MarkerPATH, header = FALSE, colClasses = c("character"), sep = delim) 
     flush.console()
     
-    if(colonyfile$n.loci!=dim(colonyfile$Markers)[2]){colonyfile<-colonyfile[which(names(colonyfile)!="MarkerPATH")]
-                                                      ;warning(paste("The number of defined loci ","(", colonyfile$n.loci,") does not equal the number of markers provided in the file selected (", dim(colonyfile$Markers)[2],").\n\n",sep=""),immediate.=TRUE)}
+    if(colonyfile$n.loci != dim(colonyfile$Markers)[2]){
+      colonyfile = colonyfile[which(names(colonyfile) != "MarkerPATH")]
+      warning(paste("The number of defined loci ", "(",  colonyfile$n.loci, ") does not equal the number of markers provided in the file selected (", dim(colonyfile$Markers)[2], ").\n\n", sep = ""), immediate. = TRUE)
+    }
   }
   
-  colonyfile$Markers[,1+dim(colonyfile$Markers)[2]]<-c("!Marker IDs","!Marker types, 0/1=Codominant/Dominant","!Marker-specific allelic dropout rate","!Other marker-specific typing-error rate")
-  write.table(colonyfile$Markers,name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
-  write("\n",name,append=TRUE)
-  
-  
+  colonyfile$Markers[, 1 + dim(colonyfile$Markers)[2]] = c("!Marker IDs", "!Marker types, 0/1=Codominant/Dominant", "!Marker-specific allelic dropout rate", "!Other marker-specific typing-error rate")
+  write.table(colonyfile$Markers, name, append = TRUE, quote = FALSE, row.names = FALSE, col.names = FALSE)
+  write("\n", name, append = TRUE)
+    
   #######################################################
   #Offspring genotype import
   #######################################################
@@ -286,237 +280,243 @@
   cat("\nProvide the path to the offspringID and genotype file.\n\n\n")
   flush.console()
   
-  while(length(colonyfile$OSGenotypePATH)==0){
-    colonyfile$OSGenotypePATH<-file.choose()
-    
-      
-    colonyfile$Offspring<-read.table(colonyfile$OSGenotypePATH,header=FALSE,colClasses=c("character"),sep=delim) 
-    if(colonyfile$n.offspring!=dim(colonyfile$Offspring)[1]){
-      colonyfile<-colonyfile[which(names(colonyfile)!="OSGenotypePATH")];
-      flush.console();
-      warning(paste("The number of defined offspring ","(", colonyfile$n.offspring,") does not equal the number of offspring provided in the file selected (", dim(colonyfile$Offspring)[1],").\n\n",sep=""),immediate.=TRUE)
+  while(length(colonyfile$OSGenotypePATH) == 0){
+    colonyfile$OSGenotypePATH = file.choose()
+    colonyfile$Offspring = read.table(colonyfile$OSGenotypePATH, header = FALSE, colClasses = c("character"), sep = delim) 
+
+    if(colonyfile$n.offspring != dim(colonyfile$Offspring)[1]){
+      colonyfile = colonyfile[which(names(colonyfile) != "OSGenotypePATH")]
+      flush.console()
+      warning(paste("The number of defined offspring ", "(", colonyfile$n.offspring, ") does not equal the number of offspring provided in the file selected (", dim(colonyfile$Offspring)[1], ").\n\n", sep = ""), immediate. = TRUE)
     }
     
-    fileloci<-(dim(colonyfile$Offspring)[2]-1)/2
-    if(colonyfile$ploidy==0){if((colonyfile$n.loci)!=fileloci){
-      colonyfile<-colonyfile[which(names(colonyfile)!="OSGenotypePATH")];
-      flush.console();
-      warning(paste("The number of defined loci ","(", colonyfile$n.loci,") does not appear to equal the number of loci provided in the file selected (", fileloci,").\n\n",sep=""),immediate.=TRUE)}
+    fileloci = (dim(colonyfile$Offspring)[2] - 1) / 2
+    
+    if(colonyfile$ploidy == 0){
+      if((colonyfile$n.loci) != fileloci){
+        colonyfile = colonyfile[which(names(colonyfile) != "OSGenotypePATH")]
+        flush.console()
+        warning(paste("The number of defined loci ", "(", colonyfile$n.loci, ") does not appear to equal the number of loci provided in the file selected (", fileloci, ").\n\n", sep = ""), immediate. = TRUE)
+      }
     }
   }
   
-  colonyfile$Offspring[,1+dim(colonyfile$Offspring)[2]]<-c("!Offspring ID and genotypes",rep("",dim(colonyfile$Offspring)[1]-1))
-  write.table(colonyfile$Offspring,name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
-  write("",name,append=TRUE)
+  colonyfile$Offspring[, 1 + dim(colonyfile$Offspring)[2]] = c("!Offspring ID and genotypes", rep("", dim(colonyfile$Offspring)[1] - 1))
+  write.table(colonyfile$Offspring, name, append = TRUE, quote = FALSE, row.names = FALSE, col.names = FALSE)
+  write("", name, append = TRUE)
   
   ######################################################
   #Sampling of candidate parents
-  ######################################################
-  
-  
   #######################################################
   #FATHERS - probability of inclusion in candidate set
   #######################################################
-  while(length(colonyfile$fatherprob)==0){
+  while(length(colonyfile$fatherprob) == 0){
     cat("What is the probability that the FATHER of an offpring is included in the candidate set?\n\n\n E.g. 0.5\n\n\n")
-    colonyfile$fatherprob<-as.numeric(scan(n=1,what="integer"))
-    if(colonyfile$fatherprob>1){
+    colonyfile$fatherprob = as.numeric(scan(n = 1, what = "integer"))
+
+    if(colonyfile$fatherprob > 1){
       flush.console()
       cat("Probabilities must be less than or equal to 1.\n")
-      colonyfile<-colonyfile[which(names(colonyfile)!="fatherprob")]
+      colonyfile = colonyfile[which(names(colonyfile) != "fatherprob")]
     }
   }
   
   #######################################################
-  #Number of candidate fathers
+  #FATHERS - number of candidate fathers
   #######################################################
-  while(length(colonyfile$n.father)==0){
+  while(length(colonyfile$n.father) == 0){
     cat("How many candidate FATHERS are there?\n\n\n")
-    colonyfile$n.father<-as.numeric(scan(n=1,what="integer"))
+    colonyfile$n.father = as.numeric(scan(n = 1, what = "integer"))
     
-    if(length(colonyfile$n.father)!=0){
+    if(length(colonyfile$n.father) != 0){
+
       #Whole number warning 
-      if(is.whole(colonyfile$n.father)==FALSE){
+      if(is.whole(colonyfile$n.father) == FALSE){
         flush.console()
-        colonyfile<-colonyfile[which(names(colonyfile)!="n.fathers")]
-        ;warning("The number of fathers must be a whole number!\n",immediate.=TRUE)
+        colonyfile = colonyfile[which(names(colonyfile) != "n.fathers")]
+        warning("The number of fathers must be a whole number!\n", immediate. = TRUE)
       }
     } 
   }
   
   #######################################################
-  #Import candidate FATHERS file
+  #FATHERS - Import candidate FATHERS file
   #######################################################
-  if(colonyfile$n.father!=0){
-    while(length(colonyfile$fathersPATH)==0){
+  if(colonyfile$n.father != 0){
+    while(length(colonyfile$fathersPATH) == 0){
       cat("Provide the path to the candidate FATHERS file.\n\n\n")
       flush.console()
-      colonyfile$fathersPATH<-file.choose()
+      colonyfile$fathersPATH = file.choose()
       
       
-      colonyfile$fathers<-read.table(colonyfile$fathersPATH,header=FALSE,sep=delim,colClasses=c("character"))
-      if(colonyfile$n.father!=dim(colonyfile$fathers)[1]){
-        colonyfile<-colonyfile[which(names(colonyfile)!="fathersPATH")];
-        flush.console();
-        warning(paste("The number of defined FATHERS ","(", colonyfile$n.father,") does not equal the number of FATHERS provided in the file selected (", dim(colonyfile$fathers)[1],").\n\n",sep=""),immediate.=TRUE)}
+      colonyfile$fathers = read.table(colonyfile$fathersPATH, header = FALSE, sep = delim, colClasses = c("character"))
+      if(colonyfile$n.father != dim(colonyfile$fathers)[1]){
+        colonyfile = colonyfile[which(names(colonyfile) != "fathersPATH")]
+        flush.console()
+        warning(paste("The number of defined FATHERS ", "(", colonyfile$n.father, ") does not equal the number of FATHERS provided in the file selected (", dim(colonyfile$fathers)[1], ").\n\n", sep=""), immediate. = TRUE)
+      }
     }
   }else{
-    colonyfile$fathersPATH<-NA
-    colonyfile$fathers<-matrix(nrow=1,ncol=1)
+    colonyfile$fathersPATH = NA
+    colonyfile$fathers = matrix(nrow = 1, ncol = 1)
   }
   
   #######################################################
   #MOTHERS - probability of inclusion in candidate set
   #######################################################
-  while(length(colonyfile$motherprob)==0){
+  while(length(colonyfile$motherprob) == 0){
     cat("What is the probability that the MOTHER of an offpring is included in the candidate set?\n\n\n E.g. 0.5\n\n\n")
-    colonyfile$motherprob<-as.numeric(scan(n=1,what="integer"))
-    if(colonyfile$motherprob>1){
+    colonyfile$motherprob = as.numeric(scan(n = 1, what = "integer"))
+    if(colonyfile$motherprob > 1){
       flush.console()
       cat("Probabilities must be less than or equal to 1.\n")
-      colonyfile<-colonyfile[which(names(colonyfile)!="motherprob")]}
+      colonyfile = colonyfile[which(names(colonyfile) != "motherprob")]
+    }
   }
   
   #######################################################
-  #Number of candidate mothers
+  #MOTHERS - Number of candidate mothers
   #######################################################
-  while(length(colonyfile$n.mother)==0){
+  while(length(colonyfile$n.mother) == 0){
     cat("How many candidate MOTHERS are there?\n\n\n")
-    colonyfile$n.mother<-as.numeric(scan(n=1,what="integer"))
+    colonyfile$n.mother = as.numeric(scan(n = 1, what = "integer"))
     
-    
-    if(length(colonyfile$n.mother)!=0){
+    if(length(colonyfile$n.mother) != 0){
+
       #Whole number warning 
-      if(is.whole(colonyfile$n.mother)==FALSE){
+      if(is.whole(colonyfile$n.mother) == FALSE){
         flush.console()
-        colonyfile<-colonyfile[which(names(colonyfile)!="n.mothers")]
-        ;warning("The number of mothers must be a whole number!\n",immediate.=TRUE)}}
+        colonyfile = colonyfile[which(names(colonyfile) != "n.mothers")]
+        warning("The number of mothers must be a whole number!\n", immediate. = TRUE)
+      }
+    }
   }
   
   #######################################################
-  #Import candidate MOTHERS
+  #MOTHERS - Import candidate MOTHERS
   #######################################################
-  if(colonyfile$n.mother!=0){
-    while(length(colonyfile$mothersPATH)==0){
+  if(colonyfile$n.mother != 0){
+    while(length(colonyfile$mothersPATH) == 0){
       cat("Provide the path to the candidate MOTHERS file.\n\n\n")
-      flush.console()
-      colonyfile$mothersPATH<-file.choose()
       
       flush.console()
+      colonyfile$mothersPATH = file.choose()
+      flush.console()
       
-      colonyfile$mothers<-read.table(colonyfile$mothersPATH,header=FALSE,sep=delim,colClasses=c("character")) 
-      if(colonyfile$n.mother!=dim(colonyfile$mothers)[1]){colonyfile<-colonyfile[which(names(colonyfile)!="mothersPATH")];
-                                                          flush.console();
-                                                          warning(paste("The number of defined MOTHERS ","(", colonyfile$n.mother,") does not equal the number of MOTHERS provided in the file selected (", dim(colonyfile$mothers)[1],").\n\n",sep=""),immediate.=TRUE)}
+      colonyfile$mothers = read.table(colonyfile$mothersPATH, header = FALSE, sep = delim, colClasses = c("character"))
+      
+      if(colonyfile$n.mother != dim(colonyfile$mothers)[1]){
+        colonyfile = colonyfile[which(names(colonyfile) != "mothersPATH")]
+        
+        flush.console()
+        warning(paste("The number of defined MOTHERS ", "(", colonyfile$n.mother, ") does not equal the number of MOTHERS provided in the file selected (", dim(colonyfile$mothers)[1], ").\n\n", sep = ""), immediate. = TRUE)
+      }
     }
   }else{
-    colonyfile$mothersPATH<-NA
-    colonyfile$mothers<-matrix(nrow=1,ncol=1)
+    colonyfile$mothersPATH = NA
+    colonyfile$mothers = matrix(nrow=1, ncol = 1)
   }
   
-  write(paste(colonyfile$fatherprob,colonyfile$motherprob,"!Probabilities that the father and mother of an offspring included in candidates"),name,append=TRUE)
-  write(paste(colonyfile$n.father,colonyfile$n.mother,"!Numbers of candidate males and females"),name,append=TRUE)
-  write("",name,append=TRUE)
+  write(paste(colonyfile$fatherprob, colonyfile$motherprob, "!Probabilities that the father and mother of an offspring included in candidates"), name, append = TRUE)
+
+  write(paste(colonyfile$n.father, colonyfile$n.mother, "!Numbers of candidate males and females"), name, append = TRUE)
+
+  write("", name, append = TRUE)
   
-  if(colonyfile$n.father!=0){
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rcolony -r 77


More information about the Rcolony-commits mailing list