def sort_by_size(infile, outfile, smallest_first=False):
seqs = {}<EOL>file_to_dict(infile, seqs)<EOL>seqs = list(seqs.values())<EOL>seqs.sort(key=lambda x: len(x), reverse=not smallest_first)<EOL>fout = utils.open_file_write(outfile)<EOL>for seq in seqs:<EOL><INDENT>print(seq, file=fout)<EOL><DEDENT>utils.close(fout)<EOL>
Sorts input sequence file by biggest sequence first, writes sorted output file. Set smallest_first=True to have smallest first