Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.progressBarFinished()
self.lastNameComponentAttribute = None
if self.optimization is None or self.optimization.graph is None or self.optimization.graph.items is None:
return
vars = [x.name for x in self.optimization.getVars()]
if not self.nameComponentCombo.currentText() in vars:
return
self.progressBarInit()
components = [c for c in self.optimization.graph.getConnectedComponents() if len(c) > 1]
if 'component name' in self.optimization.graph.items.domain:
keyword_table = self.optimization.graph.items
else:
keyword_table = orange.ExampleTable(orange.Domain(orange.StringVariable('component name')), [[''] for i in range(len(self.optimization.graph.items))])
import obiGO
ontology = obiGO.Ontology.Load(progressCallback=self.progressBarSet)
annotations = obiGO.Annotations.Load(self.organism, ontology=ontology, progressCallback=self.progressBarSet)
allGenes = set([e[str(self.nameComponentCombo.currentText())].value for e in self.optimization.graph.items])
foundGenesets = False
if len(annotations.geneNames & allGenes) < 1:
allGenes = set(reduce(operator.add, [e[str(self.nameComponentCombo.currentText())].value.split(', ') for e in self.optimization.graph.items]))
if len(annotations.geneNames & allGenes) < 1:
self.warning('no genes found')
return
else:
foundGenesets = True
def rank(a, j, reverse=False):
import orngNetwork
atts = []
atts.append(orange.StringVariable("Network Name"))
atts.append(orange.StringVariable("Network File"))
atts.append(orange.StringVariable("dir"))
atts.append(orange.StringVariable("Item Set"))
atts.append(orange.StringVariable("Edge Set"))
atts.append(orange.FloatVariable("Vertices"))
atts[-1].numberOfDecimals = 0
atts.append(orange.FloatVariable("Edges"))
atts[-1].numberOfDecimals = 0
atts.append(orange.StringVariable("Date"))
atts.append(orange.StringVariable("Description"))
netlist = orange.ExampleTable(orange.Domain(atts, False))
for netFile in glob.glob(os.path.join(os.getcwd(), '*.net')):
net = orngNetwork.Network.read(netFile)
name, ext = os.path.splitext(netFile)
itemFile = ""
if os.path.exists(name + '_items.tab'):
itemFile = name + '_items.tab'
elif os.path.exists(name + '.tab'):
itemFile = name + '.tab'
edgeFile = ""
if os.path.exists(name + '_edges.tab'):
edgeFile = name + '_edges.tab'
netlist.append([net.name, os.path.basename(netFile), "doc/datasets/", os.path.basename(itemFile), os.path.basename(edgeFile), net.nVertices, len(net.getEdges()), "4/12/2010", net.description])
def replaceAttributes(index1, index2, merged, data):
attrs = list(data.domain)
attrs.remove(data.domain[index1])
attrs.remove(data.domain[index2])
domain = orange.Domain(attrs+ [merged])
return data.select(domain)
old = all_attributes[i]
if i in special_attributes:
oldv = [v for v in old.values]
assert('.' not in oldv)
new = orange.EnumVariable(name='M_'+old.name, values=oldv+['.'])
warnings.warn('Removing special values from %s into %s.'%(old.name,new.name))
newatts.append(new)
else:
newatts.append(old)
# convert table
exs = []
# 2006-08-23: added by PJ: add a class variable (if not already existing)
if not t.domain.classVar:
newatts.append(orange.EnumVariable("class", values=["."]))
t = orange.ExampleTable(orange.Domain(t.domain.attributes, newatts[-1]), t)
newd = orange.Domain(newatts)
for ex in t:
nex = []
for i in range(len(newatts)):
if ex[i].isSpecial():
v = newatts[i]('.')
else:
v = newatts[i](int(ex[i]))
nex.append(v)
exs.append(orange.Example(newd,nex))
t = orange.ExampleTable(exs)
return t
domain = self.continuizer(attrDataset)
attrDataset = attrDataset.translate(domain)
except TypeError, e:
raise orange.KernelException, "One or more attributes form training set are missing!"
dataMatrix, classArray, x = attrDataset.toNumpy()
dataMatrix -= self.center
if self.deviation != None:
dataMatrix *= 1. / self.deviation
#save transformed data
self._dataMatrix = numpy.dot(dataMatrix, self.loadings)
attributes = [orange.FloatVariable("PC%d" % (i + 1,)) for i in range(len(self.evalues))]
new_domain = orange.Domain(attributes)
new_table = orange.ExampleTable(new_domain, self._dataMatrix)
if dataset.domain.classVar:
#suboptimal
classTable = dataset.select([dataset.domain.classVar.name])
self._classArray = numpy.array([row.getclass() for row in classTable])
new_table = orange.ExampleTable([new_table, classTable])
return new_table
domain = self.continuizer(attrDataset)
attrDataset = attrDataset.translate(domain)
except TypeError, e:
raise orange.KernelException, "One or more attributes form training set are missing!"
dataMatrix, classArray, x = attrDataset.toNumpy()
dataMatrix -= self.center
if self.deviation is not None:
dataMatrix *= 1. / self.deviation
#save transformed data
self._dataMatrix = numpy.dot(dataMatrix, self.loadings)
attributes = [orange.FloatVariable("PC%d" % (i + 1,)) for i in range(len(self.evalues))]
new_domain = orange.Domain(attributes)
new_table = orange.ExampleTable(new_domain, self._dataMatrix)
if dataset.domain.classVar:
#suboptimal
classTable = dataset.select([dataset.domain.classVar.name])
self._classArray = numpy.array([row.getclass() for row in classTable])
new_table = orange.ExampleTable([new_table, classTable])
return new_table
data2 = data.select(newattrs + [data.domain.classVar])
for ex in data2[:10]:
print ex
print "\nFayyad-Irani discretization"
entro = orange.EntropyDiscretization()
for attr in data.domain.attributes:
disc = entro(attr, data)
print "%s: %s" % (attr.name, disc.getValueFrom.transformer.points)
print
newclass = orange.EnumVariable("is versicolor", values = ["no", "yes"])
newclass.getValueFrom = lambda ex, w: ex["iris"]=="Iris-versicolor"
newdomain = orange.Domain(data.domain.attributes, newclass)
data_v = orange.ExampleTable(newdomain, data)
print "\nBi-Modal discretization on binary problem"
bimod = orange.BiModalDiscretization(splitInTwo = 0)
for attr in data_v.domain.attributes:
disc = bimod(attr, data_v)
print "%s: %s" % (attr.name, disc.getValueFrom.transformer.points)
print
print "\nBi-Modal discretization on binary problem"
bimod = orange.BiModalDiscretization()
for attr in data_v.domain.attributes:
disc = bimod(attr, data_v)
print "%s: (%5.3f, %5.3f]" % (attr.name, disc.getValueFrom.transformer.low, disc.getValueFrom.transformer.high)
print
def __call__(self, data, y, x=None, weight=None):
if y == None:
try:
y = [data.domain.classVar]
except:
import warnings
warnings.warn("multi-class learner requires either specification of response variables or a data domain with a class")
return None
if x == None:
print y
x = [v for v in data.domain.variables if v not in y]
models = []
for a in y:
newDomain = orange.Domain(x, a)
newData = orange.ExampleTable(newDomain, data)
models.append(baseLearner(newData))
return MultiClassPrediction(x=x, y=y, models=models)
filename = "imports-85.tab"
data = orange.ExampleTable(filename)
reportAttributes(data, "Original data set")
newData1 = data.select(range(5))
reportAttributes(newData1, "First five attributes")
newData2 = data.select(['engine-location', 'wheel-base', 'length'])
reportAttributes(newData2, "Attributes selected by name")
domain3 = orange.Domain([data.domain[0], data.domain['curb-weight'], data.domain[2]])
newData3 = data.select(domain3)
reportAttributes(newData3, "Attributes by domain")
domain4 = orange.Domain([data.domain[0], data.domain['curb-weight'], data.domain[2]], 0)
newData4 = data.select(domain4)
reportAttributes(newData4, "Attributes by domain")
self.send("Medoids", None)
return
clustVar = orange.EnumVariable(self.classifyName, values = [str(x) for x in range(1, 1+self.K)])
origDomain = self.data.domain
if self.addIdAs == 0:
domain=orange.Domain(origDomain.attributes,clustVar)
if origDomain.classVar:
domain.addmeta(orange.newmetaid(), origDomain.classVar)
aid = -1
elif self.addIdAs == 1:
domain=orange.Domain(origDomain.attributes+[clustVar], origDomain.classVar)
aid = len(origDomain.attributes)
else:
domain=orange.Domain(origDomain.attributes, origDomain.classVar)
aid=orange.newmetaid()
domain.addmeta(aid, clustVar)
domain.addmetas(origDomain.getmetas())
# construct a new data set, with a class as assigned by k-means clustering
table1=orange.ExampleTable(domain)
table1.extend(orange.ExampleTable(self.data))
for ex, midx in izip(table1, self.mc.mapping):
ex[aid] = clustVar(str(midx))
self.send("Examples", table1)
self.send("Medoids", table1.getitems(self.mc.medoids))