Translated admixture_initialization
This commit is contained in:
parent
542297ee82
commit
f886feb3a8
9 changed files with 57 additions and 57 deletions
17
R/admixture_initialization.R
Normal file
17
R/admixture_initialization.R
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#'@title Seuraavat kolme funktiota liittyvat alkupartition muodostamiseen.
|
||||||
|
|
||||||
|
admixture_initialization <- function (data_matrix, nclusters, Z) {
|
||||||
|
size_data <- size(data_matrix)
|
||||||
|
nloci <- size_data[2] - 1
|
||||||
|
n <- max(data_matrix[, end])
|
||||||
|
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)
|
||||||
|
for (j in 1:length(here)) {
|
||||||
|
initial_partition[here[j], 1] <- kori
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(initial_partition)
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
clearGlobalVars <- function() {
|
clearGlobalVars <- function() {
|
||||||
COUNTS <- SUMCOUNTS <- PARTITION <- POP_LOGML <- vector() # placeholders
|
# COUNTS <- SUMCOUNTS <- PARTITION <- POP_LOGML <- vector() # placeholders
|
||||||
COUNTS <<- vector()
|
COUNTS <<- vector()
|
||||||
SUMCOUNTS <<- vector()
|
SUMCOUNTS <<- vector()
|
||||||
PARTITION <<- vector()
|
PARTITION <<- vector()
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,11 @@ greedyMix <- function(
|
||||||
savePreProcessed = NULL,
|
savePreProcessed = NULL,
|
||||||
filePreProcessed = NULL
|
filePreProcessed = NULL
|
||||||
) {
|
) {
|
||||||
# ASK: graphical components. Remove?
|
# ASK: Unclear when fixedk == TRUE. Remove?
|
||||||
# check whether fixed k mode is selected
|
# check whether fixed k mode is selected
|
||||||
# h0 <- findobj('Tag','fixk_menu')
|
# h0 <- findobj('Tag','fixk_menu')
|
||||||
# fixedK = get(h0, 'userdata');
|
# fixedK = get(h0, 'userdata');
|
||||||
|
fixedK <- FALSE
|
||||||
|
|
||||||
# if fixedK
|
# if fixedK
|
||||||
# if ~(fixKWarning == 1) % call function fixKWarning
|
# if ~(fixKWarning == 1) % call function fixKWarning
|
||||||
|
|
@ -22,9 +23,11 @@ greedyMix <- function(
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
# ASK: ditto
|
||||||
# % check whether partition compare mode is selected
|
# % check whether partition compare mode is selected
|
||||||
# h1 = findobj('Tag','partitioncompare_menu');
|
# h1 = findobj('Tag','partitioncompare_menu');
|
||||||
# partitionCompare = get(h1, 'userdata');
|
# partitionCompare = get(h1, 'userdata');
|
||||||
|
partitionCompare <- FALSE
|
||||||
|
|
||||||
if (is(tietue, "list") | is(tietue, "character")) {
|
if (is(tietue, "list") | is(tietue, "character")) {
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
@ -244,13 +247,15 @@ greedyMix <- function(
|
||||||
}
|
}
|
||||||
|
|
||||||
# ==========================================================================
|
# ==========================================================================
|
||||||
# Declaring global variables
|
# Declaring global variables and changing environment of children functions
|
||||||
# ==========================================================================
|
# ==========================================================================
|
||||||
PARTITION <- vector()
|
PARTITION <- vector()
|
||||||
COUNTS <- vector()
|
COUNTS <- vector()
|
||||||
SUMCOUNTS <- vector()
|
SUMCOUNTS <- vector()
|
||||||
POP_LOGML <- vector()
|
POP_LOGML <- vector()
|
||||||
clearGlobalVars <- vector()
|
clearGlobalVars()
|
||||||
|
|
||||||
|
environment(writeMixtureInfo) <- environment()
|
||||||
# ==========================================================================
|
# ==========================================================================
|
||||||
c <- list()
|
c <- list()
|
||||||
c$data <- data
|
c$data <- data
|
||||||
|
|
@ -265,6 +270,7 @@ greedyMix <- function(
|
||||||
ekat <- t(seq(1, ninds, rowsFromInd) * rowsFromInd)
|
ekat <- t(seq(1, ninds, rowsFromInd) * rowsFromInd)
|
||||||
c$rows <- c(ekat, ekat + rowsFromInd - 1)
|
c$rows <- c(ekat, ekat + rowsFromInd - 1)
|
||||||
|
|
||||||
|
# ASK remove?
|
||||||
# partition compare
|
# partition compare
|
||||||
# if (!is.null(partitionCompare)) {
|
# if (!is.null(partitionCompare)) {
|
||||||
# nsamplingunits <- size(c$rows, 1)
|
# nsamplingunits <- size(c$rows, 1)
|
||||||
|
|
@ -291,17 +297,22 @@ greedyMix <- function(
|
||||||
# }
|
# }
|
||||||
# # return the logml result
|
# # return the logml result
|
||||||
# partitionCompare$logmls <- partitionLogml
|
# partitionCompare$logmls <- partitionLogml
|
||||||
# # set(h1, 'userdata', partitionCompare) # ASK remove?
|
# # set(h1, 'userdata', partitionCompare)
|
||||||
# return()
|
# return()
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# ASK remove (graphical part)?
|
if (fixedK) {
|
||||||
# if (fixedK) {
|
# logml_npops_partitionSummary <- indMix_fixK(c) # TODO: translate
|
||||||
# #logml_npops_partitionSummary <- indMix_fixK(c) # ASK translate?
|
# logml <- logml_npops_partitionSummary$logml
|
||||||
# } else {
|
# npops <- logml_npops_partitionSummary$npops
|
||||||
# #logml_npops_partitionSummary <- indMix(c) # ASK translate?
|
# partitionSummary <- logml_npops_partitionSummary$partitionSummary
|
||||||
# }
|
} else {
|
||||||
# if (logml_npops_partitionSummary$logml == 1) return()
|
logml_npops_partitionSummary <- indMix(c) # TODO: translate
|
||||||
|
logml <- logml_npops_partitionSummary$logml
|
||||||
|
npops <- logml_npops_partitionSummary$npops
|
||||||
|
partitionSummary <- logml_npops_partitionSummary$partitionSummary
|
||||||
|
}
|
||||||
|
if (logml_npops_partitionSummary$logml == 1) return()
|
||||||
|
|
||||||
data <- data[, seq_len(ncol(data) - 1)]
|
data <- data[, seq_len(ncol(data) - 1)]
|
||||||
|
|
||||||
|
|
@ -310,8 +321,9 @@ greedyMix <- function(
|
||||||
# inp = get(h0,'String');
|
# inp = get(h0,'String');
|
||||||
# h0 = findobj('Tag','filename2_text')
|
# h0 = findobj('Tag','filename2_text')
|
||||||
# outp = get(h0,'String');
|
# outp = get(h0,'String');
|
||||||
|
inp <- vector()
|
||||||
|
outp <- vector()
|
||||||
|
|
||||||
browser() # TEMP
|
|
||||||
changesInLogml <- writeMixtureInfo(
|
changesInLogml <- writeMixtureInfo(
|
||||||
logml, rowsFromInd, data, adjprior, priorTerm, outp, inp,
|
logml, rowsFromInd, data, adjprior, priorTerm, outp, inp,
|
||||||
popnames, fixedK
|
popnames, fixedK
|
||||||
|
|
|
||||||
16
R/indMix.R
16
R/indMix.R
|
|
@ -1157,22 +1157,6 @@ indMix <- function(c, npops, dispText) {
|
||||||
|
|
||||||
|
|
||||||
# %--------------------------------------------------------------------------
|
# %--------------------------------------------------------------------------
|
||||||
# %Seuraavat kolme funktiota liittyvat alkupartition muodostamiseen.
|
|
||||||
|
|
||||||
# function initial_partition=admixture_initialization(data_matrix,nclusters, Z)
|
|
||||||
|
|
||||||
# size_data=size(data_matrix);
|
|
||||||
# nloci=size_data(2)-1;
|
|
||||||
# n=max(data_matrix(:,end));
|
|
||||||
# T=cluster_own(Z,nclusters);
|
|
||||||
# initial_partition=zeros(size_data(1),1);
|
|
||||||
# for i=1:n
|
|
||||||
# kori=T(i);
|
|
||||||
# here=find(data_matrix(:,end)==i);
|
|
||||||
# for j=1:length(here)
|
|
||||||
# initial_partition(here(j),1)=kori;
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# function T = cluster_own(Z,nclust)
|
# function T = cluster_own(Z,nclust)
|
||||||
# true=logical(1);
|
# true=logical(1);
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,6 @@ min_MATLAB <- function(X, indices = TRUE) {
|
||||||
} else {
|
} else {
|
||||||
return(mins)
|
return(mins)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: consider using methods instead (maybe for the package)
|
||||||
|
|
@ -10,16 +10,10 @@
|
||||||
#' @param partitionSummary partitionSummary
|
#' @param partitionSummary partitionSummary
|
||||||
#' @param popnames popnames
|
#' @param popnames popnames
|
||||||
#' @param fixedK fixedK
|
#' @param fixedK fixedK
|
||||||
#' @param PARTITION PARTITION
|
|
||||||
#' @param COUNTS COUNTS
|
|
||||||
#' @param SUMCOUNTS SUMCOUNTS
|
|
||||||
#' @param LOGDIFF LOGDIFF
|
|
||||||
#' @export
|
#' @export
|
||||||
writeMixtureInfo <- function(
|
writeMixtureInfo <- function(
|
||||||
logml, rowsFromInd, data, adjprior, priorTerm, outPutFile, inputFile, partitionSummary, popnames, fixedK, PARTITION, COUNTS, SUMCOUNTS,
|
logml, rowsFromInd, data, adjprior, priorTerm, outPutFile, inputFile, partitionSummary, popnames, fixedK
|
||||||
LOGDIFF
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
changesInLogml <- list()
|
changesInLogml <- list()
|
||||||
ninds <- size(data, 1) / rowsFromInd
|
ninds <- size(data, 1) / rowsFromInd
|
||||||
npops <- size(COUNTS, 3)
|
npops <- size(COUNTS, 3)
|
||||||
|
|
@ -30,7 +24,6 @@ writeMixtureInfo <- function(
|
||||||
fid <- load(outPutFile)
|
fid <- load(outPutFile)
|
||||||
} else {
|
} else {
|
||||||
fid <- -1
|
fid <- -1
|
||||||
message('Diverting output to baps4_output.baps')
|
|
||||||
# TODO: replace sink with option that will record input and output
|
# TODO: replace sink with option that will record input and output
|
||||||
sink('baps4_output.baps', split=TRUE) # save in text anyway.
|
sink('baps4_output.baps', split=TRUE) # save in text anyway.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
% Generated by roxygen2: do not edit by hand
|
% Generated by roxygen2: do not edit by hand
|
||||||
% Please edit documentation in R/min.R
|
% Please edit documentation in R/min.R, R/min_MATLAB.R
|
||||||
\name{min_MATLAB}
|
\name{min_MATLAB}
|
||||||
\alias{min_MATLAB}
|
\alias{min_MATLAB}
|
||||||
\title{Minimum (MATLAB version)}
|
\title{Minimum (MATLAB version)}
|
||||||
\usage{
|
\usage{
|
||||||
|
min_MATLAB(X, indices = TRUE)
|
||||||
|
|
||||||
min_MATLAB(X, indices = TRUE)
|
min_MATLAB(X, indices = TRUE)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
|
@ -12,11 +14,17 @@ min_MATLAB(X, indices = TRUE)
|
||||||
\item{indices}{return indices?}
|
\item{indices}{return indices?}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
|
Either a list or a vector
|
||||||
|
|
||||||
Either a list or a vector
|
Either a list or a vector
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
|
Finds the minimum value for each column of a matrix, potentially returning the indices instead
|
||||||
|
|
||||||
Finds the minimum value for each column of a matrix, potentially returning the indices instead
|
Finds the minimum value for each column of a matrix, potentially returning the indices instead
|
||||||
}
|
}
|
||||||
\author{
|
\author{
|
||||||
|
Waldir Leoncio
|
||||||
|
|
||||||
Waldir Leoncio
|
Waldir Leoncio
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,7 @@ writeMixtureInfo(
|
||||||
inputFile,
|
inputFile,
|
||||||
partitionSummary,
|
partitionSummary,
|
||||||
popnames,
|
popnames,
|
||||||
fixedK,
|
fixedK
|
||||||
PARTITION,
|
|
||||||
COUNTS,
|
|
||||||
SUMCOUNTS,
|
|
||||||
LOGDIFF
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
|
@ -41,14 +37,6 @@ writeMixtureInfo(
|
||||||
\item{popnames}{popnames}
|
\item{popnames}{popnames}
|
||||||
|
|
||||||
\item{fixedK}{fixedK}
|
\item{fixedK}{fixedK}
|
||||||
|
|
||||||
\item{PARTITION}{PARTITION}
|
|
||||||
|
|
||||||
\item{COUNTS}{COUNTS}
|
|
||||||
|
|
||||||
\item{SUMCOUNTS}{SUMCOUNTS}
|
|
||||||
|
|
||||||
\item{LOGDIFF}{LOGDIFF}
|
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Writes information about the mixture
|
Writes information about the mixture
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
# library(devtools)#TEMP
|
|
||||||
library(testthat)#TEMP
|
|
||||||
# library(rBAPS)#TEMP
|
|
||||||
|
|
||||||
context("Opening files on greedyMix")
|
context("Opening files on greedyMix")
|
||||||
|
|
||||||
greedyMix(
|
greedyMix(
|
||||||
tietue = "data/ExamplesDataFormatting/Example baseline data in GENEPOP format for Trained clustering.txt",
|
tietue = "inst/ext/ExamplesDataFormatting/Example baseline data in GENEPOP format for Trained clustering.txt",
|
||||||
format = "GenePop",
|
format = "GenePop",
|
||||||
savePreProcessed = FALSE
|
savePreProcessed = FALSE
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue