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".4metadata:5 source: https://skillmd.com/skills/stanfish06/query-stringdb6---78# STRING Protein Interaction Database910Query the STRING API for protein-protein interaction networks.1112## When to Use1314- User asks about a protein's interaction partners15- User wants to build an interaction network16- User asks about functional associations between genes17- User wants interaction confidence scores1819## How to Execute2021```python22import requests23import json2425BASE_URL = "https://version-12-0.string-db.org/api"2627# 1. Get interaction partners28def get_interactions(genes, species=9606, score_threshold=400):29 url = f"{BASE_URL}/json/network"30 params = {31 "identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter32 "species": species,33 "required_score": score_threshold,34 "caller_identity": "bioclaw"35 }36 r = requests.get(url, params=params)37 r.raise_for_status()38 return r.json()3940# 2. Get functional enrichment41def get_enrichment(genes, species=9606):42 url = f"{BASE_URL}/json/enrichment"43 params = {44 "identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter45 "species": species,46 "caller_identity": "bioclaw"47 }48 r = requests.get(url, params=params)49 r.raise_for_status()50 return r.json()5152# 3. Get interaction partners (expand network)53def get_partners(gene, species=9606, limit=10):54 url = f"{BASE_URL}/json/interaction_partners"55 params = {56 "identifiers": gene,57 "species": species,58 "limit": limit,59 "caller_identity": "bioclaw"60 }61 r = requests.get(url, params=params)62 r.raise_for_status()63 return r.json()6465# 4. Download network image66def download_network_image(genes, species=9606, output_path="network.png"):67 url = f"{BASE_URL}/highres_image/network"68 params = {69 "identifiers": "\r".join(genes), # requests encodes \r -> %0D, STRING's identifier delimiter70 "species": species,71 "caller_identity": "bioclaw"72 }73 r = requests.get(url, params=params)74 with open(output_path, 'wb') as f:75 f.write(r.content)76 return output_path7778# Example79interactions = get_interactions(["BRCA1", "BRCA2", "TP53"])80for i in interactions[:10]:81 print(f"{i['preferredName_A']} <-> {i['preferredName_B']} score: {i['score']}")82 print(f" Sources: experimental={i.get('escore',0)}, database={i.get('dscore',0)}, textmining={i.get('tscore',0)}")83```8485## Score Thresholds8687- 900+ = Highest confidence88- 700+ = High confidence89- 400+ = Medium confidence (default)90- 150+ = Low confidence9192## Species IDs9394Human=9606, Mouse=10090, Rat=10116, Fly=7227, Yeast=4932, E.coli=5111459596## Follow-up Suggestions9798- "Want me to do enrichment analysis on this network?"99- "Should I expand the network to include more partners?"100- "Want me to download the network image?"