Merge branch 'testaaGenePopData' into dev

This commit is contained in:
Waldir Leoncio 2020-06-24 12:13:09 +02:00
commit 16ecea429c
11 changed files with 134 additions and 54 deletions

View file

@ -21,14 +21,18 @@ export(questdlg)
export(rand) export(rand)
export(randdir) export(randdir)
export(repmat) export(repmat)
export(rivinSisaltamienMjonojenLkm)
export(simulateAllFreqs) export(simulateAllFreqs)
export(simulateIndividuals) export(simulateIndividuals)
export(simuloiAlleeli) export(simuloiAlleeli)
export(size) export(size)
export(strcmp) export(strcmp)
export(suoritaMuutos) export(suoritaMuutos)
export(testaaOnkoKunnollinenBapsData)
export(testaaPop)
export(times) export(times)
export(uigetfile) export(uigetfile)
export(uiputfile) export(uiputfile)
importFrom(methods,is) importFrom(methods,is)
importFrom(stats,runif) importFrom(stats,runif)
importFrom(utils,read.delim)

View file

@ -1,7 +1,9 @@
#' @title Clustering of individuals #' @title Clustering of individuals
#' @param tietue Record #' @param tietue File
#' @param format Format of the data ("BAPS", "GenePop" or "Preprocessed") #' @param format Format of the data ("BAPS", "GenePop" or "Preprocessed")
#' @param savePreProcessed Save the pre-processed data? #' @param savePreProcessed Save the pre-processed data?
#' @param filePreProcessed Is the file already processed?
#' @importFrom utils read.delim
#' @export #' @export
greedyMix <- function( greedyMix <- function(
tietue, tietue,
@ -51,7 +53,9 @@ greedyMix <- function(
stop('Invalid alternative') stop('Invalid alternative')
} else if (input_type_name == 'BAPS-format') { } else if (input_type_name == 'BAPS-format') {
if (!is(tietue, "character")) { if (!is(tietue, "character")) {
pathname_filename <- uigetfile("*.txt", "Loaddata in BAPS-format") pathname_filename <- uigetfile(
"*.txt", "Load data in BAPS-format"
)
} else { } else {
pathname_filename <- tietue pathname_filename <- tietue
} }
@ -62,8 +66,8 @@ greedyMix <- function(
# end # end
data <- read.delim(pathname_filename) # ASK: what is the delimiter? data <- read.delim(pathname_filename) # ASK: what is the delimiter?
# ninds <- testaaOnkoKunnollinenBapsData(data) #TESTAUS # TODO: trans ninds <- testaaOnkoKunnollinenBapsData(data) # testing
# if (ninds == 0) stop('Incorrect Data-file') if (ninds == 0) stop('Incorrect Data-file')
# ASK: remove? # ASK: remove?
# h0 = findobj('Tag','filename1_text'); # h0 = findobj('Tag','filename1_text');
@ -1542,30 +1546,6 @@ greedyMix <- function(
# %------------------------------------------------------- # %-------------------------------------------------------
# function pal = testaaPop(rivi)
# % pal=1, mik<69>li rivi alkaa jollain seuraavista
# % kirjainyhdistelmist? Pop, pop, POP. Kaikissa muissa
# % tapauksissa pal=0.
# if length(rivi)<3
# pal = 0;
# return
# end
# if (all(rivi(1:3)=='Pop') | ...
# all(rivi(1:3)=='pop') | ...
# all(rivi(1:3)=='POP'))
# pal = 1;
# return
# else
# pal = 0;
# return
# end
# %----------------------------------------------------------------------------
# function dist2 = laskeOsaDist(inds2, dist, ninds) # function dist2 = laskeOsaDist(inds2, dist, ninds)
# % Muodostaa dist vektorista osavektorin, joka sis<69>lt<6C><74> yksil<69>iden inds2 # % Muodostaa dist vektorista osavektorin, joka sis<69>lt<6C><74> yksil<69>iden inds2
# % v<>liset et<65>isyydet. ninds=kaikkien yksil<69>iden lukum<75><6D>r? # % v<>liset et<65>isyydet. ninds=kaikkien yksil<69>iden lukum<75><6D>r?
@ -1706,30 +1686,6 @@ greedyMix <- function(
# %------------------------------------------------------ # %------------------------------------------------------
# function count = rivinSisaltamienMjonojenLkm(line)
# % Palauttaa line:n sis<69>lt<6C>mien mjonojen lukum<75><6D>r<EFBFBD>n.
# % Mjonojen v<>liss?t<>ytyy olla v<>lily<6C>nti.
# count = 0;
# pit = length(line);
# tila = 0; %0, jos odotetaan v<>lily<6C>ntej? 1 jos odotetaan muita merkkej?
# for i=1:pit
# merkki = line(i);
# if (isspace(merkki) & tila==0)
# %Ei tehd?mit<69><74>n.
# elseif (isspace(merkki) & tila==1)
# tila = 0;
# elseif (~isspace(merkki) & tila==0)
# tila = 1;
# count = count+1;
# elseif (~isspace(merkki) & tila==1)
# %Ei tehd?mit<69><74>n
# end
# end
# %-------------------------------------------------------
# function nimi = lueNimi(line) # function nimi = lueNimi(line)
# %Palauttaa line:n alusta sen osan, joka on ennen pilkkua. # %Palauttaa line:n alusta sen osan, joka on ennen pilkkua.
# n = 1; # n = 1;

View file

@ -0,0 +1,25 @@
#' @title Number of M queues
#' @param line line number
#' @return count
#' @export
rivinSisaltamienMjonojenLkm <- function(line) {
# Palauttaa line:n sis<69>lt<6C>mien mjonojen lukum<75><6D>r<EFBFBD>n.
# Mjonojen v<>liss?t<>ytyy olla v<>lily<6C>nti.
count <- 0
pit <- length(line)
tila <- 0 # 0, jos odotetaan v<>lily<6C>ntej? 1 jos odotetaan muita merkkej?
for (i in seq_len(pit)) {
merkki <- line[i]
if (merkki == " " & tila == 0) {
# Ei tehd?mit<69><74>n.
} else if (merkki == " " & tila == 1) {
tila <- 0
} else if (merkki != " " & tila == 0) {
tila <- 1
count <- count + 1
} else if (merkki != " " & tila == 1) {
# %Ei tehd?mit<69><74>n
}
}
return(count)
}

View file

@ -1,4 +1,5 @@
#' @title Tests GenePop data #' @title Tests GenePop data
#' @param tiedostonNimi Filename
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.
@ -16,7 +17,7 @@ testaaGenePopData <- function(tiedostonNimi) {
if (line1 == -1 | line2 == -1 | line3 == -1) { if (line1 == -1 | line2 == -1 | line3 == -1) {
stop('Incorrect file format 1168') stop('Incorrect file format 1168')
} }
if (testaaPop(line1) == 1 | testaaPop(line2) == 1) { # TODO: translate function if (testaaPop(line1) == 1 | testaaPop(line2) == 1) {
stop('Incorrect file format 1172') stop('Incorrect file format 1172')
} }
if (testaaPop(line3) == 1) { if (testaaPop(line3) == 1) {

27
R/testaaPop.R Normal file
View file

@ -0,0 +1,27 @@
#' @title Test population
#' @description Test a line in the population
#' @param rivi Line
#' @return pal
#' @export
testaaPop <- function(rivi) {
# pal=1, mik<69>li rivi alkaa jollain seuraavista
# kirjainyhdistelmist? Pop, pop, POP. Kaikissa muissa
# tapauksissa pal=0.
if (length(rivi) < 3) {
pal <- 0
return(pal)
}
if (
all(rivi[1:3] == 'Pop') |
all(rivi[1:3] == 'pop') |
all(rivi(1:3)=='POP')
) {
pal <- 1
return(pal)
} else {
pal <- 0;
return(pal)
}
return(pal)
}

View file

@ -12,11 +12,13 @@ greedyMix(
) )
} }
\arguments{ \arguments{
\item{tietue}{Record} \item{tietue}{File}
\item{format}{Format of the data ("BAPS", "GenePop" or "Preprocessed")} \item{format}{Format of the data ("BAPS", "GenePop" or "Preprocessed")}
\item{savePreProcessed}{Save the pre-processed data?} \item{savePreProcessed}{Save the pre-processed data?}
\item{filePreProcessed}{Is the file already processed?}
} }
\description{ \description{
Clustering of individuals Clustering of individuals

View file

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rivinSisaltamienMjonojenLkm.R
\name{rivinSisaltamienMjonojenLkm}
\alias{rivinSisaltamienMjonojenLkm}
\title{Number of M queues}
\usage{
rivinSisaltamienMjonojenLkm(line)
}
\arguments{
\item{line}{line number}
}
\value{
count
}
\description{
Number of M queues
}

View file

@ -6,6 +6,9 @@
\usage{ \usage{
testaaGenePopData(tiedostonNimi) testaaGenePopData(tiedostonNimi)
} }
\arguments{
\item{tiedostonNimi}{Filename}
}
\description{ \description{
Tests GenePop data Tests GenePop data
} }

View file

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/testaaOnkoKunnollinenBapsData.R
\name{testaaOnkoKunnollinenBapsData}
\alias{testaaOnkoKunnollinenBapsData}
\title{TestBAPS data}
\usage{
testaaOnkoKunnollinenBapsData(data)
}
\arguments{
\item{data}{dataset}
}
\value{
ninds
}
\description{
Test if loaded BAPS data is proper
}

17
man/testaaPop.Rd Normal file
View file

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/testaaPop.R
\name{testaaPop}
\alias{testaaPop}
\title{Test population}
\usage{
testaaPop(rivi)
}
\arguments{
\item{rivi}{Line}
}
\value{
pal
}
\description{
Test a line in the population
}

View file

@ -0,0 +1,11 @@
# library(devtools)#TEMP
# library(testthat)#TEMP
# library(rBAPS)#TEMP
context("Opening files on greedyMix")
# greedyMix(
# tietue = "data/ExamplesDataFormatting/Example baseline data in GENEPOP format for Trained clustering.txt",
# format = "GenePop",
# savePreProcessed = FALSE
# )