Python pydot.graph_from_dot_data() Examples

The following are 26 code examples of pydot.graph_from_dot_data(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pydot , or try the search function .
Example #1
Source File: predict_enriched_decision_tree.py    From PIDGINv2 with MIT License 7 votes vote down vote up
def createTree(matrix,label):
	kmeans = KMeans(n_clusters=moa_clusters, random_state=0).fit(matrix)
	vector = map(int,kmeans.labels_)
	pc_10 = int(len(querymatrix1)*0.01)
	clf = tree.DecisionTreeClassifier(min_samples_split=min_sampsplit,min_samples_leaf=min_leafsplit,max_depth=max_d)
	clf.fit(matrix,vector)
	dot_data = StringIO()
	tree.export_graphviz(clf, out_file=dot_data,
							feature_names=label,
							class_names=map(str,list(set(sorted(kmeans.labels_)))),
							filled=True, rounded=True,
							special_characters=True,
							proportion=False,
							impurity=True)
	out_tree = dot_data.getvalue()
	out_tree = out_tree.replace('True','Inactive').replace('False','Active').replace(' ≤ 0.5', '').replace('class', 'Predicted MoA')
	graph = pydot.graph_from_dot_data(str(out_tree))
	try:
		graph.write_jpg(output_name_tree)
	except AttributeError:
		graph = pydot.graph_from_dot_data(str(out_tree))[0]
		graph.write_jpg(output_name_tree)
	return

#initializer for the pool 
Example #2
Source File: findlibs.py    From binaryanalysis with Apache License 2.0 6 votes vote down vote up
def writeGraph((elfgraph, filehash, imagedir, generatesvg)):
	elfgraph_tmp = pydot.graph_from_dot_data(elfgraph)
	if type(elfgraph_tmp) == list:
		if len(elfgraph_tmp) == 1:
			elfgraph_tmp[0].write_png(os.path.join(imagedir, '%s-graph.png' % filehash))
			if generatesvg:
				elfgraph_tmp[0].write_svg(os.path.join(imagedir, '%s-graph.svg' % filehash))
	else:
		elfgraph_tmp.write_png(os.path.join(imagedir, '%s-graph.png' % filehash))
		if generatesvg:
			elfgraph_tmp.write_svg(os.path.join(imagedir, '%s-graph.svg' % filehash))

## store variable names, function names from the ELF file
## along with the type, and so on. Also store the soname for
## the ELF file, as well as any RPATH values that might have
## been defined. 
Example #3
Source File: pydot_unittest.py    From pydot with MIT License 6 votes vote down vote up
def test_unicode_ids(self):

        node1 = '"aánñoöüé€"'
        node2 = '"îôø®çßΩ"'

        g = pydot.Dot()
        g.set_charset('latin1')
        g.add_node( pydot.Node( node1 ) )
        g.add_node( pydot.Node( node2 ) )
        g.add_edge( pydot.Edge( node1, node2 ) )

        self.assertEqual( g.get_node(node1)[0].get_name(), node1 )
        self.assertEqual( g.get_node(node2)[0].get_name(), node2 )

        self.assertEqual( g.get_edges()[0].get_source(), node1 )
        self.assertEqual( g.get_edges()[0].get_destination(), node2 )
        graphs = pydot.graph_from_dot_data(g.to_string())
        (g2,) = graphs

        self.assertEqual( g2.get_node(node1)[0].get_name(), node1 )
        self.assertEqual( g2.get_node(node2)[0].get_name(), node2 )

        self.assertEqual( g2.get_edges()[0].get_source(), node1 )
        self.assertEqual( g2.get_edges()[0].get_destination(), node2 ) 
Example #4
Source File: guided_tree.py    From fairtest with Apache License 2.0 6 votes vote down vote up
def print_tree(tree, outfile, encoders):
    """
    Print a tree to a file

    Parameters
    ----------
    tree :
        the tree structure

    outfile :
        the output file

    encoders :
        the encoders used to encode categorical features
    """
    import pydot
    dot_data = StringIO()
    export_graphviz(tree, encoders, filename=dot_data)
    graph = pydot.graph_from_dot_data(dot_data.getvalue())
    graph.write_pdf(outfile) 
Example #5
Source File: plot_interactive_tree.py    From scipy_2015_sklearn_tutorial with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
def tree_image(tree, fout=None):
    try:
        import pydot
    except ImportError:
        # make a hacky white plot
        x = np.ones((10, 10))
        x[0, 0] = 0
        return x
    dot_data = StringIO()
    export_graphviz(tree, out_file=dot_data)
    data = re.sub(r"gini = 0\.[0-9]+\\n", "", dot_data.getvalue())
    data = re.sub(r"samples = [0-9]+\\n", "", data)
    data = re.sub(r"\\nsamples = [0-9]+", "", data)

    graph = pydot.graph_from_dot_data(data)
    if fout is None:
        fout = "tmp.png"
    graph.write_png(fout)
    return imread(fout) 
Example #6
Source File: dot_magic.py    From metakernel with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def cell_dot(self):
        """
        %%dot - render contents of cell as Graphviz image

        This cell magic will send the cell to the browser as
        HTML.

        Example:
            %%dot

            graph A { a->b };
        """
        try:
            import pydot
        except:
            raise Exception("You need to install pydot")
        graph = pydot.graph_from_dot_data(str(self.code))
        svg = graph.create_svg()
        if hasattr(svg, "decode"):
            svg = svg.decode("utf-8")
        html = HTML(svg)
        self.kernel.Display(html)
        self.evaluate = False 
Example #7
Source File: dot_magic.py    From metakernel with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def line_dot(self, code):
        """
        %dot CODE - render code as Graphviz image

        This line magic will render the Graphiz CODE, and render 
        it as an image.

        Example:
            %dot graph A { a->b };

        """
        try:
            import pydot
        except:
            raise Exception("You need to install pydot")
        graph = pydot.graph_from_dot_data(str(code))
        svg = graph.create_svg()
        if hasattr(svg, "decode"):
            svg = svg.decode("utf-8")
        html = HTML(svg)
        self.kernel.Display(html) 
Example #8
Source File: bytecode.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def method2format( output, _format="png", mx = None, raw = False ) :
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer
    """
    try :
        import pydot
    except ImportError :
        error("module pydot not found")

    buff = "digraph code {\n"
    buff += "graph [bgcolor=white];\n"
    buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"

    if raw == False :
        buff += method2dot( mx )
    else :
        buff += raw

    buff += "}"

    d = pydot.graph_from_dot_data( buff )
    if d :
        getattr(d, "write_" + _format)( output ) 
Example #9
Source File: supervisor.py    From fiss with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def init_supervisor_data(dotfile, sample_sets):
    """ Parse a workflow description written in DOT (like Firehose)"""
    with open(dotfile) as wf:
        graph_data = wf.read()

    graph = pydot.graph_from_dot_data(graph_data)[0]
    nodes = [n.get_name().strip('"') for n in graph.get_nodes()]

    monitor_data = dict()
    dependencies = {n:[] for n in nodes}

    # Initialize empty list of dependencies
    for n in nodes:
        monitor_data[n] = dict()
        for sset in sample_sets:
            monitor_data[n][sset] = {
                'state'        : "Not Started",
                'evaluated'    : False,
                'succeeded'    : False
            }

    edges = graph.get_edges()

    # Iterate over the edges, and get the dependency information for each node
    for e in edges:
        source = e.get_source().strip('"')
        dest = e.get_destination().strip('"')

        dep = e.get_attributes()
        dep['upstream_task'] = source

        dependencies[dest].append(dep)

    return monitor_data, dependencies 
Example #10
Source File: learn.py    From uta with Apache License 2.0 5 votes vote down vote up
def write_pdf(clf, fn):
    dot_data = StringIO()
    tree.export_graphviz(clf, out_file=dot_data)
    graph = pydot.graph_from_dot_data(dot_data.getvalue())
    graph.write_pdf(fn) 
Example #11
Source File: nx_pydot.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def read_dot(path):
    """Return a NetworkX :class:`MultiGraph` or :class:`MultiDiGraph` from the
    dot file with the passed path.

    If this file contains multiple graphs, only the first such graph is
    returned. All graphs _except_ the first are silently ignored.

    Parameters
    ----------
    path : str or file
        Filename or file handle.

    Returns
    -------
    G : MultiGraph or MultiDiGraph
        A :class:`MultiGraph` or :class:`MultiDiGraph`.

    Notes
    -----
    Use `G = nx.Graph(read_dot(path))` to return a :class:`Graph` instead of a
    :class:`MultiGraph`.
    """
    pydot = _import_pydot()
    data = path.read()

    # List of one or more "pydot.Dot" instances deserialized from this file.
    P_list = pydot.graph_from_dot_data(data)

    # Convert only the first such instance into a NetworkX graph.
    return from_pydot(P_list[0]) 
Example #12
Source File: nx_pydot.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def read_dot(path):
    """Returns a NetworkX :class:`MultiGraph` or :class:`MultiDiGraph` from the
    dot file with the passed path.

    If this file contains multiple graphs, only the first such graph is
    returned. All graphs _except_ the first are silently ignored.

    Parameters
    ----------
    path : str or file
        Filename or file handle.

    Returns
    -------
    G : MultiGraph or MultiDiGraph
        A :class:`MultiGraph` or :class:`MultiDiGraph`.

    Notes
    -----
    Use `G = nx.Graph(read_dot(path))` to return a :class:`Graph` instead of a
    :class:`MultiGraph`.
    """
    pydot = _import_pydot()
    data = path.read()

    # List of one or more "pydot.Dot" instances deserialized from this file.
    P_list = pydot.graph_from_dot_data(data)

    # Convert only the first such instance into a NetworkX graph.
    return from_pydot(P_list[0]) 
Example #13
Source File: bytecode.py    From dr_droid with Apache License 2.0 5 votes vote down vote up
def method2format( output, _format="png", mx = None, raw = False ) :
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer
    """
    try :
        import pydot
    except ImportError :
        error("module pydot not found")

    buff = "digraph code {\n"
    buff += "graph [bgcolor=white];\n"
    buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"

    if raw == False :
        buff += method2dot( mx )
    else :
        buff += raw

    buff += "}"

    d = pydot.graph_from_dot_data( buff )
    if d :
        getattr(d, "write_" + _format)( output ) 
Example #14
Source File: bytecode.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def method2format(output, _format="png", mx=None, raw=None):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """
    try:
        import pydot
    except ImportError:
        error("module pydot not found")

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_" + hashlib.md5(output).hexdigest() + " {\nlabel=\"%s\"\n" % data['name']
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, "write_" + _format.lower())(output) 
Example #15
Source File: bytecode.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def method2format( output, _format="png", mx = None, raw = False ) :
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer
    """
    try :
        import pydot
    except ImportError :
        error("module pydot not found")

    buff = "digraph code {\n"
    buff += "graph [bgcolor=white];\n"
    buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"

    if raw == False :
        buff += method2dot( mx )
    else :
        buff += raw

    buff += "}"

    d = pydot.graph_from_dot_data( buff )
    if d :
        getattr(d, "write_" + _format)( output ) 
Example #16
Source File: bytecode.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def method2format(output, _format="png", mx=None, raw=None):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """
    try:
        import pydot
    except ImportError:
        error("module pydot not found")

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_" + hashlib.md5(output).hexdigest(
    ) + " {\nlabel=\"%s\"\n" % data['name']
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, "write_" + _format.lower())(output) 
Example #17
Source File: bytecode.py    From dcc with Apache License 2.0 5 votes vote down vote up
def method2format(output, _format="png", mx=None, raw=None):
    """
    Export method to a specific file format

    @param output : output filename
    @param _format : format type (png, jpg ...) (default : png)
    @param mx : specify the MethodAnalysis object
    @param raw : use directly a dot raw buffer if None
    """
    # pydot is optional!
    import pydot

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_{} ".format(hashlib.md5(bytearray(output, "UTF-8")).hexdigest())
    buff += "{\n"
    buff += "label=\"{}\"\n".format(data['name'])
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    d = pydot.graph_from_dot_data(buff)
    if d:
        for g in d:
            getattr(g, "write_" + _format.lower())(output) 
Example #18
Source File: bytecode.py    From aurasium with GNU General Public License v3.0 5 votes vote down vote up
def method2format( output, _format="png", mx = None, raw = False ) :
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer
    """
    try :
        import pydot
    except ImportError :
        error("module pydot not found")

    buff = "digraph code {\n"
    buff += "graph [bgcolor=white];\n"
    buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"

    if raw == False :
        buff += method2dot( mx )
    else :
        buff += raw

    buff += "}"

    d = pydot.graph_from_dot_data( buff )
    if d :
        getattr(d, "write_" + _format)( output ) 
Example #19
Source File: bytecode.py    From AndroBugs_Framework with GNU General Public License v3.0 5 votes vote down vote up
def method2format(output, _format="png", mx=None, raw=None):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """
    try:
        import pydot
    except ImportError:
        error("module pydot not found")

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_" + hashlib.md5(output).hexdigest() + " {\nlabel=\"%s\"\n" % data['name']
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, "write_" + _format.lower())(output) 
Example #20
Source File: bytecode.py    From TimeMachine with GNU Lesser General Public License v3.0 5 votes vote down vote up
def method2format(output, _format="png", mx=None, raw=None):
    """
        Export method to a specific file format

        @param output : output filename
        @param _format : format type (png, jpg ...) (default : png)
        @param mx : specify the MethodAnalysis object
        @param raw : use directly a dot raw buffer if None
    """
    try:
        import pydot
    except ImportError:
        error("module pydot not found")

    buff = "digraph {\n"
    buff += "graph [rankdir=TB]\n"
    buff += "node [shape=plaintext]\n"

    if raw:
        data = raw
    else:
        data = method2dot(mx)

    # subgraphs cluster
    buff += "subgraph cluster_" + hashlib.md5(output).hexdigest() + " {\nlabel=\"%s\"\n" % data['name']
    buff += data['nodes']
    buff += "}\n"

    # subgraphs edges
    buff += data['edges']
    buff += "}\n"

    d = pydot.graph_from_dot_data(buff)
    if d:
        getattr(d, "write_" + _format.lower())(output) 
Example #21
Source File: predict_enriched_two_libraries_decision_tree.py    From PIDGINv2 with MIT License 5 votes vote down vote up
def createTree(matrix,label):
	vector = [1] * len(querymatrix1) + [0] * len(querymatrix2)
	ratio = float(len(vector)-sum(vector))/float(sum(vector))
	sw = np.array([ratio if i == 1 else 1 for i in vector])
	pc_10 = int(len(querymatrix1)*0.01)
	clf = tree.DecisionTreeClassifier(min_samples_split=min_sampsplit,min_samples_leaf=min_leafsplit,max_depth=max_d)
	clf.fit(matrix,vector)
	dot_data = StringIO()
	tree.export_graphviz(clf, out_file=dot_data,
							feature_names=label,
							class_names=['File2','File1'],
							filled=True, rounded=True,
							special_characters=True,
							proportion=False,
							impurity=True)
	out_tree = dot_data.getvalue()
	out_tree = out_tree.replace('True','Inactive').replace('False','Active').replace(' ≤ 0.5', '')
	graph = pydot.graph_from_dot_data(str(out_tree))
	try:
		graph.write_jpg(output_name_tree)
	except AttributeError:
		graph = pydot.graph_from_dot_data(str(out_tree))[0]
		graph.write_jpg(output_name_tree)
	return

#initializer for the pool 
Example #22
Source File: pydot_unittest.py    From pydot with MIT License 5 votes vote down vote up
def test_multiple_graphs(self):
        graph_data = 'graph A { a->b };\ngraph B {c->d}'
        graphs = pydot.graph_from_dot_data(graph_data)
        n = len(graphs)
        assert n == 2, n
        names = [g.get_name() for g in graphs]
        assert names == ['A', 'B'], names 
Example #23
Source File: pydot_unittest.py    From pydot with MIT License 5 votes vote down vote up
def test_graph_with_shapefiles(self):
        shapefile_dir = os.path.join(test_dir, 'from-past-to-future')
        # image files are omitted from sdist
        if not os.path.isdir(shapefile_dir):
            warnings.warn('Skipping tests that involve images, '
                          'they can be found in the `git` repository.')
            return
        dot_file = os.path.join(shapefile_dir, 'from-past-to-future.dot')


        pngs = [
            os.path.join(shapefile_dir, fname) for
            fname in os.listdir(shapefile_dir)
            if fname.endswith('.png')]

        f = open(dot_file, 'rt')
        graph_data = f.read()
        f.close()

        #g = dot_parser.parse_dot_data(graph_data)
        graphs = pydot.graph_from_dot_data(graph_data)
        (g,) = graphs
        g.set_shape_files( pngs )

        jpe_data = g.create( format='jpe' )

        hexdigest = sha256(jpe_data).hexdigest()
        hexdigest_original = self._render_with_graphviz(
            dot_file, encoding='ascii')
        self.assertEqual( hexdigest, hexdigest_original ) 
Example #24
Source File: pydot_unittest.py    From pydot with MIT License 5 votes vote down vote up
def test_attribute_with_implicit_value(self):

        d='digraph {\na -> b[label="hi", decorate];\n}'
        graphs = pydot.graph_from_dot_data(d)
        (g,) = graphs
        attrs = g.get_edges()[0].get_attributes()

        self.assertEqual( 'decorate' in attrs, True ) 
Example #25
Source File: kernelsymbols.py    From binaryanalysis with Apache License 2.0 5 votes vote down vote up
def writeGraph((symbolgraph, filehash, counter, imagedir, generatesvg)):
	symbolgraph_tmp = pydot.graph_from_dot_data(symbolgraph)
	symbolgraph_tmp.write_png(os.path.join(imagedir, '%s-%d-kernel-symbol-graph.png' % (filehash, counter)))
	if generatesvg:
		symbolgraph_tmp.write_svg(os.path.join(imagedir, '%s-%d-kernel-symbol-graph.svg' % (filehash, counter)))

## extract, lookup and bundle information for kernel files
## * version
## * kernel symbols (both locally defined and needed from remote)
## * dependencies 
Example #26
Source File: causal_graph.py    From dowhy with MIT License 4 votes vote down vote up
def __init__(self,
                 treatment_name, outcome_name,
                 graph=None,
                 common_cause_names=None,
                 instrument_names=None,
                 effect_modifier_names=None,
                 observed_node_names=None,
                 missing_nodes_as_confounders=False):
        self.treatment_name = parse_state(treatment_name)
        self.outcome_name = parse_state(outcome_name)
        instrument_names = parse_state(instrument_names)
        common_cause_names = parse_state(common_cause_names)
        self.logger = logging.getLogger(__name__)

        if graph is None:
            self._graph = nx.DiGraph()
            self._graph = self.build_graph(common_cause_names,
                                           instrument_names, effect_modifier_names)
        elif re.match(r".*\.dot", graph):
            # load dot file
            try:
                import pygraphviz as pgv
                self._graph = nx.DiGraph(nx.drawing.nx_agraph.read_dot(graph))
            except Exception as e:
                self.logger.error("Pygraphviz cannot be loaded. " + str(e) + "\nTrying pydot...")
                try:
                    import pydot
                    self._graph = nx.DiGraph(nx.drawing.nx_pydot.read_dot(graph))
                except Exception as e:
                    self.logger.error("Error: Pydot cannot be loaded. " + str(e))
                    raise e
        elif re.match(r".*\.gml", graph):
            self._graph = nx.DiGraph(nx.read_gml(graph))
        elif re.match(r".*graph\s*\{.*\}\s*", graph):
            try:
                import pygraphviz as pgv
                self._graph = pgv.AGraph(graph, strict=True, directed=True)
                self._graph = nx.drawing.nx_agraph.from_agraph(self._graph)
            except Exception as e:
                self.logger.error("Error: Pygraphviz cannot be loaded. " + str(e) + "\nTrying pydot ...")
                try:
                    import pydot
                    P_list = pydot.graph_from_dot_data(graph)
                    self._graph = nx.drawing.nx_pydot.from_pydot(P_list[0])
                except Exception as e:
                    self.logger.error("Error: Pydot cannot be loaded. " + str(e))
                    raise e
        elif re.match(".*graph\s*\[.*\]\s*", graph):
            self._graph = nx.DiGraph(nx.parse_gml(graph))
        else:
            self.logger.error("Error: Please provide graph (as string or text file) in dot or gml format.")
            self.logger.error("Error: Incorrect graph format")
            raise ValueError
        if missing_nodes_as_confounders:
            self._graph = self.add_missing_nodes_as_common_causes(observed_node_names)
        # Adding node attributes
        self._graph = self.add_node_attributes(observed_node_names)
        #TODO do not add it here. CausalIdentifier should call causal_graph to add an unobserved common cause if needed. This also ensures that we do not need get_common_causes in this class.
        self._graph = self.add_unobserved_common_cause(observed_node_names)