簡體   English   中英

用很少的替換匹配特定的模式

[英]match specific pattern with few substitution

嗨,我正在研究抗體,我必須使用 python 找到其抗原特異性的特定模式。我很想找到具有預定義替換數量的匹配模式。

我嘗試了可能的排列/組合的正則表達式 (re.findall/re.search),但這無法解決我的問題。 此外,在 inte.net 上搜索也無濟於事。

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

健康)狀況:-

我想將任何給定的字符串與模式匹配,在任何 position 的substitution_list中最多有 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)

謝謝。

在這種特殊情況下,我找到了一種方法(雖然很臟)可以幫助我。

  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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM