from Pycluster import *
import numpy as Numeric

MISSING_DATA = -9999.99


def kmeans(profileSet,k,**kw):
    ''' interface function for the kmeans implementation
    from the Pycluster. It integrates the data representation
    between GQL and Pyclyster.
    See Pycluster documetation for optional
    parameters options '''
    
    data = profileSet.profile
    m = Numeric.not_equal(data,MISSING_DATA)
    
    return kcluster(data,mask=m, nclusters=k,**kw)


def hierarchical(profileSet,k,**kw):
    ''' interface function for the kmeans implementation
    from the Pycluster. It integrates the data representation
    between GQL and Pyclyster.
    See Pycluster documetation for optional
    parameters options '''

    #XXX - check file saving
    #XXX - improve tree cutting (to avoid small clusters)
    
    data = profileSet.profile

    m = Numeric.not_equal(data,MISSING_DATA)

    (tree) = treecluster(data,mask=m, **kw)

#    writeclusterfiles("saida",data,profileSet.genename,['1','2','3','4','5','6','7'],mask=m,geneclusters=tree,genelinkdist=link)

    return tree.cut(k)

          
