Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #89 from jeromekelleher/arg-diagram
Browse files Browse the repository at this point in the history
Arg diagram
  • Loading branch information
jeromekelleher authored Jul 26, 2021
2 parents 0b75eec + 9cce402 commit 523ce98
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 42 deletions.
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
DATA=data/arg.csv\
data/mutations_perf.csv

PERF_FIGURES=figures/mutations-perf.pdf\
FIGURES=figures/mutations-perf.pdf\
figures/arg.pdf\
figures/sweeps-perf.pdf\
figures/gc-perf.pdf\
figures/dtwf-perf.pdf

FIGURES=$(PERF_FIGURES)\
figures/mutated_tree.pdf\
figures/unmutated_tree.pdf\
figures/example_tree_sequence.pdf
ILLUSTRATIONS=\
illustrations/mutated_tree.pdf\
illustrations/unmutated_tree.pdf\
illustrations/arg-ts.pdf\
illustrations/arg-ts-simplified.pdf\
illustrations/example_tree_sequence.pdf

paper.pdf: paper.tex paper.bib ${DATA} ${FIGURES}
paper.pdf: paper.tex paper.bib ${DATA} ${FIGURES} ${ILLUSTRATIONS}
pdflatex paper.tex
bibtex paper
pdflatex paper.tex
pdflatex paper.tex

$(PERF_FIGURES):
figures/%.pdf:
python3 evaluation/plot.py $*

figures/mutated_tree.svg figures/unmutated_tree.svg : pretty_pictures.py
python3 $<
illustrations/mutated_tree.svg illustrations/unmutated_tree.svg : pretty_pictures.py
python3 $< mutated-tree

illustrations/arg-ts.svg: pretty_pictures.py
python3 $< arg-ts

%.pdf : %.svg
inkscape $< --export-pdf=$@
chromium --headless --no-margins --print-to-pdf=$@ $<
# inkscape $< --export-pdf=$@

%.pdf : %.ink.svg
inkscape $< --export-pdf=$@
Expand Down
2 changes: 2 additions & 0 deletions illustrations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
60 changes: 51 additions & 9 deletions paper.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
\usepackage{environ}%
\usepackage[right]{lineno}%
\usepackage{nameref}
\usepackage{tikz}
%\usepackage{showkeys}

% local definitions
Expand All @@ -28,7 +29,8 @@
\newcommand{\phastsim}[0]{\texttt{phastsim}}

\newcommand{\jkcomment}[1]{\textcolor{red}{#1}}
\newcommand{\plrcomment}[1]{\textcolor{purple}{#1}}
% @plr - purple doesn't exist in my Latex
\newcommand{\plrcomment}[1]{\textcolor{blue}{#1}}

\begin{document}

Expand Down Expand Up @@ -191,7 +193,7 @@ \subsection*{Tree sequences}

\begin{figure}
\begin{center}
\includegraphics[width=6cm]{figures/example_tree_sequence}
\includegraphics[width=6cm]{illustrations/example_tree_sequence}
\end{center}
\caption{\label{fig-ts-example} Example tree sequence.
An example tree sequence describing genealogies and genotypes
Expand Down Expand Up @@ -341,7 +343,7 @@ \subsection*{Genetic variation}
% Mutations are not treated as first-class data --- the sequences
% were really all people were after, classically.
However, joint information about the mutations that have been simulated
-- e.g., where they have occurred on the trees --
-- e.g., where they have occurred on the trees --
is usually not retained or made available for subsequent analysis.

The approach taken in \msprime\ is quite different.
Expand Down Expand Up @@ -421,8 +423,8 @@ \subsection*{Simulating mutations}
virgoulay2021gspace}.

\begin{figure}
\includegraphics{figures/unmutated_tree}
\includegraphics{figures/mutated_tree}
\includegraphics{illustrations/unmutated_tree}
\includegraphics{illustrations/mutated_tree}
\caption{
\label{fig-mutated-trees}
Visualization of the separation between ancestry and mutation simulation:
Expand Down Expand Up @@ -858,12 +860,52 @@ \subsection*{Ancestral Recombination Graphs}
have fully coalesced (like Hudson's algorithm).

\begin{figure}

\begin{center}
\includegraphics[width=7cm]{figures/arg}
\begin{tikzpicture}[scale=0.45]

\draw (-2,0) -- (-2,3) -- (0, 3);
\draw (1,0) -- (1,1);
\draw (0,1) -- (2,1) -- (2,2) -- (4,2) -- (4,0);
\draw (3,2) -- (3,5);
\draw (0,1) -- (0,3);
\draw (-1, 3) -- (-1, 5) -- (3,5);

\draw[fill] (-2,0) circle [radius=0.05];
\draw[fill] (-1,3) circle [radius=0.05];
\draw[fill] (1,0) circle [radius=0.05];
\draw[fill] (4,0) circle [radius=0.05];
\draw[fill] (1,1) circle [radius=0.05];
\draw[fill] (3,2) circle [radius=0.05];
\draw[fill] (1,5) circle [radius=0.05];

\node [below] at (-2,0) {0};
\node [below] at (1,0) {1};
\node [below] at (4,0) {2};
\node [above] at (1,1) {3};
\node [below right] at (1,1) {$x = 0.3$};
\node [above right] at (3,2) {4};
\node [above left] at (-1,3) {5};
\node [above] at (1,5) {6};

\end{tikzpicture}
% \begin{center}
% $\equiv$
% \end{center}
% \end{column}
% \begin{column}{5cm}
\includegraphics[width=3.8cm]{illustrations/arg-ts.pdf}
\includegraphics[width=3.8cm]{illustrations/arg-ts-simplified.pdf}
\includegraphics[width=3.8cm]{figures/arg.pdf}

\end{center}
\caption{\label{fig-arg} A figure illustrating the relative size of
the full ARG representation compared the minimal tree sequence.
\jkcomment{This figure is quite preliminary and we need to improve it.}}
\caption{\label{fig-arg} (A) An simple ARG in which a recombination
occurs at position 0.3; (B) the equivalent topology depicted as a tree
sequence, including the recombination node; (C) the same tree sequence
topology ``simplified'' down to its minimal tree sequence representation;
(D) the fraction of nodes in a tree sequence that are concerned with
extra ARG information in a tree sequences returned using \msprime's
\texttt{record\_full\_arg} mode}
\end{figure}

However, this original definition of the ARG in terms of a stochastic process
Expand Down
105 changes: 82 additions & 23 deletions pretty_pictures.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,99 @@
#!/usr/bin/env python

import click
import tskit
import msprime


## Adding mutations
#
# The goal here is to make a figure with (a) a tree and (b) some mutations added to it.


ts = msprime.sim_ancestry(
@click.command()
def mutated_tree():
"""
Make a figure with (a) a tree and (b) some mutations added to it.
"""
ts = msprime.sim_ancestry(
50,
population_size=1e4,
recombination_rate=0.5e-8,
sequence_length=1000,
random_seed=14
)
random_seed=14,
)

model = msprime.F84(kappa=2)
mts = msprime.sim_mutations(ts, rate=5e-8, model=model, random_seed=5)

model = msprime.F84(kappa=2)
mts = msprime.sim_mutations(
ts,
rate=5e-8,
model=model,
random_seed=5
)

def do_svg(ts, **kwargs):

def do_svg(ts, **kwargs):
ts.draw_svg(
size=(300,200),
# Sizes are probably all wrong here
style = """\
@media print {
@page { margin: 0; size: 3in 2in}
body { margin: 1.6cm; }
}
"""
ts.draw_svg(
size=(300, 200),
node_labels={},
mutation_labels={m.id: m.derived_state for m in ts.mutations()},
symbol_size=5,
force_root_branch=True,
style=style,
**kwargs
)
)


do_svg(ts, path="illustrations/unmutated_tree.svg")
do_svg(mts, path="illustrations/mutated_tree.svg")


@click.command()
def arg_ts():
tables = tskit.TableCollection(1.0)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
tables.nodes.add_row(flags=msprime.NODE_IS_RE_EVENT, time=0.5)
# tables.nodes.add_row(flags=msprime.NODE_IS_RE_EVENT, time=0.5)
tables.nodes.add_row(flags=0, time=1.0)
tables.nodes.add_row(flags=0, time=1.5)
tables.nodes.add_row(flags=0, time=2.0)

tables.edges.add_row(0, 1, 5, 0)
tables.edges.add_row(0, 1, 3, 1)
tables.edges.add_row(0.0, 0.3, 5, 3)
tables.edges.add_row(0.3, 1, 4, 3)
tables.edges.add_row(0, 1, 4, 2)
tables.edges.add_row(0, 1, 6, 5)
tables.edges.add_row(0, 1, 6, 4)

tables.sort()
print(tables)
ts = tables.tree_sequence()

# https://stackoverflow.com/questions/46077392/additional-options-in-chrome-headless-print-to-pdf
# Sizes are probably all wrong here
style = """\
@media print {
@page { margin: 0; size: 4in 3in}
body { margin: 1.6cm; }
}
"""
svgfile = "illustrations/arg-ts.svg"
ts.draw_svg(svgfile, size=(400, 300), style=style)

print(ts.draw_text())

ts = ts.simplify()
svgfile = "illustrations/arg-ts-simplified.svg"
ts.draw_svg(svgfile, size=(400, 300), style=style)
print(ts.draw_text())


@click.group()
def cli():
pass


do_svg(ts, path="figures/unmutated_tree.svg")
do_svg(mts, path="figures/mutated_tree.svg")
cli.add_command(mutated_tree)
cli.add_command(arg_ts)

if __name__ == "__main__":
cli()

0 comments on commit 523ce98

Please sign in to comment.