# Paper Experiment Scripts This directory is a complete command plan for producing the data needed by the paper: > predictor-guided evaluation of autoregressive and masked-diffusion genomic > foundation models for controllable DeepSTARR enhancer generation. All scripts are written to use the shared environment file: ```bash source /Users/ouzhang/Desktop/genRL/project/scripts/00_setup/env.sh ``` By default, outputs are written to: ```text /Users/ouzhang/Desktop/genRL/project/paper_runs/ data/ models/ results/ figures/ ``` You can override locations before running: ```bash export RUN_ROOT=/path/to/paper_runs export DEEPSTARR_DIR=/path/to/DeepSTARR-enhancer-activity export GENERATOR_BASE_MODEL=/path/to/GENERATOR-eukaryote-1.2b-base export GENERANNO_BASE_MODEL=/path/to/GENERanno-eukaryote-0.5b-base ``` ## 0. Install Dependencies ```bash cd /Users/ouzhang/Desktop/genRL/project bash scripts/00_setup/install_requirements.sh ``` This installs the requirements from `GENERATOR/`, `GENERanno/`, and extra analysis packages: `datasets`, `huggingface_hub`, `pyarrow`, `scipy`, `scikit-learn`, `matplotlib`, `seaborn`, and `biopython`. ## 1. Download Data and Models Download DeepSTARR from HuggingFace and save `train/valid/test.parquet`: ```bash cd /Users/ouzhang/Desktop/genRL/project bash scripts/01_data/download_deepstarr.sh ``` Summarize the dataset splits for the paper's dataset table: ```bash bash scripts/01_data/summarize_deepstarr.sh ``` Prepare conditioned DeepSTARR splits using train-set activity quantiles: ```bash bash scripts/01_data/prepare_conditioned_deepstarr.sh ``` Create a GC-matched random DNA negative baseline: ```bash bash scripts/01_data/make_random_gc_baseline.sh ``` This creates: ```text ${CONDITIONED_DEEPSTARR_DIR}/train.parquet ${CONDITIONED_DEEPSTARR_DIR}/valid.parquet ${CONDITIONED_DEEPSTARR_DIR}/test.parquet ${CONDITIONED_DEEPSTARR_DIR}/conditioning_metadata.json ``` Optional: download fresh HuggingFace model snapshots: ```bash bash scripts/01_data/download_models.sh ``` If you already have local models, set: ```bash export GENERATOR_BASE_MODEL=/Users/ouzhang/Desktop/genRL/project/GENERATOR-eukaryote-1.2b-base export GENERANNO_BASE_MODEL=/Users/ouzhang/Desktop/genRL/project/models/GENERanno-eukaryote-0.5b-base ``` ## 2. Train Activity Predictor Train the DeepSTARR activity predictor: ```bash bash scripts/02_predictor/train_predictor.sh ``` Default output: ```text ${RESULT_ROOT}/deepstarr_regression/ ${RESULT_ROOT}/deepstarr_regression/best_model/ ${RESULT_ROOT}/deepstarr_regression/test_results.json ``` Plot predictor validation metrics: ```bash bash scripts/02_predictor/plot_predictor_validation.sh ``` Expected paper metrics: - Pearson for `label_0`, `label_1`, and overall. - R2 for `label_0`, `label_1`, and overall. - MAE/MSE for predictor reliability. This predictor is the oracle used to score all generated enhancer sequences. ## 3. Train Autoregressive GENERator Baselines Train unconditional AR SFT: ```bash bash scripts/03_ar_generation/train_ar_unconditional.sh ``` Train bucket-conditioned AR SFT: ```bash bash scripts/03_ar_generation/train_ar_conditioned.sh ``` The conditioned model uses: ```text = low activity = mid activity = high activity ``` Generated model paths: ```text ${AR_UNCOND_MODEL} ${AR_COND_MODEL} ``` ## 4. Evaluate AR Generation Evaluate unconditional AR generation: ```bash bash scripts/03_ar_generation/evaluate_ar_unconditional.sh ``` Evaluate conditioned AR generation: ```bash bash scripts/03_ar_generation/evaluate_ar_conditioned.sh ``` Outputs: ```text ${RESULT_ROOT}/ar_unconditional_valid/generation_details.jsonl ${RESULT_ROOT}/ar_unconditional_valid/generation_summary.json ${RESULT_ROOT}/ar_conditioned_valid/generation_details.jsonl ${RESULT_ROOT}/ar_conditioned_valid/generation_summary.json ``` These files provide sequence validity, uniqueness, bp accuracy, and generated sequence details. ## 5. Score AR Samples with the Predictor Score unconditional AR samples: ```bash bash scripts/05_scoring/score_ar_unconditional.sh ``` Score conditioned AR samples: ```bash bash scripts/05_scoring/score_ar_conditioned.sh ``` Outputs: ```text ${RESULT_ROOT}/ar_unconditional_scoring/scoring_details.jsonl ${RESULT_ROOT}/ar_unconditional_scoring/scoring_summary.json ${RESULT_ROOT}/ar_conditioned_scoring/scoring_details.jsonl ${RESULT_ROOT}/ar_conditioned_scoring/scoring_summary.json ``` These are required for controllability analysis: - predicted `label_0` - predicted `label_1` - predicted activity sum - delta vs matched reference - positive-delta rate - bucket-level high/mid/low separation ## 6. Train Masked Discrete Diffusion Train the bucket-conditioned discrete diffusion model: ```bash bash scripts/04_diffusion/train_diffusion_conditioned.sh ``` Default output: ```text ${DIFFUSION_MODEL} ``` The diffusion training objective randomly masks A/C/G/T positions and trains a masked LM to recover the original bases. The condition token is prepended when `--conditioned` is enabled. ## 7. Evaluate Diffusion First, run PLL-only evaluation: ```bash bash scripts/04_diffusion/evaluate_diffusion_pll_only.sh ``` This measures diffusion pseudo-log-likelihood: ```text ${RESULT_ROOT}/diffusion_valid_pll/diffusion_scoring_details.jsonl ${RESULT_ROOT}/diffusion_valid_pll/diffusion_scoring_summary.json ``` Then run predictor-scored diffusion evaluation: ```bash bash scripts/04_diffusion/evaluate_diffusion_with_predictor.sh ``` This is mandatory for the final paper because PLL is not an activity score. The output is: ```text ${RESULT_ROOT}/diffusion_valid_predictor/diffusion_scoring_details.jsonl ${RESULT_ROOT}/diffusion_valid_predictor/diffusion_scoring_summary.json ``` Use this to compare diffusion against AR conditioned generation under the same predictor. ## 8. Compute Sequence Quality and Distribution Metrics Run: ```bash bash scripts/06_sequence_metrics/compute_sequence_metrics.sh ``` Outputs: ```text ${RESULT_ROOT}/sequence_metrics/sequence_metrics_rows.csv ${RESULT_ROOT}/sequence_metrics/sequence_metrics_summary.json ``` Metrics include: - valid DNA rate - unique rate - sequence length - GC content - max homopolymer length - pairwise Hamming distance - nearest-reference Hamming distance - 3-mer and 4-mer Jensen-Shannon divergence to reference - predictor score when available - diffusion PLL when available These metrics are the core data for the generator comparison table. ## 9. Optional Motif Analysis Download a JASPAR motif file manually, then set: ```bash export JASPAR_MOTIFS=/path/to/JASPAR2024_CORE_non-redundant_pfms_jaspar.txt ``` Run motif scan: ```bash bash scripts/07_motif_analysis/run_motif_scan.sh ``` Output: ```text ${RESULT_ROOT}/motif_analysis/motif_scan_summary.csv ``` Use this for motif enrichment and regulatory grammar figures. If no JASPAR file is available, skip this step and report motif analysis as a future extension. ## 10. Build Paper Figures Run: ```bash bash scripts/08_visualization/make_paper_figures.sh ``` Outputs: ```text ${FIGURE_ROOT}/paper/fig_generation_gc_content.png ${FIGURE_ROOT}/paper/fig_generation_homopolymer.png ${FIGURE_ROOT}/paper/fig_nearest_reference_distance.png ${FIGURE_ROOT}/paper/fig_predicted_activity_by_method.png ${FIGURE_ROOT}/paper/fig_activity_2d_scatter.png ${FIGURE_ROOT}/paper/fig_diffusion_pll.png ${FIGURE_ROOT}/paper/fig_generator_quality_summary.png ${FIGURE_ROOT}/paper/table_generator_comparison.csv ``` If motif analysis was run, it also creates: ```text ${FIGURE_ROOT}/paper/fig_motif_hit_rate_heatmap.png ``` ## 11. One-Command Runs Core paper experiments, excluding motif analysis: ```bash cd /Users/ouzhang/Desktop/genRL/project bash scripts/09_all/run_all_core.sh ``` Core experiments plus motif analysis: ```bash export JASPAR_MOTIFS=/path/to/JASPAR2024_CORE_non-redundant_pfms_jaspar.txt bash scripts/09_all/run_all_with_optional_motifs.sh ``` ## 12. Recommended Paper Tables and Figures ### Tables 1. Dataset split statistics: - from `${RESULT_ROOT}/data/deepstarr_split_summary.json` 2. Predictor performance: - from `${PREDICTOR_DIR}/test_results.json` 3. Generator comparison: - from `${RESULT_ROOT}/sequence_metrics/sequence_metrics_summary.json` - from `${FIGURE_ROOT}/paper/table_generator_comparison.csv` 4. Controllability by bucket: - AR: `${RESULT_ROOT}/ar_conditioned_scoring/scoring_summary.json` - diffusion: `${RESULT_ROOT}/diffusion_valid_predictor/diffusion_scoring_summary.json` - negative control: `${RESULT_ROOT}/controls/random_gc_matched.jsonl` ### Figures 1. Pipeline figure: - manually draw from data -> predictor -> AR/diffusion -> evaluation. 2. Predictor validation: - `${FIGURE_ROOT}/predictor/predictor_metrics.png` 3. Generation quality: - `${FIGURE_ROOT}/paper/fig_generation_gc_content.png` - `${FIGURE_ROOT}/paper/fig_generation_homopolymer.png` - `${FIGURE_ROOT}/paper/fig_nearest_reference_distance.png` 4. Controllability: - `${FIGURE_ROOT}/paper/fig_predicted_activity_by_method.png` - `${FIGURE_ROOT}/paper/fig_activity_2d_scatter.png` 5. Diffusion naturalness: - `${FIGURE_ROOT}/paper/fig_diffusion_pll.png` 6. Motif/regulatory grammar: - `${FIGURE_ROOT}/paper/fig_motif_hit_rate_heatmap.png` ## 13. Minimum Experiments Needed for a Defensible Paper Do not submit the paper until these are complete: 1. Predictor trained and tested. 2. AR unconditional generated and scored. 3. AR conditioned generated and scored. 4. Diffusion conditioned generated and scored with the same predictor. 5. Sequence quality metrics computed for all methods. 6. At least one negative/control baseline included: - reference sequences - random GC-matched sequences - shuffled enhancers - or unconditional generator The current project already has many pieces, but the most important missing piece is diffusion evaluation with `--predictor_model`. Without that, diffusion can only be discussed as naturalness/PLL analysis, not enhancer activity control. ## 14. Paper Strengthening Experiments After `01_data`, `02_predictor`, and the first conditioned diffusion model in `04_diffusion` are complete, run the extra experiments under: ```text scripts/10_paper_strengthening/ ``` These scripts are ordered by priority. ### P0: Minimum paper closure This finishes the core paper comparison: ```bash nohup bash scripts/10_paper_strengthening/p0_minimum_paper_closure.sh > p0_minimum_paper_closure.log 2>&1 & tail -f p0_minimum_paper_closure.log ``` It runs: - predictor validation plot - AR unconditional training/evaluation/scoring - AR conditioned training/evaluation/scoring - diffusion predictor evaluation - sequence metrics - paper figure generation ### P1: Core ablations Mask-ratio ablation: ```bash nohup bash scripts/10_paper_strengthening/p1_mask_ratio_ablation.sh > p1_mask_ratio_ablation.log 2>&1 & tail -f p1_mask_ratio_ablation.log ``` Conditioning ablation: ```bash nohup bash scripts/10_paper_strengthening/p1_conditioning_ablation.sh > p1_conditioning_ablation.log 2>&1 & tail -f p1_conditioning_ablation.log ``` These are the most important extra experiments for the mutation-budget claim: - lower mask ratios should preserve reference-like sequence structure - higher mask ratios should increase novelty and diversity - conditioned diffusion should show stronger low/mid/high activity separation than unconditioned diffusion ### P2: Test split and denoising step ablation Test split evaluation: ```bash nohup bash scripts/10_paper_strengthening/p2_test_split_diffusion.sh > p2_test_split_diffusion.log 2>&1 & tail -f p2_test_split_diffusion.log ``` Denoising step ablation: ```bash nohup bash scripts/10_paper_strengthening/p2_diffusion_steps_ablation.sh > p2_diffusion_steps_ablation.log 2>&1 & tail -f p2_diffusion_steps_ablation.log ``` Use this to report final held-out results and the quality/runtime trade-off for 16, 32, 64, and 128 denoising steps. ### P3: Seed robustness ```bash nohup bash scripts/10_paper_strengthening/p3_seed_repeats_diffusion.sh > p3_seed_repeats_diffusion.log 2>&1 & tail -f p3_seed_repeats_diffusion.log ``` Use the resulting summaries to report mean and standard deviation over seeds. ### P4: Paired refinement / evolutionary editing This is the key experiment for the "diffusion as refiner" claim. It compares the same input sequence before and after a small masked-diffusion edit: ```text delta = predictor(edited_sequence) - predictor(reference_sequence) ``` It covers: - paired delta distributions across `rho = 0.01, 0.03, 0.05, 0.10, 0.20` - random mask vs entropy-guided vs logit-gap-guided position selection - best-of-N refinement curves Recommended full run: ```bash PROJECT_ROOT=$(pwd) \ RUN_ROOT=$(pwd)/paper_runs \ DEEPSTARR_DIR=$(pwd)/datas/DeepSTARR-enhancer-activity \ GENERANNO_BASE_MODEL=$(pwd)/models/GENERanno-eukaryote-0.5b-base \ DIFFUSION_MODEL=$(pwd)/saved_model/deepstarr_discrete_diffusion \ PREDICTOR_MODEL=$(pwd)/paper_runs/results/deepstarr_regression/best_model \ REFINEMENT_SPLIT=test \ REFINEMENT_NUM_SEQUENCES=1024 \ REFINEMENT_NUM_SAMPLES=8 \ REFINEMENT_MASK_RATIOS="0.01 0.03 0.05 0.10 0.20" \ REFINEMENT_STRATEGIES="random entropy logit_gap" \ REFINEMENT_DIFFUSION_STEPS=32 \ REFINEMENT_BATCH_SIZE=16 \ PREDICTOR_SCORE_BATCH_SIZE=256 \ TRANSFORMERS_NO_TF=1 \ USE_TF=0 \ TOKENIZERS_PARALLELISM=false \ nohup bash scripts/11_refinement/run_paired_refinement.sh > paired_refinement.log 2>&1 & tail -f paired_refinement.log ``` Outputs are written to: ```text paper_runs/results/refinement/paired_refinement_test ``` ### Recommended server environment On the GPU server, set project-local data/model paths before these scripts: ```bash cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/genrl-enhancer-diffusion export PROJECT_ROOT=$(pwd) export RUN_ROOT=${PROJECT_ROOT}/paper_runs export HF_ENDPOINT=https://hf-mirror.com export TRANSFORMERS_NO_TF=1 export USE_TF=0 export TOKENIZERS_PARALLELISM=false source scripts/00_setup/env.sh export DEEPSTARR_DIR=${PROJECT_ROOT}/datas/DeepSTARR-enhancer-activity export DEEPSTARR_DATASET_ID=${DEEPSTARR_DIR} export GENERATOR_BASE_MODEL=${PROJECT_ROOT}/models/GENERator-eukaryote-1.2b-base export GENERANNO_BASE_MODEL=${PROJECT_ROOT}/models/GENERanno-eukaryote-0.5b-base export PREDICTOR_DIR=${PROJECT_ROOT}/paper_runs/results/deepstarr_regression export PREDICTOR_MODEL=${PREDICTOR_DIR}/best_model export DIFFUSION_MODEL=${PROJECT_ROOT}/saved_model/deepstarr_discrete_diffusion ```