Skip to content

fix: write molecular_clock.txt in clock command - #575

Merged
ivan-aksamentov merged 2 commits into
masterfrom
fix/clock-rate-file
Apr 15, 2026
Merged

fix: write molecular_clock.txt in clock command#575
ivan-aksamentov merged 2 commits into
masterfrom
fix/clock-rate-file

Conversation

@ivan-aksamentov

Copy link
Copy Markdown
Member

fix: write molecular_clock.txt in clock command

The treetime clock command prints the rate estimate to stdout but never saves it to a file, despite the documentation listing "a text-file with the rate estimate" among the output files. The timetree command already writes this file via inline code.

Extract a shared save_molecular_clock() helper [src] that writes molecular_clock.txt and prints a confirmation message. Use it in both estimate_clock_model() [src] and run_timetree() [src], replacing the duplicated inline file-writing code.

The run_timetree print message for molecular_clock.txt incorrectly said "Inferred sequence evolution model" -- a copy-paste from the GTR block directly above it. The shared helper now prints a consistent --- molecular clock model (saved as ...) message for both commands.

Verification

Before (clock command produces no molecular_clock.txt):

$ treetime clock --tree data/h3n2_na/h3n2_na_20.nwk --dates data/h3n2_na/h3n2_na_20.metadata.csv --sequence-len 1400 --outdir clock_results
$ ls clock_results/
outliers.tsv  rerooted.newick  root_to_tip_regression.pdf  rtt.csv

After:

$ treetime clock --tree data/h3n2_na/h3n2_na_20.nwk --dates data/h3n2_na/h3n2_na_20.metadata.csv --sequence-len 1400 --outdir clock_results
--- molecular clock model (saved as clock_results/molecular_clock.txt):

Root-Tip-Regression:
 --rate:	2.826e-03
 --r^2:  	0.98
$ ls clock_results/
molecular_clock.txt  outliers.tsv  rerooted.newick  root_to_tip_regression.pdf  rtt.csv
$ cat clock_results/molecular_clock.txt
Root-Tip-Regression:
 --rate:	2.826e-03
 --r^2:  	0.98

Work items

  • Add molecular_clock.txt output to estimate_clock_model()
  • Extract shared save_molecular_clock() helper to deduplicate file-writing between clock and timetree
  • Fix copy-paste "Inferred sequence evolution model" message in run_timetree() for the molecular clock file

Possible improvements

  • Align print style for sequence_evolution_model.txt saves in run_timetree [src] and ancestral_reconstruction [src] to use --- prefix (both use '\nInferred ...' while all other file-save messages use '--- ...')

The clock command printed the rate estimate to stdout but never saved it to a file, unlike the timetree command which writes molecular_clock.txt. Add the same file output to estimate_clock_model() and extract shared save_molecular_clock() helper used by both commands.

Closes #574
The print message for the molecular clock file incorrectly said "Inferred sequence evolution model" -- a copy-paste from the GTR block above. Fix to say "Inferred molecular clock model".
@ivan-aksamentov
ivan-aksamentov merged commit c78edd1 into master Apr 15, 2026
8 checks passed
@ivan-aksamentov
ivan-aksamentov deleted the fix/clock-rate-file branch April 15, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clock does not create a text-file with the rate estimate

1 participant