【发布时间】:2020-04-28 03:05:54
【问题描述】:
我们有 2 个 DNA 序列(字符串):
>1
ATGCAT
135198
>2
ATCAT
预期输出:首先,我们需要对齐这两个字符串,然后通过索引获取相关注释:
ATGCAT
AT-CAT
13-198
第一部分可以使用 Biostrings 包完成:
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 方法(或任何其他包),也许通过将注释保留在 metadata 插槽中,然后在对齐之后,我们在元数据中得到匹配碱基的匹配注释,如下所示:
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"
注意:
- 从 BioStars 窃取作者的许可 - https://www.biostars.org/p/415896/
- 作者想要 biopython 解决方案,所以添加标签,如果可能的话也发布 python 解决方案。
【问题讨论】:
标签: python r bioinformatics biopython bioconductor