From 6665079037b64273598d0125f7e26f7b7b68c45f Mon Sep 17 00:00:00 2001 From: Eran Date: Tue, 18 Jul 2023 10:58:01 -0400 Subject: [PATCH] plot_from_file --- bigraph_viz/plot_from_file.py | 29 ++++++++ data/gut_microbiome | 122 ++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 bigraph_viz/plot_from_file.py create mode 100644 data/gut_microbiome diff --git a/bigraph_viz/plot_from_file.py b/bigraph_viz/plot_from_file.py new file mode 100644 index 0000000..5692e53 --- /dev/null +++ b/bigraph_viz/plot_from_file.py @@ -0,0 +1,29 @@ +import os +from graphviz import Source + + +def get_absolute_path(relative_path): + script_dir = os.path.dirname(os.path.realpath(__file__)) + return os.path.join(script_dir, relative_path) + + +def generate_graph_from_file(file_path, output_file=None): + # Read the content of the file + with open(file_path, 'r') as file: + graph_data = file.read() + + # Create a Source object from the Graphviz data + graph = Source(graph_data) + + # Render the graph to a file (default format is PDF, so we explicitly specify PNG) + graph.render(filename=output_file, format='png', cleanup=True) + + +def test_graph_data(): + file_path = get_absolute_path('../data/gut_microbiome') + output_file = 'out/gut_microbiome' + generate_graph_from_file(file_path=file_path, output_file=output_file) + + +if __name__ == '__main__': + test_graph_data() diff --git a/data/gut_microbiome b/data/gut_microbiome new file mode 100644 index 0000000..8d346d9 --- /dev/null +++ b/data/gut_microbiome @@ -0,0 +1,122 @@ +digraph bigraph { + // adding needed attributes here + graph [nodesep=0.06, ranksep=0.06 dpi=250 overlap=false rankdir=TB size="3,7" ratio="fill"] + node [fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine',)" [label=Intestine>, pos="0,0!"] + "('Small
Intestine', 'Duodenum')" [label=, pos="0,-1!"] + "('Small
Intestine', 'Duodenum', 'nutrients')" [label=] + "('Small
Intestine', 'Duodenum', 'mucosa')" [label=] + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus')" [label=] + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus', 'mucin')" [label=] + "('Small
Intestine', 'Duodenum', 'Epithelium')" [label=] + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" [label=cells>] + "('Small
Intestine', 'Duodenum', 'Microbiota')" [label=] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" [label=] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'mucinase')" [label=] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'flagella')" [label=] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')" [label=Firmicutes,
more>] + "('Small
Intestine', 'Jejunum')" [label=] + "('Small
Intestine', 'Ileum')" [label=] + node [constraint=false fontsize="12pt" penwidth=2 shape=box] + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells', 'secretion')" [label=] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'chemotaxis')" [label=] + "('Small
Intestine', 'Duodenum', 'uptake')" [label=] + "('Small
Intestine', 'Duodenum', 'degradation')" [label=] + "('Small
Intestine', 'Peristalsis')" [label=] + edge [arrowhead=none penwidth=2] + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus')" -> "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus', 'mucin')" + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'mucosa')" -> "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus')" + edge [style=invis] + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" -> "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells', 'secretion')" + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'Epithelium')" -> "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'mucinase')" + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'flagella')" + edge [style=invis] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'chemotaxis')" + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'Microbiota')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" + edge [style=filled] + "('Small
Intestine', 'Duodenum', 'Microbiota')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')" + edge [style=filled] + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Duodenum', 'nutrients')" + edge [style=filled] + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Duodenum', 'mucosa')" + edge [style=filled] + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Duodenum', 'Epithelium')" + edge [style=filled] + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Duodenum', 'Microbiota')" + edge [style=invis] + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Duodenum', 'uptake')" + edge [style=invis] + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Duodenum', 'degradation')" + edge [style=filled] + "('Small
Intestine',)" -> "('Small
Intestine', 'Duodenum')" + edge [style=filled] + "('Small
Intestine',)" -> "('Small
Intestine', 'Jejunum')" + edge [style=filled] + "('Small
Intestine',)" -> "('Small
Intestine', 'Ileum')" + edge [style=invis] + "('Small
Intestine',)" -> "('Small
Intestine', 'Peristalsis')" + edge [arrowhead=dot arrowsize=0.5 penwidth=1 style=dashed] + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus', 'mucin')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" [label=cells> fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + subgraph "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells', 'secretion')" { + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus', 'mucin')" -> "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells', 'secretion')" + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" -> "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells', 'secretion')" + } + "('Small
Intestine', 'Duodenum', 'mucosa')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'flagella')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + subgraph "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'chemotaxis')" { + "('Small
Intestine', 'Duodenum', 'mucosa')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'chemotaxis')" + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'flagella')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'chemotaxis')" + } + "('Small
Intestine', 'Duodenum', 'nutrients')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Duodenum', 'Epithelium')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + subgraph "('Small
Intestine', 'Duodenum', 'uptake')" { + "('Small
Intestine', 'Duodenum', 'nutrients')" -> "('Small
Intestine', 'Duodenum', 'uptake')" + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" -> "('Small
Intestine', 'Duodenum', 'uptake')" + "('Small
Intestine', 'Duodenum', 'Epithelium')" -> "('Small
Intestine', 'Duodenum', 'uptake')" + } + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus', 'mucin')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'mucinase')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')" [label=Firmicutes,
more> fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + subgraph "('Small
Intestine', 'Duodenum', 'degradation')" { + "('Small
Intestine', 'Duodenum', 'mucosa', 'mucus', 'mucin')" -> "('Small
Intestine', 'Duodenum', 'degradation')" + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli', 'mucinase')" -> "('Small
Intestine', 'Duodenum', 'degradation')" + "('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')" -> "('Small
Intestine', 'Duodenum', 'degradation')" + } + "('Small
Intestine', 'Duodenum')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Jejunum')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + "('Small
Intestine', 'Ileum')" [label= fontsize="12pt" margin=0.05 penwidth=2 shape=circle] + subgraph "('Small
Intestine', 'Peristalsis')" { + "('Small
Intestine', 'Duodenum')" -> "('Small
Intestine', 'Peristalsis')" + "('Small
Intestine', 'Jejunum')" -> "('Small
Intestine', 'Peristalsis')" + "('Small
Intestine', 'Ileum')" -> "('Small
Intestine', 'Peristalsis')" + } + edge [arrowhead=dot arrowsize=0.5 penwidth=1 style=dashed] + edge [arrowhead=none arrowtail=dot dir=both penwidth=1 style=dashed] + subgraph "[('Small
Intestine', 'Duodenum', 'Epithelium'), ('Small
Intestine', 'Duodenum', 'Microbiota'), ('Small
Intestine', 'Duodenum', 'mucosa'), ('Small
Intestine', 'Duodenum', 'nutrients')]" { + rank=same + "('Small
Intestine', 'Duodenum', 'Epithelium')" + "('Small
Intestine', 'Duodenum', 'Microbiota')" + "('Small
Intestine', 'Duodenum', 'Epithelium')" -> "('Small
Intestine', 'Duodenum', 'Microbiota')" [ordering=out style=invis] + "('Small
Intestine', 'Duodenum', 'mucosa')" + "('Small
Intestine', 'Duodenum', 'Microbiota')" -> "('Small
Intestine', 'Duodenum', 'mucosa')" [ordering=out style=invis] + "('Small
Intestine', 'Duodenum', 'nutrients')" + "('Small
Intestine', 'Duodenum', 'mucosa')" -> "('Small
Intestine', 'Duodenum', 'nutrients')" [ordering=out style=invis] + } + subgraph "[('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells'), ('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli'), ('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')]" { + rank=same + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" + "('Small
Intestine', 'Duodenum', 'Epithelium', 'Goblet
cells')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" [ordering=out style=invis] + "('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')" + "('Small
Intestine', 'Duodenum', 'Microbiota', 'E.coli')" -> "('Small
Intestine', 'Duodenum', 'Microbiota', 'Bacteroidetes,
Firmicutes,
more')" [ordering=out style=invis] + } +}