Skip to content

Instantly share code, notes, and snippets.

@mikk-c
Created September 4, 2020 07:24
Show Gist options
  • Save mikk-c/ab9369a315ecc38b74074d5e5a8188ff to your computer and use it in GitHub Desktop.
Save mikk-c/ab9369a315ecc38b74074d5e5a8188ff to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"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(\"data.txt\", create_using = nx.Graph(), delimiter = \"\\t\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"M1 = nx.read_edgelist(\"motif1.txt\", create_using = nx.Graph(), delimiter = \"\\t\")\n",
"M2 = nx.read_edgelist(\"motif2.txt\", create_using = nx.Graph(), delimiter = \"\\t\")\n",
"M3 = nx.read_edgelist(\"motif3.txt\", create_using = nx.Graph(), delimiter = \"\\t\")\n",
"M4 = nx.read_edgelist(\"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": [
"Motif 1 in G? True\n",
"Motif 2 in G? True\n",
"Motif 3 in G? True\n",
"Motif 4 in G? True\n"
]
}
],
"source": [
"print(\"Motif 1 in G? %s\" % GM1.subgraph_is_isomorphic())\n",
"print(\"Motif 2 in G? %s\" % GM2.subgraph_is_isomorphic())\n",
"print(\"Motif 3 in G? %s\" % GM3.subgraph_is_isomorphic())\n",
"print(\"Motif 4 in G? %s\" % GM4.subgraph_is_isomorphic())"
]
}
],
"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