# Remove all columns from a PHYLIP-formatted dataset that include only 0's or that include any ?'s # Make sure that the length of taxon labels is correct in the first line below # Note that the code only copies the header as is; you have to manually revise the number of characters in the new file # Andrew Hipp (ahipp@mortonarb.org), 4 July 2005 removeZeros <- function() { labelLength = 10 NexusIn <- readLines(choose.files(default = "", caption = "Input PHYLIP-formatted RFLP data file", multi = FALSE), n = -1) NexusOut = new("character") NexusOut[1] = NexusIn[1] for (i in 2:length(NexusIn)) { NexusOut[i] = substr(NexusIn[i],1,labelLength) } numberOfTaxa = length(NexusIn) - 1 for (i in (1 + labelLength):nchar(NexusIn[2])) { if (is.na(sum(as.integer(substr(NexusIn[2:length(NexusIn)],i,i))))) {print(paste("Found ambiguities in character",i - labelLength))} else if (sum(as.integer(substr(NexusIn[2:length(NexusIn)],i,i))) != 0) { print(paste("Included character",i - labelLength)) for (j in 2:length(NexusIn)) { NexusOut[j] = paste(NexusOut[j], substr(NexusIn[j],i,i), sep = "") }}} writeLines(NexusOut, file.choose()) return(NexusOut) }