Added testaaGenePopData function
This commit is contained in:
parent
3fcd4affcb
commit
8a4b2d8fc3
3 changed files with 74 additions and 81 deletions
|
|
@ -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<6D>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<6C>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<69>lt<6C><74> pilkku.
|
||||
# disp('Incorrect file format 1185'); fclose(fid);
|
||||
# return
|
||||
# end
|
||||
# pointer = 1;
|
||||
# while ~isequal(line4(pointer),',') %Tiedet<65><74>n, ett?pys<79>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<69>lt<6C><74> pilkku.
|
||||
# disp('Incorrect file format 1217'); fclose(fid);
|
||||
# return
|
||||
# end
|
||||
# pointer = 1;
|
||||
# while ~isequal(line4(pointer),',') %Tiedet<65><74>n, ett?pys<79>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);
|
||||
|
||||
# %------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
|||
63
R/testaaGenePopData.R
Normal file
63
R/testaaGenePopData.R
Normal file
|
|
@ -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<6C>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<69>lt<6C><74> pilkku.
|
||||
stop('Incorrect file format 1185')
|
||||
}
|
||||
pointer <- 1
|
||||
while (line4[pointer] != ',') { # Tiedet<65><74>n, ett?pys<79>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<69>lt<6C><74> pilkku.
|
||||
stop('Incorrect file format 1217')
|
||||
}
|
||||
pointer <- 1
|
||||
while (line4[pointer] != ',') { # Tiedet<65><74>n, ett?pys<79>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)
|
||||
}
|
||||
11
man/testaaGenePopData.Rd
Normal file
11
man/testaaGenePopData.Rd
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue