R语言 基于字符串中给定位置的字符的过滤器

41zrol4v  于 2022-12-06  发布在  其他
关注(0)|答案(1)|浏览(114)

我有下面的字符串,我想过滤的基础上,让我们说,A或T的第一个位置,其次是C或T的第二个位置,等等。

structure(list(barcode.Universe.sub = c("TCCGCTGGTGCG", "GTCGCGGACTGC", 
"CTTCCAAAATAG", "CCCCTTTCGTGG", "TTTCAGCGTCAG", "TACGAGCCTGGT", 
"AGCAGTATCAAC", "TAACCGTATAGA", "GGCTAATTCCGC", "CTCGGTTGGGCG", 
"TCCCGTGCGCCC", "TCTCCCAAACGA", "ATCATGGTCAAC", "ACCGCACTGAAC", 
"AAGTTTTCCTCA", "CTAGAGACCGAT", "CATTCTCATGGA", "ATGCGCGGCGAA", 
"GAGTGCCCTAGG", "ATGAGTAGTAGG", "TCTAGCGTCATT", "TCTCAACTTCTC", 
"GAGAACGCTCCT", "TACAGGACACAC", "GATTCTCACGAT", "GAGACGGAGGCC", 
"GCGGCTCCTCTA", "TGGATACTCTGC", "GCACCGCGTTCA", "GAATTGATAAGT", 
"GGGCAGCAGATA", "GGCATATACGGC", "TCATCACTATGA", "CGCGGCTGGGAT", 
"AGTCGCCACGCT", "TTGGCCGAAATT", "CGAGACCCACCG", "TGGTGCCTCACT", 
"CTGATACTGGGT", "AGGTGGCGTCTA", "GGCAAGGAGTAC", "GCGACTGAAATA", 
"AGCTTCGGATTA", "GTTGCCAGACTC", "AGCTGTCGCACG", "AGGGTTCGCTGT", 
"GTGCGTACCGCG", "CGCTTACACATG", "ACAACGCCATGT", "ATATACTAAGCC", 
"ACCGGAATAGCT", "CTACGAACGACT", "TAACCTTATGCT", "GCCTGCAGATGA", 
"CGAGTGCGGTGG", "TGGAGGTGTACT", "CTTCAATATTGA", "AACGACATAAAC", 
"TACAGTGGATGC", "ATCTAAGCTGTT", "GCCTGGCATCTT", "CATGGGGAACCT", 
"GCCCGAGCTAAG", "GGGTGCTCCGAC", "TAATTAGGACGC", "TACCTAAGCGAT", 
"TAGTCTGTAGGC", "CGTTAACTCCGC", "GCACGAAGTCAC", "GAGCGTCCAGCT", 
"CCGACTTACAAA", "CCGGTTCAGATG", "TGCAGCTGTGTG", "AATCTATTTCTT", 
"TCGTATAAGGTA", "AACTGGATGCCC", "ACGAAGAACGCT", "AGTGCTCTTCTG", 
"CTACAGTGTACA", "AGGGCCATACTC", "AACAACCGCTTA", "CTAGACGGCAAT", 
"GGGTTGAAGAAG", "GGAGCATACTAA", "CGAACCCCGGTA", "TGTACCATGGAA", 
"TTCGAGGTTGAT", "GTGCTTAGGATC", "CAACCGTATGAC", "GACGTCCTTCAG", 
"TGGTAATGGACA", "ACGAGCGCTATG", "GCGGAGCCACCC", "TCAGAGGCTGGA", 
"GGCCTTACGCAA", "TACGACCCATAG", "CCATTCAGCATG", "CCTAAGGGCCTT", 
"GGTCTATCGCAT", "CAGTACATGTCG")), class = c("tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -100L))

我已经尝试了stringr和特定的软件包的DNA序列(猿)没有很好的结果。

k3bvogb1

k3bvogb11#

您可以使用grep

grep("^[AT][CT]", s[,1])
# [1]  1  5 11 12 13 14 18 20 21 22 33 36 49 50 51 60 75 77 87 92 94

s[grep("^[AT][CT]", s[,1]), 1]
# [1] "TCCGCTGGTGCG" "TTTCAGCGTCAG" "TCCCGTGCGCCC" "TCTCCCAAACGA" "ATCATGGTCAAC"
# [6] "ACCGCACTGAAC" "ATGCGCGGCGAA" "ATGAGTAGTAGG" "TCTAGCGTCATT" "TCTCAACTTCTC"
#[11] "TCATCACTATGA" "TTGGCCGAAATT" "ACAACGCCATGT" "ATATACTAAGCC" "ACCGGAATAGCT"
#[16] "ATCTAAGCTGTT" "TCGTATAAGGTA" "ACGAAGAACGCT" "TTCGAGGTTGAT" "ACGAGCGCTATG"
#[21] "TCAGAGGCTGGA"

其中,^表示字符串的开头,[AT]AT匹配,[CT]CT匹配。
数据类型

s <- structure(list(barcode.Universe.sub = c("TCCGCTGGTGCG", "GTCGCGGACTGC", 
"CTTCCAAAATAG", "CCCCTTTCGTGG", "TTTCAGCGTCAG", "TACGAGCCTGGT", 
"AGCAGTATCAAC", "TAACCGTATAGA", "GGCTAATTCCGC", "CTCGGTTGGGCG", 
"TCCCGTGCGCCC", "TCTCCCAAACGA", "ATCATGGTCAAC", "ACCGCACTGAAC", 
"AAGTTTTCCTCA", "CTAGAGACCGAT", "CATTCTCATGGA", "ATGCGCGGCGAA", 
"GAGTGCCCTAGG", "ATGAGTAGTAGG", "TCTAGCGTCATT", "TCTCAACTTCTC", 
"GAGAACGCTCCT", "TACAGGACACAC", "GATTCTCACGAT", "GAGACGGAGGCC", 
"GCGGCTCCTCTA", "TGGATACTCTGC", "GCACCGCGTTCA", "GAATTGATAAGT", 
"GGGCAGCAGATA", "GGCATATACGGC", "TCATCACTATGA", "CGCGGCTGGGAT", 
"AGTCGCCACGCT", "TTGGCCGAAATT", "CGAGACCCACCG", "TGGTGCCTCACT", 
"CTGATACTGGGT", "AGGTGGCGTCTA", "GGCAAGGAGTAC", "GCGACTGAAATA", 
"AGCTTCGGATTA", "GTTGCCAGACTC", "AGCTGTCGCACG", "AGGGTTCGCTGT", 
"GTGCGTACCGCG", "CGCTTACACATG", "ACAACGCCATGT", "ATATACTAAGCC", 
"ACCGGAATAGCT", "CTACGAACGACT", "TAACCTTATGCT", "GCCTGCAGATGA", 
"CGAGTGCGGTGG", "TGGAGGTGTACT", "CTTCAATATTGA", "AACGACATAAAC", 
"TACAGTGGATGC", "ATCTAAGCTGTT", "GCCTGGCATCTT", "CATGGGGAACCT", 
"GCCCGAGCTAAG", "GGGTGCTCCGAC", "TAATTAGGACGC", "TACCTAAGCGAT", 
"TAGTCTGTAGGC", "CGTTAACTCCGC", "GCACGAAGTCAC", "GAGCGTCCAGCT", 
"CCGACTTACAAA", "CCGGTTCAGATG", "TGCAGCTGTGTG", "AATCTATTTCTT", 
"TCGTATAAGGTA", "AACTGGATGCCC", "ACGAAGAACGCT", "AGTGCTCTTCTG", 
"CTACAGTGTACA", "AGGGCCATACTC", "AACAACCGCTTA", "CTAGACGGCAAT", 
"GGGTTGAAGAAG", "GGAGCATACTAA", "CGAACCCCGGTA", "TGTACCATGGAA", 
"TTCGAGGTTGAT", "GTGCTTAGGATC", "CAACCGTATGAC", "GACGTCCTTCAG", 
"TGGTAATGGACA", "ACGAGCGCTATG", "GCGGAGCCACCC", "TCAGAGGCTGGA", 
"GGCCTTACGCAA", "TACGACCCATAG", "CCATTCAGCATG", "CCTAAGGGCCTT", 
"GGTCTATCGCAT", "CAGTACATGTCG")), class = c("tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -100L))

相关问题