<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Implementation · PhyloDiamond.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../index.html"><img src="../assets/logo.png" alt="PhyloDiamond.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../index.html">PhyloDiamond.jl</a></span></div><form class="docs-search" action="../search.html"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../index.html">Home</a></li><li><span class="tocitem">Manual</span><ul><li><a class="tocitem" href="installation.html">Installation</a></li><li class="is-active"><a class="tocitem" href="implementation.html">Implementation</a><ul class="internal"><li><a class="tocitem" href="#Main-Functions"><span>Main Functions</span></a></li><li><a class="tocitem" href="#Examples"><span>Examples</span></a></li><li><a class="tocitem" href="#Error-reporting"><span>Error reporting</span></a></li></ul></li></ul></li><li><span class="tocitem">Library</span><ul><li><a class="tocitem" href="../lib/public_methods.html">Public Methods</a></li></ul></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">Manual</a></li><li class="is-active"><a href="implementation.html">Implementation</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href="implementation.html">Implementation</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/solislemuslab/phylo-invariants/blob/master/docs/src/man/implementation.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Implementing-PhyloDiamond-Algorithm"><a class="docs-heading-anchor" href="#Implementing-PhyloDiamond-Algorithm">Implementing PhyloDiamond Algorithm</a><a id="Implementing-PhyloDiamond-Algorithm-1"></a><a class="docs-heading-anchor-permalink" href="#Implementing-PhyloDiamond-Algorithm" title="Permalink"></a></h1><h2 id="Main-Functions"><a class="docs-heading-anchor" href="#Main-Functions">Main Functions</a><a id="Main-Functions-1"></a><a class="docs-heading-anchor-permalink" href="#Main-Functions" title="Permalink"></a></h2><p>To infer a 4-node hybridization cycle, users can either input a concordance factor table or directly input a file of gene trees.</p><h3 id="Function-with-a-table-of-concordance-factors-as-input"><a class="docs-heading-anchor" href="#Function-with-a-table-of-concordance-factors-as-input">Function with a table of concordance factors as input</a><a id="Function-with-a-table-of-concordance-factors-as-input-1"></a><a class="docs-heading-anchor-permalink" href="#Function-with-a-table-of-concordance-factors-as-input" title="Permalink"></a></h3><p>The main function in the <code>PhyloDiamond.jl</code> package is:</p><pre><code class="language-julia hljs">phylo_diamond(cf::DataFrame, m::Int64, output_filename::String=&quot;phylo_diamond.txt&quot;)</code></pre><p>which has three main arguments:</p><ul><li><code>cf</code>: a DataFrame object containing concordance factor (CF) values for every 4-taxon subset in the data. Taxon names should appear in the first 4 columns and CF values in the last 3 columns<ul><li>Each row correspond to a taxon set <code>s={a,b,c,d}</code></li><li>There are only three possible quartet splits <code>q1=ab|cd, q2=ac|bd, q3=ad|bc</code></li><li>The dataframe should contain 7 columns, ordered as <code>a, b, c, d, q1, q2, q3</code></li></ul></li><li><code>m</code>: the number of optimal phylogenetic networks returned (we recommend <code>m=5</code> based on our simulations)</li><li><code>output_filename</code>: a file name for the output file (or &quot;phylo_diamond.txt&quot; by default)</li></ul><h3 id="Function-with-gene-trees-as-input"><a class="docs-heading-anchor" href="#Function-with-gene-trees-as-input">Function with gene trees as input</a><a id="Function-with-gene-trees-as-input-1"></a><a class="docs-heading-anchor-permalink" href="#Function-with-gene-trees-as-input" title="Permalink"></a></h3><p>Because of Julia&#39;s multiple dispatch, we have the same name of the function with a different type of input file:</p><pre><code class="language-julia hljs">phylo_diamond(gene_trees_filename::String, m::Int64, output_filename::String=&quot;phylo_diamond.txt&quot;)</code></pre><ul><li><code>gene_trees_filename</code>: the name of the textfile with all gene trees in parenthetical format (one gene tree per line)</li><li><code>m</code>: the number of optimal phylogenetic networks returned (we recommend <code>m=5</code> based on our simulations)</li><li><code>output_filename</code>: a file name for the output file (or &quot;phylo_diamond.txt&quot; by default)</li></ul><h2 id="Examples"><a class="docs-heading-anchor" href="#Examples">Examples</a><a id="Examples-1"></a><a class="docs-heading-anchor-permalink" href="#Examples" title="Permalink"></a></h2><p>First, we load the package:</p><pre><code class="language-julia hljs">using PhyloDiamond</code></pre><h3 id="Example-1:-A-concordance-factor-table-as-input"><a class="docs-heading-anchor" href="#Example-1:-A-concordance-factor-table-as-input">Example 1: A concordance factor table as input</a><a id="Example-1:-A-concordance-factor-table-as-input-1"></a><a class="docs-heading-anchor-permalink" href="#Example-1:-A-concordance-factor-table-as-input" title="Permalink"></a></h3><p>If your concordance factor table is in csv file format, you need to read the file in Julia first. If you have not used the <code>CSV.jl</code> package before then you may need to install it first:</p><pre><code class="language-julia hljs">using Pkg
Pkg.add(&quot;CSV&quot;)</code></pre><p>The <code>CSV.jl</code> functions are not loaded automatically and must be imported into the session:</p><pre><code class="language-julia hljs">using CSV</code></pre><p>The concordance factor table can now be read from a CSV file at path <code>input</code> using</p><pre><code class="language-julia hljs">df = DataFrame(CSV.File(input))</code></pre><p>For example:</p><pre><code class="nohighlight hljs">70×7 DataFrame
 Row │ tx1     tx2     tx3     tx4     expCF12    expCF13      expCF14     
     │ String  String  String  String  Float64    Float64      Float64     
─────┼─────────────────────────────────────────────────────────────────────
   1 │ 7       8       3       4       0.999392   0.000303961  0.000303961
   2 │ 7       8       3       1       0.993192   0.00340375   0.00340375
   3 │ 7       8       3       2       0.993192   0.00340375   0.00340375
   4 │ 7       8       3       5       0.98779    0.00610521   0.00610521
   5 │ 7       8       3       6       0.98779    0.00610521   0.00610521
   6 │ 7       8       4       1       0.993192   0.00340375   0.00340375
   7 │ 7       8       4       2       0.993192   0.00340375   0.00340375
   8 │ 7       8       4       5       0.98779    0.00610521   0.00610521
  ⋮  │   ⋮       ⋮       ⋮       ⋮         ⋮           ⋮            ⋮
  63 │ 3       1       2       6       0.0999344  0.0999344    0.800131
  64 │ 3       1       5       6       0.964386   0.0178072    0.0178072
  65 │ 3       2       5       6       0.964386   0.0178072    0.0178072
  66 │ 4       1       2       5       0.0999344  0.0999344    0.800131
  67 │ 4       1       2       6       0.0999344  0.0999344    0.800131
  68 │ 4       1       5       6       0.964386   0.0178072    0.0178072
  69 │ 4       2       5       6       0.964386   0.0178072    0.0178072
  70 │ 1       2       5       6       0.984151   0.00792452   0.00792452</code></pre><p>Then we can run the PhyloDiamond algorithm on this concordance factor table. </p><pre><code class="language-julia hljs">phylo_diamond(df, 5)</code></pre><p>This function outputs a dictionary, where is key is the rank and the value is the inferred network. The networks are represented in newick format:</p><pre><code class="nohighlight hljs">Dict{Int64, Any} with 5 entries:
  5 =&gt; &quot;((7:1,8:1):4, (((1:1,2:1):2, ((3:1,4:1):1)#H1:1::0.7):1, (#H1:1::0.3,(5:1,6:1):2):1):1);&quot;
  4 =&gt; &quot;((5:1,6:1):4, (((7:1,8:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(3:1,4:1):2):1):1);&quot;
  2 =&gt; &quot;((7:1,8:1):4, (((5:1,6:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(3:1,4:1):2):1):1);&quot;
  3 =&gt; &quot;((5:1,6:1):4, (((3:1,4:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(7:1,8:1):2):1):1);&quot;
  1 =&gt; &quot;((7:1,8:1):4, (((3:1,4:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(5:1,6:1):2):1):1);&quot;</code></pre><p>Below is what is stored in the output file (&quot;phylo_diamond.txt&quot; because we did not specify any name):</p><pre><code class="nohighlight hljs">Inference of top 5 8-taxon phylogenetic networks with phylogenetic invariants
1. N2222 (2.2216927709301364e-16)
[(1,2),(3,4),(5,6),(7,8)]
&quot;((7:1,8:1):4, (((3:1,4:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(5:1,6:1):2):1):1);&quot;
2. N2222 (2.2230610911746716e-16)
[(1,2),(5,6),(3,4),(7,8)]
&quot;((7:1,8:1):4, (((5:1,6:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(3:1,4:1):2):1):1);&quot;
3. N2222 (0.006576057988736475)
[(1,2),(3,4),(7,8),(5,6)]
&quot;((5:1,6:1):4, (((3:1,4:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(7:1,8:1):2):1):1);&quot;
4. N2222 (0.00657929000066336)
[(1,2),(7,8),(3,4),(5,6)]
&quot;((5:1,6:1):4, (((7:1,8:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(3:1,4:1):2):1):1);&quot;
5. N2222 (0.0066877783427965855)
[(3,4),(1,2),(5,6),(7,8)]
&quot;((7:1,8:1):4, (((1:1,2:1):2, ((3:1,4:1):1)#H1:1::0.7):1, (#H1:1::0.3,(5:1,6:1):2):1):1);&quot;</code></pre><p>To understand the output file, take the first network as an example. <code>N2222</code> is the structure of the network, meaning that there are 2 taxon in clades <code>n0</code>, <code>n1</code>, <code>n2</code>, <code>n3</code> (see <a href="https://arxiv.org/abs/2211.16647">Wu and Solis-Lemus, 2022</a> for more on the notation). </p><p>The value after <code>N2222</code> is the corresponding invariant score for this network, and a small score represents a highly possible network. <code>[(1,2),(3,4),(5,6),(7,8)]</code> is another representation of the same network where we specify which are the taxa in each clade. For example, <code>(1,2)</code> are the taxa in clade <code>n0</code>.</p><p>At the end, we have the newick format of the inferred network in quotes:</p><pre><code class="nohighlight hljs">&quot;((7:1,8:1):4, (((3:1,4:1):2, ((1:1,2:1):1)#H1:1::0.7):1, (#H1:1::0.3,(5:1,6:1):2):1):1);&quot;</code></pre><h3 id="Example-2:-Gene-trees-as-input"><a class="docs-heading-anchor" href="#Example-2:-Gene-trees-as-input">Example 2: Gene trees as input</a><a id="Example-2:-Gene-trees-as-input-1"></a><a class="docs-heading-anchor-permalink" href="#Example-2:-Gene-trees-as-input" title="Permalink"></a></h3><p>Here is an example of a textfile with gene tree (&quot;gt.txt&quot;):</p><pre><code class="nohighlight hljs">((7:0.722,8:0.722):2.844,(((3:0.878,4:0.878):0.907,(1:0.935,2:0.935):0.849):1.005,(5:1.853,6:1.853):0.937):0.776);
((7:0.649,8:0.649):2.104,((5:1.919,6:1.919):0.374,((3:0.634,4:0.634):1.442,(1:0.660,2:0.660):1.416):0.218):0.460);
((7:0.942,8:0.942):3.188,(6:3.361,(5:2.130,((1:0.816,2:0.816):1.294,(3:1.045,4:1.045):1.065):0.021):1.231):0.769);
  ⋮               ⋮               ⋮               ⋮               ⋮               ⋮               ⋮               ⋮
(((3:0.600,4:0.600):1.746,(1:0.841,2:0.841):1.506):0.654,((7:0.613,8:0.613):2.148,(5:0.762,6:0.762):1.999):0.239);
((7:0.702,8:0.702):2.679,((5:1.454,6:1.454):0.672,(3:1.942,(4:1.707,(1:0.674,2:0.674):1.033):0.234):0.184):1.255);
(((3:0.647,4:0.647):1.243,(1:1.407,2:1.407):0.483):0.844,((7:0.581,8:0.581):1.979,(5:1.204,6:1.204):1.357):0.173);</code></pre><p>We can call the <code>phylo_diamond</code> function directly on this file:</p><pre><code class="language-julia hljs">phylo_diamond(&quot;gt.txt&quot;, 5)</code></pre><p>The output file has the same structure as the one described in the previous section.</p><h2 id="Error-reporting"><a class="docs-heading-anchor" href="#Error-reporting">Error reporting</a><a id="Error-reporting-1"></a><a class="docs-heading-anchor-permalink" href="#Error-reporting" title="Permalink"></a></h2><p>Please report any bugs and errors by opening an <a href="https://github.com/solislemuslab/PhyloDiamond.jl/issues/new">issue</a>.</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="installation.html">« Installation</a><a class="docs-footer-nextpage" href="../lib/public_methods.html">Public Methods »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.24 on <span class="colophon-date" title="Monday 13 March 2023 21:25">Monday 13 March 2023</span>. Using Julia version 1.8.0-rc1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
