def get_random_sequence(length, exclude=None):
 seen = set()
 def add_seen(kmer):
  seen.add(kmer)
  seen.add(revcomp(kmer))
 if (exclude is not None):
  for pos in range(0, (len(exclude) - K)):
   add_seen(exclude[pos:((pos + K) - 1)])
 seq = [random.choice('ACGT') for _ in range((K - 1))]
 add_seen(''.join(seq))
 while (len(seq) < length):
  next_base = random.choice('ACGT')
  next_kmer = ''.join((seq[((- K) + 2):] + [next_base]))
  assert (len(next_kmer) == (K - 1))
  if (next_kmer not in seen):
   seq.append(next_base)
   add_seen(next_kmer)
  else:
   continue
 return ''.join(seq)

def get_random_sequence ( length , exclude = None ) : seen = set ( ) def add_seen ( kmer ) : seen . add ( kmer ) seen . add ( revcomp ( kmer ) ) if ( exclude is not None ) : for pos in range ( 0 , ( len ( exclude ) - K ) ) : add_seen ( exclude [ pos : ( ( pos + K ) - 1 ) ] ) seq = [ random . choice ( 'ACGT' ) for _ in range ( ( K - 1 ) ) ] add_seen ( '' . join ( seq ) ) while ( len ( seq ) < length ) : next_base = random . choice ( 'ACGT' ) next_kmer = '' . join ( ( seq [ ( ( - K ) + 2 ) : ] + [ next_base ] ) ) assert ( len ( next_kmer ) == ( K - 1 ) ) if ( next_kmer not in seen ) : seq . append ( next_base ) add_seen ( next_kmer ) else : continue return '' . join ( seq )
generate a random nucleotide sequence .