Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 0c820068458bd9249785c704716acfd1a9301f1c authored by gabrielle9 on 01 August 2022, 23:54:06 UTC, committed by GitHub on 01 August 2022, 23:54:06 UTC
Update README.md
updated README with eLife citation and link and more description
1 parent d118c43
  • Files
  • Changes
  • 707eb41
  • /
  • graph_network.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:0c820068458bd9249785c704716acfd1a9301f1c
directory badge
swh:1:dir:707eb411889dc1b267f05d5bf0679b7641cef443
content badge
swh:1:cnt:66751180161c64de696d647b3901e61f7b06c7b8

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
graph_network.py
import matplotlib.pyplot as plt
import networkx as nx
from networkx.drawing.nx_pydot import write_dot

def clock_type_network(conn_df, clock_df, dot_name = None, separate_E_cells = True):
    """
    Generates type collapsed version of intra clock connections with networkx

    :param conn_df: Any connections dataframe that includes all relevant connections, weight cutoff already done
    :param clock_df: Clock dataframe
    :param dot_name: name of exported dot file
    :param separate_E_cells: Should LNds be grouped
        True graph separates evening cells into subgroups E1, E2, and E3
        False graph groups LNds together and 5th s-LNv is its own node
    :return: (DiGraph) of connections between clock neurons
    """

    # separate_E_cells re-fetches adjacencies so clock_df information can be merged on instead of neuprint default
    if separate_E_cells:
        import numpy as np
        from neuprint import fetch_adjacencies, merge_neuron_properties
        clock_IDs = clock_df['bodyId'].tolist()
        neuron_df, conn_df = fetch_adjacencies(clock_IDs, clock_IDs, min_total_weight=3)
        neuron_df = neuron_df.merge(clock_df, on=["bodyId"])[['bodyId', 'type_x', 'instance', 'subphase']]
        neuron_df['type_x'] = np.where(neuron_df['subphase'] == '', neuron_df['type_x'], neuron_df['subphase'])
        neuron_df = neuron_df.rename({'type_x': 'type'}, axis='columns')
        conn_df = merge_neuron_properties(neuron_df, conn_df)
        conn_df = conn_df.groupby(['type_pre', 'type_post'], as_index=False).sum()
        G = nx.from_pandas_edgelist(conn_df, 'type_pre', 'type_post', edge_attr='weight',
                                    create_using=nx.DiGraph())
    else:
        conn_df = conn_df.groupby(['instance_pre', 'instance_post'], as_index=False).sum()
        conn_df = conn_df.replace("_R", "", regex=True)[['instance_pre', 'instance_post', 'weight']]
        G = nx.from_pandas_edgelist(conn_df, 'instance_pre', 'instance_post', edge_attr='weight',
                                    create_using=nx.DiGraph())
    
    import math

    # Generates weighting and colors for final nodes and edges
    weights = list(nx.get_edge_attributes(G, 'weight').values())
    weights = [math.log(w) for w in weights]
    val_map = {'s-LNv': '#9D3434', 'M': '#9D3434',
               'DN1a': '#C597D4',
               'DN1pA': '#3963A1',
               'DN1pB': '#3963A1',
               'LNd': '#E1B464', 'E1': '#E1B464', 'E2': '#E1B464', 'E3': '#E1B464',
               'LPN': '#4A7A0F',
               '5th s-LNv': '#D86E6E'}
    values = [val_map.get(node) for node in G.nodes()]
    e_colors = [val_map.get(u) for u, v in G.edges()]

    fig, ax = plt.subplots(figsize=(10, 10))
    pos = nx.circular_layout(G)
    nx.draw_circular(G, with_labels=True, ax=ax, connectionstyle='arc3, rad = 0.1', width=list(weights), node_color=values, edge_color=e_colors)
    nx.draw_networkx_edge_labels(G, pos, label_pos=.8, edge_labels=nx.get_edge_attributes(G, 'weight'))

    # Parallel edge weights overlap on networkx, export to dot file
    if dot_name is not None:
        write_dot(G, dot_name + '.svg')

    return G, conn_df

def neuron_graph(conn_df, dot_name = None):
    conn_df = conn_df[['instance_pre', 'instance_post', 'weight']]
    G = nx.from_pandas_edgelist(conn_df, 'instance_pre', 'instance_post', edge_attr='weight', create_using=nx.DiGraph())

    import math
    weights = list(nx.get_edge_attributes(G, 'weight').values())
    weights = [math.log(w) for w in weights]

    # Generates weighting and colors for final nodes and edges
    val_map = {'sLNv': '#9D3434',
               'DN1a': '#C597D4',
               'DN1pA': '#3963A1',
               'DN1pB': '#3963A1',
               'LNd': '#E1B464',
               'LPN': '#4A7A0F',
               '5th sLN': '#D86E6E'}
    values = [val_map.get(node[0:-1]) for node in G.nodes()]
    e_colors = [val_map.get(u[0:-1]) for u, v in G.edges()]

    fig = plt.figure(figsize=(10, 10))
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels=True, connectionstyle='arc3, rad = 0.1', width=list(weights), node_color=values,
            edge_color=e_colors, font_color="whitesmoke", node_size=2000)
    nx.draw_networkx_edge_labels(G, pos, edge_labels=nx.get_edge_attributes(G, 'weight'))

    # Parallel edge weights overlap on networkx, export to dot file
    if dot_name is not None:
        write_dot(G, dot_name + '.svg')
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API