diff --git a/Schrick-Noah_CS-6643_Lab-10.docx b/Schrick-Noah_CS-6643_Lab-10.docx index b690bb1..32fb343 100644 Binary files a/Schrick-Noah_CS-6643_Lab-10.docx and b/Schrick-Noah_CS-6643_Lab-10.docx differ diff --git a/msaUtils.R b/msaUtils.R new file mode 100644 index 0000000..29adf54 --- /dev/null +++ b/msaUtils.R @@ -0,0 +1,62 @@ +msaConvert <- function(x, type=c("seqinr::alignment", + "bios2mds::align", + "ape::AAbin", + "ape::DNAbin", + "phangorn::phyDat")) +{ + type <- match.arg(type) + + if (!is(x, "MultipleAlignment")) + stop("x must be a 'MultipleAlignment' object") + + xn <- as.character(unmasked(x)) + + if (type == "seqinr::alignment") + { + out <- list(nb=length(xn), + nam=names(xn), + seq=unname(xn), + com=NA) + + class(out) <- "alignment" + } + else if (type == "bios2mds::align") + { + out <- .Call("SplitCharVector2List", xn) + names(out) <- names(xn) + class(out) <- "align" + } + else if (type == "ape::AAbin") + { + if (!is(x, "AAMultipleAlignment")) + stop("conversion to 'ape::AAbin' only supported for ", + "amino acid sequences") + + out <- .Call("SplitCharVector2Matrix", xn, "X") + rownames(out) <- names(xn) + class(out) <- "AAbin" + } + else if (type == "ape::DNAbin") + { + if (!is(x, "DNAMultipleAlignment")) + stop("conversion to 'ape::DNAbin' only supported for ", + "DNA sequences") + + out <- .Call("SplitCharVector2Matrix", tolower(xn), "n") + rownames(out) <- names(xn) + class(out) <- "DNAbin" + } + else if (type == "phangorn::phyDat") + { + if (!is(x, "DNAMultipleAlignment")) + stop("conversion to 'phangorn::phyDat' only supported for ", + "DNA sequences") + + if (requireNamespace("phangorn", quietly=TRUE)) + out <- phangorn::as.phyDat(x) + else + stop("conversion to 'phyDat' requires package 'phangorn'") + } + + out +} \ No newline at end of file