network-node-attribute-assignment
Summary
Assign node attributes (assay membership, structural cluster identity, correlation cluster membership, and compound name) to feature nodes in a NetworkX graph constructed from multi-assay LC-MS data. This enrichment enables downstream filtering, visualization, and structural interpretation of feature relationships.
When to use
You have constructed a NetworkX graph with LC-MS features as nodes and need to annotate each node with metadata derived from the MamsiStructSearch output (assay source, isotopologue group, adduct group, structural cluster ID, correlation cluster ID, and optional compound annotation). This is required before rendering the network or filtering nodes by cluster membership.
When NOT to use
- The NetworkX graph has not yet been constructed from features—use graph construction first.
- MamsiStructSearch has not been run or its output DataFrame is incomplete or missing cluster columns.
- Features in the graph do not correspond to rows in the MamsiStructSearch DataFrame (feature name mismatch).
Inputs
- NetworkX graph object with features as nodes
- pandas DataFrame from MamsiStructSearch output (columns: Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster, Correlation cluster, Cross-assay link, optional cpdName)
Outputs
- NetworkX graph object with enriched node attributes (assay, isotopologue_group, isotopologue_pattern, adduct_group, adduct, structural_cluster, correlation_cluster, cross_assay_link, compound_name)
- Attribute-annotated feature nodes suitable for visualization and filtering
How to apply
Load the DataFrame output from MamsiStructSearch, which contains columns Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster, Correlation cluster, Cross-assay link, and optional cpdName. For each feature node in the NetworkX graph, retrieve the corresponding row and assign its metadata values as node attributes using NetworkX's node attribute dictionary (e.g., G.nodes[feature_id]['assay'] = row['Assay'], G.nodes[feature_id]['struct_cluster'] = row['Structural cluster']). Ensure all features present in the graph have complete attribute assignment. This enables node colorization by cluster in pyvis visualization and supports downstream node filtering or curation based on structural properties.
Related tools
Examples
struct = MamsiStructSearch(rt_win=5, ppm=10)
struct.load_lcms(selected)
struct.get_structural_clusters(annotate=True)
df_clusters = struct.get_struct_cluster_df()
for feature, row in df_clusters.iterrows():
G.nodes[feature]['assay'] = row['Assay']
G.nodes[feature]['structural_cluster'] = row['Structural cluster']
G.nodes[feature]['correlation_cluster'] = row['Correlation cluster']
Evaluation signals
- Every feature node in the graph has non-null values for 'assay', 'structural_cluster', and 'correlation_cluster' attributes.
- Node attribute keys match the MamsiStructSearch column names (Assay, Isotopologue group, Adduct group, Structural cluster, Correlation cluster, cpdName).
- When iterating over
G.nodes(data=True), each node dict contains ≥ 7 keys (feature identifier + 6 metadata attributes).
- Pyvis interactive visualization renders nodes with distinct colors for each unique structural_cluster value (if
include_all=True) without missing or NaN-colored nodes.
- Filtering operations (e.g.,
[node for node, attr in G.nodes(data=True) if attr['assay'] == 'HPOS']) return the expected subset of features.
Limitations
- Feature names in the NetworkX graph must exactly match feature identifiers in the MamsiStructSearch DataFrame; case-sensitive mismatches will result in missing attribute assignments.
- If MamsiStructSearch is run with
annotate=True but the assay is not supported by the National Phenome Centre ROI database, the cpdName attribute will be None/NaN for those features.
- Large networks (>5000 features) may experience slow rendering in pyvis due to force-directed layout computation; consider filtering to structural clusters of interest before visualization.
- Cross-assay link metadata is only populated when features from different assays (e.g., positive and negative ion modes) share a hypothetical neutral mass within the specified ppm tolerance.
Evidence
- [methods] 1. Load structural clusters and correlation clusters from MamsiStructSearch output (DataFrame with Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster, Correlation cluster, Cross-assay link, and optional cpdName columns). 2. Construct a NetworkX graph with features as nodes, assigning node attributes (assay, cluster membership, compound name).: "Load structural clusters and correlation clusters from MamsiStructSearch output (DataFrame with Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster,"
- [methods] Overlapping adduct clusters and isotopologue clusters are then merged to form structural clusters. Further, we search cross-assay clusters using [M+H]+/[M-H]- as link references.: "Overlapping adduct clusters and isotopologue clusters are then merged to form structural clusters. Further, we search cross-assay clusters using [M+H]+/[M-H]- as link references"
- [readme] The different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links.: "The different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links"
1---2name: network-node-attribute-assignment3description: Use when you have constructed a NetworkX graph with LC-MS features as nodes and need to annotate each node with metadata derived from the MamsiStructSearch output (assay source, isotopologue group, adduct group, structural cluster ID, correlation cluster ID, and optional compound annotation).4license: CC-BY-4.05---67# network-node-attribute-assignment89## Summary1011Assign node attributes (assay membership, structural cluster identity, correlation cluster membership, and compound name) to feature nodes in a NetworkX graph constructed from multi-assay LC-MS data. This enrichment enables downstream filtering, visualization, and structural interpretation of feature relationships.1213## When to use1415You have constructed a NetworkX graph with LC-MS features as nodes and need to annotate each node with metadata derived from the MamsiStructSearch output (assay source, isotopologue group, adduct group, structural cluster ID, correlation cluster ID, and optional compound annotation). This is required before rendering the network or filtering nodes by cluster membership.1617## When NOT to use1819- The NetworkX graph has not yet been constructed from features—use graph construction first.20- MamsiStructSearch has not been run or its output DataFrame is incomplete or missing cluster columns.21- Features in the graph do not correspond to rows in the MamsiStructSearch DataFrame (feature name mismatch).2223## Inputs2425- NetworkX graph object with features as nodes26- pandas DataFrame from MamsiStructSearch output (columns: Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster, Correlation cluster, Cross-assay link, optional cpdName)2728## Outputs2930- NetworkX graph object with enriched node attributes (assay, isotopologue_group, isotopologue_pattern, adduct_group, adduct, structural_cluster, correlation_cluster, cross_assay_link, compound_name)31- Attribute-annotated feature nodes suitable for visualization and filtering3233## How to apply3435Load the DataFrame output from MamsiStructSearch, which contains columns Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster, Correlation cluster, Cross-assay link, and optional cpdName. For each feature node in the NetworkX graph, retrieve the corresponding row and assign its metadata values as node attributes using NetworkX's node attribute dictionary (e.g., `G.nodes[feature_id]['assay'] = row['Assay']`, `G.nodes[feature_id]['struct_cluster'] = row['Structural cluster']`). Ensure all features present in the graph have complete attribute assignment. This enables node colorization by cluster in pyvis visualization and supports downstream node filtering or curation based on structural properties.3637## Related tools3839- **networkx** (Graph construction and node attribute assignment via dict-like interface) — https://github.com/networkx/networkx40- **pandas** (Read and iterate over MamsiStructSearch output DataFrame to extract node metadata) — https://github.com/pandas-dev/pandas41- **pyvis** (Render the attribute-enriched graph with node coloring by cluster membership) — https://github.com/WestHealth/pyvis42- **MamsiStructSearch** (Generate the structural cluster, correlation cluster, and feature metadata DataFrame) — https://github.com/kopeckylukas/py-mamsi4344## Examples4546```47struct = MamsiStructSearch(rt_win=5, ppm=10)48struct.load_lcms(selected)49struct.get_structural_clusters(annotate=True)50df_clusters = struct.get_struct_cluster_df()51for feature, row in df_clusters.iterrows():52 G.nodes[feature]['assay'] = row['Assay']53 G.nodes[feature]['structural_cluster'] = row['Structural cluster']54 G.nodes[feature]['correlation_cluster'] = row['Correlation cluster']55```5657## Evaluation signals5859- Every feature node in the graph has non-null values for 'assay', 'structural_cluster', and 'correlation_cluster' attributes.60- Node attribute keys match the MamsiStructSearch column names (Assay, Isotopologue group, Adduct group, Structural cluster, Correlation cluster, cpdName).61- When iterating over `G.nodes(data=True)`, each node dict contains ≥ 7 keys (feature identifier + 6 metadata attributes).62- Pyvis interactive visualization renders nodes with distinct colors for each unique structural_cluster value (if `include_all=True`) without missing or NaN-colored nodes.63- Filtering operations (e.g., `[node for node, attr in G.nodes(data=True) if attr['assay'] == 'HPOS']`) return the expected subset of features.6465## Limitations6667- Feature names in the NetworkX graph must exactly match feature identifiers in the MamsiStructSearch DataFrame; case-sensitive mismatches will result in missing attribute assignments.68- If MamsiStructSearch is run with `annotate=True` but the assay is not supported by the National Phenome Centre ROI database, the cpdName attribute will be None/NaN for those features.69- Large networks (>5000 features) may experience slow rendering in pyvis due to force-directed layout computation; consider filtering to structural clusters of interest before visualization.70- Cross-assay link metadata is only populated when features from different assays (e.g., positive and negative ion modes) share a hypothetical neutral mass within the specified ppm tolerance.7172## Evidence7374- [methods] 1. Load structural clusters and correlation clusters from MamsiStructSearch output (DataFrame with Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster, Correlation cluster, Cross-assay link, and optional cpdName columns). 2. Construct a NetworkX graph with features as nodes, assigning node attributes (assay, cluster membership, compound name).: "Load structural clusters and correlation clusters from MamsiStructSearch output (DataFrame with Feature, Assay, Isotopologue group, Isotopologue pattern, Adduct group, Adduct, Structural cluster,"75- [methods] Overlapping adduct clusters and isotopologue clusters are then merged to form structural clusters. Further, we search cross-assay clusters using [M+H]+/[M-H]- as link references.: "Overlapping adduct clusters and isotopologue clusters are then merged to form structural clusters. Further, we search cross-assay clusters using [M+H]+/[M-H]- as link references"76- [readme] The different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links.: "The different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links"