Installation

Installation of Julia

Julia is a high-level and interactive programming language (like R or Matlab), but it is also high-performance (like C). To install Julia, follow instructions here. For a quick & basic tutorial on Julia, see learn x in y minutes.

Editors:

  • Visual Studio Code provides an editor and an integrated development environment (IDE) for Julia: highly recommended!
  • Juno provides an IDE for Julia, based on the Atom editor.
  • you can also run Julia within a Jupyter notebook (formerly IPython notebook).

IMPORTANT: Julia code is just-in-time compiled. This means that the first time you run a function, it will be compiled at that moment. So, please be patient! Future calls to the function will be much much faster. Trying out toy examples for the first calls is a good idea.

Installation of the package PhyloNetworks

To install the package, type inside Julia:

using Pkg
Pkg.add("PhyloNetworks")

The first step can take a few minutes, be patient. If you already installed the package and want the latest registered version, just do this (which will update all of your packages):

Pkg.update()

Warning: It is important to update the package regularly as it is undergoing constant development. Join the google group for updates here.

Pkg.update() will install the latest registered version, but there could be other improvements in the master branch of the repository. If you want to update to the latest unregistered version of the package, you can do Pkg.add(PackageSpec(name="PhyloNetworks", rev="master")) just beware that the latest changes could be not as robust. If you want to go back to the registered package, you can do Pkg.free("PhyloNetworks").

Similarly, you can pin a version of the package Pkg.pin("PhyloNetworks") so that Pkg.update() will not modify it. You can always free a pinned package with Pkg.free("PhyloNetworks"). More on package management here.

The PhyloNetworks package has dependencies like NLopt and DataFrames (see the Project.toml file for the full list), but everything is installed automatically.

The companion package PhyloPlots has utilities to visualize networks, and for interoperability, such as to export networks to R (which can then be plotted via R). To install:

using Pkg
Pkg.add("PhyloPlots")

PhyloPlots depends on PhyloNetworks, and has further dependencies like RCall

Test example

To check that your installation worked, type this in Julia to load the package. This is something to type every time you start a Julia session:

using PhyloNetworks;

This step can also take a while, if Julia needs to pre-compile the code (after a package update for instance). Here is a very small test for the installation of PhyloNetworks.

julia> net = readTopology("(A,(B,(C,D)));");
julia> tipLabels(net)4-element Vector{String}: "A" "B" "C" "D"

You can see a list of all the functions with

varinfo(PhyloNetworks)

and press ? inside Julia to switch to help mode, followed by the name of a function (or type) to get more details about it.

Julia types

Each object in Julia has a type. We show here small examples on how to get more info on an object, what's its type, and how to manipulate objects. For example, let's take an object raxmlCF created from reading in some data (see Input for SNaQ):

julia> raxmltrees = joinpath(dirname(pathof(PhyloNetworks)), "..","examples","raxmltrees.tre");
julia> raxmlCF = readTrees2CF(raxmltrees);will use all quartets on 6 taxa calculating obsCF from 30 gene trees and for 15 quartets Reading in quartets... 0+---------------+100% *************** table of obsCF printed to file tableCF.txt descriptive stat of input data printed to file summaryTreesQuartets.txt

Typing varinfo() will provide a list of objects and packages in memory, including raxmlCF that we just created. If we want to know the type of a particular object, we do:

julia> typeof(raxmlCF)DataCF

which shows us that raxmlCF is of type DataCF. If we want to know about the attributes the object has, we can type ? in Julia, followed by DataCF for a description. We can also ask for a list of all its attributes with

julia> fieldnames(typeof(raxmlCF))(:quartet, :numQuartets, :tree, :numTrees, :repSpecies)

For example, we see that one attribute is numQuartets: its the number of 4-taxon subsets in the data. To see what this number is:

julia> raxmlCF.numQuartets15

We also noticed an attribute quartet. It is a vector of Quartet objects inside raxmlCF, so

julia> raxmlCF.quartet[2].taxon4-element Vector{String}:
 "A"
 "B"
 "C"
 "E"

will provide the list of taxon names for the second 4-taxon subset in the data. To see the observed CF, we can type

julia> raxmlCF.quartet[2].obsCF3-element Vector{Float64}:
 0.8333333333333334
 0.03333333333333333
 0.13333333333333333

We can verify the type with

julia> typeof(raxmlCF.quartet[2])Quartet

We can also read a simple network in Julia and print the list of edges

julia> str = "(A,((B,#H1),(C,(D)#H1)));";
julia> net = readTopology(str);
julia> printEdges(net)edge parent child length hybrid isMajor gamma containRoot inCycle istIdentitiable 1 -2 1 false true 1 true -1 false 2 -4 2 false true 1 true -1 false 3 -4 3 true false true -1 false 4 -3 -4 false true 1 true -1 true 5 -5 4 false true 1 true -1 false 6 3 5 false true 1 false -1 false 7 -5 3 true true true -1 true 8 -3 -5 false true 1 true -1 true 9 -2 -3 false true 1 true -1 true

We see that the edges do not have branch lengths, and the hybrid edges do not have gamma values. We can set them with

julia> setLength!(net.edge[1],1.9)
julia> setGamma!(net.edge[3],0.8)
julia> printEdges(net)edge parent child length hybrid isMajor gamma containRoot inCycle istIdentitiable 1 -2 1 1.900 false true 1 true -1 false 2 -4 2 false true 1 true -1 false 3 -4 3 true true 0.8 true -1 false 4 -3 -4 false true 1 true -1 true 5 -5 4 false true 1 true -1 false 6 3 5 false true 1 false -1 false 7 -5 3 true false 0.2 true -1 true 8 -3 -5 false true 1 true -1 true 9 -2 -3 false true 1 true -1 true

where 1 and 3 correspond to the position of the given edge to modify in the list of edges. We can only change the gamma value of hybrid edges (not tree edges). Such an attempt below will cause an error with a message to explain that the edge was a tree edge:

setGamma!(net.edge[4],0.7)
# should return this:
# ERROR: cannot change gamma in a tree edge