Merge branch 'import-matlab2r' into develop
This commit is contained in:
commit
e0b2960f1a
58 changed files with 170 additions and 764 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Package: rBAPS
|
Package: rBAPS
|
||||||
Title: Bayesian Analysis of Population Structure
|
Title: Bayesian Analysis of Population Structure
|
||||||
Version: 0.0.0.9004
|
Version: 0.0.0.9005
|
||||||
Date: 2020-11-09
|
Date: 2020-11-09
|
||||||
Authors@R:
|
Authors@R:
|
||||||
c(
|
c(
|
||||||
|
|
@ -40,4 +40,4 @@ RoxygenNote: 7.1.2
|
||||||
Suggests:
|
Suggests:
|
||||||
testthat (>= 2.1.0)
|
testthat (>= 2.1.0)
|
||||||
Imports:
|
Imports:
|
||||||
methods, ape, vcfR, Rsamtools, adegenet
|
methods, ape, vcfR, Rsamtools, adegenet, matlab2r
|
||||||
|
|
|
||||||
35
NAMESPACE
35
NAMESPACE
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
export(addAlleles)
|
export(addAlleles)
|
||||||
export(admix1)
|
export(admix1)
|
||||||
export(blanks)
|
|
||||||
export(calculatePopLogml)
|
export(calculatePopLogml)
|
||||||
export(colon)
|
|
||||||
export(computeAllFreqs2)
|
export(computeAllFreqs2)
|
||||||
export(computeIndLogml)
|
export(computeIndLogml)
|
||||||
export(computePersonalAllFreqs)
|
export(computePersonalAllFreqs)
|
||||||
|
|
@ -15,8 +13,6 @@ export(fopen)
|
||||||
export(greedyMix)
|
export(greedyMix)
|
||||||
export(handleData)
|
export(handleData)
|
||||||
export(initPopNames)
|
export(initPopNames)
|
||||||
export(inputdlg)
|
|
||||||
export(isfield)
|
|
||||||
export(laskeMuutokset4)
|
export(laskeMuutokset4)
|
||||||
export(learn_partition_modified)
|
export(learn_partition_modified)
|
||||||
export(learn_simple_partition)
|
export(learn_simple_partition)
|
||||||
|
|
@ -25,39 +21,48 @@ export(load_fasta)
|
||||||
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)
|
||||||
export(proportion2str)
|
export(proportion2str)
|
||||||
export(questdlg)
|
|
||||||
export(rand)
|
|
||||||
export(randdir)
|
export(randdir)
|
||||||
export(repmat)
|
|
||||||
export(rivinSisaltamienMjonojenLkm)
|
export(rivinSisaltamienMjonojenLkm)
|
||||||
export(selvitaDigitFormat)
|
export(selvitaDigitFormat)
|
||||||
export(simulateAllFreqs)
|
export(simulateAllFreqs)
|
||||||
export(simulateIndividuals)
|
export(simulateIndividuals)
|
||||||
export(simuloiAlleeli)
|
export(simuloiAlleeli)
|
||||||
export(size)
|
|
||||||
export(strcmp)
|
|
||||||
export(suoritaMuutos)
|
export(suoritaMuutos)
|
||||||
export(takeLine)
|
export(takeLine)
|
||||||
export(testaaOnkoKunnollinenBapsData)
|
export(testaaOnkoKunnollinenBapsData)
|
||||||
export(testaaPop)
|
export(testaaPop)
|
||||||
export(times)
|
|
||||||
export(uigetfile)
|
|
||||||
export(uiputfile)
|
|
||||||
export(writeMixtureInfo)
|
export(writeMixtureInfo)
|
||||||
import(utils)
|
|
||||||
importFrom(Rsamtools,scanBam)
|
importFrom(Rsamtools,scanBam)
|
||||||
importFrom(adegenet,.readExt)
|
importFrom(adegenet,.readExt)
|
||||||
importFrom(adegenet,read.genepop)
|
importFrom(adegenet,read.genepop)
|
||||||
importFrom(ape,as.DNAbin)
|
importFrom(ape,as.DNAbin)
|
||||||
importFrom(ape,read.FASTA)
|
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(methods,is)
|
||||||
importFrom(stats,runif)
|
importFrom(stats,runif)
|
||||||
importFrom(stats,sd)
|
importFrom(stats,sd)
|
||||||
importFrom(utils,read.delim)
|
importFrom(utils,read.delim)
|
||||||
importFrom(utils,write.table)
|
|
||||||
importFrom(vcfR,read.vcfR)
|
importFrom(vcfR,read.vcfR)
|
||||||
|
|
|
||||||
|
|
@ -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
|
# 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.
|
# 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)) {
|
if (isempty(apu)) {
|
||||||
# Nyt l<>ydetty partitio ei ole viel<65> kirjattuna summaryyn.
|
# Nyt l<>ydetty partitio ei ole viel<65> kirjattuna summaryyn.
|
||||||
npops <- length(unique(PARTITION))
|
npops <- length(unique(PARTITION))
|
||||||
|
|
|
||||||
24
R/admix1.R
24
R/admix1.R
|
|
@ -130,8 +130,8 @@ admix1 <- function(tietue) {
|
||||||
osuusTaulu[q] <- 1
|
osuusTaulu[q] <- 1
|
||||||
arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
|
arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
|
||||||
}
|
}
|
||||||
iso_arvo <- max(arvot)
|
iso_arvo <- base::max(arvot)
|
||||||
isoimman_indeksi <- match(max(arvot), arvot)
|
isoimman_indeksi <- match(base::max(arvot), arvot)
|
||||||
osuusTaulu <- zeros(1, npops)
|
osuusTaulu <- zeros(1, npops)
|
||||||
osuusTaulu[isoimman_indeksi] <- 1
|
osuusTaulu[isoimman_indeksi] <- 1
|
||||||
PARTITION[ind] <- isoimman_indeksi
|
PARTITION[ind] <- isoimman_indeksi
|
||||||
|
|
@ -149,7 +149,7 @@ admix1 <- function(tietue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Analyze further only individuals who have log-likelihood ratio larger than 3:
|
# 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")
|
cat("Possibly admixed individuals:\n")
|
||||||
for (i in 1:length(to_investigate)) {
|
for (i in 1:length(to_investigate)) {
|
||||||
cat(as.character(to_investigate[i]))
|
cat(as.character(to_investigate[i]))
|
||||||
|
|
@ -200,8 +200,8 @@ admix1 <- function(tietue) {
|
||||||
osuusTaulu[q] <- 1
|
osuusTaulu[q] <- 1
|
||||||
arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
|
arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
|
||||||
}
|
}
|
||||||
iso_arvo <- max(arvot)
|
iso_arvo <- base::max(arvot)
|
||||||
isoimman_indeksi <- match(max(arvot), arvot)
|
isoimman_indeksi <- match(base::max(arvot), arvot)
|
||||||
osuusTaulu <- zeros(1, npops)
|
osuusTaulu <- zeros(1, npops)
|
||||||
osuusTaulu[isoimman_indeksi] <- 1
|
osuusTaulu[isoimman_indeksi] <- 1
|
||||||
PARTITION[ind] <- isoimman_indeksi
|
PARTITION[ind] <- isoimman_indeksi
|
||||||
|
|
@ -233,13 +233,13 @@ admix1 <- function(tietue) {
|
||||||
missing_levels <- zeros(npops, 3) # the mean values for different levels.
|
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).
|
missing_level_partition <- zeros(ninds, 1) # level of each individual (one of the levels of its population).
|
||||||
for (i in 1:npops) {
|
for (i in 1:npops) {
|
||||||
inds <- find(PARTITION == i)
|
inds <- matlab2r::find(PARTITION == i)
|
||||||
# Proportions of non-missing data for the individuals:
|
# Proportions of non-missing data for the individuals:
|
||||||
non_missing_data <- zeros(length(inds), 1)
|
non_missing_data <- zeros(length(inds), 1)
|
||||||
for (j in 1:length(inds)) {
|
for (j in 1:length(inds)) {
|
||||||
ind <- inds[j]
|
ind <- inds[j]
|
||||||
non_missing_data[j] <- length(
|
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)
|
) / (rowsFromInd * nloci)
|
||||||
}
|
}
|
||||||
if (all(non_missing_data > 0.9)) {
|
if (all(non_missing_data > 0.9)) {
|
||||||
|
|
@ -258,7 +258,7 @@ admix1 <- function(tietue) {
|
||||||
n_levels <- length(unique(part))
|
n_levels <- length(unique(part))
|
||||||
n_missing_levels[i] <- n_levels
|
n_missing_levels[i] <- n_levels
|
||||||
for (j in 1: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 (pop in t(admix_populaatiot)) {
|
||||||
for (level in 1:n_missing_levels[pop]) {
|
for (level in 1:n_missing_levels[pop]) {
|
||||||
potential_inds_in_this_pop_and_level <-
|
potential_inds_in_this_pop_and_level <-
|
||||||
find(
|
matlab2r::find(
|
||||||
PARTITION == pop & missing_level_partition == level &
|
PARTITION == pop & missing_level_partition == level &
|
||||||
likelihood > 3
|
likelihood > 3
|
||||||
) # Potential admix individuals here.
|
) # 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
|
# In case of a rounding error, the sum is made equal to unity by
|
||||||
# fixing the largest value.
|
# fixing the largest value.
|
||||||
if ((PARTITION[ind] > 0) & (sum(proportionsIt[ind, ]) != 1)) {
|
if ((PARTITION[ind] > 0) & (sum(proportionsIt[ind, ]) != 1)) {
|
||||||
isoin <- max(proportionsIt[ind, ])
|
isoin <- base::max(proportionsIt[ind, ])
|
||||||
indeksi <- match(isoin, max(proportionsIt[ind, ]))
|
indeksi <- match(isoin, base::max(proportionsIt[ind, ]))
|
||||||
erotus <- sum(proportionsIt[ind, ]) - 1
|
erotus <- sum(proportionsIt[ind, ]) - 1
|
||||||
proportionsIt[ind, indeksi] <- isoin - erotus
|
proportionsIt[ind, indeksi] <- isoin - erotus
|
||||||
}
|
}
|
||||||
|
|
@ -352,7 +352,7 @@ admix1 <- function(tietue) {
|
||||||
pop <- PARTITION[ind]
|
pop <- PARTITION[ind]
|
||||||
if (pop == 0) { # Individual is outlier
|
if (pop == 0) { # Individual is outlier
|
||||||
uskottavuus[ind] <- 1
|
uskottavuus[ind] <- 1
|
||||||
} else if (isempty(find(to_investigate == ind))) {
|
} else if (isempty(matlab2r::find(to_investigate == ind))) {
|
||||||
# Individual had log-likelihood ratio<3
|
# Individual had log-likelihood ratio<3
|
||||||
uskottavuus[ind] <- 1
|
uskottavuus[ind] <- 1
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -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[, ncol(data_matrix)])
|
n <- base::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[, ncol(data_matrix)] == i)
|
here <- matlab2r::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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ arvoSeuraavaTila <- function(muutokset, logml) {
|
||||||
# Suorittaa yksil<69>n seuraavan tilan arvonnan
|
# Suorittaa yksil<69>n seuraavan tilan arvonnan
|
||||||
|
|
||||||
y <- logml + muutokset # siirron j<>lkeiset logml:t
|
y <- logml + muutokset # siirron j<>lkeiset logml:t
|
||||||
y <- y - max(y)
|
y <- y - base::max(y)
|
||||||
y <- exp(y)
|
y <- exp(y)
|
||||||
summa <- sum(y)
|
summa <- sum(y)
|
||||||
y <- y / summa
|
y <- y / summa
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ computeDiffInCounts <- function(rows, max_noalle, nloci, data) {
|
||||||
diffInCounts <- zeros(max_noalle, nloci)
|
diffInCounts <- zeros(max_noalle, nloci)
|
||||||
for (i in seq_len(nrow(data))) {
|
for (i in seq_len(nrow(data))) {
|
||||||
row <- data[i, ]
|
row <- data[i, ]
|
||||||
notEmpty <- as.matrix(find(row >= 0))
|
notEmpty <- as.matrix(matlab2r::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] <-
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
computeLogml <- function(counts, sumcounts, noalle, data, rowsFromInd) {
|
computeLogml <- function(counts, sumcounts, noalle, data, rowsFromInd) {
|
||||||
nloci <- size(counts, 2)
|
nloci <- size(counts, 2)
|
||||||
npops <- size(counts, 3)
|
npops <- size(counts, 3)
|
||||||
adjnoalle <- zeros(max(noalle), nloci)
|
adjnoalle <- zeros(base::max(noalle), nloci)
|
||||||
for (j in 1:nloci) {
|
for (j in 1:nloci) {
|
||||||
adjnoalle[1:noalle[j], j] <- noalle(j)
|
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
|
adjnoalle[noalle[j] + 1:ncol(adjnoalle), j] <- 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@ etsiParas <- function(osuus, osuusTaulu, omaFreqs, logml) {
|
||||||
while (ready != 1) {
|
while (ready != 1) {
|
||||||
muutokset <- laskeMuutokset4(osuus, osuusTaulu, omaFreqs, logml)
|
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")) {
|
if (any(sapply(muutokset, class) == "complex")) {
|
||||||
maxRe <- max(Re(as.vector(muutokset)))
|
maxRe <- base::max(Re(as.vector(muutokset)))
|
||||||
maxIm <- max(Im(as.vector(muutokset)))
|
maxIm <- base::max(Im(as.vector(muutokset)))
|
||||||
maxMuutos <- complex(real = maxRe, imaginary = maxIm)
|
maxMuutos <- complex(real = maxRe, imaginary = maxIm)
|
||||||
} else {
|
} else {
|
||||||
maxMuutos <- max(as.vector(muutokset))
|
maxMuutos <- base::max(as.vector(muutokset))
|
||||||
}
|
}
|
||||||
indeksi <- which(muutokset == maxMuutos)
|
indeksi <- which(muutokset == maxMuutos)
|
||||||
if (Re(maxMuutos) > 0) {
|
if (Re(maxMuutos) > 0) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ findEmptyPop <- function(npops) {
|
||||||
emptyPop <- -1
|
emptyPop <- -1
|
||||||
} else {
|
} else {
|
||||||
popDiff <- diff(c(0, pops, npops + 1))
|
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))
|
return(list(emptyPop = emptyPop, pops = pops))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,26 +9,26 @@ getDistances <- function(data_matrix, nclusters) {
|
||||||
|
|
||||||
size_data <- size(data_matrix)
|
size_data <- size(data_matrix)
|
||||||
nloci <- size_data[2] - 1
|
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)
|
distances <- zeros(choose(n, 2), 1)
|
||||||
pointer <- 1
|
pointer <- 1
|
||||||
for (i in 1:n - 1) {
|
for (i in 1:n - 1) {
|
||||||
i_data <- data_matrix[
|
i_data <- data_matrix[
|
||||||
find(data_matrix[, ncol(data_matrix)] == i),
|
matlab2r::find(data_matrix[, ncol(data_matrix)] == i),
|
||||||
1:nloci
|
1:nloci
|
||||||
]
|
]
|
||||||
for (j in (i + 1):n) {
|
for (j in (i + 1):n) {
|
||||||
d_ij <- 0
|
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
|
vertailuja <- 0
|
||||||
for (k in 1:size(i_data, 1)) {
|
for (k in 1:size(i_data, 1)) {
|
||||||
for (l in 1:size(j_data, 1)) {
|
for (l in 1:size(j_data, 1)) {
|
||||||
here_i <- find(i_data[k, ] >= 0)
|
here_i <- matlab2r::find(i_data[k, ] >= 0)
|
||||||
here_j <- find(j_data[l, ] >= 0)
|
here_j <- matlab2r::find(j_data[l, ] >= 0)
|
||||||
here_joint <- intersect(here_i, here_j)
|
here_joint <- intersect(here_i, here_j)
|
||||||
vertailuja <- vertailuja + length(here_joint)
|
vertailuja <- vertailuja + length(here_joint)
|
||||||
d_ij <- d_ij + length(
|
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])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ POP_LOGML <- array(1, dim = 100)
|
||||||
LOGDIFF <- array(1, dim = c(100, 100))
|
LOGDIFF <- array(1, dim = c(100, 100))
|
||||||
# If handling globas break, try other ideas from https://stackoverflow.com/a/65252740/1169233
|
# If handling globas break, try other ideas from https://stackoverflow.com/a/65252740/1169233
|
||||||
|
|
||||||
|
|
||||||
#' @import utils
|
|
||||||
utils::globalVariables(
|
utils::globalVariables(
|
||||||
c("PARTITION", "COUNTS", "SUMCOUNTS", "LOGDIFF", "POP_LOGML", "GAMMA_LN")
|
c("PARTITION", "COUNTS", "SUMCOUNTS", "LOGDIFF", "POP_LOGML", "GAMMA_LN")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ handleData <- function(raw_data) {
|
||||||
nloci <- size(raw_data, 2) - 1
|
nloci <- size(raw_data, 2) - 1
|
||||||
|
|
||||||
dataApu <- data[, 1:nloci]
|
dataApu <- data[, 1:nloci]
|
||||||
nollat <- find(dataApu == 0)
|
nollat <- matlab2r::find(dataApu == 0)
|
||||||
if (!isempty(nollat)) {
|
if (!isempty(nollat)) {
|
||||||
isoinAlleeli <- max(max(dataApu))
|
isoinAlleeli <- base::max(max(dataApu))
|
||||||
dataApu[nollat] <- isoinAlleeli + 1
|
dataApu[nollat] <- isoinAlleeli + 1
|
||||||
data[, 1:nloci] <- dataApu
|
data[, 1:nloci] <- dataApu
|
||||||
}
|
}
|
||||||
|
|
@ -39,16 +39,16 @@ handleData <- function(raw_data) {
|
||||||
for (i in 1:nloci) {
|
for (i in 1:nloci) {
|
||||||
alleelitLokuksessaI <- unique(data[, i])
|
alleelitLokuksessaI <- unique(data[, i])
|
||||||
alleelitLokuksessa[[i]] <- sort(alleelitLokuksessaI[
|
alleelitLokuksessa[[i]] <- sort(alleelitLokuksessaI[
|
||||||
find(
|
matlab2r::find(
|
||||||
alleelitLokuksessaI >= 0
|
alleelitLokuksessaI >= 0
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
noalle[i] <- length(alleelitLokuksessa[[i]])
|
noalle[i] <- length(alleelitLokuksessa[[i]])
|
||||||
}
|
}
|
||||||
alleleCodes <- zeros(max(noalle), nloci)
|
alleleCodes <- zeros(base::max(noalle), nloci)
|
||||||
for (i in 1:nloci) {
|
for (i in 1:nloci) {
|
||||||
alleelitLokuksessaI <- alleelitLokuksessa[[i]]
|
alleelitLokuksessaI <- alleelitLokuksessa[[i]]
|
||||||
puuttuvia <- max(noalle) - length(alleelitLokuksessaI)
|
puuttuvia <- base::max(noalle) - length(alleelitLokuksessaI)
|
||||||
alleleCodes[, i] <- as.matrix(
|
alleleCodes[, i] <- as.matrix(
|
||||||
c(alleelitLokuksessaI, zeros(puuttuvia, 1))
|
c(alleelitLokuksessaI, zeros(puuttuvia, 1))
|
||||||
)
|
)
|
||||||
|
|
@ -56,21 +56,21 @@ handleData <- function(raw_data) {
|
||||||
|
|
||||||
for (loc in seq_len(nloci)) {
|
for (loc in seq_len(nloci)) {
|
||||||
for (all in seq_len(noalle[loc])) {
|
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)
|
nrows <- size(data, 1)
|
||||||
ncols <- size(data, 2)
|
ncols <- size(data, 2)
|
||||||
rowsFromInd <- zeros(nind, 1)
|
rowsFromInd <- zeros(nind, 1)
|
||||||
for (i in 1:nind) {
|
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
|
a <- -999
|
||||||
emptyRow <- repmat(a, c(1, ncols))
|
emptyRow <- repmat(a, c(1, ncols))
|
||||||
lessThanMax <- find(rowsFromInd < maxRowsFromInd)
|
lessThanMax <- matlab2r::find(rowsFromInd < maxRowsFromInd)
|
||||||
missingRows <- maxRowsFromInd * nind - nrows
|
missingRows <- maxRowsFromInd * nind - nrows
|
||||||
data <- rbind(data, zeros(missingRows, ncols))
|
data <- rbind(data, zeros(missingRows, ncols))
|
||||||
pointer <- 1
|
pointer <- 1
|
||||||
|
|
@ -81,12 +81,12 @@ handleData <- function(raw_data) {
|
||||||
newData <- data
|
newData <- data
|
||||||
rowsFromInd <- maxRowsFromInd
|
rowsFromInd <- maxRowsFromInd
|
||||||
|
|
||||||
adjprior <- zeros(max(noalle), nloci)
|
adjprior <- zeros(base::max(noalle), nloci)
|
||||||
priorTerm <- 0
|
priorTerm <- 0
|
||||||
for (j in 1:nloci) {
|
for (j in 1:nloci) {
|
||||||
adjprior[, j] <- as.matrix(c(
|
adjprior[, j] <- as.matrix(c(
|
||||||
repmat(1 / noalle[j], c(noalle[j], 1)),
|
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])
|
priorTerm <- priorTerm + noalle[j] * lgamma(1 / noalle[j])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
R/indMix.R
50
R/indMix.R
|
|
@ -48,7 +48,7 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
return()
|
return()
|
||||||
} else {
|
} else {
|
||||||
npopsTaulu <- as.numeric(npopstext)
|
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)
|
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)) {
|
if (isempty(npopsTaulu)) {
|
||||||
logml <- 1
|
logml <- 1
|
||||||
|
|
@ -150,8 +150,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
diffInCounts <- muutokset_diffInCounts$diffInCounts
|
diffInCounts <- muutokset_diffInCounts$diffInCounts
|
||||||
|
|
||||||
if (round == 1) {
|
if (round == 1) {
|
||||||
maxMuutos <- max_MATLAB(muutokset)$max
|
maxMuutos <- matlab2r::max(muutokset)$max
|
||||||
i2 <- max_MATLAB(muutokset)$idx
|
i2 <- matlab2r::max(muutokset)$idx
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i1 != i2 & maxMuutos > 1e-5) {
|
if (i1 != i2 & maxMuutos > 1e-5) {
|
||||||
|
|
@ -174,7 +174,7 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
partitionSummary <- temp_addToSum$partitionSummary
|
partitionSummary <- temp_addToSum$partitionSummary
|
||||||
added <- temp_addToSum$added
|
added <- temp_addToSum$added
|
||||||
if (added == 1) {
|
if (added == 1) {
|
||||||
temp_minMATLAB <- min_MATLAB(
|
temp_minMATLAB <- matlab2r::min(
|
||||||
partitionSummary[, 2]
|
partitionSummary[, 2]
|
||||||
)
|
)
|
||||||
worstLogml <- temp_minMATLAB$mins
|
worstLogml <- temp_minMATLAB$mins
|
||||||
|
|
@ -195,8 +195,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
)
|
)
|
||||||
muutokset <- muutokset_diffInCounts$muutokset
|
muutokset <- muutokset_diffInCounts$muutokset
|
||||||
diffInCounts <- muutokset_diffInCounts$diffInCounts
|
diffInCounts <- muutokset_diffInCounts$diffInCounts
|
||||||
isoin <- max_MATLAB(muutokset)[[1]]
|
isoin <- matlab2r::max(muutokset)[[1]]
|
||||||
indeksi <- max_MATLAB(muutokset)[[2]]
|
indeksi <- matlab2r::max(muutokset)[[2]]
|
||||||
if (isoin > maxMuutos) {
|
if (isoin > maxMuutos) {
|
||||||
maxMuutos <- isoin
|
maxMuutos <- isoin
|
||||||
i1 <- pop
|
i1 <- pop
|
||||||
|
|
@ -222,8 +222,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
partitionSummary <- temp_addToSum$partitionSummary
|
partitionSummary <- temp_addToSum$partitionSummary
|
||||||
added <- temp_addToSum$added
|
added <- temp_addToSum$added
|
||||||
if (added == 1) {
|
if (added == 1) {
|
||||||
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
|
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
|
||||||
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
|
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -233,13 +233,13 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
maxMuutos <- 0
|
maxMuutos <- 0
|
||||||
ninds <- size(rows, 1)
|
ninds <- size(rows, 1)
|
||||||
for (pop in 1:npops) {
|
for (pop in 1:npops) {
|
||||||
inds2 <- find(PARTITION == pop)
|
inds2 <- matlab2r::find(PARTITION == pop)
|
||||||
ninds2 <- length(inds2)
|
ninds2 <- length(inds2)
|
||||||
if (ninds2 > 2) {
|
if (ninds2 > 2) {
|
||||||
dist2 <- laskeOsaDist(inds2, dist, ninds)
|
dist2 <- laskeOsaDist(inds2, dist, ninds)
|
||||||
Z2 <- linkage(t(dist2))
|
Z2 <- linkage(t(dist2))
|
||||||
if (round == 3) {
|
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) {
|
} else if (round == 4) {
|
||||||
npops2 <- 2 # Moneenko osaan jaetaan
|
npops2 <- 2 # Moneenko osaan jaetaan
|
||||||
}
|
}
|
||||||
|
|
@ -247,13 +247,13 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
muutokset <- laskeMuutokset3(
|
muutokset <- laskeMuutokset3(
|
||||||
T2, inds2, rows, data, adjprior, priorTerm, pop
|
T2, inds2, rows, data, adjprior, priorTerm, pop
|
||||||
)
|
)
|
||||||
isoin <- max_MATLAB(muutokset)[[1]]
|
isoin <- matlab2r::max(muutokset)[[1]]
|
||||||
indeksi <- max_MATLAB(muutokset)[[2]]
|
indeksi <- matlab2r::max(muutokset)[[2]]
|
||||||
if (isoin > maxMuutos) {
|
if (isoin > maxMuutos) {
|
||||||
maxMuutos <- isoin
|
maxMuutos <- isoin
|
||||||
muuttuvaPop2 <- indeksi %% npops2
|
muuttuvaPop2 <- indeksi %% npops2
|
||||||
if (muuttuvaPop2 == 0) muuttuvaPop2 <- npops2
|
if (muuttuvaPop2 == 0) muuttuvaPop2 <- npops2
|
||||||
muuttuvat <- inds2[find(T2 == muuttuvaPop2)]
|
muuttuvat <- inds2[matlab2r::find(T2 == muuttuvaPop2)]
|
||||||
i2 <- ceiling(indeksi / npops2)
|
i2 <- ceiling(indeksi / npops2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -289,8 +289,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
partitionSummary <- temp_addToSum$partitionSummary
|
partitionSummary <- temp_addToSum$partitionSummary
|
||||||
added <- temp_addToSum$added
|
added <- temp_addToSum$added
|
||||||
if (added == 1) {
|
if (added == 1) {
|
||||||
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
|
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
|
||||||
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
|
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -310,7 +310,7 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
j <- j + 1
|
j <- j + 1
|
||||||
pop <- pops[j]
|
pop <- pops[j]
|
||||||
totalMuutos <- 0
|
totalMuutos <- 0
|
||||||
inds <- find(PARTITION == pop)
|
inds <- matlab2r::find(PARTITION == pop)
|
||||||
if (round == 5) {
|
if (round == 5) {
|
||||||
aputaulu <- c(inds, rand(length(inds), 1))
|
aputaulu <- c(inds, rand(length(inds), 1))
|
||||||
aputaulu <- sortrows(aputaulu, 2)
|
aputaulu <- sortrows(aputaulu, 2)
|
||||||
|
|
@ -334,8 +334,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
diffInCounts <- muutokset_diffInCounts$diffInCounts
|
diffInCounts <- muutokset_diffInCounts$diffInCounts
|
||||||
|
|
||||||
muutokset[pop] <- -1e50 # Varmasti ei suurin!!!
|
muutokset[pop] <- -1e50 # Varmasti ei suurin!!!
|
||||||
maxMuutos <- max_MATLAB(muutokset)[[1]]
|
maxMuutos <- matlab2r::max(muutokset)[[1]]
|
||||||
i2 <- max_MATLAB(muutokset)[[2]]
|
i2 <- matlab2r::max(muutokset)[[2]]
|
||||||
updateGlobalVariables(
|
updateGlobalVariables(
|
||||||
ind, i2, diffInCounts, adjprior, priorTerm
|
ind, i2, diffInCounts, adjprior, priorTerm
|
||||||
)
|
)
|
||||||
|
|
@ -370,8 +370,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
partitionSummary <- temp_addToSum$partitionSummary
|
partitionSummary <- temp_addToSum$partitionSummary
|
||||||
added <- temp_addToSum$added
|
added <- temp_addToSum$added
|
||||||
if (added == 1) {
|
if (added == 1) {
|
||||||
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
|
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
|
||||||
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
|
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -398,7 +398,7 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
while (j < npops) {
|
while (j < npops) {
|
||||||
j <- j + 1
|
j <- j + 1
|
||||||
pop <- pops[j]
|
pop <- pops[j]
|
||||||
inds2 <- find(PARTITION == pop)
|
inds2 <- matlab2r::find(PARTITION == pop)
|
||||||
ninds2 <- length(inds2)
|
ninds2 <- length(inds2)
|
||||||
if (ninds2 > 5) {
|
if (ninds2 > 5) {
|
||||||
partition <- PARTITION
|
partition <- PARTITION
|
||||||
|
|
@ -410,7 +410,7 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
dist2 <- laskeOsaDist(inds2, dist, ninds)
|
dist2 <- laskeOsaDist(inds2, dist, ninds)
|
||||||
Z2 <- linkage(t(dist2))
|
Z2 <- linkage(t(dist2))
|
||||||
T2 <- cluster_own(Z2, 2)
|
T2 <- cluster_own(Z2, 2)
|
||||||
muuttuvat <- inds2[find(T2 == 1)]
|
muuttuvat <- inds2[matlab2r::find(T2 == 1)]
|
||||||
|
|
||||||
muutokset <- laskeMuutokset3(
|
muutokset <- laskeMuutokset3(
|
||||||
T2, inds2, rows, data, adjprior, priorTerm, pop
|
T2, inds2, rows, data, adjprior, priorTerm, pop
|
||||||
|
|
@ -441,7 +441,7 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
pop, emptyPop
|
pop, emptyPop
|
||||||
)
|
)
|
||||||
|
|
||||||
maxMuutos <- indeksi <- max_MATLAB(muutokset)
|
maxMuutos <- indeksi <- matlab2r::max(muutokset)
|
||||||
|
|
||||||
muuttuva <- inds2(indeksi)
|
muuttuva <- inds2(indeksi)
|
||||||
if (PARTITION(muuttuva) == pop) {
|
if (PARTITION(muuttuva) == pop) {
|
||||||
|
|
@ -474,8 +474,8 @@ indMix <- function(c, npops, dispText = TRUE) {
|
||||||
partitionSummary <- temp_addToSum$partitionSummary
|
partitionSummary <- temp_addToSum$partitionSummary
|
||||||
added <- temp_addToSum$added
|
added <- temp_addToSum$added
|
||||||
if (added == 1) {
|
if (added == 1) {
|
||||||
worstLogml <- min_MATLAB(partitionSummary[, 2])[[1]]
|
worstLogml <- matlab2r::min(partitionSummary[, 2])[[1]]
|
||||||
worstIndex <- min_MATLAB(partitionSummary[, 2])[[2]]
|
worstIndex <- matlab2r::min(partitionSummary[, 2])[[2]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (muutoksiaNyt == 0) {
|
if (muutoksiaNyt == 0) {
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@ initialCounts <- function(partition, data, npops, rows, noalle, adjprior) {
|
||||||
ninds <- size(rows, 1)
|
ninds <- size(rows, 1)
|
||||||
|
|
||||||
koot <- rows[, 1] - rows[, 2] + 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)
|
sumcounts <- zeros(npops, nloci)
|
||||||
for (i in 1:npops) {
|
for (i in 1:npops) {
|
||||||
for (j in 1:nloci) {
|
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)
|
sumcounts[i, j] <- length(havainnotLokuksessa)
|
||||||
for (k in 1:noalle[j]) {
|
for (k in 1:noalle[j]) {
|
||||||
alleleCode <- k
|
alleleCode <- k
|
||||||
N_ijk <- length(
|
N_ijk <- length(
|
||||||
find(data[havainnotLokuksessa, j] == alleleCode)
|
matlab2r::find(data[havainnotLokuksessa, j] == alleleCode)
|
||||||
)
|
)
|
||||||
counts[k, j, i] <- N_ijk
|
counts[k, j, i] <- N_ijk
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
initialPopCounts <- function(data, npops, rows, noalle, adjprior) {
|
initialPopCounts <- function(data, npops, rows, noalle, adjprior) {
|
||||||
nloci <- size(data, 2)
|
nloci <- size(data, 2)
|
||||||
counts <- zeros(max(noalle), nloci, npops)
|
counts <- zeros(base::max(noalle), nloci, npops)
|
||||||
sumcounts <- zeros(npops, nloci)
|
sumcounts <- zeros(npops, nloci)
|
||||||
|
|
||||||
for (i in 1:npops) {
|
for (i in 1:npops) {
|
||||||
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 <- matlab2r::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(matlab2r::find(data[i_rivit, j] == alleleCode))
|
||||||
counts[k, j, i] <- N_ijk
|
counts[k, j, i] <- N_ijk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ laskeMuutokset <- function(ind, globalRows, data, adjprior, priorTerm) {
|
||||||
COUNTS[, , i1] <- COUNTS[, , i1] + diffInCounts
|
COUNTS[, , i1] <- COUNTS[, , i1] + diffInCounts
|
||||||
SUMCOUNTS[i1, ] <- SUMCOUNTS[i1, ] + diffInSumCounts
|
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 <- setdiff(i2, i1)
|
||||||
i2_logml <- POP_LOGML[i2]
|
i2_logml <- POP_LOGML[i2]
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ laskeMuutokset2 <- function(i1, globalRows, data, adjprior, priorTerm) {
|
||||||
|
|
||||||
i1_logml <- POP_LOGML[i1]
|
i1_logml <- POP_LOGML[i1]
|
||||||
|
|
||||||
inds <- find(PARTITION == i1)
|
inds <- matlab2r::find(PARTITION == i1)
|
||||||
ninds <- length(inds)
|
ninds <- length(inds)
|
||||||
|
|
||||||
if (ninds == 0) {
|
if (ninds == 0) {
|
||||||
|
|
@ -138,7 +138,7 @@ laskeMuutokset2 <- function(i1, globalRows, data, adjprior, priorTerm) {
|
||||||
laskeMuutokset3 <- function(T2, inds2, globalRows, data, adjprior, priorTerm, i1) {
|
laskeMuutokset3 <- function(T2, inds2, globalRows, data, adjprior, priorTerm, i1) {
|
||||||
# Palauttaa length(unique(T2))*npops taulun, jossa (i,j):s alkio
|
# Palauttaa length(unique(T2))*npops taulun, jossa (i,j):s alkio
|
||||||
# kertoo, mik<69> olisi muutos logml:ss<73>, jos populaation i1 osapopulaatio
|
# 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)
|
npops <- size(COUNTS, 3)
|
||||||
npops2 <- length(unique(T2))
|
npops2 <- length(unique(T2))
|
||||||
|
|
@ -146,7 +146,7 @@ laskeMuutokset3 <- function(T2, inds2, globalRows, data, adjprior, priorTerm, i1
|
||||||
|
|
||||||
i1_logml <- POP_LOGML[i1]
|
i1_logml <- POP_LOGML[i1]
|
||||||
for (pop2 in 1:npops2) {
|
for (pop2 in 1:npops2) {
|
||||||
inds <- inds2[find(T2 == pop2)]
|
inds <- inds2[matlab2r::find(T2 == pop2)]
|
||||||
ninds <- length(inds)
|
ninds <- length(inds)
|
||||||
if (ninds > 0) {
|
if (ninds > 0) {
|
||||||
rows <- list()
|
rows <- list()
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ learn_partition_modified <- function(ordered) {
|
||||||
part <- learn_simple_partition(ordered, 0.05)
|
part <- learn_simple_partition(ordered, 0.05)
|
||||||
nclust <- length(unique(part))
|
nclust <- length(unique(part))
|
||||||
if (nclust == 3) {
|
if (nclust == 3) {
|
||||||
mini_1 <- min(ordered(which(part == 1)))
|
mini_1 <- base::ordered(which(part == 1))
|
||||||
mini_2 <- min(ordered(which(part == 2)))
|
mini_2 <- base::min(ordered(which(part == 2)))
|
||||||
mini_3 <- min(ordered(which(part == 3)))
|
mini_3 <- base::min(ordered(which(part == 3)))
|
||||||
if (mini_1 > 0.9 & mini_2 > 0.9) {
|
if (mini_1 > 0.9 & mini_2 > 0.9) {
|
||||||
part[part == 2] <- 1
|
part[part == 2] <- 1
|
||||||
part[part == 3] <- 2
|
part[part == 3] <- 2
|
||||||
|
|
|
||||||
19
R/linkage.R
19
R/linkage.R
|
|
@ -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.
|
#' 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 Y matrix
|
||||||
#' @param method either 'si', 'av', 'co' 'ce' or 'wa'
|
#' @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
|
#' @export
|
||||||
linkage <- function(Y, method = "co") {
|
linkage <- function(Y, method = "co") {
|
||||||
# TODO: compare R output with MATLAB output
|
|
||||||
k <- size(Y)[1]
|
k <- size(Y)[1]
|
||||||
n <- size(Y)[2]
|
n <- size(Y)[2]
|
||||||
m <- (1 + sqrt(1 + 8 * n)) / 2
|
m <- (1 + sqrt(1 + 8 * n)) / 2
|
||||||
if ((k != 1) | (m != trunc(m))) {
|
if ((k != 1) | (m != trunc(m))) {
|
||||||
stop(
|
stop(
|
||||||
"The first input has to match the output",
|
"The first input has to match the output of the PDIST function in size."
|
||||||
"of the PDIST function in size."
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
method <- tolower(substr(method, 1, 2)) # simplify the switch string.
|
method <- tolower(substr(method, 1, 2)) # simplify the switch string.
|
||||||
|
|
@ -30,9 +32,8 @@ linkage <- function(Y, method = "co") {
|
||||||
R <- 1:n
|
R <- 1:n
|
||||||
for (s in 1:(n - 1)) {
|
for (s in 1:(n - 1)) {
|
||||||
X <- as.matrix(as.vector(Y), ncol = 1)
|
X <- as.matrix(as.vector(Y), ncol = 1)
|
||||||
|
v <- matlab2r::min(X)$mins
|
||||||
v <- min_MATLAB(X)$mins
|
k <- matlab2r::min(X)$idx
|
||||||
k <- min_MATLAB(X)$idx
|
|
||||||
|
|
||||||
i <- floor(m + 1 / 2 - sqrt(m^2 - m + 1 / 4 - 2 * (k - 1)))
|
i <- floor(m + 1 / 2 - sqrt(m^2 - m + 1 / 4 - 2 * (k - 1)))
|
||||||
j <- k - (i - 1) * (m - i / 2) + i
|
j <- k - (i - 1) * (m - i / 2) + i
|
||||||
|
|
@ -70,9 +71,9 @@ linkage <- function(Y, method = "co") {
|
||||||
# I <- I[I > 0 & I <= length(Y)]
|
# I <- I[I > 0 & I <= length(Y)]
|
||||||
# J <- J[J > 0 & J <= length(Y)]
|
# J <- J[J > 0 & J <= length(Y)]
|
||||||
switch(method,
|
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
|
"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" = {
|
"ce" = {
|
||||||
K <- N[R[i]] + N[R[j]] # centroid linkage
|
K <- N[R[i]] + N[R[j]] # centroid linkage
|
||||||
Y[I] <- (N[R[i]] * Y[I] + N[R[j]] * Y[J] -
|
Y[I] <- (N[R[i]] * Y[I] + N[R[j]] * Y[J] -
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
newGetDistances <- function(data, rowsFromInd) {
|
newGetDistances <- function(data, rowsFromInd) {
|
||||||
ninds <- max(data[, ncol(data)])
|
ninds <- base::max(data[, ncol(data)])
|
||||||
nloci <- size(data, 2) - 1
|
nloci <- size(data, 2) - 1
|
||||||
riviLkm <- choose(ninds, 2)
|
riviLkm <- choose(ninds, 2)
|
||||||
|
|
||||||
empties <- find(data < 0)
|
empties <- matlab2r::find(data < 0)
|
||||||
data[empties] <- 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)
|
pariTaulu <- zeros(riviLkm, 2)
|
||||||
aPointer <- 1
|
aPointer <- 1
|
||||||
|
|
@ -51,10 +51,10 @@ newGetDistances <- function(data, rowsFromInd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rm(x, y, vertailutNyt)
|
rm(x, y, vertailutNyt)
|
||||||
nollat <- find(vertailuja == 0)
|
nollat <- matlab2r::find(vertailuja == 0)
|
||||||
dist <- zeros(length(vertailuja), 1)
|
dist <- zeros(length(vertailuja), 1)
|
||||||
dist[nollat] <- 1
|
dist[nollat] <- 1
|
||||||
muut <- find(vertailuja > 0)
|
muut <- matlab2r::find(vertailuja > 0)
|
||||||
dist[muut] <- summa[muut] / vertailuja[muut]
|
dist[muut] <- summa[muut] / vertailuja[muut]
|
||||||
rm(summa, vertailuja)
|
rm(summa, vertailuja)
|
||||||
Z <- linkage(t(dist))
|
Z <- linkage(t(dist))
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
poistaTyhjatPopulaatiot <- function(npops) {
|
poistaTyhjatPopulaatiot <- function(npops) {
|
||||||
# % Poistaa tyhjentyneet populaatiot COUNTS:ista ja
|
# % Poistaa tyhjentyneet populaatiot COUNTS:ista ja
|
||||||
# % SUMCOUNTS:ista. P<>ivitt<74><74> npops:in ja PARTITION:in.
|
# % 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]
|
COUNTS <- COUNTS[, , notEmpty]
|
||||||
SUMCOUNTS <- SUMCOUNTS[notEmpty, ]
|
SUMCOUNTS <- SUMCOUNTS[notEmpty, ]
|
||||||
LOGDIFF <- LOGDIFF[, notEmpty]
|
LOGDIFF <- LOGDIFF[, notEmpty]
|
||||||
|
|
||||||
for (n in 1:length(notEmpty)) {
|
for (n in 1:length(notEmpty)) {
|
||||||
apu <- find(PARTITION == notEmpty(n))
|
apu <- matlab2r::find(PARTITION == notEmpty(n))
|
||||||
PARTITION[apu] <- n
|
PARTITION[apu] <- n
|
||||||
}
|
}
|
||||||
npops <- length(notEmpty)
|
npops <- length(notEmpty)
|
||||||
|
|
|
||||||
10
R/rBAPS-package.R
Normal file
10
R/rBAPS-package.R
Normal 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
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
rand_disc <- function(CDF) {
|
rand_disc <- function(CDF) {
|
||||||
# %returns an index of a value from a discrete distribution using inversion method
|
# %returns an index of a value from a discrete distribution using inversion method
|
||||||
slump <- rand
|
slump <- rand
|
||||||
har <- find(CDF > slump)
|
har <- matlab2r::find(CDF > slump)
|
||||||
svar <- har(1)
|
svar <- har(1)
|
||||||
return(svar)
|
return(svar)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,6 @@ simuloiAlleeli <- function(allfreqs, pop, loc) {
|
||||||
cumsumma <- cumsum(freqs)
|
cumsumma <- cumsum(freqs)
|
||||||
arvo <- runif(1)
|
arvo <- runif(1)
|
||||||
isommat <- which(cumsumma > arvo)
|
isommat <- which(cumsumma > arvo)
|
||||||
all <- min(isommat)
|
all <- base::min(isommat)
|
||||||
return(all)
|
return(all)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ testaaOnkoKunnollinenBapsData <- function(data) {
|
||||||
return(ninds)
|
return(ninds)
|
||||||
}
|
}
|
||||||
lastCol <- data[, ncol(data)]
|
lastCol <- data[, ncol(data)]
|
||||||
ninds <- max(lastCol)
|
ninds <- base::max(lastCol)
|
||||||
if (any(1:ninds != unique(lastCol))) {
|
if (any(1:ninds != unique(lastCol))) {
|
||||||
ninds <- 0
|
ninds <- 0
|
||||||
return(ninds)
|
return(ninds)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ updateGlobalVariables <- function(ind, i2, diffInCounts, adjprior, priorTerm) {
|
||||||
)
|
)
|
||||||
|
|
||||||
LOGDIFF[, c(i1, i2)] <- -Inf
|
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
|
LOGDIFF[inx, ] <- -Inf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ updateGlobalVariables2 <- function(i1, i2, diffInCounts, adjprior, priorTerm) {
|
||||||
# % Suorittaa globaalien muuttujien muutokset, kun kaikki
|
# % Suorittaa globaalien muuttujien muutokset, kun kaikki
|
||||||
# % korissa i1 olevat yksil<69>t siirret<65><74>n koriin i2.
|
# % korissa i1 olevat yksil<69>t siirret<65><74>n koriin i2.
|
||||||
|
|
||||||
inds <- find(PARTITION == i1)
|
inds <- matlab2r::find(PARTITION == i1)
|
||||||
PARTITION[inds] <- i2
|
PARTITION[inds] <- i2
|
||||||
|
|
||||||
COUNTS[, , i1] <- COUNTS[, , i1] - diffInCounts
|
COUNTS[, , i1] <- COUNTS[, , i1] - diffInCounts
|
||||||
|
|
@ -34,7 +34,7 @@ updateGlobalVariables2 <- function(i1, i2, diffInCounts, adjprior, priorTerm) {
|
||||||
POP_LOGML[i2] <- computePopulationLogml(i2, adjprior, priorTerm)
|
POP_LOGML[i2] <- computePopulationLogml(i2, adjprior, priorTerm)
|
||||||
|
|
||||||
LOGDIFF[, c(i1, i2)] <- -Inf
|
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
|
LOGDIFF[inx, ] <- -Inf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,6 +56,6 @@ updateGlobalVariables3 <- function(muuttuvat, diffInCounts, adjprior, priorTerm,
|
||||||
)
|
)
|
||||||
|
|
||||||
LOGDIFF[, c(i1, i2)] <- -Inf
|
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
|
LOGDIFF[inx, ] <- -Inf
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
|
||||||
append(fid, c("Best Partition: ", "\n"))
|
append(fid, c("Best Partition: ", "\n"))
|
||||||
}
|
}
|
||||||
for (m in 1:cluster_count) {
|
for (m in 1:cluster_count) {
|
||||||
indsInM <- find(PARTITION == m)
|
indsInM <- matlab2r::find(PARTITION == m)
|
||||||
length_of_beginning <- 11 + floor(log10(m))
|
length_of_beginning <- 11 + floor(log10(m))
|
||||||
cluster_size <- length(indsInM)
|
cluster_size <- length(indsInM)
|
||||||
|
|
||||||
|
|
@ -139,8 +139,8 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
|
||||||
nimi <- as.character(popnames[i])
|
nimi <- as.character(popnames[i])
|
||||||
nameSizes[i] <- length(nimi)
|
nameSizes[i] <- length(nimi)
|
||||||
}
|
}
|
||||||
maxSize <- max(nameSizes)
|
maxSize <- base::max(nameSizes)
|
||||||
maxSize <- max(maxSize, 5)
|
maxSize <- base::max(maxSize, 5)
|
||||||
erotus <- maxSize - 5
|
erotus <- maxSize - 5
|
||||||
alku <- blanks(erotus)
|
alku <- blanks(erotus)
|
||||||
ekarivi <- c(alku, " ind", blanks(6 + erotus))
|
ekarivi <- c(alku, " ind", blanks(6 + erotus))
|
||||||
|
|
@ -193,8 +193,8 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
|
||||||
nloci <- size(COUNTS, 2)
|
nloci <- size(COUNTS, 2)
|
||||||
d <- zeros(maxnoalle, nloci, npops)
|
d <- zeros(maxnoalle, nloci, npops)
|
||||||
prior <- adjprior
|
prior <- adjprior
|
||||||
prior[find(prior == 1)] <- 0
|
prior[matlab2r::find(prior == 1)] <- 0
|
||||||
nollia <- find(all(prior == 0)) # Loci in which only one allele was detected.
|
nollia <- matlab2r::find(all(prior == 0)) # Loci in which only one allele was detected.
|
||||||
prior[1, nollia] <- 1
|
prior[1, nollia] <- 1
|
||||||
for (pop1 in 1:npops) {
|
for (pop1 in 1:npops) {
|
||||||
d[, , pop1] <- (squeeze(COUNTS[, , pop1]) + prior) /
|
d[, , pop1] <- (squeeze(COUNTS[, , pop1]) + prior) /
|
||||||
|
|
@ -261,7 +261,7 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
|
||||||
|
|
||||||
partitionSummary <- sortrows(partitionSummary, 2)
|
partitionSummary <- sortrows(partitionSummary, 2)
|
||||||
partitionSummary <- partitionSummary[size(partitionSummary, 1):1, ]
|
partitionSummary <- partitionSummary[size(partitionSummary, 1):1, ]
|
||||||
partitionSummary <- partitionSummary[find(partitionSummary[, 2] > -1e49), ]
|
partitionSummary <- partitionSummary[matlab2r::find(partitionSummary[, 2] > -1e49), ]
|
||||||
if (size(partitionSummary, 1) > 10) {
|
if (size(partitionSummary, 1) > 10) {
|
||||||
vikaPartitio <- 10
|
vikaPartitio <- 10
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -298,12 +298,12 @@ writeMixtureInfo <- function(logml, rowsFromInd, data, adjprior, priorTerm, outP
|
||||||
len <- length(npopsTaulu)
|
len <- length(npopsTaulu)
|
||||||
probs <- zeros(len, 1)
|
probs <- zeros(len, 1)
|
||||||
partitionSummary[, 2] <- partitionSummary[, 2] -
|
partitionSummary[, 2] <- partitionSummary[, 2] -
|
||||||
max(partitionSummary[, 2])
|
base::max(partitionSummary[, 2])
|
||||||
sumtn <- sum(exp(partitionSummary[, 2]))
|
sumtn <- sum(exp(partitionSummary[, 2]))
|
||||||
for (i in 1:len) {
|
for (i in 1:len) {
|
||||||
npopstn <- sum(
|
npopstn <- sum(
|
||||||
exp(
|
exp(
|
||||||
partitionSummary[find(
|
partitionSummary[matlab2r::find(
|
||||||
partitionSummary[, 1] == npopsTaulu[i]
|
partitionSummary[, 1] == npopsTaulu[i]
|
||||||
), 2]
|
), 2]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
11
README.md
11
README.md
|
|
@ -1,8 +1,9 @@
|
||||||
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
|
[](https://www.repostatus.org/#wip)
|
||||||
[](https://github.com/ocbe-uio/rBAPS/commits/master)
|
[](https://github.com/ocbe-uio/rBAPS/commits/master)
|
||||||
[](https://github.com/ocbe-uio/rBAPS)
|
[](https://github.com/ocbe-uio/rBAPS)
|
||||||
[](https://github.com/ocbe-uio/rBAPS/actions)
|
[](https://github.com/ocbe-uio/rBAPS/actions)
|
||||||
[](https://codecov.io/gh/ocbe-uio/rBAPS)
|
[](https://codecov.io/gh/ocbe-uio/rBAPS)
|
||||||
|
[](https://www.codefactor.io/repository/github/ocbe-uio/rBAPS)
|
||||||
|
|
||||||
# rBAPS
|
# rBAPS
|
||||||
R implementation of the compiled Matlab BAPS software for Bayesian Analysis of Population Structure.
|
R implementation of the compiled Matlab BAPS software for Bayesian Analysis of Population Structure.
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
24
man/cell.Rd
24
man/cell.Rd
|
|
@ -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
|
|
||||||
}
|
|
||||||
16
man/colon.Rd
16
man/colon.Rd
|
|
@ -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.
|
|
||||||
}
|
|
||||||
16
man/find.Rd
16
man/find.Rd
|
|
@ -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`
|
|
||||||
}
|
|
||||||
17
man/fix.Rd
17
man/fix.Rd
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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)
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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.
|
Z = linkage(X) returns a matrix Z that encodes a tree containing hierarchical clusters of the rows of the input data matrix X.
|
||||||
}
|
}
|
||||||
\note{
|
\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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
19
man/ones.Rd
19
man/ones.Rd
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
14
man/rBAPS.Rd
Normal 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.
|
||||||
|
}
|
||||||
19
man/rand.Rd
19
man/rand.Rd
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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.
|
|
||||||
}
|
|
||||||
|
|
@ -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.
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
23
man/size.Rd
23
man/size.Rd
|
|
@ -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.
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
22
man/times.Rd
22
man/times.Rd
|
|
@ -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.
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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.
|
|
||||||
}
|
|
||||||
19
man/zeros.Rd
19
man/zeros.Rd
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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.
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue