Package edu.cmu.tetrad.graph
Class GraphSaveLoadUtils
java.lang.Object
edu.cmu.tetrad.graph.GraphSaveLoadUtils
Methods to load or save graphs.
- Version:
- $Id: $Id
- Author:
- josephramsey
- 
Method SummaryModifier and TypeMethodDescriptionstatic nu.xom.ElementconvertToXml(Graph graph) convertToXml.getCollidersFromGraph(Node node, Graph graph) getCollidersFromGraph.static nu.xom.ElementgetRootElement(File file) getRootElement.grabLayout(List<Node> nodes) grabLayout.static StringgraphRMatrixTxt(Graph graph) graphRMatrixTxt.static StringConverts a given graph into an adjacency matrix in CPAG format.static StringSaves a PAG in the "amat.pag" format of PCALG.static StringgraphToDot(Graph graph) Converts a graph to a Graphviz .dot filestatic voidgraphToDot(Graph graph, File file) graphToDot.static StringgraphToLavaan.static StringgraphToPcalg.static StringgraphToXml(Graph graph) graphToXml.static GraphloadGraph.static GraphloadGraphAmatCpdag(File file) Loads a CPDAG in the "amat.cpdag" format of PCALG.static GraphloadGraphAmatPag(File file) Loads a PAG in the "amat.pag" format of PCALG.static GraphloadGraphBNTPcMatrix(List<Node> vars, DataSet dataSet) loadGraphBNTPcMatrix.static GraphloadGraphJson(File file) loadGraphJson.static StringloadGraphRMatrix(Graph graph) loadGraphRMatrix.static GraphloadGraphRuben(File file) loadGraphRuben.static GraphloadGraphTxt(File file) loadGraphTxt.static GraphloadRSpecial(File file) loadRSpecial.static GraphparseGraphXml(nu.xom.Element graphElement, Map<String, Node> nodes) parseGraphXml.static GraphreaderToGraphJson(Reader reader) readerToGraphJson.static GraphreaderToGraphRuben(Reader reader) readerToGraphRuben.static GraphreaderToGraphTxt(Reader reader) readerToGraphTxt.static GraphreaderToGraphTxt(String graphString) readerToGraphTxt.static voidsaveGraph.
- 
Method Details- 
loadGraphloadGraph. 
- 
loadGraphTxtloadGraphTxt. 
- 
loadGraphRubenloadGraphRuben. 
- 
loadGraphJsonloadGraphJson. 
- 
loadGraphBNTPcMatrixloadGraphBNTPcMatrix. 
- 
graphRMatrixTxtgraphRMatrixTxt. - Parameters:
- graph- a- Graphobject
- Returns:
- a Stringobject
- Throws:
- IllegalArgumentException- if any.
 
- 
loadRSpecialloadRSpecial. 
- 
loadGraphAmatCpdagLoads a CPDAG in the "amat.cpdag" format of PCALG. We will assume here that the graph in R has been saved to disk using the write.table(mat, path) method. For the amat.cpdag format, for a matrix m, there are two cases where edges occur in the graph: (1) m[i][j] = 0 and m[j][i] = 1, in which case an edge i->j exists; or, (2) m[i][j] = 1 and m[j][i] = 1, in which case an undirected edge i--j exists. In all other cases, there is no edge between i and j.- Parameters:
- file- a file in the "amat.cpdag" format of PCALG.
- Returns:
- a graph.
 
- 
loadGraphAmatPagLoads a PAG in the "amat.pag" format of PCALG. We will assume here that the graph in R has been saved to disk using the write.table(mat, path) method. For the amat.pag format, for a matrix m, endpoints are explicitly represented, as follows. 1 is a circle endpoint, 2 is an arrow endpoint, 3 is a tail endpoint, and 0 is a null endpoint (i.e., no edge). For an edge i->j, m[i][j] = 2 and m[j][i] = 3.- Parameters:
- file- a file in the "amat.cpdag" format of PCALG.
- Returns:
- a graph.
 
- 
loadGraphRMatrixloadGraphRMatrix. - Parameters:
- graph- a- Graphobject
- Returns:
- a Stringobject
- Throws:
- IllegalArgumentException- if any.
 
- 
readerToGraphTxtreaderToGraphTxt. - Parameters:
- graphString- a- Stringobject
- Returns:
- a Graphobject
- Throws:
- IOException- if any.
 
- 
readerToGraphTxtreaderToGraphTxt. - Parameters:
- reader- a- Readerobject
- Returns:
- a Graphobject
- Throws:
- IOException- if any.
 
- 
saveGraphsaveGraph. - Parameters:
- graph- The graph to be saved.
- file- The file to save it in.
- xml- True if to be saved in XML, false if in text.
 
- 
readerToGraphRubenreaderToGraphRuben. - Parameters:
- reader- a- Readerobject
- Returns:
- a Graphobject
- Throws:
- IOException- if any.
 
- 
readerToGraphJsonreaderToGraphJson. - Parameters:
- reader- a- Readerobject
- Returns:
- a Graphobject
- Throws:
- IOException- if any.
 
- 
graphToDotConverts a graph to a Graphviz .dot file
- 
graphToDotgraphToDot. 
- 
convertToXmlconvertToXml. - Parameters:
- graph- a- Graphobject
- Returns:
- an XML element representing the given graph. (Well, only a basic graph for now...)
 
- 
graphToXmlgraphToXml. 
- 
graphToLavaangraphToLavaan. 
- 
graphToPcalggraphToPcalg. 
- 
graphToAmatCpagConverts a given graph into an adjacency matrix in CPAG format.- Parameters:
- g- the input graph to be converted
- Returns:
- the adjacency matrix representation of the graph in CPAG format
- Throws:
- IllegalArgumentException- if the graph is not a MPDAG (including CPDAG or DAG)
 
- 
graphToAmatPagSaves a PAG in the "amat.pag" format of PCALG. We will save it in the form that R would print the matrix to file using write.matrix(mat, path). For the amat.pag format, for a matrix m, endpoints are explicitly represented, as follows. 1 is a circle endpoint, 2 is an arrow endpoint, 3 is a tail endpoint, and 0 is a null endpoint (i.e., no edge)
- 
parseGraphXmlpublic static Graph parseGraphXml(nu.xom.Element graphElement, Map<String, Node> nodes) throws nu.xom.ParsingExceptionparseGraphXml. 
- 
getRootElementgetRootElement. - Parameters:
- file- a- Fileobject
- Returns:
- a Elementobject
- Throws:
- nu.xom.ParsingException- if any.
- IOException- if any.
 
- 
grabLayoutgrabLayout. 
- 
getCollidersFromGraphgetCollidersFromGraph. 
 
-