]> git.donarmstrong.com Git - ape.git/blob - R/clustal.R
final commit for ape 3.0-8
[ape.git] / R / clustal.R
1 ## clustal.R (2012-11-28)
2
3 ##   Multiple Sequence Alignment with External Applications
4
5 ## Copyright 2011-2012 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 clustal <- function(x, pw.gapopen = 10, pw.gapext = 0.1,
11                     gapopen = 10, gapext = 0.2, exec = NULL,
12                     MoreArgs = "", quiet = TRUE, original.ordering = TRUE)
13 {
14     os <- Sys.info()[1]
15     if (is.null(exec)) {
16         if (os == "Linux") exec <- "clustalw"
17         if (os == "Darwin") exec <- "clustalw2"
18         if (os == "Windows") shortPathName("C:/Program Files/ClustalW2/clustalw2.exe")
19     }
20
21     if (missing(x)) {
22         system(paste(exec, "-help"))
23         return(invisible(NULL))
24     }
25
26     d <- tempdir()
27     inf <- paste(d, "input_clustal.fas", sep = "/")
28     outf <- paste(d, "input_clustal.aln", sep = "/")
29     write.dna(x, inf, "fasta")
30     prefix <- c("-INFILE", "-PWGAPOPEN", "-PWGAPEXT", "-GAPOPEN", "-GAPEXT")
31     suffix <- c(inf, pw.gapopen, pw.gapext, gapopen, gapext)
32     opts <- paste(prefix, suffix, sep = "=", collapse = " ")
33     opts <- paste(opts, MoreArgs)
34     system(paste(exec, opts), ignore.stdout = quiet)
35     res <- read.dna(outf, "clustal")
36     if (original.ordering) res <- res[labels(x), ]
37     res
38 }
39
40 muscle <- function(x, exec = "muscle", MoreArgs = "", quiet = TRUE, original.ordering = TRUE)
41 {
42     if (missing(x)) {
43         system(exec)
44         return(invisible(NULL))
45     }
46
47     d <- tempdir()
48     inf <- paste(d, "input_muscle.fas", sep = "/")
49     outf <- paste(d, "output_muscle.fas", sep = "/")
50     write.dna(x, inf, "fasta")
51     opts <- paste("-in", inf, "-out", outf)
52     if (quiet) opts <- paste(opts, "-quiet")
53     opts <- paste(opts, MoreArgs)
54     system(paste(exec, opts))
55     res <- read.dna(outf, "fasta")
56     if (original.ordering) res <- res[labels(x), ]
57     res
58 }
59
60 tcoffee <- function(x, exec = "t_coffee", MoreArgs = "", quiet = TRUE, original.ordering = TRUE)
61 {
62     if (missing(x)) {
63         system(exec)
64         return(invisible(NULL))
65     }
66
67     d <- tempdir()
68     od <- setwd(d)
69     on.exit(setwd(od))
70     inf <- "input_tcoffee.fas"
71     write.dna(x, inf, "fasta")
72     opts <- paste(inf, MoreArgs)
73     if (quiet) opts <- paste(opts, "-quiet=nothing")
74     system(paste(exec, opts))
75     res <- read.dna("input_tcoffee.aln", "clustal")
76     if (original.ordering) res <- res[labels(x), ]
77     res
78 }