StringLoader¶
- class graph.StringLoader.StringLoader(protein_query: List[str], species: int = 9606, caller_identity: str = 'StringLoaderClass', required_score: int = 400, network_type: str = 'functional', add_nodes: int = 10, mapping_limit: int = 1, timeout: int = 30)[source]
Bases:
LoaderRetrieve protein-protein interaction data from the STRING database.
This loader queries the STRING API with a list of protein identifiers, maps them to STRING identifiers, and retrieves the corresponding PPI network.
- base_url
The base URL for the STRING API.
- Type:
str
- protein_query
List of input protein identifiers.
- Type:
List[str]
- species
NCBI taxonomy ID for the organism.
- Type:
int
- required_score
Minimum confidence score for interactions.
- Type:
int
- network_type
Type of network (“functional” or “physical”).
- Type:
str
- add_nodes
Number of additional nodes to include.
- Type:
int
- raw_mapping
Raw mapping response from STRING.
- Type:
List[dict]
- raw_network
Raw network response from STRING.
- Type:
List[dict]
Example
>>> loader = StringLoader( ... protein_query=["TP53", "BRCA1", "EGFR"], ... species=9606, ... add_nodes=10, ... ) >>> data = ( ... loader ... .retrieve_data() ... .standardize_data_format() ... .get_data() ... ) >>> print(data["nodes"].head()) >>> print(data["edges"].head())
- base_url = 'https://version-12-0.string-db.org/api'
- get_network_html_div(width: str = '100%', height: str = '650px', network_flavor: str = 'confidence', add_color_nodes: int | None = None, add_white_nodes: int | None = None, hide_node_labels: bool = False, hide_disconnected_nodes: bool = False, show_query_node_labels: bool = True, block_structure_pics_in_bubbles: bool = False, include_script: bool = True, use_selected_string_ids: bool = True) str[source]
Generate an interactive STRING network HTML block for embedding in reports.
The returned HTML can be inserted directly into an HTML report and will render an interactive Cytoscape visualization of the protein network.
- Parameters:
width – CSS width for the network container. Defaults to “100%”.
height – CSS height for the network container. Defaults to “650px”.
network_flavor – Type of interaction to display (“confidence”, “evidence”, or “actions”). Defaults to “confidence”.
add_color_nodes – Number of additional nodes with color highlighting. Defaults to self.add_nodes.
add_white_nodes – Number of additional nodes without color highlighting. Defaults to self.add_nodes.
hide_node_labels – If True, hide labels on nodes. Defaults to False.
hide_disconnected_nodes – If True, hide nodes without edges. Defaults to False.
show_query_node_labels – If True, show labels only on query proteins. Defaults to True.
block_structure_pics_in_bubbles – If True, disable structure pictures in node bubbles. Defaults to False.
include_script – If True, include the STRING JavaScript library. Defaults to True.
use_selected_string_ids – If True, use mapped STRING IDs; otherwise use original protein_query. Defaults to True.
- Returns:
HTML string containing the embedded STRING network with required scripts.
- Return type:
str
Note
STRING expects the embedded network container to have id=”stringEmbedded”.
This method is intended for one STRING embedded network per HTML page.
If retrieve_data() has already been called, the method uses mapped STRING IDs. Otherwise, it falls back to the original protein_query values.
- retrieve_data() StringLoader[source]
Retrieve and map protein identifiers from STRING, then fetch the network.
This method performs two API calls: 1. Maps input proteins to STRING identifiers (get_string_ids) 2. Retrieves the PPI network for the mapped identifiers (network)
- Returns:
Self for method chaining.
- Return type:
StringLoader
- Raises:
ValueError – If no identifiers are found for the input proteins.
- standardize_data_format() StringLoader[source]
Standardize and organize retrieved PPI data into a structured format.
Converts raw STRING API responses into a dictionary containing standardized DataFrames for nodes, edges, and metadata.
- Returns:
Self for method chaining.
- Return type:
StringLoader
- Raises:
RuntimeError – If retrieve_data() has not been called first.
Note
After calling this method, use get_data() to retrieve the standardized data.