diff --git a/NAMESPACE b/NAMESPACE index 903031d..d478d16 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,14 +21,18 @@ export(questdlg) export(rand) export(randdir) export(repmat) +export(rivinSisaltamienMjonojenLkm) export(simulateAllFreqs) export(simulateIndividuals) export(simuloiAlleeli) 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 39c99ac..bf13b4f 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 } @@ -62,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'); @@ -1542,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? @@ -1706,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/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/R/testaaGenePopData.R b/R/testaaGenePopData.R index 4540493..7b3810d 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. @@ -16,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 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/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 +} 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/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 +} 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