Created
September 4, 2020 07:35
-
-
Save mikk-c/d970e5580bfae3bfa0fde81649d6a176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import networkx as nx" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"G = nx.read_edgelist(\"1/data.txt\", create_using = nx.Graph(), delimiter = \"\\t\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"M1 = nx.read_edgelist(\"1/motif1.txt\", create_using = nx.Graph(), delimiter = \"\\t\")\n", | |
"M2 = nx.read_edgelist(\"1/motif2.txt\", create_using = nx.Graph(), delimiter = \"\\t\")\n", | |
"M3 = nx.read_edgelist(\"1/motif3.txt\", create_using = nx.Graph(), delimiter = \"\\t\")\n", | |
"M4 = nx.read_edgelist(\"1/motif4.txt\", create_using = nx.Graph(), delimiter = \"\\t\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"GM1 = nx.algorithms.isomorphism.GraphMatcher(G, M1)\n", | |
"GM2 = nx.algorithms.isomorphism.GraphMatcher(G, M2)\n", | |
"GM3 = nx.algorithms.isomorphism.GraphMatcher(G, M3)\n", | |
"GM4 = nx.algorithms.isomorphism.GraphMatcher(G, M4)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"How many times motif 1 appears in G? 1448\n", | |
"How many times motif 2 appears in G? 1236\n", | |
"How many times motif 3 appears in G? 2704\n", | |
"How many times motif 4 appears in G? 1396\n" | |
] | |
} | |
], | |
"source": [ | |
"print(\"How many times motif 1 appears in G? %s\" % len(list(GM1.subgraph_isomorphisms_iter())))\n", | |
"print(\"How many times motif 2 appears in G? %s\" % len(list(GM2.subgraph_isomorphisms_iter())))\n", | |
"print(\"How many times motif 3 appears in G? %s\" % len(list(GM3.subgraph_isomorphisms_iter())))\n", | |
"print(\"How many times motif 4 appears in G? %s\" % len(list(GM4.subgraph_isomorphisms_iter())))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment