Marko Toplak avatar Marko Toplak committed 8ef1b76

Added PLS to obiGeneSetSig.

Comments (0)

Files changed (2)

     #ass = AssessLearner()(data, matcher, gsets, rankingf=AT_loessLearner())
     #ass = MeanLearner()(data, matcher, gsets, default=False)
     #ass = MedianLearner()(data, matcher, gsets)
-    #ass = PLSLearner()(data, matcher, gsets, classValues=choosen_cv)
+    ass = PLSLearner()(data, matcher, gsets, classValues=choosen_cv, minPart=0.0)
     #ass = SetSigLearner()(ldata, matcher, gsets, classValues=choosen_cv, minPart=0.0)
-    ass = PCALearner()(ldata, matcher, gsets, classValues=choosen_cv, minPart=0.0)
+    #ass = PCALearner()(ldata, matcher, gsets, classValues=choosen_cv, minPart=0.0)
     #ass = GSALearner()(ldata, matcher, gsets, classValues=choosen_cv, minPart=0.0)
 
     ar = defaultdict(list)
 from collections import defaultdict
 import stats
 from obiGsea import takeClasses
-from obiAssess import pca
+from obiAssess import pca, PLSCall
 
 def setSig_example_geneset(ex, data):
     """ Gets learning data and example with the same domain, both
         at.get_value_from = t
         return at
 
+class PLS(GeneSetTrans):
+
+    def build_feature(self, data, gs):
+
+        at = Orange.feature.Continuous(name=str(gs))
+
+        geneset = list(gs.genes)
+
+        nm, name_ind = self._mat_ni(data)
+        genes = [ nm.umatch(gene) for gene in geneset ]
+        takegenes = [ i for i,a in enumerate(genes) if a != None ]
+        genes = [ genes[i] for i in takegenes ]
+
+        domain = Orange.data.Domain([data.domain.attributes[name_ind[gene]] for gene in genes], data.domain.class_var)
+
+        datao = Orange.data.Table(domain, data)
+
+        xmean, W, P, T = PLSCall(datao, nc=1, y=[datao.domain.class_var])
+        constructt = xmean, W, P
+
+        def t(ex, w, geneset=geneset, constructt=constructt, takegenes=takegenes, domain=domain):
+
+            nm2, name_ind2 = self._mat_ni(ex)
+            genes2 = [ nm2.umatch(gene) for gene in geneset ]
+            genes2 = [ genes2[i] for i in takegenes ]
+          
+            #convert the example to the same domain
+            exvalues = [ vou(ex, gn, name_ind2) for gn in genes2 ] + [ "?" ]
+            
+            ex = numpy.array(exvalues[:-1])
+
+            xmean, W, P = constructt
+            ex = ex - xmean # same input transformation
+
+            nc = W.shape[1]
+
+            TR = numpy.empty((1, nc))
+            XR = ex
+
+            dot = numpy.dot
+
+            for i in range(nc):
+               t = dot(XR, W[:,i].T)
+               XR = XR - t*numpy.array([P[:,i]])
+               TR[:,i] = t
+
+            return TR[0][0]
+
+        at.get_value_from = t
+        return at
+
 class PCA(GeneSetTrans):
 
     def build_feature(self, data, gs):
         ol =  sorted(ar.items())
         print '\n'.join([ a + ": " +str(b) for a,b in ol])
 
-    ass = Mean(data, matcher=matcher, gene_sets=gsets, class_values=choosen_cv, min_part=0.0)
+    ass = PLS(data, matcher=matcher, gene_sets=gsets, class_values=choosen_cv, min_part=0.0)
     ar = to_old_dic(ass.domain, data[:5])
     pp2(ar)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.