def testWriteToFile3(self): """ We will test out writing out some random graphs to Pajek """ numVertices = 20 numFeatures = 0 vList = VertexList(numVertices, numFeatures) graph = SparseGraph(vList) p = 0.1 generator = ErdosRenyiGenerator(p) graph = generator.generate(graph) pw = PajekWriter() directory = PathDefaults.getOutputDir() + "test/" pw.writeToFile(directory + "erdosRenyi20", graph) #Now write a small world graph p = 0.2 k = 3 graph.removeAllEdges() generator = SmallWorldGenerator(p, k) graph = generator.generate(graph) pw.writeToFile(directory + "smallWorld20", graph)
def testWriteToFile(self): pw = PajekWriter() directory = PathDefaults.getOutputDir() + "test/" #Have to check the files fileName1 = directory + "denseTestUndirected" pw.writeToFile(fileName1, self.dGraph1) fileName2 = directory + "denseTestDirected" pw.writeToFile(fileName2, self.dGraph2) fileName3 = directory + "sparseTestUndirected" pw.writeToFile(fileName3, self.sGraph1) fileName4 = directory + "sparseTestDirected" pw.writeToFile(fileName4, self.sGraph2) fileName5 = directory + "dictTestUndirected" pw.writeToFile(fileName5, self.dctGraph1) fileName6 = directory + "dictTestDirected" pw.writeToFile(fileName6, self.dctGraph2)
def testWriteToFile2(self): pw = PajekWriter() directory = PathDefaults.getOutputDir() + "test/" def setVertexColour(vertexIndex, graph): colours = ["grey05", "grey10", "grey15", "grey20", "grey25"] return colours[vertexIndex] def setVertexSize(vertexIndex, graph): return vertexIndex def setEdgeColour(vertexIndex1, vertexIndex2, graph): colours = ["grey05", "grey10", "grey15", "grey20", "grey25"] return colours[vertexIndex1] def setEdgeSize(vertexIndex1, vertexIndex2, graph): return vertexIndex1 + vertexIndex2 pw.setVertexColourFunction(setVertexColour) fileName1 = directory + "vertexColourTest" pw.writeToFile(fileName1, self.dGraph1) pw.setVertexColourFunction(None) pw.setVertexSizeFunction(setVertexSize) fileName1 = directory + "vertexSizeTest" pw.writeToFile(fileName1, self.dGraph1) pw.setVertexSizeFunction(None) pw.setEdgeColourFunction(setEdgeColour) fileName1 = directory + "edgeColourTest" pw.writeToFile(fileName1, self.dGraph1) pw.setEdgeColourFunction(None) pw.setEdgeSizeFunction(setEdgeSize) fileName1 = directory + "edgeSizeTest" pw.writeToFile(fileName1, self.dGraph1) pw.setEdgeColourFunction(None)
def testWriteToFile2(self): pw = PajekWriter() directory = PathDefaults.getOutputDir() + "test/" def setVertexColour(vertexIndex, graph): colours = ["grey05", "grey10", "grey15", "grey20", "grey25"] return colours[vertexIndex] def setVertexSize(vertexIndex, graph): return vertexIndex def setEdgeColour(vertexIndex1, vertexIndex2, graph): colours = ["grey05", "grey10", "grey15", "grey20", "grey25"] return colours[vertexIndex1] def setEdgeSize(vertexIndex1, vertexIndex2, graph): return vertexIndex1+vertexIndex2 pw.setVertexColourFunction(setVertexColour) fileName1 = directory + "vertexColourTest" pw.writeToFile(fileName1, self.dGraph1) pw.setVertexColourFunction(None) pw.setVertexSizeFunction(setVertexSize) fileName1 = directory + "vertexSizeTest" pw.writeToFile(fileName1, self.dGraph1) pw.setVertexSizeFunction(None) pw.setEdgeColourFunction(setEdgeColour) fileName1 = directory + "edgeColourTest" pw.writeToFile(fileName1, self.dGraph1) pw.setEdgeColourFunction(None) pw.setEdgeSizeFunction(setEdgeSize) fileName1 = directory + "edgeSizeTest" pw.writeToFile(fileName1, self.dGraph1) pw.setEdgeColourFunction(None)
from apgl.viroscopy.HIVGraphReader import HIVGraphReader from apgl.io.PajekWriter import PajekWriter from apgl.util import * import logging import sys import math logging.basicConfig(stream=sys.stdout, level=logging.INFO) """ A script to load up the HIV data in its entirity. """ hivReader = HIVGraphReader() graph = hivReader.readHIVGraph() def getVertexSize(vertexIndex, graph): return math.sqrt(len(graph.neighbours(vertexIndex))) def getEdgeWeight(vertexIndex1, vertexIndex2, graph): return graph.getEdge(vertexIndex1, vertexIndex2, 0) outputDirectory = PathDefaults.getOutputDir() fileName = outputDirectory + "hivGraph" pajekWriter = PajekWriter() pajekWriter.setVertexSizeFunction(getVertexSize) pajekWriter.setEdgeWeightFunction(getEdgeWeight) pajekWriter.writeToFile(fileName, graph)