Fixed behavior of testaaGenePopData
This commit is contained in:
parent
ce3c3b7645
commit
ba1573ad59
2 changed files with 22 additions and 18 deletions
|
|
@ -147,8 +147,8 @@ greedyMix <- function(
|
||||||
# fprintf(1,'Data: %s\n',[pathname filename]);
|
# fprintf(1,'Data: %s\n',[pathname filename]);
|
||||||
# end
|
# end
|
||||||
|
|
||||||
kunnossa <- testaaGenePopData(pathname_filename)
|
kunnossa <- testaaGenePopData(filename_pathname)
|
||||||
# if (kunnossa == 0) stop("testaaGenePopData returned 0")
|
if (kunnossa == 0) stop("testaaGenePopData returned 0")
|
||||||
# [data,popnames]=lueGenePopData([pathname filename]); # TODO: trans
|
# [data,popnames]=lueGenePopData([pathname filename]); # TODO: trans
|
||||||
|
|
||||||
# h0 = findobj('Tag','filename1_text');
|
# h0 = findobj('Tag','filename1_text');
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
#' @title Tests GenePop data
|
#' @title Tests GenePop data
|
||||||
#' @param tiedostonNimi Filename
|
#' @param tiedostonNimi Filename
|
||||||
|
#' @return kunnossa (binary "ok" condition value) == 0 if the data is not valid genePop data. Otherwise, kunnossa == 1.
|
||||||
|
#' @details GenePop data are textfiles that follow the GenePop format. This function checks if such file is properly formatted as GenePop.
|
||||||
testaaGenePopData <- function(tiedostonNimi) {
|
testaaGenePopData <- function(tiedostonNimi) {
|
||||||
# kunnossa == 0, jos data ei ole kelvollinen genePop data.
|
# kunnossa == 0, jos data ei ole kelvollinen genePop data.
|
||||||
# Muussa tapauksessa kunnossa == 1.
|
# Muussa tapauksessa kunnossa == 1.
|
||||||
|
|
||||||
kunnossa <- 0
|
kunnossa <- 0
|
||||||
if (file.exists(paste0(tiedostonNimi, ".rda"))) {
|
if (file.exists(tiedostonNimi)) {
|
||||||
fid <- load(tiedostonNimi)
|
fid <- readLines(tiedostonNimi)
|
||||||
line1 <- readLines(fid)[1] # ensimmäinen rivi
|
line1 <- fid[1] # ensimmäinen rivi
|
||||||
line2 <- readLines(fid)[2] # toinen rivi
|
line2 <- fid[2] # toinen rivi
|
||||||
line3 <- readLines(fid)[3] # kolmas
|
line3 <- fid[3] # kolmas
|
||||||
} else {
|
} else {
|
||||||
fid <- line1 <- line2 <- line3 <- -1
|
fid <- line1 <- line2 <- line3 <- -1
|
||||||
}
|
}
|
||||||
|
|
@ -21,41 +23,43 @@ testaaGenePopData <- function(tiedostonNimi) {
|
||||||
stop('Incorrect file format 1172')
|
stop('Incorrect file format 1172')
|
||||||
}
|
}
|
||||||
if (testaaPop(line3) == 1) {
|
if (testaaPop(line3) == 1) {
|
||||||
# 2 rivi t<>ll<6C>in lokusrivi
|
# 2 rivi t<>ll<6C>in lokusrivi (2 rows then locus row)
|
||||||
nloci <- rivinSisaltamienMjonojenLkm(line2) # TODO: translate function
|
nloci <- rivinSisaltamienMjonojenLkm(line2)
|
||||||
line4 <- readLines(fid)[4]
|
line4 <- fid[4]
|
||||||
if (line4 == -1) stop('Incorrect file format 1180')
|
if (line4 == -1) stop('Incorrect file format 1180')
|
||||||
if (!grepl(',', line4)) {
|
if (!grepl(',', line4)) {
|
||||||
# Rivin nelj?t<>ytyy sis<69>lt<6C><74> pilkku.
|
# Rivin nelj?t<>ytyy sis<69>lt<6C><74> pilkku.
|
||||||
stop('Incorrect file format 1185')
|
stop('Incorrect file format 1185')
|
||||||
}
|
}
|
||||||
pointer <- 1
|
pointer <- 1
|
||||||
while (line4[pointer] != ',') { # Tiedet<65><74>n, ett?pys<79>htyy
|
while (substring(line4, pointer, pointer) != ',') {
|
||||||
|
# Tiedet<65><74>n, ett?pys<79>htyy
|
||||||
pointer <- pointer + 1
|
pointer <- pointer + 1
|
||||||
}
|
}
|
||||||
line4 <- line4[(pointer + 1):nchar(line4)] # pilkun j<>lkeinen osa
|
line4 <- substring(line4, pointer + 1) # pilkun j<>lkeinen osa (the part after the comma)
|
||||||
nloci2 <- rivinSisaltamienMjonojenLkm(line4)
|
nloci2 <- rivinSisaltamienMjonojenLkm(line4)
|
||||||
if (nloci2 != nloci) stop('Incorrect file format 1195')
|
if (nloci2 != nloci) stop('Incorrect file format 1195')
|
||||||
} else {
|
} else {
|
||||||
line <- readLines(fid)[4]
|
line <- fid[4]
|
||||||
lineNumb <- 4
|
lineNumb <- 4
|
||||||
while (testaaPop(line) != 1 & line != -1) {
|
while (testaaPop(line) != 1 & line != -1) {
|
||||||
line <- readLines(fid)[lineNumb]
|
line <- fid[lineNumb + 1]
|
||||||
lineNumb <- lineNumb + 1
|
lineNumb <- lineNumb + 1
|
||||||
}
|
}
|
||||||
if (line == -1) stop('Incorrect file format 1206')
|
if (line == -1) stop('Incorrect file format 1206')
|
||||||
nloci <- lineNumb - 2
|
nloci <- lineNumb - 2
|
||||||
line4 <- readLines(fid)[4] # Eka rivi pop sanan j<>lkeen
|
line4 <- fid[lineNumb + 1] # Eka rivi pop sanan j<>lkeen
|
||||||
if (line4 == -1) stop('Incorrect file format 1212')
|
if (line4 == -1) stop('Incorrect file format 1212')
|
||||||
if (!grepl(',', line4)) {
|
if (!grepl(',', line4)) {
|
||||||
# Rivin t<>ytyy sis<69>lt<6C><74> pilkku.
|
# Rivin t<>ytyy sis<69>lt<6C><74> pilkku. (The line must contain a comma)
|
||||||
stop('Incorrect file format 1217')
|
stop('Incorrect file format 1217')
|
||||||
}
|
}
|
||||||
pointer <- 1
|
pointer <- 1
|
||||||
while (line4[pointer] != ',') { # Tiedet<65><74>n, ett?pys<79>htyy
|
while (substring(line4, pointer, pointer) != ',') {
|
||||||
|
# Tiedet<65><74>n, ett?pys<79>htyy
|
||||||
pointer <- pointer + 1
|
pointer <- pointer + 1
|
||||||
}
|
}
|
||||||
line4 <- line4[(pointer + 1):nchar(line4)] # pilkun j<>lkeinen osa
|
line4 <- substring(line4, pointer + 1) # pilkun j<>lkeinen osa (the part after the comma)
|
||||||
nloci2 <- rivinSisaltamienMjonojenLkm(line4)
|
nloci2 <- rivinSisaltamienMjonojenLkm(line4)
|
||||||
if (nloci2 != nloci) stop('Incorrect file format 1228')
|
if (nloci2 != nloci) stop('Incorrect file format 1228')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue