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.Element
convertToXml
(Graph graph) convertToXml.getCollidersFromGraph
(Node node, Graph graph) getCollidersFromGraph.static nu.xom.Element
getRootElement
(File file) getRootElement.grabLayout
(List<Node> nodes) grabLayout.static String
graphRMatrixTxt
(Graph graph) graphRMatrixTxt.static String
Converts a given graph into an adjacency matrix in CPAG format.static String
Saves a PAG in the "amat.pag" format of PCALG.static String
graphToDot
(Graph graph) Converts a graph to a Graphviz .dot filestatic void
graphToDot
(Graph graph, File file) graphToDot.static String
graphToLavaan.static String
graphToPcalg.static String
graphToXml
(Graph graph) graphToXml.static Graph
loadGraph.static Graph
loadGraphAmatCpdag
(File file) Loads a CPDAG in the "amat.cpdag" format of PCALG.static Graph
loadGraphAmatPag
(File file) Loads a PAG in the "amat.pag" format of PCALG.static Graph
loadGraphBNTPcMatrix
(List<Node> vars, DataSet dataSet) loadGraphBNTPcMatrix.static Graph
loadGraphJson
(File file) loadGraphJson.static String
loadGraphRMatrix
(Graph graph) loadGraphRMatrix.static Graph
loadGraphRuben
(File file) loadGraphRuben.static String
loadGraphTxt
(Graph graph, boolean pagEdgeSpecializationMarked) Converts a given graph to human-readable text format.static Graph
loadGraphTxt
(File file) loadGraphTxt.static Graph
loadRSpecial
(File file) loadRSpecial.static Graph
parseGraphXml
(nu.xom.Element graphElement, Map<String, Node> nodes) parseGraphXml.static Graph
readerToGraphJson
(Reader reader) readerToGraphJson.static Graph
readerToGraphRuben
(Reader reader) readerToGraphRuben.static Graph
readerToGraphTxt
(Reader reader) readerToGraphTxt.static Graph
readerToGraphTxt
(String graphString) readerToGraphTxt.static void
saveGraph.
-
Method Details
-
loadGraph
-
loadGraphTxt
-
loadGraphRuben
-
loadGraphJson
-
loadGraphBNTPcMatrix
-
graphRMatrixTxt
graphRMatrixTxt.
- Parameters:
graph
- aGraph
object- Returns:
- a
String
object - 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
- aGraph
object- Returns:
- a
String
object - Throws:
IllegalArgumentException
- if any.
-
readerToGraphTxt
readerToGraphTxt.
- Parameters:
graphString
- aString
object- Returns:
- a
Graph
object - Throws:
IOException
- if any.
-
readerToGraphTxt
readerToGraphTxt.
- Parameters:
reader
- aReader
object- Returns:
- a
Graph
object - Throws:
IOException
- if any.
-
saveGraph
-
readerToGraphRuben
readerToGraphRuben.
- Parameters:
reader
- aReader
object- Returns:
- a
Graph
object - Throws:
IOException
- if any.
-
readerToGraphJson
readerToGraphJson.
- Parameters:
reader
- aReader
object- Returns:
- a
Graph
object - 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
- aFile
object- Returns:
- a
Element
object - 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
-