]> git.donarmstrong.com Git - ape.git/blob - R/clustal.R
656ecb2244e193d5f652bff4b13757d691e524bb
[ape.git] / R / clustal.R
1 ## clustal.R (2012-01-12)
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)
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     read.dna(outf, "clustal")
36 }
37
38 muscle <- function(x, exec = "muscle", MoreArgs = "", quiet = TRUE)
39 {
40     if (missing(x)) {
41         system(exec)
42         return(invisible(NULL))
43     }
44
45     d <- tempdir()
46     inf <- paste(d, "input_muscle.fas", sep = "/")
47     outf <- paste(d, "output_muscle.fas", sep = "/")
48     write.dna(x, inf, "fasta")
49     opts <- paste("-in", inf, "-out", outf)
50     if (quiet) opts <- paste(opts, "-quiet")
51     opts <- paste(opts, MoreArgs)
52     system(paste(exec, opts))
53     read.dna(outf, "fasta")
54 }
55
56 tcoffee <- function(x, exec = "t_coffee", MoreArgs = "", quiet = TRUE)
57 {
58     if (missing(x)) {
59         system(exec)
60         return(invisible(NULL))
61     }
62
63     d <- tempdir()
64     od <- setwd(d)
65     on.exit(setwd(od))
66     inf <- "input_tcoffee.fas"
67     write.dna(x, inf, "fasta")
68     opts <- paste(inf, MoreArgs)
69     if (quiet) opts <- paste(opts, "-quiet=nothing")
70     system(paste(exec, opts))
71     read.dna("input_tcoffee.aln", "clustal")
72 }