class_docstr: Class for creating and modifying the causal graph.
  
  Accepts a networkx DiGraph, a :py:class:`ProbabilisticCausalModel <dowhy.gcm.ProbabilisticCausalModel`, a graph string (or a text file) in gml format (preferred) or dot format. Graphviz-like attributes can be set for edges and nodes. E.g. style="dashed" as an edge attribute ensures that the edge is drawn with a dashed line.
  
   If a graph string is not given, names of treatment, outcome, and confounders, instruments and effect modifiers (if any) can be provided to create the graph.
class_docstr_tok: ["Class","for","creating","and","modifying","the","causal","graph",".","Accepts","a","networkx","DiGraph",",","a",":","py",":","class",":","`","ProbabilisticCausalModel","<","dowhy.gcm.ProbabilisticCausalModel","`",",","a","graph","string","(","or","a","text","file",")","in","gml","format","(","preferred",")","or","dot","format",".","Graphviz-like","attributes","can","be","set","for","edges","and","nodes",".","E.g",".","style=","''","dashed","''","as","an","edge","attribute","ensures","that","the","edge","is","drawn","with","a","dashed","line",".","If","a","graph","string","is","not","given",",","names","of","treatment",",","outcome",",","and","confounders",",","instruments","and","effect","modifiers","(","if","any",")","can","be","provided","to","create","the","graph","."]
docstr: Method to create a new graph based on the concept of do-surgery.
  
  :param node_names: focal nodes for the surgery
  :param remove_outgoing_edges: whether to remove outgoing edges from the focal nodes
  :param remove_incoming_edges: whether to remove incoming edges to the focal nodes
  :param target_node_names: target nodes (optional) for the surgery, only used when remove_only_direct_edges_to_target is True
  :param remove_only_direct_edges_to_target: whether to remove only the direct edges from focal nodes to the target nodes
  
  :returns: a new networkx graph after the specified removal of edges
docstr_tok: ["Method","to","create","a","new","graph","based","on","the","concept","of","do-surgery",".",":","param","node_names",":","focal","nodes","for","the","surgery",":","param","remove_outgoing_edges",":","whether","to","remove","outgoing","edges","from","the","focal","nodes",":","param","remove_incoming_edges",":","whether","to","remove","incoming","edges","to","the","focal","nodes",":","param","target_node_names",":","target","nodes","(","optional",")","for","the","surgery",",","only","used","when","remove_only_direct_edges_to_target","is","True",":","param","remove_only_direct_edges_to_target",":","whether","to","remove","only","the","direct","edges","from","focal","nodes","to","the","target","nodes",":","returns",":","a","new","networkx","graph","after","the","specified","removal","of","edges"]
code: def do_surgery(
      self,
      node_names,
      remove_outgoing_edges=False,
      remove_incoming_edges=False,
      target_node_names=None,
      remove_only_direct_edges_to_target=False,
  ):
      """Method to create a new graph based on the concept of do-surgery.
  
      :param node_names: focal nodes for the surgery
      :param remove_outgoing_edges: whether to remove outgoing edges from the focal nodes
      :param remove_incoming_edges: whether to remove incoming edges to the focal nodes
      :param target_node_names: target nodes (optional) for the surgery, only used when remove_only_direct_edges_to_target is True
      :param remove_only_direct_edges_to_target: whether to remove only the direct edges from focal nodes to the target nodes
  
      :returns: a new networkx graph after the specified removal of edges
      """
  
      node_names = parse_state(node_names)
      new_graph = self._graph.copy()
      for node_name in node_names:
          if remove_outgoing_edges:
              if remove_only_direct_edges_to_target:
                  new_graph.remove_edges_from(
                      [(node_name, v) for v in target_node_names]
                  )
              else:
                  children = new_graph.successors(node_name)
                  edges_bunch = [
                      (node_name, child) for child in children
                  ]
                  new_graph.remove_edges_from(edges_bunch)
          if remove_incoming_edges:
              # removal of only direct edges wrt a target is not implemented for incoming edges
              parents = new_graph.predecessors(node_name)
              edges_bunch = [(parent, node_name) for parent in parents]
              new_graph.remove_edges_from(edges_bunch)
      return new_graph
  
imports: import itertools
  import logging
  import re
  import networkx
  from dowhy.gcm.causal_models import ProbabilisticCausalModel
  from dowhy.utils.api import parse_state
  from dowhy.utils.graph_operations import daggity_to_dot
  from dowhy.utils.plotting import plot
label_desc: Use image node_id 8 for calling the CausalGraph obj's underlying member method code with example usage: obj.do_surgery(node_names, remove_outgoing_edges, remove_incoming_edges, target_node_names, remove_only_direct_edges_to_target) and returns: new_graph