Merge branch 'issue-2' into develop
This commit is contained in:
commit
5be7fb6906
5 changed files with 106 additions and 81 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.9006
|
Version: 0.0.0.9007
|
||||||
Date: 2020-11-09
|
Date: 2020-11-09
|
||||||
Authors@R:
|
Authors@R:
|
||||||
c(
|
c(
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export(linkage)
|
||||||
export(load_fasta)
|
export(load_fasta)
|
||||||
export(logml2String)
|
export(logml2String)
|
||||||
export(lueGenePopData)
|
export(lueGenePopData)
|
||||||
|
export(lueGenePopDataPop)
|
||||||
export(lueNimi)
|
export(lueNimi)
|
||||||
export(noIndex)
|
export(noIndex)
|
||||||
export(ownNum2Str)
|
export(ownNum2Str)
|
||||||
|
|
|
||||||
83
R/lueGenePopDataPop.R
Normal file
83
R/lueGenePopDataPop.R
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
#' @title Read GenePop Data
|
||||||
|
#' @note The data is given in the form where the last column tells the
|
||||||
|
#' group. popnames are as before.
|
||||||
|
#' @param tiedostonNimi Name of the file
|
||||||
|
#' @return List containing data and popnames
|
||||||
|
#' @export
|
||||||
|
lueGenePopDataPop <- function(tiedostonNimi) {
|
||||||
|
# Data annetaan muodossa, jossa viimeinen sarake kertoo ryhmän.
|
||||||
|
# popnames on kuten ennenkin.
|
||||||
|
|
||||||
|
fid <- readLines(tiedostonNimi)
|
||||||
|
line <- fid[1] # ensimmäinen rivi
|
||||||
|
line <- fid[2] # toinen rivi
|
||||||
|
count <- rivinSisaltamienMjonojenLkm(line)
|
||||||
|
|
||||||
|
line <- fid[3]
|
||||||
|
lokusRiveja <- 1
|
||||||
|
while (testaaPop(line) == 0) {
|
||||||
|
lokusRiveja <- lokusRiveja + 1
|
||||||
|
line <- fid[2 + lokusRiveja]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lokusRiveja > 1) {
|
||||||
|
nloci <- lokusRiveja
|
||||||
|
} else {
|
||||||
|
nloci <- count
|
||||||
|
}
|
||||||
|
|
||||||
|
popnames <- cell(10, 2)
|
||||||
|
data <- zeros(100, nloci + 1)
|
||||||
|
nimienLkm <- 0
|
||||||
|
ninds <- 0
|
||||||
|
poimiNimi <- 1
|
||||||
|
digitFormat = -1
|
||||||
|
while (lokusRiveja < length(fid) - 2) {
|
||||||
|
lokusRiveja <- lokusRiveja + 1 # Keeps the loop moving along
|
||||||
|
line <- fid[lokusRiveja + 2]
|
||||||
|
if (poimiNimi == 1) {
|
||||||
|
# Edellinen rivi oli 'pop'
|
||||||
|
nimienLkm <- nimienLkm + 1
|
||||||
|
ninds <- ninds + 1
|
||||||
|
if (nimienLkm > size(popnames, 1)) {
|
||||||
|
popnames <- c(popnames, cell(10, 2))
|
||||||
|
}
|
||||||
|
nimi <- lueNimi(line)
|
||||||
|
if (digitFormat == -1) {
|
||||||
|
digitFormat <- selvitaDigitFormat(line)
|
||||||
|
divider <- 10 ^ digitFormat
|
||||||
|
}
|
||||||
|
popnames[nimienLkm, 1] <- nimi # Näin se on greedyMix:issäkin?!?
|
||||||
|
popnames[nimienLkm, 2] <- ninds
|
||||||
|
poimiNimi <- 0
|
||||||
|
|
||||||
|
data <- addAlleles(data, ninds, line, divider)
|
||||||
|
|
||||||
|
} else if (testaaPop(line)) {
|
||||||
|
poimiNimi <- 1
|
||||||
|
|
||||||
|
} else if (!is.na(line)) {
|
||||||
|
ninds <- ninds + 1
|
||||||
|
data <- addAlleles(data, ninds, line, divider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data <- data[1:(ninds * 2), ]
|
||||||
|
popnames <- popnames[seq_len(nimienLkm), ]
|
||||||
|
npops <- size(popnames, 1)
|
||||||
|
ind <- 1
|
||||||
|
for (pop in 1:npops) {
|
||||||
|
if (pop < npops) {
|
||||||
|
while (ind < popnames[pop + 1, 2]) {
|
||||||
|
data[c(ind * 2 - 1, ind * 2), ncol(data)] <- pop
|
||||||
|
ind <- ind + 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (ind <= ninds) {
|
||||||
|
data[c(ind * 2 - 1, ind * 2), ncol(data)] <- pop
|
||||||
|
ind <- ind + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(list(data = data, popnames = popnames))
|
||||||
|
}
|
||||||
21
man/lueGenePopDataPop.Rd
Normal file
21
man/lueGenePopDataPop.Rd
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/lueGenePopDataPop.R
|
||||||
|
\name{lueGenePopDataPop}
|
||||||
|
\alias{lueGenePopDataPop}
|
||||||
|
\title{Read GenePop Data}
|
||||||
|
\usage{
|
||||||
|
lueGenePopDataPop(tiedostonNimi)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{tiedostonNimi}{Name of the file}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
List containing data and popnames
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Read GenePop Data
|
||||||
|
}
|
||||||
|
\note{
|
||||||
|
The data is given in the form where the last column tells the
|
||||||
|
group. popnames are as before.
|
||||||
|
}
|
||||||
|
|
@ -251,86 +251,6 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
function [data, popnames] = lueGenePopDataPop(tiedostonNimi)
|
|
||||||
% Data annetaan muodossa, jossa viimeinen sarake kertoo ryhmän.
|
|
||||||
% popnames on kuten ennenkin.
|
|
||||||
|
|
||||||
fid = fopen(tiedostonNimi);
|
|
||||||
line = fgetl(fid); %ensimmäinen rivi
|
|
||||||
line = fgetl(fid); %toinen rivi
|
|
||||||
count = rivinSisaltamienMjonojenLkm(line);
|
|
||||||
|
|
||||||
line = fgetl(fid);
|
|
||||||
lokusRiveja = 1;
|
|
||||||
while (testaaPop(line)==0)
|
|
||||||
lokusRiveja = lokusRiveja+1;
|
|
||||||
line = fgetl(fid);
|
|
||||||
end
|
|
||||||
|
|
||||||
if lokusRiveja>1
|
|
||||||
nloci = lokusRiveja;
|
|
||||||
else
|
|
||||||
nloci = count;
|
|
||||||
end
|
|
||||||
|
|
||||||
popnames = cell(10,2);
|
|
||||||
data = zeros(100, nloci+1);
|
|
||||||
nimienLkm=0;
|
|
||||||
ninds=0;
|
|
||||||
poimiNimi=1;
|
|
||||||
digitFormat = -1;
|
|
||||||
while line ~= -1
|
|
||||||
line = fgetl(fid);
|
|
||||||
|
|
||||||
if poimiNimi==1
|
|
||||||
%Edellinen rivi oli 'pop'
|
|
||||||
nimienLkm = nimienLkm+1;
|
|
||||||
ninds = ninds+1;
|
|
||||||
if nimienLkm>size(popnames,1);
|
|
||||||
popnames = [popnames; cell(10,2)];
|
|
||||||
end
|
|
||||||
nimi = lueNimi(line);
|
|
||||||
if digitFormat == -1
|
|
||||||
digitFormat = selvitaDigitFormat(line);
|
|
||||||
divider = 10^digitFormat;
|
|
||||||
end
|
|
||||||
popnames{nimienLkm, 1} = {nimi}; %Näin se on greedyMix:issäkin?!?
|
|
||||||
popnames{nimienLkm, 2} = ninds;
|
|
||||||
poimiNimi=0;
|
|
||||||
|
|
||||||
data = addAlleles(data, ninds, line, divider);
|
|
||||||
|
|
||||||
elseif testaaPop(line)
|
|
||||||
poimiNimi = 1;
|
|
||||||
|
|
||||||
elseif line ~= -1
|
|
||||||
ninds = ninds+1;
|
|
||||||
data = addAlleles(data, ninds, line, divider);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
fclose(fid);
|
|
||||||
data = data(1:ninds*2,:);
|
|
||||||
popnames = popnames(1:nimienLkm,:);
|
|
||||||
npops = size(popnames,1);
|
|
||||||
ind = 1;
|
|
||||||
for pop = 1:npops
|
|
||||||
if pop<npops
|
|
||||||
while ind<popnames{pop+1,2}
|
|
||||||
data([ind*2-1 ind*2],end) = pop;
|
|
||||||
ind = ind+1;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
while ind<=ninds
|
|
||||||
data([ind*2-1 ind*2],end) = pop;
|
|
||||||
ind = ind+1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%-------------------------------------------------------------------
|
%-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue