You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Significant TMRCA discrepancy between tsdate and Relate on 1KGP YRI (Chr 22) #507
I am currently using tsinfer + tsdate to reconstruct ARGs and estimate coalescence times. I recently ran this pipeline on Chromosome 22 of the Yoruba (YRI) samples from the 1000 Genomes Project and compared the results with those inferred by Relate.
I noticed a substantial discrepancy in the TMRCA estimates for local trees between the two methods. Specifically, tsdate produces significantly older estimates compared to Relate, especially in the deep past.
Observations
Here is the distribution of TMRCAs across Chromosome 22:
tsdate:
Median TMRCA: ~2.57 million years (assuming 25 years/gen)
Max TMRCA: ~40 million years
Relate:
Median TMRCA: ~1.46 million years (assuming 25 years/gen)
Max TMRCA: ~15 million years
As shown, the maximum TMRCA inferred by tsdate reaches ~40 MYA, whereas Relate caps around ~15 MYA. The median age is also nearly double in tsdate.
Parameters & Reproducibility
I used the following parameters:
tsinfer:
mismatch_ratio: 1
recombination_rate: 1.25e-8
tsdate:
mutation_rate: 1.25e-8
Ne (Effective Population Size): I didn't specify Ne in this pipeline.
Questions:
Is such a large discrepancy expected for African populations which have deep coalescence times?
Could this be related to the prior $N_e$ used in tsdate? If I haven't specified a demographic history, would the default prior cause this overestimation in deep time?
Any insights or suggestions on how to align these estimates would be greatly appreciated.
Following your suggestion, I set both the mismatch_ratio and recombination_rate to None in tsinfer and reran the pipeline. However, the results remain largely unchanged from the initial run (where the mismatch ratio was 1). The local trees are still showing very deep coalescence times, with a median TMRCA of approximately 2.60 million years (assuming 25 years/gen):
I also compared the tree heights between tsinfer and tsdate. I noticed that the raw tree heights produced by tsinfer are almost exclusively clustered around 1, as shown below (the height_infer column):
Here is the scatter plot comparing the two:
Is this distribution of tsinfer tree heights (clustering at 1) expected behavior? I wanted to confirm if this looks correct to you.
Hmm, how are you getting the tree heights? The height of the tree might not be the height of the oldest MRCA: the oldest node could be older than that. E.g. in the tree below, the oldest node is a little greater than 1, but the oldest MRCA is at freq 0.67
If you want the MRCA times then you need to remove nodes above the local roots, e.g. by calling simplify() first.
The tsinfer times for nodes or mutations should simply be the frequency of each of the alleles used for inference. What happens if you compare the histogram of tsinfer node times with e.g. the histogram of allele frequencies?
frommatplotlibimportpyplotasplt# Just the nodesplt.hist(inferred_ts.nodes_time)
# The mutation freqstables=inferred_ts.dump_tables()
tables.compute_mutation_times()
plt.hist(tables.tree_sequence().mutations_time, label="mutation times (equivalent to freqs)")
# Could also use the AFSplt.plot(np.arange(inferred_ts.num_samples+1) /inferred_ts.num_samples, inferred_ts.allele_frequency_spectrum(), label="AFS")
# assuming you are using the variant_data format:freqs= [np.mean(v.genotypes!=a) forv, ainzip(vdata.variants(), vdata.sites_ancestral_allele)]
plt.hist(freqs, label="Derived freqs")
I assume that you have called tsdate.preprocess_ts(...) on the output from tsinfer?
here is the codes that I used to extract tree height:
def create_tree_height_df(tree_seq):
data = []
for tree in tree_seq.trees():
if tree.num_roots > 0:
height = max(tree.time(root) for root in tree.roots)
else:
height = 0
data.append({
'tree_index': tree.index,
'tree_height': height
})
tree_height_df = pd.DataFrame(data)
return tree_height_df
I didn't call ts.simplify() in previous version. When I added ts.simplify() and then extracted the tree height, the plot is as below with log10 TMRCA Correlation (Pearson) of 0.2462:
I also plotted the frequency using the codes modified from the codes you provided:
It seems the times between tsinfer and tsdate are well correlated.
Besides, I used 25 years per generation for convenience, although it's more common to use 29 years per generation.
Pipeline of tsinfer + tsdate
I do called tsdate.preprocess_ts(...) on the output from tsinfer in tsdate.
Here is the pipeline that I used to run tsinfer:
def main():
args = get_args()
vcz_path = args.vcz_path
recombination_rate = args.recombination_rate
mismatch_ratio = args.mismatch_ratio
threads = args.threads
out_file = args.out_file # with .trees suffix or .tree.tsz
check_files(vcz_path)
print(f'vcf_path is {vcz_path}')
print(f'recombination_rate is {recombination_rate}')
print(f'mismatch_ratio is {mismatch_ratio}')
print(f'threads is {threads}')
print(f'out_file is {out_file}')
print(f'Loading vcz file: {vcz_path}')
vdata = tsinfer.VariantData(vcz_path, ancestral_state="ancestral_state", individuals_population="individuals_population")
if recombination_rate is None:
mismatch_ratio = None
print("Recombination rate is None, so mismatch ratio will be set to None as well.")
print(f'Running inference with mismatch ratio: {mismatch_ratio}, recombination rate: {recombination_rate}, threads: {threads}')
inferred_ts = tsinfer.infer(
vdata,
recombination_rate=recombination_rate,
mismatch_ratio=mismatch_ratio,
num_threads=threads
)
print(f'Saving inferred tree sequence to file: {out_file}')
if out_file.endswith('.tsz'):
tszip.compress(inferred_ts, out_file)
else:
inferred_ts.dump(out_file)
print(f'Output file is {out_file}')
print("Program is done")
and tsdate:
def main():
args = get_args()
ts_file = args.ts_file
mutation_rate = args.mutation_rate
out_file = args.out_file
check_files(ts_file)
print(f'ts file: {ts_file}')
print(f'mutation rate: {mutation_rate}')
print(f'output file: {out_file}')
print(f"Load tree sequence from {ts_file}")
ts = tszip.load(ts_file)
print(f"Original: {ts.num_nodes} nodes, {ts.num_mutations} mutations")
print("Simplifying the tree sequence")
ts_clean = ts.simplify(filter_populations=False)
print(f"Simplified: {ts_clean.num_nodes} nodes, {ts_clean.num_mutations} mutations")
## preprocess ts
print("Preprocessing the tree sequence")
simplified_ts = tsdate.preprocess_ts(
ts_clean,
remove_telomeres=True
)
## infer the time
print("Infering the time")
dated_ts = tsdate.date(simplified_ts,
mutation_rate=mutation_rate)
print("Restoring population metadata...")
tables = dated_ts.dump_tables()
# 检查 ts_clean 中是否有种群信息
if len(ts_clean.tables.populations) > 0:
# 直接用 ts_clean 的种群表替换 dated_ts 的种群表
# 因为 simplify(filter_populations=False) 保证了索引没乱
tables.populations.replace_with(ts_clean.tables.populations)
# since the metadata_schema is JSON in the tree outputed by tsinfer, we need to set it to None here which will use bytes string
tables.populations.metadata_schema = tskit.MetadataSchema(None)
# 重新构建最终的 TreeSequence
final_ts = tables.tree_sequence()
print(f"Restored metadata for {len(final_ts.tables.populations)} populations.")
else:
print("Warning: No population metadata found in input.")
final_ts = dated_ts
if out_file.endswith(".tsz"):
print(f"Save the dated tree sequence to {out_file}")
tszip.compress(final_ts, out_file)
else:
print(f"Save the dated tree sequence to {out_file}")
final_ts.dump(out_file)
print("Program is done")
print(f'Dated tree sequence saved to {out_file}')
Thanks for pointing this out! Estimating the allele age of ancient variants is particularly challenging, so allele age estimation methods can provide inconsistent results in that case. For tsinfer+tsdate, we discussed this limitation in a recently released preprint. From the discussion:
"
Recent ancestry is often tightly constrained by long shared haplotypes, providing strong
information for dating, whereas deeper genealogical structure is more weakly informed by the
data. As a consequence, absolute ages in the deep past are sensitive to timescale calibration and
to the regularisation required to stabilise root ages, and should be interpreted with appropriate
caution.
"
You can see the discordance between methods in the pairwise comparison of allele ages across five methods in the paper (Figure S10). Age estimates can disagree by several orders of magnitude in some cases. For Relate, I obtained the allele ages used in the plot by doing a weighted average of population-specific estimates. In the relevant subplot (copied below - bottom axis is for tsinfer+tsdate) you can see that tsinfer+tsdate estimates seem to be older than those of Relate on average. Despite this, tsinfer+tsdate and Relate have the highest correlation of any pair of methods!
The comparison above was based only on sites that were present in all five method datasets, which included SINGER estimates for YRI individuals only. Thus, the comparison between tsinfer+tsdate and Relate would look a bit different if it was done with all sites covered by these methods only, but it would still have many discordant outliers.
it would be an interesting project to use a different method, such as PSMC (or better, PHLASH or GammaSMC) to estimate the deepest divergence dates between any pair of samples, and compare that to the expected values from e.g. Relate or tsinfer+tsdate. @Jesson-mark : if you manage to do this, and get any useful results, please do post them here.
@Duncan-JR, thank you so much for the detailed explanation and for pointing me to the preprint and Figure S10.
The distinction regarding the constraints on recent vs. deep ancestry really clarifies why the absolute estimates can vary so much. It is reassuring to know that despite the offset in absolute ages, the correlation between tsinfer+tsdate and Relate remains the highest among the methods. This gives me more confidence in using these tools for relative comparisons. Thanks again for your help!
@hyanwong, that sounds like a fascinating project! Comparing the deep divergence dates against methods like PSMC or GammaSMC would indeed provide a valuable benchmark.
I’m definitely interested in trying this out. I’ll add this to my to-do list and look into it when I have some spare time. I will certainly post an update here if I manage to get some useful results.
@Duncan-JR, thank you so much for the detailed explanation and for pointing me to the preprint and Figure S10.
The distinction regarding the constraints on recent vs. deep ancestry really clarifies why the absolute estimates can vary so much. It is reassuring to know that despite the offset in absolute ages, the correlation between tsinfer+tsdate and Relate remains the highest among the methods. This gives me more confidence in using these tools for relative comparisons. Thanks again for your help!
@hyanwong, that sounds like a fascinating project! Comparing the deep divergence dates against methods like PSMC or GammaSMC would indeed provide a valuable benchmark.
I’m definitely interested in trying this out. I’ll add this to my to-do list and look into it when I have some spare time. I will certainly post an update here if I manage to get some useful results.
Thanks, Jie Wang: keep us posted! I'm converting this to a discussion, so feel free to post here again if you have any follow-ups.
Activity
hyanwong commentedon Mar 13, 2026
Out of interest, what if you don't specify the recombination rate in tsinfer (or set the mismatch ratio to 0, which is the same thing?)
What is the correlation between log(tsdate) and log(tsinfer) time in both cases?
Jesson-mark commentedon Mar 13, 2026
Hi Yan,
Thanks for the reply!
Following your suggestion, I set both the mismatch_ratio and recombination_rate to None in tsinfer and reran the pipeline. However, the results remain largely unchanged from the initial run (where the mismatch ratio was 1). The local trees are still showing very deep coalescence times, with a median TMRCA of approximately 2.60 million years (assuming 25 years/gen):
I also compared the tree heights between tsinfer and tsdate. I noticed that the raw tree heights produced by tsinfer are almost exclusively clustered around 1, as shown below (the
height_infercolumn):Here is the scatter plot comparing the two:
Is this distribution of tsinfer tree heights (clustering at 1) expected behavior? I wanted to confirm if this looks correct to you.
Best,
Jie
hyanwong commentedon Mar 13, 2026
Hmm, how are you getting the tree heights? The height of the tree might not be the height of the oldest MRCA: the oldest node could be older than that. E.g. in the tree below, the oldest node is a little greater than 1, but the oldest MRCA is at freq 0.67
If you want the MRCA times then you need to remove nodes above the local roots, e.g. by calling
simplify()first.The tsinfer times for nodes or mutations should simply be the frequency of each of the alleles used for inference. What happens if you compare the histogram of tsinfer node times with e.g. the histogram of allele frequencies?
I assume that you have called
tsdate.preprocess_ts(...)on the output from tsinfer?hyanwong commentedon Mar 13, 2026
BTW, I think it's standard to use 27 or 29 years per generation in humans nowadays?
hyanwong commentedon Mar 13, 2026
(also, could you show some log-time plots of tsdate vs tsinfer ages for the mutations?)
Jesson-mark commentedon Mar 14, 2026
Hi Yan,
here is the codes that I used to extract tree height:
I didn't call
ts.simplify()in previous version. When I addedts.simplify()and then extracted the tree height, the plot is as below with log10 TMRCA Correlation (Pearson) of 0.2462:I also plotted the frequency using the codes modified from the codes you provided:
the plot:
Besides, I also plotted the log-time of tsdate vs tsinfer ages for the mutations, with codes below:
the plot:
It seems the times between tsinfer and tsdate are well correlated.
Besides, I used 25 years per generation for convenience, although it's more common to use 29 years per generation.
Pipeline of tsinfer + tsdate
I do called
tsdate.preprocess_ts(...)on the output from tsinfer in tsdate.Here is the pipeline that I used to run
tsinfer:and
tsdate:Duncan-JR commentedon Mar 16, 2026
Thanks for pointing this out! Estimating the allele age of ancient variants is particularly challenging, so allele age estimation methods can provide inconsistent results in that case. For
tsinfer+tsdate, we discussed this limitation in a recently released preprint. From the discussion:"
Recent ancestry is often tightly constrained by long shared haplotypes, providing strong
information for dating, whereas deeper genealogical structure is more weakly informed by the
data. As a consequence, absolute ages in the deep past are sensitive to timescale calibration and
to the regularisation required to stabilise root ages, and should be interpreted with appropriate
caution.
"
You can see the discordance between methods in the pairwise comparison of allele ages across five methods in the paper (Figure S10). Age estimates can disagree by several orders of magnitude in some cases. For Relate, I obtained the allele ages used in the plot by doing a weighted average of population-specific estimates. In the relevant subplot (copied below - bottom axis is for tsinfer+tsdate) you can see that
tsinfer+tsdateestimates seem to be older than those of Relate on average. Despite this,tsinfer+tsdateand Relate have the highest correlation of any pair of methods!The comparison above was based only on sites that were present in all five method datasets, which included SINGER estimates for YRI individuals only. Thus, the comparison between
tsinfer+tsdateand Relate would look a bit different if it was done with all sites covered by these methods only, but it would still have many discordant outliers.hyanwong commentedon Mar 16, 2026
it would be an interesting project to use a different method, such as PSMC (or better, PHLASH or GammaSMC) to estimate the deepest divergence dates between any pair of samples, and compare that to the expected values from e.g. Relate or tsinfer+tsdate. @Jesson-mark : if you manage to do this, and get any useful results, please do post them here.
Jesson-mark commentedon Mar 17, 2026
@Duncan-JR, thank you so much for the detailed explanation and for pointing me to the preprint and Figure S10.
The distinction regarding the constraints on recent vs. deep ancestry really clarifies why the absolute estimates can vary so much. It is reassuring to know that despite the offset in absolute ages, the correlation between tsinfer+tsdate and Relate remains the highest among the methods. This gives me more confidence in using these tools for relative comparisons. Thanks again for your help!
@hyanwong, that sounds like a fascinating project! Comparing the deep divergence dates against methods like PSMC or GammaSMC would indeed provide a valuable benchmark.
I’m definitely interested in trying this out. I’ll add this to my to-do list and look into it when I have some spare time. I will certainly post an update here if I manage to get some useful results.
Duncan-JR commentedon Mar 17, 2026
Thanks, Jie Wang: keep us posted! I'm converting this to a discussion, so feel free to post here again if you have any follow-ups.