我们有2个DNA序列(字符串):
>1
ATGCAT
135198
>2
ATCAT
预期输出:首先,我们需要对齐这两个字符串,然后按索引获取相关注释:
ATGCAT
AT-CAT
13-198
第一部分可以使用生物串包完成:
library(Biostrings)
p <- DNAString("ATCAT")
s <- DNAString("ATGCAT")
s_annot <- "135198"
x <- pairwiseAlignment(pattern = p, subject = s)
aligned(x)
# A DNAStringSet instance of length 1
# width seq
# [1] 6 AT-CAT
as.character(x)
# [1] "AT-CAT"
as.matrix(x)
# [,1] [,2] [,3] [,4] [,5] [,6]
# [1,] "A" "T" "-" "C" "A" "T"
第二部分的当前解决方案:
annot <- unlist(strsplit(s_annot, ""))
annot[ which(c(as.matrix(x)) == "-") ] <- "-"
# [1] "1" "3" "-" "1" "9" "8"
工作正常,但我想知道是否有Biostrings方法(或任何其他软件包),可能是将注释保留在元数据槽中,然后在对齐后,我们在元数据中获得匹配基的匹配注释,如下所示:
getSlots("DNAString")
# shared offset length elementMetadata metadata
# "SharedRaw" "integer" "integer" "DataTable_OR_NULL" "list"
# just an idea, non-working code
s@metadata <- unlist(strsplit(s_annot , ""))
x <- pairwiseAlignment(pattern = p, subject = s)
metadata(x)
# [[1]]
# [1] "1" "3" "-" "1" "9" "8"
注意:
一种可能的解决办法:
与:
你会得到:
如果有相应的向量,可以将
Map
与dna_fun
-函数一起使用:这使得:
数据:
根据要求,Biopython解决方案:
输出:
相关问题 更多 >
编程相关推荐