Skip to content

Commit

Permalink
First v2.0 commit with @DaTa data.table slot
Browse files Browse the repository at this point in the history
  • Loading branch information
EricArcher committed Nov 21, 2016
1 parent 3125d2b commit 9101c5e
Show file tree
Hide file tree
Showing 98 changed files with 1,610 additions and 1,984 deletions.
30 changes: 12 additions & 18 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: strataG
Title: Summaries and Population Structure Analyses of Genetic Data
Description: A toolkit for analyzing stratified population genetic data.
Version: 1.0.7
Version: 2.0.0
License: GNU General Public License
Authors@R: c(
EA = person("Eric", "Archer", email = "eric.archer@noaa.gov", role = c("aut", "cre")),
Expand All @@ -12,21 +12,24 @@ Authors@R: c(
URL: https://github.com/EricArcher/strataG
BugReports: https://github.com/EricArcher/strataG/issues
Depends:
R (>= 3.2.0),
apex,
adegenet
R (>= 3.2.0)
Suggests:
knitr,
rmarkdown
rmarkdown,
testthat
Imports:
adegenet,
ape,
apex,
data.table,
copula,
DT,
ggplot2,
graphics,
grid,
gridExtra,
Hmisc,
Kmisc,
methods,
pegas,
phangorn,
Expand All @@ -45,6 +48,7 @@ Collate:
is.gtypes.R
initialize.gtypes.R
strataG-internal.R
as.array.gtypes.R
as.matrix.gtypes.R
as.data.frame.gtypes.R
alleleFreqFormat.R
Expand All @@ -58,21 +62,17 @@ Collate:
createConsensus.R
dupGenotypes.R
evanno.R
expectedNumAlleles.R
fasta.R
fastsimcoal.input.R
fastsimcoal.R
fixedDifferences.R
fixedSites.R
freq2GenData.R
fstToNm.R
fusFs.R
gelato.R
genepop.R
heterozygosity.R
Hstats.R
hweTest.R
idRows.R
iupacCode.R
jackHWE.R
labelHaplotypes.R
Expand All @@ -90,10 +90,11 @@ Collate:
nucleotideDivergence.R
nucleotideDiversity.R
numAlleles.R
numGensEq.R
numGenotyped.R
numMissing.R
permuteStrata.R
phase.R
popGenEqns.R
popStructStat.R
popStructTest.R
privateAlleles.R
Expand All @@ -106,12 +107,6 @@ Collate:
sharedLoci.R
show.gtypes.R
simGammaHaps.R
statChi2.R
statFis.R
statFst.R
statGst.R
statJostD.R
statPhist.R
strataGUI.R
strataSplit.R
stratify.R
Expand All @@ -127,14 +122,13 @@ Collate:
trimNs.R
validIupacCodes.R
variableSites.R
wrightFst.R
write.gtypes.R
write.nexus.snapp.R
gtypes2genind.R
gtypes2loci.R
gtypes2phyDat.R
df2gtypes.R
sequence2gtypes.R
gtypes2phyDat.R
LazyData: true
VignetteBuilder: knitr
LinkingTo: Rcpp
Expand Down
9 changes: 4 additions & 5 deletions NAMESPACE
Expand Up @@ -47,7 +47,6 @@ export(gtypes2genind)
export(gtypes2loci)
export(gtypes2phyDat)
export(hweTest)
export(idRows)
export(is.gtypes)
export(isTi)
export(isTv)
Expand All @@ -56,7 +55,6 @@ export(jackHWE)
export(jackInfluential)
export(labelHaplotypes)
export(ldNe)
export(loci)
export(loci2gtypes)
export(lowFreqSubs)
export(mRatio)
Expand All @@ -70,6 +68,7 @@ export(neiDa)
export(nucleotideDivergence)
export(nucleotideDiversity)
export(numAlleles)
export(numGenotyped)
export(numGensEq)
export(numMissing)
export(obsvdHet)
Expand All @@ -85,7 +84,6 @@ export(phaseWrite)
export(phyDat2gtypes)
export(popStructTest)
export(privateAlleles)
export(propSharedIds)
export(propSharedLoci)
export(propUniqueAlleles)
export(qaqc)
Expand Down Expand Up @@ -139,12 +137,12 @@ exportMethods("description<-")
exportMethods("schemes<-")
exportMethods("strata<-")
exportMethods(alleleNames)
exportMethods(as.array)
exportMethods(as.data.frame)
exportMethods(as.matrix)
exportMethods(description)
exportMethods(indNames)
exportMethods(locNames)
exportMethods(loci)
exportMethods(nInd)
exportMethods(nLoc)
exportMethods(nStrata)
Expand All @@ -158,8 +156,10 @@ exportMethods(summary)
import(adegenet)
import(ape)
import(apex)
import(data.table)
importFrom(DT,datatable)
importFrom(Hmisc,all.is.numeric)
importFrom(Kmisc,readlines)
importFrom(RColorBrewer,brewer.pal)
importFrom(Rcpp,sourceCpp)
importFrom(copula,Stirling1)
Expand Down Expand Up @@ -230,7 +230,6 @@ importFrom(stats,reorder)
importFrom(stats,sd)
importFrom(stats,var)
importFrom(swfscMisc,diversity)
importFrom(swfscMisc,harmonic.mean)
importFrom(swfscMisc,odds)
importFrom(swfscMisc,pVal)
importFrom(swfscMisc,zero.pad)
Expand Down
55 changes: 0 additions & 55 deletions R/Hstats.R

This file was deleted.

64 changes: 30 additions & 34 deletions R/RcppExports.R
@@ -1,20 +1,16 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

indGenotype <- function(nInd, numAlleles, locus) {
.Call('strataG_indGenotype', PACKAGE = 'strataG', nInd, numAlleles, locus)
}

HoCalc <- function(nInd, loci, ploidy, strata, strataN) {
.Call('strataG_HoCalc', PACKAGE = 'strataG', nInd, loci, ploidy, strata, strataN)
HoCalc <- function(nInd, locus, ploidy, strata, strataN) {
.Call('strataG_HoCalc', PACKAGE = 'strataG', nInd, locus, ploidy, strata, strataN)
}

HsCalc <- function(alleleFreq, ploidy, strataN, harmN, Ho) {
.Call('strataG_HsCalc', PACKAGE = 'strataG', alleleFreq, ploidy, strataN, harmN, Ho)
}

Hstats_C <- function(loci, strata, ploidy) {
.Call('strataG_Hstats_C', PACKAGE = 'strataG', loci, strata, ploidy)
Hstats_C <- function(loci, strata) {
.Call('strataG_Hstats_C', PACKAGE = 'strataG', loci, strata)
}

getMaxInt <- function(x) {
Expand Down Expand Up @@ -45,32 +41,32 @@ numOuterC <- function(x, y) {
.Call('strataG_numOuterC', PACKAGE = 'strataG', x, y)
}

intVecToMat <- function(x, ncol) {
.Call('strataG_intVecToMat', PACKAGE = 'strataG', x, ncol)
idStart <- function(id, ploidy) {
.Call('strataG_idStart', PACKAGE = 'strataG', id, ploidy)
}

numVecToMat <- function(x, ncol) {
.Call('strataG_numVecToMat', PACKAGE = 'strataG', x, ncol)
idGenotype <- function(locus, id, ploidy) {
.Call('strataG_idGenotype', PACKAGE = 'strataG', locus, id, ploidy)
}

calcStrataN <- function(locus, strata) {
.Call('strataG_calcStrataN', PACKAGE = 'strataG', locus, strata)
calcStrataN <- function(locus, strata, ploidy) {
.Call('strataG_calcStrataN', PACKAGE = 'strataG', locus, strata, ploidy)
}

statChi2_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statChi2_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statChi2_C <- function(loci, strataMat) {
.Call('strataG_statChi2_C', PACKAGE = 'strataG', loci, strataMat)
}

statFis_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statFis_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statFis_C <- function(loci, strataMat) {
.Call('strataG_statFis_C', PACKAGE = 'strataG', loci, strataMat)
}

alleleFreqCalc <- function(locVec, strata, ploidy) {
.Call('strataG_alleleFreqCalc', PACKAGE = 'strataG', locVec, strata, ploidy)
alleleFreqCalc <- function(locVec, strataRep) {
.Call('strataG_alleleFreqCalc', PACKAGE = 'strataG', locVec, strataRep)
}

prHetCalc <- function(alleles, nvec, locusMat, strata, ploidy) {
.Call('strataG_prHetCalc', PACKAGE = 'strataG', alleles, nvec, locusMat, strata, ploidy)
prHetCalc <- function(locus, nalleles, strata, nvec, ploidy) {
.Call('strataG_prHetCalc', PACKAGE = 'strataG', locus, nalleles, strata, nvec, ploidy)
}

varCompCalc <- function(nvec, alleleFreq, prHet, r, nbar, rnbar, nc) {
Expand All @@ -81,28 +77,28 @@ fstCalc <- function(loci, strata, ploidy) {
.Call('strataG_fstCalc', PACKAGE = 'strataG', loci, strata, ploidy)
}

statFst_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statFst_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statFst_C <- function(loci, strataMat) {
.Call('strataG_statFst_C', PACKAGE = 'strataG', loci, strataMat)
}

statFstPrime_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statFstPrime_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statFstPrime_C <- function(loci, strataMat) {
.Call('strataG_statFstPrime_C', PACKAGE = 'strataG', loci, strataMat)
}

statGst_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statGst_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statGst_C <- function(loci, strataMat) {
.Call('strataG_statGst_C', PACKAGE = 'strataG', loci, strataMat)
}

statGstPrime_C <- function(loci, strataMat, ploidy, primeType) {
.Call('strataG_statGstPrime_C', PACKAGE = 'strataG', loci, strataMat, ploidy, primeType)
statGstPrime_C <- function(loci, strataMat, primeType) {
.Call('strataG_statGstPrime_C', PACKAGE = 'strataG', loci, strataMat, primeType)
}

statGstDblPrime_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statGstDblPrime_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statGstDblPrime_C <- function(loci, strataMat) {
.Call('strataG_statGstDblPrime_C', PACKAGE = 'strataG', loci, strataMat)
}

statJostD_C <- function(loci, strataMat, ploidy) {
.Call('strataG_statJostD_C', PACKAGE = 'strataG', loci, strataMat, ploidy)
statJostD_C <- function(loci, strataMat) {
.Call('strataG_statJostD_C', PACKAGE = 'strataG', loci, strataMat)
}

ssWPCalc <- function(strataFreq, strataHapFreq, hapDist) {
Expand Down
2 changes: 1 addition & 1 deletion R/alleleFreqFormat.R
Expand Up @@ -38,7 +38,7 @@ alleleFreqFormat <- function(x, g) {
# skip (leave as NA) if either id or locus can't be found
if(!(id %in% indNames(g) | locus %in% locNames(g))) next
# get genotype of this id at this locus
gt <- unlist(loci(g, id, locus))
gt <- as.array(g, id, locus)
# if the genotype is NA skip and leave format as NA
if(any(is.na(gt))) next
# get frequency and round
Expand Down
27 changes: 15 additions & 12 deletions R/alleleFreqs.R
Expand Up @@ -22,28 +22,31 @@
#' data(msats.g)
#'
#' f <- alleleFreqs(msats.g)
#' f$D11t # Frequencies for Locus D11t
#' f$D11t # Frequencies and proportions for Locus D11t
#'
#' f.pop <- alleleFreqs(msats.g, TRUE)
#' f.pop$EV94[, , "Coastal"] # Frequencies for EV94 in the Coastal population
#' f.pop$EV94[, "freq", "Coastal"] # Frequencies for EV94 in the Coastal population
#'
#' @export

alleleFreqs <- function(g, by.strata = FALSE) {
freqs <- vector("list", length = ncol(g@loci))
strata <- rep(g@strata, g@ploidy)
for(i in 1:length(freqs)) {
if(by.strata & nlevels(strata) != 1) {
f <- table(g@loci[, i], strata)
freqs <- vector("list", length = nLoc(g))
names(freqs) <- locNames(g)
if(by.strata & nStrata(g) > 1) {
for(i in locNames(g)) {
f <- table(g@data[[i]], g@data$strata)
p <- prop.table(f, 2)
freqs[[i]] <- array(dim = list(nrow(f), 2, ncol(f)))
freqs[[i]] <- array(
dim = list(nrow(f), 2, ncol(f)),
dimnames = list(rownames(f), c("freq", "prop"), colnames(f))
)
for(j in 1:ncol(f)) freqs[[i]][, , j] <- cbind(f[, j], p[, j])
dimnames(freqs[[i]]) <- list(rownames(f), c("freq", "prop"), colnames(f))
} else {
f <- table(g@loci[, i])
}
} else {
for(i in locNames(g)) {
f <- table(g@data[[i]])
freqs[[i]] <- cbind(freq = f, prop = f / sum(f))
}
}
names(freqs) <- colnames(g@loci)
freqs
}

0 comments on commit 9101c5e

Please sign in to comment.