lang-main/docs/lang_main/render/cytoscape.html
2025-01-22 16:54:15 +01:00

798 lines
40 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<meta name="generator" content="pdoc3 0.11.5">
<title>lang_main.render.cytoscape API documentation</title>
<meta name="description" content="">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => {
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
hljs.highlightAll();
/* Collapse source docstrings */
setTimeout(() => {
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
.forEach(el => {
let d = document.createElement('details');
d.classList.add('hljs-string');
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
el.replaceWith(d);
});
}, 100);
})</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>lang_main.render.cytoscape</code></h1>
</header>
<section id="section-intro">
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="lang_main.render.cytoscape.analyse_network"><code class="name flex">
<span>def <span class="ident">analyse_network</span></span>(<span>property_degree_weighted: str = 'degree_weighted',<br>network_name: str = 'token_graph') > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def analyse_network(
property_degree_weighted: str = PROPERTY_NAME_DEGREE_WEIGHTED,
network_name: str = CYTO_BASE_NETWORK_NAME,
) -&gt; None:
node_table = p4c.get_table_columns(table=&#39;node&#39;, network=network_name)
net_analyse_possible: bool = True
if len(node_table) &lt; 4: # pragma: no cover
net_analyse_possible = False
if net_analyse_possible:
p4c.analyze_network(directed=False)
node_table = p4c.get_table_columns(table=&#39;node&#39;, network=network_name)
node_table[&#39;stress_norm&#39;] = node_table[&#39;Stress&#39;] / node_table[&#39;Stress&#39;].max()
node_table[CYTO_SELECTION_PROPERTY] = (
node_table[property_degree_weighted]
* node_table[&#39;BetweennessCentrality&#39;]
* node_table[&#39;stress_norm&#39;]
)
else: # pragma: no cover
node_table[CYTO_SELECTION_PROPERTY] = 1
p4c.load_table_data(node_table, data_key_column=&#39;name&#39;, network=network_name)</code></pre>
</details>
<div class="desc"></div>
</dd>
<dt id="lang_main.render.cytoscape.apply_style_to_network"><code class="name flex">
<span>def <span class="ident">apply_style_to_network</span></span>(<span>style_name: str = 'lang_main',<br>pth_to_stylesheet: pathlib.Path = WindowsPath('A:/Arbeitsaufgaben/lang-main/src/lang_main/cytoscape_config/lang_main.xml'),<br>network_name: str = 'token_graph',<br>node_size_property: str = 'node_selection',<br>min_node_size: int = 15,<br>max_node_size: int = 40,<br>sandbox_name: str = 'lang_main') > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def apply_style_to_network(
style_name: str = CYTO_STYLESHEET_NAME,
pth_to_stylesheet: Path = CYTO_PATH_STYLESHEET,
network_name: str = CYTO_BASE_NETWORK_NAME,
node_size_property: str = CYTO_SELECTION_PROPERTY,
min_node_size: int = 15,
max_node_size: int = 40,
sandbox_name: str = CYTO_SANDBOX_NAME,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: apply a chosen Cytoscape style to the defined network
Parameters
----------
style_name : str, optional
Cytoscape name of the style which should be applied,
by default CYTO_STYLESHEET_NAME
pth_to_stylesheet : Path, optional
path where the stylesheet definition in Cytoscape&#39;s XML format can
be found,
by default CYTO_PATH_STYLESHEET
network_name : str, optional
network to apply the style on, by default CYTO_BASE_NETWORK_NAME
Raises
------
FileNotFoundError
if provided stylesheet can not be found under the provided path
&#34;&#34;&#34;
logger.debug(&#39;Applying style to network...&#39;)
styles_avail = cast(list[str], p4c.get_visual_style_names())
logger.debug(&#39;Available styles: %s&#39;, styles_avail)
if style_name not in styles_avail:
if not pth_to_stylesheet.exists():
# existence for standard path verified at import, but not for other
# provided paths
raise FileNotFoundError(
f&#39;Visual stylesheet for Cytoscape not found under: &gt;&gt;{pth_to_stylesheet}&lt;&lt;&#39;
)
# send to sandbox
sandbox_filename = pth_to_stylesheet.name
p4c.sandbox_send_to(
source_file=pth_to_stylesheet,
dest_file=sandbox_filename,
overwrite=True,
sandbox_name=sandbox_name,
)
# load stylesheet
p4c.import_visual_styles(sandbox_filename)
p4c.set_visual_style(style_name, network=network_name)
# node size mapping, only if needed property is available
scheme = p4c.scheme_c_number_continuous(
start_value=min_node_size, end_value=max_node_size
)
node_size_map = p4c.gen_node_size_map(
node_size_property,
number_scheme=scheme,
mapping_type=&#39;c&#39;,
style_name=style_name,
default_number=min_node_size,
)
p4c.set_node_size_mapping(**node_size_map)
fit_content(network_name=network_name)
logger.debug(&#39;Style application to network successful.&#39;)</code></pre>
</details>
<div class="desc"><p>Cytoscape: apply a chosen Cytoscape style to the defined network</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>style_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>Cytoscape name of the style which should be applied,
by default CYTO_STYLESHEET_NAME</dd>
<dt><strong><code>pth_to_stylesheet</code></strong> :&ensp;<code>Path</code>, optional</dt>
<dd>path where the stylesheet definition in Cytoscape's XML format can
be found,
by default CYTO_PATH_STYLESHEET</dd>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network to apply the style on, by default CYTO_BASE_NETWORK_NAME</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>FileNotFoundError</code></dt>
<dd>if provided stylesheet can not be found under the provided path</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.build_subnetworks"><code class="name flex">
<span>def <span class="ident">build_subnetworks</span></span>(<span>nodes_to_analyse: Iterable[int],<br>network_name: str = 'token_graph',<br>export_image: bool = True,<br>target_folder: pathlib.Path = WindowsPath('A:/Arbeitsaufgaben/lang-data/out')) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def build_subnetworks(
nodes_to_analyse: Iterable[CytoNodeID],
network_name: str = CYTO_BASE_NETWORK_NAME,
export_image: bool = True,
target_folder: Path = SAVE_PATH_FOLDER,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: iteratively build subnetworks from a collection of nodes
and their respective neighbouring nodes
Parameters
----------
nodes_to_analyse : Iterable[CytoNodeID]
collection of nodes to make subnetworks from, for each node a dedicated
subnetwork will be generated
network_name : str, optional
network which contains the provided nodes,
by default CYTO_BASE_NETWORK_NAME
export_image : bool, optional
trigger image export of newly generated subnetworks, by default True
&#34;&#34;&#34;
logger.debug(&#39;Generating all subnetworks for node selection...&#39;)
for idx, node in enumerate(nodes_to_analyse):
select_neighbours_of_node(node=node, network_name=network_name)
make_subnetwork(
index=idx,
network_name=network_name,
export_image=export_image,
target_folder=target_folder,
)
logger.debug(&#39;Generation of all subnetworks for node selection successful.&#39;)</code></pre>
</details>
<div class="desc"><p>Cytoscape: iteratively build subnetworks from a collection of nodes
and their respective neighbouring nodes</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>nodes_to_analyse</code></strong> :&ensp;<code>Iterable[CytoNodeID]</code></dt>
<dd>collection of nodes to make subnetworks from, for each node a dedicated
subnetwork will be generated</dd>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network which contains the provided nodes,
by default CYTO_BASE_NETWORK_NAME</dd>
<dt><strong><code>export_image</code></strong> :&ensp;<code>bool</code>, optional</dt>
<dd>trigger image export of newly generated subnetworks, by default True</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.change_default_layout"><code class="name flex">
<span>def <span class="ident">change_default_layout</span></span>(<span>) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def change_default_layout() -&gt; None:
&#34;&#34;&#34;Cytoscape: resets the default layout to `grid` to accelerate the import process
(grid layout one of the fastest)
Raises
------
RequestException
API endpoint not reachable or CyREST operation not successful
&#34;&#34;&#34;
body: dict[str, str] = {&#39;value&#39;: &#39;grid&#39;, &#39;key&#39;: &#39;layout.default&#39;}
try:
p4c.cyrest_put(&#39;properties/cytoscape3.props/layout.default&#39;, body=body)
except RequestException as error:
logger.error(&#39;[CytoAPIConnection] Property change of default layout not successful.&#39;)
raise error</code></pre>
</details>
<div class="desc"><p>Cytoscape: resets the default layout to <code>grid</code> to accelerate the import process
(grid layout one of the fastest)</p>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>RequestException</code></dt>
<dd>API endpoint not reachable or CyREST operation not successful</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.export_network_to_image"><code class="name flex">
<span>def <span class="ident">export_network_to_image</span></span>(<span>filename: str,<br>target_folder: pathlib.Path = WindowsPath('A:/Arbeitsaufgaben/lang-data/out'),<br>filetype: Literal['JPEG', 'PDF', 'PNG', 'PS', 'SVG'] = 'SVG',<br>network_name: str = 'token_graph',<br>pdf_export_page_size: Literal['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'Auto', 'Legal', 'Letter', 'Tabloid'] = 'A4',<br>sandbox_name: str = 'lang_main') > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def export_network_to_image(
filename: str,
target_folder: Path = SAVE_PATH_FOLDER,
filetype: CytoExportFileTypes = &#39;SVG&#39;,
network_name: str = CYTO_BASE_NETWORK_NAME,
pdf_export_page_size: CytoExportPageSizes = &#39;A4&#39;,
sandbox_name: str = CYTO_SANDBOX_NAME,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: export current selected view as image
Parameters
----------
filename : str
export filename
filetype : CytoExportFileTypes, optional
export filetype supported by Cytoscape, by default &#39;SVG&#39;
network_name : str, optional
network to export, by default CYTO_BASE_NETWORK_NAME
pdf_export_page_size : CytoExportPageSizes, optional
page size which should be used for PDF exports supported by Cytoscape,
by default &#39;A4&#39;
&#34;&#34;&#34;
logger.debug(&#39;Exporting image to file...&#39;)
if not target_folder.exists(): # pragma: no cover
target_folder.mkdir(parents=True)
dst_file_pth = (target_folder / filename).with_suffix(f&#39;.{filetype.lower()}&#39;)
text_as_font = True
if filetype == &#39;SVG&#39;:
text_as_font = False
# close non-necessary windows and fit graph in frame before image display
fit_content(network_name=network_name)
# image is generated in sandbox directory and transferred to target destination
# (preparation for remote instances of Cytoscape)
p4c.export_image(
filename=filename,
type=filetype,
network=network_name,
overwrite_file=True,
all_graphics_details=True,
export_text_as_font=text_as_font,
page_size=pdf_export_page_size,
)
logger.debug(&#39;Exported image to sandbox.&#39;)
logger.debug(&#39;Transferring image from sandbox to target destination...&#39;)
sandbox_filename = f&#39;{filename}.{filetype.lower()}&#39;
p4c.sandbox_get_from(
source_file=sandbox_filename,
dest_file=str(dst_file_pth),
overwrite=True,
sandbox_name=sandbox_name,
)
logger.debug(&#39;Transfer of image from sandbox to target destination successful.&#39;)</code></pre>
</details>
<div class="desc"><p>Cytoscape: export current selected view as image</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>filename</code></strong> :&ensp;<code>str</code></dt>
<dd>export filename</dd>
<dt><strong><code>filetype</code></strong> :&ensp;<code>CytoExportFileTypes</code>, optional</dt>
<dd>export filetype supported by Cytoscape, by default 'SVG'</dd>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network to export, by default CYTO_BASE_NETWORK_NAME</dd>
<dt><strong><code>pdf_export_page_size</code></strong> :&ensp;<code>CytoExportPageSizes</code>, optional</dt>
<dd>page size which should be used for PDF exports supported by Cytoscape,
by default 'A4'</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.fit_content"><code class="name flex">
<span>def <span class="ident">fit_content</span></span>(<span>zoom_factor: float = 0.96, network_name: str = 'token_graph') > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def fit_content(
zoom_factor: float = CYTO_NETWORK_ZOOM_FACTOR,
network_name: str = CYTO_BASE_NETWORK_NAME,
) -&gt; None:
p4c.hide_all_panels()
p4c.fit_content(selected_only=False, network=network_name)
zoom_current = p4c.get_network_zoom(network=network_name)
zoom_new = zoom_current * zoom_factor
p4c.set_network_zoom_bypass(zoom_new, bypass=False, network=network_name)</code></pre>
</details>
<div class="desc"></div>
</dd>
<dt id="lang_main.render.cytoscape.get_subgraph_node_selection"><code class="name flex">
<span>def <span class="ident">get_subgraph_node_selection</span></span>(<span>network_name: str = 'token_graph', num_subgraphs: int = 5) > list[int]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def get_subgraph_node_selection(
network_name: str = CYTO_BASE_NETWORK_NAME,
num_subgraphs: int = CYTO_NUMBER_SUBGRAPHS,
) -&gt; list[CytoNodeID]:
&#34;&#34;&#34;Cytoscape: obtain the relevant nodes for iterative subgraph generation
Parameters
----------
network_name : str, optional
network to retrieve the nodes from, by default CYTO_BASE_NETWORK_NAME
property_degree_weighted : str, optional
property name which contains the weighted degree,
by default PROPERTY_NAME_DEGREE_WEIGHTED
num_subgraphs : int, optional
number of relevant nodes which form the basis to generate subgraphs from,
by default CYTO_NUMBER_SUBGRAPHS
Returns
-------
list[CytoNodeID]
list containing all relevant Cytoscape nodes
&#34;&#34;&#34;
logger.debug(&#39;Selecting nodes for subgraph generation...&#39;)
node_table = p4c.get_table_columns(table=&#39;node&#39;, network=network_name)
node_table = node_table.sort_values(by=CYTO_SELECTION_PROPERTY, ascending=False)
p4c.load_table_data(node_table, data_key_column=&#39;name&#39;, network=network_name)
node_table_choice = node_table.iloc[:num_subgraphs]
logger.debug(&#39;Selection of nodes for subgraph generation successful.&#39;)
return node_table_choice[&#39;SUID&#39;].to_list()</code></pre>
</details>
<div class="desc"><p>Cytoscape: obtain the relevant nodes for iterative subgraph generation</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network to retrieve the nodes from, by default CYTO_BASE_NETWORK_NAME</dd>
<dt><strong><code>property_degree_weighted</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>property name which contains the weighted degree,
by default PROPERTY_NAME_DEGREE_WEIGHTED</dd>
<dt><strong><code>num_subgraphs</code></strong> :&ensp;<code>int</code>, optional</dt>
<dd>number of relevant nodes which form the basis to generate subgraphs from,
by default CYTO_NUMBER_SUBGRAPHS</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>list[CytoNodeID]</code></dt>
<dd>list containing all relevant Cytoscape nodes</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.import_to_cytoscape"><code class="name flex">
<span>def <span class="ident">import_to_cytoscape</span></span>(<span>graph: networkx.classes.digraph.DiGraph | networkx.classes.graph.Graph,<br>network_name: str = 'token_graph',<br>sandbox_name: str = 'lang_main',<br>reinitialise_sandbox: bool = True) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def import_to_cytoscape(
graph: DiGraph | Graph,
network_name: str = CYTO_BASE_NETWORK_NAME,
sandbox_name: str = CYTO_SANDBOX_NAME,
reinitialise_sandbox: bool = True,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: import NetworkX graph as new network collection
Parameters
----------
graph : DiGraph | Graph
NetworkX graph object
&#34;&#34;&#34;
logger.debug(&#39;Checking Cytoscape connection...&#39;)
verify_connection()
logger.debug(&#39;Checking graph size for rendering...&#39;)
verify_graph_render_size(graph)
logger.debug(&#39;Setting default layout to improve import speed...&#39;)
change_default_layout()
logger.debug(&#39;Setting Cytoscape sandbox...&#39;)
p4c.sandbox_set(
sandbox_name=sandbox_name,
reinitialize=reinitialise_sandbox,
copy_samples=False,
)
logger.debug(&#39;Importing to and analysing network in Cytoscape...&#39;)
p4c.delete_all_networks()
p4c.create_network_from_networkx(
graph,
title=network_name,
collection=CYTO_COLLECTION_NAME,
)
analyse_network(network_name=network_name)
logger.debug(&#39;Import and analysis of network to Cytoscape successful.&#39;)</code></pre>
</details>
<div class="desc"><p>Cytoscape: import NetworkX graph as new network collection</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>graph</code></strong> :&ensp;<code>DiGraph | Graph</code></dt>
<dd>NetworkX graph object</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.layout_network"><code class="name flex">
<span>def <span class="ident">layout_network</span></span>(<span>layout_name: Literal['attribute-circle', 'attribute-grid', 'attributes-layout', 'circular', 'cose', 'degree-circle', 'force-directed', 'force-directed-cl', 'fruchterman-rheingold', 'grid', 'hierarchical', 'isom', 'kamada-kawai', 'stacked-node-layout'] = 'force-directed',<br>layout_properties: dict[str, float | bool] = {'numIterations': 1000, 'defaultSpringCoefficient': 0.0001, 'defaultSpringLength': 45, 'defaultNodeMass': 11, 'isDeterministic': True, 'singlePartition': False},<br>network_name: str = 'token_graph') > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def layout_network(
layout_name: CytoLayouts = CYTO_LAYOUT_NAME,
layout_properties: CytoLayoutProperties = CYTO_LAYOUT_PROPERTIES,
network_name: str = CYTO_BASE_NETWORK_NAME,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: apply a supported layout algorithm to currently selected
network
Parameters
----------
layout_name : CytoLayouts, optional
layout algorithm supported by Cytoscape (name of the CyREST API, does not
necessarily match the name in the Cytoscape UI),
by default CYTO_LAYOUT_NAME
layout_properties : CytoLayoutProperties, optional
configuration of parameters for the given layout algorithm,
by default CYTO_LAYOUT_PROPERTIES
network_name : str, optional
network to apply the layout algorithm on, by default CYTO_BASE_NETWORK_NAME
&#34;&#34;&#34;
logger.debug(&#39;Applying layout to network...&#39;)
p4c.set_layout_properties(layout_name, layout_properties)
p4c.layout_network(layout_name=layout_name, network=network_name)
fit_content(network_name=network_name)
logger.debug(&#39;Layout application to network successful.&#39;)</code></pre>
</details>
<div class="desc"><p>Cytoscape: apply a supported layout algorithm to currently selected
network</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>layout_name</code></strong> :&ensp;<code>CytoLayouts</code>, optional</dt>
<dd>layout algorithm supported by Cytoscape (name of the CyREST API, does not
necessarily match the name in the Cytoscape UI),
by default CYTO_LAYOUT_NAME</dd>
<dt><strong><code>layout_properties</code></strong> :&ensp;<code>CytoLayoutProperties</code>, optional</dt>
<dd>configuration of parameters for the given layout algorithm,
by default CYTO_LAYOUT_PROPERTIES</dd>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network to apply the layout algorithm on, by default CYTO_BASE_NETWORK_NAME</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.make_subnetwork"><code class="name flex">
<span>def <span class="ident">make_subnetwork</span></span>(<span>index: int,<br>network_name: str = 'token_graph',<br>export_image: bool = True,<br>target_folder: pathlib.Path = WindowsPath('A:/Arbeitsaufgaben/lang-data/out')) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def make_subnetwork(
index: int,
network_name: str = CYTO_BASE_NETWORK_NAME,
export_image: bool = True,
target_folder: Path = SAVE_PATH_FOLDER,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: generate a new subnetwork based on the currently
selected nodes and edges
Parameters
----------
index : int
id-like property to identify the subnetwork relative to its parent
network_name : str, optional
network to generate subnetwork from, by default CYTO_BASE_NETWORK_NAME
export_image : bool, optional
trigger image export of newly generated subnetwork, by default True
&#34;&#34;&#34;
logger.debug(&#39;Generating subnetwork with index %d...&#39;, index)
subnetwork_name = network_name + f&#39;_sub_{index+1}&#39;
p4c.create_subnetwork(
nodes=&#39;selected&#39;,
edges=&#39;selected&#39;,
subnetwork_name=subnetwork_name,
network=network_name,
)
p4c.set_current_network(subnetwork_name)
if export_image:
time.sleep(1)
export_network_to_image(
filename=subnetwork_name,
target_folder=target_folder,
network_name=subnetwork_name,
)
logger.debug(&#39;Generation of subnetwork with index %d successful.&#39;, index)</code></pre>
</details>
<div class="desc"><p>Cytoscape: generate a new subnetwork based on the currently
selected nodes and edges</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>index</code></strong> :&ensp;<code>int</code></dt>
<dd>id-like property to identify the subnetwork relative to its parent</dd>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network to generate subnetwork from, by default CYTO_BASE_NETWORK_NAME</dd>
<dt><strong><code>export_image</code></strong> :&ensp;<code>bool</code>, optional</dt>
<dd>trigger image export of newly generated subnetwork, by default True</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.reset_current_network_to_base"><code class="name flex">
<span>def <span class="ident">reset_current_network_to_base</span></span>(<span>) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def reset_current_network_to_base() -&gt; None:
&#34;&#34;&#34;resets to currently selected network in Cytoscape back to the base one&#34;&#34;&#34;
p4c.set_current_network(CYTO_BASE_NETWORK_NAME)</code></pre>
</details>
<div class="desc"><p>resets to currently selected network in Cytoscape back to the base one</p></div>
</dd>
<dt id="lang_main.render.cytoscape.select_neighbours_of_node"><code class="name flex">
<span>def <span class="ident">select_neighbours_of_node</span></span>(<span>node: int, neighbour_iter_depth: int = 2, network_name: str = 'token_graph') > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def select_neighbours_of_node(
node: CytoNodeID,
neighbour_iter_depth: int = CYTO_ITER_NEIGHBOUR_DEPTH,
network_name: str = CYTO_BASE_NETWORK_NAME,
) -&gt; None:
&#34;&#34;&#34;Cytoscape: iterative selection of a node&#39;s neighbouring nodes and
their connecting edges
Parameters
----------
node : CytoNodeID
node which neighbours should be selected
neighbour_iter_depth : int, optional
indicates how many levels of neighbours should be choosen, e.g. 1 --&gt; only
first-level neighbours are considered which are directly connected to the node,
2 --&gt; all nodes with iteration depth of 1 are chosen and additionally their
direct neighbours,
by default CYTO_ITER_NEIGHBOUR_DEPTH
network_name : str, optional
network to perform action on, by default CYTO_BASE_NETWORK_NAME
&#34;&#34;&#34;
logger.debug(&#39;Selecting node neighbours for %s...&#39;, node)
p4c.clear_selection(network=network_name)
p4c.select_nodes(node, network=network_name)
for _ in range(neighbour_iter_depth):
_ = p4c.select_first_neighbors(network=network_name)
_ = p4c.select_edges_connecting_selected_nodes()
logger.debug(&#39;Selection of node neighbours for %s successful.&#39;, node)</code></pre>
</details>
<div class="desc"><p>Cytoscape: iterative selection of a node's neighbouring nodes and
their connecting edges</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>node</code></strong> :&ensp;<code>CytoNodeID</code></dt>
<dd>node which neighbours should be selected</dd>
<dt><strong><code>neighbour_iter_depth</code></strong> :&ensp;<code>int</code>, optional</dt>
<dd>indicates how many levels of neighbours should be choosen, e.g. 1 &ndash;&gt; only
first-level neighbours are considered which are directly connected to the node,
2 &ndash;&gt; all nodes with iteration depth of 1 are chosen and additionally their
direct neighbours,
by default CYTO_ITER_NEIGHBOUR_DEPTH</dd>
<dt><strong><code>network_name</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>network to perform action on, by default CYTO_BASE_NETWORK_NAME</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.verify_connection"><code class="name flex">
<span>def <span class="ident">verify_connection</span></span>(<span>) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def verify_connection() -&gt; None:
&#34;&#34;&#34;Cytoscape: checks if CyREST and Cytoscape versions are compatible nad
if Cytoscape API endpoint is reachable
Raises
------
CyError
incompatible CyREST or Cytoscape versions
RequestException
API endpoint not reachable
&#34;&#34;&#34;
try:
p4c.cytoscape_ping()
except CyError as error: # pragma: no cover
logger.error(&#39;[CyError] CyREST or Cytoscape version not supported.&#39;)
raise error
except RequestException as error:
logger.error(&#39;[CytoAPIConnection] Connection to CyREST API failed.&#39;)
raise error</code></pre>
</details>
<div class="desc"><p>Cytoscape: checks if CyREST and Cytoscape versions are compatible nad
if Cytoscape API endpoint is reachable</p>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>CyError</code></dt>
<dd>incompatible CyREST or Cytoscape versions</dd>
<dt><code>RequestException</code></dt>
<dd>API endpoint not reachable</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.verify_graph_render_size"><code class="name flex">
<span>def <span class="ident">verify_graph_render_size</span></span>(<span>graph: networkx.classes.digraph.DiGraph | networkx.classes.graph.Graph,<br>max_node_count: int | None = 500,<br>max_edge_count: int | None = 800) > None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def verify_graph_render_size(
graph: Graph | DiGraph,
max_node_count: int | None = CYTO_MAX_NODE_COUNT,
max_edge_count: int | None = CYTO_MAX_EDGE_COUNT,
) -&gt; None:
&#34;&#34;&#34;verify that the graph size can still be handled within an acceptable time
frame for rendering in Cytoscape
Parameters
----------
graph : Graph | DiGraph
graph to verify
max_node_count : int | None, optional
maximum allowed number of nodes, by default CYTO_MAX_NODE_COUNT
max_edge_count : int | None, optional
maximum allowed number of edges, by default CYTO_MAX_EDGE_COUNT
Raises
------
GraphRenderError
if any of the provided limits is exceeded
&#34;&#34;&#34;
num_nodes = len(graph.nodes)
num_edges = len(graph.edges)
if max_node_count is not None and num_nodes &gt; max_node_count:
raise GraphRenderError(
f&#39;Maximum number of nodes for rendering exceeded. &#39;
f&#39;Limit {max_node_count}, Counted: {num_nodes}&#39;
)
if max_edge_count is not None and num_edges &gt; max_edge_count:
raise GraphRenderError(
f&#39;Maximum number of edges for rendering exceeded. &#39;
f&#39;Limit {max_edge_count}, Counted: {num_edges}&#39;
)</code></pre>
</details>
<div class="desc"><p>verify that the graph size can still be handled within an acceptable time
frame for rendering in Cytoscape</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>graph</code></strong> :&ensp;<code>Graph | DiGraph</code></dt>
<dd>graph to verify</dd>
<dt><strong><code>max_node_count</code></strong> :&ensp;<code>int | None</code>, optional</dt>
<dd>maximum allowed number of nodes, by default CYTO_MAX_NODE_COUNT</dd>
<dt><strong><code>max_edge_count</code></strong> :&ensp;<code>int | None</code>, optional</dt>
<dd>maximum allowed number of edges, by default CYTO_MAX_EDGE_COUNT</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>GraphRenderError</code></dt>
<dd>if any of the provided limits is exceeded</dd>
</dl></div>
</dd>
<dt id="lang_main.render.cytoscape.verify_table_property"><code class="name flex">
<span>def <span class="ident">verify_table_property</span></span>(<span>property: str,<br>table_type: Literal['node', 'edge', 'network'] = 'node',<br>network_name: str = 'token_graph') > bool</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def verify_table_property(
property: str,
table_type: Literal[&#39;node&#39;, &#39;edge&#39;, &#39;network&#39;] = &#39;node&#39;,
network_name: str = CYTO_BASE_NETWORK_NAME,
) -&gt; bool:
table = p4c.get_table_columns(table=table_type, network=network_name)
logger.debug(&#39;Table &gt;&gt;%s&lt;&lt; wiht columns: %s&#39;, table, table.columns)
return property in table.columns</code></pre>
</details>
<div class="desc"></div>
</dd>
</dl>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="lang_main.render" href="index.html">lang_main.render</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="lang_main.render.cytoscape.analyse_network" href="#lang_main.render.cytoscape.analyse_network">analyse_network</a></code></li>
<li><code><a title="lang_main.render.cytoscape.apply_style_to_network" href="#lang_main.render.cytoscape.apply_style_to_network">apply_style_to_network</a></code></li>
<li><code><a title="lang_main.render.cytoscape.build_subnetworks" href="#lang_main.render.cytoscape.build_subnetworks">build_subnetworks</a></code></li>
<li><code><a title="lang_main.render.cytoscape.change_default_layout" href="#lang_main.render.cytoscape.change_default_layout">change_default_layout</a></code></li>
<li><code><a title="lang_main.render.cytoscape.export_network_to_image" href="#lang_main.render.cytoscape.export_network_to_image">export_network_to_image</a></code></li>
<li><code><a title="lang_main.render.cytoscape.fit_content" href="#lang_main.render.cytoscape.fit_content">fit_content</a></code></li>
<li><code><a title="lang_main.render.cytoscape.get_subgraph_node_selection" href="#lang_main.render.cytoscape.get_subgraph_node_selection">get_subgraph_node_selection</a></code></li>
<li><code><a title="lang_main.render.cytoscape.import_to_cytoscape" href="#lang_main.render.cytoscape.import_to_cytoscape">import_to_cytoscape</a></code></li>
<li><code><a title="lang_main.render.cytoscape.layout_network" href="#lang_main.render.cytoscape.layout_network">layout_network</a></code></li>
<li><code><a title="lang_main.render.cytoscape.make_subnetwork" href="#lang_main.render.cytoscape.make_subnetwork">make_subnetwork</a></code></li>
<li><code><a title="lang_main.render.cytoscape.reset_current_network_to_base" href="#lang_main.render.cytoscape.reset_current_network_to_base">reset_current_network_to_base</a></code></li>
<li><code><a title="lang_main.render.cytoscape.select_neighbours_of_node" href="#lang_main.render.cytoscape.select_neighbours_of_node">select_neighbours_of_node</a></code></li>
<li><code><a title="lang_main.render.cytoscape.verify_connection" href="#lang_main.render.cytoscape.verify_connection">verify_connection</a></code></li>
<li><code><a title="lang_main.render.cytoscape.verify_graph_render_size" href="#lang_main.render.cytoscape.verify_graph_render_size">verify_graph_render_size</a></code></li>
<li><code><a title="lang_main.render.cytoscape.verify_table_property" href="#lang_main.render.cytoscape.verify_table_property">verify_table_property</a></code></li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
</footer>
</body>
</html>