-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb0c09a
commit c2f5551
Showing
4 changed files
with
82 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
|
||
landscape.ind.freq <- function(Rland,include.states=TRUE) | ||
{ | ||
l <- Rland | ||
aml <- vector("list",length(landscape.ploidy(l))) | ||
for (loc in 1:length(aml)) | ||
{ | ||
genos <- landscape.locus(l,loc)[,-1:-landscape.democol()] | ||
ploidy <- landscape.ploidy(l)[loc] | ||
if (l$loci[[loc]]$type!=253) | ||
{ | ||
lst <- landscape.locus.states(l,loc) | ||
names(lst$state) <- lst$aindex | ||
if (ploidy==2) | ||
{ | ||
genos[,1] <- unname(lst$state[as.character(genos[,1])]) | ||
genos[,2] <- unname(lst$state[as.character(genos[,2])]) | ||
} else { | ||
genos <- unname(lst$state[as.character(genos)]) | ||
} | ||
} | ||
amat <- sapply(names(table(genos)),function(x,genos,pl) | ||
{ | ||
if (pl==2) | ||
{ | ||
(as.character(genos[,1])==as.character(x))+(as.character(genos[,2])==as.character(x)) | ||
} else | ||
{ | ||
as.character(genos)==as.character(x) | ||
} | ||
},genos=genos,pl=ploidy) | ||
aml[[loc]] <- apply(amat,2,function(x,pl){x/pl},pl=ploidy) #allele freqs per ind | ||
landscape.ind.freq <- function(Rland,include.states=TRUE) { | ||
l <- Rland | ||
ploidy <- landscape.ploidy(l) | ||
aml <- vector("list", length(ploidy)) | ||
for (loc in 1:length(aml)) { | ||
genos <- landscape.locus(l, loc)[, -(1:landscape.democol())] | ||
loc.ploidy <- ploidy[loc] | ||
if (l$loci[[loc]]$type != 253) { | ||
lst <- landscape.locus.states(l, loc) | ||
names(lst$state) <- lst$aindex | ||
if (loc.ploidy == 2) { | ||
genos[, 1] <- unname(lst$state[as.character(genos[, 1])]) | ||
genos[, 2] <- unname(lst$state[as.character(genos[, 2])]) | ||
} else { | ||
genos <- unname(lst$state[as.character(genos)]) | ||
} | ||
do.call(cbind,aml) | ||
} | ||
unique.genos <- sort(as.character(unique(as.vector(genos)))) | ||
aml[[loc]] <- sapply(unique.genos, function(x) { | ||
if (loc.ploidy == 2) { | ||
(as.character(genos[, 1]) == x) + (as.character(genos[, 2]) == x) | ||
} else { | ||
as.character(genos) == x | ||
} | ||
}) / loc.ploidy | ||
} | ||
do.call(cbind, aml) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
#Create genind object from landscape | ||
#ignores the haploid loci | ||
landscape.make.genind <- function(Rland) | ||
{ | ||
tab <- landscape.ind.freq(Rland)*2 | ||
dimnames(tab) <- list(rownames=1:dim(tab)[1],colnames=landscape.freq.locnames(Rland)) | ||
pl <- landscape.ploidy(Rland) | ||
populations <- landscape.populations(Rland) | ||
gi=genind(tab,pop=as.factor(populations),ploidy=2) | ||
gi[,loc=which(pl>1)] | ||
} | ||
landscape.make.genind <- function(Rland) { | ||
tab <- landscape.ind.freq(Rland) * 2 | ||
dimnames(tab) <- list( | ||
rownames = 1:dim(tab)[1], | ||
colnames = landscape.freq.locnames(Rland) | ||
) | ||
gi <- adegenet::genind( | ||
tab, | ||
pop = as.factor(landscape.populations(Rland)), | ||
ploidy = 2 | ||
) | ||
gi[, loc = which(landscape.ploidy(Rland) > 1)] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.