Skip to content

Commit

Permalink
fixed bug in loading DNAbin objects and added citation file
Browse files Browse the repository at this point in the history
  • Loading branch information
gtonkinhill committed Jul 13, 2019
1 parent 37ba87a commit d44023b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
15 changes: 12 additions & 3 deletions R/import_fasta_sparse_nt.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ import_fasta_sparse_nt <- function(fasta, prior='baps', check.fasta=TRUE){

if(class(fasta)=="DNAbin"){
fasta <- as.character(as.matrix(fasta))
ij <- which(t(fasta) != fasta[1,], arr.ind = TRUE)
seqnames <- rownames(fasta)

cons_ref <- c(a=0,c=1,g=2,t=3,`-`=5,`n`=5)
cosensus <- apply(fasta[2:nrow(fasta),,drop=FALSE], 2, function(x){
tbl <- table(x)
cons_ref[names(tbl)[which.max(tbl)]]
})

fasta[fasta=='a'] <- 1
fasta[fasta=='c'] <- 2
fasta[fasta=='g'] <- 3
fasta[fasta=='t'] <- 4
fasta[fasta=='-'] <- 5
fasta[fasta=='n'] <- 5
fasta <- apply(fasta, 2, as.numeric)

ij <- which(t(fasta) != (cosensus+1), arr.ind = TRUE)
snp.data <- list(num.seqs=nrow(fasta),
consensus=fasta[1,]-1,
consensus=cosensus,
seq.length=ncol(fasta),
seq.names=rownames(fasta))

snp.matrix <- t(sparseMatrix(i=ij[,1], j=ij[,2], x=t(fasta)[ij],
dims = c(snp.data$seq.length, snp.data$num.seqs),
dimnames = list(1:snp.data$seq.length, snp.data$seq.names)))
dimnames = list(1:snp.data$seq.length, seqnames)))

} else {
snp.data <- import_fasta_to_vector_each_nt(fasta)
Expand Down
17 changes: 17 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
citHeader("The best way to cite fastbaps in publications is to use:")

citEntry(entry = "Article",
title = "Fast hierarchical Bayesian analysis of population structure",
author = personList(as.person("Gerry Tonkin-Hill"),
as.person("John A Lees"),
as.person("Stephen D Bentley"),
as.person("Simon D W Frost"),
as.person("Jukka Corander")),
journal = "Nucleic Acids Res..",
year = "2019",
pages = "1362--4962",
url = "http://dx.doi.org/10.1093/nar/gkz361",

textVersion = "Tonkin-Hill,G., Lees,J.A., Bentley,S.D., Frost,S.D.W. and Corander,J. (2019) Fast hierarchical Bayesian analysis of population structure. Nucleic Acids Res., 10.1093/nar/gkz361."


Binary file modified inst/vignette-supp/unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d44023b

Please sign in to comment.