"read.npl" <- function(fname="ch12ed.txt",maxpoints=1000,colnum=4, outfile="npl.txt"){ tx <- readLines(fname, n=-1) n1 <- seq(along=tx) len <- length(tx) mn <- sapply(tx, function(x) {as.numeric(length(grep("analyzing pedigree F", x)))}) idrows <- n1[mn>0] firstrows <- idrows+3 z <- sapply(tx[firstrows],function(x)substring(x,1,7)==" 0.00") idrows <- idrows[z] firstrows <- firstrows[z] tf <- min((firstrows[1]:(firstrows[1]+maxpoints)) [tx[firstrows[1]:(firstrows[1]+maxpoints)]==""]) nrows <- tf-firstrows[1] m <- as.numeric(sapply(tx[idrows], function(x)regexpr("F[A-Z][0-9][0-9][0-9]",x))) nam <- sapply(strsplit(tx[idrows],"F"),function(x)x[2]) nam <- sapply(strsplit(nam,"\\."),function(x)x[1]) nam <- paste("F",nam,sep="") seqrows <- unlist(lapply(firstrows,function(x)x:(x+nrows-1))) tx <- tx[seqrows] write.table(tx,quote=F,file="xlods.txt") xy <- read.table("xlods.txt",header=F,skip=1) npl <- t(matrix(xy[,colnum],nrow=nrows)) pos <- t(matrix(xy[,2],nrow=nrows)) poscheck <- apply(pos,2,function(x)any(x!=x[1])) if(any(poscheck))stop("Positions are not identical across families") positions <- pos[1,] dimnames(npl) <- list(nam,paste(positions)) write.table(npl, file=outfile) invisible(npl) }