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 Summary
Modifier 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 StringloadGraphTxt(Graph graph, boolean pagEdgeSpecializationMarked) Converts a given graph to human-readable text format.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
-
loadGraph
-
loadGraphTxt
-
loadGraphRuben
-
loadGraphJson
-
loadGraphBNTPcMatrix
-
graphRMatrixTxt
graphRMatrixTxt.
- Parameters:
graph- aGraphobject- Returns:
- a
Stringobject - Throws:
IllegalArgumentException- if any.
-
loadRSpecial
-
loadGraphAmatCpdag
Loads 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.
-
loadGraphAmatPag
Loads 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.
-
loadGraphRMatrix
loadGraphRMatrix.
- Parameters:
graph- aGraphobject- Returns:
- a
Stringobject - Throws:
IllegalArgumentException- if any.
-
readerToGraphTxt
readerToGraphTxt.
- Parameters:
graphString- aStringobject- Returns:
- a
Graphobject - Throws:
IOException- if any.
-
readerToGraphTxt
readerToGraphTxt.
- Parameters:
reader- aReaderobject- Returns:
- a
Graphobject - Throws:
IOException- if any.
-
saveGraph
-
readerToGraphRuben
readerToGraphRuben.
- Parameters:
reader- aReaderobject- Returns:
- a
Graphobject - Throws:
IOException- if any.
-
readerToGraphJson
readerToGraphJson.
- Parameters:
reader- aReaderobject- Returns:
- a
Graphobject - Throws:
IOException- if any.
-
graphToDot
-
graphToDot
-
convertToXml
-
graphToXml
-
graphToLavaan
-
graphToPcalg
-
graphToAmatCpag
Converts 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)
-
graphToAmatPag
Saves 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) -
parseGraphXml
-
getRootElement
getRootElement.
- Parameters:
file- aFileobject- Returns:
- a
Elementobject - Throws:
nu.xom.ParsingException- if any.IOException- if any.
-
grabLayout
-
getCollidersFromGraph
-
loadGraphTxt
Converts a given graph to human-readable text format.- Parameters:
graph- the graph to be convertedpagEdgeSpecializationMarked- whether to add edge specialization markups to the graph before conversion- Returns:
- the human-readable representation of the graph
-