Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate top two images in summary figure #122

Open
Islast opened this issue Jun 13, 2019 · 6 comments
Open

Recreate top two images in summary figure #122

Islast opened this issue Jun 13, 2019 · 6 comments
Assignees

Comments

@Islast
Copy link
Collaborator

Islast commented Jun 13, 2019

pnas summary figure

In this summary figure from the PNAS paper we have two lovely plots of the connectome. To recreate these we will need the following things:

  • (x,y,z) coordinates of each of the nodes. For a scona BrainNetwork N these are stored at N.centroids as a dict mapping nodes to (x,y,z) tuples.
  • sagittal, axial and coronal views of the network. This are derived basically by deleting one of the coordinates (x, y or z) to produce a 2-d layout. this layout can then be passed to networkx's network plotting routines
    The original code used to do this is here and there is also a reimplementation of it here. It is possible that neither work, but hopefully they will guide you.
  • a network plotting tool, I suggest using the networkx.drawing module.

The code to create the original figure can be found here

I forget what the original colouring scheme for the nodes is. It may have been a data driven community analysis of the nodes (network communities can be accessed at N.partition()) or by some other scheme. Kirstie can let us know when she gets back, for now I think it's best to simply accept as an argument some dictionary mapping nodes to colours.

Let me know if you have any concerns. Good luck and don't be afraid to ask questions!

@wingedRuslan
Copy link
Collaborator

wingedRuslan commented Jun 17, 2019

@Islast Could you please elaborate on the idea of ordered nodes?

    # We're going to figure out the best way to plot these nodes
    # so that they're sensibly on top of each other
    sort_dict = {}
    sort_dict['axial'] = 'z'
    sort_dict['coronal'] = 'y'
    sort_dict['sagittal'] = 'x'

    node_order = np.argsort(df[sort_dict[orientation]]).values

    # Now remove all the nodes that are not in the node_list
    node_order = [ x for x in node_order if x in node_list ]

and later we use it here:

for node in node_order:
    plot(node)

Just can not figure out by which criteria we are sorting.
Do we sort in the ascending order by the values of x or y or z based on the orientation?

@wingedRuslan
Copy link
Collaborator

wingedRuslan commented Jun 17, 2019

Hi @KirstieJane ,

Could you please explain what the parameter measure='module' to the plot_anatomical_network means?

def plot_anatomical_network(G, **measure='module'**, orientation='sagittal', cmap_name='jet_r', continuous=False ...

And then we pass measure to setup_color_list

    colors_list = setup_color_list(df,
                                    cmap_name=cmap_name,
                                    sns_palette=sns_palette,
                                    measure=measure,
                                    vmin=vmin,
                                    vmax=vmax,
                                    continuous=continuous)
def setup_color_list(df, cmap_name='jet', sns_palette=None, measure='module', continuous=False, vmax=1, vmin=0):
    '''
    Use a colormap to set colors for each value in the
    sort_measure and return a list of colors for each node

    # Figure out how many different colors you need
    n = np.float(len(set(df[measure])))

And also how do we decide which color a node will have? (e.g. in the image above, nodes are displayed in 4 different colors)

I thought that measure is one of the nodal measures we calculate for our nodes (like degree, closeness, betweenness ...). And my best guess was that color and measure is connected. Depending on the measure we select a color for a node.

But does it mean that there will be as many colors as different measure for nodes?

ps. I have already created the above mentioned images, but at this moment all nodes are "green"

@KirstieJane
Copy link
Member

KirstieJane commented Jun 17, 2019

Hi @wingedRuslan!! This is so exciting that you can make the figures!

Let me try to answer some of the questions (brushing off my memory hat from 3 years ago 😆)

Ordered nodes (re: #122 (comment))

Do we sort in the ascending order by the values of x or y or z based on the orientation?

The short answer is, yes 😸

The nodes in a 2D image of the brain will overlap. For example when you're looking sideways at the brain (top left image) the nodes on the left and right sides will be on top of each other. The sorting in the code above says:

  • If you want to look at the brain in a sagittal orientation with the front of the brain on the right side of the image (top left image, think of this as the eyes looking to the right side of the screen) then you need to put the left most nodes at the back and work towards the right (the side closest to you in the image). The x coordinate dictates the left to right position on the brain (see: http://www.fieldtriptoolbox.org/faq/how_are_the_different_head_and_mri_coordinate_systems_defined/#details-of-the-mni-coordinate-system)
  • If you want to look at the brain in an axial orientation (top right image above) then we're going to imagine that we're looking from above the head down onto the brain. So we'll plot the most inferior nodes first (those with the smallest z coordinates) and add the more superior ones on top of the others.
  • There isn't a version of the coronal orientation (although it would be great to make one). That image looks from the front of the brain and plots the nodes nearest the back of the brain first.

If this isn't clear @wingedRuslan, please let me know - it might be easiest to cover in the weekly call when I can point and explain things in person!

measure='module' (re: #122 (comment))

I thought that measure is one of the nodal measures we calculate for our nodes (like degree, closeness, betweenness ...). And my best guess was that color and measure is connected. Depending on the measure we select a color for a node.

Yes! Exactly. In the code above I've chosen to color each node according to the module in which it is allocated by the community partition. Do we have that in the code?

(Update: Looking at the code in scona/graph_measures.py#L279-L295 below, I think the answer is no 😄. But then I looked in scona/classes.py#L223-L241 and the class does calculate the module for each node. I've opened a new issue to see if we can document this better! #123)

A few more notes on this function (which definitely needs more documentation, and can be found at

def setup_color_list(df, cmap_name='jet', sns_palette=None, measure='module', continuous=False, vmax=1, vmin=0):
)

  • df: data frame containing a row for each node in the network (or subnetwork)
  • cmap_name: the matplotlib colourmap: https://matplotlib.org/examples/color/colormaps_reference.html. The code reads this colourmap in by default (L2710). If continous is True then it scales the colourmap to be between vmin and vmax. If continuous is False then The default value is jet. If continuous is False then you split up the range of the colourmap into n RGB values: cmap((i+0.5)/n)
  • sns_palette: If this is passed then it is used to allocate discrete color values for the measures. Good for modules etc and when you know you've passed the right number of colors. Here's more information about palettes if you haven't seen them yet: https://seaborn.pydata.org/tutorial/color_palettes.html
  • measure: By default we colour in the nodes according to which module they've been allocated to by the community partition. This is quite nice as it will usually be quite a small number of groups (4 above) and so you can pick 4 separate colours from the continuous colourmap. If you passed something like degree here, you'd want to make sure that the continuous measure was True so it could pick from across the colour spectrum.
  • continuous: Tells the arguments above how to deal with coming up with the colours.

I hope that's helpful! Let me know if not!

@wingedRuslan
Copy link
Collaborator

Thank you @KirstieJane ! it is definitely helpful :)

I still have a vague picture about ordered nodes. So yeah, looking forward to a weekly call, if I would not understand before by myself.

it might be easiest to cover in the weekly call when I can point and explain things in person!

And speaking about measure='module', do we decide the color of a node based only on this measure, or we could pass any other measure?

What I do not understand is that if we pass, let's say, measure=betweenness we will have as many colors as there are distinct values of measure. So we will have 300 different colors for 300 different measures of nodes(number of nodes 300). Is it okay? Cause I think it would be quite messy.

@Islast
Copy link
Collaborator Author

Islast commented Jun 18, 2019

I think in the case that you pass measure=betweenness you want a continuous cmap. I think the best way to handle this is to allow the user to specify which colourmap they want to use.

@wingedRuslan
Copy link
Collaborator

@KirstieJane, what do you think about the produced figures for measure = "module" ?
axial

coronal

sagittal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants