### Setup Output Directory Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su basic protocol 1.ipynb Prepares a local directory named 'output' for storing files downloaded from Cytoscape. This example uses Windows-specific commands; adjust for other operating systems. It ensures the directory is clean before use. ```python !del /s/q/f output !rmdir output !mkdir output !dir output OUTPUT_DIR = 'output/' ``` -------------------------------- ### Setup Directories for Data and Output Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su Basic Protocol 2.ipynb Creates 'Barabasi' and 'output' directories for storing downloaded data and files exported from Cytoscape. This example uses Windows-style commands; adapt for Linux/Mac. Ensure Cytoscape is running before executing. ```python !del /s/q/f Barabasi !rmdir Barabasi !mkdir Barabasi !del /s/q/f output !rmdir output !mkdir output !dir OUTPUT_DIR = 'output/' ``` -------------------------------- ### Install and List Apps Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Installs a specified Cytoscape application and then lists all installed applications, printing the version of the target application if found. This is useful for managing Cytoscape's functionality. ```python p4c.install_app('MCODE') iapps = p4c.get_installed_apps() print(iapps) for app in iapps: if app['appName'] == 'MCODE': print(app['version']) ``` -------------------------------- ### Install and Import py4cytoscape in Notebook Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet demonstrates how to uninstall an existing py4cytoscape installation, install it using pip, and then import the library to call a function. Useful for ensuring the latest version is used in a Notebook. ```python import sys !{sys.executable} -m pip uninstall -y py4cytoscape !{sys.executable} -m pip install py4cytoscape import py4cytoscape as p4c p4c.cytoscape_version_info() ``` -------------------------------- ### Install py4cytoscape and dependencies Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Install the py4cytoscape library and its necessary dependencies. It is recommended to check for and manage specific app versions like StringApp if required for certain functionalities. ```python pip install py4cytoscape pip install networkx pip install pandas pip install requests pip install jupyterlab ``` -------------------------------- ### py4cytoscape Summary Log Example Source: https://github.com/cytoscape/py4cytoscape/blob/master/LOGGING.rst Example of py4cytoscape's Summary logging, showing HTTP calls and results. This format is enabled by default for INFO level logging. ```text [INFO] py4...S: ǀHTTP DELETE(http://localhost:1234/v1/networks) [INFO] py4...S: ǀOK[200] ``` -------------------------------- ### Verify py4cytoscape installation and Cytoscape connection Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Execute these Python commands in a console after starting Cytoscape to confirm py4cytoscape is installed and can communicate with Cytoscape. This checks basic connectivity and retrieves version information. ```python import py4cytoscape as py4 dir(py4) py4.cytoscape_ping() py4.cytoscape_version_info() ``` -------------------------------- ### Example Default Styling Functions (Commented Out) Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Demonstrates various specific functions for setting default node visual properties. These are commented out and can be uncommented for use. ```python # p4c.set_visual_style('STRING - ovarian cancer') # p4c.set_node_shape_default('ELLIPSE', style_name='STRING - ovarian cancer') # p4c.set_node_size_default(50, style_name='STRING - ovarian cancer') # p4c.set_node_color_default('#D3D3D3', style_name='STRING - ovarian cancer') # p4c.set_node_border_width_default(2, style_name='STRING - ovarian cancer') # p4c.set_node_color_default('#616060', style_name='STRING - ovarian cancer') # p4c.set_node_font_size_default(14, style_name='STRING - ovarian cancer') ``` -------------------------------- ### Install and Import gProfiler Package Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su basic protocol 1.ipynb This snippet shows how to install the gProfiler package using pip if it's not already present, and then imports the necessary GProfiler class for subsequent analysis. ```python !pip install gprofiler-official from gprofiler import GProfiler ``` -------------------------------- ### py4cytoscape Detail Log Example with Nested Calls Source: https://github.com/cytoscape/py4cytoscape/blob/master/LOGGING.rst Example of py4cytoscape's Detail logging, demonstrating nested function calls and their execution flow. This is typically enabled at DEBUG level. ```text 2020-06-06 15:29:55,721 [DEBUG] py4...: ǀCalling cytoscape_version_info(base_url='http://localhost:1234/v1') 2020-06-06 15:29:55,721 [DEBUG] py4...: ǀǀCalling cyrest_get('version', base_url='http://localhost:1234/v1') 2020-06-06 15:29:55,721 [DEBUG] py4...: ǀǀHTTP GET(http://localhost:1234/v1/version) 2020-06-06 15:29:55,737 [DEBUG] py4...: ǀǀOK[200], content: {"apiVersion":"v1","cytoscapeVersion":"3.9.0-SNAPSHOT"} 2020-06-06 15:29:55,738 [DEBUG] py4...: ǀǀReturning 'cyrest_get': {"apiVersion": "v1", "cytoscapeVersion": "3.9.0-SNAPSHOT"} 2020-06-06 15:29:55,738 [DEBUG] py4...: ǀReturning 'cytoscape_version_info': {"apiVersion": "v1", "cytoscapeVersion": "3.9.0-SNAPSHOT"} ``` -------------------------------- ### Install py4cytoscape and Dependencies Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Installs py4cytoscape and related Python libraries using pip. This is a prerequisite for using py4cytoscape. ```bash !python3 -m pip install python-igraph requests pandas networkx !python3 -m pip install py4cytoscape !python3 -m pip install ndex2 wget ``` -------------------------------- ### Install a particular py4cytoscape development version using git clone Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Install a specific development version of py4cytoscape (e.g., 0.0.11) by cloning the repository. This method is an alternative to using pip for specific versions. ```bash pip install igraph requests pandas networkx colorbrewer chardet decorator backoff colour git clone git://github.com/cytoscape/py4cytoscape@0.0.11 ``` -------------------------------- ### Install Unreleased py4cytoscape from GitHub in Notebook Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet shows how to uninstall the current py4cytoscape, install a version directly from a GitHub repository, and then import the library. This is useful for testing unreleased versions. ```python import sys !{sys.executable} -m pip uninstall -y py4cytoscape !{sys.executable} -m pip install git+https://github.com/cytoscape/py4cytoscape import py4cytoscape as p4c p4c.cytoscape_version_info() ``` -------------------------------- ### Install py4cytoscape and dependencies with pacboy (MSYS2) Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Use this command to install py4cytoscape and its required Python packages on Windows via MSYS2 using pacboy. Ensure you have pacboy installed. ```bash pacboy -S python-{requests,networkx,igraph,pandas,pip}:p --needed pip install py4cytoscape ``` -------------------------------- ### Install latest release of py4cytoscape Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Install the current stable release of py4cytoscape and its dependencies using pip. This is the recommended method for most users. ```bash pip install igraph requests pandas networkx colorbrewer chardet decorator backoff colour pip install py4cytoscape ``` -------------------------------- ### Install and Use MCODE for Gene Clustering Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su Basic Protocol 2.ipynb Installs the MCODE application, clusters genes using default settings, and extracts the second cluster. Includes a time delay to ensure the MCODE drawing finishes before exporting the image. ```python p4c.install_app('MCODE') p4c.commands_post('mcode cluster network=""') p4c.commands.commands_post('mcode view id=1 rank=2') import time time.sleep(2) # Wait for MCode to finish before accessing its networks p4c.notebook_export_show_image() ``` -------------------------------- ### Install clusterMaker2 App Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su basic protocol 1.ipynb Installs the clusterMaker2 application in Cytoscape if it is not already installed. This app is required for network module identification. ```python p4c.install_app('clusterMaker2') ``` -------------------------------- ### Install latest development version of py4cytoscape from GitHub Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Install the most recent development version of py4cytoscape directly from its GitHub repository using pip. This is useful for testing the latest features or bug fixes. ```bash pip install igraph requests pandas networkx colorbrewer chardet decorator backoff colour pip install git+https://github.com/cytoscape/py4cytoscape.git ``` -------------------------------- ### Load Network from String Database Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Load a network from the String database by constructing and running a command string. This example queries for 'ovarian cancer' in Homo sapiens with a cutoff of 0.9. ```python # Querying String database for ovarian cancer string_cmd_list = ['string disease query','disease="ovarian cancer"', 'species="Homo sapiens"', 'limit=100', 'cutoff=0.9'] string_cmd = " ".join(string_cmd_list) p4c.commands.commands_run(string_cmd) ``` -------------------------------- ### Get All Style Mappings Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves all mapping configurations for a specified style. This provides a comprehensive overview of how attributes are mapped to visual properties. ```python p4c.get_style_all_mappings('STRING - ovarian cancer') ``` -------------------------------- ### Enable Summary Logging via Environment Variable Source: https://github.com/cytoscape/py4cytoscape/blob/master/LOGGING.rst Example of enabling py4cytoscape Summary logging by setting the PY4CYTOSCAPE_SUMMARY_LOGGER environment variable to True. This is a convenient way to turn on console logging. ```bash set PY4CYTOSCAPE_SUMMARY_LOGGER=True ``` -------------------------------- ### Get Current Working Directory and Absolute Path Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Demonstrates how to get the current working directory and the absolute path of a file using the `os` module in Python. This is useful for verifying file locations. ```python import os print(os.getcwd()) print(os.path.abspath('foo')) print(os.path.abspath('C:\\Users\\CyDeveloper\\PycharmProjects\\py4cytoscape\\tests\\scratchpad\\foo')) ``` -------------------------------- ### Install a specific py4cytoscape branch version from GitHub Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Install a specific development branch of py4cytoscape (e.g., version 0.0.10) from GitHub using pip. This allows you to pin to a particular release candidate or feature branch. ```bash pip install igraph requests pandas networkx colorbrewer chardet decorator backoff colour pip install git+https://github.com/cytoscape/py4cytoscape.git@0.0.10 ``` -------------------------------- ### Import Network from Tabular File Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su Basic Protocol 2.ipynb Loads a network into Cytoscape from a local tabular file. It specifies options for header rows, starting rows for data, and column types. ```python p4c.close_session(False) p4c.import_network_from_tabular_file('Barabasi/supplementary_tableS4.txt', first_row_as_column_names=True, start_load_row=2, column_type_list='x,s,x,t,i') ``` -------------------------------- ### Enable and Restore Summary Logger at Runtime Source: https://github.com/cytoscape/py4cytoscape/blob/master/LOGGING.rst Example of enabling py4cytoscape Summary logging at execution time using set_summary_logger() and restoring the previous state. This is useful for temporary logging within code blocks or notebooks. ```python old_state = set_summary_logger(True) # ... make several py4cytoscape calls ... set_summary_logger(old_state) ``` -------------------------------- ### Get All Style Mappings Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves all active style mappings for a given style name. Useful for reviewing current mappings and troubleshooting. ```python # This function returns all the active mappings for all the properties p4c.get_style_all_mappings('STRING - ovarian cancer') ``` -------------------------------- ### Import Network File from URL Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su basic protocol 1.ipynb Downloads a network file from a specified URL (Dropbox in this case) into the Cytoscape sandbox. This function is suitable for local setups where the notebook and Cytoscape run on the same machine. ```python res_mitab = p4c.import_file_from_url("https://www.dropbox.com/s/8wc8o897tsxewt1/BIOGRID-ORGANISM-Saccharomyces_cerevisiae-3.2.105.mitab?dl=0", "BIOGRID-ORGANISM-Saccharomyces_cerevisiae-3.2.105.mitab") print(f'Network file BIOGRID-ORGANISM-Saccharomyces_cerevisiae-3.2.105.mitab has {res_mitab["fileByteCount"]} bytes') ``` -------------------------------- ### Remove Disconnected Sub-networks and Fit Content Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su Basic Protocol 2.ipynb Installs the 'Largest Subnetwork' app, selects the subnetwork containing a specified node (e.g., node 812), inverts the selection to isolate disconnected nodes, deletes them, and then fits the remaining network to the display area. Use this to clean up networks by removing isolated components. ```python p4c.install_app('Largest Subnetwork') res = p4c.commands_post('network select subnetwork createSubnetwork=false includesNode=812') print(f'Count of nodes selected: {len(res["nodes"])}') p4c.invert_node_selection() p4c.delete_selected_nodes() p4c.fit_content() p4c.notebook_export_show_image() ``` -------------------------------- ### Import and Call py4cytoscape in Local Notebook Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet shows the basic steps to import the py4cytoscape library and call a function, such as checking Cytoscape version information, within a local Jupyter Notebook environment. Assumes py4cytoscape is already installed. ```python import py4cytoscape as p4c p4c.cytoscape_version_info() ``` -------------------------------- ### Export Network to Different Sandbox Locations Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Shows how to export a network using `p4c.export_network`. The destination can be controlled by `p4c.sandbox_set`, which allows setting the sandbox directory to 'mine' or a custom path (None defaults to the scratchpad). ```python print('should go to scratchpad') print(p4c.export_network('foo')) print('should set up installation directory') print(p4c.sandbox_set(None)) print(p4c.export_network('foo')) print('should go to sandbox mine') print(p4c.sandbox_set('mine')) print(p4c.export_network('foo')) ``` -------------------------------- ### Create and Display a Simple Graph Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/yFiles.ipynb Initializes a GraphWidget and sets nodes and edges with properties. Use this for basic graph visualization. ```python from yfiles_jupyter_graphs import GraphWidget w = GraphWidget() w.set_nodes([ {'id': 0, 'properties': {'label': 'Hello World'}}, {'id': 1, 'properties': {'label': 'This is a second node.'}} ]) w.set_edges([ {'id': 0, 'start': 0, 'end': 1, 'properties': {'label': 'edge between first and second node'}} ]) w.show() ``` -------------------------------- ### Run All Deep Tests Source: https://github.com/cytoscape/py4cytoscape/blob/master/INSTALL.rst Executes the complete py4cytoscape test suite from the command line. This may take a significant amount of time. Console output is redirected to 'cons' and 'err' files. ```bash runalltests.bat ``` -------------------------------- ### Initialize py4cytoscape Browser Client Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Executes a Python script from a URL to initialize the py4cytoscape browser client. This is necessary for remote notebook environments like Google Colab to connect to Cytoscape. ```python import requests exec(requests.get("https://raw.githubusercontent.com/cytoscape/jupyter-bridge/master/client/p4c_init.py").text) IPython.display.Javascript(_PY4CYTOSCAPE_BROWSER_CLIENT_JS) # Start browser client ``` -------------------------------- ### Invoke GET Request for Cytoscape Session Name Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Use `commands.cyrest_get` to invoke a GET request to retrieve the name of the current Cytoscape session. This is useful when a direct py4cytoscape function is not available for this operation. The second argument is an empty dictionary as there are no parameters for this specific operation. ```python commands.cyrest_get('session/name', {}) ``` -------------------------------- ### Export Network to PDF Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su Basic Protocol 2.ipynb Exports the current network to a PDF file. Ensure the output directory is correctly set. Overwrites the file if it already exists. ```python OUT_FILE = 'Disease.pdf' p4c.export_image(f'{OUTPUT_DIR}{OUT_FILE}', type='PDF', overwrite_file=True) ``` -------------------------------- ### Open Session and Export Image (Full Paths) Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet shows how to open a Cytoscape session and export an image using full, non-portable paths. This method is generally discouraged due to portability issues. ```python open_session('C:\\Users\\Me\\Documents\\CyFiles\\mySession') # ... export_image('C:\\Users\\Me\\Documents\\CyFiles\\myImage.png') ``` -------------------------------- ### Get Specific Style Mapping Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves the details of a specific visual property mapping for a given style. Useful for inspecting or verifying applied styles. ```python p4c.get_style_mapping('STRING - ovarian cancer', 'NODE_FILL_COLOR') ``` -------------------------------- ### Get Cytoscape Version Info Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Fetches detailed version information for Cytoscape and its associated APIs. This is helpful for ensuring compatibility or troubleshooting version-specific issues. ```python p4c.cytoscape_version_info() ``` -------------------------------- ### Get Network List Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Retrieves a list of available network files in Cytoscape. This is useful for checking existing networks before loading or creating new ones. ```python p4c.get_network_list() ``` -------------------------------- ### Manual Node Color Mapping Equivalent Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet shows the equivalent manual configuration for a node color mapping, detailing parameters like table column, values, colors, and mapping type. It serves as a reference for the automatic generator. ```python set_node_color_mapping(table_column='Degree', table_column_values=['8', '7', '6', '5', '4', '3', '2', '1'], colors=['#7FC97F', '#BEAED4', '#FDC086', '#FFFF99', '#386CB0', '#F0027F', '#BF5B17', '#666666'], mapping_type='d', default_color=None, style_name='galFiltered Style', network=None, base_url:'http://127.0.0.1:1234/v1') ``` -------------------------------- ### Get Available Line Styles Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves a list of all available line styles for edges in Cytoscape. Use this to explore different ways to represent connections between nodes. ```python p4c.get_line_styles() # List of all available line styles ``` -------------------------------- ### Get Available Arrow Shapes Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves a list of all available arrow shapes that can be used for edges in Cytoscape. This is useful for understanding the range of arrow styles you can apply. ```python p4c.get_arrow_shapes() # List of all available arrow shapes. ``` -------------------------------- ### Connect and Check Cytoscape Version Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Carissa.ipynb Establishes a connection to a running Cytoscape instance and retrieves version information. Ensure Cytoscape is running before executing. ```python import networkx as nx import py4cytoscape as p4c p4c.cytoscape_ping() p4c.cytoscape_version_info() g = nx.Graph([(1, 2), (3, 4), (1, 4)]) ``` -------------------------------- ### Set and Use a Specific Sandbox Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet shows how to set a specific sandbox for workstation-based workflows, disabling sample data copying and reinitialization. It then proceeds to open a session and export an image. ```python sandbox_set('mySandbox', copy_samples=False, reinitialize=False) open_session('mySession') # ... export_image('myImage.png') ``` -------------------------------- ### Get Visual Property Names Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves a comprehensive list of all visual property names available in Cytoscape. This is essential for programmatically controlling every aspect of network appearance. ```python p4c.get_visual_property_names() # Names of all visual properties. ``` -------------------------------- ### Continuous Node Color Mapping with Default Brewer Palette Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Applies a continuous mapping for node colors based on the 'Degree' attribute using a default Brewer palette (GnBu). Ideal for gradients. ```python set_node_color_mapping(**gen_node_color_map('Degree', style_name='galFiltered Style')) ``` -------------------------------- ### Get Available Node Shapes Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Retrieves a list of all available node shapes that can be used to represent nodes in Cytoscape. This helps in visualizing different types of entities in your network. ```python p4c.get_node_shapes() # List of all available node shapes ``` -------------------------------- ### Open Session and Export Image (Relative Paths) Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet demonstrates opening a Cytoscape session and exporting an image using relative paths. This approach is suitable for workstation-based Python workflows. ```python open_session('mySession') # ... export_image('myImage.png') ``` -------------------------------- ### Call MCODE Cluster Function Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet demonstrates how to call the MCODE cluster function with specific parameters using the commands.commands_post method. Ensure MCODE app is installed in Cytoscape. ```python commands.commands_post('mcode cluster degreeCutoff=2 fluff=true fluffNodeDensityCutoff=0.1 haircut=true includeLoops=false kCore=2 maxDepthFromStart=100 network=current nodeScoreCutoff=0.2 scope=NETWORK') ``` -------------------------------- ### Set Edge Widths Based on Neighbor Count (Weight) Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Notebooks/Gang Su Basic Protocol 2.ipynb Creates a mapping to set edge line widths proportional to the 'Weight' attribute. Edges with Weight=1 have a width of 1, and each increment in Weight adds 3 to the width. Useful for emphasizing connections based on their importance or strength. ```python p4c.set_edge_line_width_mapping(**p4c.gen_edge_width_map('Weight', p4c.scheme_d_number_series(start_value=1, step=3), mapping_type='d', style_name='default')) ``` -------------------------------- ### Download and Load Network Files Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Downloads network data files (nodes and edges) from specified URLs into the Cytoscape sandbox and prints their byte counts. This prepares data for network creation. ```python p4c.sandbox_set(None) # Download nodes_COAD.tsv to Cytoscape sandbox res_nodes = p4c.sandbox_url_to('https://drive.google.com/file/d/1twJQO9UR6LBuOPaGgjjxDsWZNEFHvl-O/view?usp=sharing', 'nodes_COAD.tsv') res_nodes # Download edges_COAD.tsv to Cytoscape sandbox res_edges = p4c.sandbox_url_to('https://drive.google.com/file/d/1CmM-TKqJ7RDe99U1e7xYWRG86GzClC3v/view?usp=sharing', 'edges_COAD.tsv') res_edges print(f'Network file nodes_COAD.tsv has {res_nodes["fileByteCount"]} bytes') print(f'Network file edges_COAD.tsv has {res_edges["fileByteCount"]} bytes') ``` -------------------------------- ### Set Detail Log Directory Environment Variable Source: https://github.com/cytoscape/py4cytoscape/blob/master/LOGGING.rst Example of setting the PY4CYTOSCAPE_DETAIL_LOGGER_DIR environment variable to override the default log directory. This is useful for redirecting logs to a specific location. ```bash set PY4CYTOSCAPE_DETAIL_LOGGER_DIR=/tmp/p4clogs ``` -------------------------------- ### Generate Edge Arrow Shape Map Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Generates an edge source arrow shape mapping for an 'interaction' attribute. This is an example of mapping edge visual properties based on attribute values. ```python set_edge_source_arrow_shape_mapping(**gen_edge_arrow_map('interaction', ``` -------------------------------- ### Load Tab-Separated Table Data Source: https://github.com/cytoscape/py4cytoscape/wiki/Load-Data-Table-From-File Transfers a local file to the Cytoscape sandbox and imports it as a table. Use `keyColumnIndex` to specify the column for matching and `startLoadRow` to skip header comments. ```python import py4cytoscape as p4c soft_name = p4c.sandbox_send_to('GDS112_full.soft', 'GEO/GDS112_full.soft')['filePath'] p4c.commands_post(f'table import file file="{soft_name}" keyColumnIndex=10 startLoadRow=83') ``` -------------------------------- ### Demonstrate layout_from_coords Function Usage Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md This snippet shows how to call the `layout_from_coords` function with a DataFrame containing node coordinates. Ensure the DataFrame `df` is defined as shown previously. ```python # Demostrate the use of the layout_from_coords() function layout_from_coords('current', df) ``` -------------------------------- ### Set Continuous Node Color Mapping Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/Harsh1.ipynb Maps a numerical attribute ('Disease Score') to a continuous gradient of node fill colors. This example demonstrates mapping a range of attribute values to specific hex colors, from yellow to red. ```python # Map 'Disease Score' to Node Fill Color # Range: 2.898488 (yellow) to 5.0 (red) p4c.set_node_color_mapping( 'stringdb::disease score', # Attribute to map [2.898488, 5.0], # Range of attribute values ['#FBE723', '#ff003c'], # Gradient colors: yellow to red mapping_type='c', # Mapping type : continuous style_name='STRING - ovarian cancer' # Style to modify ) ``` -------------------------------- ### Generate Node Color Map with Custom Palettes Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Generates a node color mapping specifying custom sequential and divergent Brewer palettes. This allows explicit control over the color schemes used for mapping. ```python set_node_color_mapping(**gen_node_color_map('Expressed', (palette_color_brewer_s_YlGn(), palette_color_brewer_d_Spectral()), style_name='galFiltered Style')) ``` -------------------------------- ### Generate Node Color Map with Default Palettes Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Generates a node color mapping using default sequential and divergent Brewer palettes. Use this when the data distribution is unknown and you want py4cytoscape to choose appropriate palettes. ```python set_node_color_mapping(**gen_node_color_map('Expressed', style_name='galFiltered Style')) ``` -------------------------------- ### Generate Node Opacity Map with Continuous Number Scheme Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Generates a node fill opacity mapping for an 'Expressed' attribute using a continuous number scheme. This maps the attribute's values to an opacity range from a start to an end value. ```python set_node_fill_opacity_mapping(**gen_node_opacity_map('Expressed', scheme_c_number_continuous(start_value=50, end_value=200), style_name='galFiltered Style')) ``` -------------------------------- ### Transfer Files to Sandbox Source: https://github.com/cytoscape/py4cytoscape/blob/master/tests/scratchpad/Alexandra.ipynb Use `sandbox_get_from` to transfer local files to the py4cytoscape sandbox environment. This is necessary for files that need to be accessed within the Python VM. ```python p4c.sandbox_get_from('nodes_COAD.tsv') p4c.sandbox_get_from('edges_COAD.tsv') ``` -------------------------------- ### Generate Node Opacity Map with Custom Number Series Scheme Source: https://github.com/cytoscape/py4cytoscape/blob/master/doc/concepts.md Generates a node fill opacity mapping for a 'Degree' attribute using a custom divergent number series scheme. This allows specifying the start value and step for the opacity range. ```python set_node_fill_opacity_mapping(**gen_node_opacity_map('Degree', scheme_d_number_series(start_value=100, step=20), mapping_type='d', style_name='galFiltered Style')) ```