def detect_clusters(c, current_seq, MIN_SEQ, non_un_gl=False):
current_loci = {}<EOL>current_clus = {}<EOL>sequence2clusters = defaultdict(set)<EOL>lindex = <NUM_LIT:0><EOL>eindex = <NUM_LIT:0><EOL>previous_id = <NUM_LIT:0><EOL>for line in c.features():<EOL><INDENT>c, start, end, name, score, strand, c_id = line<EOL>name = int(name.replace('<STR_LIT>', '<STR_LIT>'))<EOL>pos = int(start) if strand == "<STR_LIT:+>" else int(end)<EOL>if name not in current_seq:<EOL><INDENT>continue<EOL><DEDENT>if c.find('<STR_LIT>') > -<NUM_LIT:1> and non_un_gl:<EOL><INDENT>continue<EOL><DEDENT>if c_id != previous_id:<EOL><INDENT>if previous_id > <NUM_LIT:0>:<EOL><INDENT>if len(current_clus[eindex].idmembers) < MIN_SEQ:<EOL><INDENT>for s in current_clus[eindex].idmembers:<EOL><INDENT>sequence2clusters[s] = sequence2clusters[s] - set([eindex])<EOL><DEDENT>del current_clus[eindex]<EOL><DEDENT><DEDENT>logger.debug("<STR_LIT>" % (c_id, previous_id, name))<EOL>lindex += <NUM_LIT:1><EOL>eindex += <NUM_LIT:1><EOL>current_clus[eindex] = cluster(eindex)<EOL>newpos = position(lindex, c, start, end, strand)<EOL>current_loci[lindex] = newpos<EOL><DEDENT>current_loci[lindex].end = int(end)<EOL>current_loci[lindex].coverage[pos] += <NUM_LIT:1><EOL>size = range(pos, pos + current_seq[name].len)<EOL>current_loci[lindex].counts.update(dict(zip(size, [current_seq[name].total()] * current_seq[name].len)))<EOL>current_clus[eindex].idmembers[name] = <NUM_LIT:1><EOL>current_clus[eindex].add_id_member([name], lindex)<EOL>current_seq[name].add_pos(lindex, pos)<EOL>previous_id = c_id<EOL>sequence2clusters[name].add(eindex)<EOL><DEDENT>logger.info("<STR_LIT>" % eindex)<EOL>metacluster_obj, cluster_id = _find_metaclusters(current_clus, sequence2clusters, current_seq, MIN_SEQ)<EOL>return cluster_info_obj(current_clus, metacluster_obj, current_loci, current_seq)<EOL>
Parse the merge file of sequences position to create clusters that will have all
sequences that shared any position on the genome

:param c: file from bedtools with merge sequence positions
:param current_seq: list of sequences
:param MIN_SEQ: int cutoff to keep the cluster or not. 10 as default

:return: object with information about:
    * cluster
    * dict with sequences (as keys) and cluster_id (as value)
    * sequences
    * loci