STRING Protein Interaction Database
Query the STRING API for protein-protein interaction networks.
When to Use
- User asks about a protein's interaction partners
- User wants to build an interaction network
- User asks about functional associations between genes
- User wants interaction confidence scores
How to Execute
import requests
import json
BASE_URL = "https://version-12-0.string-db.org/api"
# 1. Get interaction partners
def get_interactions(genes, species=9606, score_threshold=400):
url = f"{BASE_URL}/json/network"
params = {
"identifiers": "%0d".join(genes),
"species": species,
"required_score": score_threshold,
"caller_identity": "bioclaw"
}
r = requests.get(url, params=params)
r.raise_for_status()
return r.json()
# 2. Get functional enrichment
def get_enrichment(genes, species=9606):
url = f"{BASE_URL}/json/enrichment"
params = {
"identifiers": "%0d".join(genes),
"species": species,
"caller_identity": "bioclaw"
}
r = requests.get(url, params=params)
r.raise_for_status()
return r.json()
# 3. Get interaction partners (expand network)
def get_partners(gene, species=9606, limit=10):
url = f"{BASE_URL}/json/interaction_partners"
params = {
"identifiers": gene,
"species": species,
"limit": limit,
"caller_identity": "bioclaw"
}
r = requests.get(url, params=params)
r.raise_for_status()
return r.json()
# 4. Download network image
def download_network_image(genes, species=9606, output_path="/workspace/group/network.png"):
url = f"{BASE_URL}/highres_image/network"
params = {
"identifiers": "%0d".join(genes),
"species": species,
"caller_identity": "bioclaw"
}
r = requests.get(url, params=params)
with open(output_path, 'wb') as f:
f.write(r.content)
return output_path
# Example
interactions = get_interactions(["BRCA1", "BRCA2", "TP53"])
for i in interactions[:10]:
print(f"{i['preferredName_A']} <-> {i['preferredName_B']} score: {i['score']}")
print(f" Sources: experimental={i.get('escore',0)}, database={i.get('dscore',0)}, textmining={i.get('tscore',0)}")
Score Thresholds
- 900+ = Highest confidence
- 700+ = High confidence
- 400+ = Medium confidence (default)
- 150+ = Low confidence
Species IDs
Human=9606, Mouse=10090, Rat=10116, Fly=7227, Yeast=4932, E.coli=511145
Follow-up Suggestions
- "Want me to do enrichment analysis on this network?"
- "Should I expand the network to include more partners?"
- "Want me to download the network image?"
1---2name: query-stringdb3description: Query STRING for protein-protein interactions. Use when user asks about protein interactions, interaction networks, binding partners, or interactome. Triggers on "string", "protein interaction", "interaction network", "binding partners", "interactome", "PPI".4---5
6# STRING Protein Interaction Database
7
8Query the STRING API for protein-protein interaction networks.
9
10## When to Use
11
12- User asks about a protein's interaction partners
13- User wants to build an interaction network
14- User asks about functional associations between genes
15- User wants interaction confidence scores
16
17## How to Execute
18
19```python
20import requests
21import json
22
23BASE_URL = "https://version-12-0.string-db.org/api"
24
25# 1. Get interaction partners
26def get_interactions(genes, species=9606, score_threshold=400):
27 url = f"{BASE_URL}/json/network"
28 params = {
29 "identifiers": "%0d".join(genes),
30 "species": species,
31 "required_score": score_threshold,
32 "caller_identity": "bioclaw"
33 }
34 r = requests.get(url, params=params)
35 r.raise_for_status()
36 return r.json()
37
38# 2. Get functional enrichment
39def get_enrichment(genes, species=9606):
40 url = f"{BASE_URL}/json/enrichment"
41 params = {
42 "identifiers": "%0d".join(genes),
43 "species": species,
44 "caller_identity": "bioclaw"
45 }
46 r = requests.get(url, params=params)
47 r.raise_for_status()
48 return r.json()
49
50# 3. Get interaction partners (expand network)
51def get_partners(gene, species=9606, limit=10):
52 url = f"{BASE_URL}/json/interaction_partners"
53 params = {
54 "identifiers": gene,
55 "species": species,
56 "limit": limit,
57 "caller_identity": "bioclaw"
58 }
59 r = requests.get(url, params=params)
60 r.raise_for_status()
61 return r.json()
62
63# 4. Download network image
64def download_network_image(genes, species=9606, output_path="/workspace/group/network.png"):
65 url = f"{BASE_URL}/highres_image/network"
66 params = {
67 "identifiers": "%0d".join(genes),
68 "species": species,
69 "caller_identity": "bioclaw"
70 }
71 r = requests.get(url, params=params)
72 with open(output_path, 'wb') as f:
73 f.write(r.content)
74 return output_path
75
76# Example
77interactions = get_interactions(["BRCA1", "BRCA2", "TP53"])
78for i in interactions[:10]:
79 print(f"{i['preferredName_A']} <-> {i['preferredName_B']} score: {i['score']}")
80 print(f" Sources: experimental={i.get('escore',0)}, database={i.get('dscore',0)}, textmining={i.get('tscore',0)}")
81```
82
83## Score Thresholds
84
85- 900+ = Highest confidence
86- 700+ = High confidence
87- 400+ = Medium confidence (default)
88- 150+ = Low confidence
89
90## Species IDs
91
92Human=9606, Mouse=10090, Rat=10116, Fly=7227, Yeast=4932, E.coli=511145
93
94## Follow-up Suggestions
95
96- "Want me to do enrichment analysis on this network?"
97- "Should I expand the network to include more partners?"
98- "Want me to download the network image?"