title: Updating values based on removed characters from string
body: <p>I am working with a dataset in which I want to extract a certain substring from a sequence. </p>
  
  <p>One of my columns contains indexes of characters within the sequence which are referenced (e.g.) <code>[45,45,D]</code> meaning that the character at the 45th position belongs to class D and indicates that the characters at position 1 to 44 are not referenced, and I have therefore removed them. </p>
  
  <p>Once the characters at those positions have been removed, I want to update the numbers in that column to indicate (e.g) <code>[1,1,D]</code> as now the 45th position is now referencing the first position.</p>
  
  <p>I am finding this difficult, as for example, for the another sequence, <code>[84,115,S]</code> So the characters at position 84 to 115 belongs to class S. The next pair of values is <code>[151, 152, 'C']</code> 
  Therefore, the characters at position 116 to 150 have been removed, and <code>[151, 152, 'C']</code> must be updated to <code>[116, 117,S]</code>. 
  The subsequent numbers in the list must also be updated (i.e.) the next number will be [118,..] instead of [153,...].</p>
  
  <p>I have provided a sample of the original sequence, the shortened sequence and the referenced character positions. </p>
  
  <p><strong>Original Sequence</strong>: MSEVTRSLLQRWGASLRRGADFDSWGQLVEAIDEYQILARHLQKEAQAQHNNSEFTEEQKKTIGKIATCLELRSAALQSTQSQEEFKLEDLKKLEPILKNILTYNKEFPFDVQPIPLRRILAPGEEENLEFEEDEEGGAGAGPPDSFSARVPGTLLPRLPSEPGMTLLTIRIEKIGLKDAGQCIDPYITVSVKDLNGIDLTPVQDTPVASRKEDTYVHFNVDIELQKHVERLTKGAAIFFEFKHYKPKKRFTSTKCFAFMEMDEIKPGPIVIELYKKPTDFKRKKLQLLTKKPLYLHLHQSLHKE</p>
  
  <p><strong>Shortened Sequence</strong>: MSEVTRSLLQRWGASLRRGADFDSWGQLVEAIDEYQILARHLQKEAQAQHNNSEFTEEQKKTIGKIATCLELRSAALQSTQSQEEFKLEDLKKLEPILKNILTYNKEFPFDVQPIVPGTLLPRLPSEPGMTLLTIRIEKIGLKDAGQCIDPYITVSVKDLNGIDLTPVQDTPVASRKEDTYVHFNVDIELQKHVERLTKGAAIFFEFKHYKPKKRFTSTKCFAFMEMDEIKPGPIVIELYKKPTDFKRKKLQLLTKKPLYLHLHQSLHKE</p>
  
  <p><strong>Referenced character positions</strong>: <code>[[1, 3, 'C'], [4, 48, 'S'], [49, 54, 'C'], [55, 79, 'S'], [80, 83, 'C'], [84, 115, 'S'], [151, 152, 'C'], [153, 304, 'S'], [305, 305, 'D']]</code></p>
  
  <p>My current approach is as follows: </p>
  
  <p>Looking at the two entries: <code>[84, 115, 'S']</code> and <code>[151, 152, 'C']</code>
  Say:
  A = 115 and B = 151.
  The difference between these two numbers is 36, therefore if I subtract 35 from each of the subsequent numbers after 151, it will give me the correct positioning of the class: i.e. [116, 117, ‘C’]. I need to do this for every place where some of the sequence has been removed. </p>
  
  <p>So I compare every 2nd number in the first [] with the first number of the next [] and if this difference is > 1, then the index has to be updated. </p>
  
  <p>I also have the case where part of the sequence is removed from the start of the sequence also. </p>
  
  <p>I have tried this by doing as follows: </p>
  
  <p>Where "shortenedlist1" is a list of lists which contain the numbers referring to the character positions: (i.e.) <code>[[45, 45, 46, 49, 50, 66, 67, 101, 102, 103, 104, 106, 107, 108, 109, 120, 121, 121, 122, 123, 124, 140, 141, 149, 150, 176, 177, 178, 179, 181, 182, 194, 195, 213, 214, 217], [1, 1, 2, 143, 144, 145], [1, 145], [24, 29, 30, 91, 92, 92], [22, 24, 25, 38, 39, 55, 56, 348]...</code></p>
  
  <pre><code>mylist = []
  i=0
  j=0
  
  for sublist in shortened_list1:
      while j &lt; len(shortened_list1):
          A = sublist[0]
          Y = sublist[i+1]
          Z = sublist[j+2]
  
          if A != 0:
              sublist = [x - (A-1) for x in sublist]
              mylist.append(sublist)
          elif (Z-Y) &gt;1:
              sublist = [x - (Z-Y-1) for x in sublist]
              mylist.append(sublist)
  
  mylist
  </code></pre>
  
  <p>This returns the correct result for the first sublist. But does not work for subsequent sublists, or for cases when the portion of the sequence has been removed from the middle. </p>