def get_chromosome_lengths(fasta_file, fancy_sort=True):
chromlen = []<EOL>with gzip.open(fasta_file, '<STR_LIT>', encoding='<STR_LIT:ascii>') as fh:<EOL><INDENT>fasta = SeqIO.parse(fh, '<STR_LIT>')<EOL>for i, f in enumerate(fasta):<EOL><INDENT>chromlen.append((f.id, len(f.seq)))<EOL>_LOGGER.info('<STR_LIT>', f.id)<EOL><DEDENT><DEDENT>chromlen = pd.Series(OrderedDict(chromlen))<EOL>chromlen.index.name = '<STR_LIT>'<EOL>chromlen.name = '<STR_LIT>'<EOL>if fancy_sort:<EOL><INDENT>chrom_for_sorting = chromlen.index.to_series().apply(_transform_chrom)<EOL>a = chrom_for_sorting.argsort(kind='<STR_LIT>')<EOL>chromlen = chromlen.iloc[a]<EOL><DEDENT>return chromlen<EOL>
Extract chromosome lengths from genome FASTA file.