0

我正在尝试从序列比对(比对对象)中提取一组比对序列SeqinR

dput()alignment(S4 对象)的下方

structure(list(nb = 39, nam = c("Lip4", "pdb|5FRD|A", "pdb|1M33|A", 
"pdb|5H3H|B", "pdb|1HL7|B", "pdb|1A8S|A", "pdb|1WPR|B", "pdb|4JYM|A", 
"pdb|2OCI|A", "pdb|1XRO|A", "pdb|3OOS|A", "pdb|2RHW|A", "pdb|2WUF|B", 
"pdb|1IUP|A", "pdb|4LXI|A", "GBD36331.1", "ADV62823.1", "KRA67074.1", 
"WP_030056103.1", "OHD12261.1", "WP_084594117.1", "WP_091643197.1", 
"OGO52173.1", "KFN38864.1", "GBC76610.1", "PKN85453.1", "ACU30832.1", 
"KPJ59441.1", "WP_028052179.1", "OGN93027.1", "OGO32450.1", "PSN93892.1", 
"ESQ22364.1", "WP_069806679.1", "WP_013336464.1", "WP_066315780.1", 
"KRT77961.1", "OIO07272.1", "WP_009823005.1"), seq = list("ygglgwvdnrggsadlgvsmggaplllplgdpilhf", 
    "-----w-dlpngsay-ghslggapllyplgdpilhf", "wgglgwldlpggsaxagwslggapltlplgdpwsh-", 
    "vggmgfydyrggsadlgfsmggagllldlgdpilhy", "ygglgwvdrrggsadlgfsmgtlglfvplgdpvyhf", 
    "yggfgwvdrrggsadlgfstggvgallplgdpvlhf", "-ggfgwvdyvggsadlghsvgagplmlplcdpllhy", 
    "-gglgwvdnmggtsdlghsvsagpimlphsdplvhh", "ygglgfvdprggsadlgwsdggapmi-plgdpvlhf", 
    "ykptgyvdqfggsvelgssyggaqlviplgdpilhf", "------vnlkggsidlghsaggaqivlpfgdpilhf", 
    "yggmgwvdspgnsaalgnamggaplllkfgdpilhf", "ygglgwvdqpggsaalgnalggapllvplgdpilhf", 
    "ygglgyvdmvggtvhlgnafggasml-plgdpilhf", "ygglgrvdmvggtthlgnamggaplllplgdpighf", 
    "-gglgvvelrgarvdlgvsfggapvalplgdpihhf", "-ggmglvslrggsadlgvsfggvplllplgdpifhc", 
    "ygglgwvfqiggsvylgesfggvp-llplgdpifhf", "ygglgwvylrghssdlgwsyggvglllplgdpllhf", 
    "ygglgwvdnrggsadaglsmggaplllplgdpilhf", "fgglgwvdnrggtadagvsmggaplllplgdpilhf", 
    "ygglgwvdnrggsadagvsmggapmllplgdpllhf", "ygglgwvdnrdgsadlgvsmggapllvplgdpilhf", 
    "ygglgwvdnrggsadlgismggaplllplgdpllhf", "ygglgwtdnrggsadlghsmggaplllplgdpilhf", 
    "ygglgwvdnrggsadlglsmggapllapmadplmhf", "----gwcdnrggsadlgvsmggapvllplgdpiehf", 
    "ygglgwvdnrggtadqgvsvggapllvplgdpilhf", "yggcgwldnrggsadlgismggaplllplgdhilhf", 
    "ygglgfvdnrggsadvgismggaplllplgdpilhf", "yggmgyldnrggsadigasmggaplllplgdsilhf", 
    "ygglgwldnrggsadlgvsmggaplllplgdpilhf", "ygglgwldnrggstdlgvsmggadlllplgdnilhf", 
    "ygglgwldnrggsvdlgvsmggaplllplgdpilhf", "ygglgwldnrggsadlgfsmggaglllptgdpifhh", 
    "ygglgwvdnrggtadqgvsmggapllvklgdpiehf", "ygglgwvdnrggsadlgaslggaplllplgdpilhf", 
    "ygglgwvdnrggsadlgaslggaallpplgdpilhf", "ygglgwvdnrggsgdlgwslgglgallplgdpilhf"), 
    com = NA), class = "alignment")

我正在尝试这种方式:

library(seqinr)

fas <- read.alignment("data.fa")
n <- c("OGO52173.1", "KFN38864.1", "GBC76610.1")
sub_fas <- fas[ fas$nam %in% n ]

但是我得到了一种不同的对象,如下所示dput()

structure(list(39, c("Lip4", "pdb|5FRD|A", "pdb|1M33|A", "pdb|5H3H|B", 
"pdb|1HL7|B", "pdb|1A8S|A", "pdb|1WPR|B", "pdb|4JYM|A", "pdb|2OCI|A", 
"pdb|1XRO|A", "pdb|3OOS|A", "pdb|2RHW|A", "pdb|2WUF|B", "pdb|1IUP|A", 
"pdb|4LXI|A", "GBD36331.1", "ADV62823.1", "KRA67074.1", "WP_030056103.1", 
"OHD12261.1", "WP_084594117.1", "WP_091643197.1", "OGO52173.1", 
"KFN38864.1", "GBC76610.1", "PKN85453.1", "ACU30832.1", "KPJ59441.1", 
"WP_028052179.1", "OGN93027.1", "OGO32450.1", "PSN93892.1", "ESQ22364.1", 
"WP_069806679.1", "WP_013336464.1", "WP_066315780.1", "KRT77961.1", 
"OIO07272.1", "WP_009823005.1"), list("ygglgwvdnrggsadlgvsmggaplllplgdpilhf", 
    "-----w-dlpngsay-ghslggapllyplgdpilhf", "wgglgwldlpggsaxagwslggapltlplgdpwsh-", 
    "vggmgfydyrggsadlgfsmggagllldlgdpilhy", "ygglgwvdrrggsadlgfsmgtlglfvplgdpvyhf", 
    "yggfgwvdrrggsadlgfstggvgallplgdpvlhf", "-ggfgwvdyvggsadlghsvgagplmlplcdpllhy", 
    "-gglgwvdnmggtsdlghsvsagpimlphsdplvhh", "ygglgfvdprggsadlgwsdggapmi-plgdpvlhf", 
    "ykptgyvdqfggsvelgssyggaqlviplgdpilhf", "------vnlkggsidlghsaggaqivlpfgdpilhf", 
    "yggmgwvdspgnsaalgnamggaplllkfgdpilhf", "ygglgwvdqpggsaalgnalggapllvplgdpilhf", 
    "ygglgyvdmvggtvhlgnafggasml-plgdpilhf", "ygglgrvdmvggtthlgnamggaplllplgdpighf", 
    "-gglgvvelrgarvdlgvsfggapvalplgdpihhf", "-ggmglvslrggsadlgvsfggvplllplgdpifhc", 
    "ygglgwvfqiggsvylgesfggvp-llplgdpifhf", "ygglgwvylrghssdlgwsyggvglllplgdpllhf", 
    "ygglgwvdnrggsadaglsmggaplllplgdpilhf", "fgglgwvdnrggtadagvsmggaplllplgdpilhf", 
    "ygglgwvdnrggsadagvsmggapmllplgdpllhf", "ygglgwvdnrdgsadlgvsmggapllvplgdpilhf", 
    "ygglgwvdnrggsadlgismggaplllplgdpllhf", "ygglgwtdnrggsadlghsmggaplllplgdpilhf", 
    "ygglgwvdnrggsadlglsmggapllapmadplmhf", "----gwcdnrggsadlgvsmggapvllplgdpiehf", 
    "ygglgwvdnrggtadqgvsvggapllvplgdpilhf", "yggcgwldnrggsadlgismggaplllplgdhilhf", 
    "ygglgfvdnrggsadvgismggaplllplgdpilhf", "yggmgyldnrggsadigasmggaplllplgdsilhf", 
    "ygglgwldnrggsadlgvsmggaplllplgdpilhf", "ygglgwldnrggstdlgvsmggadlllplgdnilhf", 
    "ygglgwldnrggsvdlgvsmggaplllplgdpilhf", "ygglgwldnrggsadlgfsmggaglllptgdpifhh", 
    "ygglgwvdnrggtadqgvsmggapllvklgdpiehf", "ygglgwvdnrggsadlgaslggaplllplgdpilhf", 
    "ygglgwvdnrggsadlgaslggaallpplgdpilhf", "ygglgwvdnrggsgdlgwslgglgallplgdpilhf"), 
    NA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL), .Names = c("nb", "nam", "seq", "com", 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA))

另外,我没有得到基于 list 的子集n

fas在此示例中,我希望与 variable 中包含相同的对象但仅包含 3 个元素n

提前致谢

4

2 回答 2

1

我相信这可能有更好的方法来做到这一点。
但我用一个技巧解决了。

首先,我导入文件read.fasta没有read.alignment,我仍在使用seqinr.

fas <- read.fasta("file.fa")

之后,我tibble在列表中构建了一个 , 过滤器,并使用as.alignmentwhich 是对齐对象的构造函数。

tibble(x) %>% 
  cbind(names = names(x)) %>% 
  filter(names %in% n) %>% 
  as.alignment(nb = nrow(.), seq = pull(., x), nam = pull(., names))

有了这个,我做了我需要的。

改进是完全有用和可以接受的。不管怎么说,还是要谢谢你。我希望它可以帮助某人。

于 2019-03-22T19:27:24.933 回答
-1
align <- read.alignment("fastafile",format="fasta")

align.temp.nam <- align$nam[align$nam %in% n]

align.temp.seq <- align$seq[align$nam %in% n]

align.sub <- as.alignment(nb=length(align.temp.nam),nam=align.temp.nam,seq=align.temp.seq)
于 2019-08-17T13:51:56.073 回答