Skip to content

Commit

Permalink
Add check for if only 1 sample input
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinmdouglas committed Nov 7, 2022
1 parent 9d2b62a commit 43311a5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions R/phyloseq_UniFrac_fork.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ fast_weighted_UniFrac <- function(tips_abun, tree, ncores = 1) {

# Re-order rows to match tip label order if needed.
if (! identical(rownames(tips_abun), tree$tip.label)){
tips_abun <- tips_abun[tree$tip.label, ]
tips_abun <- tips_abun[tree$tip.label, , drop = FALSE]
}

tips_abun <- as.matrix(tips_abun)

if (ncol(tips_abun) == 1) {
null_out <- matrix(NA, nrow = 1, ncol = 1)
rownames(null_out) <- colnames(tips_abun)[1]
colnames(null_out) <- colnames(tips_abun)[1]
return(null_out)
}

# Create N x 2 matrix of all pairwise combinations of samples.
sample_combos <- combn(colnames(tips_abun), 2, simplify = FALSE)

Expand Down Expand Up @@ -181,11 +188,18 @@ fast_unweighted_UniFrac <- function(tips_abun, tree, ncores = 1) {

# Re-order rows to match tip label order if needed.
if (! identical(rownames(tips_abun), tree$tip.label)){
tips_abun <- tips_abun[tree$tip.label, ]
tips_abun <- tips_abun[tree$tip.label, , drop = FALSE]
}

tips_abun <- as.matrix(tips_abun)

if (ncol(tips_abun) == 1) {
null_out <- matrix(NA, nrow = 1, ncol = 1)
rownames(null_out) <- colnames(tips_abun)[1]
colnames(null_out) <- colnames(tips_abun)[1]
return(null_out)
}

# Create N x 2 matrix of all pairwise combinations of samples.
sample_combos <- combn(colnames(tips_abun), 2, simplify = FALSE)

Expand Down

0 comments on commit 43311a5

Please sign in to comment.