def shuffle_genome(genome, cat, fraction = float(<NUM_LIT:100>), plot = True,alpha = <NUM_LIT:0.1>, beta = <NUM_LIT>,min_length = <NUM_LIT:1000>, max_length = <NUM_LIT>):
header = '<STR_LIT>' % (genome.name)<EOL>sequence = list('<STR_LIT>'.join([i[<NUM_LIT:1>] for i in parse_fasta(genome)]))<EOL>length = len(sequence)<EOL>shuffled = []<EOL>while sequence is not False:<EOL><INDENT>s = int(random.gammavariate(alpha, beta))<EOL>if s <= min_length or s >= max_length:<EOL><INDENT>continue<EOL><DEDENT>if len(sequence) < s:<EOL><INDENT>seq = sequence[<NUM_LIT:0>:]<EOL><DEDENT>else:<EOL><INDENT>seq = sequence[<NUM_LIT:0>:s]<EOL><DEDENT>sequence = sequence[s:]<EOL><INDENT>if bool(random.getrandbits(<NUM_LIT:1>)) is True:<EOL><INDENT>seq = rev_c(seq)<EOL>print('<STR_LIT>' % ('<STR_LIT>'.format(s)), file=sys.stderr)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>' % ('<STR_LIT>'.format(s)), file=sys.stderr)<EOL><DEDENT><DEDENT>shuffled.append('<STR_LIT>'.join(seq))<EOL>if sequence == []:<EOL><INDENT>break<EOL><DEDENT><DEDENT>random.shuffle(shuffled)<EOL>if fraction == float(<NUM_LIT:100>):<EOL><INDENT>subset = shuffled<EOL><DEDENT>else:<EOL><INDENT>max_pieces = int(length * fraction/<NUM_LIT:100>)<EOL>subset, total = [], <NUM_LIT:0><EOL>for fragment in shuffled:<EOL><INDENT>length = len(fragment)<EOL>if total + length <= max_pieces:<EOL><INDENT>subset.append(fragment)<EOL>total += length<EOL><DEDENT>else:<EOL><INDENT>diff = max_pieces - total<EOL>subset.append(fragment[<NUM_LIT:0>:diff])<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if cat is True:<EOL><INDENT>yield [header, '<STR_LIT>'.join(subset)]<EOL><DEDENT>else:<EOL><INDENT>for i, seq in enumerate(subset):<EOL><INDENT>yield ['<STR_LIT>' % (header, i), seq]<EOL><DEDENT><DEDENT>
randomly shuffle genome