WhitakerLab / scona

Code to analyse structural covariance brain networks using python.
https://whitakerlab.github.io/scona/
MIT License
67 stars 33 forks source link

Recreate top two images in summary figure #122

Open Islast opened 5 years ago

Islast commented 5 years ago

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:

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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: https://github.com/WhitakerLab/scona/issues/122#issuecomment-502652647)

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 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: https://github.com/WhitakerLab/scona/issues/122#issuecomment-502738400)

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! https://github.com/WhitakerLab/scona/issues/123)

A few more notes on this function (which definitely needs more documentation, and can be found at https://github.com/WhitakerLab/scona/blob/38e5f3157d6864909a5cd480dce96f9c2a44337f/scona/scripts/make_figures.py#L2697)

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

wingedRuslan commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

coronal

sagittal