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": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter
"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": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter
"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="network.png"):
url = f"{BASE_URL}/highres_image/network"
params = {
"identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter
"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---56# STRING Protein Interaction Database78Query the STRING API for protein-protein interaction networks.910## When to Use1112- User asks about a protein's interaction partners13- User wants to build an interaction network14- User asks about functional associations between genes15- User wants interaction confidence scores1617## How to Execute1819```python20import requests21import json2223BASE_URL = "https://version-12-0.string-db.org/api"2425# 1. Get interaction partners26def get_interactions(genes, species=9606, score_threshold=400):27 url = f"{BASE_URL}/json/network"28 params = {29 "identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter30 "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()3738# 2. Get functional enrichment39def get_enrichment(genes, species=9606):40 url = f"{BASE_URL}/json/enrichment"41 params = {42 "identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter43 "species": species,44 "caller_identity": "bioclaw"45 }46 r = requests.get(url, params=params)47 r.raise_for_status()48 return r.json()4950# 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()6263# 4. Download network image64def download_network_image(genes, species=9606, output_path="network.png"):65 url = f"{BASE_URL}/highres_image/network"66 params = {67 "identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter68 "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_path7576# Example77interactions = 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```8283## Score Thresholds8485- 900+ = Highest confidence86- 700+ = High confidence87- 400+ = Medium confidence (default)88- 150+ = Low confidence8990## Species IDs9192Human=9606, Mouse=10090, Rat=10116, Fly=7227, Yeast=4932, E.coli=5111459394## Follow-up Suggestions9596- "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?"