title: Repair one string relative to another in Python
body: <p>Query     "AAAAA-AAACAAA-AAAAAA"</p>
  
  <p>Reference "AA-AATAAAAAAATAAAAAA"</p>
  
  <p>In Python,how do I repair a string (Query) relative to a Reference string where dashes in the query are substituted for the reference character, and dashes in the Reference string result in deletions in the corresponding Query character?</p>
  
  <p>"AAAAA-AAACAAA-AAAAAA" should become </p>
  
  <p>"AAAATAAACAAATAAAAAA"
  (where parantheses here "AA()AA(T)AAACAAA(T)AAAAAA" highlight the modified characters)</p>
  
  <p>Below is code that can repair the dashes in the Query relative to the reference which may or may not be helpful(line numbers are specific to the file, not relevant here, I apologize for the non-pythonic code!), but I cannot modify the Query according to dashes in the reference....</p>
  
  <pre><code>    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 &lt; len(indices):
                      y+=1
  
                      if y &lt; 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:]+"&gt;1"
              found = 0
              y = 0
  </code></pre>