2020-07-14 13:37:56 +02:00
|
|
|
|
#' @title Initialize Pop Names
|
|
|
|
|
|
#' @param nameFile nameFile
|
|
|
|
|
|
#' @param indexFile indexFile
|
|
|
|
|
|
#' @export
|
|
|
|
|
|
initPopNames <- function(nameFile, indexFile) {
|
2021-11-10 14:02:35 +01:00
|
|
|
|
# Palauttaa tyhj<68>n, mik<69>li nimitiedosto ja indeksitiedosto
|
|
|
|
|
|
# eiv<69>t olleet yht?pitki?
|
2020-07-14 13:37:56 +02:00
|
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
|
indices <- load(indexFile)
|
2020-07-14 13:37:56 +02:00
|
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
|
fid <- load(nameFile)
|
|
|
|
|
|
if (fid == -1) {
|
|
|
|
|
|
# File didn't exist
|
|
|
|
|
|
stop("Loading of the population names was unsuccessful")
|
|
|
|
|
|
}
|
|
|
|
|
|
line <- readLines(fid)[1]
|
|
|
|
|
|
counter <- 1
|
|
|
|
|
|
names <- vector()
|
|
|
|
|
|
while ((line != -1) & (line != "")) {
|
|
|
|
|
|
names[counter] <- line
|
|
|
|
|
|
line <- readLines(fid)[counter]
|
|
|
|
|
|
counter <- counter + 1
|
|
|
|
|
|
}
|
2020-07-14 13:37:56 +02:00
|
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
|
if (length(names) != length(indices)) {
|
|
|
|
|
|
cat("The number of population names must be equal to the number of")
|
|
|
|
|
|
cat("entries in the file specifying indices of the first individuals")
|
|
|
|
|
|
cat("of each population.")
|
|
|
|
|
|
}
|
2020-07-14 13:37:56 +02:00
|
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
|
popnames <- cell(length(names), 2)
|
|
|
|
|
|
for (i in 1:length(names)) {
|
|
|
|
|
|
popnames[i, 1] <- names[i]
|
|
|
|
|
|
popnames[i, 2] <- indices[i]
|
|
|
|
|
|
}
|
|
|
|
|
|
return(popnames)
|
|
|
|
|
|
}
|