From 8a4b2d8fc3ddb70a64a98a4be1d2e66b5845de33 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Mon, 8 Jun 2020 15:41:52 +0200 Subject: [PATCH] Added testaaGenePopData function --- R/greedyMix.R | 81 ---------------------------------------- R/testaaGenePopData.R | 63 +++++++++++++++++++++++++++++++ man/testaaGenePopData.Rd | 11 ++++++ 3 files changed, 74 insertions(+), 81 deletions(-) create mode 100644 R/testaaGenePopData.R create mode 100644 man/testaaGenePopData.Rd diff --git a/R/greedyMix.R b/R/greedyMix.R index 5731d9d..201e045 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -1613,87 +1613,6 @@ greedyMix <- function( # emptyPop = min(find(popDiff > 1)); # end -# %-------------------------------------------------------------------- - - -# function kunnossa = testaaGenePopData(tiedostonNimi) -# % kunnossa == 0, jos data ei ole kelvollinen genePop data. -# % Muussa tapauksessa kunnossa == 1. - -# kunnossa = 0; -# fid = fopen(tiedostonNimi); -# line1 = fgetl(fid); %ensimm�inen rivi -# line2 = fgetl(fid); %toinen rivi -# line3 = fgetl(fid); %kolmas - -# if (isequal(line1,-1) | isequal(line2,-1) | isequal(line3,-1)) -# disp('Incorrect file format 1168'); fclose(fid); -# return -# end -# if (testaaPop(line1)==1 | testaaPop(line2)==1) -# disp('Incorrect file format 1172'); fclose(fid); -# return -# end -# if testaaPop(line3)==1 -# %2 rivi t�ll�in lokusrivi -# nloci = rivinSisaltamienMjonojenLkm(line2); -# line4 = fgetl(fid); -# if isequal(line4,-1) -# disp('Incorrect file format 1180'); fclose(fid); -# return -# end -# if ~any(line4==',') -# % Rivin nelj?t�ytyy sis�lt�� pilkku. -# disp('Incorrect file format 1185'); fclose(fid); -# return -# end -# pointer = 1; -# while ~isequal(line4(pointer),',') %Tiedet��n, ett?pys�htyy -# pointer = pointer+1; -# end -# line4 = line4(pointer+1:end); %pilkun j�lkeinen osa -# nloci2 = rivinSisaltamienMjonojenLkm(line4); -# if (nloci2~=nloci) -# disp('Incorrect file format 1195'); fclose(fid); -# return -# end -# else -# line = fgetl(fid); -# lineNumb = 4; -# while (testaaPop(line)~=1 & ~isequal(line,-1)) -# line = fgetl(fid); -# lineNumb = lineNumb+1; -# end -# if isequal(line,-1) -# disp('Incorrect file format 1206'); fclose(fid); -# return -# end -# nloci = lineNumb-2; -# line4 = fgetl(fid); %Eka rivi pop sanan j�lkeen -# if isequal(line4,-1) -# disp('Incorrect file format 1212'); fclose(fid); -# return -# end -# if ~any(line4==',') -# % Rivin t�ytyy sis�lt�� pilkku. -# disp('Incorrect file format 1217'); fclose(fid); -# return -# end -# pointer = 1; -# while ~isequal(line4(pointer),',') %Tiedet��n, ett?pys�htyy. -# pointer = pointer+1; -# end - -# line4 = line4(pointer+1:end); %pilkun j�lkeinen osa -# nloci2 = rivinSisaltamienMjonojenLkm(line4); -# if (nloci2~=nloci) -# disp('Incorrect file format 1228'); fclose(fid); -# return -# end -# end -# kunnossa = 1; -# fclose(fid); - # %------------------------------------------------------ diff --git a/R/testaaGenePopData.R b/R/testaaGenePopData.R new file mode 100644 index 0000000..4540493 --- /dev/null +++ b/R/testaaGenePopData.R @@ -0,0 +1,63 @@ +#' @title Tests GenePop data +testaaGenePopData <- function(tiedostonNimi) { + # kunnossa == 0, jos data ei ole kelvollinen genePop data. + # Muussa tapauksessa kunnossa == 1. + + kunnossa <- 0 + if (file.exists(paste0(tiedostonNimi, ".rda"))) { + fid <- load(tiedostonNimi) + line1 <- readLines(fid)[1] # ensimmäinen rivi + line2 <- readLines(fid)[2] # toinen rivi + line3 <- readLines(fid)[3] # kolmas + } else { + fid <- line1 <- line2 <- line3 <- -1 + } + + if (line1 == -1 | line2 == -1 | line3 == -1) { + stop('Incorrect file format 1168') + } + if (testaaPop(line1) == 1 | testaaPop(line2) == 1) { # TODO: translate function + stop('Incorrect file format 1172') + } + if (testaaPop(line3) == 1) { + # 2 rivi t�ll�in lokusrivi + nloci <- rivinSisaltamienMjonojenLkm(line2) # TODO: translate function + line4 <- readLines(fid)[4] + if (line4 == -1) stop('Incorrect file format 1180') + if (!grepl(',', line4)) { + # Rivin nelj?t�ytyy sis�lt�� pilkku. + stop('Incorrect file format 1185') + } + pointer <- 1 + while (line4[pointer] != ',') { # Tiedet��n, ett?pys�htyy + pointer <- pointer + 1 + } + line4 <- line4[(pointer + 1):nchar(line4)] # pilkun j�lkeinen osa + nloci2 <- rivinSisaltamienMjonojenLkm(line4) + if (nloci2 != nloci) stop('Incorrect file format 1195') + } else { + line <- readLines(fid)[4] + lineNumb <- 4 + while (testaaPop(line) != 1 & line != -1) { + line <- readLines(fid)[lineNumb] + lineNumb <- lineNumb + 1 + } + if (line == -1) stop('Incorrect file format 1206') + nloci <- lineNumb - 2 + line4 <- readLines(fid)[4] # Eka rivi pop sanan j�lkeen + if (line4 == -1) stop('Incorrect file format 1212') + if (!grepl(',', line4)) { + # Rivin t�ytyy sis�lt�� pilkku. + stop('Incorrect file format 1217') + } + pointer <- 1 + while (line4[pointer] != ',') { # Tiedet��n, ett?pys�htyy + pointer <- pointer + 1 + } + line4 <- line4[(pointer + 1):nchar(line4)] # pilkun j�lkeinen osa + nloci2 <- rivinSisaltamienMjonojenLkm(line4) + if (nloci2 != nloci) stop('Incorrect file format 1228') + } + kunnossa <- 1 + return(kunnossa) +} \ No newline at end of file diff --git a/man/testaaGenePopData.Rd b/man/testaaGenePopData.Rd new file mode 100644 index 0000000..167b33c --- /dev/null +++ b/man/testaaGenePopData.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/testaaGenePopData.R +\name{testaaGenePopData} +\alias{testaaGenePopData} +\title{Tests GenePop data} +\usage{ +testaaGenePopData(tiedostonNimi) +} +\description{ +Tests GenePop data +}