Merge branch 'import-matlab2r' into develop

This commit is contained in:
Waldir Leoncio 2022-02-03 10:49:59 +01:00
commit e0b2960f1a
58 changed files with 170 additions and 764 deletions

View file

@ -1,6 +1,6 @@
Package: rBAPS
Title: Bayesian Analysis of Population Structure
Version: 0.0.0.9004
Version: 0.0.0.9005
Date: 2020-11-09
Authors@R:
c(
@ -40,4 +40,4 @@ RoxygenNote: 7.1.2
Suggests:
testthat (>= 2.1.0)
Imports:
methods, ape, vcfR, Rsamtools, adegenet
methods, ape, vcfR, Rsamtools, adegenet, matlab2r

View file

@ -2,9 +2,7 @@
export(addAlleles)
export(admix1)
export(blanks)
export(calculatePopLogml)
export(colon)
export(computeAllFreqs2)
export(computeIndLogml)
export(computePersonalAllFreqs)
@ -15,8 +13,6 @@ export(fopen)
export(greedyMix)
export(handleData)
export(initPopNames)
export(inputdlg)
export(isfield)
export(laskeMuutokset4)
export(learn_partition_modified)
export(learn_simple_partition)
@ -25,39 +21,48 @@ export(load_fasta)
export(logml2String)
export(lueGenePopData)
export(lueNimi)
export(matlab2r)
export(noIndex)
export(ownNum2Str)
export(poistaLiianPienet)
export(proportion2str)
export(questdlg)
export(rand)
export(randdir)
export(repmat)
export(rivinSisaltamienMjonojenLkm)
export(selvitaDigitFormat)
export(simulateAllFreqs)
export(simulateIndividuals)
export(simuloiAlleeli)
export(size)
export(strcmp)
export(suoritaMuutos)
export(takeLine)
export(testaaOnkoKunnollinenBapsData)
export(testaaPop)
export(times)
export(uigetfile)
export(uiputfile)
export(writeMixtureInfo)
import(utils)
importFrom(Rsamtools,scanBam)
importFrom(adegenet,.readExt)
importFrom(adegenet,read.genepop)
importFrom(ape,as.DNAbin)
importFrom(ape,read.FASTA)
importFrom(matlab2r,blanks)
importFrom(matlab2r,cell)
importFrom(matlab2r,colon)
importFrom(matlab2r,find)
importFrom(matlab2r,inputdlg)
importFrom(matlab2r,isempty)
importFrom(matlab2r,isfield)
importFrom(matlab2r,isspace)
importFrom(matlab2r,max)
importFrom(matlab2r,min)
importFrom(matlab2r,ones)
importFrom(matlab2r,rand)
importFrom(matlab2r,repmat)
importFrom(matlab2r,reshape)
importFrom(matlab2r,size)
importFrom(matlab2r,sortrows)
importFrom(matlab2r,squeeze)
importFrom(matlab2r,strcmp)
importFrom(matlab2r,times)
importFrom(matlab2r,zeros)
importFrom(methods,is)
importFrom(stats,runif)
importFrom(stats,sd)
importFrom(utils,read.delim)
importFrom(utils,write.table)
importFrom(vcfR,read.vcfR)

View file

@ -4,7 +4,7 @@ addToSummary <- function(logml, partitionSummary, worstIndex) {
# annettua logml arvoa, niin lis<69>t<EFBFBD><74>n worstIndex:in kohtaan uusi logml ja
# nykyist<73> partitiota vastaava nclusters:in arvo. Muutoin ei tehd<68> mit<69><74>n.
apu <- find(abs(partitionSummary[, 2] - logml) < 1e-5)
apu <- matlab2r::find(abs(partitionSummary[, 2] - logml) < 1e-5)
if (isempty(apu)) {
# Nyt l<>ydetty partitio ei ole viel<65> kirjattuna summaryyn.
npops <- length(unique(PARTITION))

View file

@ -130,8 +130,8 @@ admix1 <- function(tietue) {
osuusTaulu[q] <- 1
arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
}
iso_arvo <- max(arvot)
isoimman_indeksi <- match(max(arvot), arvot)
iso_arvo <- base::max(arvot)
isoimman_indeksi <- match(base::max(arvot), arvot)
osuusTaulu <- zeros(1, npops)
osuusTaulu[isoimman_indeksi] <- 1
PARTITION[ind] <- isoimman_indeksi
@ -149,7 +149,7 @@ admix1 <- function(tietue) {
}
# Analyze further only individuals who have log-likelihood ratio larger than 3:
to_investigate <- t(find(likelihood > 3))
to_investigate <- t(matlab2r::find(likelihood > 3))
cat("Possibly admixed individuals:\n")
for (i in 1:length(to_investigate)) {
cat(as.character(to_investigate[i]))
@ -200,8 +200,8 @@ admix1 <- function(tietue) {
osuusTaulu[q] <- 1
arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
}
iso_arvo <- max(arvot)
isoimman_indeksi <- match(max(arvot), arvot)
iso_arvo <- base::max(arvot)
isoimman_indeksi <- match(base::max(arvot), arvot)
osuusTaulu <- zeros(1, npops)
osuusTaulu[isoimman_indeksi] <- 1
PARTITION[ind] <- isoimman_indeksi
@ -233,13 +233,13 @@ admix1 <- function(tietue) {
missing_levels <- zeros(npops, 3) # the mean values for different levels.
missing_level_partition <- zeros(ninds, 1) # level of each individual (one of the levels of its population).
for (i in 1:npops) {
inds <- find(PARTITION == i)
inds <- matlab2r::find(PARTITION == i)
# Proportions of non-missing data for the individuals:
non_missing_data <- zeros(length(inds), 1)
for (j in 1:length(inds)) {
ind <- inds[j]
non_missing_data[j] <- length(
find(data[(ind - 1) * rowsFromInd + 1:ind * rowsFromInd, ] > 0)
matlab2r::find(data[(ind - 1) * rowsFromInd + 1:ind * rowsFromInd, ] > 0)
) / (rowsFromInd * nloci)
}
if (all(non_missing_data > 0.9)) {
@ -258,7 +258,7 @@ admix1 <- function(tietue) {
n_levels <- length(unique(part))
n_missing_levels[i] <- n_levels
for (j in 1:n_levels) {
missing_levels[i, j] <- mean(non_missing_data[find(part == j)])
missing_levels[i, j] <- mean(non_missing_data[matlab2r::find(part == j)])
}
}
}
@ -269,7 +269,7 @@ admix1 <- function(tietue) {
for (pop in t(admix_populaatiot)) {
for (level in 1:n_missing_levels[pop]) {
potential_inds_in_this_pop_and_level <-
find(
matlab2r::find(
PARTITION == pop & missing_level_partition == level &
likelihood > 3
) # Potential admix individuals here.
@ -338,8 +338,8 @@ admix1 <- function(tietue) {
# In case of a rounding error, the sum is made equal to unity by
# fixing the largest value.
if ((PARTITION[ind] > 0) & (sum(proportionsIt[ind, ]) != 1)) {
isoin <- max(proportionsIt[ind, ])
indeksi <- match(isoin, max(proportionsIt[ind, ]))
isoin <- base::max(proportionsIt[ind, ])
indeksi <- match(isoin, base::max(proportionsIt[ind, ]))
erotus <- sum(proportionsIt[ind, ]) - 1
proportionsIt[ind, indeksi] <- isoin - erotus
}
@ -352,7 +352,7 @@ admix1 <- function(tietue) {
pop <- PARTITION[ind]
if (pop == 0) { # Individual is outlier
uskottavuus[ind] <- 1
} else if (isempty(find(to_investigate == ind))) {
} else if (isempty(matlab2r::find(to_investigate == ind))) {
# Individual had log-likelihood ratio<3
uskottavuus[ind] <- 1
} else {

View file

@ -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[, ncol(data_matrix)])
n <- base::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[, ncol(data_matrix)] == i)
here <- matlab2r::find(data_matrix[, ncol(data_matrix)] == i)
for (j in 1:length(here)) {
initial_partition[here[j], 1] <- kori
}

View file

@ -2,7 +2,7 @@ arvoSeuraavaTila <- function(muutokset, logml) {
# Suorittaa yksil<69>n seuraavan tilan arvonnan
y <- logml + muutokset # siirron j<>lkeiset logml:t
y <- y - max(y)
y <- y - base::max(y)
y <- exp(y)
summa <- sum(y)
y <- y / summa

View file

@ -6,7 +6,7 @@ computeDiffInCounts <- function(rows, max_noalle, nloci, data) {
diffInCounts <- zeros(max_noalle, nloci)
for (i in seq_len(nrow(data))) {
row <- data[i, ]
notEmpty <- as.matrix(find(row >= 0))
notEmpty <- as.matrix(matlab2r::find(row >= 0))
if (length(notEmpty) > 0) {
diffInCounts[row(notEmpty) + (notEmpty - 1) * max_noalle] <-

View file

@ -1,10 +1,10 @@
computeLogml <- function(counts, sumcounts, noalle, data, rowsFromInd) {
nloci <- size(counts, 2)
npops <- size(counts, 3)
adjnoalle <- zeros(max(noalle), nloci)
adjnoalle <- zeros(base::max(noalle), nloci)
for (j in 1:nloci) {
adjnoalle[1:noalle[j], j] <- noalle(j)
if ((noalle(j) < max(noalle))) {
if ((noalle(j) < base::max(noalle))) {
adjnoalle[noalle[j] + 1:ncol(adjnoalle), j] <- 1
}
}

View file

@ -10,13 +10,13 @@ etsiParas <- function(osuus, osuusTaulu, omaFreqs, logml) {
while (ready != 1) {
muutokset <- laskeMuutokset4(osuus, osuusTaulu, omaFreqs, logml)
# Work around R's max() limitation on complex numbers
# Work around R's base::max() limitation on complex numbers
if (any(sapply(muutokset, class) == "complex")) {
maxRe <- max(Re(as.vector(muutokset)))
maxIm <- max(Im(as.vector(muutokset)))
maxRe <- base::max(Re(as.vector(muutokset)))
maxIm <- base::max(Im(as.vector(muutokset)))
maxMuutos <- complex(real = maxRe, imaginary = maxIm)
} else {
maxMuutos <- max(as.vector(muutokset))
maxMuutos <- base::max(as.vector(muutokset))
}
indeksi <- which(muutokset == maxMuutos)
if (Re(maxMuutos) > 0) {

View file

@ -6,7 +6,7 @@ findEmptyPop <- function(npops) {
emptyPop <- -1
} else {
popDiff <- diff(c(0, pops, npops + 1))
emptyPop <- min(find(popDiff > 1))
emptyPop <- base::min(matlab2r::find(popDiff > 1))
}
return(list(emptyPop = emptyPop, pops = pops))
}

View file

@ -9,26 +9,26 @@ getDistances <- function(data_matrix, nclusters) {
size_data <- size(data_matrix)
nloci <- size_data[2] - 1
n <- max(data_matrix[, ncol(data_matrix)])
n <- base::max(data_matrix[, ncol(data_matrix)])
distances <- zeros(choose(n, 2), 1)
pointer <- 1
for (i in 1:n - 1) {
i_data <- data_matrix[
find(data_matrix[, ncol(data_matrix)] == i),
matlab2r::find(data_matrix[, ncol(data_matrix)] == i),
1:nloci
]
for (j in (i + 1):n) {
d_ij <- 0
j_data <- data_matrix[find(data_matrix[, ncol()] == j), 1:nloci]
j_data <- data_matrix[matlab2r::find(data_matrix[, ncol()] == j), 1:nloci]
vertailuja <- 0
for (k in 1:size(i_data, 1)) {
for (l in 1:size(j_data, 1)) {
here_i <- find(i_data[k, ] >= 0)
here_j <- find(j_data[l, ] >= 0)
here_i <- matlab2r::find(i_data[k, ] >= 0)
here_j <- matlab2r::find(j_data[l, ] >= 0)
here_joint <- intersect(here_i, here_j)
vertailuja <- vertailuja + length(here_joint)
d_ij <- d_ij + length(
find(i_data[k, here_joint] != j_data[l, here_joint])
matlab2r::find(i_data[k, here_joint] != j_data[l, here_joint])
)
}
}

View file

@ -5,8 +5,6 @@ POP_LOGML <- array(1, dim = 100)
LOGDIFF <- array(1, dim = c(100, 100))
# If handling globas break, try other ideas from https://stackoverflow.com/a/65252740/1169233
#' @import utils
utils::globalVariables(
c("PARTITION", "COUNTS", "SUMCOUNTS", "LOGDIFF", "POP_LOGML", "GAMMA_LN")
)

View file

@ -24,9 +24,9 @@ handleData <- function(raw_data) {
nloci <- size(raw_data, 2) - 1
dataApu <- data[, 1:nloci]
nollat <- find(dataApu == 0)
nollat <- matlab2r::find(dataApu == 0)
if (!isempty(nollat)) {
isoinAlleeli <- max(max(dataApu))
isoinAlleeli <- base::max(max(dataApu))
dataApu[nollat] <- isoinAlleeli + 1
data[, 1:nloci] <- dataApu
}
@ -39,16 +39,16 @@ handleData <- function(raw_data) {
for (i in 1:nloci) {
alleelitLokuksessaI <- unique(data[, i])
alleelitLokuksessa[[i]] <- sort(alleelitLokuksessaI[
find(
matlab2r::find(
alleelitLokuksessaI >= 0
)
])
noalle[i] <- length(alleelitLokuksessa[[i]])
}
alleleCodes <- zeros(max(noalle), nloci)
alleleCodes <- zeros(base::max(noalle), nloci)
for (i in 1:nloci) {
alleelitLokuksessaI <- alleelitLokuksessa[[i]]
puuttuvia <- max(noalle) - length(alleelitLokuksessaI)
puuttuvia <- base::max(noalle) - length(alleelitLokuksessaI)
alleleCodes[, i] <- as.matrix(
c(alleelitLokuksessaI, zeros(puuttuvia, 1))
)
@ -56,21 +56,21 @@ handleData <- function(raw_data) {
for (loc in seq_len(nloci)) {
for (all in seq_len(noalle[loc])) {
data[find(data[, loc] == alleleCodes[all, loc]), loc] <- all
data[matlab2r::find(data[, loc] == alleleCodes[all, loc]), loc] <- all
}
}
nind <- max(data[, ncol(data)])
nind <- base::max(data[, ncol(data)])
nrows <- size(data, 1)
ncols <- size(data, 2)
rowsFromInd <- zeros(nind, 1)
for (i in 1:nind) {
rowsFromInd[i] <- length(find(data[, ncol(data)] == i))
rowsFromInd[i] <- length(matlab2r::find(data[, ncol(data)] == i))
}
maxRowsFromInd <- max(rowsFromInd)
maxRowsFromInd <- base::max(rowsFromInd)
a <- -999
emptyRow <- repmat(a, c(1, ncols))
lessThanMax <- find(rowsFromInd < maxRowsFromInd)
lessThanMax <- matlab2r::find(rowsFromInd < maxRowsFromInd)
missingRows <- maxRowsFromInd * nind - nrows
data <- rbind(data, zeros(missingRows, ncols))
pointer <- 1
@ -81,12 +81,12 @@ handleData <- function(raw_data) {
newData <- data
rowsFromInd <- maxRowsFromInd
adjprior <- zeros(max(noalle), nloci)
adjprior <- zeros(base::max(noalle), nloci)
priorTerm <- 0
for (j in 1:nloci) {
adjprior[, j] <- as.matrix(c(
repmat(1 / noalle[j], c(noalle[j], 1)),
ones(max(noalle) - noalle[j], 1)
ones(base::max(noalle) - noalle[j], 1)
))
priorTerm <- priorTerm + noalle[j] * lgamma(1 / noalle[j])
}

View file

@ -48,7 +48,7 @@ indMix <- function(c, npops, dispText = TRUE) {
return()
} else {
npopsTaulu <- as.numeric(npopstext)
ykkoset <- find(npopsTaulu == 1)
ykkoset <- matlab2r::find(npopsTaulu == 1)
npopsTaulu[ykkoset] <- NA # Mik<69>li ykk<6B>si<73> annettu yl<79>rajaksi, ne poistetaan (if ones are given as an upper limit, they are deleted)
if (isempty(npopsTaulu)) {
logml <- 1
@ -150,8 +150,8 @@ indMix <- function(c, npops, dispText = TRUE) {
diffInCounts <- muutokset_diffInCounts$diffInCounts
if (round == 1) {
maxMuutos <- max_MATLAB(muutokset)$max
i2 <- max_MATLAB(muutokset)$idx
maxMuutos <- matlab2r::max(muutokset)$max
i2 <- matlab2r::max(muutokset)$idx
}
if (i1 != i2 & maxMuutos > 1e-5) {
@ -174,7 +174,7 @@ indMix <- function(c, npops, dispText = TRUE) {
partitionSummary <- temp_addToSum$partitionSummary
added <- temp_addToSum$added
if (added == 1) {
temp_minMATLAB <- min_MATLAB(
temp_minMATLAB <- matlab2r::min(
partitionSummary[, 2]
)
worstLogml <- temp_minMATLAB$mins
@ -195,8 +195,8 @@ indMix <- function(c, npops, dispText = TRUE) {
)
muutokset <- muutokset_diffInCounts$muutokset
diffInCounts <- muutokset_diffInCounts$diffInCounts
isoin <- max_MATLAB(muutokset)[[1]]
indeksi <- max_MATLAB(muutokset)[[2]]
isoin <- matlab2r::max(muutokset)[[1]]
indeksi <- matlab2r::max(muutokset)[[2]]
if (isoin > maxMuutos) {
maxMuutos <- isoin
i1 <- pop
@ -222,8 +222,8 @@ indMix <- function(c, npops, dispText = TRUE) {
partitionSummary <- temp_addToSum$partitionSummary
added <- temp_addToSum$added
if (added == 1) {
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
}
}
} else {
@ -233,13 +233,13 @@ indMix <- function(c, npops, dispText = TRUE) {
maxMuutos <- 0
ninds <- size(rows, 1)
for (pop in 1:npops) {
inds2 <- find(PARTITION == pop)
inds2 <- matlab2r::find(PARTITION == pop)
ninds2 <- length(inds2)
if (ninds2 > 2) {
dist2 <- laskeOsaDist(inds2, dist, ninds)
Z2 <- linkage(t(dist2))
if (round == 3) {
npops2 <- max(min(20, floor(ninds2 / 5)), 2)
npops2 <- base::max(base::min(20, floor(ninds2 / 5)), 2)
} else if (round == 4) {
npops2 <- 2 # Moneenko osaan jaetaan
}
@ -247,13 +247,13 @@ indMix <- function(c, npops, dispText = TRUE) {
muutokset <- laskeMuutokset3(
T2, inds2, rows, data, adjprior, priorTerm, pop
)
isoin <- max_MATLAB(muutokset)[[1]]
indeksi <- max_MATLAB(muutokset)[[2]]
isoin <- matlab2r::max(muutokset)[[1]]
indeksi <- matlab2r::max(muutokset)[[2]]
if (isoin > maxMuutos) {
maxMuutos <- isoin
muuttuvaPop2 <- indeksi %% npops2
if (muuttuvaPop2 == 0) muuttuvaPop2 <- npops2
muuttuvat <- inds2[find(T2 == muuttuvaPop2)]
muuttuvat <- inds2[matlab2r::find(T2 == muuttuvaPop2)]
i2 <- ceiling(indeksi / npops2)
}
}
@ -289,8 +289,8 @@ indMix <- function(c, npops, dispText = TRUE) {
partitionSummary <- temp_addToSum$partitionSummary
added <- temp_addToSum$added
if (added == 1) {
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
}
}
} else {
@ -310,7 +310,7 @@ indMix <- function(c, npops, dispText = TRUE) {
j <- j + 1
pop <- pops[j]
totalMuutos <- 0
inds <- find(PARTITION == pop)
inds <- matlab2r::find(PARTITION == pop)
if (round == 5) {
aputaulu <- c(inds, rand(length(inds), 1))
aputaulu <- sortrows(aputaulu, 2)
@ -334,8 +334,8 @@ indMix <- function(c, npops, dispText = TRUE) {
diffInCounts <- muutokset_diffInCounts$diffInCounts
muutokset[pop] <- -1e50 # Varmasti ei suurin!!!
maxMuutos <- max_MATLAB(muutokset)[[1]]
i2 <- max_MATLAB(muutokset)[[2]]
maxMuutos <- matlab2r::max(muutokset)[[1]]
i2 <- matlab2r::max(muutokset)[[2]]
updateGlobalVariables(
ind, i2, diffInCounts, adjprior, priorTerm
)
@ -370,8 +370,8 @@ indMix <- function(c, npops, dispText = TRUE) {
partitionSummary <- temp_addToSum$partitionSummary
added <- temp_addToSum$added
if (added == 1) {
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
}
}
} else {
@ -398,7 +398,7 @@ indMix <- function(c, npops, dispText = TRUE) {
while (j < npops) {
j <- j + 1
pop <- pops[j]
inds2 <- find(PARTITION == pop)
inds2 <- matlab2r::find(PARTITION == pop)
ninds2 <- length(inds2)
if (ninds2 > 5) {
partition <- PARTITION
@ -410,7 +410,7 @@ indMix <- function(c, npops, dispText = TRUE) {
dist2 <- laskeOsaDist(inds2, dist, ninds)
Z2 <- linkage(t(dist2))
T2 <- cluster_own(Z2, 2)
muuttuvat <- inds2[find(T2 == 1)]
muuttuvat <- inds2[matlab2r::find(T2 == 1)]
muutokset <- laskeMuutokset3(
T2, inds2, rows, data, adjprior, priorTerm, pop
@ -441,7 +441,7 @@ indMix <- function(c, npops, dispText = TRUE) {
pop, emptyPop
)
maxMuutos <- indeksi <- max_MATLAB(muutokset)
maxMuutos <- indeksi <- matlab2r::max(muutokset)
muuttuva <- inds2(indeksi)
if (PARTITION(muuttuva) == pop) {
@ -474,8 +474,8 @@ indMix <- function(c, npops, dispText = TRUE) {
partitionSummary <- temp_addToSum$partitionSummary
added <- temp_addToSum$added
if (added == 1) {
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
}
}
if (muutoksiaNyt == 0) {

View file

@ -3,18 +3,18 @@ initialCounts <- function(partition, data, npops, rows, noalle, adjprior) {
ninds <- size(rows, 1)
koot <- rows[, 1] - rows[, 2] + 1
maxSize <- max(koot)
maxSize <- base::max(koot)
counts <- zeros(max(noalle), nloci, npops)
counts <- zeros(base::max(noalle), nloci, npops)
sumcounts <- zeros(npops, nloci)
for (i in 1:npops) {
for (j in 1:nloci) {
havainnotLokuksessa <- find(partition == i & data[, j] >= 0)
havainnotLokuksessa <- matlab2r::find(partition == i & data[, j] >= 0)
sumcounts[i, j] <- length(havainnotLokuksessa)
for (k in 1:noalle[j]) {
alleleCode <- k
N_ijk <- length(
find(data[havainnotLokuksessa, j] == alleleCode)
matlab2r::find(data[havainnotLokuksessa, j] == alleleCode)
)
counts[k, j, i] <- N_ijk
}

View file

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

View file

@ -68,7 +68,7 @@ laskeMuutokset <- function(ind, globalRows, data, adjprior, priorTerm) {
COUNTS[, , i1] <- COUNTS[, , i1] + diffInCounts
SUMCOUNTS[i1, ] <- SUMCOUNTS[i1, ] + diffInSumCounts
i2 <- find(muutokset == -Inf) # Etsit<69><74>n populaatiot jotka muuttuneet viime kerran j<>lkeen. (Searching for populations that have changed since the last time)
i2 <- matlab2r::find(muutokset == -Inf) # Etsit<69><74>n populaatiot jotka muuttuneet viime kerran j<>lkeen. (Searching for populations that have changed since the last time)
i2 <- setdiff(i2, i1)
i2_logml <- POP_LOGML[i2]
@ -95,7 +95,7 @@ laskeMuutokset2 <- function(i1, globalRows, data, adjprior, priorTerm) {
i1_logml <- POP_LOGML[i1]
inds <- find(PARTITION == i1)
inds <- matlab2r::find(PARTITION == i1)
ninds <- length(inds)
if (ninds == 0) {
@ -138,7 +138,7 @@ laskeMuutokset2 <- function(i1, globalRows, data, adjprior, priorTerm) {
laskeMuutokset3 <- function(T2, inds2, globalRows, data, adjprior, priorTerm, i1) {
# Palauttaa length(unique(T2))*npops taulun, jossa (i,j):s alkio
# kertoo, mik<69> olisi muutos logml:ss<73>, jos populaation i1 osapopulaatio
# inds2(find(T2==i)) siirret<65><74>n koriin j.
# inds2(matlab2r::find(T2==i)) siirret<65><74>n koriin j.
npops <- size(COUNTS, 3)
npops2 <- length(unique(T2))
@ -146,7 +146,7 @@ laskeMuutokset3 <- function(T2, inds2, globalRows, data, adjprior, priorTerm, i1
i1_logml <- POP_LOGML[i1]
for (pop2 in 1:npops2) {
inds <- inds2[find(T2 == pop2)]
inds <- inds2[matlab2r::find(T2 == pop2)]
ninds <- length(inds)
if (ninds > 0) {
rows <- list()

View file

@ -11,9 +11,9 @@ learn_partition_modified <- function(ordered) {
part <- learn_simple_partition(ordered, 0.05)
nclust <- length(unique(part))
if (nclust == 3) {
mini_1 <- min(ordered(which(part == 1)))
mini_2 <- min(ordered(which(part == 2)))
mini_3 <- min(ordered(which(part == 3)))
mini_1 <- base::ordered(which(part == 1))
mini_2 <- base::min(ordered(which(part == 2)))
mini_3 <- base::min(ordered(which(part == 3)))
if (mini_1 > 0.9 & mini_2 > 0.9) {
part[part == 2] <- 1
part[part == 3] <- 2

View file

@ -8,17 +8,19 @@
#' Z = linkage(X) returns a matrix Z that encodes a tree containing hierarchical clusters of the rows of the input data matrix X.
#' @param Y matrix
#' @param method either 'si', 'av', 'co' 'ce' or 'wa'
#' @note This is also a base Matlab function. The reason why the source code is also present here is unclear.
#' @note This is also a base MATLAB function. The reason why the BAPS
#' source code also contains a LINKAGE function is unclear. One could speculate
#' that BAPS should use this function instead of the base one, so this is why
#' this function is part of this package (instead of a MATLAB-replicating
#' package such as matlab2r)
#' @export
linkage <- function(Y, method = "co") {
# TODO: compare R output with MATLAB output
k <- size(Y)[1]
n <- size(Y)[2]
m <- (1 + sqrt(1 + 8 * n)) / 2
if ((k != 1) | (m != trunc(m))) {
stop(
"The first input has to match the output",
"of the PDIST function in size."
"The first input has to match the output of the PDIST function in size."
)
}
method <- tolower(substr(method, 1, 2)) # simplify the switch string.
@ -30,9 +32,8 @@ linkage <- function(Y, method = "co") {
R <- 1:n
for (s in 1:(n - 1)) {
X <- as.matrix(as.vector(Y), ncol = 1)
v <- min_MATLAB(X)$mins
k <- min_MATLAB(X)$idx
v <- matlab2r::min(X)$mins
k <- matlab2r::min(X)$idx
i <- floor(m + 1 / 2 - sqrt(m^2 - m + 1 / 4 - 2 * (k - 1)))
j <- k - (i - 1) * (m - i / 2) + i
@ -70,9 +71,9 @@ linkage <- function(Y, method = "co") {
# I <- I[I > 0 & I <= length(Y)]
# J <- J[J > 0 & J <= length(Y)]
switch(method,
"si" = Y[I] <- apply(cbind(Y[I], Y[J]), 1, min), # single linkage
"si" = Y[I] <- apply(cbind(Y[I], Y[J]), 1, base::min), # single linkage
"av" = Y[I] <- Y[I] + Y[J], # average linkage
"co" = Y[I] <- apply(cbind(Y[I], Y[J]), 1, max), # complete linkage
"co" = Y[I] <- apply(cbind(Y[I], Y[J]), 1, base::max), # complete linkage
"ce" = {
K <- N[R[i]] + N[R[j]] # centroid linkage
Y[I] <- (N[R[i]] * Y[I] + N[R[j]] * Y[J] -

View file

@ -1,11 +1,11 @@
newGetDistances <- function(data, rowsFromInd) {
ninds <- max(data[, ncol(data)])
ninds <- base::max(data[, ncol(data)])
nloci <- size(data, 2) - 1
riviLkm <- choose(ninds, 2)
empties <- find(data < 0)
empties <- matlab2r::find(data < 0)
data[empties] <- 0
data <- apply(data, 2, as.numeric) # max(noalle) oltava <256
data <- apply(data, 2, as.numeric) # base::max(noalle) oltava <256
pariTaulu <- zeros(riviLkm, 2)
aPointer <- 1
@ -51,10 +51,10 @@ newGetDistances <- function(data, rowsFromInd) {
}
rm(x, y, vertailutNyt)
nollat <- find(vertailuja == 0)
nollat <- matlab2r::find(vertailuja == 0)
dist <- zeros(length(vertailuja), 1)
dist[nollat] <- 1
muut <- find(vertailuja > 0)
muut <- matlab2r::find(vertailuja > 0)
dist[muut] <- summa[muut] / vertailuja[muut]
rm(summa, vertailuja)
Z <- linkage(t(dist))

View file

@ -1,13 +1,13 @@
poistaTyhjatPopulaatiot <- function(npops) {
# % Poistaa tyhjentyneet populaatiot COUNTS:ista ja
# % SUMCOUNTS:ista. P<>ivitt<74><74> npops:in ja PARTITION:in.
notEmpty <- find(any(SUMCOUNTS, 2))
notEmpty <- matlab2r::find(any(SUMCOUNTS, 2))
COUNTS <- COUNTS[, , notEmpty]
SUMCOUNTS <- SUMCOUNTS[notEmpty, ]
LOGDIFF <- LOGDIFF[, notEmpty]
for (n in 1:length(notEmpty)) {
apu <- find(PARTITION == notEmpty(n))
apu <- matlab2r::find(PARTITION == notEmpty(n))
PARTITION[apu] <- n
}
npops <- length(notEmpty)

10
R/rBAPS-package.R Normal file
View file

@ -0,0 +1,10 @@
#' @title Bayesian Analysis of Population Structure
#' @description This is a partial implementation of the BAPS software
#' @docType package
#' @name rBAPS
#' @note Found a bug? Want to suggest a feature? Contribute to the scientific
#' and open source communities by opening an issue on our home page.
#' Check the "BugReports" field on the package description for the URL.
#' @importFrom matlab2r blanks cell colon find inputdlg isempty isfield isspace max min ones rand repmat reshape size sortrows squeeze strcmp times zeros
#' @importFrom stats runif
NULL

View file

@ -1,7 +1,7 @@
rand_disc <- function(CDF) {
# %returns an index of a value from a discrete distribution using inversion method
slump <- rand
har <- find(CDF > slump)
har <- matlab2r::find(CDF > slump)
svar <- har(1)
return(svar)
}

View file

@ -26,6 +26,6 @@ simuloiAlleeli <- function(allfreqs, pop, loc) {
cumsumma <- cumsum(freqs)
arvo <- runif(1)
isommat <- which(cumsumma > arvo)
all <- min(isommat)
all <- base::min(isommat)
return(all)
}

View file

@ -12,7 +12,7 @@ testaaOnkoKunnollinenBapsData <- function(data) {
return(ninds)
}
lastCol <- data[, ncol(data)]
ninds <- max(lastCol)
ninds <- base::max(lastCol)
if (any(1:ninds != unique(lastCol))) {
ninds <- 0
return(ninds)

View file

@ -14,7 +14,7 @@ updateGlobalVariables <- function(ind, i2, diffInCounts, adjprior, priorTerm) {
)
LOGDIFF[, c(i1, i2)] <- -Inf
inx <- c(find(PARTITION == i1), find(PARTITION == i2))
inx <- c(matlab2r::find(PARTITION == i1), matlab2r::find(PARTITION == i2))
LOGDIFF[inx, ] <- -Inf
}
@ -22,7 +22,7 @@ updateGlobalVariables2 <- function(i1, i2, diffInCounts, adjprior, priorTerm) {
# % Suorittaa globaalien muuttujien muutokset, kun kaikki
# % korissa i1 olevat yksil<69>t siirret<65><74>n koriin i2.
inds <- find(PARTITION == i1)
inds <- matlab2r::find(PARTITION == i1)
PARTITION[inds] <- i2
COUNTS[, , i1] <- COUNTS[, , i1] - diffInCounts
@ -34,7 +34,7 @@ updateGlobalVariables2 <- function(i1, i2, diffInCounts, adjprior, priorTerm) {
POP_LOGML[i2] <- computePopulationLogml(i2, adjprior, priorTerm)
LOGDIFF[, c(i1, i2)] <- -Inf
inx <- c(find(PARTITION == i1), find(PARTITION == i2))
inx <- c(matlab2r::find(PARTITION == i1), matlab2r::find(PARTITION == i2))
LOGDIFF[inx, ] <- -Inf
}
@ -56,6 +56,6 @@ updateGlobalVariables3 <- function(muuttuvat, diffInCounts, adjprior, priorTerm,
)
LOGDIFF[, c(i1, i2)] <- -Inf
inx <- c(find(PARTITION == i1), find(PARTITION == i2))
inx <- c(matlab2r::find(PARTITION == i1), matlab2r::find(PARTITION == i2))
LOGDIFF[inx, ] <- -Inf
}

View file

@ -64,7 +64,7 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
append(fid, c("Best Partition: ", "\n"))
}
for (m in 1:cluster_count) {
indsInM <- find(PARTITION == m)
indsInM <- matlab2r::find(PARTITION == m)
length_of_beginning <- 11 + floor(log10(m))
cluster_size <- length(indsInM)
@ -139,8 +139,8 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
nimi <- as.character(popnames[i])
nameSizes[i] <- length(nimi)
}
maxSize <- max(nameSizes)
maxSize <- max(maxSize, 5)
maxSize <- base::max(nameSizes)
maxSize <- base::max(maxSize, 5)
erotus <- maxSize - 5
alku <- blanks(erotus)
ekarivi <- c(alku, " ind", blanks(6 + erotus))
@ -193,8 +193,8 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
nloci <- size(COUNTS, 2)
d <- zeros(maxnoalle, nloci, npops)
prior <- adjprior
prior[find(prior == 1)] <- 0
nollia <- find(all(prior == 0)) # Loci in which only one allele was detected.
prior[matlab2r::find(prior == 1)] <- 0
nollia <- matlab2r::find(all(prior == 0)) # Loci in which only one allele was detected.
prior[1, nollia] <- 1
for (pop1 in 1:npops) {
d[, , pop1] <- (squeeze(COUNTS[, , pop1]) + prior) /
@ -261,7 +261,7 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
partitionSummary <- sortrows(partitionSummary, 2)
partitionSummary <- partitionSummary[size(partitionSummary, 1):1, ]
partitionSummary <- partitionSummary[find(partitionSummary[, 2] > -1e49), ]
partitionSummary <- partitionSummary[matlab2r::find(partitionSummary[, 2] > -1e49), ]
if (size(partitionSummary, 1) > 10) {
vikaPartitio <- 10
} else {
@ -298,12 +298,12 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
len <- length(npopsTaulu)
probs <- zeros(len, 1)
partitionSummary[, 2] <- partitionSummary[, 2] -
max(partitionSummary[, 2])
base::max(partitionSummary[, 2])
sumtn <- sum(exp(partitionSummary[, 2]))
for (i in 1:len) {
npopstn <- sum(
exp(
partitionSummary[find(
partitionSummary[matlab2r::find(
partitionSummary[, 1] == npopsTaulu[i]
), 2]
)

View file

@ -1,8 +1,9 @@
[![](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![](https://img.shields.io/github/last-commit/ocbe-uio/rBAPS.svg)](https://github.com/ocbe-uio/rBAPS/commits/master)
[![](https://img.shields.io/github/languages/code-size/ocbe-uio/rBAPS.svg)](https://github.com/ocbe-uio/rBAPS)
[![R build status](https://github.com/ocbe-uio/rBAPS/workflows/R-CMD-check/badge.svg)](https://github.com/ocbe-uio/rBAPS/actions)
[![](https://codecov.io/gh/ocbe-uio/rBAPS/branch/develop/graph/badge.svg)](https://codecov.io/gh/ocbe-uio/rBAPS)
[![Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![last commit](https://img.shields.io/github/last-commit/ocbe-uio/rBAPS.svg)](https://github.com/ocbe-uio/rBAPS/commits/master)
[![code size](https://img.shields.io/github/languages/code-size/ocbe-uio/rBAPS.svg)](https://github.com/ocbe-uio/rBAPS)
[![check status](https://github.com/ocbe-uio/rBAPS/workflows/R-CMD-check/badge.svg)](https://github.com/ocbe-uio/rBAPS/actions)
[![codecov](https://codecov.io/gh/ocbe-uio/rBAPS/branch/develop/graph/badge.svg)](https://codecov.io/gh/ocbe-uio/rBAPS)
[![CodeFactor](https://www.codefactor.io/repository/github/ocbe-uio/rBAPS/badge)](https://www.codefactor.io/repository/github/ocbe-uio/rBAPS)
# rBAPS
R implementation of the compiled Matlab BAPS software for Bayesian Analysis of Population Structure.

View file

@ -1,23 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/blanks.R
\name{blanks}
\alias{blanks}
\title{Blanks}
\usage{
blanks(n)
}
\arguments{
\item{n}{length of vector}
}
\value{
Vector of n blanks
}
\description{
Create character vector of blanks
}
\details{
This function emulates the behavior of a homonimous function from Matlab
}
\author{
Waldir Leoncio
}

View file

@ -1,24 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cell.R
\name{cell}
\alias{cell}
\title{Cell array}
\usage{
cell(n, sz = c(n, n), expandable = FALSE, ...)
}
\arguments{
\item{n}{a the first dimension (or both, if sz is not passed)}
\item{sz}{the second dimension (or 1st and 2nd, if not passed)}
\item{expandable}{if TRUE, output is a list (so it can take different
lengths)}
\item{...}{Other dimensions}
}
\value{
An array of zeroes with the dimensions passed on call
}
\description{
Creates an array of zeros
}

View file

@ -1,16 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colon.R
\name{colon}
\alias{colon}
\title{Vector creation}
\usage{
colon(a, b)
}
\arguments{
\item{a}{initial number}
\item{b}{final number}
}
\description{
Simulates the function `colon()` and its equivalent `:` operator from Matlab, which have a similar but not quite equivalent behavior when compared to `seq()` and `:` in R.
}

View file

@ -1,16 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/find.R
\name{find}
\alias{find}
\title{Find indices and values of nonzero elements}
\usage{
find(x, sort = TRUE)
}
\arguments{
\item{x}{object or logic operation on an object}
\item{sort}{sort output?}
}
\description{
Emulates behavior of `find`
}

View file

@ -1,17 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fix.R
\name{fix}
\alias{fix}
\title{Round toward zero}
\usage{
fix(X)
}
\arguments{
\item{X}{input element}
}
\description{
Rounds each element of input to the nearest integer towards zero. Basically the same as trunc()
}
\author{
Waldir Leoncio
}

View file

@ -1,18 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/inputdlg.R
\name{inputdlg}
\alias{inputdlg}
\title{Gather user input}
\usage{
inputdlg(prompt, dims = 1, definput = NULL)
}
\arguments{
\item{prompt}{Text field with user instructions}
\item{dims}{number of dimensions in the answwers}
\item{definput}{default value of the input}
}
\description{
Replicates the functionality of the homonymous function in Matlab (sans dialog box)
}

View file

@ -1,17 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/isempty.R
\name{isempty}
\alias{isempty}
\title{Is Array Empty?}
\usage{
isempty(x)
}
\arguments{
\item{x}{array}
}
\description{
Determine whether array is empty. An empty array, table, or timetable has at least one dimension with length 0, such as 0-by-0 or 0-by-5.
}
\details{
Emulates the behavior of the `isempty` function on Matlab
}

View file

@ -1,20 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/isfield.R
\name{isfield}
\alias{isfield}
\title{Checks if a list contains a field}
\usage{
isfield(x, field)
}
\arguments{
\item{x}{list}
\item{field}{name of field}
}
\description{
This function tries to replicate the behavior of the `isfield`
function in Matlab
}
\references{
https://se.mathworks.com/help/matlab/ref/isfield.html
}

View file

@ -1,23 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/isspace.R
\name{isspace}
\alias{isspace}
\title{Determine space characters}
\usage{
isspace(A)
}
\arguments{
\item{A}{a character array or a string scalar}
}
\value{
a vector TF such that the elements of TF are logical 1 (true) where corresponding characters in A are space characters, and logical 0 (false) elsewhere
}
\description{
Determine which characters are space characters
}
\note{
Recognized whitespace characters are ` ` and `\\t`.
}
\author{
Waldir Leoncio
}

View file

@ -23,5 +23,9 @@ output format of PDIST.
Z = linkage(X) returns a matrix Z that encodes a tree containing hierarchical clusters of the rows of the input data matrix X.
}
\note{
This is also a base Matlab function. The reason why the source code is also present here is unclear.
This is also a base MATLAB function. The reason why the BAPS
source code also contains a LINKAGE function is unclear. One could speculate
that BAPS should use this function instead of the base one, so this is why
this function is part of this package (instead of a MATLAB-replicating
package such as matlab2r)
}

View file

@ -1,46 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/matlab2r.R
\name{matlab2r}
\alias{matlab2r}
\title{Convert Matlab function to R}
\usage{
matlab2r(
filename,
output = "diff",
improve_formatting = TRUE,
change_assignment = TRUE,
append = FALSE
)
}
\arguments{
\item{filename}{name of the file}
\item{output}{can be "asis", "clean", "save" or "diff"}
\item{improve_formatting}{if `TRUE` (default), makes minor changes
to conform to best-practice formatting conventions}
\item{change_assignment}{if `TRUE` (default), uses `<-` as the assignment operator}
\item{append}{if `FALSE` (default), overwrites file; otherwise, append
output to input}
}
\value{
text converted to R, printed to screen or replacing input file
}
\description{
Performs basic syntax conversion from Matlab to R
}
\note{
This function is intended to expedite the process of converting a
Matlab function to R by making common replacements. It does not have the
immediate goal of outputting a ready-to-use function. In other words,
after using this function you should go back to it and make minor changes.
It is also advised to do a dry-run with `output = "clean"` and only switching
to `output = "save"` when you are confident that no important code will be
lost (for shorter functions, a careful visual inspection should suffice).
}
\author{
Waldir Leoncio
}

View file

@ -1,22 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/min_max_MATLAB.R
\name{max_MATLAB}
\alias{max_MATLAB}
\title{Maximum (MATLAB version)}
\usage{
max_MATLAB(X, indices = TRUE)
}
\arguments{
\item{X}{matrix}
\item{indices}{return indices?}
}
\value{
Either a list or a vector
}
\description{
Finds the minimum value for each column of a matrix, potentially returning the indices instead
}
\author{
Waldir Leoncio
}

View file

@ -1,22 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/min_max_MATLAB.R
\name{min_MATLAB}
\alias{min_MATLAB}
\title{Minimum (MATLAB version)}
\usage{
min_MATLAB(X, indices = TRUE)
}
\arguments{
\item{X}{matrix}
\item{indices}{return indices?}
}
\value{
Either a list or a vector
}
\description{
Finds the minimum value for each column of a matrix, potentially returning the indices instead
}
\author{
Waldir Leoncio
}

View file

@ -1,23 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nargin.R
\name{nargin}
\alias{nargin}
\title{Number of function input arguments}
\usage{
nargin()
}
\value{
An integer
}
\description{
Returns the number of arguments passed to the parent function
}
\note{
This function only makes sense inside another function
}
\references{
https://stackoverflow.com/q/64422780/1169233
}
\author{
Waldir Leoncio
}

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zeros_ones.R
\name{ones}
\alias{ones}
\title{Matrix of ones}
\usage{
ones(n1, n2 = n1, ...)
}
\arguments{
\item{n1}{number of rows}
\item{n2}{number of columns}
\item{...}{extra dimensions}
}
\description{
wrapper of `zeros_or_ones()` that replicates the behavior of
the `ones()` function on Matlab
}

View file

@ -1,29 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/questdlg.R
\name{questdlg}
\alias{questdlg}
\title{Prompt for multiple-choice}
\usage{
questdlg(
quest,
dlgtitle = "",
btn = c("y", "n"),
defbtn = "n",
accepted_ans = c("y", "yes", "n", "no")
)
}
\arguments{
\item{quest}{Question}
\item{dlgtitle}{Title of question}
\item{btn}{Vector of alternatives}
\item{defbtn}{Scalar with the name of the default option}
\item{accepted_ans}{Vector containing accepted answers}
}
\description{
This function aims to loosely mimic the behavior of the
questdlg function on Matlab
}

14
man/rBAPS.Rd Normal file
View file

@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rBAPS-package.R
\docType{package}
\name{rBAPS}
\alias{rBAPS}
\title{Bayesian Analysis of Population Structure}
\description{
This is a partial implementation of the BAPS software
}
\note{
Found a bug? Want to suggest a feature? Contribute to the scientific
and open source communities by opening an issue on our home page.
Check the "BugReports" field on the package description for the URL.
}

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rand.R
\name{rand}
\alias{rand}
\title{Generate matrix with U(0, 1) trials}
\usage{
rand(r = 1, c = 1)
}
\arguments{
\item{r}{number of rows of output matrix}
\item{c}{number of columns of output matrix}
}
\value{
\eqn{r \times c} matrix with random trials from a standard uniform distribution.
}
\description{
Imitates the behavior of `rand()` on Matlab
}

View file

@ -1,29 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/repmat.R
\name{repmat}
\alias{repmat}
\title{Repeat matrix}
\usage{
repmat(mx, n)
}
\arguments{
\item{mx}{matrix}
\item{n}{either a scalar with the number of replications in both rows and
columns or a <= 3-length vector with individual repetitions.}
}
\value{
matrix replicated over `ncol(mx) * n` columns and `nrow(mx) * n` rows
}
\description{
Repeats a matrix over n columns and rows
}
\details{
This function was created to replicate the behavior of a homonymous
function on Matlab
}
\note{
The Matlab implementation of this function accepts `n` with length > 2.
It should also be noted that a concatenated vector in R, e.g. `c(5, 2)`, becomes a column vector when coerced to matrix, even though it may look like a row vector at first glance. This is important to keep in mind when considering the expected output of this function. Vectors in R make sense to be seen as column vectors, given R's Statistics-oriented paradigm where variables are usually disposed as columns in a dataset.
}

View file

@ -1,27 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reshape.R
\name{reshape}
\alias{reshape}
\title{Reshape array}
\usage{
reshape(A, sz)
}
\arguments{
\item{A}{input matrix}
\item{sz}{vector containing the dimensions of the output vector}
}
\description{
Reshapes a matrix according to a certain number of dimensions
}
\details{
This function replicates the functionality of the `reshape()`
function on Matlab. This function is basically a fancy wrapper for the
`array()` function in R, but is useful because it saves the user translation
time. Moreover, it introduces validation code that alter the behavior of
`array()` and makes it more similar to `replicate()`.
}
\note{
The Matlab function also accepts as input the dismemberment of sz as
scalars.
}

View file

@ -1,21 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/setdiff_MATLAB.R
\name{setdiff_MATLAB}
\alias{setdiff_MATLAB}
\title{Set differences of two arrays}
\usage{
setdiff_MATLAB(A, B, legacy = FALSE)
}
\arguments{
\item{A}{first array}
\item{B}{second array}
\item{legacy}{if `TRUE`, preserves the behavior of the setdiff function from MATLAB R2012b and prior releases. (currently not supported)}
}
\description{
Loosely replicates the behavior of the homonym Matlab function
}
\author{
Waldir Leoncio
}

View file

@ -1,23 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/size.R
\name{size}
\alias{size}
\title{Size of an object}
\usage{
size(x, d)
}
\arguments{
\item{x}{object to be evaluated}
\item{d}{dimension of object to be evaluated}
}
\description{
This functions tries to replicate the behavior of the base function "size" in Matlab
}
\note{
On MATLAB, size(1, 100) returns 1. As a matter of fact, if the user
calls for a dimension which x doesn't have `size()` always returns 1. R's
default behavior is more reasonable in those cases (i.e., returning NA),
but since the point of this function is to replicate MATLAB behaviors
(bugs and questionable behaviors included), this function also does this.
}

View file

@ -1,16 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sortrows.R
\name{sortrows}
\alias{sortrows}
\title{Sort rows of matrix or table}
\usage{
sortrows(A, column = 1)
}
\arguments{
\item{A}{matrix}
\item{column}{ordering column}
}
\description{
Emulates the behavior of the `sortrows` function on Matlab
}

View file

@ -1,33 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/squeeze.R
\name{squeeze}
\alias{squeeze}
\title{Squeeze}
\usage{
squeeze(A)
}
\arguments{
\item{A}{input or array matrix}
}
\value{
An array with the same elements as the input array, but with
dimensions of length 1 removed.
}
\description{
Remove dimensions of length 1
}
\details{
This function implements the behavior of the homonimous function on
Matlab. `B = squeeze(A)` returns an array with the same elements as the
input array A, but with dimensions of length 1 removed. For example, if A is
a 3-by-1-by-1-by-2 array, then squeeze(A) returns a 3-by-2 matrix. If A is a
row vector, column vector, scalar, or an array with no dimensions of length
1, then squeeze returns the input A.
}
\note{
This is basically a wrapper of drop() with a minor adjustment to adapt
the output to what happens on Matlab
}
\author{
Waldir Leoncio
}

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/strcmp.R
\name{strcmp}
\alias{strcmp}
\title{Compare two character elements}
\usage{
strcmp(s1, s2)
}
\arguments{
\item{s1}{first character element (string, vector or matrix)}
\item{s2}{second character element (string, vector or matrix)}
}
\value{
a logical element of the same type as the input
}
\description{
Logical test if two character elements are identical
}

View file

@ -1,22 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/times.R
\name{times}
\alias{times}
\title{Element-wise matrix multiplication}
\usage{
times(a, b)
}
\arguments{
\item{a}{first factor of the multiplication}
\item{b}{second factor of the multiplication}
}
\value{
matrix with dimensions equal to the larger of the two factors
}
\description{
Emulates the `times()` and `.*` operators from Matlab.
}
\details{
This function basically handles elements of different length better than the `*` operator in R, at least as far as behavior from a Matlab user is expecting.
}

View file

@ -1,20 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/uigetfile.R
\name{uigetfile}
\alias{uigetfile}
\title{Select a file for loading}
\usage{
uigetfile(filter = "", title = "")
}
\arguments{
\item{filter}{Filter listed files}
\item{title}{Pre-prompt message}
}
\description{
Loosely mimics the functionality of the `uigetfile` function on
Matlab.
}
\references{
https://se.mathworks.com/help/matlab/ref/uigetfile.html
}

View file

@ -1,17 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/uiputfile.R
\name{uiputfile}
\alias{uiputfile}
\title{Save file}
\usage{
uiputfile(filter = ".rda", title = "Save file")
}
\arguments{
\item{filter}{accepted file extension}
\item{title}{Title}
}
\description{
This function intends to loosely mimic the behaviour of the
homonymous Matlab function.
}

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zeros_ones.R
\name{zeros}
\alias{zeros}
\title{Matrix of zeros}
\usage{
zeros(n1, n2 = n1, ...)
}
\arguments{
\item{n1}{number of rows}
\item{n2}{number of columns}
\item{...}{extra dimensions}
}
\description{
wrapper of `zeros_or_ones()` that replicates the behavior of
the `zeros()` function on Matlab
}

View file

@ -1,27 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zeros_ones.R
\name{zeros_or_ones}
\alias{zeros_or_ones}
\title{Matrix of zeros or ones}
\usage{
zeros_or_ones(n, x)
}
\arguments{
\item{n}{scalar or 2D vector}
\item{x}{value to fill matrix with}
}
\value{
n-by-n matrix filled with `x`
}
\description{
Generates a square or rectangular matrix of zeros or ones
}
\details{
This is a wrapper function to replicate the behavior of the
`zeros()` and the `ones()` functions on Matlab
}
\note{
Actually works for any `x`, but there's no need to bother imposing
validation controls here.
}