Fixed syntax

This commit is contained in:
Waldir Leoncio 2020-11-19 07:53:36 +01:00
parent 97af90d05d
commit 46a9249e5a
9 changed files with 46 additions and 17 deletions

View file

@ -23,6 +23,7 @@ export(linkage)
export(logml2String) export(logml2String)
export(lueGenePopData) export(lueGenePopData)
export(lueNimi) export(lueNimi)
export(matlab2r)
export(noIndex) export(noIndex)
export(ownNum2Str) export(ownNum2Str)
export(poistaLiianPienet) export(poistaLiianPienet)
@ -49,3 +50,4 @@ export(writeMixtureInfo)
importFrom(methods,is) importFrom(methods,is)
importFrom(stats,runif) importFrom(stats,runif)
importFrom(utils,read.delim) importFrom(utils,read.delim)
importFrom(utils,write.table)

View file

@ -6,12 +6,12 @@
admixture_initialization <- function (data_matrix, nclusters, Z) { admixture_initialization <- function (data_matrix, nclusters, Z) {
size_data <- size(data_matrix) size_data <- size(data_matrix)
nloci <- size_data[2] - 1 nloci <- size_data[2] - 1
n <- max(data_matrix[, end]) n <- max(data_matrix[, ncol(data_matrix)])
T <- cluster_own(Z, nclusters) T <- cluster_own(Z, nclusters)
initial_partition <- zeros(size_data[1], 1) initial_partition <- zeros(size_data[1], 1)
for (i in 1:n) { for (i in 1:n) {
kori <- T[i] kori <- T[i]
here <- find(data_matrix[,end] == i) here <- find(data_matrix[, ncol(data_matrix)] == i)
for (j in 1:length(here)) { for (j in 1:length(here)) {
initial_partition[here[j], 1] <- kori initial_partition[here[j], 1] <- kori
} }

View file

@ -15,7 +15,7 @@ cluster_own <- function(Z, nclust) {
for (k in (m - maxclust + 1):(m - 1)) { for (k in (m - maxclust + 1):(m - 1)) {
i = Z(k, 1) # left tree i = Z(k, 1) # left tree
if (i <= m) { # original node, no leafs if (i <= m) { # original node, no leafs
T(i) = clsnum T[i] = clsnum
clsnum = clsnum + 1 clsnum = clsnum + 1
} else if (i < (2 * m - maxclust + 1)) { # created before cutoff, search down the tree } else if (i < (2 * m - maxclust + 1)) { # created before cutoff, search down the tree
T <- clusternum(Z, T, i - m, clsnum) T <- clusternum(Z, T, i - m, clsnum)

View file

@ -9,8 +9,8 @@ computeDiffInCounts <- function(rows, max_noalle, nloci, data) {
notEmpty <- find(row>=0) notEmpty <- find(row>=0)
if (length(notEmpty) > 0) { if (length(notEmpty) > 0) {
diffInCounts(row(notEmpty) + (notEmpty - 1) * max_noalle) <- diffInCounts[row(notEmpty) + (notEmpty - 1) * max_noalle] <-
diffInCounts(row(notEmpty) + (notEmpty - 1) * max_noalle) + 1 diffInCounts[row(notEmpty) + (notEmpty - 1) * max_noalle] + 1
} }
} }
return(diffInCounts) return(diffInCounts)

View file

@ -52,7 +52,7 @@ indMix <- function(c, npops, dispText) {
} else { } else {
npopsTaulu <- as.numeric(npopstext) npopsTaulu <- as.numeric(npopstext)
ykkoset <- find(npopsTaulu == 1) ykkoset <- find(npopsTaulu == 1)
npopsTaulu(ykkoset) <- list() # Mik<69>li ykk<6B>si<73> annettu yl<79>rajaksi, ne poistetaan. npopsTaulu[ykkoset] <- list() # Mik<69>li ykk<6B>si<73> annettu yl<79>rajaksi, ne poistetaan.
if (isempty(npopsTaulu)) { if (isempty(npopsTaulu)) {
logml <- 1 logml <- 1
partitionSummary <- 1 partitionSummary <- 1
@ -68,7 +68,7 @@ indMix <- function(c, npops, dispText) {
nruns <- length(npopsTaulu) nruns <- length(npopsTaulu)
initData <- data initData <- data
data <- data[,1:(end - 1)] data <- data[,1:(ncol(data) - 1)]
logmlBest <- -1e50 logmlBest <- -1e50
partitionSummary <- -1e50 * ones(30, 2) # Tiedot 30 parhaasta partitiosta (npops ja logml) partitionSummary <- -1e50 * ones(30, 2) # Tiedot 30 parhaasta partitiosta (npops ja logml)
@ -76,13 +76,13 @@ indMix <- function(c, npops, dispText) {
worstLogml <- -1e50 worstLogml <- -1e50
worstIndex <- 1 worstIndex <- 1
for (run in 1:nruns) { for (run in 1:nruns) {
npops <- npopsTaulu(run) npops <- npopsTaulu[run]
if (dispText) { if (dispText) {
dispLine() dispLine()
print( print(
paste0( paste0(
'Run ', num2str(run), '/', num2str(nruns), 'Run ', as.character(run), '/', as.character(nruns),
', maximum number of populations ', num2str(npops), '.' ', maximum number of populations ', as.character(npops), '.'
) )
) )
} }
@ -120,7 +120,7 @@ indMix <- function(c, npops, dispText) {
print( print(
paste0( paste0(
'Mixture analysis started with initial', 'Mixture analysis started with initial',
num2str(npops), as.character(npops),
'populations.' 'populations.'
) )
) )
@ -130,7 +130,7 @@ indMix <- function(c, npops, dispText) {
muutoksia <- 0 muutoksia <- 0
if (dispText) { if (dispText) {
print(paste('Performing steps:', num2str(roundTypes))) print(paste('Performing steps:', as.character(roundTypes)))
} }
for (n in 1:length(roundTypes)) { for (n in 1:length(roundTypes)) {
@ -545,7 +545,7 @@ indMix <- function(c, npops, dispText) {
npops <- poistaTyhjatPopulaatiot(npops) npops <- poistaTyhjatPopulaatiot(npops)
POP_LOGML <- computePopulationLogml(1:npops, adjprior, priorTerm) POP_LOGML <- computePopulationLogml(1:npops, adjprior, priorTerm)
if (dispText) { 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(paste('Log(ml) =', as.character(logml)))
print(' ') print(' ')
} }

View file

@ -7,11 +7,11 @@ initialPopCounts <- function(data, npops, rows, noalle, adjprior) {
for (j in 1:nloci) { for (j in 1:nloci) {
i_rivit <- rows(i, 1):rows(i, 2) i_rivit <- rows(i, 1):rows(i, 2)
havainnotLokuksessa <- find(data[i_rivit, j] >= 0) havainnotLokuksessa <- find(data[i_rivit, j] >= 0)
sumcounts(i, j) <- length(havainnotLokuksessa) sumcounts[i, j] <- length(havainnotLokuksessa)
for (k in 1:noalle[j]) { for (k in 1:noalle[j]) {
alleleCode <- k alleleCode <- k
N_ijk <- length(find(data[i_rivit, j] == alleleCode)) N_ijk <- length(find(data[i_rivit, j] == alleleCode))
counts(k, j, i) <- N_ijk counts[k, j, i] <- N_ijk
} }
} }
} }

View file

@ -1,7 +1,7 @@
laskeLoggis <- function(counts, sumcounts, adjprior) { laskeLoggis <- function(counts, sumcounts, adjprior) {
npops <- size(counts, 3) 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))) sum3 <- sum(sum(lgamma(adjprior))) - sum(sum(lgamma(1 + sumcounts)))
logml2 <- sum1 - npops * sum3 logml2 <- sum1 - npops * sum3
loggis <- logml2 loggis <- logml2

View file

@ -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) { laskeOsaDist <- function(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<EFBFBD>. # % v<>liset et<65>isyydet. ninds=kaikkien yksil<69>iden lukum<75><6D>r<EFBFBD>.
ninds2 <- length(inds2) ninds2 <- length(inds2)
apu <- zeros(nchoosek(ninds2, 2), 2) apu <- zeros(choose(ninds2, 2), 2)
rivi <- 1 rivi <- 1
for (i in 1:ninds2-1) { for (i in 1:ninds2-1) {
for (j in i+1:ninds2) { for (j in i+1:ninds2) {

21
man/laskeOsaDist.Rd Normal file
View file

@ -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
}