Package: pymotif
PymotifA Python package that lets you plot Motif graphs within Jupyter Notebook / Jupyter Lab:It's that easy to get started!FeaturesSeamless integration into existing Jupyter workflowsMultiple data import optionsProgrammatic graph manipulationEasy code sharing and reuseInstallationYou can install usingpip(we recommend using virtual environments):pip install pymotifAnd it should work. In some cases, you may also need to install and enable Jupyter extensions:# Jupyter Lab
jupyter labextension install @jupyter-widgets/jupyterlab-manager

# For Jupyter Lab <= 2, you may need to install the extension manually
jupyter labextension install @cylynx/pymotif

# For Jupyter Notebook <= 5.2, you may need to enable nbextensions
jupyter nbextension enable --py [--sys-prefix|--user|--system] pymotifDemoDemo notebooks can be found in theexamplesfolder. For a start, check outexamples/introduction.ipynb, which gives a quick overview of the available functionality!Motif ClassAs shown above, using Motif in Jupyter involves importing and instantiating theMotifclass frompymotif.InstantiationfrompymotifimportMotifmotif=Motif()motif.plot()# or just 'motif'Motif()accepts various instantiation parameters (refer to Motif's__init__method for updated information):All parameters are optional.
Only one graph import (json_path, nx_graph, neo4j_graph, or csv_path) can be passed each time.

json_path: str
    Path to a local JSON file containing the graph data.
    If this is used, all other params will be ignored.

nx_graph: nx.Graph
    A networkx graph to be rendered

neo4j_graph: neo4j.graph.Graph
    A neo4j graph to be rendered, obtained from the neo4j.Result.graph() method.
    Ref: https://neo4j.com/docs/api/python-driver/current/api.html#graph

csv_path: str
    Path to a local CSV edgelist file

style: dict
    The rendered graph's style. Its format depends on Motif's StyleOptions interface:
    https://github.com/cylynx/motif.gl/blob/c79ba6549407979a4ec0214cc6c7c7d0f2a3be41/packages/motif/src/redux/graph/types.ts#L206

title: str
    The rendered graph's titleOther params are ignored when using JSON files because the file itself may also contain pre-defined styles, titles, or other settings.Example Usage# import a csv file and set a titlemotif=Motif(csv_path=<YOURCSVPATH>,title='my first csv import')# import a json file. as mentioned above, using json ignores all other paramsmotif=Motif(json_path=<YOURJSONPATH>,title='ignored parameter')# import a networkx graph and arrange it in a grid layoutstyle={'layout':{'type':'grid'}}motif=Motif(nx_graph=<YOURNETWORKXGRAPH>,style=style)AttributesThere is only one class attribute for now:state: dict
    There are 2 possible keys: data, style.
    Data is a list of graph data describing what will be rendered in the widget.
    Style is a dict describing how the graphs will be rendered.

    Follows the TLoadFormat interface defined in Motif's types.ts:
    https://github.com/cylynx/motif.gl/blob/master/packages/motif/src/redux/graph/types.ts#L283Example Usagem=Motif(<YOURPARAMS>)# check graph's initial statem.state# stuff happens...# sanity checkm.stateThis may be useful for debugging your graph objects at various points in time throughout your analysis.Methodsdefadd_graph(self,**kwargs):"""Adds another graph to an existing Motif widget.Takes the same parameters as __init__.If provided, graph settings here will overwrite those set previously (e.g. style)."""defset_style(self,style:dict,overwrite=False):"""Allows updating the style of an existing widget.------------Parameters------------style: dictThe rendered graph's styleoverwrite=False:If True, overwrites all existing styles with the passed 'style' param.If False, merges 'style' param with existing styles"""defplot(self):""" Plots the graphs' current state as a Jupyter widget """Example Usage# create a new graphm=Motif(<YOURPARAMS>)# add another previously-saved graph from a JSON filem.add_graph(json_path=<YOURJSONPATH>)# adjust and overwrite the combined graphs' stylem.set_style(style=<YOURSTYLE>,overwrite=True)# plot the combined graphm.plot()DevelopmentThis section contains instructions for developing Pymotif locally.For a more thorough walkthrough check out the official Jupyter widgets guide:https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Custom.htmlCreate a new conda environment with the dependenciesTo create the environment, execute the following command:conda create -n motif -c conda-forge jupyterlab nodejs pythonThen activate the environment with:conda activate motifBuild and install the widget for developmentSince the widget contains a Python part, you need to install the package in editable mode:npm run pymotif:build // In root directory to link it with monorepo setup
python -m pip install -e .If you are using JupyterLab:jupyter labextension develop --overwrite .If you are using the Classic Notebook:jupyter nbextension install --sys-prefix --symlink --overwrite --py pymotif
jupyter nbextension enable --sys-prefix --py pymotifTo continuously monitor the project for changes and automatically trigger a rebuild, start Jupyter in watch mode:jupyter lab --watchAnd in a separate session, begin watching the source directory for changes:npm run pymotif  // In root directory to link it with monorepo setupAfter a change wait for the build to finish and then refresh your browser and the changes should take effect.If you make a change to the python code then you will need to restart the notebook kernel to have it take effect.PublishingUpdate the version in package.jsonRelase the@cylynx/pymotifpackages:npm login
npm run pymotif:publishBundle the python package:python setup.py sdist bdist_wheelUpdate the version inpymotif/_version.pyIf frontend version dependency has changed, updatepymotif/_frontend.pyPublish the package to PyPI:pip install twine
twine upload dist/pymotif*