SKILL.md
Version Compatibility
Reference examples tested with: matplotlib 3.8+, numpy 1.26+, pandas 2.2+, scipy 1.12+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Longitudinal Monitoring
"Track ctDNA levels over my patient's treatment" → Monitor tumor fraction and mutation dynamics across serial liquid biopsy timepoints for treatment response assessment and early relapse detection.
- Python:
pandas+matplotlibfor trend analysis and molecular response classification
Track ctDNA dynamics over treatment for response assessment and relapse detection.
Key Metrics
| Metric | Description | Clinical Relevance |
|---|---|---|
| Tumor fraction trend | Change over time | Response/progression |
| Mutation clearance | Time to undetectable | Depth of response |
| Molecular relapse | ctDNA rise | Early relapse detection |
| Lead time | ctDNA vs imaging | Months before clinical |
Tracking Tumor Fraction
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def analyze_tf_dynamics(patient_data):
'''
Analyze tumor fraction dynamics over treatment.
Args:
patient_data: DataFrame with columns [sample_id, timepoint, tumor_fraction, treatment_phase]
'''
# Sort by timepoint
patient_data = patient_data.sort_values('timepoint')
# Calculate log2 fold changes
baseline_tf = patient_data.iloc[0]['tumor_fraction']
patient_data['log2_fc'] = np.log2(patient_data['tumor_fraction'] / baseline_tf)
# Calculate response metrics
min_tf = patient_data['tumor_fraction'].min()
min_timepoint = patient_data.loc[patient_data['tumor_fraction'].idxmin(), 'timepoint']
metrics = {
'baseline_tf': baseline_tf,
'nadir_tf': min_tf,
'nadir_timepoint': min_timepoint,
'max_reduction': baseline_tf - min_tf,
'log2_max_reduction': np.log2(baseline_tf / min_tf) if min_tf > 0 else np.inf
}
return patient_data, metrics
def define_response(tf_series, baseline, criteria='2log'):
'''
Define molecular response based on tumor fraction changes.
Args:
tf_series: Series of tumor fractions
baseline: Baseline tumor fraction
criteria: Response criteria (e.g., '2log' for 2-log reduction)
'''
if criteria == '2log':
# 2-log (100-fold) reduction
threshold = baseline / 100
elif criteria == '1log':
threshold = baseline / 10
elif criteria == 'undetectable':
threshold = 0.001 # Assay-dependent LOD
response = tf_series < threshold
return response
