def initialize(self, VTKWebApp, args): dataid = args.id treedata = getDBdata(dataid) VTKWebApp.tree1 = treedata["tree1"] VTKWebApp.tree2 = treedata["tree2"] VTKWebApp.table = dataid+ ".csv" # Create default pipeline (Only once for all the session) if not VTKWebApp.view: # read the trees treeReader1 = vtk.vtkNewickTreeReader() treeReader1.SetReadFromInputString(1) treeReader1.SetInputString(VTKWebApp.tree1) treeReader1.Update() tree1 = treeReader1.GetOutput() treeReader2 = vtk.vtkNewickTreeReader() treeReader2.SetReadFromInputString(1) treeReader2.SetInputString(VTKWebApp.tree2) treeReader2.Update() tree2 = treeReader2.GetOutput() # read the table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(VTKWebApp.table) tableReader.SetHaveHeaders(True) tableReader.DetectNumericColumnsOn() tableReader.ForceDoubleOn() tableReader.Update() table = tableReader.GetOutput() # setup the tanglegram tanglegram = vtk.vtkTanglegramItem() tanglegram.SetTree1(tree1); tanglegram.SetTree2(tree2); tanglegram.SetTable(table); tanglegram.SetTree1Label("tree1"); tanglegram.SetTree2Label("tree2"); # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1,1,1) view.GetRenderWindow().SetSize(800,600) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(tanglegram) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # VTK Web application specific VTKWebApp.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
def initialize(self): global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor # Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery()) # Update authentication key to use self.updateSecret(_PhylogeneticTree.authKey) # Create default pipeline (Only once for all the session) if not _PhylogeneticTree.view: # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetFileName(_PhylogeneticTree.treeFilePath) treeReader.Update() reader = treeReader.GetOutput() # read in a table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(_PhylogeneticTree.csvFilePath) tableReader.SetHaveHeaders(True) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() # play with the heatmap vis treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(reader) treeHeatmapItem.SetTable(table) # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1, 1, 1) view.GetRenderWindow().SetSize(800, 600) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(treeHeatmapItem) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # VTK Web application specific _PhylogeneticTree.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject( "VIEW", view.GetRenderWindow())
def initialize(self): global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor # Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery()) # Update authentication key to use self.updateSecret(_PhylogeneticTree.authKey) # Create default pipeline (Only once for all the session) if not _PhylogeneticTree.view: # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetFileName(_PhylogeneticTree.treeFilePath) treeReader.Update() reader = treeReader.GetOutput() # read in a table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(_PhylogeneticTree.csvFilePath) tableReader.SetHaveHeaders(True) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() # play with the heatmap vis treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(reader); treeHeatmapItem.SetTable(table); # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1,1,1) view.GetRenderWindow().SetSize(800,600) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(treeHeatmapItem) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # VTK Web application specific _PhylogeneticTree.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
def testReadWrite(self): t = '(A:1,B:2,(C:3,D:4)E:5)F;' reader = vtk.vtkNewickTreeReader() reader.SetReadFromInputString(True) reader.SetInputString(t) reader.Update() writer = vtk.vtkNewickTreeWriter() writer.WriteToOutputStringOn() writer.SetInputData(reader.GetOutput()) writer.Update() t_return = writer.GetOutputStdString() self.assertEqual(t,t_return)
def testReadWrite(self): t = '(A:1,B:2,(C:3,D:4)E:5)F;' reader = vtk.vtkNewickTreeReader() reader.SetReadFromInputString(True) reader.SetInputString(t) reader.Update() writer = vtk.vtkNewickTreeWriter() writer.WriteToOutputStringOn() writer.SetInputData(reader.GetOutput()) writer.Update() t_return = writer.GetOutputStdString() self.assertEqual(t, t_return)
def testTreeOutput(self): tree_reader = vtk.vtkNewickTreeReader() tree_reader.ReadFromInputStringOn() tree_reader.SetInputString(tree_data) rcal = vtk.vtkRCalculatorFilter() rcal.SetInputConnection(tree_reader.GetOutputPort()) rcal.SetRscript("library(ape)\n\ output = read.tree(text=\"" + tree_data + "\")\n") rcal.GetTree('output') rcal.Update() expected_tree = tree_reader.GetOutput() self.assertTrue(treeEquals(expected_tree, rcal.GetOutput()))
def initialize(self, VTKWebApp, args): VTKWebApp.treeFilePath = args.tree VTKWebApp.csvFilePath = args.table # Create default pipeline (Only once for all the session) if not VTKWebApp.view: # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetFileName(VTKWebApp.treeFilePath) treeReader.Update() reader = treeReader.GetOutput() # read in a table tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(VTKWebApp.csvFilePath) tableReader.SetHaveHeaders(1) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() # play with the heatmap vis treeHeatmapItem = vtk.vtkTreeHeatmapItem() treeHeatmapItem.SetTree(reader) treeHeatmapItem.SetTable(table) # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1, 1, 1) view.GetRenderWindow().SetSize(800, 600) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(treeHeatmapItem) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # VTK Web application specific VTKWebApp.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
def testTreeOutput(self): tree_reader = vtk.vtkNewickTreeReader() tree_reader.ReadFromInputStringOn() tree_reader.SetInputString(tree_data) rcal = vtk.vtkRCalculatorFilter() rcal.SetInputConnection(tree_reader.GetOutputPort()) rcal.SetRscript("library(ape)\n\ output = read.tree(text=\"" + tree_data + "\")\n"); rcal.GetTree('output') rcal.Update() expected_tree = tree_reader.GetOutput() self.assertTrue(treeEquals(expected_tree, rcal.GetOutput()))
def NewickToVTKTree(newick): reader = vtk.vtkNewickTreeReader() reader.SetReadFromInputString(1) reader.SetInputString(newick, len(newick)) reader.Update() return reader.GetOutput()
def initialize(self, VTKWebApp, args): dataid = args.id treedata = getDBdata(dataid) VTKWebApp.tree = treedata["tree"] VTKWebApp.table = dataid+ ".csv" # Create default pipeline (Only once for all the session) if not VTKWebApp.view: treeHeatmapItem = vtk.vtkTreeHeatmapItem() # read in a tree treeReader = vtk.vtkNewickTreeReader() treeReader.SetReadFromInputString(1) treeReader.SetInputString(VTKWebApp.tree) treeReader.Update() tree = treeReader.GetOutput() treeHeatmapItem.SetTree(tree) if (VTKWebApp.table != "none" and os.path.isfile(VTKWebApp.table)): # read in a table print("read table"+ VTKWebApp.table) tableReader = vtk.vtkDelimitedTextReader() tableReader.SetFileName(VTKWebApp.table) tableReader.SetHaveHeaders(1) tableReader.DetectNumericColumnsOn() tableReader.Update() table = tableReader.GetOutput() if (table): treeHeatmapItem.SetTable(table) # setup the window view = vtk.vtkContextView() view.GetRenderer().SetBackground(1,1,1) view.GetRenderWindow().SetSize(800,600) iren = view.GetInteractor() iren.SetRenderWindow(view.GetRenderWindow()) transformItem = vtk.vtkContextTransform() transformItem.AddItem(treeHeatmapItem) transformItem.SetInteractive(1) view.GetScene().AddItem(transformItem) view.GetRenderWindow().SetMultiSamples(0) iren.Initialize() view.GetRenderWindow().Render() # adjust zoom so the item nicely fills the screen itemSize = [0, 0] treeHeatmapItem.GetSize(itemSize) itemSize.append(0) transformItem.GetTransform().MultiplyPoint(itemSize, itemSize) newWidth = view.GetScene().GetSceneWidth() newHeight = view.GetScene().GetSceneHeight() pageWidth = newWidth pageHeight = newHeight sx = pageWidth / itemSize[0] sy = pageHeight / itemSize[1] if sy < sx: scale = sy; else: scale = sx; if scale > 1: scale = scale * 0.5 else: scale = scale * 0.9 transformItem.Scale(scale, scale) # center the item within the screen itemCenter = [0, 0] treeHeatmapItem.GetCenter(itemCenter) itemCenter.append(0) centerPt = vtk.vtkPoints2D() centerPt.InsertNextPoint(newWidth / 2.0, newHeight / 2.0) transformItem.GetTransform().InverseTransformPoints(centerPt, centerPt) sceneCenter = [0, 0] centerPt.GetPoint(0, sceneCenter) dx = -1 * (itemCenter[0] - sceneCenter[0]) dy = -1 * (itemCenter[1] - sceneCenter[1]) transformItem.Translate(dx, dy) # VTK Web application specific VTKWebApp.view = view.GetRenderWindow() self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
import vtk reader = vtk.vtkNewickTreeReader() reader.SetReadFromInputString(True) reader.SetInputString(input, len(input)) reader.Update() output = reader.GetOutput()