【问题标题】:match specific pattern with few substitution用很少的替换匹配特定的模式
【发布时间】:2022-12-13 08:56:18
【问题描述】:

嗨,我正在研究抗体,我必须使用 python 找到其抗原特异性的特定模式。我很困惑地想找到一个具有预定义替换次数的匹配模式。

我尝试了可能的排列/组合的正则表达式 (re.findall/re.search),但这无法解决我的问题。此外,在互联网上搜索也无济于事。

不确定它是否需要 AI/ML 算法来匹配特定模式。

健康)状况:-

我想将任何给定的字符串与图案最多 4 可能的替代品替换列表在任何位置 在不改变其原始框架的情况下。

substitution_list='A','C','D','E','F','G','H','I','K','L','M','N', 'P','Q','R','S','T','V','W','Y']

模式 =“AVTLDPQRSTSTRP”

例如:-

  string_1="AV**A**LDPQRSTSTRP" --> matched
  string_2="AV**A**LDPQ**C**STSTRP" --> matched
  string_3="AV**V**L**P**PQ**L**ST**L**TRP" --> matched
  string_4="**L**V**V**L**P**PQ**L**STS**C**RP" --> NOT matched (5 substitution)
  string_5="TRPAVQRSTLDPTS" --> NOT matched (original frame has changed)

谢谢。

【问题讨论】:

  • 你能解释一下你的例子吗?如何匹配字符串 3 但不匹配字符串 4 并解释字符串 4 有 5 个替换
  • @Ramesh 因为允许替换的最大数量是 4,它在 sring_3 中,但是 string_4 有 5 个替换,这是定义禁止的。

标签: python machine-learning bioinformatics string-matching


【解决方案1】:

在这种特殊情况下,我找到了一种方法(虽然很脏)可以帮助我。

  def match_pattern(string):
        pattern='AVTLDPQRSTSTRP'  ### standard template

        max_subs=4 ### maximum allowed substitutions
        score=0
        for i in range(len(string)):
            if string[i]!=pattern[i]:
                score+=1
        # print(score)
        if score <=max_subs:
            print('String matched')
        else:
            print('Not matched')

测试

 test_strings=["AVALDPQRSTSTRP" ,"AVALDPQCSTSTRP" ,"AVVLPPQLSTLTRP" ,"LVVLPPQLSTSCRP" ,"TRPAVQRSTLDPTS"]
 for string in test_strings:
     match_pattern(string)


  String matched
  String matched
  String matched
  Not matched
  Not matched

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    相关资源
    最近更新 更多