def positions_to_contigs(positions):
if isinstance(positions, np.ndarray):<EOL><INDENT>flattened_positions = positions.flatten()<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>flattened_positions = np.array(<EOL>[pos for contig in positions for pos in contig])<EOL><DEDENT>except TypeError:<EOL><INDENT>flattened_positions = np.array(positions)<EOL><DEDENT><DEDENT>if (np.diff(positions) == <NUM_LIT:0>).any() and not (<NUM_LIT:0> in set(positions)):<EOL><INDENT>warnings.warn("<STR_LIT>")<EOL>return positions<EOL><DEDENT>n = len(flattened_positions)<EOL>contigs = np.ones(n)<EOL>counter = <NUM_LIT:0><EOL>for i in range(<NUM_LIT:1>, n):<EOL><INDENT>if positions[i] == <NUM_LIT:0>:<EOL><INDENT>counter += <NUM_LIT:1><EOL>contigs[i] += counter<EOL><DEDENT>else:<EOL><INDENT>contigs[i] = contigs[i - <NUM_LIT:1>]<EOL><DEDENT><DEDENT>return contigs<EOL>
Flattens and converts a positions array to a contigs array, if applicable.