How to use the igraph.Graph.TupleList function in igraph

To help you get started, we’ve selected a few igraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github testedminds / sand / sand / graph.py View on Github external
def from_edges(edges, source_key='source', target_key='target', weight_key='weight', directed=True):
    """
    Given a List of Dictionaries with source, target, and weight attributes, return a weighted, directed graph.
    """
    raw = list(map(lambda x: [x[source_key], x[target_key], int(x[weight_key])], edges))
    g = IGraph.TupleList(raw, weights=True, directed=directed)
    g.vs['indegree'] = g.degree(mode="in")
    g.vs['outdegree'] = g.degree(mode="out")
    g.vs['label'] = g.vs['name']
    if 'group' not in g.vs.attributes():
        g.vs['group'] = labels_to_groups(g.vs['label'])
    return g
github pnnl / socialsim / december-measurements / cascade_measurements.py View on Github external
def igraph_from_pandas_edgelist(df, source, target, directed):
    edgelist = df[[source, target]].apply(tuple, axis=1).tolist()
    return Graph.TupleList(edgelist, directed=directed)
github saezlab / pypath / src / functional.py View on Github external
key = lambda i: i[1], reverse = True)[:20])
mostcomterm = set(mostcommon.keys())
mostspecial = dict([(db, [t for t in lst if topcountrall[t] == 1][:10]) \
    for db, lst in enr_db.iteritems()])

edges = []
for term in mostcommon.keys():
    for db, lst in enr_db.iteritems():
        if term in lst[:10]:
            edges.append((db, term))

for db, terms in mostspecial.iteritems():
    for term in terms[:3]:
        edges.append((db, term))

gg = igraph.Graph.TupleList(edges)

repl = {
    'signaling pathway': 'signaling',
    'Genes involved in ': '',
    'toll-like receptor': 'TLR',
    'epidermal growth factor receptor': 'EGFR',
    'peptidyl-tyrosine': 'tyrosine',
    'signal transduction': 'signaling',
    'protein kinase A': 'PKA'
}
rerepl = re.compile('|'.join(repl.keys()))
regid = re.compile(r'[\[\(].*[\]\)]')

gg.vs['typ'] = ['gsetc' if v['name'] in mostcomterm \
    else 'gsets' if v['name'] not in net.sources \
    else 'db' for v in gg.vs]
github saezlab / pypath / src / resource_graph.py View on Github external
plot.save()

## ## ##

redges = [(s1, s2, pypath.common.simpson_index(
    [r.pmid for r in uniqList(flatList([[] if s1 not in e['refs_by_source'] \
        else e['refs_by_source'][s1] \
        for e in net.graph.es]))], 
    [r.pmid for r in uniqList(flatList([[] if s2 not in e['refs_by_source'] \
        else e['refs_by_source'][s2] \
        for e in net.graph.es]))]
    )) for s1 in list(set(net.sources) - set(['ACSN'])) \
        for s2 in list(set(net.sources) - set(['ACSN']))]


g = igraph.Graph.TupleList([e for e in redges if e[2] > 0.0545 and e[0] != e[1]], 
    edge_attrs = ['weight'])
g.simplify(combine_edges = 'mean')


lo = g.layout_fruchterman_reingold(weights = 'weight', repulserad = g.vcount() ** 2.8, 
    maxiter = 1000, area = g.vcount() ** 2.3)

g.vs['ncount'] = [len(uniqList(flatList([e['refs_by_source'][v['name']] \
    for e in net.graph.es \
    if v['name'] in e['refs_by_source']])))**0.48 for v in g.vs]

scale = [50, 100, 500, 1000, 2000]
escale = [0.05, 0.1, 0.2, 0.5]

g.add_vertices([str(i) for i in scale])
g.add_vertices(['%.2f_%u' % (i, a) for i in escale for a in [0, 1]])
github saezlab / pypath / src / functional.py View on Github external
key = lambda i: i[1], reverse = True)[:20])
mostcomterm = set(mostcommon.keys())
mostspecial = dict([(db, [t for t in lst if topcountrall[t] == 1][:10]) \
    for db, lst in enr_db.iteritems()])

edges = []
for term in mostcommon.keys():
    for db, lst in enr_db.iteritems():
        if term in lst[:10]:
            edges.append((db, term))

for db, terms in mostspecial.iteritems():
    for term in terms[:3]:
        edges.append((db, term))

gg = igraph.Graph.TupleList(edges)

repl = {
    'signaling pathway': 'signaling',
    'Genes involved in ': '',
    'Toll-like receptor': 'TLR',
}
rerepl = re.compile('|'.join(repl.keys()))
regid = re.compile(r'[\[\(].*[\]\)]')

gg.vs['typ'] = ['gsetc' if v['name'] in mostcomterm \
    else 'gsets' if v['name'] not in net.sources \
    else 'db' for v in gg.vs]
gg.vs['color'] = ['#6EA945AA' if v['typ'] == 'db' \
    else '#007B7FAA' if v['typ'] == 'gsetc' \
        else '#FCCC06AA' for v in gg.vs]
gg.vs['shape'] = ['circle' if v['typ'] == 'db' else 'rectangle' for v in gg.vs]
github saezlab / pypath / src / pypath / plot.py View on Github external
def init_sgraph(self):
        self.sgraph = igraph.Graph.TupleList(self.edges, edge_attrs = ['weight'])
        self.sgraph.simplify(combine_edges = 'mean')
github pnnl / socialsim / december-measurements / network_measurements.py View on Github external
def build_undirected_graph(self, df):
        
        #self.main_df = pd.read_csv(data)
        self.main_df = self.main_df[['nodeUserID','nodeID']]
        
        left_nodes = np.array(self.main_df['nodeUserID'].unique().tolist())
        right_nodes = np.array(self.main_df['nodeID'].unique().tolist())
        el = self.main_df.apply(tuple, axis=1).tolist()
        edgelist = list(set(el))
 
        #iGraph Graph object construction
        B = ig.Graph.TupleList(edgelist, directed=False)
        names = np.array(B.vs["name"])
        types = np.isin(names,right_nodes)
        B.vs["type"] = types
        p1,p2 = B.bipartite_projection(multiplicity=False)
        
        self.gUNig = None
        if (self.project_on == "user"):
            self.gUNig = p1
        else:
            self.gUNig = p2

        #self.gUNig = B.bipartite_projection(multiplicity=False, which = 0)

        
        #SNAP graph object construction
        self.gUNsn = sn.TUNGraph.New()
github saezlab / pypath / src / resource_graph.py View on Github external
#net.init_network(pfile = 'cache/default_plus_acsn.pickle')
net.init_network(pfile = 'cache/default_network_wo-intact_ltp-only.pickle')

net.genesymbol_labels()

## ## ##

sim = net.databases_similarity()

edges = [e for e in [(it[0], iit[0], iit[1], sim['nodes'][it[0]][iit[0]]) \
    for it in sim['edges'].items() for iit in it[1].items()] \
    if (e[2] > 0.15 or (e[0] == 'MatrixDB' and e[2] > 0.02) or \
    (e[0] == 'NRF2ome' and e[2] > 0.07) or (e[0] == 'ACSN' and e[2] > 0.10)) \
    and e[0] != e[1]]

g = igraph.Graph.TupleList(edges, edge_attrs = ['weight', 'nodes'])
g.simplify(combine_edges = 'mean')


lo = g.layout_fruchterman_reingold(weights = 'weight', repulserad = g.vcount() ** 2.8, 
    maxiter = 1000, area = g.vcount() ** 2.3)

g.vs['ncount'] = [len([e for e in net.graph.es if v['name'] in e['sources']])**0.55 for v in g.vs]

scale = [50, 100, 500, 1000, 5000]
escale = [0.05, 0.1, 0.2, 0.5]

g.add_vertices([str(i) for i in scale])
g.add_vertices(['%.2f_%u' % (i, a) for i in escale for a in [0, 1]])
g.add_edges([('%.2f_%u' % (i, 0), '%.2f_%u' % (i, 1)) for i in escale])

xmax = max([c[0] for c in lo._coords])
github graphistry / pygraphistry / graphistry / plotter.py View on Github external
ig.vs['community'] = ig.community_infomap().membership
                g.bind(point_color='community').plot(ig)
        """


        import igraph
        self._check_mandatory_bindings(False)
        self._check_bound_attribs(edges, ['source', 'destination'], 'Edge')
        
        self._node = self._node or Plotter._defaultNodeId
        eattribs = edges.columns.values.tolist()
        eattribs.remove(self._source)
        eattribs.remove(self._destination)
        cols = [self._source, self._destination] + eattribs
        etuples = [tuple(x) for x in edges[cols].values]
        return igraph.Graph.TupleList(etuples, directed=directed, edge_attrs=eattribs,
                                      vertex_name_attr=self._node)