![](/img/trans.png)
[英]Match all words except a specific few for substitution purposes, math expression use case
[英]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.