The Resistance Paradox
Visualizing collateral sensitivity of antibiotic resistance.
Project Summary
The objective of this project was to identify and visualize collateral sensitivity in antibiotic-resistant bacteria using a given dataset. The final artifact is a self-contained, interactive Svelte component that renders a D3.js force-directed graph, enabling users to explore non-obvious antimicrobial relationships.
Phase 1: Data Preparation & Correlation Analysis
This phase focused on transforming raw categorical data into a quantitative format for statistical analysis. Source for dataset: Kaggle
Data Preprocessing
The dataset, containing patient metadata and categorical resistance phenotypes (R for Resistant, S for Susceptible), was loaded into a pandas DataFrame. Personally Identifiable Information (PII) was removed, and the analysis focused on antibiotic columns.
Binarization
Categorical data was binarized: Resistance (R) was mapped to 1, and all other states (S, I, nulls) were mapped to 0.
View Source Code
Click to expand interactive code modal
Phase 2: Backend Logic (Client-Side Implementation)
To ensure portability and performance for a portfolio context, a client-side data lookup strategy replaced a traditional server-side predictive model. The resistance_correlations.json file acts as a static “backend,” eliminating the need for server maintenance or API calls, making the visualization self-contained.
Phase 3: Interactive Frontend Component (Svelte & D3.js)
This phase involved building a reusable Svelte component for data visualization.
### Component Architecture A Svelte component, `ResistanceParadox.svelte`, was created. On initialization (`onMount`), it fetches and parses the `resistance_correlations.json` file.
Visualization Engine
D3.js was used to render a force-directed graph:
- Initialized
d3.forceSimulationfor physics-based node layout (antibiotics). - Bound SVG
<circle>elements to antibiotic data. - Attached DOM events (
.on('click', ...)) to capture user interactions.
Reactivity
User clicks trigger an updateSelection function that looks up correlation data. Svelte’s class: directive dynamically applies CSS classes to D3 nodes based on correlation coefficients.
View Source Code
Click to expand interactive code modal
Find the Superbug’s Secret Weakness
This interactive chart visualizes a fascinating phenomenon in microbiology called collateral sensitivity. Sometimes, when a bacteria becomes resistant to one drug, it develops a surprise weakness to another. Your goal is to find these hidden weaknesses.
How to Interact
Click any circle (an antibiotic) to see how bacteria resistant to it are affected by other drugs.
Watch the colors change. Each color tells a part of the story.
Drag the circles to rearrange the graph for a better view.
Use the “Reset View” button to start a new discovery.
What the Colors Mean
- Red (Selected): This is the antibiotic the bacteria is already resistant to.
- Green (Rival): This is the jackpot! You've found a hidden weakness. The bacteria is now likely susceptible to this antibiotic.
- Orange (Teammate): The bacteria is likely resistant to these antibiotics as well.
- Grey (Neutral): These have no strong relationship with your selection.
Understanding the Controls
Use Demo Data: Real-world data can be subtle. Check this box to load a perfect “textbook example” that is guaranteed to show all the color interactions.
Enable Animation: This turns on the bacterium in the corner. Watch it grow stronger when it finds teammates (orange) or become vulnerable when you find a rival (green)!
Results & User Interaction
Results
The analysis identified multiple antibiotic pairs with strong negative correlations (r < -0.5), validating the collateral sensitivity hypothesis, as well as positive correlations indicating cross-resistance.
User Interaction
Users interact by clicking an antibiotic node in the graph, triggering an instant update. The color-coded feedback indicates:
- Selected (Red): The reference antibiotic to which a bacterium is resistant.
- Susceptible (Blue): Antibiotics likely effective, showing collateral sensitivity.
- Cross-Resistant (Orange): Antibiotics likely ineffective.
- Neutral (Faded): Uncorrelated antibiotics.