title: Getting the next set of letters from a sequence in a loop
body: <p>I am working on a program that identifies ORFs from a sequence. I seem to be stumbling upon an error while the program is supposed to be analyzing the codons from the sequence.
  My code is:</p>
  
  <pre><code>def __init__(self,sequence):
      self.sequence = Seq(sequence)
      self.reverse = self.sequence.reverse_complement()
      self.sequence = str(self.sequence)
      self.stopcodons = ["TAG", "TAA", "TGA"]
      self.start = 'ATG'
      self.length = 0
      self.result = ("+",0,0,0,0)
  
  def codon(self,frame):
      start = frame
      while start +3 &lt;=len(self.sequence):
          yield (self.sequence[start:start+3],start)
          start += 3
      #print (start)
  
  def direction(self):
      direction = "+"
      for frame in range(3):
        self.ORF(frame, direction)
      direction = "-"
      for frame in range(3):
          self.sequence = self.reverse
          self.ORF(frame, direction)
      SeqAnalyzer.results()
  
  def ORF(self, frame, direction):
      orf_beg = 0
      codon_frame = self.codon(frame)
      while True:
          i, index = next(codon_frame)
          if i in self.start or not self.start and i not in self.stopcodons:
              orf_beg = index + 1
          elif i in self.stopcodons:
              orf_ending = index + 3
              length = (orf_ending - orf_beg) + 1
              if length &gt; self.length:
                  self.length = length
                  self.result = (direction, frame, orf_beg, orf_ending, length)
                  print(self.result)
              break
  def results(self):
      print("'{}{:+d} {:&gt;5d}..{:&gt;5d} {:&gt;5d}'" .format(self.result))
  </code></pre>
  
  <p>When running it I get an error of:</p>
  
  <pre><code>File "C:/Users/Alex/OneDrive/Python/Lab 5/findORFs.py", line 33, in direction
  
  self.ORF(frame, direction)
  File "C:/Users/Alex/OneDrive/Python/Lab 5/findORFs.py", line 44, in ORF
  
  i, index = next(codon_frame)
  StopIteration
  </code></pre>
  
  <p>The problem seems to be coming from my Next(codon_frame) but have no idea how I would go about fixing that.</p>