# How to get all motif samples？

**URL:** <https://igraph.discourse.group/t/how-to-get-all-motif-samples/1817>\
**Category:** Usage\
**Tags:** Python\
**Created:** [22 May 2024 12:55 UTC](https://igraph.discourse.group/t/how-to-get-all-motif-samples/1817 "2024-05-22T12:55:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amber](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/amber/32/1076_2.png) [@amber](https://igraph.discourse.group/u/amber)\
**Post date:** [22 May 2024 12:55 UTC](https://igraph.discourse.group/t/how-to-get-all-motif-samples/1817/1 "2024-05-22T12:55:53Z")

</div>

I’m using python igraph to find the motifs and vertices invovled in a directed and weighted graph with the method `motifs_randesu` .  
How do I get a list of all associated vertices for each motif？ 😀  
Let’s say for example: motif: 0-\>1 2-\>0 1-\>2, maybe eligible vertices are:[(0, 2, 3), (3, 5, 6)]  
Or maybe i can get the motifs from a given vertex? 😀  
Let’s say for example: i have a vertex, all the motif counts of this vertex can be obtained  
Thank you so much! 🤗

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [22 May 2024 22:02 UTC](https://igraph.discourse.group/t/how-to-get-all-motif-samples/1817/2 "2024-05-22T22:02:57Z")

</div>

I think this functionality is not currently exposed in Python (correct me if I’m wrong, @tamas). However, it _is_ possible with the C library, see [igraph Reference Manual](https://igraph.org/c/html/latest/igraph-Motifs.html#igraph_motifs_randesu_callback). It could be exposed in Python if there is demand.

What is your specific use case? For example, in the Mathematica interface of igraph I have [`IGMotifsVertexParticipation`](http://szhorvat.net/mathematica/IGDocumentation/#igmotifsvertexparticipation), which gives motif counts per vertex.

---

<div class="post-metadata">

**Author:** ![amber](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/amber/32/1076_2.png) [@amber](https://igraph.discourse.group/u/amber)\
**Post date:** [23 May 2024 04:44 UTC](https://igraph.discourse.group/t/how-to-get-all-motif-samples/1817/3 "2024-05-23T04:44:25Z")

</div>

Thanks a lot!  
I found that `callback` parameter of method `motifs_randesu` can give me the node lists of each type motif.  
Here’s the case i need, and i already fix it! 😊

```auto
    def motif_callback(graph, node_list, motif):
        print(f'Motif found: {motif} with nodes {node_list}')

motif_counts = g.motifs_randesu(size=3, callback = motif_callback)

```

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [23 May 2024 10:40 UTC](https://igraph.discourse.group/t/how-to-get-all-motif-samples/1817/4 "2024-05-23T10:40:04Z")

</div>

I’m sorry, so indeed it is exposed in Python. I kept looking for a separate function with the callback functionality.
