Added bare-bones lueGenePopData
This commit is contained in:
parent
b2d1b830cd
commit
862a91febc
4 changed files with 84 additions and 64 deletions
|
|
@ -13,6 +13,7 @@ export(inputdlg)
|
|||
export(isfield)
|
||||
export(laskeMuutokset4)
|
||||
export(learn_simple_partition)
|
||||
export(lueGenePopData)
|
||||
export(noIndex)
|
||||
export(ownNum2Str)
|
||||
export(poistaLiianPienet)
|
||||
|
|
|
|||
|
|
@ -1580,70 +1580,6 @@ greedyMix <- function(
|
|||
|
||||
# %------------------------------------------------------
|
||||
|
||||
|
||||
# function [data, popnames] = lueGenePopData(tiedostonNimi)
|
||||
|
||||
# fid = fopen(tiedostonNimi);
|
||||
# line = fgetl(fid); %ensimm<6D>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<73>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
|
||||
|
||||
# data = data(1:ninds*2,:);
|
||||
# popnames = popnames(1:nimienLkm,:);
|
||||
# fclose(fid);
|
||||
|
||||
# %--------------------------------------------------------
|
||||
|
||||
|
||||
# function data = addAlleles(data, ind, line, divider)
|
||||
# % Lisaa BAPS-formaatissa olevaan datataulukkoon
|
||||
# % yksil<69><6C> ind vastaavat rivit. Yksil<69>n alleelit
|
||||
|
|
|
|||
66
R/lueGenePopData.R
Normal file
66
R/lueGenePopData.R
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#' @title Read GenePop Data
|
||||
#' @description Reads GenePop-formatted data
|
||||
#' @param tiedostonNimi Name of the file
|
||||
#' @return list containing data and popnames
|
||||
#' @export
|
||||
lueGenePopData <- function (tiedostonNimi) {
|
||||
|
||||
fid <- load(tiedostonNimi)
|
||||
line1 <- readLines(fid)[1] # ensimmäinen rivi
|
||||
line2 <- readLines(fid)[2] # toinen rivi
|
||||
count <- rivinSisaltamienMjonojenLkm(line)
|
||||
|
||||
line <- readLines(fid)[3]
|
||||
lokusRiveja <- 1
|
||||
while (testaaPop(line) == 0) {
|
||||
lokusRiveja <- lokusRiveja + 1 # locus row
|
||||
line <- readLines(fid)[3 + 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 (line != -1) {
|
||||
line <- readLines(fid)[lokusRiveja + 1]
|
||||
lokusRiveja <- lokusRiveja + 1
|
||||
|
||||
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<73>kin?!?
|
||||
popnames[nimienLkm, 2] <- ninds
|
||||
poimiNimi <- 0
|
||||
|
||||
data <- addAlleles(data, ninds, line, divider)
|
||||
|
||||
} else if (testaaPop(line)) {
|
||||
poimiNimi <- 1
|
||||
|
||||
} else if (line != -1) {
|
||||
ninds <- ninds + 1
|
||||
data <- addAlleles(data, ninds, line, divider)
|
||||
}
|
||||
}
|
||||
|
||||
data <- data[1:(ninds * 2),]
|
||||
popnames <- popnames[seq_len(nimienLkm),]
|
||||
return(list(data = data, popnames = popnames))
|
||||
}
|
||||
17
man/lueGenePopData.Rd
Normal file
17
man/lueGenePopData.Rd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/lueGenePopData.R
|
||||
\name{lueGenePopData}
|
||||
\alias{lueGenePopData}
|
||||
\title{Read GenePop Data}
|
||||
\usage{
|
||||
lueGenePopData(tiedostonNimi)
|
||||
}
|
||||
\arguments{
|
||||
\item{tiedostonNimi}{Name of the file}
|
||||
}
|
||||
\value{
|
||||
list containing data and popnames
|
||||
}
|
||||
\description{
|
||||
Reads GenePop-formatted data
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue