Added translation of admix

This commit is contained in:
Waldir Leoncio 2020-03-18 14:50:33 +01:00
parent 25cbfe4ed3
commit 76c408613d

View file

@ -1,49 +1,64 @@
#' @title Admixture analysis #' @title Admixture analysis
#' @param tietue record #' @param tietue a named record list
#' @details If the record == -1, the mixture results file is loaded. Otherwise, will the required variables be retrieved from the record fields? #' @details If the record == -1, the mixture results file is loaded. Otherwise,
#' will the required variables be retrieved from the record fields?
#' `tietue`should contain the following elements: PARTITION, COUNTS, SUMCOUNTS,
#' alleleCodes, adjprior, popnames, rowsFromInd, data, npops, noalle
#' @export #' @export
admix1 <- function(tietue) { admix1 <- function(tietue, PARTITION = matrix(NA, 0, 0),
COUNTS = matrix(NA, 0, 0), SUMCOUNTS = NA) {
if (!is.list(tietue)) { if (!is.list(tietue)) {
# c(filename, pathname) = uigetfile('*.mat', 'Load mixture result file'); message('Load mixture result file. These are the files in this directory:')
# if (filename==0 & pathname==0), return; print(list.files())
# else pathname_filename <- file.choose()
# disp('---------------------------------------------------'); if (!file.exists(pathname_filename)) {
# disp(['Reading mixture result from: ',[pathname filename],'...']); stop(
# end "File ", pathname_filename,
# pause(0.0001); " does not exist. Check spelling and location."
)
} else {
cat('---------------------------------------------------\n');
message('Reading mixture result from: ', pathname_filename, '...')
}
sys.sleep(0.0001) #ASK: what for?
# ASK: what is this supposed to do? What do graphic obj have to do here?
# h0 = findobj('Tag','filename1_text'); # h0 = findobj('Tag','filename1_text');
# set(h0,'String',filename); clear h0; # set(h0,'String',filename); clear h0;
# struct_array = load([pathname filename]); struct_array <- load(pathname_filename)
# if isfield(struct_array,'c') #Matlab versio if (isfield(struct_array, 'c')) { #Matlab versio
# c = struct_array.c; c <- struct_array$c
# if ~isfield(c,'PARTITION') | ~isfield(c,'rowsFromInd') if (!isfield(c, 'PARTITION') | !isfield(c,'rowsFromInd')) {
# disp('Incorrect file format'); stop('Incorrect file format')
# return }
# end } else if (isfield(struct_array, 'PARTITION')) { #Mideva versio
# elseif isfield(struct_array,'PARTITION') #Mideva versio c <- struct_array
# c = struct_array; if (!isfield(c,'rowsFromInd')) stop('Incorrect file format')
# if ~isfield(c,'rowsFromInd') } else {
# disp('Incorrect file format'); stop('Incorrect file format')
# return }
# end
# else
# disp('Incorrect file format');
# return;
# end
# if isfield(c, 'gene_lengths') && ... if (isfield(c, 'gene_lengths') &
# (strcmp(c.mixtureType,'linear_mix') | ... strcmp(c$mixtureType, 'linear_mix') |
# strcmp(c.mixtureType,'codon_mix')) # if the mixture is from a linkage model strcmp(c$mixtureType, 'codon_mix')) { # if the mixture is from a linkage model
# # Redirect the call to the linkage admixture function. # Redirect the call to the linkage admixture function.
# c.data = noIndex(c.data,c.noalle); # call function noindex to remove the index column # call function noindex to remove the index column
# linkage_admix(c); c$data <- noIndex(c$data, c$noalle)
# linkage_admix(c) # ASK: translate this function to R or drop?
# return # return
# end stop("linkage_admix not implemented")
}
# PARTITION = c.PARTITION; COUNTS = c.COUNTS; SUMCOUNTS = c.SUMCOUNTS; PARTITION <- c$PARTITION
# alleleCodes = c.alleleCodes; adjprior = c.adjprior; popnames = c.popnames; COUNTS <- c$COUNTS
# rowsFromInd = c.rowsFromInd; data = c.data; npops = c.npops; noalle = c.noalle; SUMCOUNTS <- c$SUMCOUNTS
alleleCodes <- c$alleleCodes
adjprior <- c$adjprior
popnames <- c$popnames
rowsFromInd <- c$rowsFromInd
data <- c$data
npops <- c$npops
noalle <- c$noalle
} else { } else {
PARTITION <- tietue$PARTITION PARTITION <- tietue$PARTITION
COUNTS <- tietue$COUNTS COUNTS <- tietue$COUNTS
@ -57,297 +72,334 @@ admix1 <- function(tietue) {
noalle <- tietue$noalle noalle <- tietue$noalle
} }
# answers = inputdlg({['Input the minimum size of a population that will'... answers <- inputdlg(
# ' be taken into account when admixture is estimated.']},... prompt = paste(
# 'Input minimum population size',[1],... "Input the minimum size of a population that will",
# {'5'}); "be taken into account when admixture is estimated."
# if isempty(answers) return; end ),
# alaRaja = str2num(answers{1,1}); definput = 5
# [npops] = poistaLiianPienet(npops, rowsFromInd, alaRaja); )
alaRaja <- as.num(answers)
npops <- poistaLiianPienet(npops, rowsFromInd, alaRaja)
# nloci = size(COUNTS,2); nloci <- size(COUNTS, 2)
# ninds = size(data,1)/rowsFromInd; ninds <- size(data, 1) / rowsFromInd
# answers = inputdlg({['Input number of iterations']},'Input',[1],{'50'}); answers <- inputdlg('Input number of iterations', 50)
# if isempty(answers) return; end if (isempty(answers)) return()
# iterationCount = str2num(answers{1,1}); iterationCount <- as.numeric(answers[1, 1]) # maybe [[]]?
# answers = inputdlg({['Input number of reference individuals from each population']},'Input',[1],{'50'}); answers <- inputdlg(
# if isempty(answers) nrefIndsInPop = 50; prompt = 'Input number of reference individuals from each population',
# else nrefIndsInPop = str2num(answers{1,1}); definput = 50
# end )
if (isempty(answers)) {
# answers = inputdlg({['Input number of iterations for reference individuals']},'Input',[1],{'10'}); nrefIndsInPop <- 50
# if isempty(answers) return; end } else {
# iterationCountRef = str2num(answers{1,1}); nrefIndsInPop <- as.numeric(answers[1, 1])
}
# # First calculate log-likelihood ratio for all individuals: answers <- inputdlg(
# likelihood = zeros(ninds,1); prompt = 'Input number of iterations for reference individuals',
# allfreqs = computeAllFreqs2(noalle); definput = 10
# for ind = 1:ninds )
# omaFreqs = computePersonalAllFreqs(ind, data, allfreqs, rowsFromInd); if (isempty(answers)) return()
# osuusTaulu = zeros(1,npops); iterationCountRef <- as.numeric(answers[1, 1])
# if PARTITION(ind)==0
# # Yksil?on outlier # First calculate log-likelihood ratio for all individuals:
# elseif PARTITION(ind)~=0 likelihood <- zeros(ninds, 1)
# if PARTITION(ind)>0 allfreqs <- computeAllFreqs2(noalle)
# osuusTaulu(PARTITION(ind)) = 1; for (ind in 1:ninds) {
# else omaFreqs <- computePersonalAllFreqs(ind, data, allfreqs, rowsFromInd)
# # Yksilöt, joita ei ole sijoitettu mihinkään koriin. osuusTaulu <- zeros(1, npops)
# arvot = zeros(1,npops); if (PARTITION[ind] == 0) {
# for q=1:npops # Yksil?on outlier
# osuusTaulu = zeros(1,npops); } else if (PARTITION[ind] != 0) {
# osuusTaulu(q) = 1; if (PARTITION[ind] > 0) {
# arvot(q) = computeIndLogml(omaFreqs, osuusTaulu); osuusTaulu(PARTITION[ind]) <- 1
# end } else {
# [iso_arvo, isoimman_indeksi] = max(arvot); # Yksilöt, joita ei ole sijoitettu mihinkään koriin.
# osuusTaulu = zeros(1,npops); arvot <- zeros(1, npops)
# osuusTaulu(isoimman_indeksi) = 1; for (q in 1:npops) {
# PARTITION(ind)=isoimman_indeksi; osuusTaulu <- zeros(1, npops)
# end osuusTaulu[q] <- 1
# logml = computeIndLogml(omaFreqs, osuusTaulu); arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
# logmlAlku = logml; }
# for osuus = [0.5 0.25 0.05 0.01] iso_arvo <- max(arvot)
# [osuusTaulu, logml] = etsiParas(osuus, osuusTaulu, omaFreqs, logml); isoimman_indeksi <- match(max(arvot), arvot)
# end osuusTaulu <- zeros(1, npops)
# logmlLoppu = logml; osuusTaulu[isoimman_indeksi] <- 1
# likelihood(ind) = logmlLoppu-logmlAlku; PARTITION[ind] <- isoimman_indeksi
# end }
# end logml <- computeIndLogml(omaFreqs, osuusTaulu)
logmlAlku <- logml
# # Analyze further only individuals who have log-likelihood ratio larger than 3: for (osuus in c(0.5, 0.25, 0.05, 0.01)) {
# to_investigate = (find(likelihood>3))'; etsiResult <- etsiParas(osuus, osuusTaulu, omaFreqs, logml)
# disp('Possibly admixed individuals: '); osuusTaulu <- etsiResult[1]
# for i = 1:length(to_investigate) logml <- etsiResult[2]
# disp(num2str(to_investigate(i))); }
# end logmlLoppu <- logml
# disp(' '); likelihood[ind] <- logmlLoppu - logmlAlku
# disp('Populations for possibly admixed individuals: '); }
# admix_populaatiot = unique(PARTITION(to_investigate)); }
# for i = 1:length(admix_populaatiot)
# disp(num2str(admix_populaatiot(i))); # Analyze further only individuals who have log-likelihood ratio larger than 3:
# end to_investigate <- t(find(likelihood > 3))
cat('Possibly admixed individuals:\n')
# # THUS, there are two types of individuals, who will not be analyzed with for (i in 1:length(to_investigate)) {
# # simulated allele frequencies: those who belonged to a mini-population cat(as.character(to_investigate[i]))
# # which was removed, and those who have log-likelihood ratio less than 3. }
# # The value in the PARTITION for the first kind of individuals is 0. The cat(' ')
# # second kind of individuals can be identified, because they do not cat('Populations for possibly admixed individuals:\n')
# # belong to "to_investigate" array. When the results are presented, the admix_populaatiot <- unique(PARTITION[to_investigate])
# # first kind of individuals are omitted completely, while the second kind for (i in 1:length(admix_populaatiot)) {
# # of individuals are completely put to the population, where they ended up cat(as.character(admix_populaatiot[i]))
# # in the mixture analysis. These second type of individuals will have a }
# # unit p-value.
# THUS, there are two types of individuals, who will not be analyzed with
# simulated allele frequencies: those who belonged to a mini-population
# # Simulate allele frequencies a given number of times and save the average # which was removed, and those who have log-likelihood ratio less than 3.
# # result to "proportionsIt" array. # The value in the PARTITION for the first kind of individuals is 0. The
# second kind of individuals can be identified, because they do not
# proportionsIt = zeros(ninds,npops); # belong to "to_investigate" array. When the results are presented, the
# for iterationNum = 1:iterationCount # first kind of individuals are omitted completely, while the second kind
# disp(['Iter: ' num2str(iterationNum)]); # of individuals are completely put to the population, where they ended up
# allfreqs = simulateAllFreqs(noalle); # Allele frequencies on this iteration. # in the mixture analysis. These second type of individuals will have a
# unit p-value.
# for ind=to_investigate
# #disp(num2str(ind));
# omaFreqs = computePersonalAllFreqs(ind, data, allfreqs, rowsFromInd); # Simulate allele frequencies a given number of times and save the average
# osuusTaulu = zeros(1,npops); # result to "proportionsIt" array.
# if PARTITION(ind)==0
# # Yksil?on outlier proportionsIt <- zeros(ninds, npops)
# elseif PARTITION(ind)~=0 for (iterationNum in 1:iterationCount) {
# if PARTITION(ind)>0 cat('Iter:', as.character(iterationNum))
# osuusTaulu(PARTITION(ind)) = 1; allfreqs <- simulateAllFreqs(noalle) # Allele frequencies on this iteration.
# else
# # Yksilöt, joita ei ole sijoitettu mihinkään koriin. for (ind in to_investigate) {
# arvot = zeros(1,npops); #disp(num2str(ind));
# for q=1:npops omaFreqs <- computePersonalAllFreqs(
# osuusTaulu = zeros(1,npops); ind, data, allfreqs, rowsFromInd
# osuusTaulu(q) = 1; )
# arvot(q) = computeIndLogml(omaFreqs, osuusTaulu); osuusTaulu = zeros(1, npops)
# end if (PARTITION[ind] == 0) {
# [iso_arvo, isoimman_indeksi] = max(arvot); # Yksil?on outlier
# osuusTaulu = zeros(1,npops); } else if (PARTITION[ind] != 0) {
# osuusTaulu(isoimman_indeksi) = 1; if (PARTITION[ind] > 0) {
# PARTITION(ind)=isoimman_indeksi; osuusTaulu(PARTITION[ind]) <- 1
# end } else {
# logml = computeIndLogml(omaFreqs, osuusTaulu); # Yksilöt, joita ei ole sijoitettu mihinkään koriin.
arvot <- zeros(1, npops)
# for osuus = [0.5 0.25 0.05 0.01] for (q in 1:npops) {
# [osuusTaulu, logml] = etsiParas(osuus, osuusTaulu, omaFreqs, logml); osuusTaulu <- zeros(1, npops)
# end osuusTaulu[q] <- 1
# end arvot[q] <- computeIndLogml(omaFreqs, osuusTaulu)
# proportionsIt(ind,:) = proportionsIt(ind,:).*(iterationNum-1) + osuusTaulu; }
# proportionsIt(ind,:) = proportionsIt(ind,:)./iterationNum; iso_arvo <- max(arvot)
# end isoimman_indeksi <- match(max(arvot), arvot)
# end osuusTaulu <- zeros(1, npops)
osuusTaulu[isoimman_indeksi] <- 1
# #disp(['Creating ' num2str(nrefIndsInPop) ' reference individuals from ']); PARTITION[ind] <- isoimman_indeksi
# #disp('each population.'); }
logml <- computeIndLogml(omaFreqs, osuusTaulu)
# #allfreqs = simulateAllFreqs(noalle); # Simuloidaan alleelifrekvenssisetti
# allfreqs = computeAllFreqs2(noalle); # Koitetaan tällaista. for (osuus in c(0.5, 0.25, 0.05, 0.01)) {
etsiResult <- etsiParas(osuus, osuusTaulu, omaFreqs, logml)
osuusTaulu <- etsiResult[1]
# # Initialize the data structures, which are required in taking the missing logml <- etsiResult[2]
# # data into account: }
# n_missing_levels = zeros(npops,1); # number of different levels of "missingness" in each pop (max 3). }
# missing_levels = zeros(npops,3); # the mean values for different levels. proportionsIt[ind, ] <- proportionsIt[ind, ] * (iterationNum - 1) +
# missing_level_partition = zeros(ninds,1); # level of each individual (one of the levels of its population). osuusTaulu
# for i=1:npops proportionsIt[ind, ] <- proportionsIt[ind, ] / iterationNum
# inds = find(PARTITION==i); }
# # Proportions of non-missing data for the individuals: }
# non_missing_data = zeros(length(inds),1);
# for j = 1:length(inds) #disp(['Creating ' num2str(nrefIndsInPop) ' reference individuals from ']);
# ind = inds(j); #disp('each population.');
# non_missing_data(j) = length(find(data((ind-1)*rowsFromInd+1:ind*rowsFromInd,:)>0)) ./ (rowsFromInd*nloci);
# end #allfreqs = simulateAllFreqs(noalle); # Simuloidaan alleelifrekvenssisetti
# if all(non_missing_data>0.9) allfreqs <- computeAllFreqs2(noalle); # Koitetaan tällaista.
# n_missing_levels(i) = 1;
# missing_levels(i,1) = mean(non_missing_data);
# missing_level_partition(inds) = 1; # Initialize the data structures, which are required in taking the missing
# else # data into account:
# [ordered, ordering] = sort(non_missing_data); n_missing_levels <- zeros(npops, 1) # number of different levels of "missingness" in each pop (max 3).
# #part = learn_simple_partition(ordered, 0.05); missing_levels <- zeros(npops, 3) # the mean values for different levels.
# part = learn_partition_modified(ordered); missing_level_partition <- zeros(ninds, 1) # level of each individual (one of the levels of its population).
# aux = sortrows([part ordering],2); for (i in 1:npops) {
# part = aux(:,1); inds <- find(PARTITION == i)
# missing_level_partition(inds) = part; # Proportions of non-missing data for the individuals:
# n_levels = length(unique(part)); non_missing_data <- zeros(length(inds), 1)
# n_missing_levels(i) = n_levels; for (j in 1:length(inds)) {
# for j=1:n_levels ind <- inds[j]
# missing_levels(i,j) = mean(non_missing_data(find(part==j))); non_missing_data[j] <- length(
# end find(data[(ind - 1) * rowsFromInd + 1:ind * rowsFromInd, ] > 0)
# end ) / (rowsFromInd * nloci)
# end }
if (all(non_missing_data > 0.9)) {
# # Create and analyse reference individuals for populations n_missing_levels[i] <- 1
# # with potentially admixed individuals: missing_levels[i, 1] <- mean(non_missing_data)
# refTaulu = zeros(npops,100,3); missing_level_partition[inds] <- 1
# for pop = admix_populaatiot' } else {
# TODO: fix syntax
# for level = 1:n_missing_levels(pop) # [ordered, ordering] = sort(non_missing_data);
ordered <- ordering <- sort(non_missing_data)
# potential_inds_in_this_pop_and_level = ... #part = learn_simple_partition(ordered, 0.05);
# find(PARTITION==pop & missing_level_partition==level &... part <- learn_partition_modified(ordered)
# likelihood>3); # Potential admix individuals here. aux <- sortrows(cbind(part, ordering), 2)
part = aux[, 1]
# if ~isempty(potential_inds_in_this_pop_and_level) missing_level_partition[inds]<- part
n_levels <- length(unique(part))
# #refData = simulateIndividuals(nrefIndsInPop,rowsFromInd,allfreqs); n_missing_levels[i] <- n_levels
# refData = simulateIndividuals(nrefIndsInPop, rowsFromInd, allfreqs, ... for (j in 1:n_levels) {
# pop, missing_levels(pop,level)); missing_levels[i, j] <- mean(non_missing_data[find(part == j)])
}
# disp(['Analysing the reference individuals from pop ' num2str(pop) ' (level ' num2str(level) ').']); }
# refProportions = zeros(nrefIndsInPop,npops); }
# for iter = 1:iterationCountRef
# #disp(['Iter: ' num2str(iter)]); # Create and analyse reference individuals for populations
# allfreqs = simulateAllFreqs(noalle); # with potentially admixed individuals:
refTaulu <- zeros(npops, 100, 3)
# for ind = 1:nrefIndsInPop for (pop in t(admix_populaatiot)) {
# omaFreqs = computePersonalAllFreqs(ind, refData, allfreqs, rowsFromInd);
# osuusTaulu = zeros(1,npops); for (level in 1:n_missing_levels[pop]) {
# osuusTaulu(pop)=1;
# logml = computeIndLogml(omaFreqs, osuusTaulu); potential_inds_in_this_pop_and_level <-
# for osuus = [0.5 0.25 0.05 0.01] find(
# [osuusTaulu, logml] = etsiParas(osuus, osuusTaulu, omaFreqs, logml); PARTITION == pop & missing_level_partition == level &
# end likelihood > 3
# refProportions(ind,:) = refProportions(ind,:).*(iter-1) + osuusTaulu; ) # Potential admix individuals here.
# refProportions(ind,:) = refProportions(ind,:)./iter;
# end if (!isempty(potential_inds_in_this_pop_and_level)) {
# end
# for ind = 1:nrefIndsInPop #refData = simulateIndividuals(nrefIndsInPop,rowsFromInd,allfreqs);
# omanOsuus = refProportions(ind,pop); refData <- simulateIndividuals(
# if round(omanOsuus*100)==0 nrefIndsInPop, rowsFromInd, allfreqs, pop,
# omanOsuus = 0.01; missing_levels[pop, level]
# end )
# if abs(omanOsuus)<1e-5
# omanOsuus = 0.01; cat(
# end 'Analysing the reference individuals from pop', pop,
# refTaulu(pop, round(omanOsuus*100),level) = refTaulu(pop, round(omanOsuus*100),level)+1; '(level', level, ').'
# end )
# end refProportions <- zeros(nrefIndsInPop, npops)
# end for (iter in 1:iterationCountRef) {
# end #disp(['Iter: ' num2str(iter)]);
allfreqs <- simulateAllFreqs(noalle)
# # Rounding of the results:
# proportionsIt = proportionsIt.*100; proportionsIt = round(proportionsIt); for (ind in 1:nrefIndsInPop) {
# proportionsIt = proportionsIt./100; omaFreqs <- computePersonalAllFreqs(
# for ind = 1:ninds ind, refData, allfreqs, rowsFromInd
# if ~any(to_investigate==ind) )
# if PARTITION(ind)>0 osuusTaulu <- zeros(1, npops)
# proportionsIt(ind,PARTITION(ind))=1; osuusTaulu[pop] <- 1
# end logml <- computeIndLogml(omaFreqs, osuusTaulu)
# else for (osuus in c(0.5, 0.25, 0.05, 0.01)) {
# # In case of a rounding error, the sum is made equal to unity by etsiResult <- etsiParas(
# # fixing the largest value. osuus, osuusTaulu, omaFreqs, logml
# if (PARTITION(ind)>0) & (sum(proportionsIt(ind,:)) ~= 1) )
# [isoin,indeksi] = max(proportionsIt(ind,:)); osuusTaulu <- etsiResult[1]
# erotus = sum(proportionsIt(ind,:))-1; logml <- etsiResult[2]
# proportionsIt(ind,indeksi) = isoin-erotus; }
# end refProportions[ind, ] <-
# end refProportions[ind, ] * (iter - 1) + osuusTaulu
# end refProportions[ind, ] <- refProportions[ind, ] / iter
}
# # Calculate p-value for each individual: }
# uskottavuus = zeros(ninds,1); for (ind in 1:nrefIndsInPop) {
# for ind = 1:ninds omanOsuus <- refProportions[ind, pop]
# pop = PARTITION(ind); if (round(omanOsuus * 100) == 0) {
# if pop==0 # Individual is outlier omanOsuus <- 0.01
# uskottavuus(ind)=1; }
# elseif isempty(find(to_investigate==ind)) if (abs(omanOsuus) < 1e-5) {
# # Individual had log-likelihood ratio<3 omanOsuus <- 0.01
# uskottavuus(ind)=1; }
# else refTaulu[pop, round(omanOsuus*100), level] <-
# omanOsuus = proportionsIt(ind,pop); refTaulu[pop, round(omanOsuus*100),level] + 1
# if abs(omanOsuus)<1e-5 }
# omanOsuus = 0.01; }
# end }
# if round(omanOsuus*100)==0 }
# omanOsuus = 0.01;
# end # Rounding of the results:
# level = missing_level_partition(ind); proportionsIt <- proportionsIt * 100
# refPienempia = sum(refTaulu(pop, 1:round(100*omanOsuus), level)); proportionsIt <- round(proportionsIt)
# uskottavuus(ind) = refPienempia / nrefIndsInPop; proportionsIt <- proportionsIt / 100
# end for (ind in 1:ninds) {
# end if (!any(to_investigate == ind)) {
if (PARTITION[ind] > 0) {
# tulostaAdmixtureTiedot(proportionsIt, uskottavuus, alaRaja, iterationCount); proportionsIt[ind, PARTITION[ind]] <- 1
}
# viewPartition(proportionsIt, popnames); } else {
# In case of a rounding error, the sum is made equal to unity by
# talle = questdlg(['Do you want to save the admixture results?'], ... # fixing the largest value.
# 'Save results?','Yes','No','Yes'); if ((PARTITION[ind] > 0) & (sum(proportionsIt[ind, ]) != 1)) {
# if isequal(talle,'Yes') isoin <- max(proportionsIt[ind, ])
# #waitALittle; indeksi <- match(isoin, max(proportionsIt[ind, ]))
# [filename, pathname] = uiputfile('*.mat','Save results as'); erotus <- sum(proportionsIt[ind, ]) - 1
proportionsIt[ind, indeksi] <- isoin - erotus
}
# if (filename == 0) & (pathname == 0) }
# # Cancel was pressed }
# return
# else # copy 'baps4_output.baps' into the text file with the same name. # Calculate p-value for each individual:
# if exist('baps4_output.baps','file') uskottavuus <- zeros(ninds, 1)
# copyfile('baps4_output.baps',[pathname filename '.txt']) for (ind in 1:ninds) {
# delete('baps4_output.baps') pop <- PARTITION[ind]
# end if (pop == 0) { # Individual is outlier
# end uskottavuus[ind] <- 1
} else if (isempty(find(to_investigate == ind))) {
# Individual had log-likelihood ratio<3
# if (~isstruct(tietue)) uskottavuus[ind] <- 1
# c.proportionsIt = proportionsIt; } else {
# c.pvalue = uskottavuus; # Added by Jing omanOsuus <- proportionsIt[ind, pop]
# c.mixtureType = 'admix'; # Jing if (abs(omanOsuus) < 1e-5) {
# c.admixnpops = npops; omanOsuus <- 0.01
# # save([pathname filename], 'c'); }
# save([pathname filename], 'c', '-v7.3'); # added by Lu Cheng, 08.06.2012 if (round(omanOsuus*100)==0) {
# else omanOsuus <- 0.01
# tietue.proportionsIt = proportionsIt; }
# tietue.pvalue = uskottavuus; # Added by Jing level <- missing_level_partition[ind]
# tietue.mixtureType = 'admix'; refPienempia <- sum(refTaulu[pop, 1:round(100*omanOsuus), level])
# tietue.admixnpops = npops; uskottavuus[ind] <- refPienempia / nrefIndsInPop
# # save([pathname filename], 'tietue'); }
# save([pathname filename], 'tietue', '-v7.3'); # added by Lu Cheng, 08.06.2012 }
# end
# end # ASK: Remove? are these plotting functions?
tulostaAdmixtureTiedot(proportionsIt, uskottavuus, alaRaja, iterationCount)
viewPartition(proportionsIt, popnames)
talle = inputdlg('Do you want to save the admixture results? [Y/n]', 'y')
if (talle %in% c('y', 'Y', 'yes', 'Yes')) {
#waitALittle;
filename <- inputdlg(
'Save results as (file name):', 'admixture_results.rda'
)
if (filename == 0) {
# Cancel was pressed
return()
} else { # copy 'baps4_output.baps' into the text file with the same name.
if (file.exists('baps4_output.baps')) {
file.copy('baps4_output.baps', paste0(filename, '.txt'))
file.remove('baps4_output.baps')
}
}
if (!isstruct(tietue)) {
c$proportionsIt <- proportionsIt
c$pvalue <- uskottavuus # Added by Jing
c$mixtureType <- 'admix' # Jing
c$admixnpops <- npops;
save(c, file=filename)
} else {
tietue$proportionsIt <- proportionsIt
tietue$pvalue <- uskottavuus; # Added by Jing
tietue$mixtureType <- 'admix'
tietue$admixnpops <- npops
save(tietue, file=filename)
}
}
} }