File: random.msa.R

package info (click to toggle)
r-cran-bios2cor 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,520 kB
  • sloc: makefile: 5
file content (44 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Package: Bios2cor 
# This file is part of the Bios2cor and Bios2mds R package.
# Bios2cor and Bios2mds are free softwares: you can redistribute them and/or modify
# them under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# See the GNU General Public License at:
# http://www.gnu.org/licenses/
#

random.msa <- function (nb.seq = 100, id = "SEQ", nb.pos = 100, gap = FALSE, aa.strict = FALSE,align = NULL, align.replace = TRUE) {

  #one letter codes for amino acids 
  aa <- c("A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K",
    "M", "F", "P", "S", "T", "W", "Y", "V", "B", "Z", "J", "X")
  replace <- TRUE
  #remove ambiguous amino acids
  if (aa.strict)
    aa <- aa[1:20]

  if (gap)
    aa <- c(aa, "-")

  if(!is.null(align)){
    if (!inherits(align, "align"))
        stop("mmds is not a 'align' object")
    aa <-as.vector(unlist(align))
    replace<-align.replace
  }

  msa <- lapply(seq_len(nb.seq), function (i) {sample(aa, nb.pos, replace = replace)})

  msa.names <- paste(id, seq_len(nb.seq), sep = "")

  names(msa) <- msa.names

  return(msa)
}