From 6b36b5c843ddb3b325aa49970be1fe622798cae5 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 24 Jun 2020 11:48:23 +0200 Subject: [PATCH 1/5] Improved documentation --- NAMESPACE | 1 + R/greedyMix.R | 8 ++++++-- R/testaaGenePopData.R | 1 + man/greedyMix.Rd | 4 +++- man/testaaGenePopData.Rd | 3 +++ man/testaaOnkoKunnollinenBapsData.Rd | 17 +++++++++++++++++ tests/testthat/test.greedyMix.R | 11 +++++++++++ 7 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 man/testaaOnkoKunnollinenBapsData.Rd create mode 100644 tests/testthat/test.greedyMix.R diff --git a/NAMESPACE b/NAMESPACE index 903031d..c9f3172 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,7 @@ export(simuloiAlleeli) export(size) export(strcmp) export(suoritaMuutos) +export(testaaOnkoKunnollinenBapsData) export(times) export(uigetfile) export(uiputfile) diff --git a/R/greedyMix.R b/R/greedyMix.R index 39c99ac..fa88ff1 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -1,7 +1,9 @@ #' @title Clustering of individuals -#' @param tietue Record +#' @param tietue File #' @param format Format of the data ("BAPS", "GenePop" or "Preprocessed") #' @param savePreProcessed Save the pre-processed data? +#' @param filePreProcessed Is the file already processed? +#' @importFrom utils read.delim #' @export greedyMix <- function( tietue, @@ -51,7 +53,9 @@ greedyMix <- function( stop('Invalid alternative') } else if (input_type_name == 'BAPS-format') { if (!is(tietue, "character")) { - pathname_filename <- uigetfile("*.txt", "Loaddata in BAPS-format") + pathname_filename <- uigetfile( + "*.txt", "Load data in BAPS-format" + ) } else { pathname_filename <- tietue } diff --git a/R/testaaGenePopData.R b/R/testaaGenePopData.R index 4540493..5654dcf 100644 --- a/R/testaaGenePopData.R +++ b/R/testaaGenePopData.R @@ -1,4 +1,5 @@ #' @title Tests GenePop data +#' @param tiedostonNimi Filename testaaGenePopData <- function(tiedostonNimi) { # kunnossa == 0, jos data ei ole kelvollinen genePop data. # Muussa tapauksessa kunnossa == 1. diff --git a/man/greedyMix.Rd b/man/greedyMix.Rd index 8909046..b8a04cb 100644 --- a/man/greedyMix.Rd +++ b/man/greedyMix.Rd @@ -12,11 +12,13 @@ greedyMix( ) } \arguments{ -\item{tietue}{Record} +\item{tietue}{File} \item{format}{Format of the data ("BAPS", "GenePop" or "Preprocessed")} \item{savePreProcessed}{Save the pre-processed data?} + +\item{filePreProcessed}{Is the file already processed?} } \description{ Clustering of individuals diff --git a/man/testaaGenePopData.Rd b/man/testaaGenePopData.Rd index 167b33c..1f8864d 100644 --- a/man/testaaGenePopData.Rd +++ b/man/testaaGenePopData.Rd @@ -6,6 +6,9 @@ \usage{ testaaGenePopData(tiedostonNimi) } +\arguments{ +\item{tiedostonNimi}{Filename} +} \description{ Tests GenePop data } diff --git a/man/testaaOnkoKunnollinenBapsData.Rd b/man/testaaOnkoKunnollinenBapsData.Rd new file mode 100644 index 0000000..1dc5d51 --- /dev/null +++ b/man/testaaOnkoKunnollinenBapsData.Rd @@ -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 +} diff --git a/tests/testthat/test.greedyMix.R b/tests/testthat/test.greedyMix.R new file mode 100644 index 0000000..18e72e7 --- /dev/null +++ b/tests/testthat/test.greedyMix.R @@ -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 +# ) \ No newline at end of file From eebe7a76352af3eeab00ec87e5eb630ed5d4ae45 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 24 Jun 2020 11:49:16 +0200 Subject: [PATCH 2/5] Enabled testaaOnkoKunnollinenBapsData --- R/greedyMix.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/greedyMix.R b/R/greedyMix.R index fa88ff1..9323899 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -66,8 +66,8 @@ greedyMix <- function( # end data <- read.delim(pathname_filename) # ASK: what is the delimiter? - # ninds <- testaaOnkoKunnollinenBapsData(data) #TESTAUS # TODO: trans - # if (ninds == 0) stop('Incorrect Data-file') + ninds <- testaaOnkoKunnollinenBapsData(data) # testing + if (ninds == 0) stop('Incorrect Data-file') # ASK: remove? # h0 = findobj('Tag','filename1_text'); From 156b0c58b3c24a136450f6a3b94e4ac1563bd594 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 24 Jun 2020 11:49:29 +0200 Subject: [PATCH 3/5] Translated testaaPop --- R/greedyMix.R | 24 ------------------------ R/testaaGenePopData.R | 2 +- R/testaaPop.R | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 R/testaaPop.R diff --git a/R/greedyMix.R b/R/greedyMix.R index 9323899..4445e4b 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -1546,30 +1546,6 @@ greedyMix <- function( # %------------------------------------------------------- -# function pal = testaaPop(rivi) -# % pal=1, mik�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) # % Muodostaa dist vektorista osavektorin, joka sis�lt�� yksil�iden inds2 # % v�liset et�isyydet. ninds=kaikkien yksil�iden lukum��r? diff --git a/R/testaaGenePopData.R b/R/testaaGenePopData.R index 5654dcf..7b3810d 100644 --- a/R/testaaGenePopData.R +++ b/R/testaaGenePopData.R @@ -17,7 +17,7 @@ testaaGenePopData <- function(tiedostonNimi) { if (line1 == -1 | line2 == -1 | line3 == -1) { 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') } if (testaaPop(line3) == 1) { diff --git a/R/testaaPop.R b/R/testaaPop.R new file mode 100644 index 0000000..37040fe --- /dev/null +++ b/R/testaaPop.R @@ -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�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) +} \ No newline at end of file From eb14afae8aaa6dd024dd20c6bfc661e61b7ff453 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 24 Jun 2020 12:11:54 +0200 Subject: [PATCH 4/5] Translated rivinSisaltamienMjonojenLkm --- R/rivinSisaltamienMjonojenLkm.R | 25 +++++++++++++++++++++++++ man/rivinSisaltamienMjonojenLkm.Rd | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 R/rivinSisaltamienMjonojenLkm.R create mode 100644 man/rivinSisaltamienMjonojenLkm.Rd diff --git a/R/rivinSisaltamienMjonojenLkm.R b/R/rivinSisaltamienMjonojenLkm.R new file mode 100644 index 0000000..2e8888f --- /dev/null +++ b/R/rivinSisaltamienMjonojenLkm.R @@ -0,0 +1,25 @@ +#' @title Number of M queues +#' @param line line number +#' @return count +#' @export +rivinSisaltamienMjonojenLkm <- function(line) { + # Palauttaa line:n sis�lt�mien mjonojen lukum��r�n. + # Mjonojen v�liss?t�ytyy olla v�lily�nti. + count <- 0 + pit <- length(line) + tila <- 0 # 0, jos odotetaan v�lily�ntej? 1 jos odotetaan muita merkkej? + for (i in seq_len(pit)) { + merkki <- line[i] + if (merkki == " " & tila == 0) { + # Ei tehd?mit��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��n + } + } + return(count) +} \ No newline at end of file diff --git a/man/rivinSisaltamienMjonojenLkm.Rd b/man/rivinSisaltamienMjonojenLkm.Rd new file mode 100644 index 0000000..bb7a547 --- /dev/null +++ b/man/rivinSisaltamienMjonojenLkm.Rd @@ -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 +} From 0e7e2086c6b81bdf3cb1f824acec473f336b6e74 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Wed, 24 Jun 2020 12:12:10 +0200 Subject: [PATCH 5/5] Updated documentation --- NAMESPACE | 3 +++ R/greedyMix.R | 24 ------------------------ man/testaaPop.Rd | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 man/testaaPop.Rd diff --git a/NAMESPACE b/NAMESPACE index c9f3172..d478d16 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,7 @@ export(questdlg) export(rand) export(randdir) export(repmat) +export(rivinSisaltamienMjonojenLkm) export(simulateAllFreqs) export(simulateIndividuals) export(simuloiAlleeli) @@ -28,8 +29,10 @@ export(size) export(strcmp) export(suoritaMuutos) export(testaaOnkoKunnollinenBapsData) +export(testaaPop) export(times) export(uigetfile) export(uiputfile) importFrom(methods,is) importFrom(stats,runif) +importFrom(utils,read.delim) diff --git a/R/greedyMix.R b/R/greedyMix.R index 4445e4b..bf13b4f 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -1686,30 +1686,6 @@ greedyMix <- function( # %------------------------------------------------------ - -# function count = rivinSisaltamienMjonojenLkm(line) -# % Palauttaa line:n sis�lt�mien mjonojen lukum��r�n. -# % Mjonojen v�liss?t�ytyy olla v�lily�nti. -# count = 0; -# pit = length(line); -# tila = 0; %0, jos odotetaan v�lily�ntej? 1 jos odotetaan muita merkkej? -# for i=1:pit -# merkki = line(i); -# if (isspace(merkki) & tila==0) -# %Ei tehd?mit��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��n -# end -# end - - -# %------------------------------------------------------- - # function nimi = lueNimi(line) # %Palauttaa line:n alusta sen osan, joka on ennen pilkkua. # n = 1; diff --git a/man/testaaPop.Rd b/man/testaaPop.Rd new file mode 100644 index 0000000..873dd6a --- /dev/null +++ b/man/testaaPop.Rd @@ -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 +}