scieee AI-readable full text Open interactive document viewer

Algebraic statistics in phylogenetic reconstruction: incorporating invariable sites

Mañez Fernandez, Davinia

Abstract

In modern phylogenetics, when comparing sequences of DNA the traditional approach assumes that nu- cleotide substitutions follow a Markov model, that sites on a DNA sequence evolve independently and in the same way. However, recent studies have shown that some positions in DNA sequences remain invariant. This thesis aims to investigate cases where certain regions of DNA sequences do not change throughout the evolutionary process. The approach, inspired by the work of Allman and Rhodes in [1], considers a model where a proportion of sites in the DNA sequences cannot vary, while the remaining sites are variable. This model is referred to as the general Markov model plus invariable sites (GM + I ). In [1] they obtain formulae to recover the called invariable parameters involved in the GM + I model. We implement a computational method based on this proposition using Python and evaluate its performance using simulated data. The performance of the method is analyzed in different situations, and potential improvements and variations based on our findings are suggested.

Full text

Universitat Polit`ecnica de Catalunya Facultat de Matem`atiques i Estad´ıstica Master in Advanced Mathematics and Mathematical Engineering Master’s thesis Algebraic statistics in phylogenetic reconstruction: incorporating invariable sites Davinia M´a˜nez Fern´andez Supervised by Marta Casanellas Rius and Jes´us Fern´andez S´anchez June, 2023 Thanks to my tutors Marta Casanellas and Jes´us Fern´andez for their excellent guidance in the research of this thesis and for the time and effort they dedicated to helping me. Of course, I also thank my family for always supporting and encouraging me throughout my mathematics career. Abstract In modern phylogenetics, when comparing sequences of DNA the traditional approach assumes that nucleotide substitutions follow a Markov model, that sites on a DNA sequence evolve independently and in the same way. However, recent studies have shown that some positions in DNA sequences remain invariant. This thesis aims to investigate cases where certain regions of DNA sequences do not change throughout the evolutionary process. The approach, inspired by the work of Allman and Rhodes in [1], considers a model where a proportion of sites in the DNA sequences cannot vary, while the remaining sites are variable. This model is referred to as the general Markov model plus invariable sites (GM +I). In [1] they obtain formulae to recover the called invariable parameters involved in the GM +Imodel. We implement a computational method based on this result using Python and evaluate its performance using simulated data. The performance of the method is analyzed in different situations, and potential improvements and variations based on our findings are suggested. Keywords phylogenetic tree, Markov process, flattening, invariable parameters, invariable sites,... 1 2 Contents 1 Introduction 5 2 Preliminaries 7 2.1 Phylogenetic trees ....................................... 7 2.2 Markov processes on phylogenetic trees ........................... 8 2.3 Edge flattening ........................................ 10 2.4 Measures on distributions ................................... 11 3 Invariable sites model and its identifiability 13 3.1 The general Markov plus invariable sites model ....................... 13 3.2 Invariable sites and parameters of the GM +Imodel .................... 13 3.3 Phylogenetic Invariants .................................... 14 3.4 Invariable site parameters ................................... 16 4 Learning parameters 21 4.1 First results on simulations .................................. 25 4.2 Results on more realistic simulated data ........................... 29 4.3 Modifications on the method ................................. 33 5 Conclusions and discussion 39 A Implementation of the method 43 3 Incorporating invariable sites 4 1. Introduction Throughout life many philosophers and scientists have wondered: How can we organise living beings? Many ways of species classification could be considered depending on different aspects. Surely, one of the main approaches to answer this question is provided by taking into account the evolutionary relations among species, as they provide a powerful framework for ordering species into a hierarchy of relationships based on their evolutionary history and biological similarities. Evolutionary relationships (also known as phylogenies) between species can be represented as phylogenetic trees, which we will define mathematically later. Biologically speaking, they are a visual representation of the relationships between different organisms, showing the path through evolutionary time from a common ancestor to different descendants. These trees help to organize species into groups based on their evolutionary history and degree of relatedness. It is believed that Edward Hitchcock and Charles Darwin were pioneer in considering phylogenetic or evolutionary trees, see [10], as the best way to group organisms and to describe the evolution of species. Nowadays, one of the main goals of phylogenetics is the reconstruction of the phylogenetic trees taking as input a collection of DNA sequences usually arising from homologous genes. To this aim, it is usual to model the corresponding evolutionary processes as a Markov chain and the substitution of nucleotides at all sites of the sequences as independent and according to the same probabilities. However, this is known to be an unrealistic assumption. Several studies have shown that invariable sites should be considered when modelling DNA sequences, for instance [12] provides evidence that there exists a fraction of sites that cannot vary in mitochondrial and nuclear DNA even after allowing for different rates of transition and transversion substitutions. In this project, we want to investigate the particular case where there are regions of the sequences that remain invariant in the whole evolutionary process, that is, the nucleotides at those regions are not substituted along the process, probably because they encode relevant biological information that does not allow nucleotide substitutions. To this end, we adopt the approach of Allman and Rhodes in [1]. They consider that a proportion δof sites of the DNA sequences is not allowed to change, while the other part is variable. The resulting model is called the general Markov model plus invariable sites (GM +I) (see Section 3). We will pay special attention to a relevant result of the cited paper (here Proposition 3.3) as it provides simple rational formulae, expressed in terms of determinantal ratios, to recover the parameter δand the distribution of nucleotides at the invariable sites involved in the GM +Imodel. We implement a method to recover these parameters inspired by this result using the computational language Python. In Section 4we test its performance on simulated data and after studying the performance on different scenarios, we suggest some improvements and variations of the method. Figure 1: Charles Darwin and his first diagram of an evolutionary tree from his First Notebook on Transmutation of Species (1837) on view at the Museum of Natural History in Manhattan. 5 Incorporating invariable sites H(P,Q) = 1 √2v u u t n X i=1 (√pi−√qi)2(2) Note that, as the coordinates of Pand Qare non-negative, the expression above is well-defined. On the other hand, the Frobenius norm, sometimes also called the Euclidean norm, is a matrix norm of an m×nmatrix Adefined as the square root of the sum of the absolute squares of its elements aij , ||A||F= m X i=1 n X j=1 |aij |2. This norm will be used to measure distance between flattening matrices. 12 3. Invariable sites model and its identifiability Recall we are supposing sequences evolve under a model in which a certain proportion δof sites are invariable and the remaining sites are susceptible to vary. We assume that the variable sites evolve independently and identically according to Markov processes on the underlying evolutionary tree. Concerning the invariable sites, as a very first approximation one could think about counting the number of sites that have not varied between the given sequences. However, the problem appears when some of the variable sites may be constant across the species and thus be indistinguishable from unvaried sites. Additionally, we want to know the proportion of invariable sites directly related with the tree root sequence, so a comparison between the given sequences is not enough. 3.1 The general Markov plus invariable sites model We already have a clear idea of the general Markov model and it is time to introduce the model this project will focus on: the general Markov plus invariable sites, GM+I. We follow the approach introduced by Allman and Rhodes in [1]. To begin with, let Tbe a tree with nleaves labeled as a1,a2, ... , anand assume that all internal vertices are of valence at least 3. We suppose that the number of taxa is bigger than the number of states, this is, n≥κ. Next, we describe the parameterization of the κ-state GM +Imodel of sequence evolution along T. It can be seen as a kind of generalization from the GM model as it depends not only on the transition or the root distribution parameters but also on two more, introduced in the section below, which determine the invariable part of the alignment. 3.2 Invariable sites and parameters of the GM +Imodel Suppose sequences evolve under a model where a certain proportion δof sites are supposed to vary according to a common set of parameters for the GM model, though independently of one another, while the remaining sites are invariable, this is, unable to undergo substitution. If a site is invariable, it is assigned with a state i∈[κ] = {1, 2, ... , κ}with probability πI(i). Then, this model is characterized by the two mentioned parameters: the class size parameter δand the state distribution vector πI= (πI(1), ... , πI(κ)), which we can refer to as the invariable parameters. First of all, we introduce a class size parameter δ, which denotes the probability that any particular site in a sequence does not change, so we say the site is invariable with probability δ. Then, this position will be assigned with a state i∈[κ] with probability πI(i), where πI= (πI(1), ... , πI(κ)) is a distribution of states, giving the state distribution for invariable sites. As previously mentioned, a root distribution vector is needed, we will denote it as πGM = (πGM (1), ... , πGM (κ)). In addition, we require the transition matrices Medescribed before in Section 2.2 too. As before, the parameterization map giving the joint distribution of the variables at the leaves of Tis denoted by ϕT:S→[0, 1]κn s7→ P 13 Incorporating invariable sites Here Sis the stochastic parameter space too, but due to the incorporation of the parameters related to the invariable sites, it has a bigger dimension than the one for the general Markov model. Indeed, here S⊂[0, 1]Nhas dimension N= 1 + (κ−1) + (κ−1) + |E|κ(κ−1) = 2κ−1 + |E|κ(κ−1). On the other hand, Pis again an n-dimensional κ×···×κarray, with entries indexed by the states at the leaves of T, ordered as a1,a2, ... , an. The entries of Pare polynomial functions in the parameters sexplicitly given by P(i1,i2, ... , in) = δϵ(i1,i2, ... , in)πI(i1) + (1 −δ)X (jv)∈H πGM (jr)Y e Me(jvi,jvj)!, (3) where ϵ(i1,i2, ... , in) is 1 if all ijare equal and 0 otherwise. When δ= 0, this is precisely the general Markov model introduced before. In order to analyse the GM +Imodel we can decompose it into the invariable and the non-invariable parts. This way, we are able to partly apply the known results for the GM model to develop tools for the model we want to study. One can look at (3) and notice that P= (1 −δ)PGM +δPI, (4) where PGM is an array in the image of the GM parameterization map on Tand PIis the array defined by PI(i1, ... , in) = πI(ij) if i1=··· =in=ijand 0, otherwise. 3.3 Phylogenetic Invariants To introduce this important concept it has to be mentioned that Cavender and Felsenstein, and Lake introduced phylogenetic invariants in 1987 in two independent works, [5] and [9], respectively. Now, we present an informal definition for DNA sequences given by Allman, E.S. and Rhodes, J.A. in [2]. Phylogenetic invariants are polynomial relationships that must hold between the frequencies of various base patterns in idealized data which is perfectly in accord with a particular model and tree. More generally, an invariant for a model is a polynomial that gives zero when evaluated on any distribution arising from that model, regardless of the parameter values leading to that distribution. On a distribution that does not arise from the model, an invariant typically evaluates to give a non-zero result. By testing whether such polynomials for various trees are “nearly zero” when evaluated on the observed frequencies of patterns in real data sequences, it is hoped that one could infer which tree best explained the data. We formally define now phylogenetic invariants in the framework of algebraic geometry, see [14] for a good reference. The parameterization ϕTgiven by polynomial expressions on domain S⊆RNcan be uniquely extended to a polynomial map with domain CNgiven by the same polynomial expressions, which we again denote by ϕT:CN→Cκn. The phylogenetic variety,VT, is the smallest algebraic variety in Cκncontaining ϕT(CN), i.e., the closure of the image of ϕTunder the Zariski topology, VT=Im(ϕT)⊆Cκn. Let C[P] denote the ring of polynomials in the κnindeterminates {pi1···in|ij∈[κ]}. Then the collection of all polynomials in C[P] vanishing on VTforms an ideal IT. We refer to ITas the phylogenetic ideal of T, and its elements as phylogenetic invariants of T. More explicitly, a polynomial f∈C[P] is a phylogenetic 14 Figure 6: The fiand hiare invariants for two alternative models. All joint distributions arising from the first model lie in the “surface” defined by fi(P) = 0, and similarly for the second. To decide which model better explains a data point ˜ P, we attempt to judge whether fi(˜ P)≈0 or hi(˜ P)≈0. invariant if, and only if, f(P0) = 0 for every P0∈ϕT(CN), or equivalently, if, and only if, f(P0) = 0 for every P0∈ϕT(S). The edge flattenings, introduced in Section 2.3, provide us with the phylogenetic invariants for the 2−state GM model on a binary n-taxon tree Tand also help us to obtain phylogenetic invariants when κ≥2.They give us a “coarser” graphical model with one hidden κ−state internal node and two descendent nodes with κmand κn−mstates, respectively (see the tree placed on the right of Figure 5). The edge flattening of P simply prevents one from examining the finer structure in the joint distribution array that arises from the branching of Ton either side of an edge e. We have seen in Section 2that the rank of a flattening Fewhich comes from any P∈ϕr(S) is at most κ. As a consequence, all (κ+1)×(κ+1) minors of Femust vanish. These minors therefore give phylogenetic invariants, which we call edge invariants associated to the edge e. When κis exactly 2 these minors generate all the phylogenetic invariants, while when κ≥2 one needs more polynomials, see [4]. Theorem 3.1 ([4], Section 8).For the 2−state GM model on a binary n-taxon tree T, the phylogenetic ideal ITis generated by all 3×3minors of all edge flattenings Feof P. Moreover, for the κ−state GM model on an n-taxon tree T, the phylogenetic ideal ITcontains all (κ+ 1) ×(κ+ 1) minors of all edge flattenings of P. The next theorem concerning the GM model is useful to find some elements of the phylogenetic ideal for the GM +Imodel for any number of taxa n≥4 and κ≥2: Proposition 3.2 (Phylogenetic invariants for GM + I, [1]). •For the 4−taxon tree Tab|cd and the 2−state GM +I model, the cubic determinantal polynomials f1=det    p1112 p1121 p1122 p1212 p1221 p1222 p2112 p2121 p2122  f2=det    p1211 p1212 p1221 p2111 p2112 p2121 p2211 p2212 p2221   are phylogenetic invariants. These are the 3×3minors of the flattening matrix 15 Incorporating invariable sites Fab|cd =    p1111 p1112 p1121 p1122 p1211 p1212 p1221 p1222 p2111 p2112 p2121 p2122 p2211 p2212 p2221 p2222     (5) that do not involve either of the entries p1111 or p2222. •More generally, for n ≥4and κ≥2, consider the κ−state GM+I model on an n-taxon tree T. Then for each edge e of T, all (κ+ 1) ×(κ+ 1) minors of the flattening Feof P that avoid all entries pii...i,i∈[κ]are phylogenetic invariants of T. Proof. We prove the first statement. Recall PGM is a 4−dimensional 2 ×2×2×2 array arising from the GM model on Tand PIis the array defined by PI(i1, ... , in) = πI(ij) if i1=··· =in=ijand 0, otherwise. Flattening these arrays with respect to the internal edge of the tree, we obtain FGM =    ˜p1111 ˜p1112 ˜p1121 ˜p1122 ˜p1211 ˜p1212 ˜p1221 ˜p1222 ˜p2111 ˜p2112 ˜p2121 ˜p2122 ˜p2211 ˜p2212 ˜p2221 ˜p2222     ,FI=    πI(1) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 πI(2)     , if ˜pijkl denotes the entries of PGM . Looking at (4), for any P=ϕT(s) we have P= (1 −δ)PGM +δPI, consequently: Fab|cd = (1 −δ)FGM +δFI= (1 −δ)    ˜p1111 ˜p1112 ˜p1121 ˜p1122 ˜p1211 ˜p1212 ˜p1221 ˜p1222 ˜p2111 ˜p2112 ˜p2121 ˜p2122 ˜p2211 ˜p2212 ˜p2221 ˜p2222     +δ    πI(1) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 πI(2)     (6) If pijkl denote the entries of the flattening Fab|cd , note that pijkl = ˜pijkl unless i=j=k=l. By Theorem 3.1, all 3 ×3 minors of FGM vanish. Since the “upper right” and “lower left” minors of Fab|cd are the same as those of FGM , up to a factor of (1 −δ)3, they also vanish. Straightforward modifications to this argument give the general case. As a byproduct of the development of these GM +Iinvariants, we are led to rational formulas for recovering all the parameters related to the invariable sites (proportion of invariable sites and stationary distribution of these invariable sites) from a joint distribution. We explain this in the next sections, as these formulas are crucial to our identification of numerical parameters. 3.4 Invariable site parameters Proposition 3.3 (Recovery of invariable site parameters, [1]). •For the 4−taxon tree Tab|cd and the 2−state GM+I model, suppose P =ϕT(s). Then (if P is generic enough) the parameters in srelated to invariable sites can be recovered from P by the following formulas: 16 δ=|A1|+|A2| |B|,πI= (|A1|+|A2|)−1(|A1|,|A2|), where B=p1212 p1221 p2112 p2121,A1=  p1111 p1112 p1121 p1211 p1212 p1221 p2111 p2112 p2121 ,A2=  p1212 p1221 p1222 p2112 p2121 p2122 p2212 p2221 p2222 . •More generally, for the κ−state GM + I model on Tab|cd , the invariable sites parameters can be recovered from a generic point in the image of the parameterization map by rational formulas of the form δ=Pi∈[κ]|Ai| |B|,πI= X i∈[κ]|Ai|  −1 (|A1|,|A2|, ... , |Aκ|), where |B|is any κ×κminor of Fab|cd that omits the rows and columns indexed by ii, and |Ai|is the (κ+ 1) ×(κ+ 1) minor obtained by including all rows and columns chosen for B and in addition the ii row and column. We prove it for κ= 2 and the case κ= 4 is treated more informally with an example. Proof. For a P∈Im(ϕT), we have already seen in equation (6) that Fab|cd can be expressed as Fab|cd = (1 −δ)FGM +δFI. So, if δ= 1 we have A1= (1 −δ)  ˜p1111 ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121 +δ  πI(1) 0 0 0 0 0 0 0 0 = (1 −δ)  ˜p1111 +δ 1−δπI(1) ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121 . Using that determinants are linear in columns we obtain that |A1|=det  (1 −δ)  ˜p1111 +δ 1−δπI(1) ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121  = =det  (1 −δ)  ˜p1111 ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121  +det  (1 −δ)  δ 1−δπI(1) ˜p1112 ˜p1121 0 ˜p1212 ˜p1221 0 ˜p2112 ˜p2121  = = (1 −δ)3det    ˜p1111 ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121  +det  (1 −δ)  δ 1−δπI(1) ˜p1112 ˜p1121 0 ˜p1212 ˜p1221 0 ˜p2112 ˜p2121  . 17 Incorporating invariable sites And using that determinants are linear in rows, we have |A1|= (1 −δ)3det    ˜p1111 ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121  +det    δπI(1) 0 0 0 (1 −δ)˜p1212 (1 −δ)˜p1221 0 (1 −δ)˜p2112 (1 −δ)˜p2121  + +det    0 (1 −δ)˜p1112 (1 −δ)˜p1121 0 (1 −δ)˜p1212 (1 −δ)˜p1221 0 (1 −δ)˜p2112 (1 −δ)˜p2121  , so |A1|= (1 −δ)3det    ˜p1111 ˜p1112 ˜p1121 ˜p1211 ˜p1212 ˜p1221 ˜p2111 ˜p2112 ˜p2121  +det    δπI(1) 0 0 0 (1 −δ)˜p1212 (1 −δ)˜p1221 0 (1 −δ)˜p2112 (1 −δ)˜p2121  . Because all 3 ×3 minors of FGM evaluate to zero by Proposition 3.2, we obtain the next simplification for |A1|: |A1|=δπI(1)det (1 −δ)˜p1212 (1 −δ)˜p1221 (1 −δ)˜p2112 (1 −δ)˜p2121. Thus, looking at the definition of Band at equality (6) we notice that Bcan be expressed as B=(1 −δ)˜p1212 (1 −δ)˜p1221 (1 −δ)˜p2112 (1 −δ)˜p2121, so, we have |A1|=δπI(1)|B|. Consequently, if |B| = 0, δπI(1) = |A1| |B|. Analogously, since A2is the “lower right” submatrix of Fab|cd , then δπI(2) = |A2| |B|. As a consequence of these two equations and the fact that πI(1) + πI(2) = 1, we get δ=|A1|+|A2| |B|, which implies πI= (|A1|+|A2|)−1(|A1|,|A2|), as desired. In order to prove it we have used δ= 1, |B| = 0, |A1|+ |A2| = 0, these are conditions that hold for generic choices of the parameters that define P=ϕT(s). Therefore, the parameters δ,πIare generically identifiable for GM +Ion T, this is, for a generic P∈ Im(ϕT), πIand δare identifiable. Remark 3.4.For the case when κ= 4, we can choose several Bmatrices, in fact there are κ2−κ κ2 different choices, which means we have 12 42= (12·11·10·9 4·3·2)2= 245025 basic sets of formulae to recover δ and πI. 18 Example 3.5. For instance, if we choose B=    p1212 p1213 p1214 p1221 p1312 p1313 p1314 p1321 p1412 p1413 p1414 p1421 p2112 p2113 p2114 p2121     , then A1=      p1111 p1112 p1113 p1114 p1121 p1211 p1212 p1213 p1214 p1221 p1311 p1312 p1313 p1314 p1321 p1411 p1412 p1413 p1414 p1421 p2111 p2112 p2113 p2114 p2121       corresponds to the extension of Badding the entry in the ii-row and ii-column. The other Ai,i∈ {1, 2, 3, 4} can be analogously built looking at the next flattening matrix Fe(we mark in green what we have to merge to Bin order to get A1, in blue A2, in pink A3and in gray A4). Now, just following the Proposition 3.3 we have that:    δ=|A1|+|A2|+|A3|+|A4| |B|, πI=|A1| |A1|+|A2|+|A3|+|A4|,|A2| |A1|+|A2|+|A3|+|A4|,|A3| |A1|+|A2|+|A3|+|A4|,|A4| |A1|+|A2|+|A3|+|A4|.(7) 19 Incorporating invariable sites 20 4. Learning parameters In this section we describe how we implement the previous results and test these implementations on simulated data. As we have seen in the previous section, if we want to estimate the invariable parameters of a tree T, an amount of κ2−κ κ2 Bmatrices can be used. This means that the estimated parameters depend on the choice of the matrix B and we do not know which selection will approximate better these parameters. We focus on the binary case and the main case of interest in phylogenetics, that is, P={1, 2, 3, 4}, representing the nucleotides A,G,C,T. Our first approach to recover the invariable parameters is estimating the parameters δand πIfrom some possible matrices Bin the diagonal of the flattening matrix Fe When κ= 2 there will be only one possible matrix Bin the diagonal, while in the case of 4 states we choose three possible matrices, denoted as Bj,j∈ {1, 2, 3}, each one giving rise to a different estimation of δand πI: B1=    p1212 p1213 p1214 p1221 p1312 p1313 p1314 p1321 p1412 p1413 p1414 p1421 p2112 p2113 p2114 p2121     ,B2=    p2323 p2324 p2331 p2332 p2423 p2424 p2431 p2432 p3123 p3124 p3131 p3132 p3223 p3224 p3231 p3232     and (8) B3=    p3434 p3441 p3442 p3443 p4134 p4141 p4142 p4143 p4234 p4241 p4242 p4243 p4334 p4341 p4342 p4343     . The reason to choose three matrices is to get more robustness than in comparison to choosing only one. However, there are many other possibilities for choosing B’s that will be explored later. To get ˆ δand ˆπI we do the arithmetic mean of the distinct values of ˆ δand ˆπI: ˆ δ=ˆ δ1+ˆ δ2+ˆ δ3 3and ˆπI=ˆπ1+ ˆπ2+ ˆπ3 3, where ˆ δj, ˆπjdenotes the estimation of δ,πIobtained considering Bjand applying the first formula in (7). Therefore, our algorithm will output ˆ δtogether with the corresponding ˆπI-value obtained according to these considerations. With the purpose of optimizing the algorithm some conditions have been applied, which the reader can look at in Appendix A. After analyzing different data sets, we observed the calculations sometimes output excessively large ˆ δ. This is mainly due to the fact that |B|or Pi∈[κ]|Ai|could be very close to zero. Since δrepresents a probability (or a proportion) for invariable sites, it can not be bigger than 1 or smaller than 0, so, the restriction 0 ≤ˆ δ≤1 is demanded before presenting the estimated ˆ δ. To reach this condition, for each Bjwe verify if 0 ≤ˆ δj≤1. So, the definition of ˆ δcan be improved like that: ˆ δ=Pj∈Pˆ δj card(P), (9) 21 Incorporating invariable sites Figure 10: Average accuracy of the method represented by ||ˆ FGM −FGM ||F ||FGM ||F, which is represented on the y-axis. Different colors are used to represent different values of δ. 28 4.2 Results on more realistic simulated data b a ab a Figure 11: 4-taxon tree Twith branch lengths With the purpose of continue analysing how well the method IM works, we have done several boxplots with the results obtained after applying the algorithm to another set of simulated data. The tree in Figure 11 is considered, where aand bcorrespond to branch lengths, meaning the expected number of elapsed substitutions per site along the respective branch. This is a usual set up to test different phylogenetic reconstruction methods, see [8]. Length atakes values in {0.15, 0.55, 1.05}, while btakes values in {1.01, 0.55, 1.05}. Six different sets of data have been considered, each of them contains 100 alignments of the same length (either 1000 or 10000). They are organised according to the values (a,b)∈ {(15, 101), (55, 55), (105, 105)}. Different values of the parameter δhave been chosen, specifically (δ∈ {0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}and πI= (0.2, 0.1, 0.3, 0.4). We have displayed boxplots in three figures, one for each different choice of (a,b) (see Fig. 12,13 and 14). We analyse the average δ-accuracy and the average πI-accuracy simultaneously. In green the means have been painted, while in orange one can see the medians. One important fact we notice is that, as we have seen before, when δis bigger both estimations are better. Additionally, we have to highlight that the boxes get smaller when δincreases, this means that when this parameter gets bigger the values of both the δestimation and the πIestimation are closer to the median than when δis smaller. Moreover, we observe that when N= 10000 the two estimations are generally better than when N= 1000, which happened in the other simulated data too. In fact, one can realised that the order of the error is almost the same as the one previously obtained from the transition matrices in (12), which were more realistic than the ones in (11). 29 Incorporating invariable sites Figure 12: In both figures δis represented on the x-axis. In the boxplot on top |δ−ˆ δ|takes values on the y-axis, while in the boxplot on the bottom there are the values H(πI, ˆπI) on this axis. Two colors, blue and yellow, are used to differentiate the length of the alignments (N). The green dashed lines represent the means of the error for each value of δ, while the medians are displayed with orange lines. The circles represent the outliers. 30 Figure 13: In both figures δis represented on the x-axis. In the boxplot on top |δ−ˆ δ|takes values on the y-axis, while in the boxplot on the bottom there are the values H(πI, ˆπI) on this axis. Two colors, blue and yellow, are used to differentiate the length of the alignments (N). The green dashed lines represent the means of the error for each value of δ, while the medians are displayed with orange lines. The circles represent the outliers. 31 Incorporating invariable sites Figure 14: In both figures δis represented on the x-axis. In the boxplot on top |δ−ˆ δ|takes values on the y-axis, while in the boxplot on the bottom there are the values H(πI, ˆπI) on this axis. Two colors, blue and yellow, are used to differentiate the length of the alignments (N). The green dashed lines represent the means of the error for each value of δ, while the medians are displayed with orange lines. The circles represent the outliers. 32 4.3 Modifications on the method After seeing these first results, it is natural to think about possible options to optimize the algorithm. In this section we propose two different variations of the method. One interesting idea is to calculate the determinants of every possible Bmatrix of the flattening and to choose a certain amount of B’s with largest value of determinant, instead of the ones we have chosen. A function that calculates these determinants has been implemented in Python. Looking at Figure 15 one can see every 4x4 determinant for possible B’s painted, triggered by calculation order. The 42−4 4= 495 determinants of the submatrices centered at the diagonal of Fe, which we refer as the diagonal determinants, are represented by orange stars. It makes sense to consider diagonal determinants because the largest elements of a flattening matrix lie in the diagonal (although in rows/columns not allowed in B). These determinants are special for us because they contain the three consecutive Bmatrices of the diagonal of Feconsidered in (8), in the graphic their determinants are represented by red stars. We observe that, considering the flattening from the transition matrices in (11), some of these diagonal determinants are very close to the set of the smallest positive values of all determinants. Figure 15: Determinants of all possible Bmatrices, considering the transition matrices in (11), are represented by blue circles. Orange stars represent the diagonal determinants and red stars represent the determinants of the matrices in (8). The values are scaled up by 106. If we consider more biologically realistic transition matrices, with bigger diagonal values than the matrices in (11), for example, the ones in (12), and πGM = (0.4, 0.1, 0.3, 0.2) we get the graphic of determinant values in Figure 16. We observe two remarkable aspects in it. Firstly, there are positive 4x4 diagonal 33 Incorporating invariable sites determinants far from 0. ˜ Mar =    0.6 0.1 0.1 0.2 0.1 0.6 0.1 0.2 0.2 0.2 0.4 0.2 0.1 0.1 0.1 0.7     ,˜ Mbr =    0.7 0.1 0.1 0.1 0.1 0.6 0.1 0.2 0.1 0.1 0.7 0.1 0.1 0.2 0.1 0.6     ,˜ Mfd =    0.7 0.1 0.1 0.1 0.1 0.6 0.1 0.2 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7     , (12) ˜ Mrf =1 2(˜ Mar +˜ Mbr ), ˜ Mfc =1 2(˜ Mfd +˜ Mrb). Secondly, if we select only the diagonal determinants we have a representative sample of all positive values of 4x4 determinants. Figure 16: Determinants of all possible Bmatrices, considering the transition matrices in (12), are represented by blue circles. Orange stars represent the diagonal determinants and red stars represent the determinants of the matrices in (8). The values are scaled up by 106. We implemented a new estimation method choosing the three matrices Bthat had largest determinants. As this has large computational cost, in order to decrease it we decided to work only with the diagonal determinants. So in the Appendix you can find the algorithm IMsorted−dets (see (23)), which uses the three largest diagonal determinants. We achieve this using the program of Fig. 22 in Appendix which, given a flattening, calculates a dictionary with all the diagonal determinants of this flattening sorted by value in descendant order. The keys of the dictionary are the rows and columns which form the submatrix that has the corresponding determinant. This method outputs the dictionary and the variable “values”, which has 34 the rows and columns of each submatrix that has as determinant one of the three biggest ones, this way later we can access to these submatrices that will be the Bmatrices. Another approach is, apart from choosing the three B’s that have largest determinants, changing the way of calculating the estimations of the invariable sites parameters too. The program IMlogarithms (see Fig. 24 in Appendix) calculates Dj=log ˆ δj=log(P4 i=1 |Aj i|)−log(|Bj|), for every j∈ {1, 2, 3}(giving rise to the three largest |B1|,|B2|,|B3|), to finally output ˆ δj=exp(D1)+exp(D2)+exp(D3) 3. And it also calculates Pj= log(abs(|Aj 1|))−log(|Aj 1|+|Aj 2|+|Aj 3|+|Aj 4|), log(abs(|Aj 2|))−log(|Aj 1|+|Aj 2|+|Aj 3|+|Aj 4|), log(abs(|Aj 3|))− log(|Aj 1|+|Aj 2|+|Aj 3|+|Aj 4|), log(abs(|Aj 4|)) −log(|Aj 1|+|Aj 2|+|Aj 3|+|Aj 4|) to finally output ˆπj I= exp(P1)+exp(P2)+exp(P3) 3. On the one hand, in Figure 17 and Figure 18 one can see the δ-accuracy of the IMsorted−dets method looking at the graphics placed at the bottom and the δ-accuracy of the IMlogarithms method looking at the ones placed at the top right. The first figure corresponds to the transition matrices in (11), while the second one to the ones in (12). We notice how both IMlogarithms and IMsorted−dets increase remarkably the accuracy estimating δ. On the other hand, in Figure 19 and Figure 20 we can observe the πI-accuracy of the IMsorted−dets and IMlogarithms methods looking at the graphics depicted at the bottom and at the top right, respectively. As before, the first figure corresponds to the transition matrices in (11), while the second one to the ones in (12). Both methods improve the accuracy estimating πI. Figure 17: Average δ-accuracy of IM (left) , IMlogarithms (right) and IMsorted−dets (bottom), considering the set of matrices (11). Different colors are used to represent different values of δ. 35 Incorporating invariable sites Figure 18: Average δ-accuracy of IM (left), IMlogarithms (right) and IMsorted−dets (bottom), considering the set of matrices (12). Different colors are used to represent different values of δ. Figure 19: Average πI-accuracy of IM (left), IMlogarithms (right) and IMsorted−dets (bottom), considering the set of matrices (11). Different colors are used to represent different values of δ. 36 Figure 20: Average πI-accuracy of IM (left), IMlogarithms (right) and IMsorted−dets (bottom), considering the set of matrices (12). Different colors are used to represent different values of δ. 37 Incorporating invariable sites Figure 21: IM program 44 Figure 22: Function that, given a flattening, calculates a dictionary with all the diagonal determinants of this flattening sorted by value in descendant order 45 Incorporating invariable sites Figure 23: IMsorted−dets program 46 Figure 24: IMlogarithms program 47