[Biopython] [BioPython] JP (Jarvis Patrick) Clustering
    Brad Chapman 
    chapmanb at 50mail.com
       
    Wed Apr 22 13:09:53 UTC 2009
    
    
  
Hi Florian;
[Moving to Biopython list]
> >> Does anybody know an (open source) clustering package containing the 
> >> Jarvis Patrick clustering algorithm?
> >>     
> > Here is a version in R and C:
> > http://rguha.net/code/R/#jp
[...]
> Do you know how to do the 'rpy calls '
>
> >dyn.load('jpc.so')
> >source('jpc.R')
> >clus <- jpc(dat, j=3, k=1, diss=FALSE) 
> 
> for executing the script?
Sure, here is how I would do it with python and rpy2. This builds a
random array of 10 items to cluster, each with 4 points, and then runs
the JPC clustering algorithm from Rajarshi's page on them. At the end,
it shows how to extract the clustered indexes from the results.
Hope this helps,
Brad
import numpy
import rpy2.robjects as robjects
import rpy2.robjects.numpy2ri
robjects.r('''
    dyn.load('jpc.so')
    source('jpc.R')
''')
num_groups = 10
data = numpy.random.random((num_groups, 4))
cluster = robjects.r.jpc(data, j=3, k=1, diss=False)
for gindex in range(num_groups):
    print 'Group ID:', gindex, 'Cluster ID:', cluster[0][1][gindex]
print cluster
    
    
More information about the Biopython
mailing list