我正在尝试从具有SeqinR
的序列比对(比对对象)的序列中提取一组比对序列。
在dput()
(S4对象)的alignment
下方
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))
此外,我没有基于列表n
的子集。
在此示例中,我希望对象与fas
相同,但变量n
中仅包含3个元素。
预先感谢
答案 0 :(得分:0)
我相信这样做可能会有更好的方法。
但是我解决了一个难题。
首先,我以read.fasta
否read.alignment
导入文件,但我仍在使用seqinr
。
fas <- read.alignment("file.fa")
之后,我构建一个tibble
,基于列表进行过滤,并使用as.alignment
(它是用于对齐对象的构造函数)。
tibble(x) %>%
cbind(names = names(x)) %>%
filter(names %in% n) %>%
as.alignment(nb = nrow(.), seq = pull(., x), nam = pull(., names))
以此,我做了我所需要的。
改进是完全有用且可以接受的。 不管怎么说,还是要谢谢你。 我希望它可以帮助某人。
答案 1 :(得分:-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)