libs/decluster.py
def extractMembers(cluster_file, cluster_reps):
    '''
        Description: Takes a cluster file from cdhit and extracts all members
            from a cluster if the cluster representative is defined in a list.
            
        Inputs:
        cluster_file - string. Path to a cd_hit cluster file
        cluster_reps - list. A list of cluster headers, whose members should be extracted from the cluster_file
        
        Outputs:
        out - list. A list of cluster headers extracted from the cluster file
    '''
    cur_cluster = None
    clusters = {}
    with open(cluster_file, 'r') as f:
        for line in f:
            if line.startswith('>'):
                if not cur_cluster is None:
                    clusters[cur_cluster]=temp
                cur_cluster = None
                temp = []
            else:
                cur_header = line.split('...')[0].split(' ')[-1].strip()
                if cur_header.startswith('>'):
                    cur_header = cur_header[1:]
                temp.append( cur_header )
                if line.strip().endswith('*'):
                    cur_cluster = cur_header
        if not cur_cluster is None:
            clusters[cur_cluster]=temp
    out = []
    for rep in cluster_reps:
        if clusters.get(rep) is not None:
            out.extend(clusters[rep])
    return list(set(out))

        Description: Takes a cluster file from cdhit and extracts all members
            from a cluster if the cluster representative is defined in a list.
            
        Inputs:
        cluster_file - string. Path to a cd_hit cluster file
        cluster_reps - list. A list of cluster headers, whose members should be extracted from the cluster_file
        
        Outputs:
        out - list. A list of cluster headers extracted from the cluster file
    
Takes a cluster file from cdhit and extracts all members
from a cluster if the cluster representative is defined in a list.

string. Path to a cd_hit cluster file
cluster_reps - list. A list of cluster headers, whose members should be extracted from the cluster_file

list. A list of cluster headers extracted from the cluster file
Takes a cluster file from cdhit and extracts all members from a cluster if the cluster representative is defined in a list . string . Path to a cd_hit cluster file cluster_reps - list . A list of cluster headers whose members should be extracted from the cluster_file list . A list of cluster headers extracted from the cluster file
def extractMembers(cluster_file, cluster_reps):
    cur_cluster = None
    clusters = {}
    with open(cluster_file, 'r') as f:
        for line in f:
            if line.startswith('>'):
                if not cur_cluster is None:
                    clusters[cur_cluster]=temp
                cur_cluster = None
                temp = []
            else:
                cur_header = line.split('...')[0].split(' ')[-1].strip()
                if cur_header.startswith('>'):
                    cur_header = cur_header[1:]
                temp.append( cur_header )
                if line.strip().endswith('*'):
                    cur_cluster = cur_header
        if not cur_cluster is None:
            clusters[cur_cluster]=temp
    out = []
    for rep in cluster_reps:
        if clusters.get(rep) is not None:
            out.extend(clusters[rep])
    return list(set(out))
def extractMembers ( cluster_file , cluster_reps ) : cur_cluster = None clusters = { } with open ( cluster_file , 'r' ) as f : for line in f : if line . startswith ( '>' ) : if not cur_cluster is None : clusters [ cur_cluster ] = temp cur_cluster = None temp = [ ] else : cur_header = line . split ( '...' ) [ 0 ] . split ( ' ' ) [ - 1 ] . strip ( ) if cur_header . startswith ( '>' ) : cur_header = cur_header [ 1 : ] temp . append ( cur_header ) if line . strip ( ) . endswith ( '*' ) : cur_cluster = cur_header if not cur_cluster is None : clusters [ cur_cluster ] = temp out = [ ] for rep in cluster_reps : if clusters . get ( rep ) is not None : out . extend ( clusters [ rep ] ) return list ( set ( out ) )
Description: Takes a cluster file from cdhit and extracts all members
from a cluster if the cluster representative is defined in a list.
Description : Takes a cluster file from cdhit and extracts all members from a cluster if the cluster representative is defined in a list .
'''
        Description: Takes a cluster file from cdhit and extracts all members
            from a cluster if the cluster representative is defined in a list.
            
        Inputs:
        cluster_file - string. Path to a cd_hit cluster file
        cluster_reps - list. A list of cluster headers, whose members should be extracted from the cluster_file
        
        Outputs:
        out - list. A list of cluster headers extracted from the cluster file
    '''
cluster_file
cluster_reps