From 19e212b1372fedeb8d009e35fa242e0504bf3237 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Thu, 19 Nov 2020 14:29:37 +0100 Subject: [PATCH 1/2] Removed global variables from argument lists --- R/admix1.R | 8 ++------ R/computeAllFreqs2.R | 5 +---- R/computePersonalAllFreqs.R | 6 ++---- R/laskeMuutokset12345.R | 5 +---- R/poistaLiianPienet.R | 7 +------ R/simulateAllFreqs.R | 3 +-- R/suoritaMuutos.R | 3 +-- R/viewPartition.R | 32 ++++++++++++++++---------------- man/admix1.Rd | 13 +------------ man/computeAllFreqs2.Rd | 6 +----- man/computePersonalAllFreqs.Rd | 6 ++---- man/laskeMuutokset4.Rd | 4 +--- man/poistaLiianPienet.Rd | 15 +-------------- man/simulateAllFreqs.Rd | 4 +--- man/suoritaMuutos.Rd | 4 +--- 15 files changed, 33 insertions(+), 88 deletions(-) diff --git a/R/admix1.R b/R/admix1.R index abc24e5..99e5b86 100644 --- a/R/admix1.R +++ b/R/admix1.R @@ -5,13 +5,9 @@ #' `tietue`should contain the following elements: PARTITION, COUNTS, SUMCOUNTS, #' alleleCodes, adjprior, popnames, rowsFromInd, data, npops, noalle #' @param tietue tietue -#' @param PARTITION PARTITION -#' @param COUNTS COUNTS -#' @param SUMCOUNTS SUMCOUNTS #' @importFrom methods is #' @export -admix1 <- function(tietue, PARTITION = matrix(NA, 0, 0), - COUNTS = matrix(NA, 0, 0), SUMCOUNTS = NA) { +admix1 <- function(tietue) { if (!is.list(tietue)) { message('Load mixture result file. These are the files in this directory:') print(list.files()) @@ -270,7 +266,7 @@ admix1 <- function(tietue, PARTITION = matrix(NA, 0, 0), for (level in 1:n_missing_levels[pop]) { - potential_inds_in_this_pop_and_level <- + potential_inds_in_this_pop_and_level <- find( PARTITION == pop & missing_level_partition == level & likelihood > 3 diff --git a/R/computeAllFreqs2.R b/R/computeAllFreqs2.R index 4b87fea..e90d358 100644 --- a/R/computeAllFreqs2.R +++ b/R/computeAllFreqs2.R @@ -2,11 +2,8 @@ #' @description Lisää a priori jokaista alleelia joka populaation joka lokukseen #' j 1/noalle(j) verran. #' @param noalle noalle -#' @param COUNTS counts -#' @param SUMCOUNTS sumcounts #' @export -computeAllFreqs2 <- function (noalle, COUNTS = matrix(NA, 0, 0), - SUMCOUNTS = NA) { +computeAllFreqs2 <- function (noalle) { max_noalle <- size(COUNTS, 1) nloci <- size(COUNTS,2) diff --git a/R/computePersonalAllFreqs.R b/R/computePersonalAllFreqs.R index f0845f6..7ccd4e9 100644 --- a/R/computePersonalAllFreqs.R +++ b/R/computePersonalAllFreqs.R @@ -1,17 +1,15 @@ #' @title Compute Personal Freqs #' @description Laskee npops*(rowsFromInd*nloci) taulukon, jonka kutakin #' saraketta vastaa yksilön ind alleeli. Eri rivit ovat alleelin -#' alkuperäfrekvenssit eri populaatioissa. Jos yksilölt?puuttuu jokin alleeli, +#' alkuperäfrekvenssit eri populaatioissa. Jos yksilölt?puuttuu jokin alleeli, #' niin vastaavaan kohtaa tulee sarake ykkösi? #' @param ind ind #' @param data data #' @param allFreqs allFreqs #' @param rowsFromInd rowsFromInd -#' @param COUNTS COUNTS #' @export -computePersonalAllFreqs <- function(ind, data, allFreqs, rowsFromInd, -COUNTS = matrix(0)) { +computePersonalAllFreqs <- function(ind, data, allFreqs, rowsFromInd) { nloci <- ifelse(is.na(dim(COUNTS)[2]), 1, dim(COUNTS)[2]) npops <- ifelse(is.na(dim(COUNTS)[3]), 1, dim(COUNTS)[3]) diff --git a/R/laskeMuutokset12345.R b/R/laskeMuutokset12345.R index bfb4d59..4d14e0f 100644 --- a/R/laskeMuutokset12345.R +++ b/R/laskeMuutokset12345.R @@ -7,11 +7,8 @@ #' @param omaFreqs own Freqs? #' @param osuusTaulu Percentage table? #' @param logml log maximum likelihood -#' @param COUNTS COUNTS #' @export -laskeMuutokset4 <- function ( - osuus, osuusTaulu, omaFreqs, logml, COUNTS = matrix(0) -) { +laskeMuutokset4 <- function (osuus, osuusTaulu, omaFreqs, logml) { npops <- ifelse(is.na(dim(COUNTS)[3]), 1, dim(COUNTS)[3]) notEmpty <- which(osuusTaulu > 0.005) muutokset <- zeros(npops) diff --git a/R/poistaLiianPienet.R b/R/poistaLiianPienet.R index 19eabea..22ecfac 100644 --- a/R/poistaLiianPienet.R +++ b/R/poistaLiianPienet.R @@ -5,13 +5,8 @@ #' @param npops npops #' @param rowsFromInd rowsFromInd #' @param alaraja alaraja -#' @param PARTITION PARTITION -#' @param COUNTS COUNTS -#' @param SUMCOUNTS SUMCOUNTS #' @export -poistaLiianPienet <- function (npops, rowsFromInd, alaraja, - PARTITION = matrix(NA, 0, 0), COUNTS = matrix(NA, 0, 0), - SUMCOUNTS = NA) { +poistaLiianPienet <- function (npops, rowsFromInd, alaraja) { popSize <- zeros(1,npops) if (npops > 0) { for (i in 1:npops) { diff --git a/R/simulateAllFreqs.R b/R/simulateAllFreqs.R index 81995b4..8097ba3 100644 --- a/R/simulateAllFreqs.R +++ b/R/simulateAllFreqs.R @@ -2,10 +2,9 @@ #' @description Lisää jokaista alleelia joka populaation joka lokukseen j1/noalle(j) verran. Näin saatuja counts:eja vastaavista Dirichlet-jakaumista simuloidaan arvot populaatioiden alleelifrekvensseille. #' Add each allele to each locus in each population by j 1 / noalle(j). The Dirichlet distributions corresponding to the counts thus obtained simulate values for the allele frequencies of the populations. #' @param noalle noalle -#' @param COUNTS COUNTS #' @export -simulateAllFreqs <- function(noalle, COUNTS = matrix(NA, 0, 0)) { +simulateAllFreqs <- function(noalle) { max_noalle <- size(COUNTS, 1) nloci <- size(COUNTS, 2) npops <- size(COUNTS, 3) diff --git a/R/suoritaMuutos.R b/R/suoritaMuutos.R index daa48f9..bb39850 100644 --- a/R/suoritaMuutos.R +++ b/R/suoritaMuutos.R @@ -3,9 +3,8 @@ #' @param osuusTaulu Percentage table? #' @param osuus percentage? #' @param indeksi index -#' @param COUNTS counts #' @export -suoritaMuutos <- function (osuusTaulu, osuus, indeksi, COUNTS = matrix(0)) { +suoritaMuutos <- function (osuusTaulu, osuus, indeksi) { npops <- ifelse(is.na(dim(COUNTS)[3]), 1, dim(COUNTS)[3]) i1 <- indeksi %% npops diff --git a/R/viewPartition.R b/R/viewPartition.R index 80a3b73..b478219 100644 --- a/R/viewPartition.R +++ b/R/viewPartition.R @@ -1,9 +1,9 @@ -viewPartition <- function(osuudet, popnames, COUNTS = matrix(0, 0, 0)) { +viewPartition <- function(osuudet, popnames) { npops <- size(COUNTS, 3) nind <- size(osuudet,1) -# TODO: translate if necessary. Remove if this function won't be used +# TODO: translate if necessary. Remove if this function won't be used # disp(['Number of populations: ' num2str(npops)]); # if npops>30 # disp(' '); @@ -12,27 +12,27 @@ viewPartition <- function(osuudet, popnames, COUNTS = matrix(0, 0, 0)) { # disp(' '); # return; # end - - + + # varit = givecolors(npops); # korkeinviiva = 1.05; # pieninarvo = -korkeinviiva; - - + + # h0 = figure; # set(h0, 'NumberTitle', 'off'); %image_figure; %Muutettu # tiedot.popnames = popnames; # tiedot.info = osuudet; # set(h0,'UserData',tiedot); - + # set(gca, 'Xlim', [-.5 ,nind+.5], 'YLim', [pieninarvo ,korkeinviiva], ... # 'XTick', [], 'XTickLabel', [], 'YTick', [], 'YTickLabel', []); - + # for i=1:nind - + # if any(osuudet(i,:)>0) # cumOsuudet = cumsum(osuudet(i,:)); - + # % Pylv��n piirt�minen # for j=1:npops # if j==1 @@ -50,21 +50,21 @@ viewPartition <- function(osuudet, popnames, COUNTS = matrix(0, 0, 0)) { # end # end # end - - - + + + # if ~isempty(popnames) # npops = size(popnames,1); # for i=1:npops # firstInd = popnames{i,2}; # line([firstInd-1, firstInd-1], [0,1], 'Color', 'k'); %Populaatioiden rajat - + # if i Date: Fri, 11 Dec 2020 12:29:55 +0100 Subject: [PATCH 2/2] Initializing globals (#10) --- R/globals.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/globals.R b/R/globals.R index b994258..2fea390 100644 --- a/R/globals.R +++ b/R/globals.R @@ -1,3 +1,10 @@ +COUNTS <- vector() +SUMCOUNTS <- vector() +PARTITION <- vector() +POP_LOGML <- vector() +LOGDIFF <- vector() + +#' @import utils utils::globalVariables( c("PARTITION", "COUNTS", "SUMCOUNTS", "LOGDIFF", "POP_LOGML", "GAMMA_LN") ) \ No newline at end of file