查询“AAAA-AACAAA-AAAAAA”
参考“AA-AATAAAAAAAATAAAAAA”
在 Python 中,如何修复相对于参考字符串的字符串(查询),其中查询中的破折号替换参考字符,并且参考字符串中的破折号导致相应查询字符中的删除?
“AAAAA-AAACAAA-AAAAAA”应该变成
“AAAATAAAACAAATAAAAAA”(此处的括号“AA()AA(T)AAACAAA(T)AAAAAA”突出显示修改后的字符)
下面是可以修复查询中相对于参考的破折号的代码,这可能有用也可能没有帮助(行号特定于文件,在这里不相关,我为非 pythonic 代码道歉!),但我无法修改根据参考文献中的破折号查询....
if "Query identifier" in line:
Query = line[24:-12]
if "-" in Query:
indices = [i for i, x in enumerate(Query) if x == "-"]
QueryStringUntilFirstDash = Query[:indices[0]]
found = 2
if found ==2 and "Reference identifier" in line:
Ref = line[24:-12]
if len(indices) == 1:
QueryDashToEnd.append(Query[indices[0]+1:])
print QueryStringUntilFirstDash+Ref[indices[0]]+str(QueryDashToEnd[0])
del(A[:])
else:
while y < len(indices):
y+=1
if y < len(indices):
DashesMiddleofQuery.append(Query[indices[y-1]:indices[y]])
DashesMiddleofQuerySubstitution = [B.replace('-', Ref[indices[y-1]]) for B in B]
Concat= ''.join(B)
del(B[:])
print UID
print Beg+str(Concat)+Query[indices[-1]+1:]+">1"
found = 0
y = 0