Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

# Calculate tree heights, giving uncoalesced sites the maximum time
def tree_heights(ts):
uncoalesced_height = ts.metadata['SLiM']['tick']
heights = np.zeros(ts.num_trees + 1)
for tree in ts.trees():
if tree.num_roots > 1: # not fully coalesced
heights[tree.index] = uncoalesced_height
else:
children = tree.children(tree.root)
real_root = tree.root if len(children) > 1 else children[0]
heights[tree.index] = tree.time(real_root)
roots = tree.roots
if len(roots) == 1:
children = tree.children(roots[0])
if len(children) == 1:
roots = children
root_heights = [tree.time(r) for r in roots]
assert len(set(root_heights)) == 1
heights[tree.index] = root_heights[0]
heights[-1] = heights[-2] # repeat the last entry for plotting with step
return heights

# Plot tree heights before recapitation
breakpoints = list(ts.breakpoints())
heights = tree_heights(ts)
plt.step(breakpoints, heights, where='post')
plt.show()
plt.step(breakpoints, heights, where='post', label="SLiM")

# Recapitate!
recap = pyslim.recapitate(ts, ancestral_Ne=1e5, recombination_rate=3e-10, random_seed=1)
Expand All @@ -34,7 +34,9 @@ def tree_heights(ts):
# Plot the tree heights after recapitation
breakpoints = list(recap.breakpoints())
heights = tree_heights(recap)
plt.step(breakpoints, heights, where='post')
plt.show()
plt.step(breakpoints, heights, where='post', label="recapitated")
plt.xlabel("genome"); plt.ylabel("time ago (generations)")
plt.savefig("tree_heights.png")



Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

# Calculate tree heights, giving uncoalesced sites the maximum time
def tree_heights(ts):
uncoalesced_height = ts.metadata['SLiM']['tick']
heights = np.zeros(ts.num_trees + 1)
for tree in ts.trees():
if tree.num_roots > 1: # not fully coalesced
heights[tree.index] = uncoalesced_height
else:
children = tree.children(tree.root)
real_root = tree.root if len(children) > 1 else children[0]
heights[tree.index] = tree.time(real_root)
roots = tree.roots
if len(roots) == 1:
children = tree.children(roots[0])
if len(children) == 1:
roots = children
root_heights = [tree.time(r) for r in roots]
assert len(set(root_heights)) == 1
heights[tree.index] = root_heights[0]
heights[-1] = heights[-2] # repeat the last entry for plotting with step
return heights

# Plot tree heights before recapitation
breakpoints = list(ts.breakpoints())
heights = tree_heights(ts)
plt.step(breakpoints, heights, where='post')
plt.show()
plt.step(breakpoints, heights, where='post', label="SLiM")

# Recapitate!
recap = pyslim.recapitate(ts, ancestral_Ne=1e5, recombination_rate=3e-10, random_seed=1)
Expand All @@ -34,7 +34,9 @@ def tree_heights(ts):
# Plot the tree heights after recapitation
breakpoints = list(recap.breakpoints())
heights = tree_heights(recap)
plt.step(breakpoints, heights, where='post')
plt.show()
plt.step(breakpoints, heights, where='post', label="recapitated")
plt.xlabel("genome"); plt.ylabel("time ago (generations)")
plt.savefig("tree_heights.png")



Loading