[Rcolony-commits] r63 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 10 19:24:32 CEST 2009
Author: jonesor
Date: 2009-08-10 19:24:32 +0200 (Mon, 10 Aug 2009)
New Revision: 63
Modified:
pkg/R/build.colony.input.R
pkg/R/get.colony.data.R
pkg/R/get.interm.data.R
pkg/R/monitor.colony.R
pkg/R/run.colony.R
Log:
Various bug fixes.
Modified: pkg/R/build.colony.input.R
===================================================================
--- pkg/R/build.colony.input.R 2009-08-10 13:39:21 UTC (rev 62)
+++ pkg/R/build.colony.input.R 2009-08-10 17:24:32 UTC (rev 63)
@@ -208,7 +208,7 @@
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(colonyfile$interval,"! I, Monitor interval in Iterate#/Seconds"),name,append=TRUE)}
+write(paste(format(colonyfile$interval,scientific=F),"! I, Monitor interval in Iterate#/Seconds"),name,append=TRUE)}
#######################################################
# ! B, 0/1=Other platform/Windows execution
@@ -618,7 +618,7 @@
#Paternal Dyads
-if(length(colonyfile$paternal.dyads)==0){
+if(dim(colonyfile$paternal.dyads)[1]==0){
write.table("0 !Number of known paternities",name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
write("",name,append=TRUE)}else{
write.table(paste(dim(colonyfile$paternal.dyads)[1],"!Number of known paternities"),name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
@@ -628,7 +628,7 @@
write("",name,append=TRUE)}
#Maternal Dyads
-if(length(colonyfile$maternal.dyads)==0){
+if(dim(colonyfile$maternal.dyads)[1]==0){
write.table("0 !Number of known maternities",name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
write("",name,append=TRUE)}else{
write.table(paste(dim(colonyfile$maternal.dyads)[1],"!Number of known maternities"),name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
@@ -639,7 +639,7 @@
#Paternal sibships
-if(length(colonyfile$paternal.sibships)==0){
+if(dim(colonyfile$paternal.sibships)[1]==0){
write.table("0 !Number of known paternal sibships with unknown fathers",name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
write("",name,append=TRUE)}else{
write.table(paste(dim(colonyfile$paternal.sibships)[1],"!Number of known paternal sibships with unknown fathers "),name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
@@ -648,7 +648,7 @@
#Maternal sibships
-if(length(colonyfile$maternal.sibships)==0){
+if(dim(colonyfile$maternal.sibships)[1]==0){
write.table("0 !Number of known maternal sibships with unknown mothers",name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
write("",name,append=TRUE)}else{
write.table(paste(dim(colonyfile$maternal.sibships)[1],"!Number of known maternal sibships with unknown mothers "),name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
@@ -710,7 +710,7 @@
}
-#Futher checks
+#Further checks
#if this is true, then all offspring in the dyad file are present in the offspring genotype file
if(sum(colonyfile$excluded.paternities$V1%in%colonyfile$Offspring[,1])==length(colonyfile$excluded.paternities$V1)){}else{
colonyfile<-colonyfile[which(names(colonyfile)!="excluded.paternities.PATH")];
@@ -731,7 +731,7 @@
csum<-NULL
for (i in 1:dim(colonyfile$excluded.paternities)[1]){
csum[i]<-length(colonyfile$excluded.paternities[i,][!is.na(colonyfile$excluded.paternities[i,])])}
-colonyfile$excluded.paternities[,1]<-csum
+#colonyfile$excluded.paternities[,1]<-csum
csum<-csum-1
write.table(paste(colonyfile$n.excluded.paternities,"!Number of offspring with known excluded paternity"),name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
@@ -799,6 +799,7 @@
if(colonyfile$n.excluded.maternities>0){#Write ExcludedMaternity.txt file
temp1<-as.data.frame(colonyfile$excluded.maternities)
names(temp1)<-c("OffspringID",paste("ExcludedMotherID",1:(dim(temp1)[2]-1),sep=""))
+
write.table(temp1,"ExcludedMaternity.txt",row.names=FALSE,quote=FALSE,col.names=TRUE)}
#Futher checks
@@ -814,7 +815,7 @@
if(sum(os%in%colonyfile$mothers[,1])==length(os)){}else{
colonyfile<-colonyfile[which(names(colonyfile)!="excluded.maternities.PATH")];
flush.console();
-warning(paste("Fathers in excluded maternities file are not present in the mothers genotype data:",paste(os[which(os%in%colonyfile$mothers[,1]==FALSE)], collapse=", ")),immediate.=TRUE)}
+warning(paste("Mothers in excluded maternities file are not present in the mothers genotype data:",paste(os[which(os%in%colonyfile$mothers[,1]==FALSE)], collapse=", ")),immediate.=TRUE)}
@@ -823,7 +824,7 @@
csum<-NULL
for (i in 1:dim(colonyfile$excluded.maternities)[1]){
csum[i]<-length(colonyfile$excluded.maternities[i,][!is.na(colonyfile$excluded.maternities[i,])])}
-colonyfile$excluded.maternities[,1]<-csum
+#colonyfile$excluded.maternities[,1]<-csum
csum<-csum-1
write.table(paste(colonyfile$n.excluded.maternities,"!Number of offspring with known excluded maternity"),name,append=TRUE,quote=FALSE,row.names=FALSE,col.names=FALSE)
@@ -900,7 +901,6 @@
-#ORJ: The formatting for this needs to be checked with Jinliang.
colonyfile$excluded.paternal.sibships[,1+dim(colonyfile$excluded.paternal.sibships)[2]]<-c("!Size of known excluded paternal sibship, and IDs of excluded offspring in the sibship",rep("",dim(colonyfile$excluded.paternal.sibships)[1]-1))
csum<-NULL
for (i in 1:dim(colonyfile$excluded.paternal.sibships)[1]){
Modified: pkg/R/get.colony.data.R
===================================================================
--- pkg/R/get.colony.data.R 2009-08-10 13:39:21 UTC (rev 62)
+++ pkg/R/get.colony.data.R 2009-08-10 17:24:32 UTC (rev 63)
@@ -15,7 +15,7 @@
#Extract the number of offspring from the dat file. This information is used for error checking later on.
-n<-x[grep("! I, Number of offspring in the sample",x)]
+n<-x[3]
n <- sub("! I, Number of offspring in the sample", "",n)
n <- sub("^[\t\n\f\r ]*", "",n) #remove leading whitespace
n<-as.numeric(gsub("([A-Za-z0-9]*)([!0-9A-Za-z ]*)", "\\1", n, perl=TRUE))
@@ -25,9 +25,15 @@
###################################################
offspring<-x[grep("!Offspring ID and genotypes",x):(grep("!Prob that the dad and mum of an offspring included in candidates",x)-2)] #M for male, F for female
+offspring<-offspring[offspring!=""]
+
fathers<-x[grep("!Candidate M ID and genotypes",x):(grep("!Candidate F ID and genotypes",x)-2)] #M for male, F for female
+fathers<-fathers[fathers!=""]
+
mothers<-x[grep("!Candidate F ID and genotypes",x):(grep("!Number of offspring with known father",x)-3)] #M for male, F for female
+mothers<-mothers[mothers!=""]
+
#remove leading whitespace
offspring <- sub("^[\t\n\f\r ]*", "",offspring) #remove leading whitespace
fathers <- sub("^[\t\n\f\r ]*", "",fathers) #remove leading whitespace
Modified: pkg/R/get.interm.data.R
===================================================================
--- pkg/R/get.interm.data.R 2009-08-10 13:39:21 UTC (rev 62)
+++ pkg/R/get.interm.data.R 2009-08-10 17:24:32 UTC (rev 63)
@@ -16,7 +16,7 @@
return(x.out)}
-outfile<-readLines(paste(datadir,"temp.txt",sep=""))
+outfile<-readLines(paste(datadir,"temp.txt",sep="/"))
Itr<-getval("Itr",outfile)
length(Itr)
Modified: pkg/R/monitor.colony.R
===================================================================
--- pkg/R/monitor.colony.R 2009-08-10 13:39:21 UTC (rev 62)
+++ pkg/R/monitor.colony.R 2009-08-10 17:24:32 UTC (rev 63)
@@ -17,7 +17,7 @@
if(elapsed.t>interv.t){
- fileok<-file.exists(paste(datadir,"temp.txt",sep=""))
+ fileok<-file.exists(paste(datadir,"temp.txt",sep="/"))
if(fileok==TRUE){
if(!is.na(get.interm.data(datadir=datadir,variable=variable,n=n)[1,1])){
@@ -28,9 +28,18 @@
x<-MidResult[,1]
y<-MidResult[,2]
+
+if(last.few==0){
plot(x,y,xlab="",ylab="",type="n")
points(x,y,type="b")
+}else{
+fr<-length(x)-last.few
+if(fr<1){fr<-1}else{}
+plot(x[fr:length(x)],y[fr:length(x)],xlab="",ylab="",type="n")
+points(x[fr:length(x)],y[fr:length(x)],type="b")}
+
+
#add points to show max and min reached till that point
title(xlab="NumIterate",ylab=variable)
@@ -38,12 +47,12 @@
#add routine to delete contents if file is too big.
#50lines?
-tmp<-readLines(paste(datadir,"temp.txt",sep=""))
+tmp<-readLines(paste(datadir,"temp.txt",sep="/"))
n<-50
from<-if(length(tmp)-n>0){length(tmp)-n>0}else{1}
to<-length(tmp)
-write.table(tmp[from:to],file="temp.txt",row.names=FALSE,col.names=FALSE,quote=FALSE)
+write.table(tmp[from:to],file=paste(datadir,"temp.txt",sep="/"),row.names=FALSE,col.names=FALSE,quote=FALSE)
if(showres==TRUE){print(MidResult)}
Modified: pkg/R/run.colony.R
===================================================================
--- pkg/R/run.colony.R 2009-08-10 13:39:21 UTC (rev 62)
+++ pkg/R/run.colony.R 2009-08-10 17:24:32 UTC (rev 63)
@@ -1,8 +1,8 @@
-run.colony<-function(colonyexecpath="prompt",datfilepath="prompt",wait=TRUE,monitor=TRUE){
+run.colony<-function(colonyexecpath="prompt",datfilepath="prompt",wait=FALSE,monitor=TRUE){
#don't forget the trailing slash!
if(colonyexecpath=="prompt"){
-cat("Please click to select your Colony2 executable (probably called Colony2.exe or Colony2.app).\n\n")
+cat("Please click to select your Colony2 executable (probably called Colony2.exe or Colony2).\n\n")
flush.console()
colonyexecpath<-file.choose()}
@@ -30,7 +30,7 @@
if(monitor==TRUE&wait==TRUE){stop("If you want to monitor the output, you must set wait as FALSE. Otherwise you cannot run other functions in the same R console.")}
-cat("Be aware: this may take several minutes, hours, or even weeks to run, depending on the settings.\n")
+cat("Be aware: this may take several minutes, hours, or even weeks to run, depending on the settings used.\n")
platform<-.Platform
if(platform$OS.type=="unix"){
@@ -38,8 +38,9 @@
#Unix/MacOSX commands
#Copy Colony2 program to the working directory
- system(paste("cp",colonyexecpath,datadir,sep=" "))
-
+ if(file.exists("Colony2")==FALSE){
+system(paste("cp",colonyexecpath,datadir,sep=" "))
+ }
#Rename the DAT file as Colony2.DAT (unless it is already called "Colony2.DAT")
if(filename!="Colony2.DAT"){system(paste("mv",paste(datadir,filename,sep=""),paste(datadir,"Colony2.DAT",sep=""),sep=" "))}
@@ -52,11 +53,18 @@
#It is recommended that monitor = TRUE only be used if you will periodically monitor the system, otherwise the text file will grow very large and may burden the system.
#There is currently no way of monitoring the Windows system.
#if(monitor==TRUE){system("./Colony2.exe 2>&1 | tee temp.txt",wait=wait)}else{system("./Colony2.exe",wait=wait)}
+
+cat("#! /bin/sh\necho Running Colony2\nexport G95_MEM_SEGMENTS=0\n./Colony2" , file = paste(datadir,"Colony2.sh",sep=""),append = FALSE)
+
if(monitor==TRUE){system("sh Colony2.sh | tee temp.txt",wait=wait)}else{system("sh Colony2.sh",wait=wait)}
+#if(monitor==TRUE){system("./Colony2 | tee temp.txt",wait=wait)}else{system("./Colony2",wait=wait)}
#Remove the Colony2.exe and
system(paste("rm",colonyexec))
+ #
+ if(file.exists("Colony2.sh")){system(paste("rm Colony2.sh"))}else{}
+
if(filename!="Colony2.DAT"){system("rm Colony2.DAT")}
More information about the Rcolony-commits
mailing list