我创建了一些随机试验数据,如下所示:
Trial1 <- AminoAcidTrialGenerator2(10, 6, aacodons$MOD_Frequency); Trial1
使用我编写的函数创建该函数,以基于概率分布以3个字母的代码生成氨基酸序列。
这将输出:
[[1]]
[1] cys glu glu stop phe asn
21 Levels: ala arg asn asp cys gln glu gly his ile leu lys ... val
[[2]]
[1] cys pro ile lys cys arg
21 Levels: ala arg asn asp cys gln glu gly his ile leu lys ... val
[[3]]
[1] asp gln gln ala gln his
21 Levels: ala arg asn asp cys gln glu gly his ile leu lys ... val
[[4]]
[1] thr pro lys thr lys phe
21 Levels: ala arg asn asp cys gln glu gly his ile leu lys ... val
[[5]]
[1] ala gly his arg stop trp
21 Levels: ala arg asn asp cys gln glu gly his ile leu lys ... val
我的emperical.codon.freq函数应该做的是创建一个新的TrialData列表,其中包含每个试验中每个三个字母字符出现的频率计数。
emperical.Codon.Freq <- function(trialvec) {
TrialData <- list()
ecf.df <- data.frame(Codon = aacodons$Amino_Acid)
for (i in 1:length(unlist(trialvec[i]))) {
indexv <- is.element(ecf.df$Codon, unlist(trialvec[i]))
name <- paste("Trial", i, sep = "_")
currentT <- unlist(trialvec[i])
for (f in 1:length(indexv)) {
c[i] <- sum(is.element(currentT,
aacodons$Amino_Acid[indexv][f]),
na.rm = TRUE)
TrialData[[i]] <- unlist(c)
}
}
TrialData
}
当我尝试运行该函数emperical.Codon.frequency时,出现错误消息:
TrialData [[i]]中的错误<-unlist(c):尝试选择少于一个 intergerOneIndex中的元素。
dput(Trial1)
list(structure(c(5L, 7L, 7L, 17L, 14L, 3L), .Label = c("ala",
"arg", "asn", "asp", "cys", "gln", "glu", "gly", "his", "ile",
"leu", "lys", "met", "phe", "pro", "ser", "stop", "thr", "trp",
"tyr", "val"), class = "factor"), structure(c(5L, 15L, 10L, 12L,
5L, 2L), .Label = c("ala", "arg", "asn", "asp", "cys", "gln",
"glu", "gly", "his", "ile", "leu", "lys", "met", "phe", "pro",
"ser", "stop", "thr", "trp", "tyr", "val"), class = "factor"),
structure(c(4L, 6L, 6L, 1L, 6L, 9L), .Label = c("ala", "arg",
"asn", "asp", "cys", "gln", "glu", "gly", "his", "ile", "leu",
"lys", "met", "phe", "pro", "ser", "stop", "thr", "trp",
"tyr", "val"), class = "factor"), structure(c(18L, 15L, 12L,
18L, 12L, 14L), .Label = c("ala", "arg", "asn", "asp", "cys",
"gln", "glu", "gly", "his", "ile", "leu", "lys", "met", "phe",
"pro", "ser", "stop", "thr", "trp", "tyr", "val"), class = "factor"),
structure(c(1L, 8L, 9L, 2L, 17L, 19L), .Label = c("ala",
"arg", "asn", "asp", "cys", "gln", "glu", "gly", "his", "ile",
"leu", "lys", "met", "phe", "pro", "ser", "stop", "thr",
"trp", "tyr", "val"), class = "factor"), structure(c(1L,
19L, 5L, 10L, 3L, 7L), .Label = c("ala", "arg", "asn", "asp",
"cys", "gln", "glu", "gly", "his", "ile", "leu", "lys", "met",
"phe", "pro", "ser", "stop", "thr", "trp", "tyr", "val"), class = "factor"),
structure(c(14L, 14L, 19L, 3L, 12L, 14L), .Label = c("ala",
"arg", "asn", "asp", "cys", "gln", "glu", "gly", "his", "ile",
"leu", "lys", "met", "phe", "pro", "ser", "stop", "thr",
"trp", "tyr", "val"), class = "factor"), structure(c(13L,
5L, 9L, 21L, 16L, 13L), .Label = c("ala", "arg", "asn", "asp",
"cys", "gln", "glu", "gly", "his", "ile", "leu", "lys", "met",
"phe", "pro", "ser", "stop", "thr", "trp", "tyr", "val"), class = "factor"),
structure(c(2L, 21L, 8L, 16L, 3L, 17L), .Label = c("ala",
"arg", "asn", "asp", "cys", "gln", "glu", "gly", "his", "ile",
"leu", "lys", "met", "phe", "pro", "ser", "stop", "thr",
"trp", "tyr", "val"), class = "factor"), structure(c(10L,
11L, 20L, 11L, 5L, 17L), .Label = c("ala", "arg", "asn",
"asp", "cys", "gln", "glu", "gly", "his", "ile", "leu", "lys",
"met", "phe", "pro", "ser", "stop", "thr", "trp", "tyr",
"val"), class = "factor"))