(libhookecurve.py, hooke.py , fit.py, generalvclamp.py) Added color attribute to...
[hooke.git] / pcluster.py
index 3707b5a8ec179f076115f83c8bc07dd4622356d9..8f144fcd787c5d31fccc05e52f5f6d0e21104896 100644 (file)
@@ -39,7 +39,7 @@ class pclusterCommands:
                 pl_value=float(pl_expression[1]) #actual value
             else:
                 pl_value=None
-                           
+                
         #configuration variables
         min_npks = self.convfilt_config['minpeaks']
         min_deviation = self.convfilt_config['mindeviation']
@@ -312,24 +312,22 @@ class pclusterCommands:
         f=open(file_name)
         rows = f.readlines()
         for row in rows:
-               if row[0]=="/":
-                       nPlotTot = nPlotTot+1
-                       #plot_path_temp = row.split("/")[6][:-1]
-                       plot_path_temp = row
-               if row[0]==" " and row.find('nan')==-1:
-                       row = row[row.index(";",2)+2:].split(" ; ")     # non considero la prima colonna col #picchi
-                       row = [float(i) for i in row]
+            if row[0]=="/":
+                nPlotTot = nPlotTot+1
+                #plot_path_temp = row.split("/")[6][:-1]
+                plot_path_temp = row
+            if row[0]==" " and row.find('nan')==-1:
+                row = row[row.index(";",2)+2:].split(" ; ")    # non considero la prima colonna col #picchi
+                row = [float(i) for i in row]
                         
-                       #0:Mean delta, 1:Median delta, 2:Mean force, 3:Median force, 4:First peak length, 5:Last peak length
+                #0:Mean delta, 1:Median delta, 2:Mean force, 3:Median force, 4:First peak length, 5:Last peak length
                         #6:Max delta 7:Min delta 8:Max force 9:Min force 10:Std delta 11:Std force
-                       if (row[0]<500 and row[1]<500 and row[2]<500 and row[3]<500 and row[4]<500 and row[5]<500):
-                               if (row[0]>0 and row[1]>0 and row[2]>0 and row[3]>0 and row[4]>0 and row[5]>0 and row[6]>0 and row[7]>0 and row[8]>0 and row[9]>0):
-                                       nPlotGood = nPlotGood+1
-                                       self.pca_paths[nPlotGood] = plot_path_temp
-                                        #row=[row[1],row[2],row[4],row[10],row[11]]
-                                        #row=[row[10],row[11], row[0], row[2]]
-                                       self.pca_myArray.append(row)
-                        
+                if (row[0]<9000 and row[1]<9000 and row[2]<9000 and row[3]<9000 and row[4]<9000 and row[5]<9000):
+                    if (row[0]>0 and row[1]>0 and row[2]>0 and row[3]>0 and row[4]>0 and row[5]>0):
+                        self.pca_paths[nPlotGood] = plot_path_temp
+                        row=[row[1],row[2]]
+                        self.pca_myArray.append(row)
+                        nPlotGood = nPlotGood+1
                         
         f.close()
         print nPlotGood, "of", nPlotTot
@@ -337,19 +335,40 @@ class pclusterCommands:
         # array convert, calculate PCA, transpose
         self.pca_myArray = np.array(self.pca_myArray,dtype='float')
         print self.pca_myArray.shape
+        '''for i in range(len(self.pca_myArray)):
+            print i, self.pca_paths[i]
+            print i, self.pca_myArray[i]'''
         self.pca_myArray = pca(self.pca_myArray, output_dim=2) #other way -> y = mdp.nodes.PCANode(output_dim=2)(gigi)
         myArrayTr = np.transpose(self.pca_myArray)
         
+        '''for i in range(len(self.pca_myArray)):
+            print i, self.pca_paths[i]
+            print i, self.pca_myArray[i]'''
+        
         # plotting
         X=myArrayTr[0]
         Y=myArrayTr[1]
         clustplot=lhc.PlotObject()
-        clustplot.add_set(X,Y)
-        #clustplot.add_set(X[:14],Y[:14])
+        
+        Xsyn=[]
+        Ysyn=[]
+        Xgb1=[]
+        Ygb1=[]
+        for index in range(len(self.pca_paths)):
+            if 'syn' in self.pca_paths[index]:
+                Xsyn.append(X[index])
+                Ysyn.append(Y[index])
+            else:
+                Xgb1.append(X[index])
+                Ygb1.append(Y[index])
+        
+        clustplot.add_set(Xsyn,Ysyn)
+        clustplot.add_set(Xgb1,Ygb1)
         clustplot.normalize_vectors()
+        clustplot.styles=['scatter', 'scatter']
+        clustplot.colors=[None,'red']
         #clustplot.styles=['scatter',None]
         clustplot.destination=1
-        
         self._send_plot([clustplot])
         self.clustplot=clustplot
         
@@ -362,7 +381,7 @@ class pclusterCommands:
         indice = point[0].index
         plot_file = self.pca_paths[indice]
         dot_coord = self.pca_myArray[indice]
-        print "file: " + str(plot_file)
+        print "file: " + str(plot_file).rstrip()
         print "id: " + str(indice)
         print "coord: " + str(dot_coord)
         self.do_genlist(str(plot_file))