From 46a9249e5ad7df702c19df9c8f26f6bc65f0adf1 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Thu, 19 Nov 2020 07:53:36 +0100 Subject: [PATCH] Fixed syntax --- NAMESPACE | 2 ++ R/admixture_initialization.R | 4 ++-- R/cluster_own.R | 2 +- R/computeDiffInCounts.R | 4 ++-- R/indMix.R | 16 ++++++++-------- R/initialPopCounts.R | 4 ++-- R/laskeLoggis.R | 2 +- R/laskeOsaDist.R | 8 +++++++- man/laskeOsaDist.Rd | 21 +++++++++++++++++++++ 9 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 man/laskeOsaDist.Rd diff --git a/NAMESPACE b/NAMESPACE index 42b0063..0be8af8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(linkage) export(logml2String) export(lueGenePopData) export(lueNimi) +export(matlab2r) export(noIndex) export(ownNum2Str) export(poistaLiianPienet) @@ -49,3 +50,4 @@ export(writeMixtureInfo) importFrom(methods,is) importFrom(stats,runif) importFrom(utils,read.delim) +importFrom(utils,write.table) diff --git a/R/admixture_initialization.R b/R/admixture_initialization.R index 4d9f6c8..c69dd63 100644 --- a/R/admixture_initialization.R +++ b/R/admixture_initialization.R @@ -6,12 +6,12 @@ admixture_initialization <- function (data_matrix, nclusters, Z) { size_data <- size(data_matrix) nloci <- size_data[2] - 1 - n <- max(data_matrix[, end]) + n <- max(data_matrix[, ncol(data_matrix)]) T <- cluster_own(Z, nclusters) initial_partition <- zeros(size_data[1], 1) for (i in 1:n) { kori <- T[i] - here <- find(data_matrix[,end] == i) + here <- find(data_matrix[, ncol(data_matrix)] == i) for (j in 1:length(here)) { initial_partition[here[j], 1] <- kori } diff --git a/R/cluster_own.R b/R/cluster_own.R index b94b7b8..0d64102 100644 --- a/R/cluster_own.R +++ b/R/cluster_own.R @@ -15,7 +15,7 @@ cluster_own <- function(Z, nclust) { for (k in (m - maxclust + 1):(m - 1)) { i = Z(k, 1) # left tree if (i <= m) { # original node, no leafs - T(i) = clsnum + T[i] = clsnum clsnum = clsnum + 1 } else if (i < (2 * m - maxclust + 1)) { # created before cutoff, search down the tree T <- clusternum(Z, T, i - m, clsnum) diff --git a/R/computeDiffInCounts.R b/R/computeDiffInCounts.R index de19e30..af53f61 100644 --- a/R/computeDiffInCounts.R +++ b/R/computeDiffInCounts.R @@ -9,8 +9,8 @@ computeDiffInCounts <- function(rows, max_noalle, nloci, data) { notEmpty <- find(row>=0) if (length(notEmpty) > 0) { - diffInCounts(row(notEmpty) + (notEmpty - 1) * max_noalle) <- - diffInCounts(row(notEmpty) + (notEmpty - 1) * max_noalle) + 1 + diffInCounts[row(notEmpty) + (notEmpty - 1) * max_noalle] <- + diffInCounts[row(notEmpty) + (notEmpty - 1) * max_noalle] + 1 } } return(diffInCounts) diff --git a/R/indMix.R b/R/indMix.R index 6b11bf9..3fc2359 100644 --- a/R/indMix.R +++ b/R/indMix.R @@ -52,7 +52,7 @@ indMix <- function(c, npops, dispText) { } else { npopsTaulu <- as.numeric(npopstext) ykkoset <- find(npopsTaulu == 1) - npopsTaulu(ykkoset) <- list() # Mik�li ykk�si� annettu yl�rajaksi, ne poistetaan. + npopsTaulu[ykkoset] <- list() # Mik�li ykk�si� annettu yl�rajaksi, ne poistetaan. if (isempty(npopsTaulu)) { logml <- 1 partitionSummary <- 1 @@ -68,7 +68,7 @@ indMix <- function(c, npops, dispText) { nruns <- length(npopsTaulu) initData <- data - data <- data[,1:(end - 1)] + data <- data[,1:(ncol(data) - 1)] logmlBest <- -1e50 partitionSummary <- -1e50 * ones(30, 2) # Tiedot 30 parhaasta partitiosta (npops ja logml) @@ -76,13 +76,13 @@ indMix <- function(c, npops, dispText) { worstLogml <- -1e50 worstIndex <- 1 for (run in 1:nruns) { - npops <- npopsTaulu(run) + npops <- npopsTaulu[run] if (dispText) { dispLine() print( paste0( - 'Run ', num2str(run), '/', num2str(nruns), - ', maximum number of populations ', num2str(npops), '.' + 'Run ', as.character(run), '/', as.character(nruns), + ', maximum number of populations ', as.character(npops), '.' ) ) } @@ -120,7 +120,7 @@ indMix <- function(c, npops, dispText) { print( paste0( 'Mixture analysis started with initial', - num2str(npops), + as.character(npops), 'populations.' ) ) @@ -130,7 +130,7 @@ indMix <- function(c, npops, dispText) { muutoksia <- 0 if (dispText) { - print(paste('Performing steps:', num2str(roundTypes))) + print(paste('Performing steps:', as.character(roundTypes))) } for (n in 1:length(roundTypes)) { @@ -545,7 +545,7 @@ indMix <- function(c, npops, dispText) { npops <- poistaTyhjatPopulaatiot(npops) POP_LOGML <- computePopulationLogml(1:npops, adjprior, priorTerm) if (dispText) { - print(paste('Found partition with', num2str(npops), 'populations.')) + print(paste('Found partition with', as.character(npops), 'populations.')) print(paste('Log(ml) =', as.character(logml))) print(' ') } diff --git a/R/initialPopCounts.R b/R/initialPopCounts.R index 2cb4806..2bd08ed 100644 --- a/R/initialPopCounts.R +++ b/R/initialPopCounts.R @@ -7,11 +7,11 @@ initialPopCounts <- function(data, npops, rows, noalle, adjprior) { for (j in 1:nloci) { i_rivit <- rows(i, 1):rows(i, 2) havainnotLokuksessa <- find(data[i_rivit, j] >= 0) - sumcounts(i, j) <- length(havainnotLokuksessa) + sumcounts[i, j] <- length(havainnotLokuksessa) for (k in 1:noalle[j]) { alleleCode <- k N_ijk <- length(find(data[i_rivit, j] == alleleCode)) - counts(k, j, i) <- N_ijk + counts[k, j, i] <- N_ijk } } } diff --git a/R/laskeLoggis.R b/R/laskeLoggis.R index 7bcd26f..672dec9 100644 --- a/R/laskeLoggis.R +++ b/R/laskeLoggis.R @@ -1,7 +1,7 @@ laskeLoggis <- function(counts, sumcounts, adjprior) { npops <- size(counts, 3) - sum1 <- sum(sum(sum(gammaln(counts + repmat(adjprior, c(1, 1, npops)))))) + sum1 <- sum(sum(sum(lgamma(counts + repmat(adjprior, c(1, 1, npops)))))) sum3 <- sum(sum(lgamma(adjprior))) - sum(sum(lgamma(1 + sumcounts))) logml2 <- sum1 - npops * sum3 loggis <- logml2 diff --git a/R/laskeOsaDist.R b/R/laskeOsaDist.R index 1ea9495..018614d 100644 --- a/R/laskeOsaDist.R +++ b/R/laskeOsaDist.R @@ -1,9 +1,15 @@ +#' @title Lower part of the dist +#' @description Constructs from the dist vector a subvector containing the individual inds2, Forms dist sub-vectors the vector, which includes yksiliden inds2 +#' @param inds2 inds2 +#' @param dist dist +#' @param ninds ninds +#' @author Waldir Leoncio laskeOsaDist <- function(inds2, dist, ninds) { # % Muodostaa dist vektorista osavektorin, joka sis�lt�� yksil�iden inds2 # % v�liset et�isyydet. ninds=kaikkien yksil�iden lukum��r�. ninds2 <- length(inds2) - apu <- zeros(nchoosek(ninds2, 2), 2) + apu <- zeros(choose(ninds2, 2), 2) rivi <- 1 for (i in 1:ninds2-1) { for (j in i+1:ninds2) { diff --git a/man/laskeOsaDist.Rd b/man/laskeOsaDist.Rd new file mode 100644 index 0000000..f577c89 --- /dev/null +++ b/man/laskeOsaDist.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/laskeOsaDist.R +\name{laskeOsaDist} +\alias{laskeOsaDist} +\title{Lower part of the dist} +\usage{ +laskeOsaDist(inds2, dist, ninds) +} +\arguments{ +\item{inds2}{inds2} + +\item{dist}{dist} + +\item{ninds}{ninds} +} +\description{ +Constructs from the dist vector a subvector containing the individual inds2, Forms dist sub-vectors the vector, which includes yksiliden inds2 +} +\author{ +Waldir Leoncio +}