Skip to content

Commit

Permalink
🐛 Fix dotfiles to handle BIDS
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed May 5, 2021
1 parent c5f322e commit 80d3f7e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions CPAC/pipeline/nipype_pipeline_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from nipype.pipeline import engine as pe
from nipype.pipeline.engine.utils import (
_create_dot_graph,
format_dot,
generate_expanded_graph,
get_print_name,
_replacefunk,
Expand Down Expand Up @@ -204,6 +205,62 @@ def _get_dot(
logger.debug("cross connection: %s", dotlist[-1])
return ("\n" + prefix).join(dotlist)

def write_graph(
self,
dotfilename="graph.dot",
graph2use="hierarchical",
format="png",
simple_form=True,
):
graphtypes = ["orig", "flat", "hierarchical", "exec", "colored"]
if graph2use not in graphtypes:
raise ValueError(
"Unknown graph2use keyword. Must be one of: " + str(graphtypes)
)
base_dir, dotfilename = os.path.split(dotfilename)
if base_dir == "":
if self.base_dir:
base_dir = self.base_dir
if self.name:
base_dir = os.path.join(base_dir, self.name)
else:
base_dir = os.getcwd()
os.makedirs(base_dir, exist_ok=True)
if graph2use in ["hierarchical", "colored"]:
if self.name[:1].isdigit(): # these graphs break if int
raise ValueError(
"{} graph failed, workflow name cannot begin "
"with a number".format(graph2use)
)
dotfilename = os.path.join(base_dir, dotfilename)
self.write_hierarchical_dotfile(
dotfilename=dotfilename,
colored=graph2use == "colored",
simple_form=simple_form,
)
outfname = format_dot(dotfilename, format=format)
else:
graph = self._graph
if graph2use in ["flat", "exec"]:
graph = self._create_flat_graph()
if graph2use == "exec":
graph = generate_expanded_graph(deepcopy(graph))
outfname = export_graph(
graph,
base_dir,
dotfilename=dotfilename,
format=format,
simple_form=simple_form,
)

logger.info(
"Generated workflow graph: %s (graph2use=%s, simple_form=%s)."
% (outfname, graph2use, simple_form)
)
return outfname

write_graph.__doc__ = pe.Workflow.write_graph.__doc__

def write_hierarchical_dotfile(
self, dotfilename=None, colored=False, simple_form=True
):
Expand Down

0 comments on commit 80d3f7e

Please sign in to comment.