def testChainOp(self): verts = array([[-.1, -.1], [-.1, 1.1], [1.1, 1.1], [1.1, -.1]]) cols = [0, 1] g = PolyGate(verts, cols) self.fcm.gate(g).gate(g) self.assertTrue(all(self.fcm.view() == array([[0, 1, 2]])), 'gate excluded wrong points')
def build_Polygon(rect, prefix=None, suffix=None, name_prefix=None): if isinstance(name_prefix, str): name = name_prefix + "::" + rect.attrib['name'] else: name = rect.attrib['name'] verts = [] axis = [rect.attrib['xAxisName'], rect.attrib['yAxisName']] if prefix is not None and prefix is not '': for i,j in enumerate(axis): if j.startswith(prefix): axis[i] = j.replace(prefix,'') if suffix is not None and suffix is not '': for i,j in enumerate(axis): if j.endswith(suffix): axis[i] = j[:-(len(suffix))] #replaced[i] = True axis = tuple(axis) for vert in rect.iter('Vertex'): x = float(vert.attrib['x']) y = float(vert.attrib['y']) verts.append((x,y)) return PolyGate(verts, axis, name)
def testGate(self): verts = array([[-.1, -.1], [-.1, 1.1], [1.1, 1.1], [1.1, -.1]]) cols = [0, 1] g = PolyGate(verts, cols) self.fcms.gate(g) assert_array_equal(self.fcms['test_fcm1'].view(), array([[1, 1, 1]]), 'Gating failed') assert_array_equal(self.fcms['test_fcm2'].view(), array([[1, 1, 1]]), 'Gating failed')
def testPolyGate(self): verts = array([[-.1, -.1], [-.1, 1.1], [1.1, 1.1], [1.1, -.1]]) cols = [0, 1] g = PolyGate(verts, cols) self.fcm.gate(g) assert all(self.fcm.view() == array([[0, 1, 2] ])), 'gate excluded wrong points' self.fcm.visit('root') self.fcm.gate(g) nodes = self.fcm.tree.nodes.keys() assert 'g2' in nodes, 'gating name mangled' assert 'g1' in nodes, 'gating name mangled'
def testEmptyPolyGate(self): verts = array([[10, 10], [10, 11], [11, 11], [11, 10]]) cols = [0, 1] g = PolyGate(verts, cols) self.fcm.gate(g) assert_array_equal(self.fcm.view(), array([]).reshape((0, 3)), 'gated region not empty') self.fcm.gate(g) assert_array_equal(self.fcm.view(), array([]).reshape((0, 3)), 'gated region not empty') nodes = self.fcm.tree.nodes.keys() assert 'g2' in nodes, 'gating name mangled' assert 'g1' in nodes, 'gating name mangled'
def testCopy(self): cpy = self.fcm.copy() self.assertFalse(cpy is self.fcm, "copy reproduced the exact same object") self.assertTrue(cpy.tree.pprint() == self.fcm.tree.pprint(), "copy failed to reproduce the view tree") # make sure changes to object self.fcm don't show up on cpy verts = array([[-.1, -.1], [-.1, 1.1], [1.1, 1.1], [1.1, -.1]]) cols = [0, 1] g = PolyGate(verts, cols) self.fcm.gate(g) self.assertFalse(cpy.tree.pprint() == self.fcm.tree.pprint(), "copy failed to reproduce the view tree") #make sure tree is actually copied cpy = self.fcm.copy() self.assertTrue(cpy.tree.pprint() == self.fcm.tree.pprint(), "copy failed to reproduce the view tree")
alpha=alpha, **kwargs) ax.fill(gate.vert.T[0], gate.vert.T[1], edgecolor='black', facecolor='none') if __name__ == '__main__': import fcm import numpy import matplotlib import matplotlib.pyplot as plt x = fcm.loadFCS('../../sample_data/3FITC_4PE_004.fcs') g = PolyGate(numpy.array([[0, 0], [500, 0], [500, 500], [0, 500]]), [0, 1]) g3 = QuadGate([250, 300], (2, 3)) fig = plt.figure() ax = fig.add_subplot(2, 2, 1) plot_gate(x, g, ax, name="firstgate", alpha=.5, bgalpha=.5) ax = fig.add_subplot(2, 2, 2) mx = x[:, 2].max() print mx g2 = ThresholdGate(mx - 1, 2) plot_gate(x, g2, ax, name="secondgate", chan=(2, 3), alpha=.5) # , bgc='red', c='green') print x.shape print x[:] x.visit('root') ax = fig.add_subplot(2, 2, 3)