code: def scan_for_valid_codon(codon_span, strand, seqid, genome, type='start'):
      
      s, e = codon_span[0], codon_span[1]
      while True:
          if (type == 'start' and strand == '+') or \
              (type == 'stop' and strand == '-'):
              s, e = s - 3, e - 3
          else:
              s, e = s + 3, e + 3
  
          codon = _fasta_slice(genome, seqid, s, e, strand)
          is_valid = is_valid_codon(codon, type=type)
          if not is_valid:
              if type == 'start':
                  ## if we are scanning upstream for a valid start codon,
                  ## stop scanning when we encounter a stop
                  if is_valid_codon(codon, type='stop'):
                      return (None, None)
              elif type == 'stop':
                  ## if we are scanning downstream for a valid stop codon,
                  ## stop scanning when we encounter a start
                  if is_valid_codon(codon, type='start'):
                      return (None, None)
              continue
          break
  
      return (s, e)
docs: Given a codon span, strand and reference seqid, scan upstream/downstream
      to find a valid in-frame start/stop codon