gravatar for hniels01

4 hours ago by

I am trying Circos plotting for the first time, to plot pathway nodes for proteins. I followed a posting on Medium to see how to set it up and run it. I have a short list of 8 proteins that I wanted to plot the pathway nodes for. After setting things up, when I ask for the plot I get an error "A CircosPlot only makes sense for at least 3 nodes", and then Python tells me that the error happens at this step in the function "assert len(graph.nodes) >= 3". So it is failing this checkpoint in the plotting function. To make sure that it wasn't because I have too small a group, I tried it with a set of 35 proteins from a another part of the overall experiment. I get the same error. I have looked at the elements of the data frame created in the setup, and the array of interactions created before doing the plot, and see no concerns there. This is the code I have been using:

import nxviz
import jinja2
import networkx as nx
import requests
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from nxviz.plots import CircosPlot

protein_list = ['pentraxin 3', 'serpin E1', 'cyr61', 'coagulation factor 3', 'cxcl16', 'mcp-1', 'igfbp3', 'ip10']
proteins = '%0d'.join(protein_list)
url = '' + proteins + '&species=9606'
r = requests.get(url)

lines = r.text.split('n')        # pull the text from the response object and split based on new lines
data_p = [l.split('t') for l in lines]        # split each line into its components based on tabs
         # convert to dataframe using the first row as the column names; drop empty, final row
df_p = pd.DataFrame(data_p[1:-1], columns = data_p[0]) 
        # dataframe with the preferred names of the two proteins and the score of the interaction
interactions = df_p[['preferredName_A', 'preferredName_B', 'score']] 

G=nx.Graph(name='Angiogenesis Proteins Interaction Graph')
interactions = np.array(interactions)       # convert to array for clarity
for i in range(len(interactions)):
    interaction = interactions[i]
    a = interaction[0] # protein a node
    b = interaction[1] # protein b node
    w = int(float(interaction[2])*100)      # score as weighted edge

c = CircosPlot(G,node_labels=True)

And this is the error from this last code chunk:

*AssertionError                            Traceback (most recent call last)
<ipython-input-60-68b2d8dfc6d3> in <module>
----> 1 c = CircosPlot(G,node_labels=True)
      2 c.draw()
      3 in __init__(self, graph, **kwargs)
    501         # A CircosPlot only makes sense for at least 3 nodes
--> 502         assert len(graph.nodes) >= 3
    503         # Node labels are specified in the node_label_layout argument
    504         specified_layout = kwargs.pop("node_label_layout", None)


I would appreciate any suggestions people can offer.

Source link