source: orange-bioinformatics/docs/modules/assess2.py @ 1623:186d828e3699

Revision 1623:186d828e3699, 1.1 KB checked in by mitar, 2 years ago (diff)

Renamed documentation directory.

Line 
1import orange
2import obiAssess
3import obiGeneSets
4
5gs = obiGeneSets.collections([":kegg:hsa"])
6data = orange.ExampleTable("DLBCL.tab")
7
8asl = obiAssess.AssessLearner()
9ass = asl(data, "hsa", geneSets=gs)
10
11def genesetsAsAttributes(data, ass, domain=None):
12    """
13    Construct new data set with gene sets as attributes from data
14    set "data" with assess model "ass".
15    """
16
17    ares = {}
18    for ex in data:
19        cres = ass(ex)
20        for name,val in cres.items():
21            aresl = ares.get(name, [])
22            aresl.append(val)
23            ares[name] = aresl
24
25    ares = sorted(ares.items())
26
27    if not domain: #construct new domain instance if needed
28        domain = orange.Domain([ orange.FloatVariable(name=name) \
29            for name in [ a[0] for a in ares]], data.domain.classVar )
30
31    examples = [ [ b[zap] for a,b in ares ] + \
32        [ data[zap][-1] ]   for zap in range(len(data)) ]
33
34    et = orange.ExampleTable(domain, examples)
35    return et
36
37tdata = genesetsAsAttributes(data, ass)
38
39print "First 10 attributes of the first example in transformed data set"
40for pathw, enric in zip(tdata.domain,tdata[0])[:10]:
41    print pathw.name, enric.value
Note: See TracBrowser for help on using the repository browser.