Skip to content

Add comprehensive growth rate analysis and scoring script #8

Description

@zorian15

Growth Rate Analysis Script Plan with Data Export

Overview

Create scripts/score_growth_rates.py to evaluate growth rate predictions and export detailed data.

Script Structure & Outputs

1. Core Script: scripts/score_growth_rates.py

python scripts/score_growth_rates.py \
  --config configs/growth_rate_config.yaml \
  --build flu-simulated-150k-samples \
  --output-dir results/flu-simulated-150k-samples/growth_rate_analysis/

2. Output Structure:

results/{build}/growth_rate_analysis/
├── scores/
│   ├── growth_rate_scores.tsv          # Window-level metrics
│   └── variant_growth_rate_scores.tsv  # Variant-level metrics
└── growth_rates/
    ├── FGA/
    │   ├── growth_rates_north_2026-10-01.tsv
    │   ├── growth_rates_tropics_2026-10-01.tsv
    │   └── ...
    └── GARW/
        ├── growth_rates_north_2026-10-01.tsv
        └── ...

3. Growth Rate Data Files Content:

Each growth_rates_{location}_{pivot_date}.tsv contains:

  • date, variant: Identifiers
  • r_data, r_model: Core growth rate values
  • median_r, r_lower_95, r_upper_95: Model estimates with CIs
  • smoothed_frequency, raw_frequency: Variant frequencies
  • smoothed_sequences, raw_sequences: Sequence counts
  • case_counts, total_case_counts: Case data
  • filtered: Boolean indicating if point passed filtering criteria

4. Key Functions:

def export_growth_rates_data(growth_rates_df, output_dir, model, location, pivot_date):
    # Save processed growth rates data to TSV files
    # Follows same naming convention as existing results/*/estimates/
    
def calculate_comprehensive_metrics(growth_rates_df):
    # Window-level and variant-level metrics using existing antigentools functions
    
def process_all_model_results(config):
    # Discover all rt_*.tsv files, process each window
    # Export both metrics and raw growth rate data

5. Configuration File: configs/growth_rate_config.yaml

models: ["FGA", "GARW"]
locations: ["north", "tropics", "south"]
filtering:
  min_sequence_count: 10
  min_variant_frequency: 0.01  
  min_total_sequences: 300
  epsilon: 1e-3
  min_segment_length: 3
spline_smoothing:
  factor: 1.0
  order: 3
export_options:
  save_growth_rates: true
  save_filtered_only: false  # Include all data points

6. Integration Benefits:

  • Data export enables detailed downstream analysis
  • Consistent format matches existing results structure
  • Preserves provenance - all intermediate calculations saved
  • Reproducible pipeline from raw model outputs to final metrics
  • Easy visualization - growth rate files can be directly plotted

7. Usage in Analysis:

# Load exported growth rate data for specific window
gr_df = pd.read_csv("results/.../growth_rates/FGA/growth_rates_tropics_2028-10-01.tsv", sep="\t")

# Plot using existing functions
plot_growth_rate_dynamics(gr_df, location="tropics", ...)

This creates a comprehensive growth rate evaluation pipeline that both scores model performance AND preserves all the detailed data needed for publication figures and deep-dive analysis.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions