contents 3.5 Discussion 42 4 viruses phenotypic diffusion: escaping the immune systems chase 47 4.1 Introduction 47 4.1.1 From the microscopic model to Langevin equations 48 4.1.2 Simplified description 49 4.1.3 Deterministic fixed points 50 4.2 Phenomenological model in phenotypic space 51 4.2.1 Fitness function 52 4.2.2 System's scales 53 4.3 Numerical simulations 54 4.3.1 Implementation 54 4.3.2 Observables estimation -clustering analysis 57 4.3.3 Preliminary numerical results 57 4.4 Wave solution 59 4.4.1 Regulation of population size 61 4.4.2 Traveling wave scaling in phenotypic space 63 4.5 Adding other dimensions to the linear wave 65 4.5.1 Shape of viral dispersion 65 4.5.2 Lineage trajectory diffusivity in antigenic space 67 4.6 Conclusions and near future directions 69 ii infer evolutionary constraints at finer scales: proteins, evolution and statistical physics 71 5 statistical physics for protein sequences 73 5.1 Background and motivation 73 5.2 Statistical mechanics, inference and protein sequences 75 5.2.1 Canonical ensemble 75 5.2.2 Maximum Likelihood 79 5.2.3 Maximum Entropy principle and inverse Potts problem 79 5.3 Parameters and optimization 82 5.3.1 Boltzmann learning 82 5.3.2 Gauge invariance and regularization 84 5.4 General applications of DCA 85 5.5 Repeat proteins families 86 5.5.1 Repeat proteins 86 5.5.2 Global ensemble features of repeat proteins sequence space 89 5.5.3 Making sense of empirical patterns: repeats evolutionary model 90 6 size and structure of the sequence space of repeat proteins 93 6.1 Abstract 93 6.2 Introduction 93 6.3 Results 95 6.3.1 Statistical models of repeat-protein families 95 6.3.2 Statistical energy vs unfolding energy 1.2 two examples of constraints in evolution

A B S T R A C T

Evolution constrains organism diversity through natural selection. Here we build theoretical models to study the effect of evolutionary constraints on two natural systems at different scales: viral-immune coevolution and protein evolution.

First we study how immune systems constrain the evolutionary path of viruses which constantly try to escape immune memory updates. We start by studying numerically a minimal agent based model with a few simple ingredients governing the microscopic interactions between viruses and immune systems in an abstract framework. These ingredients couple processes at different scales -immune response, epidemiology, evolution -that all together determine the evolutionary outcome. We find that the population of immune systems drives viruses to a set of interesting evolutionary patterns, which can also be observed in nature. We map these evolutionary strategies onto model parameters. Then we study a coarse-grained theoretical model for the evolution of viruses and immune receptors in antigenic space consisting of a system of coupled stochastic differential equations, inspired by the previous agent-based simulations. This study sheds light on the interplay between the different scales constituting this phylodynamic system. We obtain some analytical insights into how immune systems constrain viral evolution in antigenic space while viruses manage to sustain a steady state escape dynamics. We validate the theoretical predictions against numerical simulations.

In the second part of this work we exploit the enormous amount of protein sequence data to extract information about the evolutionary constraints acting on repeat protein families, whose elements are proteins made of many repetitions of conserved portions of amino-acids, called repeats. We couple an inference scheme to computational models, which leverage equilibrium statistical mechanics ideas to characterize the macroscopic observables arising from a probabilistic description of protein sequences. We use this framework to address how functional constraints reduce and shape the global space of repeat protein sequences that survive selection. We obtain an estimate of the number of accessible sequences, and we characterize quantitatively the relative role of different constraints and phylogenetic effects in reducing this space. Our results suggest that the studied repeat protein families are constrained by a rugged landscape shaping the accessible sequence space in multiple clustered subtypes of the same family. Then we exploit the same framework to address the interplay between evolutionary constraints and phylogenetic correlations in repeat tandem arrays. As a result we infer quantitatively the functional constraints, together with the relative timescale between repeat duplications/deletions and point mutations. We also investigate and map what microscopic evolutionary mechanisms can generate specific inter-repeat statistical patterns, which are recurrently observed in data. Preliminary results suggest that evolution of repeat tandem arrays is strongly out of equilibrium.

iii R E S U M É L'évolution limite la diversité des organismes par la sélection naturelle. Nous construisons ici des modèles théoriques pour étudier l'effet des contraintes évolutives sur deux systèmes biologiques à des échelles différentes : la coévolution virale-immune et l'évolution des protéines.

Nous étudions d'abord comment les systèmes immunitaires limitent le parcours évolutif des virus qui tentent constamment d'échapper aux mises à jour de la mémoire immunitaire. Nous commençons par étudier numériquement un modèle agent-based minimal régissant les interactions microscopiques entre les virus et les systèmes immunitaires dans un cadre abstrait. Ces ingrédients couplent des processus biologiques à différentes échellesréponse immunitaire, épidémiologie, évolution -qui conjointement déterminent le résultat de l'évolution. Nous constatons que la population des systèmes immunitaires pousse les virus vers un ensemble de motifs biologiquement pertinents. Nous caractérisons ces stratégies évolutives en fonction des paramètres du modèle. Ensuite nous étudions un description à gros grains décrivant l'évolution des virus et des récepteurs immunitaires dans l'espace antigénique. Cette approche consistant en un système d'équations différentielles stochastiques couplées permet de clarifier l'interaction entre les différentes échelles qui constituent ce système phylodynamique. Nous obtenons une description analytique de la façon dont les systèmes immunitaires limitent l'évolution des virus dans l'espace antigénique, alors que les virus parviennent à maintenir une dynamique de fuite en régime permanent. Nous validons les prédictions théoriques à l'aide des simulations numériques.

Dans la deuxième partie de ce travail, nous exploitons l'énorme quantité de données accessible sur les séquences protéiques pour extraire des informations sur les contraintes évolutives agissant sur les familles de protéines répétées, constituées de nombreuses répétitions de portions conservées d'acides aminés. Nous couplons un schéma d'inférence à des modèles numériques en nous appuyant sur des idées de mécanique statistique à l'équilibre afin caractériser les observables biologiques découlant d'une description probabiliste des séquences de protéines. Nous utilisons ce cadre pour étudier comment les contraintes fonctionnelles réduisent et façonnent l'espace global des séquences protéiques répétées qui survivent à la sélection. Nous obtenons une estimation du nombre de séquences accessibles, et nous caractérisons quantitativement le rôle relatif des différentes contraintes et des effets phylogénétiques dans la réduction de cet espace. Nos résultats suggèrent que les familles de protéines répétées étudiées sont contraintes par un paysage accidenté qui façonne l'espace des séquences accessibles en plusieurs sous-types groupés de la même famille. Nous exploitons ensuite le même cadre pour étudier l'interaction entre les contraintes évolutives et les corrélations phylogénétiques dans les séries de répétitions. Nous déduisons quantitativement les contraintes fonctionnelles, ainsi que l'échelle de temps relative entre les duplications/suppressions des répétitions et les mutations iv ponctuelles. Nous étudions et caractérisons également les mécanismes évolutifs microscopiques qui peuvent générer des motifs statistiques spécifiques entre répétitions, observés de manière récurrente dans les données. Les résultats préliminaires suggèrent que l'évolution des séries de répétitions est un processus fortement hors équilibre. Chapter 3 is the direct copy of the work published in [START_REF] Marchi | Multi-lineage evolution in viral populations driven by host immune systems[END_REF] in collaboration with Michael Lässig from the University of Cologne.

Chapter 4 includes some work that is currently being prepared for future publication (Marchi Mora Walczak, in preparation).

Chapter 6 is the direct copy of the work published in [START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF] in collaboration with Ezequiel Galpern, Rocio Espada and Diego Ferreiro from the University of Buenos Aires.

Chapter 7 is part of a work in progress, in collaboration with Ezequiel Galpern and Diego Ferreiro from the University of Buenos Aires (Marchi Galpern Ferreiro Mora Walczak, in preparation).

vii A C K N O W L E D G M E N T S

This PhD has been a long journey, and it's only now that, looking back, I realize how rich of a journey it was. It was rich of scientific stimuli, ideas, exciting discussions, conferences and collaborations in amazing places. It was rich of joy and beautiful moments. It was rich of bad moments too, some say that hardship make us grow, could be. It was rich of life. But most importantly it was rich of friends, amazing people that left a mark and made this journey so special. I will try here in the impossible task of expressing my gratitude to all the people that shared a part of this important path with me. I apologize in advance to those I will inevitably forget to mention.

First of all, I would like to thank Aleksandra and Thierry who supervised me these past four years. I know I was an annoying student for you at times, not the perfect student you dream of that does what he is told when he is told. From the other side of the fence I can tell you that you were annoying supervisors a few times too. But no matter the problems, you always kept advising and teaching me with the same dedication, and I have you to thank for my scientific maturation. Ultimately I want to thank you for the distinctive feature that characterizes the way you handle your group and makes it a great environment for young researchers to grow: thank you for caring.

I want to thank also two great researchers I had the chance to collaborate with, Michael Lässig and Diego Ferreiro, for sharing their knowledge with me and exposing me to new ideas and different ways of thinking about scientific problems.

I thank Edo Kussell and Martin Weigt for having agreed to be the referees of this thesis, and also Olivier Martin and Joshua Weitz, whom I look forward to working with, for being part of my jury.

Vorrei ringraziare Francesco Zamponi per aver seguito lo sviluppo di questa tesi facendomi da mentore (o tutor, non ricordo mai), e per alcuni mirati consigli che mi ha dato durante questo percorso.

Un grazie enorme va a Marco, per essere stato il mio primo punto di riferimento nel mondo accademico ed il mio primo mentore scientifico durante la magistrale. E' grazie a te se non sono finito a fare robe pallose tipo condensati di Bose-Einstein o DFT. Ma soprattutto grazie per tutti gli ottimi, accurati consigli che hai continuato a darmi anche durante tutto il dottorato nonostante non ne fossi tenuto. E anche per aver accettato di farmi da tutor (o mentore, chi lo sa).

Voglio anche ringraziare Gabriele Micali, Diana Fusco e soprattutto Jacopo(ne) per i buoni (ne sono sicuro) consigli sulla scelta del post-doc.

Then I want to thank all the people from the group I had the pleasure to overlap and share thoughts, lunches, coffees and many beers with: Andreas, Quentin, Alec, Huy, Silvia, Victor, Natanael, Thomas, Federica, Giulio, Cosimo (wow lots of money these ERC), Mathias, Carlos, Meriem, Maria and Francesco. A special thanks goes to Max. One of the hardest periods ix during this PhD was the transition between the two "generations" of the group, when there were basically only you and I. Your chill and confident vibe helped me a lot those times, and your advices on PhD life were true pearls.

I thank all the great people that made my life better here in Paris, and I drank even more beers with: Dimi and Angie, Clement and Zaira, Ayrton, Diana, Ido, Ivan, Elisabetta, Louis, Lorenzo, Fabio, Marco, Diego, Simone, Alessandro, Luca, Jessica, Bahadir, Margareth, Constance, Ema, Noemie, Marion. I thank my companions of a travel in a far and different land, Moshir, Federico, Eugenio and Angelo. Merci aussi a ma coloc Marie-Laure de supporter mon mode de vie bizarre. I thank the awful student residence in Montrouge (apart from the rooftop, that's cool) because it made me meet two amazing friends, Umar and Patric. Grazie al mio amico Dario, che come me ha viaggiato per davvero, e sa che il viaggio ti cambia per sempre.

Un gracias grandisimo a la primera persona que me hizo sentir como en casa aquí en Paris recibiendome como parte de su familia, Christian eres un grande.

Ovviamente un grazie speciale a Micio, Aldo e Daniele, per tutto quello che abbiamo condiviso durante gli ultimi tre anni. Nonostante il tanto tempo passato assieme, con voi non ho mai dovuto smussare gli angoli del mio carattere.

Tambien gracias a mis amigos en Argentina. A los chicos del lab, Nacho, Diego de vuelta, Rocio, Cesar, Juli, Brenda, Maria, Lucho, Ariel, porque cuando estuve ahì nunca me faltò nada. Eze, es un placer colaborar con tigo, y gracias para hacerme conocer con pasion la cultura Argentina, la historia y la politica Sudamericana, y la buenisima fugazzeta. Y gracias al mejor anfitrion del mundo, mi amigo Juan, spero di vederti presto in Europa col tuo nuovo passaporto Italiano.

Per gente che si sposta di continuo e che non sa dove sarà tra due anni è difficile definire il concetto di "casa". A me piace pensare che casa sia ovunque siano gli amici, le persone che ci vogliono bene. In questo senso Milano non ha mai smesso di essere casa mia, e di ciò devo ringraziare i miei amici storici, che ogni volta che torno mi fanno sentire bene, come se non me ne fossi mai andato. Quindi grazie a Jacopo, Matteo, Ste, Simo, Marti, Massi, Benni, Natalia, Giacomo, e grazie ai fisici con cui ho condiviso tante avventure, Penni, Giulia, Ruzza, Salvo, Carlo, Carlone, Sara, Silvia, Robi, Enrico, Benny, Simo, Andrea.

E per finire, il grazie più grande va alla mia famiglia. Grazie a Laura e a Nico. Papà, anche se non ci parliamo spesso mi capisci sempre pienamente senza bisogno di molte parole, grazie. Grazie zio Gigi per avere sempre un pensiero rivolto a me. Corine, se sono arrivato fino a questo punto devo ringraziare in gran parte te, ti abbraccio forte. Mamma, grazie per esserci sempre stata incondizionatamente, nonostante le mie distanze, per avermi sempre supportato quando ne ho avuto bisogno durante tutti questi anni. Ti voglio bene.

x C O N T E N T S

M O D E L I N G E V O L U T I O N A R Y C O N S T R A I N T S AT D I F F E R E N T S C A L E S

1.1 some philosophy (of science) Life is complicated. Living systems, and hence biology, are characterized by a multitude of chemical and physical processes that interact at different scales. In some cases these many complicated processes characterizing complex living systems can give rise to just a few emergent macroscopic patterns, which are typically driven by interactions. For example a flock of birds or a community of bacteria behave collectively in a few stereotyped ways. When looking at these systems in a coarse-grained collective fashion they are much simpler to describe than the dynamics of all their constituents. At the same time understanding each constituent process independently, for instance the behavior of a bird when taken alone, does not add much to the understanding of the behavior of the system at the global level. In order to address scientifically the biochemical and physical processes at the base of living systems, and whether and how macroscopic patterns emerge from the microscopic constituent, we need quantitative data about such processes at various scales.

Recent technological advances opened the possibility to inspect biological processes addressing quantitative questions previously out of reach. For example the advance in sequencing techniques reduced drastically the cost of sequencing, which combined with recent high-throughput techniques triggered an exponential growth of genomic sequence data. Apart from the amount of data, another aspect that saw a recent improvement in many fields of micro-biology is the precision of the information that can be extracted. Now it is possible to inspect the behavior of a community consisting of thousands of bacteria at the single cell level in order to address interactions and correlations between them, rather than just average community observables like few decades ago. Another example comes from immunology, where recent high throughput sequencing techniques opened a window on the processes driving the adaptive immune system evolution, which is an evolutionary process taking place in parallel in any individual. This constitutes an unprecedented chance to improve our understanding of evolution.

But data alone do not complete the process of scientific understanding, we need some framework to interpret them in order to extract information on the system under study. If one just fits the data with many parameters in order to reproduce their correlations, no new insight is gained on the underlying processes. That's why theory and mathematical models constitute a fundamental part of the scientific process. One can use models to interpret data and produce new insights that can be used to inform future experiments. The ingredients of a model can be derived from first principles, or are inspired by intuition on some empirical phenomenon. The parame-ters defining a model can be inferred from data, provided that data carry enough independent information with respect to the number of parameters. The model abstraction mapping concepts to mathematical description is extremely useful to gain insight on what key ingredients are necessary to describe a given phenomenon. Then the descriptive model's conceptual ingredients can be turned into testable predictions to confirm or falsify a set of hypotheses upon collection of new data, in a loop refining theory and experiments in subsequent cycles. Hence the ability of mapping concepts to description, making predictions and test hypotheses are essential features that theory brings to the understanding of biological systems.

As hinted above, in some fields of biology where data is extracted through genetic sequencing the recent years have seen an explosion in data availability. For example this is the case of proteins sequences, where an overwhelming amount of amino-acid sequence data are being generated, most of which are not annotated. If one cares about exploiting these data to add new insights on the biological process one needs a unique framework that can explain all data at the same time, while giving useful results fast enough compared with the production of new data. Sometimes the available theoretical models fail in this task because they are not general enough, and in the case of computational models they can even be too slow to produce viable results. In this situation we can apply statistical inference techniques combined with computational models in order to overcome this limitation. This approach makes a virtue out of necessity as it exploits the huge amount of data statistics to extract information that can be fed into the previously inappropriate theoretical models to make them more general. We will see below an application of this approach to proteins evolution.

When studying complex multi-scales phenomena that give rise to global patterns and are largely not understood, it can be useful to make a further abstraction step in modeling. One can summarize the empirical knowledge on the phenomenon into few key ingredients, defining simple interaction rules between the system's constituents. The resulting minimal model will produce a set of global patterns that can be confronted with empirical observations. These types of models typically ignore a lot of the system's details in order to be general with as few parameters as possible. Therefore they will not produce detailed predictions to be matched precisely to some specific realization of the system under study. On the other hand they can be used to distinguish qualitatively between drastically different scenarios, and to pinpoint the few fundamental concepts producing some recurrent set of patterns in the system. We will see below an example of this modeling perspective applied to viral evolution.

two examples of constraints in evolution

In this thesis we explore some concepts related to the fundamental biological process driving the naturally observed patterns in the heritable characteristics of living systems over long timescales: evolution. The genes of organisms is passed onto descendants and can be modified by various sources of genetic variation. They are expressed into proteins through complicated patterns of gene regulation, that build up a considerable part of organism characteristics, called phenotype (reality is more complicated, this is a conceptual example). Given a certain environmental condition certain characteristics make individuals fitter than others. These individuals will produce more offspring with similar phenotypes whereas less suitable ones will go extinct. This process is known as natural selection.

Natural selection therefore imposes some constraints on the evolution of organisms, and shapes the observed patterns of their diversity. As a conceptual example, in a fixed environment one can imagine different niches of organisms with similar characteristics. In each niche diversification and selection will drive the organisms to have nearly fittest characteristics. The same idealized process can be viewed in an abstract characteristics space, where natural selection is encoded in a rugged fitness landscape with many maxima. In this situation evolution will search the characteristics space through diversification, and organisms will be selected so that for long times they will form different species with characteristics close to the maxima of the fitness landscape.

In the first Part of this thesis we will study minimal models for the coevolution of viruses and immune systems. The main idea underlying this Part is that population immune systems constrain the possible evolutionary strategies that viruses can adopt to escape them. At the microscopic level this system as a whole consists of an absurdly complicated variety of biochemical processes. The proteins expressed on lymphocytes interact with those on the viruses driving the immune response, viruses mutate into different strains and at the same time they spread in a population of individuals with different immune repertoires, which in turn are infected by random samples drawn from the pathogen diversity. This system at longer timescales drives the evolution of virus (and immune repertoire) diversity. The evolutionary outcomes can present a relatively small set of patterns, such as extinctions, sustained evolution with low diversity, and speciation into different clusters of viruses. In our models we consider few simple ingredients governing the interactions between viruses and immune systems in an abstract framework, namely the mutations of viruses in phenotypic space, the recognition of viruses by immune receptors, the immune repertoires update and the epidemiological spread of viruses in a population. In these minimal models at the population level immune systems drive viruses onto a set of interesting evolutionary patterns that we map onto the model parameters. These can be qualitatively observed in nature.

So far we introduced some ideas of evolution at the scale of populations, but evolution acts primarily at much finer molecular scales through modifications in some gene. This gene will therefore be present in nature with some diversity, that will reflect in a certain amount of variability in the amino-acid sequences of the corresponding protein. The resulting set of proteins from the same gene mutants constitute a family of proteins. These have to fulfill precise functions in the cell. If some sequence variation undermines the protein functional effectiveness the cells expressing the "faulty" gene will go extinct because of natural selection. So also at this scale selection enforces constraints on the diversity that a family of functional proteins can display. Note that this is a conceptual example; the term "family" in the remainder of this thesis will have a different meaning as it does not necessarily consist of proteins expressed from mutants of the same gene.

In the second part of the thesis we will exploit the enormous amount of protein sequence data to extract information on the evolutionary constraints acting on protein families. We will couple an inference scheme to computational models to address how functional constraints reduce and shape the global space of protein sequences that survive selection. Then we will exploit the same framework to address what microscopic evolutionary mechanisms may generate specific intra-sequence high order statistical patterns, that are recurrently observed in the protein families under study.

statistical mechanics offers a theoretical framework to study evolution

Evolution is characterized by a great degree of intrinsic stochasticity in mutations, selection and also from the fact that populations are formed by a finite number of individuals. It follows automatically that stochastic processes, and more generally statistical physics, are a great theoretical framework to study evolutionary dynamics.

We discussed above that evolution, as well as many other biological systems, sees incredibly many microscopic constituents following complicated dynamics. The result of these dynamics can be summarized at the population level by coarse-grained observables. Moreover the interaction between microscopic constituent can produce the emergence of simple patterns at the population level. Statistical mechanics describes a system composed of many constituents by adopting a probabilistic framework that aims at quantitatively predicting macroscopic observables, that characterize the system. Typically, when the microscopic constituents interact, statistical mechanics models predict the emergence of simple patterns in the system behavior, which in physics are called phase transitions. This is another hint that statistical mechanics offers a suitable theoretical framework for studying evolution.

In the first Part of the thesis we exploit tools from out-of-equilibrium statistical mechanics to study the emergence of patterns from simple interaction rules between viruses and immune systems.

In the second Part we largely use equilibrium statistical mechanics ideas to characterize the macroscopic observables arising from a probabilistic description of protein sequences.

thesis organization

The rest of this thesis is structured into three parts. In Part i we study how the population level immune systems constrain the evolutionary path of viruses, which constantly try to escape the immune memory updates. Specifically in Chapter 2 we introduce the co-evolving system under study consisting of the arms race between pathogens and immune systems. This system couples different timescales, the immune response at the individual level, the epidemiological spread in a population, and the evolutionary dynamics of viruses. We introduce the main technical tools used later on, largely coming from out-of-equilibrium statistical mechanics. We then introduce some relevant conceptual ideas, recurrent in models of evolution and epidemiology.

In Chapter 3 we study numerically a minimal agent based model for the evolution of viruses that give rise to acute infections. We address how qualitatively different evolutionary patterns, which can be observed in the natural evolution of some viruses, arise at the population level from the microscopic interactions between viruses and immune systems. This Chapter is a direct copy of the work published in [START_REF] Marchi | Multi-lineage evolution in viral populations driven by host immune systems[END_REF].

In Chapter 4 we study a coarse grained theoretical model for the evolution of viruses in antigenic space, driven by the population immune systems. We obtain some analytical insights on this process as well as on the interplay of the different timescales constituting this phylodynamic system, and we validate them against numerical simulations. This Chapter presents some results from a work currently in progress (Marchi Mora Walczak, in preparation).

In Part ii we use available protein sequence data to infer some mechanisms and constraints driving the evolution of some repeat-protein (formed by tandem arrays of many similar repeated units) families. In Chapter 5 we give a broad overview on inferring proteins evolutionary features from sequence statistics. We introduce the equilibrium statistical mechanics and inference tool used in the rest of Part ii. We discuss briefly the connection between these two broad subjects and how they can be used on proteins. We finally give a brief introduction on the specific biological system we will study: repeat proteins. Chapter 6 addresses how inferred local constraints on amino-acid sequences (representing the functional constraints imposed on proteins families by evolution) affect the size and the shape of the accessible sequence space. This Chapter is a direct copy of the work published in [START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF] In Chapter 7 we address the interplay between evolutionary constraints and phylogenetic correlations in repeat tandem arrays. We investigate the evolutionary mechanisms giving rise to the empirically observed inter-repeat statistical patterns. This Chapter is part of a work in progress, in collaboration with Ezequiel Galpern and Diego Ferreiro (Marchi Galpern Ferreiro Mora Walczak, in preparation).

Part iii, consisting of Chapter 8, concludes summarizing and discussing the main contributions presented in this thesis, and suggests some ideas for future research directions.

Part I I M M U N E S Y S T E M S C O N S T R A I N T H E E V O L U T I O N A R Y PAT H S O F V I R U S E S

PAT H O G E N S A G A I N S T I M M U N E S Y S T E M S , A N A R M S R A C E A C R O S S T I M E S C A L E S

background and motivation

During the course of evolution across the whole tree of life immune systems have developed more and more complicated defense systems, which exploit several layers of defense to protect organisms from a huge diversity of pathogens [START_REF] Medzhitov | Recognition of microorganisms and activation of the immune response[END_REF][START_REF] Murphy | Janeway's Immunobiology. Janeway's Immunobiology[END_REF]. Even some of these pathogens, bacteria, have to defend themselves from other pathogens, such as bacteriophage viruses.

Depending on the branch of the tree of life the strategies and actors involved in the immune protection can change. Vertebrates are the organisms with the most complex immune system. A first layer of protection is provided by the innate immune system, which is present in invertebrates as well. This provides an immediate generic response able to distinguish self from non-self, targeting the latter, but is not highly specific to any subsets of pathogens, therefore it can be inefficient against rare or dynamically changing pathogens. This immune system layer evolves passively by random mutations and the selected variants are inherited by the organism progeny, therefore the innate immune system adapts through natural selection on evolutionary timescales which are dictated by the organism reproduction time.

A more specific and effective protection is provided by the adaptive immune system [START_REF] Danilova | The evolution of immune mechanisms[END_REF], which is evolutionary newer and as such is only present in (most) vertebrates. This layer of immune defense is mainly constituted by B and T cell lymphocytes, which express on their surface some receptors that are able to bind with high specificity to some proteins present on the surface of pathogens, called antigens. Once the lymphocytes recognize an antigen binding to it, the immune system responds by producing cells and/or enzymes able to identify and destroy the pathogens presenting that antigen. Moreover during an infection the lymphocytes specific to that pathogen are positively selected and are amplified by several orders of magnitude [START_REF] Macfarlane | A modification of Jerne's theory of antibody production using the concept of clonal selection[END_REF]. A fraction of these lymphocytes, the memory cells, is retained for long times after infection, so that the adaptive immune system carries memory of past infections and is ready to clear efficiently further infections by the same pathogen [START_REF] Farber | Human memory T cells: Generation, compartmentalization and homeostasis[END_REF].

Therefore the diversity of the receptors present in the immune systems is key to providing an efficient protection from the many pathogens in the environment [START_REF] Callan | Repertoire sequencing and the statistical ensemble approach to adaptive immunity[END_REF]. This diversity is generated through a set of complex mutations/insertions/deletions/recombinations events in the lymphocyte genes encoding parts of the receptors [START_REF] Elhanati | Quantifying selection in immune receptor repertoires[END_REF][START_REF] Ndifon | Chromatin conformation governs T-cell receptor Jβ gene segment usage[END_REF]. Then it is shaped and constrained by natural selection dictated by recognition of infecting pathogens and to avoid the recognition of macromolecules belonging to the self [START_REF] Murphy | Janeway's Immunobiology. Janeway's Immunobiology[END_REF]. The outcome of the adaptive immune system evolutionary dynamics is not inherited by the progeny, so this consists of a system that adapt to sudden changes in the pathogenic environment within the organism lifespan, on much faster timescales than the innate immune system.

These mechanisms create an eco-evolutionary experiment that takes place in parallel in any individual under similar initial conditions. Recent technological developments in sequencing techniques opened a window into these processes taking place within each one of us [START_REF] Boudinot | New perspectives for large-scale repertoire analysis of immune receptors[END_REF][START_REF] Six | The Past, Present, and Future of Immune Repertoire Biology -The Rise of Next-Generation Repertoire Analysis[END_REF][START_REF] Weinstein | High-Throughput Sequencing of the Zebrafish Antibody Repertoire[END_REF], offering a unique opportunity to address open questions on the fundamental principles underlying evolution. This newly available information can be exploited to refine the theoretical tools in our hands to reach a more thorough understanding of evolutionary mechanisms and to predict evolutionary outcomes over longer timescales [START_REF] Lässig | Predicting evolution[END_REF].

An important characteristic of the adaptive immune system is that pathogens recognition by lymphocyte receptors is not only highly specific, but is also cross-reactive [START_REF] Mason | A very high level of crossreactivity is an essential feature of the T-cell receptor[END_REF][START_REF] Sewell | Why must T cells be cross-reactive?[END_REF][START_REF] Venturi | The molecular basis for public T-cell responses?[END_REF][START_REF] Zarnitsyna | Estimating the Diversity, Completeness, and Cross-Reactivity of the T Cell Repertoire[END_REF], meaning that the same receptor can recognize different antigens, typically closely related from a molecular point of view. Since the number of possible antigens is much higher than the number of immune cells in an individual, cross-reactivity is necessary to ensure protection from the pathogenic environment.

At the same time pathogens constantly evolve and adapt to escape the immune systems, in order to survive. When a pathogen spreads through a host population, it always needs susceptible hosts, i.e. hosts that do not carry preexisting immune memory against it, in order to proliferate. At the same time when infecting new hosts it triggers their immune response, contributing to the population level protection against itself and similar pathogens (through the cross-reactivity introduced before). Therefore if the pathogen spreads too fast through a consistent fraction of the population before previously infected hosts lose their acquired immunity, or are substituted by naive newborns that carry no immune memory, it needs to find some new niche of hosts to infect. If it is infectious enough it can achieve this by spreading to a new geographical area poorly connected with the previous one, or it can evolve by random mutations and immune driven selection away from the existing population immune coverage. If it fails in doing so the pathogen disappears after a fast epidemic outbreak, as it is thought to have been the case for the Zika virus in the Americas [START_REF] Kathleen | Projecting the end of the Zika virus epidemic in Latin America : a modelling analysis[END_REF].

The former is a simple conceptual sketch that holds in most cases. The situation can be more complicated if hosts are not able to mount an efficient immune response to clear the pathogen infection as in chronic or persistent infections, if the pathogen causes the quick death of a considerable fraction of infected hosts -which is a relatively rare situation in evolutionary perspective since this is also unfavorable for pathogens that die with their host -or if the pathogen suddenly increases or changes hosts pool by performing a "spillover" to a different hosts specie. These more complex dynamics go beyond the scope of this work.

The complex interaction between pathogen evolution and immune system adaptation couples processes at different scales such as the immune response to infections, the epidemiological dynamics of pathogens in a hosts population and the long-term evolution of pathogens and populations of im-mune systems. The resulting multi-scale process is sometimes referred to as phylodynamics [START_REF] Grenfell | Unifying the Epidemiological and Evolutionary Dynamics of Pathogens[END_REF].

Depending on the relative speed of pathogen vs immune system adaptation, which in turn impacts the epidemiological timescale of infections, this process can generate very different evolutionary scenarios. For instance some RNA viruses like measles evolve slowly compared to the range of cross-reactivity of responding immune receptors and therefore typically can only infect an individual once in its lifetime. These viruses spread through epidemiological bursts of short infections that exhaust the pool of susceptible individual in certain geographical regions. The resulting phylogenetic patterns do not show strong selection signatures, with many strains that coexist for decades driven by non-selective spatio-temporal epidemiological dynamics [START_REF] Grenfell | Unifying the Epidemiological and Evolutionary Dynamics of Pathogens[END_REF].

On the opposite side of the spectrum we find rapidly mutating RNA viruses like HIV, which are so efficient in escaping the mounting immune response that the immune system is unable to clear the infection. This gives rise to lifelong persistent infections with strong intra-host natural selection on the virus [START_REF] Grenfell | Unifying the Epidemiological and Evolutionary Dynamics of Pathogens[END_REF].

In between these extremes there are a range of pathogens that evolve moderately fast, such as influenza A, which triggers acute infections that are cleared by the immune system after a short period of time ( ∼ 3 -7 days) [START_REF] Nicholson | Textbook of Influenza. Blackwell Science[END_REF]. After infections hosts are immune to similar viral strains, but flu mutates fast enough so that the acquired adaptive immune protection becomes outdated compared to the new circulating strains. The same individual can be re-infected by newer flu strains typically after ∼ 5 -10 years [START_REF] Bedford | Integrating influenza antigenic dynamics with molecular evolution[END_REF][START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF][START_REF] Neher | Prediction, dynamics, and visualization of antigenic phenotypes of seasonal influenza viruses[END_REF][START_REF] Smith | Mapping the Antigenic and Genetic[END_REF], so that flu constantly replenishes the pool of susceptible individuals. At the same time influenza undergoes fierce selection driven by the immune systems of the host population, which constrain its escape evolutionary path by limiting its diversity and canalizing its phylogenetic tree along one main trunk of evolution [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Hadfield | Nextstrain: real-time tracking of pathogen evolution[END_REF][START_REF] Velislava | The evolution of seasonal influenza viruses[END_REF][START_REF] Rambaut | The genomic and epidemiological dynamics of human influenza A virus[END_REF]. The resulting phylogenetic pattern turns out to be very similar to that of intra-host HIV evolution. HIV is fast enough to trigger a long-lasting co-evolutionary dynamics with single hosts adaptive immune systems [START_REF] Grenfell | Unifying the Epidemiological and Evolutionary Dynamics of Pathogens[END_REF], rather than with the totality of population immune systems, which adapt more slowly as a whole.

Generally, if pathogens persist for long enough times across several epidemic cycles, the complex interaction with immune systems gives rise to an ongoing out-of equilibrium co-evolutionary dynamics. Immune systems adapt to protect from pathogens, "chasing " them, and at the same time they constrain the possible ways pathogens can evolve to escape their protection, driving the resulting pathogens evolution on a reduced set of drastically different solutions.

It is yet poorly understood in what ways the microscopic interactions between pathogens and immune systems at the immune response and epidemiological scale generate few collective evolutionary patterns at the population level [START_REF] Grenfell | Unifying the Epidemiological and Evolutionary Dynamics of Pathogens[END_REF]. Understanding this multi-scale process more thoroughly, and developing theoretical predictive frameworks, carries an obvious applicative interest since it is tightly coupled to efficient vaccine design and to limiting the emergence of drug resistance and of new diseases. There is also an intrinsic theoretical interest in studying these co-evolutionary dynamics in order to pinpoint the central principles shaping and directing evolution, and to understand what are the key modeling ingredients necessary to predict future evolutionary outcomes from past information [START_REF] Lässig | Predicting evolution[END_REF].

The first part of this thesis studies two theoretical minimal models coupling epidemiological to evolutionary dynamics, adopting a different degree of coarse-graining. These aim precisely at addressing what few simple ingredients are necessary to produce different evolutionary patterns which qualitatively resemble some of those empirically observed, and how the microscopic dynamics constrain those patterns. We do so following the line of a few other works taking similar perspectives [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Julia | Dynamics and selection of manystrain pathogens[END_REF][START_REF] Grenfell | Unifying the Epidemiological and Evolutionary Dynamics of Pathogens[END_REF][START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225].

Given the stochasticity and the out-of-equilibrium nature of evolutionary processes the natural framework to address these questions is provided by out-of-equilibrium statistical mechanics. Below we introduce some basic technical concepts that are going to come in handy later on, and then we highlight their connection to evolution and some other theoretical concepts that are ubiquitous in this first part.

technical tools: stochastic processes and numerical simulations

As mentioned above, the techniques exploited in the first half of the thesis are borrowed from statistical mechanics. Historically this theoretical framework was first formulated to describe physical systems at equilibrium, meaning that no net energy flow is present between the various microstates composing the system, therefore no energy is dissipated and no entropy is produced. The second part of the thesis relies heavily on tools from equilibrium statistical mechanics, and a quick outline of basic equilibrium statistical mechanics concepts can be found in 5.2, as well as some relevant historical remarks.

But evolution of populations is so intrinsically out of equilibrium, with many irreversible transitions such as extinctions and organisms exploring always new evolutionary strategies, that in the first part we will exclusively adopt out of equilibrium techniques. Therefore here, unconventionally, we first introduce basic techniques belonging to out-of-equilibrium statistical mechanics, despite these would come second both historically and conceptually.

Markov processes

A stochastic process is defined as a collection of random variables living in some measurable space, X ∈ S. So if the process evolves with time within a certain time interval T we can write it as {X(t) : t ∈ T } ∈ S T . Upon sampling a finite number of times, the process is characterized by the probability of observing a specific sequence of events P(X 1 = x 1 , t 1 ; X 2 = x 2 , t 2 ; . . . ; X n = x n , t n ), where we denoted X(t 1 ) = X 1 for brevity.

A Markov process is a particular type of stochastic process that has the property of being memoryless. Therefore the outcome of the process at step n + 1 depends just on the state of the process at step n, without an explicit dependence on the process history. Formally this means that the probability distribution of the process P(x 1 , t 1 ; x 2 , t 2 ; . . . ; x n , t n ) obeys the following relation :

P(x n+1 , t n+1 |x 1 , t 1 ; x 2 , t 2 ; . . . ; x n , t n ) = P(x n+1 , t n+1 |x n , t n ) , (1)
and P(x n+1 , t n+1 |x n , t n ) defines the transition probability from state x n to state x n+1 . It's easy to see from (1) that the Markov process is entirely defined by the set of transition probabilities between all system states at all times, plus the initial condition P(x 1 , t 1 ). An important special case of Markov processes are time-homogeneous Markov processes, where the transition probability P(x n+1 , t n+1 |x n , t n ) only depends on t n+1 -t n .

If one considers the discrete-states version of a (time-homogeneous) Markov process, sometimes called Markov chain, the totality of transition probabilities can be recapitulated in the transition matrix T. T x,y = P(X n+1 = x, n + 1|X n = y, n) if x = y, and T x,x = 1y P(X n+1 = y, n + 1|X n = x, n) that is probability of not undergoing any transition between n and n + 1where we discretized time too. In this case from (1) the probability P(n) distribution for any state x at time n is given by:

P(n) = T • P(n -1) , (2)
or in the continuous time version

dP dt (t) = (T -1) • P(t) . (3)
This equation, describing the time evolution of the probability distribution, is called Master Equation.

A Markov process is said to be at steady state if its probability distribution does not depend on time, therefore if

dP dt (t) = 0 . (4)
Note that the concept of steady state is not limited to Markov processes, as it is applicable to any stochastic process under a more general condition. If the process is ergodic, which means that the probability of reaching any state from any other state in a finite number of time steps is greater than 0, the transition matrix is irreducible and the Perron-Frobenius theorem ensures the existence of a unique steady state distribution P s , that is the largest eigenvector of T.

The generalization of (3) to continuous states can be seen in the context of (time-homogeneous) Markov jump processes, where a jump from state x to [x , x + dx ) in an infinitesimal time interval dt happens with rate W(x |x)dx = lim dt→0 P(x ,t+dt|x,t)dx dt

. Now the master equation reads

∂P(x, t) ∂t = dx [W(x|x )P(x , t) -W(x |x)P(x, t)] . (5)

Fokker-Plank and Langevin equations

If the jump rates W(x |x) are peaked at x, and therefore the process consists of many small jumps, the master equation in ( 5) can be Taylor expanded till the second order in |x -x| through the Kramers-Moyal expansion, yielding the so-called Fokker-Plank equation:

∂P(x, t) ∂t = - ∂ ∂x [α 1 (x)P(x, t)] + 1 2 ∂ 2 ∂x 2 [α 2 (x)P(x, t)] , (6)
where

α n (x) = dx (x -x) n W(x |x) . ( 7
)
The Fokker-Plank equation represents a diffusion process, and can be used to describe many physical phenomena. In physics the first and second moments of the jump kernel α 1 (x) and α 2 (x) are usually called drift and diffusion coefficient respectively. Thanks to this approximation we reduced the dimensionality of the problem from the number of states in the system (eq. ( 3)) to 1 -times the dimensionality of the space S, but here we are presenting the 1-dimensional case for brevity. Hence we are left with a problem that is in principle easier to solve. This turns out to be an accurate approximation for many systems, even when the process is not rigorously Gaussian and moments higher than the second could play a role.

Sometimes the partial differential equation ( 6) can still be hard or even impossible to solve analytically. It can be more practical to study the individual realizations of the stochastic process x(t). The equation governing their dynamics will be a stochastic differential equation of the form

dx(t) dt = µ(x) + σ(x)ξ(t) , (8)
where ξ(t) is the noise term, generally assumed to be Gaussian and δcorrelated (white noise) as ξ(t)ξ(t ) = δ(t -t ), with 0 average ξ(t) = 0.

Eq. ( 8) is ambiguous. When integrating it, passing from discrete sums to continuous integrals, we have to define where sums are evaluated in the infinitesimal interval due to the δ correlated stochastic term. For the considerations below to be valid Eq. ( 8) has to be understood in Ito convention (more details in [START_REF] Gardiner | Handbook of Stochastic Methods for Physics, Chemistry, and the Natural Sciences[END_REF]). Eq. ( 8) implies that the stochastic process realization can be formalized with such an equation consisting of the average deterministic term µ(x) plus an approximate noise term. The deterministic term is sometimes easier to derive from the microscopic ingredient of a model rather than the transition probabilities involving the whole state space appearing in the master equation.

The single realizations description of (8) and the whole probability distribution description of (6) can describe the same stochastic process, and one can transform one into the the other substituting α 1 (x) = µ(x) and

α 2 (x) = σ(x) 2 .
This concludes our brief introduction on stochastic processes. For a more complete, thorough and pedagogical introduction we refer the reader to check [START_REF] Godfried | Stochastic processes in physics and chemistry[END_REF].

Numerical simulations of stochastic processes

Some times one is able to define a stochastic model to describe a system under study, but the analytical progress that can be done on such model can be very limited. And other times it may even be impossible to write down equations from the set of basic ingredients defining the model. Fortunately there are several computational techniques that can help to study the model behavior and compare its prediction with the modeled phenomenon even in such cases.

First, from the differential equations we can directly find numerical approximation to their solutions. Even for the Langevin equation ( 8) there is a generalization of the Euler method to stochastic differential equations, called Euler-Maruyama algorithm [START_REF] Gardiner | Handbook of Stochastic Methods for Physics, Chemistry, and the Natural Sciences[END_REF] as well as higher order methods.

Another approach is to simulate directly the set of rules defining the model through a broad class of computational algorithms that rely on generating (pseudo-)randomness and then sampling from it. These methods are called Monte Carlo. They were introduced and systematically used by Ulam and von Neumann while studying neutron diffusion at the Los Alamos National Laboratory during World War II. The name Monte Carlo was the code name of their work, secret at the time. It was inspired by the eponymous Casino in Monaco, and it was proposed by Metropolis because allegedly Ulam's uncle "would borrow money from relatives because he just had to go to Monte Carlo" [START_REF] Metropolis | The beginning[END_REF].

The idea underlying Monte Carlo is to reproduce the model dynamics by drawing samples from the corresponding probability distribution. In the first part of the thesis we will use Monte Carlo methods to simulate processes that are not necessarily at equilibrium nor at steady state. In the second half we will use this scheme to simulate a system at equilibrium drawing from the desired Boltzmann distribution using the Metropolis-Hastings algorithm, and then we will use a Markov chain Monte Carlo designed to reproduce the desired steady state distribution of an out-of-equilibrium system. Note that even if here we introduce these algorithms in the context of stochastic processes, their scope is broad enough that they can be used to tackle purely deterministic problems such as solving integrals, by virtue of the fact that for many i.i.d. random variables the sample average and the ensemble average converge due to the law of large numbers.

For a detailed introduction to Monte Carlo methods and an overview of many applications in physics and chemistry we refer the reader to check [START_REF] Allen | Computer Simulation of Liquids[END_REF] More precisely, in Chapter 3, which is the direct copy of the published work in [START_REF] Marchi | Multi-lineage evolution in viral populations driven by host immune systems[END_REF], we will study a model coupling viral evolution, epidemiological dynamics and immune memory by means of an agent based Monte Carlo simulation. This is a computational model that explicitly considers a great number of agents, in our case hosts and viral strains. It is based on a set of rules governing the interactions between these agents, for instance infections , immune update, mutations and selection, which define the microscopic ingredients of the model, and in our case carry intrinsically random features. The algorithm advances the time evolution of the system simulating the simultaneous "actions" and interactions of all of the components according to the few rules governing them. The goal is to study how these microscale dynamic interactions produce complex pattern in the system as a whole, in our case meaning at the population level.

The strength of this computational approach lies in the clarity and intuitiveness of the microscopic ingredients of the model, which the modeler is free to gauge to attain the desired level of detail. Therefore agent based models can be used to build accurate and realistic generative simulations of complex systems without the need to rely on many assumptions. The weakness of this approach lies in its high computational cost due to the huge number of agents that need to be modeled explicitly, which severely limits its practical applications unless a sufficient amount of computational resources are available. This drawback is further stressed by the fact that the emergent behavior and the relative importance of stochasticity as a confounding factor depend strongly on the population size [START_REF] Lysenko | A Framework for Megascale Agent Based Model Simulations on Graphics Processing Units[END_REF].

To overcome this limitation in studying the model behavior and scaling, as well as to be able to perform some analytical progress that may reveal some universal feature of the studied phenomenon, in Chapter 4 we study a more coarse-grained model consisting of a system of stochastic reaction-diffusion equations. These are Langevin equations of the form [START_REF] Andrade | Protein Repeats: Structures, Functions, and Evolution[END_REF] where the random variable is an high-dimensional object describing the state of a whole population. To complement the analytics we study the model numerically with another kind of Monte Carlo simulation that implements the ingredients of the reaction-diffusion system on a discrete lattice, to extrapolate the relevant observable of this model: the population distribution over the lattice sites. This simulation is not agent based in the sense that we don't explicitly simulate all of the hosts and viral strains anymore, but only their relative fraction on each lattice site. More details are given in Chapter 4

conceptual tools: theoretical models of evolution and epidemiology

As we mentioned in 2.1 the first part of the thesis will study theoretical models coupling processes at different scales: immune response, epidemiological spread of pathogens in host populations and evolution. Our perspective is mainly centered on the latter aspect, therefore this introductory section is going to focus mainly on modeling evolution.

We will restrict our investigation to pathogens that produce acute infections and elicit a strong immune response producing long-lasting immune memory. Hence in our modeling of evolutionary timescales the immune systems role at the individual level can be described in a very simple coarsegrained way, with immune memory building up deterministically based on the past history of pathogens infections. When looking at different relative timescales this approximation fails and one has to explicitly consider the stochastic process governing the adaptive immune system evolution in each individual, including the ecological competition of lymphocytes during infections. Since we will not consider these dynamics, this introduction will not cover these topics. For more information on how to build theoretical models of immune responses within individuals see [START_REF] Perelson | Immunology for physicists[END_REF] and [START_REF] Altan-Bonnet | Quantitative immunology for physicists[END_REF].

In the following we give an example of how statistical mechanics can be used to model the evolution of populations. Then we introduce some concepts that are largely exploited in the literature of theoretical models for evolution, which will be central in the first part of the thesis. We conclude with a very short introduction to mean field epidemiological models.

Diffusion equations for populations evolution

The main forces driving evolution are mutations,genetic drift and selection -and sex/recombination, but for the most part this thesis will not consider this aspect, albeit extremely important in many situations. Mutations are changes in the genome of an organism that generate new variants called mutants, increasing the diversity of a population. These are intrinsically random events, as proven by the famous Luria-Delbruck experiment [START_REF] Salvador | Mutations of bacteria from virus sensitivity to virus resistance[END_REF]. Genetic drift is the stochastic change of the frequency in a population of some mutants induced by the fact that populations consist of a finite number of individuals. Selection is the process through which mutants that are fitter for the current environment produce more offspring than the others increasing their relative fraction in the population. This also carries some degree of stochasticity due to demographic noise, which becomes relevant when the number of individuals with a given mutation is small. Due to these various sources of randomness stochastic processes are a well suited framework to study the evolution of population diversity.

As an example let's consider the Wright-Fisher model, where at each generation the population is fixed to N individuals. The population is divided in two types, i individuals will be of type A and the rest of type B. In this simplified model there are no further mutations so from a generation to the next an individual will always produce individuals of the same type. At each generation t the offspring population is sampled randomly from the population at t -1, and individuals of type A are sampled with probability ρ i , which in the neutral (no selection) case reduces to the fraction of A, f = i N . The population composition at time t is the result of N Bernoulli trials with probability ρ i therefore the transition rates from a population state i to a state j is the Bernoulli distribution of having j successes out of the Bernoulli trials N j ρ j i (1 -ρ i ) (N-j) . From this object we can write a Master equation of the form (2), therefore we are able to write the equations governing the time evolution of the stochastic process starting from the microscopic definition of the model. The analytical treatment of the master equation is very hard, but it can be studies numerically through Markov Chain Monte Carlo simulations.

Otherwise we can try to reduce it to some approximate form. In the neutral case looking at the variations of f this process has 0 mean and variance f(1 -f). When N is large we can consider f as a continuous variable. Taking the continuous time approximation and rescaling time by the population size we can write a Fokker-Plank diffusion equation for the probability of observing f at time t, ϕ(f, t):

∂ϕ(f, t) ∂t = 1 2 ∂ 2 ∂f 2 [f(1 -f)ϕ(f, t)] , (9)
which assumes that only the first two moments of ϕ matter and is amenable of analytical progress [START_REF] Kimura | Process leading to quasi-fixation of genes in natural populations due to random fluctuation of selection intensities[END_REF]. This diffusion formulation of population genetics was first introduced by Kimura in 1953 [START_REF] Kimura | Process leading to quasi-fixation of genes in natural populations due to random fluctuation of selection intensities[END_REF], who reformulated the problem in 1962 with a "backward" Kolmogorov equation, more suitable to calculate first passage times, in this case the time of fixation of mutants [START_REF] Kimura | On the Probability of Fixation of Mutant Genes in a Population[END_REF]. This formulation has been widely adopted in theoretical population genetics ever since. Equation ( 9) takes into account only genetic drift. One can introduce a selection advantage s to strain A over B, in which case

ρ i = f(s+1) f(s+1)+(1-f) .
Hence the average change in frequencies across generations is

δ f = f(s+1) f(s+1)+(1-f) - f ∼ sf(1 -f),
where in the last passage we assume s 1. The resulting diffusion equation reads

∂ϕ(f, t) ∂t = -s ∂ ∂f [f(1 -f)ϕ(f, t)] + 1 2 ∂ 2 ∂f 2 [f(1 -f)ϕ(f, t)] , (10)
therefore the selection pressure enters in the drift term of the equation. Note that even though the random population sampling in population genetic is called drift, it constitutes the diffusion term of the Fokker-Plank equation, not the drift term. The diffusion equation can be generalized further to account for other ingredients such as mutations [START_REF] Kimura | Diffusion models in population genetics[END_REF].

The selection advantage of a mutant with respect to another is also called relative fitness, which determines the expected change of frequency of a mutant in a population. One can also refer to absolute fitness, which also contain information on the time evolution of the total population size N(t).

From genotypes to phenotypes to fitness: cross-reactivity in recognition space

So far we have introduced mutations that generate diversity introducing mutants in the population, and selection that determines the relative success of different mutants in the population. But we haven't specified in what space mutations act and what traits are selected.

The information regarding organism features is (partly) encoded in their genome, or genotype. This dictates the expression of proteins in cells via transcription and translation that in turn build up the phenotype of the organism. Actually phenotype is not entirely determined by genotype since there are many sources of noise and errors when translating DNA into proteins and in the proteins function. Even knowing the exact genome of an organism it's very hard to predict its phenotype, a problem known as genotype-phenotype mapping. But in the context of evolution genotype is regarded as the main entity encoding information on phenotype, and mutations usually denote changes in the genome, also because only those changes are heritable and propagate through generations.

Then natural selection acts on some collective traits arising from the phenotype, and such traits largely depend on the environment and on the context in which selection acts. This adds a further layer of complication to the path from genotype to fitness, provided that such fitness can be defined and that it makes sense to define it as a scalar growth rate, which is a concept that has been challenged in recent works [START_REF] Tikhonov | Innovation rather than improvement: a solvable high-dimensional model highlights the limitations of scalar fitness[END_REF].

Keeping these caveats in mind when modeling evolution we have to choose in what space our model will live, whether genotypic, phenotypic or fitness. In the context of modeling co-evolution between viruses and immune receptors many previous works embedded theoretical models directly in phenotypic space and then defined a non-linear scalar function to map phenotype to fitness [START_REF] Altan-Bonnet | Quantitative immunology for physicists[END_REF][START_REF] Perelson | Immunology for physicists[END_REF]. This was done for example by considering the string matching problem between antigens and immune receptors that aims at modeling the binding affinity between them, as a proxy for the probability that a receptor recognizes an antigen. Previous works considered either strings of aminoacids [START_REF] George | Effects of thymic selection on T cell recognition of foreign and tumor antigenic peptides[END_REF][START_REF] Košmrlj | How the thymus designs antigen-specific and self-tolerant T cell receptor sequences[END_REF], or binary strings [START_REF] Nourmohammad | Host-Pathogen Coevolution and the Emergence of Broadly Neutralizing Antibodies in Chronic Infections[END_REF], or even sequences of abstract objects determining the antigens and immune receptors features in an abstract shape space [START_REF] Detours | A quantitative theory of affinity-driven T cell repertoire selection[END_REF][START_REF] Perelson | Theoretical studies of clonal selection minimal antibody repertoire size and reliability of self non self discrimination[END_REF]. In this framework cross-reactivity emerges naturally from the fact that antigen strings being more similar will also have similar affinity to a given immune receptor string.

One can take a further abstraction step and consider an unspecified phenotypic space. Both antigens and immune receptors can be thought of as points in this space, each set of coordinates characterizing a phenotype [START_REF] Sasaki | Evolution of antigen drift/switching: continuously evading pathogens[END_REF]. Then the probability that a receptor ad position x recognizes an antigen at position y P(x, y) can be modeled as a decreasing function of the distance between them on this abstract space ||x -y|| [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Mayer | How a well-adapted immune system is organized[END_REF][START_REF] Mayer | How a well-adapting immune system remembers[END_REF], which is why we call this space recognition space. The shape and strength of this dependence are set by the cross-reactivity kernel H(||x -y||, d) which depends on a typical recognition width d, so that P(x, y) ∝ H(||x -y||, d), as sketched in Figure 1. These ingredients determine the fitness f(x) of a virus at position x facing a population of immune receptors distributed in recognition space as h(x ):

f(x) = F h(x )H(||x -x ||, d)dx , (11)
where F is an arbitrary non-linear function mapping phenotype to fitness, and in this case it has to be decreasing since its argument is the convolution between cross reactivity kernel and immune protection. The other process embedded in this phenotypic space are mutations, which can be seen as jump where the jump length is drawn from some distribution with average mutation effect σ. Therefore σ d sets the scale of the recognition space. The dimensionality of such a recognition space is still an open question. Restricting the scope to viruses, specifically to flu, previous works have analyzed the antibody response when presenting different viral strains to blood sera from ferrets, containing different antibodies mixtures. The different resulting immune responses can be used to place viral strains in a common phenotypic space, called antigenic space, and it was shown that reducing the dimensionality of such space to 2 dimensions reproduces strikingly well the evolutionary patterns observed at the level of genotype [START_REF] Smith | Mapping the Antigenic and Genetic[END_REF]. With this technique it was shown that influenza A evolution is centered on a relatively straight line in this reduced antigenic space [START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF]. Motivated by these experimental results in the following two Chapters we will consider bi-dimensional recognition spaces, such as the one in Figure 1.

Some inference works on influenza phylogenies included an effective interstrain interaction term in viral strain fitness accounting for the immune pressure from the population immune memory, that relies on the concept of cross-reactivity. The resulting model was very successful in predicting short time flu evolution from past strains [START_REF] Luksza | A predictive fitness model for influenza[END_REF]. For a specific review on predictive models for influenza see [START_REF] Morris | Predictive modeling of influenza shows the promise of applied evolutionary biology[END_REF]. Whatever the modeling choice may be, the role of cross-reactivity is central in shaping pathogens-immune interactions.

Evolution in structured and fluctuating fitness landscapes

As we hinted in sec. 2.3.2 the map from phenotypic traits to fitness depends on the environment that the population is experiencing. In nature such environment can fluctuate drastically and unpredictably -think for example about a population of bacteria infecting an host that suddenly is attacked by the immune system or antibiotics.

In the past many theoretical models based on out-of-equilibrium statistical mechanics and information theory addressed the central question of how organisms cope with randomness in the environment [START_REF] Chevin | Adaptation, plasticity, and extinction in a changing environment: towards a predictive theory[END_REF][START_REF] Nicholas W Frankel | Adaptability of nongenetic diversity in bacterial chemotaxis[END_REF][START_REF] Tetsuya | Fluctuation relations of fitness and information in population dynamics[END_REF]103,[START_REF] Mayer | Diversity of immune strategies explained by adaptation to pathogen statistics[END_REF][START_REF] Mayer | Transitions in optimal adaptive strategies for populations in fluctuating environments[END_REF][START_REF] Rivoire | Informations in models of evolutionary dynamics[END_REF][START_REF] Rivoire | The value of information for populations in varying environments[END_REF][START_REF] Skanata | Evolutionary Phase Transitions in Random Environments[END_REF][START_REF] Sughiyama | Steady-state thermodynamics for population growth in fluctuating environments[END_REF]. In this situation organisms may either adapt by passive selection acting over the population diversity, generated by stochastic transition between phenotypes -bet hedging strategy -or actively sense the environment to switch to the most convenient type. Some works addressed what strategy is optimal with respect to some gain function, the long term population benefit, taking into account short term fitness and sensing costs. The optimal strategy typically depends on the statistics and timescales of environmental fluctuations [103,[START_REF] Mayer | Diversity of immune strategies explained by adaptation to pathogen statistics[END_REF][START_REF] Mayer | Transitions in optimal adaptive strategies for populations in fluctuating environments[END_REF][START_REF] Rivoire | The value of information for populations in varying environments[END_REF][START_REF] Skanata | Evolutionary Phase Transitions in Random Environments[END_REF].

Sometimes the active sensing evolutionary strategy has been modeled with Bayesian filtering [START_REF] Chen | Bayesian filtering: From Kalman filters to particle filters, and beyond[END_REF], or reinforcement learning [START_REF] Pack | Reinforcement learning: A survey[END_REF]. Organisms update their prior on the parameters ruling the environmental dynamics, which in turn determines their prediction of future environmental realizations, based on the history of past experiences [START_REF] Kato | Understanding Adaptive Immune System as Reinforcement Learning[END_REF][START_REF] Mayer | How a well-adapting immune system remembers[END_REF]. This approach bears strong conceptual and formal connection with the field of behavioral neuroscience [START_REF] David H Gire | Mice develop efficient strategies for foraging and navigation using complex natural stimuli[END_REF][START_REF] Kutschireiter | Nonlinear Bayesian filtering and learning: a neuronal dynamics for perception[END_REF][START_REF] Wiktor | Adaptive coding for dynamic sensory inference[END_REF][START_REF] Reddy | Learning to soar in turbulent environments[END_REF].

In sec. 2.3.2 we introduced the concept of fitness as a scalar field on some high dimensional space f(x), the fitness landscape. The idea of studying evolution in a structured fitness landscape was introduced by Wright in 1932 [START_REF] Wright | The roles of mutation, inbreeding, crossbreeding, and selection in evolution[END_REF]. Such landscape may be rugged, with many local maxima. A population will evolve towards one of those, or more in which case the population differentiates into different types, or species. The population typically will not be exactly peaked on maxima due to the entropic force introduced by random mutations. The evolution of a population in a static fitness landscape bears a formal connection with standard equilibrium statistical physics. We will present a simple example of this connection in the context of proteins evolution in sec. 6.3.2. Note that as pointed out in sec. 2.3.1 selection is defined in relative terms between mutants, therefore the selection coefficient s(x) appearing in [START_REF] Barrick | Folding landscapes of ankyrin repeat proteins : experiments meet theory[END_REF] corresponds to the gradient of the fitness landscape ∇ x f(x). Now s depends explicitly on x since we are considering a continuous infinity of mutants that could arise in the population.

From what we said at the beginning of this section we can see that such a static landscape picture is not realistic in many real-life scenarios. This idealization was generalized to time-varying fitness landscapes, called seascapes [START_REF] Merrell | The Adaptive Seascape: The Mechanism of Evolution[END_REF]. In this time varying situation, fitness alone cannot be used to compare populations at different times to measure adaptation. If now we call x i the composition of type frequencies in the population at sampled time t i , we can define the cumulative fitness flux of some evolutionary path as ϕ = i ∆x i ∇f(x i , t i ). This quantifies evolution in fitness seascapes because it explicitly takes into account the variations of selection coefficient with time, but not of absolute fitness that is unrelated to adaptation, as sketched in fig. 2. Fitness flux was proposed as a universal measure of populations adaptation [START_REF] Mustonen | From fitness landscapes to seascapes: non-equilibrium dynamics of selection and adaptation[END_REF][START_REF] Mustonen | Fitness flux and ubiquity of adaptive evolution[END_REF]. It was shown to generalize Fisher's fundamental theorem of evolution [START_REF] Ronald | The genetical theory of natural selection[END_REF] to explicitly consider the entropic contributions of

A B

Figure 2 -Evolution in fitness landscapes and seascapes The evolutionary history of a population is described by a series of type frequency states x = (x 0 , . . . , x n ) at times (t 0 , . . . , t n ) (here, n = 3). Evolutionary time increases between the initial state (rhombus) and the final state (square).

The cumulative fitness flux in each time interval (gray-filled vertical arrows) is the product of the frequency change ∆x i = x i+1 -x i between successive states (horizontal arrows) and the selection coefficient s(x i , t i ) of this change; the cumulative flux ϕ(x) of the entire history is the sum of these terms. (B) Evolution in a fitness seascape F(x, t). The gradient of this function defines time-dependent selection coefficients s(x, t) = ∇F(x, t). The cumulative fitness flux of a population history is defined in terms of selection coefficients and frequency changes as before. However, it no longer equals the fitness difference between initial and final population, because its definition does not include the explicit time dependence of fitness during the history that is unrelated to adaptation (unfilled vertical arrows). Figure and caption adapted from [START_REF] Mustonen | Fitness flux and ubiquity of adaptive evolution[END_REF].

mutations and genetic drift, as well as the time dependence of the fitness seascape that can drive the system out of equilibrium, in which case the population will continue to adapt to the new environmental challenges and the total fitness flux will be positive [START_REF] Mustonen | Fitness flux and ubiquity of adaptive evolution[END_REF].

The concepts of evolution in fluctuating environments and in structured time-varying fitness landscapes are relevant to co-evolutionary systems and certainly to the situation we will study in the next two chapters, since each of the two stochastically evolving populations determines the environment of the other. We decided to introduce them here briefly for sake of completeness, even though none of the modeling frameworks mentioned in this section is formally used in this thesis. The central aspect that is missing in these formalisms to generalize to co-evolution is the explicit feedback of the population stochastic evolutionary path onto the history of the environment -the other population. The fitness flux formulation was adapted to account for this feedback in a recent model for in-host co-evolution of HIV and adaptive immune system [START_REF] Nourmohammad | Host-Pathogen Coevolution and the Emergence of Broadly Neutralizing Antibodies in Chronic Infections[END_REF].

Traveling wave theory of adaptation

Adaptation in asexual populations has been the object of many theoretical investigations that focused on the role of clonal interference [START_REF] Philip | The fate of competing beneficial mutations in an asexual population[END_REF][START_REF] Wilke | The speed of adaptation in large asexual populations[END_REF] Individuals can mutate, replicate ("birth"), and be eliminated from the gene pool ("death"), as illustrated. These simple dynamical rules give rise to a distribution of growth rates resembling a bell-like curve at steady state, which propagates toward higher growth rates like a solitary wave. is the fact that multiple strains circulate at the same time competing against each other. These works originally studied the effect of mutations of different strength neglecting multiple small mutations on the same lineage, and assuming they all start from the same fitness background. More recent works have taken the opposite approximation, hence they considered many small mutations of the same strength arising from different fitness backgrounds [START_REF] Brunet | The stochastic edge in adaptive evolution[END_REF][START_REF] Michael | Beneficial mutation selection balance and the effect of linkage on positive selection[END_REF][START_REF] Igor M Rouzine | The solitary wave of asexual evolution[END_REF]. These find that the fitness distribution f(x) of the population forms a coherent wave which travels with constant speed v towards higher fitnesses -but remember that fitness is defined in relative terms, especially in these models -leaving its shape unaltered. Some later models generalized the ingredients to account for clonal interference from different fitness background, multiple mutations, and variable mutations effects at the same time [START_REF] Benjamin H Good | Distribution of fixed beneficial mutations and the rate of adaptation in asexual populations[END_REF].

A common denominator of these models is the central role of the stochasticity of the few founders constituting the nose of the fitness distribution in determining the fate of the quasi deterministic bulk of the population. The results for some observables such as the speed of the wave as a function of population size depends drastically on modeling microscopic details, like the shape of mutation effects distribution or of the fitness nose, which is sometimes heuristically modeled as a discrete cutoff to a deterministic FKPP-like equation [START_REF] Brunet | Shift in the velocity of a front due to a cutoff[END_REF][START_REF] Brunet | Effect of selection on ancestry: an exactly soluble case and its phenomenological generalization[END_REF][START_REF] Cohen | Front propagation up a reaction rate gradient[END_REF][START_REF] Tsimring | RNA virus evolution via a fitness-space model[END_REF]. In most cases the speed scales with some power of the logarithm of the population size. The ensemble of these models constitute the basis of the so-called traveling wave "theory" of adaptation. The nature of the characteristic traveling wave in fitness space is exemplified in Figure 3.

Apart from different modeling choices these works analyzed different regimes of evolutionary parameters. Some addressed the regime where the mutations rate is low compared to the strength of selection [START_REF] Michael | Beneficial mutation selection balance and the effect of linkage on positive selection[END_REF][START_REF] Benjamin H Good | Distribution of fixed beneficial mutations and the rate of adaptation in asexual populations[END_REF], whereas others re-framed the problems in terms of a diffusion equation that implicitly assumes many small mutations [START_REF] Hallatschek | The noisy edge of traveling waves[END_REF][START_REF] Richard | E (14)[END_REF]. All of these models constrain the population size N to some extent, either exactly at any time, or on average through some autoregressive stochastic process.

Recently some models of viral phylodynamics used some results of traveling wave models to connect the timescales of epidemiology and evolution [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225]. In Chapter 4 we will adopt a similar strategy, applying to a coarse-grained phylodynamic model in phenotypic space the scalings derived in [START_REF] Cohen | Front propagation up a reaction rate gradient[END_REF]. These scalings were mapped to asexual evolution in [START_REF] Richard | E (14)[END_REF]. They consider an effective diffusion process for the distribution of fitness y, c(y, t):

∂ t c(y, t) ≈ (y -λ)c(y, t) + µ δ 2 2 ∂ 2 y c(y, t) + c(y, t)η(y, t), ( 12
)
where η is a Gaussian δ-correlated white noise, and λ constrains the mean fitness through an autoregressive process to keep the population size constant on average. Mutations happen at rate µ and carry log-fitness effect δ, drawn from some distribution with second moment δ 2 . The diffusion constant in fitness space is defined as D = µ δ 2 2 . The width of the fitness wave σ scale as a function of average population size N and fitness diffusion constant D as

σ = D 1/3 (24 ln(ND 1/3 )) 1/6 . ( 13
)
The speed of the fitness wave v is related to the width by Fisher's theorem

σ 2 = v, therefore v = D 2/3 (24 ln(ND 1/3 )) 1/3 . ( 14
)
The fittest in the population is ahead of the bulk by x c ∼ σ 4 /4D, yielding

x c ∼ 1 4 D 1/3 (24 ln(ND 1/3 )) 2/3 (15)
As mentioned above, these scalings are derived assuming a population size that is constant on average but is allowed to fluctuate over fast timescales compared to evolution -such as epidemiological timescales -and assuming the diffusion limit in eq. ( 12) which is valid if mutations are frequent and small [START_REF] Richard | E (14)[END_REF].

Epidemiological models

As introduced in sec. 2.1 our goal is to study models of pathogens evolution that explicitly consider the epidemiological spread in a host population. When modeling epidemiology, there are many possible levels of coarse graining, from agent based models, to meta-population models, to mean field coupled equation that consider the population as perfectly mixed. In many modeling applications the population structure and the network of transmissions are important to capture fundamental features of the epidemiological dynamics, but on the evolutionary timescales considered in this work the disease spread can be considered as well mixed. Therefore here we introduce the most common mean field model for epidemiology, the SIR model, and we will not touch upon other modeling perspectives. For a review of epidemiological models on structured transmission networks see [START_REF] Pastor-Satorras | Epidemic processes in complex networks[END_REF].

Mean field models for epidemiology, also called compartmental models, were first introduced in 1927 by Kermack and McKendrick [94]. In these models the population is partitioned into various compartments describing the transient situation of hosts with respect to the disease -S for susceptible, I for infected, R for recovered, D for dead, E for exposed, and many more. A set of coupled differential equation governs the transitions between the various compartments. Apart from the partitioning that completely characterize the population, there is no other structure differentiating hosts, in this sense these model can be regarded as mean field or well mixed.

The most widespread of such models is the SIR model, where the population is fixed to N hosts (in the most basic formulation) and is partitioned in three compartments, the susceptible hosts that can get infected by the pathogen, the currently infected and the recovered that were previously infected and developed immunity that prevents them to get infected againunlike in the SIRS model where after some time recovered hosts lose immunity and become susceptible again.

The time evolution of the number of hosts in each of these compartments is governed by these differential equations:

dS dt = - βIS N , dI dt = βIS N -γI , (16)
dR dt =γI ,
where β is the rate of infection per "contact" per time and γ is the rate of recovery per infection per time.

An important quantity in this model is the basic reproduction number R 0 = β γ , that is the number of new infections transmitted by an infected host in a population of susceptible subjects. When stochasticity is explicitly accounted for in the model this interpretation of R 0 holds on average. We can rewrite the equation for the number of infected as follows

dI dt = R 0 S N -1 γI . ( 17
)
This shows that if R 0 S(0) < N then dI dt < 0 and the epidemic cannot burst into an outbreak. In particular in a situation where there is no preexisting immunity in the population, due to vaccinations or otherwise, and S(0) ∼ N, R 0 = 1 separates a phase where the epidemics dies out from the opposite one where it starts with an exponential growth.

A feature of this class of models is that they consider the pathogens as a unique indistinguishable entity, with the recovered obtaining lasting immunity against all pathogen strains unconditionally. This could be a good approximation for pathogens that evolve much slower than the cross-reactivity of the corresponding lymphocyte receptors, so that effectively the immune memory they trigger is efficient against any circulating pathogen strain at all times. But this approximation is not good for the situations we plan to study where pathogens are able to evolve away from the immune memory. In this case one needs to generalize this setting to explicitly consider many pathogen mutants, and treat separately the compartments with respect to each of these mutants, for example denoting with I i the set of hosts that are infected by mutant i. Then one models the probability that immune receptors specific to mutant i are also effective against j with a cross-reactivity c ij , so that hosts recovered from i are also partially contributing to deplete the number of susceptible to j, for example as

S j ∼ N(1 - R j N )(1 -c ij R i N )
. We neglected the infected hosts as in most cases they are a subleading fraction of the population. This is conceptually similar to a fitness as defined in eq. ( 11). In the following two Chapters we will take a similar approach.

M U LT I -L I N E A G E E V O L U T I O N I N V I R A L P O P U L AT I O N S D R I V E N B Y H O S T I M M U N E S Y S T E M S

abstract

Viruses evolve in the background of host immune systems that exert selective pressure and drive viral evolutionary trajectories. This interaction leads to different evolutionary patterns in antigenic space. Examples observed in nature include the effectively one-dimensional escape characteristic of influenza A and the prolonged coexistence of lineages in influenza B. Here we use an evolutionary model for viruses in the presence of immune host systems with finite memory to obtain a phase diagram of evolutionary patterns in a two-dimensional antigenic space. We find that for small effective mutation rates and mutation jump ranges, a single lineage is the only stable solution. Large effective mutation rates combined with large mutational jumps in antigenic space lead to multiple stably co-existing lineages over prolonged evolutionary periods. These results combined with observations from data constrain the parameter regimes for the adaptation of viruses, including influenza.

introduction

Different viruses exhibit diverse modes of evolution [START_REF] Sylvain Gandon | Forecasting Epidemiological and Evolutionary Dynamics of Infectious Diseases[END_REF][START_REF] Julia | Dynamics and selection of manystrain pathogens[END_REF][START_REF] Koelle | Understanding the dynamics of rapidly evolving pathogens through modeling the tempo of antigenic change : In fl uenza as a case study[END_REF]225], from relatively slowly evolving viruses that show stable strains over many host generations such as measles [START_REF] Bryan T Grenfell | Dynamics of measles epidemics: scaling noise, determinism, and predictability with the TSIR model[END_REF], to co-existing serotypes or strains such as noroviruses [START_REF] White | Evolution of norovirus[END_REF] or influenza B [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Paul A Rota | Lineages of Influenza Type B Virus since 1983[END_REF], and quickly mutating linear strains such as most known variants of influenza A [START_REF] Smith | Mapping the Antigenic and Genetic[END_REF]. Despite the different patterns of evolutionary phylogenies and population diversity, all viruses share the common feature that they co-evolve with their hosts' immune systems. The effects of the co-evolution depend on the mutation timescales of the viruses and the immune systems, the ratio of which varies for different viruses. However, in the simplest setting, the population of hosts exerts a selective pressure on the viral population, resulting in the evolution of the viral population towards more distant areas of antigenic space from the host population. Here, we explore this mutual dynamics in a model of viruses that evolve in the background of host immune systems. While several previous studies of pathogen-immune dynamics have foccussed on specific systems [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Ben | Minimal within-host dengue models highlight the specific roles of the immune response in primary and secondary dengue infections[END_REF][START_REF] Maciej | Epidemic dynamics and antigenic evolution in a single season of influenza A[END_REF][START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF][START_REF] Sylvain Gandon | Forecasting Epidemiological and Evolutionary Dynamics of Infectious Diseases[END_REF][START_REF] Bryan T Grenfell | Dynamics of measles epidemics: scaling noise, determinism, and predictability with the TSIR model[END_REF][START_REF] Keeling | Mathematical modelling of infectious diseases[END_REF][START_REF] Koelle | Understanding the dynamics of rapidly evolving pathogens through modeling the tempo of antigenic change : In fl uenza as a case study[END_REF][START_REF] Luksza | A predictive fitness model for influenza[END_REF][START_REF] Kathleen | Projecting the end of the Zika virus epidemic in Latin America : a modelling analysis[END_REF][START_REF] Nicholas G Reich | Interactions between serotypes of dengue highlight epidemiological impact of cross-immunity[END_REF], here we study generic evolutionary patterns [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225]. Specifically, we are interested in how the host immune cross-reactivity and memory control the patterns of viral diversity.

These evolutionary processes lead to a joint dynamics that has often been modeled by so called Susceptible-Infected-Recovered (SIR) approaches to describe the host population [START_REF] Anderson | Infectious diseases of humans: dynamics and control[END_REF][START_REF] Kermack | A contribution to the Mathematical Theory of Epidemics[END_REF], possibly coupled with a mutating viral population. In their simplest form, these models have successfully explained and predicted the temporal and historical patterns of infections, such as measles [START_REF] Bryan T Grenfell | Dynamics of measles epidemics: scaling noise, determinism, and predictability with the TSIR model[END_REF], where there are little mutations, or dengue, where enhancement between a small number of strains can lead to complex dynamics [START_REF] Ferguson | The effect of antibody-dependent enhancement on the transmission dynamics and persistence of multiple-strain pathogens[END_REF]. These methods have been important in helping develop vaccination and public health policies.

Apart from a large interest in the epidemiology of viruses [START_REF] Keeling | Mathematical modelling of infectious diseases[END_REF], a large extension of SIR models has also tackled questions on the role of complete and partial cross-coverage, and how that explains infection patterns for different viruses [START_REF] Sylvain Gandon | Forecasting Epidemiological and Evolutionary Dynamics of Infectious Diseases[END_REF][START_REF] Nicholas G Reich | Interactions between serotypes of dengue highlight epidemiological impact of cross-immunity[END_REF], the role of spatial structure on infections [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF], as well as antigenic sin [START_REF] Ben | Minimal within-host dengue models highlight the specific roles of the immune response in primary and secondary dengue infections[END_REF][START_REF] Mongkolsapaya | Original antigenic sin and apoptosis in the pathogenesis of dengue hemorrhagic fever[END_REF]. Most of these questions were asked with the goal of explaining infection and evolutionary patterns of specific viruses, such as dengue [START_REF] Ben | Minimal within-host dengue models highlight the specific roles of the immune response in primary and secondary dengue infections[END_REF][START_REF] Nicholas G Reich | Interactions between serotypes of dengue highlight epidemiological impact of cross-immunity[END_REF], influenza [START_REF] Maciej | Epidemic dynamics and antigenic evolution in a single season of influenza A[END_REF][START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF][START_REF] Koelle | Understanding the dynamics of rapidly evolving pathogens through modeling the tempo of antigenic change : In fl uenza as a case study[END_REF][START_REF] Luksza | A predictive fitness model for influenza[END_REF] or Zika [START_REF] Kathleen | Projecting the end of the Zika virus epidemic in Latin America : a modelling analysis[END_REF]. Here we take a more abstract approach, aimed at understanding the role of immunological cross-reactivity and mutation distance in controlling the evolutionary patterns of diversity.

At the same time, the wealth of samples collected over the years, aided by sequencing technologies, has allowed for data analysis of real evolutionary histories for many types of viruses. One of the emerging results is the relatively low dimensionality of antigenic space -an effective phenotypic space that recapitulates the impact of host immune systems on viral evolution. Antigenic mapping, which provides a methodology for a dimensionality reduction of data [START_REF] Smith | Mapping the Antigenic and Genetic[END_REF] based on phenotypic titer experiments, such as Hemaglutanin Inhibition (HI) assays for influenza [START_REF] George | Studies of a n t i g e n i c d i f f e r e n c e s among strains of i n f l u e n z a a by means of r e d cell a g g l u t i n a t i o n[END_REF], has shown that antigenic space is often effectively low-dimensional. For example, influenza A evolution is centered on a relatively straight line in antigenic space [START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF]. This form suggests that at a given time influenza A strains form a quasispecies of limited diversity in antigenic space, with escape mutations driven by antigenic pressure moving its center of mass [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225].

We focus on a simplified model of viral evolution in a finite-dimensional space that delineates evolutionary patterns with different complexity of coexisting lineages. Recent models of these dynamics have focused only on the linear evolutionary regime relevant of influenza A [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF] or have used an infinite-dimensional representation of antigenic space [225]. Here we also model immune memory in more detail, while keeping a simplified infection dynamics with a small number of model parameters. Unlike in previous approaches, we assume a finite memory timescale. While our treatment does not account for many features of host-immune dynamics (as discussed in sections 3.3 and 3.5) it offers a stepping stone to future more in-depth analysis of the role of host repertoires.

Our analysis is motivated by different evolutionary trends observed in influenza: the single strain of influenza A compared to the two stably coexisting lineages of influenza B. Using these observations as a starting point, we study a generic model which assumes that immune receptors can recognize and remember several viruses, additionally to virus mutation and immune-driven selection and we show that these elements are sufficient to obtain specific evolutionary patterns. This model is stripped of many of the details that are undoubtedly important for the specific case of in- ing an infection, a virus attempts to infect on average R 0 hosts, however not all infections are successful. The immune repertories of some hosts can clear the virus (case of host 3) since their cross-reactivity kernels from existing memory receptors confer protection. However if the host does not have protection against the infecting virus (case of host 2), the host becomes infected. After the infection this host acquires immunity against the infecting virus. Since the virus can mutate within a given host (host 1), the infecting virus can be a mutated variant (case of host 2) with probability P mut = 1 -e -µt I and the ancestral strain that infected host 1 with rate 1 -P mut = e -µt I (case of host 3). The cross-reactivity kernel is taken to be an exponential function f(r) = exp(-r d ), meaning that viruses are recognized by receptors if they are closer in phenotypic space. Jumps are in a random direction and their size is distributed according to a Gamma distribution of mean σ and shape parameter 2. The dimensionless ratio σ/d controls the ability of viruses to escape immunity. We assume no selection within one host. fluenza, such as seasonal variability, geographic and temporal niches, crossinfections between species etc. However, thanks to its generality, our model shows that the different evolutionary trends can be obtained without calling upon niches or subpopulations, and it can be generalized to a range of fastevolving viruses that cause acute, single species host infections. Our goal is not to model the evolution of any specific virus but to identify the conditions under which different evolutionary trends emerge.

methods

The model

We implement a stochastic agent based simulation scheme to describe viral evolution in the background of host immune systems. Its main ingredients are sketched in Fig. 4. We fix the number of hosts to describe a large reservoir N = 10 7 and do not consider host birth-death dynamics. The number of hosts is chosen to be large, since we are not considering the possibility of extinction of the host reservoir. Hosts can get infected by a given viral strain if they are not already infected by it (equivalently to susceptible individuals in SIR models) in a way that the infection probability depends on the hosts infection history. Hosts are defined by the set of immune receptors they carry.

We work in a 2-dimensional antigenic space, where each viral strain and each immune receptor in every host is a point in a 2D phenotypic space. This phenotypic space is motivated both by antigenic maps [START_REF] Smith | Mapping the Antigenic and Genetic[END_REF] and shape space used in immunology to describe the effective distance between immune receptors and antigen [START_REF] Arup | Statistical mechanical concepts in immunology[END_REF][START_REF] Mayer | How a well-adapted immune system is organized[END_REF][START_REF] Mayer | How a well-adapting immune system remembers[END_REF][START_REF] Nourmohammad | Host-Pathogen Coevolution and the Emergence of Broadly Neutralizing Antibodies in Chronic Infections[END_REF][START_REF] Perelson | Theoretical studies of clonal selection minimal antibody repertoire size and reliability of self non self discrimination[END_REF][START_REF] Perelson | Immunology for physicists[END_REF][START_REF] Wang | Manipulating the Selection Forces during Affinity Maturation to Generate Cross-Reactive HIV Antibodies[END_REF]. The recognition probability of viruses by immune receptors is encoded in a cross-reactivity kernel f(r) that depends on the distance between the virus and the receptor in this effective 2D space. We take f(r) = e -r/d to be an exponential function with parameter d, that determines the cross-reactivity -the width of immune coverage given by a specific receptor [START_REF] Luksza | A predictive fitness model for influenza[END_REF].

All hosts start off with naive immune systems, implemented as a uniformly zero immune coverage in phenotypic space. If a host is infected by a virus, after the infection a new immune receptor is added to the host repertoire with a phenotypic position equivalent to the position of the infecting viral strain. Hosts have finite memory and the size of the memory pool of each host immune system M determines the maximum number of receptors in a host repertoire, corresponding to the last M viral strains that infected that host. This constraint can also be seen as the amount of resources that can be allocated to protect the host against that particular virus. In this work we set M = 5.

A new infection lasts a fixed time of t I = 3 days before the infected host tries to infect a certain number of new hosts (among those that are not already infected), drawn from a Poisson distribution with average R 0 . The timescale of 3 days is motivated by the fact that an acute infection typically lasts about a week, but transmission usually occurs early on during the infection. At this time the infection in the initial host is cleared and a memory immune receptor is added to its repertoire as explained above. During an infection a virus can mutate in the host with a rate µ. Since we concentrate on the low mutation limit, µt I 1, we limit the number of per-host mutations to at most one. Following [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF][START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF], a mutation in a virus with phenotype a produces a mutant with phenotype b with probability density ρ(a → b) = (1/2π)(4r ab /σ 2 )e -2r ab /σ (Gamma distribution with shape factor 2), where r ab is the Euclidean distance between a and b, so that the average mutation effect is σ. As a result the newly infected individual can be infected with the same ("wild-type") virus that infected the previous individual with Poisson rate e -µt I , or by a mutant virus with probability P mut = 1e -µt I for each infection event.

Not all transmission attempts lead to an infection. When a virus attempts to infect a host, an infection takes place with probability f(r), where f is the cross-reactivity kernel defined above and r is the distance in the 2D phenotypic space between the infecting viral strain and the closest receptor in the host repertoire. If the host repertoire is empty, the infection takes place with probability one. The viral mutation jump size and the cross-reactivity kernel set two length scales in the phenotypic space, σ and d (Fig. 4). Their dimensionless ratio σ/d is one of the relevant parameters of the problem. In this work we kept d fixed and then varied σ to explore their ratio. We do not explicitly consider competition between immune receptors within hosts, or complex in-host dynamics. Table 3 summarizes the variables used in the model and the main equations.

Initial conditions and parameter fine-tuning

We simulate several cycles of infection and recovery, keeping track of the phenotypic evolution of viruses and immune receptors throughout time by recording the set of points describing viruses and receptors in phenotypic space at each time, as well as what immune receptors correspond to each host. Once every 360 days we save a snapshot with the coordinates of all the circulating viruses. In addition we save the phylogenetic tree of a subsample of the viruses.

In order to quickly reach a regime of co-evolution with a single viral lineage tracked by immune systems, we set initial conditions so that the viral population is slightly ahead of the population of immune memories. Details of the initial conditions are given in Appendix A.1.1).

Viruses can survive for long times only because of an emergent feedback phenomenon that stabilizes the viral population when R 0 is fixed, as explained in Section 3.4.2. Even with that feedback, R 0 needs to be fined-tuned to obtain stable simulations. With poorly tuned parameters, viruses go extinct very quickly after an endemic phase, as also noted in [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF]. The detailed procedure for setting R 0 is described in Appendix A.1.2. Roughly speaking, R 0 needs to be chosen so that the average effective number of infected people at each transmission event is equal 1, or R 0 p f = 1, where p f is the average probability that each exposure leads to an infection. We further require that the fraction of infected hosts tends towards a target value, fi , which acts as an additional parameter in our model. To do this, R 0 is first adaptively adjusted at each time as:

R 0 = 1 p f + fi -f i fi , (18)
where p f is averaged over the past 1000 transmission events, and f i the current fraction of infected hosts. After that first equilibration stage, R 0 is frozen to its last value. Despite the explicit feedback (∝ fi -f i ) being removed, the population size is stabilized by the emergent feedback. As a result, the virus population is stable for long times for a wide range of parameter choices (Fig. 6).

To have more control over our evolution experiment we also analyze a variant of the model where we keep constraining the viral population size, constantly adjusting R 0 using Eq. 18 for the whole duration of the simulation (100 years). In this way the fraction of infected hosts f i is stabilized around the average fi .

Simulations were analyzed by grouping viral strains into lineages using a standard clustering algorithm, as described in Appendix A.3.1. The traces in each lineage were analyzed to evaluate their speed and variance in phenotypic space, as well as their angular persistence time (see Appendix A.3.2 for details). We built phylogenetic trees from subsamples of strains as detailed in Appendix A.3.3.

Detailed mutation model

We also considered a detailed in-host mutation model, in which we explicitly calculate the probability of producing a new mutant within a host. We present this model in detail in Appendix A.2 for the case where only one mutant reaches a high frequency during the infection time and we compare the results of this model to the simplified fixed mutation rate model described above.

The general idea is that we consider a population of viruses that replicate with rate α and mutate with rate µ resulting in a non-homogeneous Poisson mutation rate µe αt . The replication rate is the same for all mutants, i.e. there is no selection within one host and the relative fraction of the mutants depends only on the time at which the corresponding mutation arose.

For the case when only one mutation impacts the ancestral strain frequency, we simply calculate the time of the mutation event and use it to find the probability that an invader mutant reaches a certain frequency at the end of the infection. We then randomly sample the ancestral or mutant strain according to their relative frequencies at the end of the infection to decide which one infects the next host.

results

Modes of antigenic evolution

Typical trajectories in phenotypic space show different patterns depending on the model parameters. In the following, we describe a ballistic (Fig. 5 A iiii), a diffusive (Fig. 5 B i-iii), a transient splitting (Fig. 5 C i-iii), and a stable splitting (Fig. 5 D i-iii) regime and delineate the corresponding regions of the µ -σ parameter space. Here we present these four regimes and show sample evolutionary trajectories and corresponding phylogenic trees. We quantify these trajectories and describe the parameter regimes in which they appear in Fig. 6 and7. Ballistic regime. In this regime of one-dimensional evolution, viruses mutate locally forming a concentrated cluster of similar individuals, called a lineage. Successful mutation events, which take the viral strains away from the regions of antigenic space protected by host immune systems, progressively move the lineage forward (Fig. 5 A). For small values of the mutation rate and small mutation jump sizes the trajectory in phenotypic space is essentially linear, with new mutants always growing as far away as possible from existing host immune systems, which themselves track viruses but with a delay. The delayed immune pressure creates a fitness gradient for the virus population, which forms a traveling fitness wave [START_REF] Michael | Beneficial mutation selection balance and the effect of linkage on positive selection[END_REF][START_REF] Richard | E (14)[END_REF]225] fueled by this gradient. A similar linear wave scenario was studied in one dimension by Rouzine and Rozhnova [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]. Diffusive regime. As we increase the mutation jump range the trajectories loose their persistence length and the trajectories in phenotypic space start to turn randomly, as new strains are less sensitive to the pressure of host immune systems (Fig. 5 B).

Both ballistic and diffusive regimes lead to phylogenetic trees with one main trunk and a short distance to the last common ancestor (Fig. 5 A ii-iii and Fig. 5 B ii-iii). The mean time to the most common ancestor, TMRCA is the same in these two regimes (Fig. 5 A iii and Fig. 5 B iii). This trend is characteristic of influenza A evolution and has been discussed in detail in Ref. [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF]. Transient splitting regime. Alternatively, we observe a bifurcation regime, where at a certain point in time two mutants form two new co-existing branches, roughly equidistant from both each other and the ancestral strain in antigenic space (Fig. 5 C). Each branch has similar characteristics as the single lineage in the one dimensional evolution of Fig. 5 A-i andB-i. These co-existing branches give rise to phylogenetic trees with two trunks (Fig. 5 C-iii). In the example shown in Fig. 5 C-iii, the two lineages stably co-exist for ∼ 20 years, leading to a linear increase of the distance to the last common ancestor, until one of them goes extinct, returning the evolution to one dominant lineage with small distances to the last common ancestor (Fig. 5 C-ii). Stable splitting regime. The two branches can stably co-exist for over ∼ 80 years (Fig. 5 D, only the first 50 years are shown), starting with similar trends as in the example in Fig. 5 C-i, not returning to the one dominant lineage regime, but even further branching in a similar equidistant way at later times (not shown). This trend leads to evolutionary trees with multiple stable trunks (Fig. 5 D-iii), with local diversity within each of them and a linear increase of the distance to the last common ancestor over long times (Fig. 5 D-ii).

Stability

The mean extinction time of viral populations depends on the parameter regime (Fig. 6). A stable viral population is achieved in the σ d regime thanks to stabilizing feedback [225]: if viruses become too abundant they drag the immune coverage onto the whole viral population, and the number of viruses decreases since infecting a new host becomes harder. As a result the relative advantage of the fittest strains with respect to the bulk of the population decreases as more hosts are protected against all viruses. This feedback slows down the escape of viruses to new regions of antigenic space and the adaptation process. Conversely, when the virus abundance drops, the population immune coverage is slower in catching up with the propagating viruses. The fittest viral strains gain a larger advantage with respect to the bulk and this drives viral evolution faster towards new antigenic regions and higher fitness, increasing the number of viruses.

This stabilizing feedback is very sensitive to the speed and amplitude of variation. Abrupt changes or big fluctuations in population size can drive the viral population to extinction. Because of this, viruses often go extinct very quickly after an endemic phase [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF]225], as is proposed to have been the fate of the Zika epidemic [225]. Here we focus on the stable evolutionary regimes, starting from a well equilibrated initial condition as explained in section 3.3.2.

Phase diagram of evolutionary regimes

Our results depend on three parameters: the mutation rate µ, the mutation jump distance measured in units of cross-reactivity σ/d, and the target fraction of infected individuals in the population, fi . The observed evolutionary regimes described in Fig. 5 depend on the parameter regimes, as summarized in the phase diagrams presented in Fig. 7 for various fractions of infected hosts fi (panels i -iv).

The mean number of distinct stable lineages increases with both the mutation rate and the mutation jump distance (Fig. 7 A). Because the process is stochastic, even in regimes where multiple lineages are possible, particular realizations of the process taken at particular times may have one or more lineages. The fraction of time when the population is made of a single lineage (chosen rather than the fraction of runs with a single lineage, which strongly depends on simulation time) decreases with mutation rate and jumping distance (Figure 7 B), while the rate of formation of new lineages increases (Fig. 7C). All three quantities indicate that large and frequent mutations promote the emergence of multiple lineages. This multiplicity of lineages arises when mutations are frequent and large enough so that two si- multaneous escape mutants may reach phenotypic positions that are distant enough from each other so that their sub-lineages stop feeling each other's competition and become independent.

Increasing the mutation rate or the mutation jump distance alone is not always enough to create a multiplicity of lineages. For small fi = 5 • 10 -4 (Fig. 7 Ai) and moderate jump sizes, the single-lineage regime is very robust to a large increase in the mutation rate, meaning the cross-immunity nips in the bud any attempt to sprout a new lineage from mutations with small effects, however frequent they are.

Coalescence times (Fig. 7 D) give a measure of the number of mutations to the last common ancestor, and are commonly used in population genetics to characterize the evolutionary dynamics. In the case of a single lineage, coalescence times are short, corresponding to the time it takes for an escape mutation furthest away from the immune pressure to get established in the population. However, when there are multiple lineages, the coalescence time corresponds to the last time a single lineage was present. Such an event can be very rare when the average number of lineages is high, leading to very large coalescence times. Accordingly, the coalescence time increases with lineage multiplicity, and thus with mutation rate and jump size.

In general, large target fractions of infected hosts, fi , lead to more lineages on average and a higher probability to have more than one lineage. Increasing the number of infected individuals increases the effective mutation rate and allows the virus to explore evolutionary space faster. This rescaling allows more viruses to find niches and increases the chances of having coexisting lineages. While an increased fraction of infected hosts may also limit the virgin exploration space where viruses can attack non-protected individuals, this effect may be negligible when the target fractions fi are small as considered here.

Incidence rate

When viruses split into lineages, the implicit feedback mechanism described earlier to explain stability remains valid for each cluster independently (unless the number of independent lineages exceeds the immune memory pool M). As a result each lineage can support roughly a fraction fi of the hosts, which defines a "carrying capacity" of each lineage. As a result the viral population size, also known as incidence rate, is proportional to the number of lineages (Fig. 8). Yet the incidence fluctuates with time, with clear bottlenecks when a new cluster is founded.

Speed of adaptation and intra-lineage diversity

Whether there is a single lineage or multiple ones, each lineage moves forward in phenotypic space by escaping the immune pressure of recently infected and protected hosts lying close behind. We examined the speed of adaptation and the diversity of lineages of viral diversity present at a given time (Fig. 9). We calculated the speed of adaptation in units of crossreactivity radii d per year by taking, for each lineage, the difference in the two dimensional phenotypic coordinate of the average virus at time points one year apart. We quantified the diversity by approximating the density of each lineage at a given time by a Gaussian distribution in two-dimensional phenotypic space and calculating its variance along the direction of the lineage adaptation in phenotypic space.

The speed of adaptation increases with the mutational jump size σ, and also shows a weak dependence on the mutation rate µ. The variance in the viral population also increases with the jump size, and in general scales with the speed of adaptation. Fisher's theorem states that the speed of adaptation is proportional to the fitness variance of the population. A correspondence between speed and variance in phenotypic space is thus expected if fitness is linearly related to phenotypic position. While such a linear mapping does not hold in general in our model, the immune pressure does create a nonlinear and noisy fitness gradient, which can explain this scaling between speed and diversity.

Antigenic persistence

While lineage clusters tend to follow a straight line, their direction fluctuates as escape mutants can explore directions that are orthogonal to the main direction of the immune pressure. For this reason, while the phylogenetic trees in the ballistic and diffusive regimes in Fig. 5 A and B are very similar (quantified by the same value of TMRCA compared to the transient splitting and stable splitting regimes), the sample evolutionary trajectories look very different. In Fig. 10 we plot the rate at which trajectories turn, changing their direction by at least 30 degrees (see Appendix A.3.2). As noted in Fig. 5, small mutation jump sizes σ favor long periods of linear motion and low turn rates. As σ increases, the turn rate increases.

Several factors affect the turn rate as measured from the simulations. A lineage splitting induces a turn, and regions of phase space where multiple lineages are possible favor short persistence times. The same goes for population extinction: regimes where the population extinction rate is higher do not allow us to observe long persistence times, masking the dependence of the turn rate on µ. Generally, we expect lineage clusters to undergo more angular diffusion in phenotypic space as mutations become more important (large σ). Mutants can explore new regions of the phenotypic space, causing the population to stochastically turn while keeping a cohesive shape. On the other hand, lower mutation rates may mean that fewer mutants will do this exploration, increasing stochasticity in cluster dynamics and effectively increasing the turn rate. In this regime of stochastic turning, predicting the phenotype of future viral strains is much harder than in the linear regime.

Dimension of phenotypic space

We explored the effect of phenotypic space dimensions on our results. In Fig. 11 we plot the average number of neighbours of a given viral strain within distance r from that strain (for short distances so that only pairs from the same lineage are considered). This measure scales as r D for the cumulative number of neighbours plotted in Fig. 11, where D = 2 is the dimen- sion of phenotypic space, as expected for a uniformly distributed cluster of strains in finite dimension. By contrast, that number would be expected to scale exponentially with r for a neutral process in infinite dimensions. This result suggests that in low dimensions, which seems to be the experimentally valid limit, the dimension of the space does restrict the dynamics and cannot be neglected. However we are unable to separate the effects of selection and phenotypic space dimensionality. It also implies that lineages form dense, space-filling clusters in phenotypic space. We expect this result to hold for any reasonably low dimension, and will break down in high dimension.

Robustness to details of intra-host dynamics and population size control

To test whether a detailed treatment of intra-host viral dynamics would affect our results, we also considered a detailed mutation model, where we calculate the probability of producing a mutation within each individual (see Appendix A.2). Specifically, we compare the model that calculates the probability of having a mutated strain given in Eq. 142 to the simplified model with the mutation rate implemented as discussed above. As we see from Fig. 12 and Fig. 13, the general evolutionary features are the same as for the simplified model: the probability of multi-lineage trajectories increases with increasing µ and σ, as does the lineage splitting rate and the speed of adaptation. The diversity in phenotypic space in the direction parallel (Fig. 13 B) to the direction of motion increases with the mutation jump size, as expected, as well as the turn rate (Fig. 12 D).

Lastly we asked how our results would be affected by strictly constraining the viral population size (as explained in Sec. 3.3.2), rather than letting it fluctuate under the control of the emergent negative feedback. The corre- sponding phase diagrams show the same evolutionary regimes as a function of µ and σ/d (Fig. S1), and the same general dependencies on model parameters of the speed of adaptation (Fig. S2) and turn rate (Fig. S3), as with a fluctuating population.

discussion

Our model describes regimes of viral evolution with different complexity: one strain dominates (Fig. 5 A,B), two dominant strains coexist over timescales longer than the host lifetime (Fig. 5 C), or multiple strains coexist in a stable way (Fig. 5 D). The single-strain regime clearly maps onto influenza A. Influenza B evolution, which is split into the Victoria or Yamagata sublineages, is consistent with prolonged (Fig. 5 C) or stable coexistence (Fig. 5 D). We can use our results to characterize the differences in the evolutionary constraints acting on the adaptive processes of influenza A and B. Our results suggest that the combination of mutation rate and effective mutation jump distance in influenza A must be smaller than in influenza B. Since the mutation rates are similar, this means that the effect of mutations at sites in influenza B has a larger phenotypic effect. Alternatively, the effective number of infected individuals per transmission event (R 0 in classical SIR models, equal to R 0 p f in our model) could be larger in influenza B than influenza A. Another possibility is that, since lineage splitting happens stochastically, the difference between the two species is just due to different random realizations.

Our goal was to show that a simple model without additional elements such as the introduction of geographic, demographic or spatial niches can reproduce different evolutionary trends observed in fast evolving viruses. If we consider any specific virus, these specific elements become important for explaining the detailed patterns of evolution. For example, for the flu virus the seasonal and geographical correlations, as well as the existence of animal reservoirs for human infections and the travel patterns of humans are necessary to predict the global spread of the virus. These additional features lead to a wealth of specific behaviours, but our analysis shows that the stable co-existence of different strains emerges from evolutionary considerations without the need to invoke these additional features.

Our model has the following ingredients: infected hosts pass on infections, viruses mutate, we work in two-dimensional phenotypic space, immune receptors can recognize different viruses (are cross-reactive) and the immune system updates its memory based on the viruses it has seen. Eliminating cross-reactivity and immune memory would result in viruses growing freely, without feeling the immune pressure. In this situation we would not observe the lineage splitting caused by avoiding immune hosts. Similarly, a one dimensional model cannot lead to lineage splitting [START_REF] Michael | Beneficial mutation selection balance and the effect of linkage on positive selection[END_REF][START_REF] Richard | E (14)[END_REF][START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF].

We note that co-existing lineages can be obtained in models of evolving populations with weekly interacting niches without any selection pressure (of immune origin or any other)-the number of lineages will simply correspond to the number of niches we assume, each population will evolve according to neutral (e.g. Wright-Fisher) dynamics and the distance between the niches will depend on where we locate them. Unless there is a niche substructure, we will not observe additional within niche splittings. Therefore observing subsequent lineages within data (which to the best of our knowledge has not been observed) would suggest selection-induced splitting as opposed to pure niches. Our goal was not to explore such niche-induced lineages.

Based on the evolutionary regime it is observed in, our model could be used to constrain unknown parameters in particular viral systems, such as the mutation rate or typical effect of mutations. The evolutionary mode also depends crucially on the cross-immunity range d, which could be tested using neutralization assays.

A more detailed comparison between our models and data, which includes virus-specific features, would require refining the mapping between sequence data and phenotypic space. Antigenic maps are a step in this direction, as well as high-throughput genotype-phenotype experiments that map viral strains into virulence phenotypes and similar experiments that map immune receptor sequences into measures of antigen recognition [START_REF] Rhys | Measuring the sequence-affinity landscape of antibodies with massively parallel titration curves[END_REF]. For our model, the mean extinction times of viruses are plotted in Fig. 6. For example, for a mutation rate of µ 0.001, mutation jump size σ/d < 0.05 and a mean number of infected individuals of fi = 10 -3 , viruses survive on average less than 50 years.

Multiple co-existing lineages have been observed in the flu [START_REF] Paul A Rota | Lineages of Influenza Type B Virus since 1983[END_REF]. The question remains if the multiple lineages are self-generated due to population level immune pressure. One test of this scenario is to map the evolutionary regimes where we expect splitting. However, this may not directly validate or falsify the idea due to the mapping problems described above, and also the fact that lineage splitting is a stochastic event, so a lack of splitting in one sample does not mean it cannot happen. An alternative test of the idea of self-generated niches could be performed in synthetic CRISPRphage evolutionary systems [START_REF] Chabas | Evolutionary emergence of infectious diseases in heterogeneous host populations[END_REF]. Averaging over many realisations of the evolutionary experiments, and varying the protection level of the bacteria could help make the mapping between the parameters and increase the observation rate of splitting events.

Our model is applicable to acute infections that spread within one species due to a rapidly evolving virus at the population level and the host clears within a short timescales compared to its lifetime. For this reason it is a possible model of flu spreading but neither of HIV evolution, which mainly evolves in hosts, nor DNA viruses or slow evolving RNA viruses such as measles. Here we mainly discuss our results in the context of influenza evolution, however a detailed comparative study of how often the different evolutionary trends are observed across fast evolving viruses is an interesting future direction.

Our model shares similarities with previously considered models of viral evolution [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF]225], while focusing on distinct questions. Among differences in modeling details, our hosts have finite memory capacity and forget past strains after some time, compared to infinite memory assumed in past work. Comparing our simulations with Ref. [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF]225] in their relevant regimes, we do not see noticeable differences in the main trends of evolution, which suggests that the effects of losing memory are quantitative rather than qualitative at the population scale, at least for the parameters regimes that were inspected. The need for revaccination against certain even slowly evolving viruses (although this is not the type studies here), suggests that the timescales for memory loss can be variable and some antigens stimulate lifelong memory, while the memory repertoire against other antigens decays more rapidly. We assume exponentially decaying cross-reactivity, similarly to [225] (although it is linearized in their analysis). By contrast, Ref. [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF] uses a linear cross-reactivity, but this minor difference is unlikely to influence the results. Ref. [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF] focused specifically on the question of explaining the single dominant lineage in influenza A evolution. While the existence of lineage bifurcations was acknowledged in Ref. [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF], this regime was not explored. Instead, a more detailed geographical model was considered, with migrations between different geographical zones. For the single lineage regime, with the addition of seasonal niches Ref. [START_REF] Bedford | Canalization of the evolutionary trajectory of the human influenza virus[END_REF] report a decreased extinction rate compared to our model, as one would expect from classical models. Ref.

[225] asked a similar question we did about the conditions under which strain bifurcations may occur, but in the context of an infinite antigenic space. The general trends seem to be independent of the dimensionality of the space, since both models recover the same behaviour. However, the exact scaling laws reported in Ref. [225] seem to be more sensitive to the model assumptions. Lastly, while we also considered a more detailed model of intra-host influenza evolution, we found that it could be mapped onto an effective model of viral transmission with mutations, with little impact on the results.

Two main effective parameters control the evolutionary patterns: the effective mutation rate and the mutational jump size, measured in units of the cross-reactivity radius. The effective mutation rate is a combination of the actual mutation rate per host, and the mean number of infected hosts at each cycle: larger fractions of infected individuals lead to more opportunities for the virus to escape host immunity, and faster viral adaptation as a whole. Additionally, a feedback mechanism is observed between the host immune systems and the viruses: too successful viruses infect many hosts, effectively speeding up the rate at which the susceptible host reservoir is depleted, and mounting up the immune pressure. Our model does not include host death, since we assume we are in the limit of very large host reservoirs. Accounting for host extinction may leads to a different interesting problem that has been explored using SIR models [START_REF] Allen | Extinction thresholds in deterministic and stochastic epidemic models[END_REF][START_REF] Bryan T Grenfell | Dynamics of measles epidemics: scaling noise, determinism, and predictability with the TSIR model[END_REF]. In the context of our model however, host death would effectively amount to reducing the hosts' immune memory capacity M.

The effects of dimensionality on the observed evolutionary trajectories are worth discussing in more detail. The infinite dimensional model is similar in spirit to the infinite sites model of sequence evolution: infinite dimensions mean there is always a direction for the virus to escape to. Conversely, low dimensions result in an effectively stronger feedback of the host immune systems on the possible trajectories of the escaping virus. This generates effective mutation and jump rates that depend on the primary parameters in a nonlinear way, with possibly different effects in different parameter regimes.

We also observe a breakdown of the scaling of observables such as the coalescence time and the mean number of co-existing lineages with µσ 2 (see Fig. S4), as would be predicted by the diffusion limit of the traveling wave framework [START_REF] Cohen | Front propagation up a reaction rate gradient[END_REF][START_REF] Richard | E (14)[END_REF]. These results indicate that the discreteness of mutations matter. The effective dimensionality of the phenotypic space depends on the parameters, going from effectively one in the linear regime to the dimension of the phenotypic space in the splitting regime. We expect that our results generalize to higher dimensions than 2, with each splitting event leading to a new direction in phenotypic space and increasing the effective dimension of the viral population.

In summary, a detailed exploration of the mutation rate and jump distance, as well as the fraction of infected individuals allowed us to understand the constraints that lead to different modes of antigenic evolution and, in particular, lineage splitting at different rates and with different survival times of new (sub-)lineages. Observed bifurcations are rare in nature, which puts an evolutionary constraint on the adaptation process.

V I R U S E S P H E N O T Y P I C D I F F U S I O N : E S C A P I N G T H E I M M U N E S Y S T E M S C H A S E

introduction

In the previous Chapter we studied a minimal model for the interaction between viruses and population immune systems to study the emergence of different patterns at evolutionary timescales. This investigation was entirely based on numerical simulations of an agent-based implementation, which allowed us to study the interesting phenomenology of the model. On the other hand this carried technical problems in scaling up the population size N, and does not allow for a quantitative theoretical understanding of how the patterns emerge and of their generality.

In this Chapter we study a more coarse-grained "phenomenological" model for the diffusion of viruses in antigenic space, chased by the population immune systems, defined by two coupled stochastic differential equations.

Here by phenomenological we mean that the equations defining this model could be invoked to mimic the phenomenology of the agent-based model investigated in the previous Chapter. It's inspired on the agent-based model for viruses that give rise to acute infections such as flu, but its abstract formulation makes it suitable to model different systems with similar phenomenology, where the relative epidemiological and evolutionary timescales are similar.

Two recent works [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225] proposed similar analytical models for influenza phylodynamics assuming that the immune repertoire of hosts can hold information on an infinite number of past infections. Moreover [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF] embeds viral evolution in a 1D antigenic space, where viruses can only escape immune systems in one direction, whereas [225] considers an infinitedimensional antigenic space in which all mutations are beneficial. Here we don't make a specific assumption on antigenic space dimensionality in the model formulation, and we model explicitly the fact that the immune repertoire capacity is not infinite. Considering a finite-dimensional antigenic space with dimension greater than 1 allows us to address the shape of viruses evolutionary paths in this space.

For pedagogical purposes we start here in the introduction by showing how similar equations could be derived directly from the microscopic ingredients of the agent-based model under some assumptions, in a similar way as in 2.3.1 we derived eq. ( 10) from the ingredients of that basic model. Then we show that lineage separation cannot be obtained as a Turing pattern [START_REF] Mathison | The chemical basis of morphogenesis[END_REF] emerging from the deterministic part of the resulting equations, which suggests that the patterns observed in Chapter 3 are the product of the dynamic realizations of the stochastic evolutionary process rather than the long term fixed points of some deterministic process.

Then we introduce the final version of the phenomenological model and we study its behavior both analytically and numerically. This is still a work in progress.

From the microscopic model to Langevin equations

Here we faithfully translate the microscopic ingredients of the model in Chapter 3 into equations. Each host can infect a number of new hosts drawn from a Poisson distribution with mean R 0 as before, and at each infection transmission these new viruses can mutate with probability P mut . Upon mutation a virus with phenotype a will produce a mutant with phenotype b with a jump probability P(a → b) depending only on the jump length, whose distribution has average effect σ. As an infection is cleared the considered host immune system is updated to the position of the last infecting virus. Recognition probability of viruses by immune receptors is encoded in a cross-reactivity kernel H(r) that depends on the distance between the virus and the receptor in an abstract 2D antigenic space. At the population level, if a virus with coordinate x is transmitted at time t, we can denote the probability that it survives as

f(x, t) = 1 -h(x , t)H(x -x )dx (19)
where h(x , t) is the probability to find an immune receptor at position x at time t. Together with R 0 this determines the fitness of viruses. If the transmitted virus, whether the wild-type or a mutant, is recognized by a receptor it dies instantaneously without triggering an infection. As a first approximation we will neglect fluctuations in the number of attempted new infections around R 0 . These ingredients determine the average dynamics of the distribution of viruses in antigenic space. Hence we can write the following discrete time recursive equations for the distribution of viruses in antigenic space ρ(x, t), and for h(x, t):

         ρ(x, t + 1) =R 0 (t)ρ(x, t)(1 -P mut )f(x, t + 1) + P mut f(x, t + 1)R 0 (t) dJP(J)ρ(x -J, t) + ξ V h(x, t + 1) = h(x, t) + N N H (ρ(x, t) -h(x, t)) + ξ H ( 20
)
where N is the number of viruses and N H is the fixed number of hosts. ξ V , ξ H are complicated multiplicative noise terms. In the first equation we have that viruses replicate at rate R 0 f and mutate in antigenic space. Because of the microscopic details of the model, namely the fact that recognized mutants die instantaneously, mutations and growth are coupled in the term P mut f(x, t + 1)R 0 (t) dJP(J)n(x -J, t). In the second equation we have that the immune receptors in x update proportionally to ρ(x, t) since they update to the position of the last infecting virus, and the number of immune receptors in the population is fixed, so they have to be depleted from somewhere else (-h(x, t) term). This immune update at the population level happens at rate N N H , which is the probability that a specific host is infected, because the condition to update the immune receptor is precisely to get infected.

Taking the continuous time limit rescaling time by the average infection duration τ i , in the limit N N H 1 we have:

           ∂ρ(x, t) ∂t =R 0 (t)(1 -P mut )ρ(x, t)f(x, t) -ρ(x, t) + P mut f(x, t)R 0 (t) dJP(J)ρ(x -J, t) + ξ V ∂h(x,t) ∂t = N N H (ρ(x, t) -h(x, t)) + ξ H . (21)
These are Langevin equations for specific realizations of viruses and immune receptor distributions (frequencies), not to be confused with the master equation for the probability of such distributions P ρ and P h over the space of all possible frequencies summing to 1. The deterministic part of these equations, motivated above, follows precisely from the microscopic ingredients of the model studied in Chapter 3.

We recall that in Chapter 3, in the model initialization, we were modulating R 0 via an autoregressive process to keep the viral population size N constant on average for some time. In this framework the condition to have a stationary virus number, on average, would read:

R 0 (t) = 1 (1 -P mut ) dxρ(x, t)f(x, t) + P mut dxf(x, t) dJP(J)ρ(x -J, t) , (22)
where the denominator can be interpreted as the total probability that the virus survives upon passing an infection, p f . This can either be imposed, or it can be an emergent feature of the model if ρ and h satisfy this condition for some R 0 that does not depend on time.

If we consider the limit of rapidly vanishing jump probability P, we can Taylor expand ρ in the convolutions with P(J) and take the diffusion approximation:

   ∂ρ(x,t) ∂t = R 0 (t)ρ(x, t)f(x, t) -ρ(x, t) + P mut f(x, t)R 0 (t) σ 2 2 ∆ x ρ(x, t) + ξ V ∂h(x,t) ∂t = N N H (ρ(x, t) -h(x, t)) + ξ H , (23)
and the stationary population constraint translates into:

R 0 (t) = 1 dxρ(x, t)f(x, t) + P mut σ 2 2 dxf(x, t)∆ x ρ(x.t) (24)

Simplified description

To simplify the description we can ignore the microscopic details of the model giving rise to the coupling between mutations and proliferation and invoke some "phenomenological" reaction diffusion equations that are not formally related in the details but include the same ingredients, namely immune-constrained virus growth, mutations, population size constant on average, immune update:

   ∂ρ(x,t) ∂t = 1 τ i (f(x, t) -f ρ (t))ρ(x, t) + µ σ 2 2 ∆ x ρ(x, t) + ξ V ∂h(x,t) ∂t = N N H τ i (ρ(x, t) -h(x, t)) + ξ H , (25)
where

f ρ (t) = dxρ(x, t)f(x, t), (26)
enforces that the number of viruses is constant on average. Here we are not rescaling time by τ i anymore, and µ = P mut /τ i is the mutation rate of viruses. The noise satisfy the relations:

ξ V = ξ V = 0 (27) ξ V (x, t)ξ V (x, t ) = δ(t -t ) ρ(x, t) τ i (28) ξ H (x, t)ξ H (x, t ) = δ(t -t ) N τ i N H h(x, t)(1 -h(x, t)), (29)
where the demographic noise correlator for ξ V is given by the viruses birthdeath process, whereas the one for ξ H reflects the Bernoulli trials of updating immune receptors at position x rather than somewhere else.

Deterministic fixed points

Here we study if non-homogeneous patterns can emerge as the fixed points of the deterministic part of eqs. [START_REF] Brunet | The stochastic edge in adaptive evolution[END_REF]. We also assume that the antigenic space is finite. If we consider the case where h is homogeneous then from eq. [START_REF] Gregory | The tetratricopeptide repeat: a structural motif mediating protein-protein interactions[END_REF]

follows that f(x, t) = f ρ (t) ∀x, therefore ∂ρ(x, t) ∂t = µ σ 2 2 ∆ x ρ(x, t) (30)
that relaxes to an homogeneous solution as well. We can ask whether this homogeneous solution is stable upon a perturbation [START_REF] Koch | Biological pattern formation: from basic mechanisms to complex structures[END_REF][START_REF] Murray | Mathematical biology II: spatial models and biomedical applications[END_REF][START_REF] James | Mathematical biology: I. An introduction[END_REF]. Therefore we study the stability of solutions of the type:

   ρ(x, t) = ρ 0 + η(x, t) h(x, t) = h 0 + (x, t) (31)
where η ρ 0 and h 0 , and dxη(x, t) = dx (x, t) = 0. The equations for the perturbation to leading order become:

   ∂η(x,t) ∂t = 1 τ i ρ 0 (1 -(x , t)H(x -x )dx ) + µ σ 2 2 ∆ x η(x, t) ∂ (x,t) ∂t = N N H τ i (η(x, t) -(x, t)) (32)
We can take the Fourier transform of these equations, which can be written as ∂U(k,t) ∂t = M(k)U(k, t). Under the ansatz that perturbations are of the form U(k, t) = e λ k t U k , this is equal to solve the eigenvalues problem λ k U(k, t) = M(k)U(k, t) with matrix:

M(k) = -µσ 2 2 k 2 ρ 0 τ i (δ(k) -H(k))) N N H τ i -N N H τ i ( 33
)
where H is the Fourier transform of the cross-reactivity kernel. The homogeneous solution is unstable only if there is some eigenvalue λ k > 0 for some k > 0. Dropping the term δ(k) and studying the eigenvalues of matrix [START_REF] Arup | Statistical mechanical concepts in immunology[END_REF] reveals that ∀k > 0 the maximum eigenvalue can be positive only if H(k) < 0, which is never the case for the exponential and Gaussian kernels we used in Chapter 3, and therefore in those cases the homogeneous distribution of viruses and immune coverage is always a stable fixed point of the deterministic dynamics. This suggests that the patterns observed in Chapter 3 result from the stochastic transient dynamics emerging at the population level from the microscopic interaction between viruses and immune systems, rather than from the long term fixed point of the system dynamics in the absence of noise.

phenomenological model in phenotypic space

Here we introduce a phenomenological model for viral diffusion and immune update in antigenic space, with the goal of studying its dynamics. This generalizes the model introduced in eq. [START_REF] Brunet | The stochastic edge in adaptive evolution[END_REF]. In this coarse-grained model n(x, t) denotes the density of viruses at position x in antigenic space (x is a d-dimensional vector), and h(x, t) the density of hosts with protection x:

∂n(x, t) ∂t = f(x, t)n(x, t) + D∇ 2 n + n(x, t)η(x, t), dh(x, t) dt = 1 N h τ i n(x, t) -h(x, t) N(t) M (34)
with fitness of virus at x defined as:

f(x, t) = F h(x , t)H(x -x )dx , (35)
where is H the cross-reactivity Kernel, and F is a decreasing function. Here τ i is the infection timescale (e.g. the average time after which one infected host infects someone else). The diffusion coefficient D describes the effect of infinitesimal mutations on the phenotype. The total viral population size N(t) = dxn(x, t) can fluctuate, but not the host population, which is assumed to be constant. The number of hosts N h dictates the timescale at which the host protection density is updated in [START_REF] Chen | Bayesian filtering: From Kalman filters to particle filters, and beyond[END_REF]. We assume that each host carries M immune receptors and the probability density of protection h(x, t) is the probability of finding hosts with any receptor in x. It follows that dxh(x, t) = M.

With respect to [START_REF] Brunet | The stochastic edge in adaptive evolution[END_REF] we express the dynamics in terms of the virus density n = Nρ. Here we ignore the noise term on the hosts dynamics and we will consider a more general nonlinear form of the fitness function, motivated below. We also add that hosts can have up to M receptors instead of just 1. None of these differences affects the linear stability analysis of sec. (4.1.3), and the intuition behind each term appearing in the equations is the same.

Assuming constant N(t) = N, h is given as a function of n as:

h(x, t) = M N t -∞ (dt /τ) e -(t-t )/τ n(x, t ), (36)
with τ = τ i MN h /N. This means that the viruses leave a trace of immune receptors chasing behind them, and τ sets the average timescale of this lag, being the average time after which a specific receptor gets updated.

Fitness function

Here we motivate a choice for the fitness function F(c) in eq. ( 35), where we call c = c(x, t) = h(x , t)H(xx )dx whose value can go from 0 to M, and which corresponds to the population immune protection at phenotypetime coordinate (x, t). With M = 1 attempted infections of viruses characterized by that coordinate will succeed on average with probability

1 -c. Therefore F(c) = ln R 0 (1-c) τ i
where R 0 is the average number of infections by each infected host in a susceptible population. Note that for R 0 (1 -c) ∼ 1 this reduces exactly to the growth term in [START_REF] Boutet | UniProtKB/Swiss-Prot[END_REF].

With a generic M, the probability that a specific attempted infection from virus with phenotype x succeeds will be equal to the product of the probabilities that the virus escapes immunity by all the M receptors in the infected host: M r=1 (1 -c r ), where c r = H(xx r ) is the protection conferred to that host by its rth receptor. We can assume that we cannot partition the receptors in M classes, meaning all M receptors within one host are indistinguishable and they carry a contribution c h /M to the total protection c h = r c r of that host. In other words we identify a host protection with the protection given by any of its receptors picked at random. Hence the infection on average would succeed with probability (1 -c h M ) M . With many hosts we can assume a complete mean-field description for receptors partitioning into different hosts and write the infection success probability as (1 -c M ) M . Therefore:

f(x, t) = F (c(x, t)) = ln R 0 (1 -c(x,t) M ) M τ i = M τ i ln (1 -c(x, t)) + F 0 , (37)
where in the last equality we rescale the protection c = c M and we identify the exponential growth rate of viruses in a naive population as F 0 = ln R 0 τ i . As discussed below, the stability of the model requires that the viral population stays concentrated around the region where f(x, t) = 0, which happens for ã such that F( ã) = 0. Then: where the fitness function is effectively linear with derivative

ã = F -1 (0) = 1 -e -τ i F 0 M , (38)
population level immune coverage c(x, t) = h(x , t)H(x -x )dx viral fitness function F (c(x, t)) = M τ i ln 1 -c(x,t) M + F 0 selection coefficient s = M(e τ i F 0 M -
b = dF d c | ã = - M τ i e τ i F 0 M . ( 39
)
Note that for M → ∞ the fitness function becomes linear:

F (c(x, t)) → F 0 -c(x,t) τ i .
In the following we will measure time in units of τ i , so we set τ i = 1 without loss of generality. Therefore all of the above can be parametrized by a single extra parameter F 0 .

System's scales

Table 2 summarizes model parameters and observables, some of which refer specifically to the microscopic numerical implementation of the model, and will be introduced below. Observables can be related to three classes corresponding to the three scales involved in this phylodynamic system: the immune response scale including the immune repertoire size M, the epidemiological scale including all observables related to the epidemiological spread in the population -such as number of hosts N h , number of viruses N, transmission time τ i and spread rate F 0 -and the evolutionary scale including the processes of mutation and recognition.

In this model (inspired by acute infections) the immune response is assumed to be infinitely fast so that effectively the epidemiological scales account for the immune response one as well, which is why for example the timescale of immune repertoire update at the whole population level τ is driven by the epidemiological timescales. Both epidemiological and evolutionary scales play an important role to map immune protection to fitness, as evident from eq. [START_REF] Cohen | Front propagation up a reaction rate gradient[END_REF]. In table 2 we left the various contributions of τ i explicit, whereas we set it to 1 in the main text.

numerical simulations

In order to study the model behavior and to validate the analytical insights presented below we implement a numerical version of it, accounting for all terms in the reaction-diffusion equations in eq. ( 34) while implementing antigenic space as an infinite discrete lattice. While the model in eq. ( 34) does not make any specific assumption on the space dimensionality, the first version of the numerical implementation assumes a 2D space. Model parameters below are given in units of the lattice spacing.

Implementation

The numerical implementation considers the antigenic space as a 2D squared lattice. Each of its sites being characterized by the number of viruses n, the number of immune receptors H = int(N h h) -so that the numerical simulation considers a fully discretized version of viruses and hosts densitiesand the fitness of viruses f. This is given by eq. ( 35) replacing the integral in continuous space with a sum in discrete space, and we enforce it to be f -1.

Given a set of parameters, the simulation is initiated with viruses distributed as a (discretely binned) 2D Gaussian distribution with average coordinate (0, 0), with same standard deviation σ in every independent direction, calculated as a function of the parameters from eq. ( 60), that comes from the traveling wave theory as we will see below. On top of that on each lattice site with y = 0 and 0 < x < u c are placed int(N/1000) viruses, with u c given by eq. ( 62). The total initial number of viruses N is calculated approximately from eq. [START_REF] Frankel | Understanding Molecular Simulation: From Algorithms to Applications[END_REF]. At the same time the MN h immune receptors are distributed linearly along the x axis according to the discrete histogram of shape given by eq. ( 43) with t = 0, assuming that they are uniformly distributed in -2σ < y < 2σ. The number of hosts N h is enforced exactly, this being a fixed parameter of the model rather than a dynamic observable like N.

Each time step, corresponding to τ i = 1 time units, consists of four substeps performed in the following order: update of the immune system according to the second equation in eq. ( 34), growth of viruses in their lattice sites according to their current fitness, diffusion on the lattice, update of viral fitness at each populated lattice site. More details on each sub-step are given below.

The procedure is re-iterated till t max = 5 * 10 6 time steps are completed, some scalar observables such as total number of viruses summarizing the status of the simulation is saved every 10 steps, the whole distribution of viruses on the lattice is saved every 100 steps, a subsample of the distribution of hosts on the lattice is saved every 1000 steps and checkpoints with the full status of the simulation are saved every 10000 steps. If the total number of viruses reaches 0 (extinction) or N h ("explosion", which is an unrealistic situation) the simulation is aborted and resumed from the last checkpoint, at least 1000 steps in the past to avoid resuming from a point where viruses are already doomed. The full simulation is stopped when either the time step t reaches t max or when viruses go extinct (or explode) 20 times in a row starting from the same checkpoint. Before performing any analysis on the model-generated time-series a transient of at least 20000 time steps is discarded, and the remaining simulation is considered valid only if it consists of at least other 30000 cycles.

Within each time step the immune receptors are updated by adding to each lattice site an amount equal to n, which leaves exactly N receptors to be removed from somewhere. For each lattice site with H > 0 receptors we draw the number of receptors to be removed from a Binomial distribution with probability N/(MN h ) and H trials, stopping when the total number of removed receptors is equal to N. If after cycling through the lattice sites with H > 0 the removed receptors are less than N for each of the (typically few) missing removals we draw where to remove it from at random from all coordinates with H > 0. This algorithm ensures that the number of receptors after the update is always MN h . We should notice that this microscopic implementation includes the binomial noise that we ignored in the analytical formulation eq. [START_REF] Chen | Bayesian filtering: From Kalman filters to particle filters, and beyond[END_REF].

Then at each site with n > 0 viruses and fitness f, n is updated by drawing it from a Poisson distribution with average (f + 1)n.

To implement the diffusion sub-step, the algorithm takes as input the microscopic mutation rate per infection µ. We cycle over all lattice sites with n > 0. The number of viruses that mutate is drawn from a Binomial distribution with probability P mut = 1 -e -µ . For each of these mutated viruses the number of multiple mutation events within the time step is drawn from a Poisson distribution with rate µ conditioned on having at least 1 event. For each mutation event the new mutant is picked in continuous space in a random direction from the previous mutation. Its distance δ is drawn from a Gamma distribution with shape factor 20 and average δ :

Γ (δ|20, δ 20 ) = 1 Γ (20) δ 20 δ 19 e -20δ
δ . A similar mutation kernel was considered in Chapter 3 and in [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]. The shape factor was arbitrarily picked high to have a peaked jump length distribution for technical implementation reasons related to the discrete lattice memory storage. We argue that the outcome of this diffusion model will not depend on details such as the precise shape of the mutation kernel, provided that it does not have power-law tails. We decided to avoid implementing mutations simply as walks to one of the 4 neighboring sites because it is known that this implementation can bias random walk results in presence of strong fields [START_REF] Michel | Building reliable lattice Monte Carlo models for real drift and diffusion problems[END_REF]. The final position of the mutation on the lattice is given by the closest lattice site to the drawn position in continuous space, so that ρ(δ) ∼ Γ (δ|20, δ 20 ). Because of this discrete casting the actual average mutation effect is only approximately ∼ δ . When looking at a single direction x in antigenic space these microscopic mutations produce a statistics of 1D displacements δ x , from which we can map back the microscopic mutations model into the macroscopic diffusion in eq. ( 34) according to D = µ 2 var 1d (δ x ). The last sub-step within each cycle is the fitness update, which is also the computational bottleneck of the simulation. We implemented four algorithms for this step.

1) The full convolution in eq. ( 35) (discretized) can be computed exactly summing on all coordinates with h > 0.

2) Otherwise it can be computed to update f from the previous value just summing on all coordinates where h changed in the current time step, in which case the update does not introduce any new approximation to the fitness, but it does not correct for previous errors. These methods alone turned out to be very slow in many parameter ranges. Therefore we approximate the convolution using two approximated algorithms.

3) The first relies on non-homogeneous fast Fourier transforms ("NFFT") implemented by [START_REF] Keiner | Using NFFT 3-a software library for various nonequispaced fast Fourier transforms[END_REF]. Details and benchmarks on using NFFT to compute convolutions can be found in [START_REF] Potts | Fast convolution with radial kernels at nonequispaced knots[END_REF].

4)

The second is a "far field" approximation of the cross-reactivity kernel, where we neglect the component in the distance perpendicular to the direction from the receptor coordinate x to the average viral coordinate x n . In this way the kernel becomes separable and we can pre-compute a bunch of h contributions to eq. ( 35) that carry the same contribution to the fitness ∀x, while keeping the approximation small. Then we run either algorithm 2) or 3) on the rest of the coordinates we could not pre-compute. Finally we estimate the time complexity runtime at each cycle from the numbers of coordinates with n and h greater than zero and that updated in the current cycle. We decide which algorithm to use between 2), 4)+2) and 4)+3) based on that. In order not to accumulate too many fitness approximations we keep track of a proxy for the fitness errors, and if this becomes too big we keep algorithm 2) for as long as needed to lower the error. Every 10000 steps we update the fitness with the exact algorithm 1). This procedure allows for a huge speed-up with negligible fitness approximations.

During the simulation the lattice is expanded infinitely to make always new antigenic space for the viruses to explore. At the same time it's cropped behind the oldest immune receptors in order to leave just enough space for all viruses and immune receptors while keeping the RAM consumption limited. This approach was preferred to periodic boundary conditions given the difficulty to predict a priori the exact span of the trace of immune systems behind the viruses.

We study numerically the model varying the parameters corresponding to the recognition width r, the mutation rate µ (while keeping fixed the parameters of the mutation kernel), the number of hosts N h , the rate of epidemiological spread F 0 , and the size of the immune repertoire M (but in this thesis we only present results for M = 1, apart from the cartoon in figure 15B).

Observables estimation -clustering analysis

In order to analyze the organization of viruses in phenotypic space, for each saved snapshot we take all the coordinates with n > 0 and then cluster them into separate lineages through the python scikit-learn DBSCAN algorithm [START_REF] Pedregosa | Scikit-learn: Machine Learning in Python[END_REF] [START_REF] Ester | A density based algorithm for discovering clusters in large spatial databases with noise[END_REF] with the minimal number of samples min_samples = 10. The parameter defines the maximum distance between two samples that are considered to be in the neighborhood of each other. We perform the clustering for different values of and select the value that minimizes the variance of the 10th nearest neighbor distance (the clustering results are not sensitive to this choice). Then this preliminary clustering step is refined merging clusters if their centroids are closer than the sum of the maximum distances of all the points in each cluster from the corresponding centroid. We impose this extra requirement in order to reduce the noise from the clustering algorithm.

From the clustered lineages we can easily obtain a series of related observables, such as the number of lineages and the fraction of time in which viruses are clustered in a single lineage. We can also track their separate trajectories in antigenic space. A split of a lineage into two new lineages is defined when two clusters are detected where previously there was one. A cluster extinction is defined when a cluster ceases to be detected from one snapshot to the next. For each separate lineage we can estimate its properties in antigenic space, such as its adaptation speed v, the width of its profile in the direction of motion σ as well as in the perpendicular direction σ ⊥ , or the distance of the fittest strain to the centroid u c . When there is more than one separate lineage it is clear that these quantities only make sense if estimated per coherent lineage, rather than globally on the whole viral population.

Preliminary numerical results

Here we present some preliminary results of the numerical simulations detailed above. First, figure 14 sketches that viruses travel coherently in a very compact blob in order to escape the immune systems update, which leaves a long memory trace behind them. The memory update timescale is given by τ as explicit in eq. ( 36). If the viral population travels with an approximately constant speed v this translates in a memory trace scale in antigenic space vτ as explained in section 4.4 below. Therefore vτ and the recognition scale r set the two relevant scales in antigenic space, and are highlighted in figure 14 for reference (vτ is calculated from the model parameters from eq. ( 55)). As we will see in section 4.4.1 the epidemiological spread rate F 0 sets the relation between these two scales. Figure 15 conceptually sketches that in different regions of the parameters space viruses escape the immune chase through drastically different evolutionary strategies. The patterns emerging from this coarse-grained model are qualitatively similar to those we obtained with an agent based model in Chapter 3: viruses either evolve in a single compact lineage or split into more independent lineages evolving independently (figure 15B). Each lineage diffuses in phenotypic space with a characteristic persistence length that depends itself on the model parameters. Figure 15A shows the average antigenic trajectory of viruses that evolve at all times in a very compact single lineage (similar to what shown in figure 14) that diffuses revolving a few times around itself.

Inspecting the model behavior more systematically we also get qualitative trends of the model observables as a function of the parameters similar to those of Chapter 3. For instance figure 16A shows that the faster and bigger the mutations the more it takes for viruses to go extinct. Figure 16C shows that at the same time faster and bigger mutations cause also an higher rate of lineage splitting, driving the single-to multi-lineages transitions in figure 7. The simulations in figure 16 have N h = 10 10 , F 0 = 1 and M = 1, but we also systematically explored N h = 10 8 , 10 12 and F 0 = 3 that give similar qualitative trends (not shown). Note that with M = 1 viruses are almost always found in a single lineage as shown in figure 16D. When mutations are bigger and faster more lineages become slightly more likely, but at the same time the model loses stability with viruses reaching N h (exploding) faster, as shown in figure 16B. Our intuition is that the immune memory can only withstand up to M separated lineages for a sustained period of time, because on average that is the amount of information each host repertoire can store about uncorrelated (far with respect to r) viral lineages. If an M + 1th lineage is formed and gets far enough from the others, viruses will always have a big pool of susceptible individuals (on average N h /(M + 1)) since new repertoire updates triggered by a recent infection will always make hosts susceptible to one of the other M strains. Indeed the cartoon 15A displaying more lineages at the same time results from a simulation with M = 5 (the same M we used in Chapter 3). At the time of writing we are systematically exploring the M = 5 parameters manifold with numerical simulations to confirm this intuition.

wave solution

In the following we presents some analytical results of this model, derived in an unpublished work that is currently in progress (Marchi Mora Walczak, in preparation).

We assume that the equations (34) admit a traveling wave solution of the form with

n(x, t) = n 1 (x 1 , t)ϕ(x 2 , . . . , x d ), ( 40
)
n 1 (x 1 , t) = N √ 2πσ 2 exp - (x 1 -vt) 2 2σ 2 , (41)
i.e. traveling in the x 1 direction, with fluctuations in the other dimensions given by ϕ(x 2 , . . . , x d , t).

In the limit where the wave is thin compared to the adaptation time scale, vτ σ, and assuming that the directions 2, . . . , d behave independently, we have

h(x, t) = h 1 (x 1 , t)ϕ(x 2 , . . . , x d ) (42)
with

h 1 (x 1 , t) ≈ M dt /τe -(t-t )/τ δ(x -vt ) = M vτ e -(vt-x 1 )/(vτ) . ( 43
)
for x 1 < vt, and h 1 (x 1 , t) = 0 for x 1 > vt. We define

u = x 1 -vt. (44)
Assuming an exponential cross-reactivity Kernel:

H(x) = exp - x r , (45)
the fitness inside the wave (u > 0, x i = 0 for i > 1) reads:

f(u, t) = F Me -u/r 1 + vτ/r ≈ F M 1 + vτ/r + F M 1 + vτ/r Mu r + vτ (46)
for u r, while at the back (u < 0):

f(u, t) =F Me -|u|/(vτ) 1 + vτ/r + M e -|u|/r -e -|u|/(vτ) 1 -vτ/r ≈F M 1 + vτ/r + F M 1 + vτ/r Mu r + vτ , (47)
for |u| r, vτ. So to summarize:

f ≈ f * + su with s = F M 1 + vτ/r M r + vτ . ( 48
)
If we assume that even the fittest u is r, this simply creates a linear fitness gradient, mapping phenotype to fitness space with scale s. This allows us to connect our model to the traveling wave theory introduced in 2.3.4, provided that the wave ansatz is correct.

Then the first equation in [START_REF] Chen | Bayesian filtering: From Kalman filters to particle filters, and beyond[END_REF] becomes:

∂n 1 (x 1 , t) ∂t = s(x 1 -vt)n 1 (x 1 , t) + D ∂ 2 n 1 ∂x 2 1 + noise, (49)
with the change of variable x1 = sx 1 , ṽ = sv, ñ1 = s -d n 1 , then we get back the same traveling wave equation of [START_REF] Richard | E (14)[END_REF]:

∂ ñ1 (x 1 , t) ∂t = (x 1 -ṽt) ñ1 (x 1 , t) + D ∂ 2 ñ1 ∂x 2 1 + noise, (50)
with D = Ds 2 .

Regulation of population size

A first requirement for the wave ansatz of eq. ( 40) to be stable is that the population size, governed by the equation dN(t) dt = f N(t), does not vary too much. So we need the condition that the average fitness is zero:

f = f * = F M 1 + vτ/r = 0. (51)
Using the explicit fitness function motivated in sec. 4.2.1 this implies given parameters set specified in the legend (apart from r that also varies). Antigenic space is measured in units of δ , time is measured in years unless otherwise specified. The gray line represents the identity. On the x-axis the average of the observables time-series estimated on simulation results, on the y-axis the theoretical prediction for that observable given the parameters. A) The strength of selection s (theory predicts eq. ( 54)). B) The scale of the immune memory trace behind viruses in antigenic space vτ (theory predicts eq. ( 55)). In all these simulation M = 1.

ã = a M = 1 -e -F 0 M = 1 1 + vτ/r , ( 52
)
so F 0 tunes the ratio vτ/r as

vτ r = 1 e F 0 M -1 . ( 53
)
The slope of F at the equilibrium point sets s:

s = ã| b| r = M(e F 0 M -1) r . ( 54
)
Putting eqs. ( 53) and ( 54) together:

vτ = M s . ( 55
)
Figure 17 presents the numerical check of equations (54) (panel A) and (55) (panel B). In the simulation results the selection strength s is estimated for each lineage as the difference between the largest and the average fitness in the lineage, divided by the distance in antigenic space between the fittest strain and the lineage centroid. The speed of adaptation v is also estimated for each lineage from the centroids trajectories, and τ is calculated according to its definition where N is the time average of the viral population size resulting from the simulations. The good agreement between theory and simulations supports the assumption we did in section 4.4, that lineages are very compact in antigenic space |u| r, vτ and adapt forming a stable wave in an approximately linear fitness landscape.

Recall τ = MN h /N depends on N. v will depend on N too in the traveling wave theory, but only logarithmically as in equation [START_REF] Bedford | Integrating influenza antigenic dynamics with molecular evolution[END_REF]. The average fitness is thus a decreasing function of N, which means that N should converge to N 0 such that F[M/(1 + v(N 0 )MN h /rN 0 )] = 0. Intuitively, larger viral populations imply faster adaptation dynamics of the host population, which results in reduced fitness for the viral population as a whole.

Traveling wave scaling in phenotypic space

Here we map the scalings of [START_REF] Richard | E (14)[END_REF], recapitulated in sec. 2.3.4, to our model in phenotypic space. To summarize the scales: width of the distribution σ, the adaptation scale vτ, and the cross-reactivity scale r. What seems to give sensible results is σ vτ, and σ r, meaning that the viral population is very compact.

We have s 2 σ 2 = sv by Fisher's theorem, and v is given by the analysis of the fitness nose (see [START_REF] Richard | E (14)[END_REF]):

s 2 σ 2 = D2/3 (24 ln(N D1/3 )) 1/3 , (56)
or

σ = (D/s) 1/3 (24 ln(N(Ds 2 ) 1/3 )) 1/6 , (57)
and

v = D 2/3 s 1/3 (24 ln(N(Ds 2 ) 1/3 )) 1/3 . ( 58
)
The fittest in the population is ahead of the bulk by u c = sσ 4 /4D (see [START_REF] Richard | E (14)[END_REF]), or

u c ∼ 1 4 (D/s) 1/3 (24 ln(N(Ds 2 ) 1/3 )) 2/3 (59)
Plugging in (54) these become:

σ = Dr M(e F 0 M -1) 1/3   24 ln   ND 1/3 M(e F 0 M -1) r 2/3     1/6 , (60)
v = D 2/3 M(e F 0 M -1) r 1/3   24 ln   ND 1/3 M(e F 0 M -1) r 2/3     1/3 , (61)
u c ∼ 1 4 Dr M(e F 0 M -1) 1/3   24 ln   ND 1/3 M(e F 0 M -1) r 2/3     2/3 . ( 62
)
The validity of these theoretical predictions is checked against simulations in figure 18. If the mutation rate µ is high enough the theoretical predictions are accurate. As mentioned in section 2.3.4 these scaling are derived relying (1/day) Figure 18 -The traveling wave theory predictions are accurate when mutations are frequent Numerical check of theoretical predictions. Each point corresponds to a given parameters set specified in the legend (apart from r that also varies). Antigenic space is measured in units of δ , time is measured in years unless otherwise specified. The gray line represents the identity. A) On the x-axis the variance of the lineage density profile in antigenic space in the direction of motion σ 2 . On the y-axis the speed of the lineages adaptation in antigenic space v (both are measured from simulation results), rescaled by s as in eq. ( 54). Fisher's theorem in antigenic space s 2 σ 2 = sv holds well in our numerical simulations, on average. B) C) D) On the x-axis the average of the observables timeseries estimated on simulation results, on the y-axis the traveling wave theory prediction for that observable given the parameters, for B) the speed of the lineages adaptation in antigenic space v (eq. ( 61)), C) the standard deviation of the lineage density profile in antigenic space in the direction of motion σ (eq. ( 60)), D) the distance in antigenic space between the fittest strain and the lineage bulk u c (eq. ( 62)). In all these simulation M = 1.

on a diffusion approximation [START_REF] Richard | E (14)[END_REF] that holds for many small mutations. So it is not surprising that the predictions break with very little µ, and this numerical check gives us a scale for when that happens. Note that the Fisher's theorem in antigenic space in panel 18A does not rely on any of these scalings, and therefore holds across all simulated µs. Due to the discrete casting of continuous mutations, it is not straightforward to calculate exactly D from µ, therefore we infer it from the resulting jump statistics as mentioned in section 4.3.1. These equations have a weak logarithmic dependence on the viral population size N which is not a fixed model parameter but emerges from the stability of the traveling wave (equation ( 51)). To calculate the theoretical predictions from the expressions above we plug in N as the time average of the viral population size resulting from the simulations.

From the definition of τ, eq. ( 55) and eq. ( 61) we have the following transcendental equation for N in the stable regime:

N N h = M τ = sv = D 2/3 M(e F 0 M -1) r 4/3   24 ln   ND 1/3 M(e F 0 M -1) r 2/3     1/3 . ( 63
)
Figure 19 shows the comparison between the (numerical) solution of this equation and the results of the simulations of the model. Again, the theoretical prediction is accurate if the mutation rate µ is high enough.

For the wave ansatz to be valid we want u c r, so we need to additionally assume that r scales with N faster than u c , r ln(N). We also want σ vτ, therefore r

M(e F 0 M -1) M 3/2 ln(N) 1/4
, that is automatically satisfied by the previous condition for F 0

M

O(1), as evident from eq. ( 53), otherwise the stringent condition r e

F 0
M is required.

adding other dimensions to the linear wave

So far we focused on the dynamics along the linear direction of the fitness gradient x 1 . Here we address how the viral dynamics behaves in the other neutral directions. In particular we derive the shape of the cloud where n(x, t) > 0, and with perturbative arguments we address the nature of the trajectories of the average viral strain x n(x,t) (t).

Shape of viral dispersion

For the above formulas to be correct, one needs to assume that the wave is localized in the direction 2, . . . , d relative to the cross-reactivity scale r. The directions orthogonal to the direction of the wave are approximately neutral, but they still map to the wave in fitness space, they just don't advance the population fitness. Therefore the coalescence between two individuals is dominated by the faster-than-neutral process in the direction of selection. From [START_REF] Richard | E (14)[END_REF] we expect two individuals to have a common ancestor on average T 2 = ασ 2 /2D generations in the past. α is an unspecified numerical factor (1/day) between 1 and 2 resulting from numerical simulations in [START_REF] Richard | E (14)[END_REF] (cfr Fig. 3).

Since each individual diffuses with coefficient D, this means that the square root of the mean squared distance between two of them in each of the orthogonal directions should be 4D T 2 = √ 2ασ. We assume that the viral density profile is Gaussian also in the neutral directions. In this case the average distance in these directions between two randomly sampled viruses is simply √ 2σ ⊥ . Combining with the previous result we get σ ⊥ = √ ασ, which still depends on the numerical prefactor 1 < α < 2. Conveniently, this implies that the wave looks somewhat ellipsoid, slightly elongated in the neutral directions, but with linear dimensions of the same order of magnitude. Therefore the condition σ r automatically ensures localization in all dimensions.

Figure 20 shows that numerical simulations confirm (on average) this theoretical prediction. In this numerical check we tune the numerical prefactor α so that the theoretical predictions are asymptotically correct for large µ On the x-axis the standard deviation of the lineage density profile in antigenic space in the direction of motion σ multiplied by √ 1.7, on the y-axis the standard deviation of the lineage density profile in antigenic space in the direction perpendicular respect to that of motion σ ⊥ . σs are measured in units of δ for each lineage separately. Each point is the average of the observables time-series for a given parameters set, specified in the legend (apart from r that also varies). The gray line represents the identity. In all these simulation M = 1.

where the diffusion approximation of [START_REF] Richard | E (14)[END_REF] holds. The resulting α ∼ 1.7 is compatible with the numerical results in [START_REF] Richard | E (14)[END_REF]Fig. 3.

This result is also qualitatively consistent with the slightly elongated shape of the viral blob in the cartoon 14B, but note that the argument presented here holds only on average. At a given time snapshot fluctuations may drive the blob aspect ratio away from this theoretical prediction. But we don't expect fluctuations due to finite size to cause differences of orders of magnitude.

Lineage trajectory diffusivity in antigenic space

The tip of the noise of the wave moves forward with speed v, but it also diffuses in other dimensions with diffusivity D. Since the whole population is always founded by the tip of the noise, it's the motion of that tip and that tip alone that matters, so we can simply consider a diffusion process.

Following this idea, in a work still in progress (Marchi Mora Walczak, in preparation) we performed a perturbative analysis on the lineage trajectories. This led to some analytical insights on the lineage trajectory diffusivity in antigenic space, here I will just revise the main conceptual steps leading to the solution.

As the tip diffuses in the x i (i > 1) directions, it will also feel a "force" in these directions, derived from the gradient of f(x, t), ∂ i f(x, t). Recall that the speed of the wave goes as s 1/3 , where s = ∇ x f(x, t) at x 1 = vt, and in the direction of ∇ x f(x, t). The vector speed is:

v = v(s) ∇ x f(x, t)| x 1 =vt s . ( 64
)
We assume that the main direction is in x 1 , s ≈ ∂ x 1 f, treating the other directions perturbatively, so that for i > 1

v i ≈ v ∂ x i f ∂ x 1 f . ( 65
)
Let us use the shorhand x = x 1 , and y = x i for i > 1. The dynamics in y reads:

∂ t y = v ∂ y f ∂ x f + √ 2Dη(t), (66)
where η(t) is a Gaussian white noise of unit magnitude η(t)η(t ) = δ(tt ). That noise represents the fluctuations of the nose. We can approximate the viral wave as point-like at x = vt, y = y(t), so that it travels almost linearly along x with small orthogonal perturbations across a timescale set by τ. In this way we can solve for the first term in eq. ( 66) yielding (for long times):

∂ t y = ∞ 0 dt T y(t) -y(t -t ) t e -t /T + √ 2Dη(t), (67)
with T = R/v. Here in turn we have 1/R = 1/r + 1/(vτ), so that R is a generalized antigenic space scale accounting for both scales in our model. Eq. ( 67) means that the derivative of y is equal to the average slope with itself in the past, averaged with exponentially decaying kernel, to which noise is added.

We can analyze this equation in Fourier space and then transform back. In the long-time limit at leading order y follows a Langevin equation with no damping:

∂ 2 t y = √ 8D T η(t). ( 68
)
This means that the direction of propagation of the wave diffuses. In 2D, this direction is given by an angle α ≈ ∂ y f/s, so that at long times α follows a diffusion process with diffusivity 4D/R 2 :

∂ t α = √ 8D R η(t). (69)
The result generalizes to any dimension. As a result, at leading order the wave follows a persistent random walk with persistence length

L P = vR 2 /4D, (70)
with R = vτr/(vτ + r) = Mr/(M + sr) = r/(e F 0 /M ).

In order to verify the theoretical prediction in eq. ( 70) we are currently analyzing the results of numerical simulations of the model to infer trajectories persistence length.

conclusions and near future directions

In this Chapter we defined a coarse-grained phenomenological model for viral evolution in antigenic space driven by the hosts' immune update. This was inspired from intuition given by the study of an agent-based numerical model, introduced in Chapter 3 for the evolution of viruses giving rise to acute infections.

Our theoretical model allowed us to reach a more thorough understanding of the interplay of different epidemiological and evolutionary scales in this phylodynamic system. We made analytical progress assuming a stable wave solution. Under this assumption, viruses evolve in a stable wave in antigenic space resulting from an approximately linear fitness landscape where adaptation can continue indefinitely. At the same time we started investigating a numerical version of this model implemented from its microscopic ingredients. The theoretical predictions linking the epidemiological parameters to the features of antigenic evolution such as the strength of selection and the scale of immune memory, as well as a rescaled version of Fisher's theorem in antigenic space, are confirmed by simulations in the whole range of simulated parameters.

Then we mapped the traveling wave scaling derived in the diffusion limit in [START_REF] Cohen | Front propagation up a reaction rate gradient[END_REF][START_REF] Richard | E (14)[END_REF] to our model. Comparing the results with simulations we found a good agreement when the mutation rate µ is high enough. Consistently with the diffusion approximation, the scaling predictions break down for small mutation rate (given a fixed mutation effect). We can quantify the order of magnitude of µ at which the system crosses over to a different regime, ∼ 10 -3 days -1 . In the near future it would be interesting to see if we manage to derive some scalings for our model in the opposite regime, where evolution is driven by rare and large mutations.

Despite being more coarse-grained, this model qualitatively presents the same patterns of extinction and lineage splitting as the more detailed model of Chapter 3, that are also observed in nature for example in influenza evolution. A next step in this work in progress will be to perform analytical first-passage-time calculations to derive the extinction rates, and the transition between one to many co-evolving lineages. This could allow us to identify the mechanisms underlying these event, and whether they are driven by some reduced model coordinate that would be more compact to study rather than the many model parameters. Our intuition is that the host population can withstand at most M independent lineages, we are currently running other simulations to see if that's the case.

The co-evolution between antigens and immune receptors in an abstract phenotypic space was studied in a previous work [START_REF] Sasaki | Evolution of antigen drift/switching: continuously evading pathogens[END_REF]. They consider a situation of strong selection on antigens within one host, taking into account the explicit time evolution of the immune response during an infection. Therefore their model is more suitable to persistent infections where the immune response of each host drives the evolution of pathogens (such as HIV), rather than our scenario of acute infections where viral evolution is driven by the population immune memory. In their model there is no cross-reactivity, instead the system is stabilized by deleterious mutations. Despite the modeling differences, and the fact that they consider a purely deterministic system, they also observe the emergence of a stable wave of pathogens adaptation in phenotypic space. In future it could be interesting to see whether replacing cross-reactivity with deleterious mutations could also lead to different evolutionary trends and diffusion in a phenotypic space with dimension greater than 1.

Recently similar models of influenza phylodinamics were proposed [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225]. These made stringent assumptions on the dimensionality of the space where viruses evolve. Here we relax these assumptions in the model formulation. This allowed us to address some features of viral evolution such as antigenic organization of the viral population and diffusivity of viral lineages in antigenic space, which would have been even impossible to define otherwise. Unlike these works we also explicitly consider the capacity of immune repertoire, hoping to understand its impact.

Using the traveling wave scaling we found that viral lineages on average are concentrated in elliptical blobs slightly elongated on the neutral directions. This prediction was confirmed by simulations in the regime of validity of the traveling wave scalings.

Finally we derived analytically the persistence length of the average trajectory diffusion of viral lineages in antigenic space. Another near future task will be to validate this analytical result against simulations.

Part II So far this thesis focused mainly on coarse grained models addressing how interactions between individuals give rise to emergent behaviors at the population level at evolutionary timescales. We studied evolution in abstract phenotypic spaces, since evolutionary forces mainly act at the phenotype level. Therefore we did not consider the molecular-scale mechanisms giving rise to a given evolutionary outcome. In this second part of the thesis we will switch perspective and address the evolutionary forces constraining the principal microscopic constituent of living cells: proteins.

I N F E R E V O L U T I O N A R Y C O N S T R A I N T S AT F I N E R S C
Proteins are synthesized from genetic material through transcription and translation, and consist of amino-acid chains that will fold in a 3D structure depending on the biochemical interactions among the constituent aminoacids, on environmental variables such as temperature and PH, and on the interactions with other macromolecules in the cells. The resulting 3D structure will determine the set of functions that a protein will be able to perform according to the surrounding environment. This set of functions can be seen as the phenotype associated to a protein on which evolution is going to act: mutations in the genotype will propagate downstream to the phenotype and natural selection will favor those cells expressing a set of proteins whose function is fitter in the current environment. Therefore a protein phenotype is related to its 3D structure, and this is why the structure is often taken as a proxy for phenotype [START_REF] Anfinsen | Principles that Govern the Folding of Protein Chains[END_REF]. But even with this conceptual simplification, predicting a protein structure from its amino-acid sequence is an extremely hard challenge that has not a general solution. A lot of advances have been achieved in the protein folding field through advanced molecular dynamics algorithms that model the inter-amino-acid interactions to find the ground states of the folding dynamics. But, due to the huge number of degrees of freedom and the frustrated nature of the folding landscape, even the most advanced algorithms run on the most powerful supercomputer would not manage to explore all the free energy minima of a general protein sequence, even for relatively short sequences [START_REF] Levinthal | How to fold graciously[END_REF].

On the other hand, rapid progresses in DNA sequencing techniques made it easier and cheaper to put together sequences of formerly unexplored parts of genomes, which then can be translated into corresponding amino-acid sequences. As a consequence the number of available protein sequences is growing exponentially, but only a few of them are being manually annotated with experimentally observed 3D structures. For example in the open access proteins database UniProt [START_REF]UniProt: a hub for protein information[END_REF] there are currently 180 millions amino-acid sequences, only 560000 of which are annotated (0.3%) (https://www.uniprot. org/). In this situation we need to extract information on structure function and selection from this huge amount of sequences through statistical Figure 21 -Evolutionary constraints shaping the variability between homologous sequences: While constraints on individual residues (e.g., active sites) lead to variable levels of amino-acid conservation, the conservation of contacts leads to the coevolution of structurally neighboring residues and therefore to correlations between columns in a multiplesequence-alignment of homologous proteins (here an artificial alignment is shown for illustration). Figure and caption adapted from [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF] inference and computational modeling. As discussed above, direct numerical simulation techniques on single sequences can be an extremely powerful tool to increase the information we have on a few of these sequences, but it's not a viable strategy to retrieve this huge amount of missing information. Therefore we need to turn to probabilistic approaches to infer the desired observables from the available sequence statistics, and this is indeed the strategy we will adopt in this second part of the thesis.

In particular, the PFAM database (https://pfam.xfam.org/) stores protein sequences as multiple sequence alignments (MSA), classified into families of homologous sequences through alignment and classification bioinformatic tools that exploit the information present in the sequences single-site amino-acid compositions [START_REF] Finn | The Pfam protein families database: towards a more sustainable future[END_REF]. Each of these families contains sequences that share some recent common ancestor, and were selected through evolution to fold to a highly conserved 3D structure and to perform a similar set of functions. At the same time sequences within a family are highly variable, with an average 20-30% identity [START_REF] Bateman | The Pfam protein families database[END_REF][START_REF] Robert D Finn | Pfam: the protein families database[END_REF]. If we were to draw at random amino-acid sequences with the same variability the resulting proteins typically would not even be able to fold at all, let alone fold in a specific way and perform specific functions. This suggests that the process of evolution couples the generation of randomness through mutations to natural selection that acts through constraints which are very specific to each family. The statistics that sequences exhibit is a result of these two opposed forces, and, assuming that evolution acting on proteins families is close to equilibrium, we can use these resulting statistical observations to infer the evolutionary constraints acting on a family, such as 3D structure and contacts. For example the amount of variability on a single site of the MSA will inform of how crucial it is for folding that a specific amino-acid is found in that specific location (conservation). Or studying how changes in one site are related to changes in some other site can tell us what sites interact, either through contacts or indirectly (covariation). Figure 21 shows this relationship between structure and sequence statistics resulting from evolutionary constraints, that can in turn be exploited with statistical inference.

Many past works adopted this approach extracting information from sequence statistics. A first approach was to look at correlations between pairs of amino-acid sites, but these cannot distinguish between direct and indirect interactions and therefore are of little use to infer structural constraints [START_REF] Dunn | Mutual information without the influence of phylogeny or entropy dramatically improves residue contact prediction[END_REF][START_REF] Fodor | Influence of conservation on calculations of amino acid covariance in multiple sequence alignments[END_REF][START_REF] Angel | Ab initio folding of proteins using restraints derived from evolutionary information[END_REF]. In the past ten years great advances were made thanks to the introduction of the direct coupling analysis method, called DCA, that models the statistical ensemble of whole sequences all together rather than just focusing on 1 or 2-sites frequencies, and can therefore correctly distinguish direct from indirect interactions [START_REF] Morcos | Direct coupling analysis for protein contact prediction[END_REF][START_REF] Szurmant | Inter-residue, inter-protein and inter-family coevolution: bridging bridging the scales[END_REF][START_REF] Weigt | Identification of direct residue contacts in proteinprotein interaction by message passing[END_REF] . These new classes of models have been very successful in reproducing three dimensional structures, in particular in predicting what sites are in contact with each other [START_REF] Ekeberg | Improved contact prediction in proteins: using pseudolikelihoods to infer Potts models[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Espada | Capturing coevolutionary signals inrepeat proteins[END_REF][START_REF] Thomas | Three-dimensional structures of membrane proteins from genomic sequencing[END_REF][START_REF] Morcos | Direct-coupling analysis of residue coevolution captures native contacts across many protein families[END_REF][START_REF] Weigt | Identification of direct residue contacts in proteinprotein interaction by message passing[END_REF], but also in predicting other characteristics more closely linked to the evolutionary process, such as the effect of point mutations [START_REF] Contini | A many-body term improves the accuracy of effective potentials based on protein coevolutionary data[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Figliuzzi | Coevolutionary landscape inference and the context-dependence of mutations in beta-lactamase TEM-1[END_REF][START_REF] Haldane | Structural propensities of kinase family proteins from a Potts model of residue co-variation[END_REF][START_REF] Thomas | Mutation effects predicted from sequence co-variation[END_REF]. They even drove the synthesis of new functional proteins [START_REF] Russ | Evolution-based design of chorismate mutase enzymes[END_REF][START_REF] Socolich | Evolutionary information for specifying a protein fold[END_REF][START_REF] Tian | Co-Evolutionary Fitness Landscapes for Sequence Design[END_REF]. In the following we will give a short introduction on the concepts underlying these models, that are principally coming from statistical physics and Bayesian inference, and the principal computational techniques that can be used to infer them. Then we will briefly lay down the content of the next two thesis Chapters.

statistical mechanics, inference and protein sequences

Canonical ensemble

Statistical mechanics is a theoretical framework that allows us to describe complex ensembles of many interacting constituents. This framework aims to find analytical descriptions for macroscopic statistical observables characterizing the system (the macrostates), not caring about the deterministic microscopic dynamics of all of the constituents degrees of freedom (the microstates) which would be intractable. Instead it introduces a probabilistic approach determined by the few interaction rules between the constituents. By dropping the detailed microscopic description, statistical mechanics is able to produce extremely general models that can be applied to many different fields where the macroscopic phenomena typically fall onto the same small set of solutions. For example one can use the same class of models to describe superfluid helium, liquid crystals [START_REF] Chaikin | Principles of Condensed Matter Physics[END_REF] and flocks of birds [START_REF] Toner | Long-Range Order in a Two-Dimensional Dynamical XY Model: How Birds Fly Together[END_REF]. Now we give a short historical introduction to equilibrium statistical mechanics. We present standard textbook arguments in order to highlight few key concepts, that will be central in the remainder of this thesis.

One of the milestones of statistical mechanics, the Boltzmann distribution, relates the probability to observe a constituent (a particle) in a given microstate of the system to the energy of that state (in units defined by the system temperature). This was first derived by Boltzmann in 1877 (English trans-lation in [START_REF] Sharp | Translation of Ludwig Boltzmann's Paper "On the Relationship between the Second Fundamental Theorem of the Mechanical Theory of Heat and Probability Calculations Regarding the Conditions for Thermal Equilibrium[END_REF]) to describe the distribution of energy within an ideal gas of many particles in thermal bath. The result yields the famous expression:

P(σ) = e -βE(σ) Z , (71)
derived constraining the total number of particles and the total energy, where a microstate σ has energy E(σ) and β = 1 k B T is the inverse temperature that rescales the energy through the Boltzmann constant k B . The normalization Z = σ e -βE(σ) is called partition function. A key ingredient of this derivation is that particles interact weakly and can be considered as statistically independent.

Note that this derivation requires that the gas is in thermal equilibrium, therefore there is no net flow of energy in the system, which corresponds to no net flow of probability between the states. The presence or absence of equilibrium distinguishes statistical mechanics models into two branches, in-and out-of-equilibrium. In the latter case the detailed balance condition is violated and the system can present net flow of probability within its states. In general the out-of-equilibrium systems may not be in steady state, and the probability distribution over the states may change irreversibly over time. These are the kind of beasts we were dealing with in the first half of the thesis, whereas for the most part of this second half we will be using models that formally map onto equilibrium statistical mechanics.

In 1902 Gibbs gave a more general derivation of ( 71) in [START_REF] Gibbs | Elementary Principles in Statistical Mechanics[END_REF], which does not require that the microscopic constituents to be independent. He considered many identical systems composed by many microscopic constituents. Such subsystems thermally interact weekly, but there is no constraint on the interactions between constituents. The subsystems can exchange energy, while the total energy of the ensemble of such subsystems is constrained, so that, if the system is at equilibrium, the energy of each subsystem is constrained only on average to E = Ē. The fact that the whole systems is composed by many subsystems in thermal equilibrium implies that the temperature T is constant, and many modern formulations directly study one of such subsystems in thermal equilibrium with a much bigger heat reservoir. In statistical mechanics such an ensemble is called Canonical ensemble.

From here one way to derive the ensemble probability distribution (rather than counting the number of states with a given energy and applying the steepest descent method as did Boltzmann in his derivation) is to start from Gibbs' definition of entropy for one of such subsystems:

S = -k B σ P(σ) ln P(σ), (72)
where we indicate again system states as σ. Then, since the system is at equilibrium, we can exploit the second law of thermodynamics and require that the probability distribution over the phase space is the one maximizing the entropy, while constraining the average energy of the system. Hence we just have to solve the following simple Lagrange multipliers problem (imposing also the normalization condition for the probability distribution):

P(σ) = arg max P(σ) -k B σ P(σ) ln P(σ) -k B λ σ P(σ) -1 -k B β σ P(σ)E(σ) -Ē . ( 73
)
The solution yields again [START_REF] Philip | The fate of competing beneficial mutations in an asexual population[END_REF], but now in a much more general scope. This procedure of maximizing the entropy under a set of constraints, which in this context was called Gibbs algorithm, was a precursor of the more general inference paradigm named Maximum entropy principleintroduced by Jaynes [START_REF] Jaynes | Information Theory and Statistical Mechanics. II[END_REF][START_REF] Jaynes | Information Theory and Statistical Mechanics[END_REF], that we will see in a moment.

Another key quantity that characterize the canonical ensemble is the Helmoltz free energy, which is a constant (with respect to the ensemble that still depends on state variables such as temperature) carrying information about all the ensemble microstates. In fact it carries the same amount of information as the partition function:

F(T ) = E -T S = - ln(Z(β)) β . ( 74
)
One important characteristics of the partition function is that the ensemble average of any term A appearing in the Hamiltonian coupled to a parameter λ, E = E 0 + λA, can be easily calculated as a derivative:

A = - 1 β ∂ ln(Z) ∂λ . ( 75
)
This holds for the average energy as well:

E = - ∂ ln(Z) ∂β . ( 76
)
In general this functional relation holds between any pairs of conjugate intensive and extensive variables where intensive variable is fixed in that specific ensemble, but note that finding the analytical solution of the partition function (or equivalently the free energy) sometimes is not possible, in which cases one must recur to perturbative or numerical methods like Monte-Carlo sampling (introduced in section 2.2.3). Importantly, the same argument also give us a recipe to address the fluctuations of the system observables, for example for the energy we have:

E 2 -E 2 = ∂ 2 ln(Z) ∂β 2 = ∂ E ∂β = C v k B β 2 , (77)
relating energy fluctuation with the heat capacity, therefore with the response of the energy upon temperature perturbations. This is one of the most basic forms of the fluctuation-dissipation theorem which relates the thermal fluctuations of a system quantity in equilibrium with the dissipation process taking place when driving the system out of equilibrium.

One last thing to note is that here we described only the canonical ensemble, where the fixed quantities are temperature, volume and number of particles, but changing what quantities are constrained we obtain different ensembles. If one allows the number of particles to fluctuate while fixing its conjugate variable, the chemical potential, we have the grand canonical ensemble, while constraining the system energy we have the microcanonical ensemble. Under certain conditions, all of these ensembles are "equivalent" in the thermodynamic limit, that is when the number of constituents N → ∞. This is known as the equivalence of ensembles. In fact one has to specify what he means by "equivalent". Here we refer to the so-called thermodynamic equivalence, which means that the thermodynamics quantities derived from the entropy and from the free energy in the microcanonical and canonical ensembles respectively are the same. This holds whenever the entropy is convex. Requiring that the measures of two ensembles converge (in some rigorous mathematical sense) to the same probability distribution is a much stricter condition and less is known about under what conditions this formally holds [START_REF] Touchette | Equivalence and Nonequivalence of Ensembles: Thermodynamic, Macrostate, and Measure Levels[END_REF]. In the microcanonical ensemble all the microstates whose energy falls within an infinitely small range around Ẽ have equal probability P = 1/W( Ẽ), where W( Ẽ) is the number of such microstates, and 0 otherwise. One possible definition of entropy for such ensemble is the Boltzmann entropy:

S B ( Ẽ) = k B ln W( Ẽ), (78)
that counts the number of microstates with non-zero probability, and can be shown to be equivalent in thermodynamic limit to the entropy calculated counting all microstates with energy lower than Ẽ as if P(E) ∝ Θ( Ẽ -E). In this ensemble temperature is defined as 1/(∂S B /∂ Ẽ). In a continuous system, we can write the canonical partition function as:

Z = d Ẽe -β Ẽ dσδ( Ẽ -E(σ)) = d Ẽe -β Ẽ+S B ( Ẽ) = d Ẽe -N(β ˜ -s B ( Ẽ) , (79)
where in the last passage we simply wrote explicitly the energy and Boltzmann entropy s B per degree of freedom. In the thermodynamic limit, if ∂ 2 S B /∂ Ẽ2 < 0, we can evaluate the integral by saddle-point, yielding

log Z ∼ -inf Ẽ β Ẽ -S B ( Ẽ) , (80)
by comparing ( 80) and ( 74) we learn that βF and S B are the Legendre transform of one another, and therefore the thermodynamic quantities obtained deriving one or the other will be the same. In particular one can see directly that the entropies of the two ensembles coincide and that Ẽ = E , where the canonical average is taken at inverse temperature β = ∂S B /∂ Ẽ, given by the minimization.

The canonical ensemble and the concept of statistical equilibrium will be central in the remainder of the thesis, and in 6 we will make use of the equivalence of microcanonical and canonical entropies and of the fluctuationdissipation theorem, the latter indirectly.

Maximum Likelihood

As we mentioned above, the perspective of this second part of the thesis is to infer a statistical model, parametrized by a set of parameters Θ, which are the unknown we need to estimate from a set of M N-dimensional observations O = x 1 , x 2 , . . . , x M , in this case the amino-acid sequences in the MSA. Given a model Θ, the probability that it generates the observable x is P(x|Θ), that is the likelihood of x under the given model. We can use Bayes theorem to express the posterior probability that a model Θ is the true process underlying a set of given observables :

P(Θ|O) = P(O|Θ)P(Θ) P(O) . ( 81
)
If we have no prior information on the parameters distribution, we would consider an uniform P(Θ), and the posterior becomes proportional to the likelihood, P(Θ|O) ∝ P(O|Θ). Maximizing with respect to Θ gives the so called Maximum Likelihood Estimator Θ ML for the model parameters, that has many important properties, such as that for large sample sizes is the most "precise" (lowest mean squared error) consistent estimator for Θ [START_REF] Nguyen | Inverse statistical problems: from the inverse Ising problem to data science[END_REF]. We can conveniently write it in log-space as:

Θ ML = arg max Θ {log (P(O|Θ))} . (82)
Note that if we include a prior on the parameters in the maximization, then we have the maximum a posteriori estimator :

Θ MAP = arg max Θ {log (P(O|Θ)) + log (P(Θ))} , (83)
which is formally equivalent to maximum likelihood with some regularization constraint on the parameters, that we will see below in the context of our protein sequences inference.

Maximum Entropy principle and inverse Potts problem

In order to be able to apply [START_REF] Hallatschek | The noisy edge of traveling waves[END_REF] to a concrete inference problem like ours one still has to specify the functional dependence of P(x|Θ) on Θ. We do not have any prior knowledge on that, but we have a set of empirical observables that we can compute on the MSA, and the minimal requirement that the inferred statistical model must meet is to reproduce such observables. More precisely we want a statistical model P(σ) for the MSA amino-acid sequences σ = σ 1 , σ 2 , . . . , σ i , . . . , σ N , where with σ i we indicate the amino-acid present at position i in the sequence, that can take values from 1 to q = 21 (20 aminoacids symbols, plus a symbol for the alignment gaps). The model has to reproduce some moments (in our case the first and second moments) of a set of observables. For example if the model must reproduce the observable O(σ) on average we will impose the ensemble average to be equal to the empirical sample average of O:

σ P(σ)O(σ) = 1 M M s=1 O(σ s ),
where the left-hand-side sum is taken over all possible configurations (sequences), whereas on the right we have a sum over the M sequences in the MSA.

From the MSA we compute the sample-average occurrence, i. e.the empirical frequency, of having an amino-acid σ i = a at position i f i (a), as well as the 2-points empirical frequency f i,j (a, b):

f i (a) = 1 M M s=1 δ σ s i ,a , (84)
f i,j (a, b) = 1 M M s=1 δ σ s i ,a δ σ s j ,b . (85)
Then we want:

p i (a) := σ P(σ)δ σ i ,a = f i (a), (86)
p i,j (a, b) := σ P(σ)δ σ i ,a δ σ j ,b = f i,j (a, b), (87)
for all i, j > i, a, b.

While imposing these constraints we want the model to be as random as possible, therefore we want to apply a Lagrange multiplier problem to the Shannon entropy

S = - σ P(σ) ln P(σ), (88)
which is analogous to what we saw before in the derivation of the canonical ensemble. The maximization reads:

P(σ) = arg max P(σ) - σ P(σ) ln P(σ) -λ σ P(σ) -1 + i a h i (a) σ P(σ)δ σ i ,a -f i (a) + i<j a,b J ij (a, b) σ P(σ)δ σ i ,a δ σ j ,b -f i,j (a, b)    . (89)
The solution yields a Boltzmann equilibrium distribution of the form (71), with Hamiltonian:

E(σ) = - i h i (σ i ) - i<j J ij (σ i , σ j ) , (90)
that is the Hamiltonian of a Potts model (whose restriction to the binary case q = 2 is the Ising model) with external fields h an couplings J. Hence we are back to the canonical ensemble we introduced above, with partition function Z(h, J) = σ e β( i h i (σ i )+ i<j J ij (σ i ,σ j )) . This inference framework of maximizing the Shannon entropy while constraining some empirical observables moments is the afore-mentioned Maximum Entropy principle, named MaxEnt, introduced by Jaynes in 1957 [START_REF] Jaynes | Information Theory and Statistical Mechanics. II[END_REF][START_REF] Jaynes | Information Theory and Statistical Mechanics[END_REF]. The idea is that the best model choice is the one that does not introduce any constraint or information other than what is directly deductible from the prior data at hand. In his works, Jaynes emphasized the correspondence between statistical mechanics and information theory, arguing that Gibbs and Shannon entropy are basically the same thing, and proposed a view of statistical mechanics as an application of a more general inference tool to deal with incomplete knowledge.

The maximum entropy principle was criticized due to the arbitrary freedom in what information to feed to the model and what observables to constrain in cases where such a choice may not be obvious. Specifically the use of MaxEnt for DCA (direct coupling analysis) was criticized mainly for two reasons. First, such simple pairwise models cannot capture the true, complex, fitness function ruling protein evolution, and therefore are not true, general, generative models for protein sequences that would generally fold and perform the function expected from the studied protein family. But in fact most of the times that is not the purpose that MaxEnt is used for. Rather, one feeds some specific and controlled information (through the constrained observables) to the model, and checks in what such informed model succeeds, and in what ways it fails if it does, which is still a very informative process. Therefore, quoting [START_REF] Van Nimwegen | Inferring Contacting Residues within and between Proteins: What Do the Probabilities Mean?[END_REF], success or failure of the max-ent distribution on a particular problem has little to do with whether it accurately describes a "true" distribution, but rather reflects to what extent the provided information suffices for solving the problem at hand. Not to mention the fact that usually we have very little information on such true distribution anyways, so this criticism turns out to be sterile, if applied unconditionally.

The second main criticism is that we are not feeding all of the information at disposal to the model since we have the whole MSA but we compress the constraints to first and second moments, or equivalently pairwise interactions, while in principle higher order interaction may play an important role, as suggested by the fact that deep-learning techniques effectively accounting for higher order statistics recently outperformed pairwise methods in predicting structure from amino-acid sequences [START_REF] Alquraishi | End-to-end differentiable learning of protein structure[END_REF][START_REF] Senior | Improved protein structure prediction using potentials from deep learning[END_REF]. A pragmatic reason for this choice can be that to accurately estimate higher order correlations one needs much more data. Regardless, as shown by many previous works, pairwise correlations are usually enough in this context to extract a lot of useful information, and even to make predictions on higher order observables not used to learn the model [50, 51, 57, 132-134, 150, 198, 202, 219].

Here we will follow the line of these works, and we will use MaxEnt feeding it with precise information to address precise questions. In doing so we are aware of the implications of the constraints choice, and of the formalism limitations in not providing unlimited answers to a problem with limited available information, be it data or prior knowledge coming from the laws of physics and chemistry. To explain this concept with a simple analogy, if you want to use MaxEnt to model the "true" 3D probability of desks position in a room, you either need data about the z coordinate (showing they all lay on the floor) or you have to include prior knowledge on a physical force breaking the symmetry of the z direction: gravity. Otherwise your generated desks will be floating in the air uniformly distributed in z. On the other hand if you just want to distinguish two rooms where desks are systematically disposed in different ways, you are perfectly fine ignoring any information about z and gravity, and this is indeed the spirit in which we will apply MaxEnt to proteins in this second half of the thesis.

Returning to the inference problem under study, thanks to MaxEnt we derived the functional form of the statistical model P(σ|h, J) on the parameters h, J, and we can now write explicitly the log-likelihood (82) to maximize to find the maximum likelihood parameters h, J ML :

h, J ML = arg max h,J {L(O|h, J)} = arg max h,J    i a h i (a)f i (a) + i<j a,b J ij (a, b)f i,j (a, b) -log (Z(h, J))    . ( 91
)
The underlying assumption when writing the log-likelihood as a sum of independent terms is that the data samples are drawn from the underlying distribution as independent random variables. In the case of homologous proteins MSAs this is far from the truth since sequences are related by some recent common ancestor. Therefore all statistics computed on these sequences must be re-weighted to correct for sequence similarities due to this phylogenetic effect (see [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF] for more details). This reweighting is a hack that has to be done ad-hoc for any dataset, as we will further discuss in Chapter 8. A last important remark is that the optimization problem of the cross-entropy is convex [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF][START_REF] Nguyen | Inverse statistical problems: from the inverse Ising problem to data science[END_REF], or equivalently the maximization in ( 91) is concave . With this we close the circle between protein sequences, statistical physics and inference, on which is grounded the rest of this thesis.

parameters and optimization

Boltzmann learning

We finally derived an explicit function to maximize to find our best estimate parameters (91) via convex optimization, but this depends explicitly on the system partition function. As we already mentioned, in most practical applications it is not possible to calculate it analytically, therefore we need some way to estimate approximately the log-likelihood. Here we present the algorithm we will use later, sometimes called Boltzmann learning. There are other methods one can choose, the interested reader can find a detailed description of such methods in [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF], alongside their strengths and limitations. Among these, Boltzmann learning is the most intuitive and robust, but comes with an high computational cost. Luckily the systems we will apply it to are small enough so that we can use this method.

To reach the likelihood maximum, which is the last necessary step to learn the statistical model, we perform a numerical gradient ascent by updating the parameters according to the log-likelihood gradient ∇ h,J L(h, J), whose components can be computed from (91) as:

∂L(h, J) ∂h i (a) = f i (a) -p i (a), (92)
∂L(h, J) ∂J ij (a, b) = f i,j (a, b) -p i,j (a, b), (93)
therefore the gradient is just the difference between the empirical and the model frequencies, which is not surprising since the parameters were introduced as Lagrange multipliers in [START_REF] Jaynes | Information Theory and Statistical Mechanics[END_REF] to ensure the moments matching conditions ( 86), [START_REF] Jacquin | Benchmarking Inverse Statistical Approaches for Protein Structure and Design with Exactly Solvable Models[END_REF].

At each iteration of the parameters update, we generate many sequences through Monte-Carlo sampling, according to the Boltzmann probability P(σ|h, J) defined by the current parameters. Then we compute the model generated amino-acid frequencies as an estimate of the true model probabilities,

p i (a) ∼ f MC i (a) and p i,j (a, b) ∼ f MC i,j (a, b).
Then we can update the model parameters for the next iteration t + 1 as

h i (a) t+1 ← h i (a) t + i [f i (a) -f MC i (a)], (94)
J ij (a, b) t+1 ← J ij (a, b) t + ij [f ij (a, b) -f MC ij (a, b)]. (95)
If we choose update parameters s small enough, we can repeat this procedure and we are guaranteed to reach the maximum after a certain number of iterations thanks to the convexity of the problem. But in the convergent regime, the lower the s, the longer it will take to converge. There are some ways to speed up the convergence of gradient descent algorithms, for example make depend on the iteration t (as done for example in [START_REF] Tkacik | Ising models for networks of real neurons[END_REF]), or add an inertia term to the update rules mimicking acceleration [START_REF] Goh | Why Momentum Really Works[END_REF], as introduced by Polyak in 1964 [START_REF] Polyak | Some methods of speeding up the convergence of iteration methods[END_REF]:

h i (a) t+1 ← h i (a) t + i [f i (a) -f MC i (a)] + I i (h i (a) t -h i (a) t-1 ), (96)
J ij (a, b) t+1 ← J ij (a, b) t + ij [f ij (a, b) -f MC ij (a, b)] + I ij (J ij (a, b) t -J ij (a, b) t-1 ), (97)
which is the algorithm we will use in Chapter 7. If convenient for the specific optimization problem to be solved, one can also make the inertia term depend on the iteration as I(t), typically through the so-called Nesterov's accelerated gradient method [START_REF] Nesterov | A method for solving the convex programming problem with convergence rate O(1/k2)[END_REF][START_REF] Su | A Differential Equation for Modeling Nesterov's Accelerated Gradient Method: Theory and Insights[END_REF]. This is very important for example for training deep neural networks [START_REF] Sutskever | On the importance of initialization and momentum in deep learning[END_REF]. One may naively think that solving a convex optimization problem is an easy task, but in practice, when dealing with ill-conditioned, discontinuous, and/or high dimensional functions (which is our case) this is far from being true. Convex optimization is a big computer science sub-field on its own.

Gauge invariance and regularization

The frequencies f i (a) and f ij (a, b) we used to constrain the Lq + L(L-1) 2 q 2 parameters through (86) [START_REF] Jacquin | Benchmarking Inverse Statistical Approaches for Protein Structure and Design with Exactly Solvable Models[END_REF] are not all independent from each other since the f ij (a, b) reduce to the f i (a) when marginalized, which in turn sum up to 1. Therefore the independent parameters are only L(q -1) + L(L-1) 2 (q -1) 2 . This leads the Hamiltonian (90) to be invariant under a class of gauge transformations of its parameters [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF] that change the model energy only up to an additive constant, therefore leaving the ensemble distribution P(σ) unchanged. We can fix a gauge for the Hamiltonian, for instance the widely used "zero-sum gauge". We can do this introducing the transformed fields h, J such that E(σ| h, J) = E(σ|h, J) + C ∀σ and

a hi (a) = a Jij (a, σ j ) = b Jij (σ i , b) = 0 ∀i, j, σ i , σ j . ( 98
)
The solution, using the symmetry J ij (σ i , σ j ) = J ji (σ j , σ i ), reads:

hi

(σ i ) = h i (σ i ) - 1 q a h i (a) + 1 2q j =i b J ij (σ i , b) + a J ji (a, σ i ) - 2 q a,b J ij (a, b) , (99)
Jij (σ i , σ j ) = J ij (σ i , σ j ) - 1 q a J ij (a, σ j ) - 1 q b J ij (σ i , b) + 1 q 2 a,b J ij (a, b), (100)
C = 1 q i a h i (a) + 1 2q 2 i,j a,b J ij (a, b). ( 101
)
This gauge sets the energy scale so that randomly sequences drawn from a uniform amino-acid distribution have on average 0 energy. Another effect of the huge number of parameters, especially when these are significantly more than the number of samples to compute the empirical frequencies, is overfitting of rare patterns, as clearly explained in [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF]. In order to avoid this effect, but also to speed up the learning convergence, we can apply a penalty, or regularization, on the parameters. For instance we can impose some constraint on their L 2 norm so that they cannot take arbitrarily big values, and the object to be maximized would now be:

L(O|h, J) = i a h i (a)f i (a) + i<j a,b J ij (a, b)f i,j (a, b) -log (Z(h, J)) - γ 1 i a h i (a) 2 -γ 2 i<j a,b J ij (a, b) 2 . ( 102
)
Otherwise one can choose to apply a penalty on the L 1 norm

L(O|h, J) = i a h i (a)f i (a) + i<j a,b J ij (a, b)f i,j (a, b) -log (Z(h, J)) - γ 1 i a |h i (a)| -γ 2 i<j a,b |J ij (a, b)|, (103)
that in addition to large parameters, penalizes very small ones forcing a subset of parameters to 0, and therefore enforcing a sparse solution. In the following we will use the latter regularization on the Js, which are the leading term in parameters number. Comparing ( 102) and ( 103) to [START_REF] George | Studies of a n t i g e n i c d i f f e r e n c e s among strains of i n f l u e n z a a by means of r e d cell a g g l u t i n a t i o n[END_REF] we see that adding a regularization to the likelihood is equivalent to performing a MAP with a non-uniform parameters prior P(Θ), in this case Gaussian and exponential respectively. Finally another effect of regularization is that it lifts the gauge degeneracy. So for example, if for some application one cares about what Js are set to 0 by the L 1 regularization, then he should not fix an explicit gauge.

general applications of dca

So far we have given a broad yet synthetic overview of the basic theoretical concepts and techniques underlying inference on homologous proteins MSAs,. As briefly mentioned in 5.1 DCA provides an inference scheme to learn a statistical model for whole sequences P(σ).

Now we can describe a couple of applications that this method is typically used for. One direct way of using P(σ) of a certain protein family, is to use it as "generative" model to look for highly represented sequences that are not present in the empirical dataset and inspect their properties with respect to the reference family. For the reasons discussed in 5.2.3 these may very well fail to fold. When they do fold and have the expected properties this leads to the discovery of viable controlled synthetic proteins that may turn useful in a range of applications, such as drug design [START_REF] Russ | Evolution-based design of chorismate mutase enzymes[END_REF][START_REF] Socolich | Evolutionary information for specifying a protein fold[END_REF][START_REF] Tian | Co-Evolutionary Fitness Landscapes for Sequence Design[END_REF]. When these sequences do not fold, the way this fails may still be informative on some key biochemical properties missing in the statistical model, and on why such properties were not captured by an ensemble of sequences undergoing natural selection.

Otherwise the statistical model can also be used as a classifier, determining the probability that some new sequence, not present in the learning statistics, belong to a given family. This is referred to as homology detection [START_REF] Jacquin | Benchmarking Inverse Statistical Approaches for Protein Structure and Design with Exactly Solvable Models[END_REF].

As we explained in 5.1, the connection between proteins 3D structure, evolution, and sequence statistics makes DCA a very powerful tool to predict structures, and in particular contacts between couples of amino-acid sites [START_REF] Ekeberg | Improved contact prediction in proteins: using pseudolikelihoods to infer Potts models[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Espada | Capturing coevolutionary signals inrepeat proteins[END_REF][START_REF] Thomas | Three-dimensional structures of membrane proteins from genomic sequencing[END_REF][START_REF] Jacquin | Benchmarking Inverse Statistical Approaches for Protein Structure and Design with Exactly Solvable Models[END_REF][START_REF] Morcos | Direct-coupling analysis of residue coevolution captures native contacts across many protein families[END_REF][START_REF] Weigt | Identification of direct residue contacts in proteinprotein interaction by message passing[END_REF]. To do so, we need to fix a gauge for the inferred parameters, as the one introduced in 5.3.2. Then a good predictor for contacts is the "coupling strength" between sites i, j, calculated as the Frobenius norm of the submatrix J ij (•, •):

C i,j = a,b J ij (a, b) 2 . ( 104
)
Finally, we can use the inferred Hamiltonian to predict fitness effect of mutations [START_REF] Contini | A many-body term improves the accuracy of effective potentials based on protein coevolutionary data[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Figliuzzi | Coevolutionary landscape inference and the context-dependence of mutations in beta-lactamase TEM-1[END_REF][START_REF] Haldane | Structural propensities of kinase family proteins from a Potts model of residue co-variation[END_REF], for example using as a proxy for the fitness the unfolding energy difference between mutants and wild type ∆∆G. In 6.3.2 below we provide an illustrative argument for the relation between statistical and unfolding energy in a simple equilibrium population genetics setting. Note that nor this last paragraph nor the simple conceptual sketch in 6.3.2 imply that the model reproduces the whole true protein distribution and the exact fitness function across the whole sequence space via the statistical energy E(σ). Therefore they are not in contrast with what discussed in 5.2.3. The fact that E(σ) can be used to predict point mutations effects with respect to reference wildtypes means that it's a good approximation for the fitness in the vicinity of well represented sequences.

repeat proteins families

Repeat proteins

In the following, we will apply the method introduced above to infer statistical models for a specific kind of proteins: repeat proteins. Repeat proteins are proteins where some modular part of typical length l r ∼ 20 -40 amino-acids, named repeat, is repeated many times in a tandem array. These tandems produce typical structural motifs, characterized accordeonlike folds, with interactions both in and between different repeats (fig. 22) that are all crucial for the protein folding to be successful. As a result these proteins tend to fold into elongated structures with simple topologies and yet great application potential, that made them a successful target for protein design [START_REF] Tj Brunette | Exploring the repeat protein universe through computational protein design[END_REF][START_REF] Rowling | Dissecting and reprogramming the folding and assembly of tandem-repeat proteins[END_REF][START_REF] Urvoas | Design, production and molecular structure of a new family of artificial alpha-helicoidal repeat proteins (αRep) based on thermostable HEAT-like repeats[END_REF].

Repeat tandems are ubiquitous in proteomes across the tree of life. They occur in 14% of all proteins [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF], and they represent about 6% of polypeptide sequences codified in eukaryotic genomes [START_REF] Åsa K Björklund | Expansion of protein domain repeats[END_REF]. They are frequently found in contexts where they mediate protein-protein interactions with a surprisingly high specificity and in important signaling proteins [START_REF] Gregory | The tetratricopeptide repeat: a structural motif mediating protein-protein interactions[END_REF][START_REF] Kobe | The leucine-rich repeat as a protein recognition motif[END_REF][START_REF] Li | Ankyrin repeat: a unique motif mediating protein-protein interactions[END_REF][START_REF] Steven | The ankyrin repeat: a diversity of interactions on a common structural framework[END_REF]. Moreover a repeat protein family, LRR, was found to play a fundamental role in the adaptive immune system of jawless vertebrates [START_REF] Pancer | Somatic diversification of variable lymphocyte receptors in the agnathan sea lamprey[END_REF]. These findings suggest that their modular structure make these proteins very fit in general for target-specific binding, and binding modularly to many different targets at the same time. This high occurrence of the "repeat tandem strategy" across evolution points to some very general advantage in their modular composition. What such advantage could be is also related to the question of how tandem repeats arise in a first place. Apart from amino-acid mutations, repeat proteins are believed to evolve via duplication, deletions and rearrangement of whole repeats [START_REF] Schüler | Evolution of protein domain repeats in Metazoa[END_REF]. This may effectively speed up evolution of repeat proteins, since they can duplicate and move around long sequences parts that were previously selected for stability. Hence it was hypothesized that, apart from the binding efficiency mentioned above, this lower evolutionary cost may play a role in repeat tandems success [START_REF] Andrade | Protein Repeats: Structures, Functions, and Evolution[END_REF]. Then, this is also related to the question of what is the fundamental repeated unit that remains functional when isolated from the rest of the array. These are all important questions that remain largely unanswered. Little is known even on the molecular mechanisms underlying repeat duplications and deletions and linking these to selection [START_REF] Schüler | Evolution of protein domain repeats in Metazoa[END_REF]. Therefore repeat proteins constitute a great research challenge in the road to understand proteins evolution, from sequence to folding to function.

It seems reasonable that repeat proteins "linear" topology and the consequent approximate discrete translational invariance across the tandem array has to do with the process of duplication and deletion of repeats. At the sequence level this introduces some global similarity between repeats that are originating from a common ancestor, typically after a duplication that puts two equal repeats next to each other, and the degree of similarity depends on the phylogenetic relationship between the repeats. This similarity can be quantified by the repeat identity, the number of matches between two repeats (repeat 1 and repeat 2 for instance) amino-acid sequences

ID 1,2 = l r i=1 δ(σ 1 i , σ 2 i )
, where i is the amino-acid position in the repeat, going from 1 to the repeat length l r . These phylogenetic effects within the same protein mix themselves with the inter-repeat interactions that enforce some functional constraints, and confound the statistical analysis. Recently a DCA scheme was proposed taking into account these global effect [START_REF] Espada | Capturing coevolutionary signals inrepeat proteins[END_REF], and then the same authors proposed a way to infer a repeat proteins family statistical model that introduces a global term λ ID in the Potts statistical energy (90) in order to disentangle the global phylogenetic effects from the inter-repeat evolutionary constraints [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF]. We will use the same inference scheme in 6.

Repeat proteins represent a relatively simple system thanks to their modularity, but at the same time they present a rich variety of effects acting at different scales, shaping the outcome of their evolution. They have local within-repeat interactions, long-range interactions between different repeats, and global high order correlation due to phylogeny, similar to those between homologous sequences but on the same protein sequence. The simultaneous presence of these different constraints, which can be mapped and disentangled, make these proteins a rich object to study the impact of such constraints both at the local amino-acid sites level and at the global evolutionary sequence space level (which will be the goal of Chapter 6).

These phylogenetic effects between repeats can be mapped to some molecular duplication-deletion mechanism that acts locally on the sequence, in the sense that duplicated twins are found next to each other in the tandem array. The empirical sequence statistics could then be used to learn something on this mechanism ruling repeats evolution (which we will try to do in Chapter 7). A future perspective then could be to generalize this evolutionary mechanism and link it to the broader-scale diversity of repeats within the whole family across different organisms, aiming at extracting some information on the general multi-scale processes underlying forward proteins evolution.

The last implication of repeat proteins linear modularity is that, if one can identify the building block of this tandem array that can independently fold and then combine in a repetitive fashion [START_REF] Diego U Ferreiro | The energy landscapes of repeat-containing proteins: topology, cooperativity, and the folding funnels of one-dimensional architectures[END_REF], this gives an excellent lower dimension study model to address the coupling between sequence and structure. B) The local constraints also make the "evolutionary energy landscape" rugged, with local minima, where proteins sequences can get stuck during the evolutionary process, of which the coarse-grained partition into families is a first exampled. The set of sequences that evolve to a given local minimum defines the basin of attraction of that minimum. Panel B from [START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF] We will exploit this aspect by studying some of these blocks, identified as consecutive repeat pairs consisting of L = 50 -70 amino-acid sequences. This greatly reduces the dimensionality of the inference problem with respect to having to infer a statistical energy of whole arrays of hundreds amino-acids, which are otherwise typical sizes in DCA studies. In this case the number of parameters is of order O((Lq) 2 ) ∼ 10 6 , and we study highly abundant protein families, with at least 10 4-5 sequences in the MSA, implying 10 7-8 samples to estimate empirical frequencies. Working in this relatively well represented regime easies some technical difficulties, such as model learning computational cost and overfitting, at least in relative terms with respect to typical DCA research.

Global ensemble features of repeat proteins sequence space

Generally the inference scheme introduced above was used successfully to address local amino-acid constraints, important for the protein function, enforced by evolution on some protein family sequences, as mentioned above. But little is known about the effect of these local constraints on the global features of a protein family sequence space.

Such local effects will constrain the total number of that family sequences that could ever be accessible by evolution (in the sense that would fold and perform a specific function), which as we discussed earlier is orders of magnitude lower than the total possible polypeptide strings of a given length [START_REF] David | How much of protein sequence space has been explored by life on Earth ?[END_REF][START_REF] Shakhnovich | Protein design : a perspective from simple tractable models[END_REF]. A statistical analysis on the sequences that were sampled so far can aim at addressing this issue by quantifying some proxy for the size of the evo-lutionary accessible sequence space of some protein family, as sketched in fig. 24A. The relationship between sequence statistics and number of evolvable sequences, sometimes passing through folding, have been addressed in few precedent works [11, 44-46, 129, 189, 203]. In Chapter 6, that is a direct reprint of our published work [START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF], we follow this line of research and use the inference and statistical mechanics tools introduced in 5.2 to estimate the space of accessible sequences via the Shannon entropy (88) of the inferred statistical ensemble P(σ). Exploiting the separability of multiscale mappable constraints present in repeat-proteins we could go beyond previous works addressing precisely their relative effects.

Apart from the accessible sequence space size, the local constraints also affect the shape of this high-dimensional space by introducing some ruggedness in the evolutionary fitness landscape, in similar way as proteins are structured in families performing different sets of functions (fig. 24B). In Chapter 6 we also address this aspect, asking whether the proteins sequence space is homogeneous or it shows signature of different "basins" or subfamilies.

Making sense of empirical patterns: repeats evolutionary model

As mentioned in 5.5.1 it is believed that repeat tandems evolve via point mutations plus duplications, deletions and rearrangement of global repeats [START_REF] Andrade | Protein Repeats: Structures, Functions, and Evolution[END_REF][START_REF] Schüler | Evolution of protein domain repeats in Metazoa[END_REF]. Such a mechanism, apart from generating a universe of arrays of different lengths within the same family, would propagate phylogenetic effects within the same repeat array, impacting its amount of discrete translational invariance, i. e.the similarity between different repeats quantified by the identity ID 1,2 = l r i=1 δ(σ 1 i , σ 2 i ), disregarding alignment gaps. A recent study [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF] recapitulated some interesting statistical patterns characterizing length and inter-repeat similarity of the Ankyrin family ANK. Chapter 7 summarizes a work that is currently in preparation, in collaboration with Ezequiel Galpern and Diego Ferreiro at the University of Buenos Aires. In this work we extract some statistical observations from the same dataset studied in [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF], summarized in fig. 25.

We study a simple evolutionary model for repeat proteins, where mutations occur on top of repeat duplications and deletions. Fig. 34 outlines the key events underlying this simple model. We use this basic model combined with the inverse Potts model inference scheme to learn its parameters, in order to reproduce the empirical amino-acid frequencies introduced above, f i (σ i ) and f ij (σ i , σ j ), as well as the average first neighbors similarity ID 1st , that is the average of 25B. Then we address what other aspects of the statistics in fig. 25B,C,D this basic "null" model manages to capture, and what fundamentally novel ingredients are necessary to qualitatively reproduce more empirical trends. This gives a robust way of addressing the underlying processes behind repeat arrays evolution, in order to discriminate between different mechanisms at least qualitatively while still inferring quantitative features of this evolutionary process.

S I Z E A N D S T R U C T U R E O F T H E S E Q U E N C E S PA C E O F R E P E AT P R O T E I N S

abstract

The coding space of protein sequences is shaped by evolutionary constraints set by requirements of function and stability. We show that the coding space of a given protein family -the total number of sequences in that family-can be estimated using models of maximum entropy trained on multiple sequence alignments of naturally occuring amino acid sequences. We analyzed and calculated the size of three abundant repeat proteins families, whose members are large proteins made of many repetitions of conserved portions of ∼ 30 amino acids. While amino acid conservation at each position of the alignment explains most of the reduction of diversity relative to completely random sequences, we found that correlations between amino acid usage at different positions significantly impact that diversity. We quantified the impact of different types of correlations, functional and evolutionary, on sequence diversity. Analysis of the detailed structure of the coding space of the families revealed a rugged landscape, with many local energy minima of varying sizes with a hierarchical structure, reminiscent of fustrated energy landscapes of spin glass in physics. This clustered structure indicates a multiplicity of subtypes within each family, and suggests new strategies for protein design.

introduction

Natural proteins contain a record of their evolutionary history, as selective pressure constrains their amino-acid sequences to perform certain functions. However, if we take all proteins found in nature, their sequence appears to be random, without any apparent rules that distinguish their sequences from arbitrary polypeptides. Nonetheless, the volume of sequence space taken up by existing proteins is very small compared to all possible polypeptide strings of a given length [START_REF] David | How much of protein sequence space has been explored by life on Earth ?[END_REF], even more so when specializing to a given structure [START_REF] Shakhnovich | Protein design : a perspective from simple tractable models[END_REF]. Clearly, not all variants are equally likely to survive [START_REF] Nikolay V Dokholyan | Understanding conserved amino acids in proteins[END_REF][START_REF] Mandecki | The game of chess and searches in protein sequence space[END_REF][START_REF] Frank | Natural Selection and the Complexity of the Gene[END_REF]. To better understand the structure of the space of natural proteins, it is useful to group them into families of proteins with similar fold, function, and sequence, believed to be under a common selective pressure. Assuming that the ensemble of protein families is equilibrated, there should exist a relationship between the conserved features of their amino acid sequences and their function. This relation can be extracted by examining statistics of amino-acid composition, starting with single sites in multiple alignments (as provided by e.g. PFAM [START_REF] Bateman | The Pfam protein families database[END_REF][START_REF] Robert D Finn | Pfam: the protein families database[END_REF]). More interesting information can be extracted from covariation of amino acid usages at pairs of positions [START_REF] Morcos | Direct coupling analysis for protein contact prediction[END_REF][START_REF] Neher | How frequent are correlated changes in families of protein sequences?[END_REF][START_REF] Szurmant | Inter-residue, inter-protein and inter-family coevolution: bridging bridging the scales[END_REF] or using machine-learning techniques [START_REF] Tubiana | Learning protein constitutive motifs from sequence data[END_REF]. Models of protein 93 sequences based of pairwise covariations have been shown to successfully predict pair-wise amino-acid contacts in three dimensional structures [START_REF] Ekeberg | Improved contact prediction in proteins: using pseudolikelihoods to infer Potts models[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Espada | Capturing coevolutionary signals inrepeat proteins[END_REF][START_REF] Thomas | Three-dimensional structures of membrane proteins from genomic sequencing[END_REF][START_REF] Morcos | Direct-coupling analysis of residue coevolution captures native contacts across many protein families[END_REF][START_REF] Weigt | Identification of direct residue contacts in proteinprotein interaction by message passing[END_REF], aid protein folding algorithms [START_REF] Marks | Protein 3D structure computed from evolutionary sequence variation[END_REF][START_REF] Schug | High-resolution protein complexes from integrating genomic information with molecular simulation[END_REF], and predict the effect of point mutations [START_REF] Contini | A many-body term improves the accuracy of effective potentials based on protein coevolutionary data[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Figliuzzi | Coevolutionary landscape inference and the context-dependence of mutations in beta-lactamase TEM-1[END_REF][START_REF] Haldane | Structural propensities of kinase family proteins from a Potts model of residue co-variation[END_REF]. However, little is known on how these identified amino-acid constraints affect the global size, shape and structure of the sequence space. Accounting for these questions is a first step towards drawing out the possible and the realized evolutionary trajectories of protein sequences [START_REF] Maynard | Natural Selection and the Concept of a Protein Space[END_REF][START_REF] Daniel M Weinreich | Darwinian evolution can follow only very few mutational paths to fitter proteins[END_REF].

We use tools and concepts from the statistical mechanics of disordered systems to study collective, protein-wide effects and to understand how evolutionary constraints shape the landscape of protein families. We go beyond previous work which focused on local effects -pairwise contacts between residues, effect of single amino-acid mutations -to ask how amino-acid conservation and covariation restrict and shape the landscape of sequences in a family. Specifically, we characterize the size of the ensemble, defined as the effective number of sequences of a familiy, as well as its detailed structure: is it made of one block or divided into clusters of "basins"? These are intrinsically collective properties that can not be assessed locally.

Repeat proteins are excellent systems in which to quantify these collective effects, as they combine both local and global interactions. Repeat proteins are found as domains or subdomains in a very large number of functionally important proteins, in particular signaling proteins (e.g. NF-κB, p16, Notch [START_REF] Li | Ankyrin repeat: a unique motif mediating protein-protein interactions[END_REF]). Usually they are composed of tandem repetitions of ∼ 30 amino-acids that fold into elongated architectures. Repeat proteins have been divided into different families based on their structural similarity. Here we consider three abundant repeat protein families: ankyrin repeats (ANK), tetratricopeptide repeats (TPR), leucine-rich repeat (LRR) that fold into repetitive structures (see Fig. 27). In addition to interactions between residues within one repeat, repeat protein evolution is constrained by inter-repeat interactions, which lead to the characteristic accordeon-like folds. Through these separable types of constraints, as well as the possibility of intra-and inter-familly comparisons, repeat proteins are perfect candidates to ask questions about the origins and the effects of the constraints that globally shape the sequences.

A recent study [START_REF] Tian | How Many Protein Sequences Fold to a Given Structure ? A Coevolutionary Analysis[END_REF] addressed the question of the total number of sequences within a given protein family, focusing on ten single-domain families. They took a similar thermodynamic approach to the one followed here, but had to estimate experimentally the free energy threshold ∆G below which the sequences would fold properly. Here we overcome this limitation by forgoing this threshold entirely. Instead we determine the sequence entropy directly, which is argued to be equivalent to using a threshold free energy by virtue of the equivalence of ensembles. We precisely quantify the sequence entropy of three repeat-protein families for which detailed evolutionary energetic fields are known [START_REF] Barton | On the Entropy of Protein Families[END_REF]. We explore the properties of the evolutionary landscape shaped by the amino-acid frequency constraints and correlations. We ask whether the energy landscape, defined in sequence space of repeat proteins, is made of a single basin, or rather of a multitude of basins connected by ridges and passes, called "metastable states", as would be expected from spin-glass theory. Using the specific example of repeat proteins makes it possible to analyze the source of the potential landscape ruggedness, and use it to identify which repeat-protein families can be well separated into subfamilies. The rich metastable state structure that we find demonstrates the importance of interactions in shaping the protein family ensemble.

ANK TPR LRR

results

Statistical models of repeat-protein families

We start by building statistical models for the three repeat protein families presented in Fig. 27 (ANK, TPR, LRR). These models give the probability P(σ) to find in the family of interest a particular sequence σ = (σ 1 , . . . , σ 2L ) for two consecutive repeats of size L. The model is designed to be as random as possible, while agreeing with key statistics of variation and co-variation in a multiple sequence alignment of the protein family. Specifically, P(σ) is obtained as the distribution of maximum entropy [START_REF] Jaynes | Information Theory and Statistical Mechanics[END_REF] which has the same amino-acid frequencies at each position as in the alignment, as well as the same joint frequencies of amino acid usage in each pair of positions. Additionally, repeat proteins share many amino acids between consecutive repeats, both due to sharing a common ancestor and to evolutionary selection acting on the protein. To account for this special property of repeat proteins, we require that the model reproduces the distribution of overlaps ID(σ) = L i=1 δ σ i ,σ i+L between consecutive repeats. Using the technique of Lagrange multipliers, the distribution can be shown to take the form [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF]:

P(σ) = (1/Z)e -E(σ) , (105)
with

E(σ) = - 2L i=1 h i (σ i ) - 2L i,j=1 J ij (σ i , σ j ) + λ ID (σ) , (106)
where h i (σ), J ij (σ i , σ j ), and {λ ID }, ID = 0, 1, . . . , L, are adjustable Lagrange multipliers that are fit to the data to reproduce the experimentally observed site-dependent amino-acid frequencies f i (σ i ), joint probabilities between two positions, f ij (σ i , σ j ), and the distribution of Hamming distances between consecutive repeats P(ID(σ)), which is equivalent to maximize the likelihood of the data under the model. We fit these parameters using a gradient ascent algorithm: we start from an initial guess of the parameters, then generate sequences via Monte-Carlo simulations and update the parameters proportionally to the difference between the empirical and model generated observables

f i (σ i ) -f model i (σ i ), f ij (σ i , σ j ) -f model ij (σ i , σ j
) and P(ID(σ)) -P(ID(σ)) model . We repeat the previous steps until the model reproduces the empirical observables defined above, with a target precision motivated according to the finite size of our original dataset, as in Ref. [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF]. See Sec. B.1.2 for more details. We tested the convergence of the model learning by synthetically generating datasets and relearning the model (see Sec. B.1.5).

By analogy with Boltmzan's law, we call E(σ) a statistical energy, which is in general distinct from any physical energy. The particular form of the energy [START_REF] Lässig | Predicting evolution[END_REF] resembles that of a disordered Potts model. This mathematical equivalence allows for the possibility to study effects that are characteristic of disordered systems, such as frustration or the existence of an energy landscape with multiple valleys, as we will discuss in the next sections.

Eq. 106 is the most constrained form of the model, which we will denote by E full (σ). One can explore the impact of each constraint on the energy landscape by removing them from the model. For instance, to study the role of inter-repeat sequence similarity due to a common evolutionary origin, one can fit the model without the constraint on repeat overlap ID, i.e. without the λ ID term in Eq. 106. We call the corresponding energy function E 2 . One can further remove constraints on pairwise positions that are not part of the same repeat, making the two consecutive repeats statistically independent and imposing h i = h i+L (E ir ), or only linked through phylogenic conservation through λ ID (E ir,-). Finally one can remove all interaction constraints to make all positions independent of each other (E 1 ), or even remove all constraints (E rand ≡ 0).

Statistical energy vs unfolding energy

The evolutionary information contained in multiple sequence alignments of protein families is summarized in our model by the energy function E(σ). Since this information is often much easier to access than structural or functional information, there is great interest in extracting functional or structural properties from multiple sequence alignments, provided that there exists a clear quantitative relationship between statistical energy and physical energy.

Such a relationship was determined experimentally for repeat proteins by using E(σ) to predict the effect of point mutations on the folding stability measured by the free energy difference between the folded and unfolded states, ∆G, called the unfolding energy [START_REF] Contini | A many-body term improves the accuracy of effective potentials based on protein coevolutionary data[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF]. Synthetic sequences with low E(σ) have also been shown to reproduce the fold and function of natural sequences [START_REF] Tian | Co-Evolutionary Fitness Landscapes for Sequence Design[END_REF]. Here, extending an argument already developed in previous work [START_REF] Nikolay | Understanding Hierarchical Protein Evolution from First Principles[END_REF][START_REF] Morcos | Coevolutionary information , protein folding landscapes , and the thermodynamics of natural selection[END_REF][START_REF] Shakhnovich | Engineering of stable and fastfolding sequences of model proteins[END_REF][START_REF] Shakhnovich | A new approach to the design of stable proteins[END_REF], we show how this correspondance between statistical likelihood and folding stability arises in a simple model of evolution.

Evolutionary theory predicts that the prevalence of a particular genotype σ, i.e. the probability of finding it in a population, is related to its fitness F(σ). In the limit where mutations affecting the protein are rare compared to the time it takes for mutations to spread through the population, Kimura [START_REF] Kimura | On the Probability of Fixation of Mutant Genes in a Population[END_REF] showed that the probability of a mutation giving a fitness advantage (or disadvantage depending on the sign) ∆F over its ancestor will fix in the population with probability 2∆F/(1 -e -2N∆F ), where N is the effective population size. The dynamics of successful substitution satisfies detailed balance [START_REF] Berg | Adaptive evolution of transcription factor binding sites[END_REF], with the steady state probability

P(σ) = (1/Z)e 2NF(σ) . ( 107
)
Again, one may recognize a formal analogy with Boltzmann's distribution, where F plays the role of a negative energy, and N an inverse temperature. If we now assume that fitness is determined by the unfolding free energy ∆G, F(σ) = f(∆G(σ)), then the distribution of genotypes we expect to observe in a population is

P(σ) = (1/Z)e 2Nf(∆G(σ)) . ( 108
)
Note that a similar relation should hold even if we relax the hypotheses of the evolutionary model. While in more general contexts (e.g. high mutation rate, recombination), the relation between ln P(σ) and F(σ) may not be linear, such nonlinearities could be subsumed into the function f. Identifying terms in the two expressions ( 105) and ( 107), we obtain a relation between the statistical energy E, and the unfolding free energy ∆G:

E(σ) = -2Nf(∆G(σ)). ( 109
)
For instance, if we assume a linear relation between fitness and ∆G, f(∆G) = A + B∆G, then we get a linear relationship between the statistical energy and ∆G, as was found empirically for repeat proteins [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF]. Strikingly, the relationship f does not have to be linear or even smooth for this correspondance to work. Imagine a more stringent selection model, where f(∆G) is a threshold function, f(∆G) = 0 for ∆G > ∆G sel and -∞ otherwise (lethal). In that case the probability distribution is P(σ) = (1/Z)Θ(∆G -∆G sel ), where Θ(x) is Heaviside's function. Using a saddle-point approximation, one can show that in the thermodynamic limit (long proteins, or large L) the distribution concentrates at the border ∆G sel , and is equivalent to a "canonical" description [START_REF] Morcos | Coevolutionary information , protein folding landscapes , and the thermodynamics of natural selection[END_REF][START_REF] Shakhnovich | Engineering of stable and fastfolding sequences of model proteins[END_REF][START_REF] Shakhnovich | A new approach to the design of stable proteins[END_REF]: 2)) of sequences made of two consecutive repeats, for the three protein families shown in Fig. 27. Entropies are calculated for models of different complexity: model of random amino acids (S rand = 2L ln( 21), divided by ln(2) when expressed in bits); independentsite model (S 1 ), pairwise interaction model (S 2 ); pairwise interaction model with constraints due to repeat similarity λ ID (S full ); pairwise interaction model of two non-interacting repeats learned without (S ir ) and with (S ir,-) constraints on repeat similarity. Fig. 28 shows graphically some of the information contained in this table.

P sel (σ) = (1/Z)e ∆G(σ)/T sel , (110)
where the "temperature" T sel is set to match the mean ∆G between the two descriptions:

∆G T sel = ∆G sel . ( 111
)
This correspondance is mathematically similar to the equivalence between the micro-canonical and canonical ensembles in statistical mechanics. Statistical energy and unfolding free energy are linearly related by equating (Eq. 105) and (Eq. 110):

E(σ) = E 0 -∆G(σ)/T sel , (112)
despite f being nonlinear. Eq. 112 is in fact very general and should hold for any f in the thermodynamic limit in the vicinity of E .

Equivalence between two definitions of entropies

There are several ways to define the diversity of a protein family. The most intuitive one, followed by [START_REF] Tian | How Many Protein Sequences Fold to a Given Structure ? A Coevolutionary Analysis[END_REF], is to count the total number of amino acid sequences that have an unfolding free energy ∆G sel above a threshold ∆G sel [START_REF] Shakhnovich | Protein design : a perspective from simple tractable models[END_REF]. This number naturally defines a Boltzmann entropy,

S = ln N(σ : ∆G(σ) > ∆G sel ). ( 113
)
Alternatively, starting from a statistical model P(σ), one can calculate its Shannon entropy, defined as

S = - σ P(σ) ln P(σ), (114)
as was done in Ref. [START_REF] Barton | On the Entropy of Protein Families[END_REF]. What is the relation between these two definitions? By the same saddle-point approximation as in the previous section, the two are identical in the thermodyamic limit (large L), provided that the condition (Eq. 111) is satisfied. We can thus reconcile the two definitions of the entropy in that limit.

To calculate the Boltzmann entropy (Eq. 113), one needs to first evaluate the threshold E sel in terms of statistical energy. This threshold is given by E sel = E 0 -∆G sel /T sel , where E 0 and T sel can be obtained directly by fitting (Eq. 112) to single-mutant experiments. E sel can also be obtained as a discrimination threshold separating sequences that are known to fold properly versus sequences that do not [START_REF] Tian | How Many Protein Sequences Fold to a Given Structure ? A Coevolutionary Analysis[END_REF]. In that case, assuming that the linear relationship (Eq. 112) was evaluated empirically using single mutants, this relationship can be inverted to get ∆G sel in physical units.

Calculating the Shannon entropy Eq. ( 114), on the other hand, does not require to define any threshold. However, the threshold in the equivalent Boltzmann entropy can be obtained using Eqs. 111 and 112, i.e. E sel = E , where the average is performed using the distribution defined in Eqs. 105-106.

Entropy of repeat protein families

To compare how the different elements of the energy function affect diversity, we calculate the entropy of ensembles built of two consecutive repeats from a given protein family for the different kinds of models described earlier, from the least constrained to the most constrained: E rand , E 1 , E ir , E ir,-, E 2 , E full . In the case of models with interactions, calculating the entropy directly from the definition Eq. ( 114) is impossible due to the large sums. A previous study of entropies of protein families used an approximate mean-field algorithm, called the Adaptive Cluster Expansion [START_REF] Barton | On the Entropy of Protein Families[END_REF], for both parameter fitting and entropy estimation. Here we estimated the entropies using thermodynamic integration of Monte-Carlo simulations, as detailed in Sec. B.1.4. This method is expected to be asymptotically unbiased and accurate in the limit of large Monte-Carlo samples.

The resulting entropies and their differences are reported in Table 3 and Fig. 28. All three considered families (ankyrins (ANK), leucine-rich repeats (LRR), and tetratricopeptides (TPR)) show a large reduction in entropy (∼ 40 -50%) compared to random polypeptide string models of the same length 2L (of entropy S rand = 2L ln( 21)). Interactions and phylogenic similarity between repeats generally have a noticeable effect on family diversity, although the magnitude of this effect depends on the family: (S 1 -S full )/S full = 7% for ANK, versus, 13% for LRR, and 16% for TPR. Thus, although interactions are essential in correctly predicting the folding properties, they seem to only have a modest effect on constraining the space of accessible proteins compared to that of single amino-acid frequencies. However, when converted to numbers of sequences, this reduction is substantial, from e S 1 ∼ 3 • 10 54 to e S full ∼ 2 • 10 50 for ANK, from 10 39 to 10 34 for LRR, and from 7 • 10 50 to 4 • 10 42 for TPR.

By considering models with more and more constraints, and thus with lower and lower entropy, we can examine more finely the contribution of each type of correlation to the entropy reduction, going from E 1 to E ir to E ir,-to E full . This division allows us to quantify the relative importance of phylogenic similarity between consecutive repeats (λ ID ) relative to the impact of functional interactions (J ij ), as well as the relative weights of repeat-repeat versus within-repeat interactions (Fig. 28). We find that phylogenic similarity contributes substantially to the entropy reduction, as measured by S ir -S ir,-= 4.5 bits for ANK, 4.3 bits for LRR, and 10.7 bits for TPR. The contribution of repeat-repeat interactions (S ir,--S full ∼ 5 bits for all three families) is comparable or of the same order of magnitude as that of withinrepeat interactions (S 1 -S ir = 4.3 bits for ANK, 6.9 bits for LRR, and 11.4 bits for TPR). This result emphasizes the importance of physical interactions between neighboring repeats in the whole protein.

On a technical note, we also find that pairwise interactions encode constraints that are largely redundant with the constraint of phylogenic similarity between consecutive repeats, as can be measured by the double difference S ir -S ir,--S 2 + S full > 0 (Fig. 28, orange bars). This redundancy comes from the fact that, in absence of an explicit constaint on P(ID) in E 2 , the interaction couplings J i,i+L (σ, σ) between homologous positions in the two repeats is expected to favor pairs of identical residues to mimic the effect of λ ID . This redundancy motivates the need to correct for this phylogenic bias before estimating repeat-repeat interactions.

Comparing the three families, ANK has little phylogenic bias between consecutive repeats, and relatively weak interactions. By contrast, TPR has a strong phylogenic bias and strong within-repeat interactions.

Effect of interaction range

We wondered whether interactions constraining the space of accessible proteins had a characteristic lengthscale. To answer this question, for each protein family in Fig. 27, we learn a sequence of models of the form Eq. 106, in which J ij was allowed to be non-zero only within a certain interaction range d(i, j) W, where the distance d(i, j) between sites i and j can be defined in two different ways: either the linear distance |i -j| expressed in number of amino-acid sites, or the three-dimensional distance between the closest heavy atoms in the reference structure of the residues. Details about the learning procedure and error estimation are given in the Methods; see also Fig. S5 for an alternative error estimate.

The entropy of all families decreases with interaction range W, both in linear and three-dimensional distance, as more constraints are added to reduce diversity (Fig. 29 for ANK, and Fig. S6 for LRR and TPR). The initial drop as a function of linear distance (Fig. 29A) is explained by the many local interactions between nearby residues in the sequence. The entropy then plateaus until interactions between same-position residues in consecutive repeats are included in the W range, which leads to a sharp entropy drop at W = L. This suggests that long range interactions along the sequence generally do not constrain the protein ensemble diversity, except for interactions at exactly the scale of the repeat. This result suggests that the repeat structure is an important constraint limiting protein sequence exploration. These observations hold for all three repeat protein families. The importance of 3D structure in reducing the entropy can also be appreciated in the entropy decay as a function of physical distance (Fig. 29B repeat interactions (S ir,--S full , purple), and phylogenic bias between consecutive repeats (S ir -S ir,-, blue), to the entropy reduction from an independent-site model. All three contributions are comparable, but with a larger effect of within-repeat interactions and phylogenic bias in TPR. The fourth bar (orange) quantifies the redundancy between two constraints with overlapping scopes: the constraint on consecutiverepeat similary, and the constraint on repeat-repeat correlations. This redundancy is naturally measured within information theory by the difference of impact (i.e. entropy reduction) of a constraint depending on whether or not the other constraint is already enforced.

this characteristic distance interactions are not crucial in constraining the space of accessible sequences.

Multi-basin structure of the energy landscape

The energy function of Eq. ( 106) takes the same mathematical form as a disordered Potts model. These models, in particular in cases where σ i can only take two values, have been extensively studied in the context of spin glasses [START_REF] Mezard | Spin Glass Theory and Beyond[END_REF]. In these systems, the interaction terms -J ij (σ i , σ j ) imply contradictory energy requirements, meaning that not all of these terms can be minimized at the same time -a phenomenon called frustration. Because of frustration, natural dynamics aimed at minimizing the energy are expected to get stuck into local, non-global energy minima (Fig. 30), significantly slowing down thermalization. This phenomenon is similar to what happens in structural glasses in physics, where the energy landscape is "rugged" with many local minima that hinder the dynamics. Incidentally, concepts from glasses and spin glasses have been very important for understanding protein folding dynamics [START_REF] Bryngelson | Spin glasses and the statistical mechanics of protein folding[END_REF]. We asked whether the energy landscape of Eq. ( 106) was rugged with multiple minima, and investigated its structure. To find local minima, we performed a local energy minimization of E full (learned with all constraints including on P(ID), but taken with λ ID = 0 to focus on functional energy terms). By analogy with glasses, such a minimization is sometimes called a zero-temperature Monte-Carlo simulation or a "quench". The minimization procedure was started from many initial conditions corresponding to naturally occuring sequences of consecutive repeat pairs. At each step of the minimization, a random beneficial (energy decreasing) single mutation is picked; double mutations are allowed if they correspond to twice the same single mutation on each of the two repeats. Minimization stops when there are no more beneficial mutations. This stopping condition defines a local energy minimum, for which any mutation increases the energy. The set of sequences which, when chosen as initial conditions, lead to a given local minimum defines the basin of attraction of that energy mimimum (Fig. 30). The size of a basin corresponds to the number of natural proteins belonging to that basin. Performing this procedure on natural sequences of consecutive repeat pairs from all three families yielded a large number of local minima (Fig. 31).

local minima global minimum basins

To control for the phylogenetic bias that links natural sequences, we repeated this analysis on sequences synthetically generated from the model (E full ), and obtained very similar results (see Fig. S10 for ANK). When ranked from largest to smallest, the distribution of basin sizes follows a power law (Fig. 31A for ANK and Fig. S7A and Fig. S8A for LRR and TPR). The energy of the minimum of each basin generally increases with the rank, meaning that largest basins are also often the lowest. Despite this multiplicity of local minima, the Monte-Carlo dynamics that we used in previous sections for learning the model parameters and for estimating the entropy did not get stuck in these minima, suggesting relatively low energy barriers between them.

The partition of sequences into basins allows for the definition of a new kind of entropy S conf =b P(b) ln P(b) called configurational entropy, based on the distribution of basin sizes, P(b) = σ∈b P(σ), where σ ∈ b means that energy minimization starting with sequence σ leads to basin b. This configurational entropy measures the effective diversity of basins, and is thus much lower than the sequence entropy S full , while the difference S full -S conf measures the average diversity of sequences within each basin. We find S conf =5.1 bits for ANK, 6.0 bits for LRR, and 10.4 bits for TPR. As each basin corresponds to a distinct sub-family within each family [START_REF] Nikolay | Understanding Hierarchical Protein Evolution from First Principles[END_REF], this entropy quantifies the effective number of these subgroups.

While basins are very numerous, they are also not independent of each other. An analysis of pairwise distances (measured as the Hamming distance between the local minima) between the largest basins reveals that they can be organised into clusters (panels B of Figs. 31, S7, and S8), suggesting a hierarchical structure of basins, as is common in spin glasses [START_REF] Mezard | Spin Glass Theory and Beyond[END_REF].

The impact of repeat-repeat interactions on the multi-basin structure can be assessed by repeating the analysis on the model of non-interacting repeats, E ir . In that model the two repeats are independent, so it suffices to study local energy minima of single repeats -local minima of pairs of repeats follow simply from the combinatorial pairing of local minima in each repeat. The analyses of basin size distributions, energy minima, and pairwise distances in single repeats are shown in panels C and D of Figs. 31, S7, and S8. We still find a substantial number of unrelated energy minima, suggesting again several distinct subfamilies even at the single-repeat level. For comparison, the configurational entropy of pairs of independent repeats is 6.9 bits for ANK, 6.7 for LRR, and 7.6 for TPR. While for ANK and LRR repeat-repeat interactions decrease the configurational entropy, as they do for the conventional entropy, they in fact increase entropy for TPR, making the energy landscape even more frustrated and rugged.

Note that the independent sites model E 1 defines a convex energy landscape with a single local minimum -the consensus sequence -as all constraints h i can be optimized independently. To address how the interactions contribute in shaping the sequence space, going from a convex to a rugged landscape, we repeated the analysis with a limited linear interaction range W of 3 and 10 (models of Fig. 29 A). We find that the more interactions we add, the more local minima we find (Fig. S9A andB for ANK with W = 3, and C and D for W = 10). The minima cluster into clearer sub-blocks structure as the interaction range is increased, consistent with the entropy reduction observed in 29 A.

In summary, the analysis of the energy landscape reveals a rich structure, with many local minima ranging many different scales, and with a hierarchical structure between them.

Distance between repeat families

Lastly, we compared the statistical energy landscapes of different repeat families. Specifically, we calculated the Kullback-Leibler divergence between the probability distributions P(σ) (given by Eqs. 105-106) of two different families, after aligning them together in a single multiple sequence alignment (see Sec. B.1.7).

We find essentially no similarity between ANK and TPR, despite them having similar lengths: D KL (ANK||TPR) = 227.6 bits, and D KL (TPR||ANK) = 214.1 bits. These values are larger than the Kullback-Leibler divergence between the full models for these families and a random polypetide, D KL (ANK||rand) = 122.8 bits, and D KL (TPR||rand) = 157.6 bits. LRR is not comparable to ANK or TPR as it is much shorter, and a common alignment is impractical. These large divergences between families of repeat proteins show that different families impose quantifiably different constraints, which have forced them to diverge into different troughs of non-overlapping energy landscapes. This lack of overlap makes it impossible to find intermediates between the two families that could evolve into proteins belonging to both families.

discussion

Our analysis of repeat protein families shows that the constraints between amino acids in the sequences allows for an estimation of the size of the accessible sequence space. The obtained numbers (ranging from 141 bits to 167 bits, corresponding to 10 36 to 10 50 sequences) are of course huge compared to the number of sequences in our initial samples (∼ 20, 500 for ANK, ∼ 18, 800 for LRR, and ∼ 10, 000 for TPR), but comparable to the total number of proteins having been explored over the whole span of evolution, estimated to be 10 43 in Ref. [START_REF] David | How much of protein sequence space has been explored by life on Earth ?[END_REF].

In particular, we have quantified the reduction of the accessible sequence space with respect to random polypeptides. While most of this reduction is attributable to conservation of residues at each site, interactions between amino acids, both within and between consecutive repeats, significantly constrain the diversity of all repeat families. The break-up of entropy reduction between the three different sources of constraints -within-repeat interactions, between-repeat interactions, and evolutionary conservation between consecutive repeats -is fairly balanced, although TPR stands out as having more within-repeat interactions and more conservation between neighbours, suggesting that it may have had less time to equilibrate.

All studied repeat families have rugged energy landscapes with multiple local energy minima. Note that the emergence of this multi-valley landscape is a consequence of the interactions between amino acids: models of independent positions (E 1 ) only admit a single energy minimum corresponding to the consensus sequence. This multiplicity of minima allow us to collapse multiple sequences to a small number of coarse-grained attractor basins. These basins suggest that mutations between sequences within one coarse-grained basin are much more likely than mutating into sequences in other basins. In general, our results paint a picture of further subdivisions within a family, and define sub-families due to the fine grained interaction structure. Going beyond single families, this analysis suggest a view in which natural proteins all live in a global evolutionary landscape, of which families would be basins, or clusters of basins, with a hierarchical structure [START_REF] Nikolay | Understanding Hierarchical Protein Evolution from First Principles[END_REF].

This overall picture of the sequence energy landscape is reminiscent of the hierarchical picture of the structural energy landscape of globular proteins, an overall funneled shape with tiers within tiers [START_REF] Frauenfelder | Proteins[END_REF]. The form of the energy landscape forcibly shapes the accessible evolutionary paths be-tween sequences. The rugged and further subdivided structure shows that the uncovered constraints are global, and not just pairwise between specific residues. Therefore even changing two residues together, as is often done in laboratory experiments, is not enough to recover the evolutionary trajectories. While other approaches have explored local accessible directions of evolution [START_REF] Facco | The intrinsic dimension of protein sequence evolution[END_REF], our results suggest more global, non local modes of evolution between clusters.

Interestingly, the sequences that correspond to the energy minima of the landscapes are not found in the natural dataset. This observation can be either due to sampling bias (we have not yet observed the sequence with the minimal energy, although it exists), or this sequence may not have been sampled by nature. Alternatively, there may be additional functional constraint that are not included in our model to avoid these low energy sequences (e.g. a too stable protein may be difficult to degrade).

Even more intriguingly, sequences with minimal energy do not correspond to the consensus sequence of the alignment (whose energy is marked by a gray line in panel A of Figs. 31, S7, and S8), suggesting that the consensus sequence can be improved upon. All three repeat protein families studied here have been shown to be amenable to simple consensus-guided design of synthetic proteins. Synthetic proteins based on the consensus sequences of multiple alignments [START_REF] Ykelien | DARPins and other repeat protein scaffolds : advances in engineering and applications[END_REF] were found to be foldable and very stable against chemical and thermal denaturation. Mutations towards consensus amino acids in the ANK family members have been experimentally shown to both stabilize the whole repeat-array and they may tune the folding paths towards nucleating folding in the consensus sites [START_REF] Barrick | Folding landscapes of ankyrin repeat proteins : experiments meet theory[END_REF][START_REF] Tripp | Rerouting the Folding Pathway of the Notch Ankyrin Domain by Reshaping the Energy Landscape[END_REF] . Our results suggest that interactions may play an additional role in stabilizing the sequences, and propose alternative solutions to the consensus sequences in the design of synthetic proteins.

E V O L U T I O N A R Y M O D E L F O R R E P E AT A R R AY S

introduction

In the previous chapter we adopted a MaxEnt (maximum entropy) formulation to model pairs of consecutive repeats, adding a global term λ(ID) to the Potts energy (90) to take into account the inter-repeat similarity coming from phylogenetic effects. Here we want to take a more direct approach and combine the usual inverse Potts model scheme to infer an evolutionary energy of the form [START_REF] Pack | Reinforcement learning: A survey[END_REF], encoding the functional constraints acting on repeat arrays, with an explicit model for the evolution of repeats in an array that could capture the propagation of phylogenetic effects. This Chapter presents work that is still in progress.

A recent work [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF] studied tandem arrays detected in natural proteins belonging to the Ankyrin family (ANK). They reported some interesting empirical observations characterizing the inter-repeat similarity. Figure 32 recapitulates some of these observations, which we are going to focus on, measured on our dataset (more details in section C.1), which is the same studied in [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF]. First of all our model must be able to reproduce the length distribution, in number of repeats N r , of the arrays in the dataset (fig. 32A). Then we focus on the inter-repeat similarity. We quantify this similarity, or identity, by the number of matches between two different repeats ID 1,2 = l r i=1 δ(σ 1 i , σ 2 i ), disregarding alignment gaps. Fig. 32B,C,D show some empirical identity patterns. Panel B plots the probability distribution of repeat similarity between consecutive repeats in an array. Panel C plots the average similarity between 1st neighbor repeats conditioning on the number of repeats in an array, as a function of the number of repeats. Longer arrays have more similar first neighbors repeats. Panel D plots the average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The resulting similarity shows a saw-like trend with second neighbors that are on average more similar than first neighbors.

As we introduced in 5.5.3, apart from point mutations repeats in an array can also be duplicated and deleted all together [START_REF] Andrade | Protein Repeats: Structures, Functions, and Evolution[END_REF][START_REF] Schüler | Evolution of protein domain repeats in Metazoa[END_REF]. The molecular mechanism underlying these duplications and deletions, that we will call dupdel, is unknown, and it is not even clear that such mechanism would be unique to all organisms [START_REF] Åsa K Björklund | Expansion of protein domain repeats[END_REF]. However, a possible mechanism is that of "unequal crossing over" of genetic material. This is a mechanism that deletes a sequence of genetic material (in our case encoding some repeat) from a DNA strand placing it in the corresponding position in the sister chromatid during mitosis (or homologous chromosome in meiosis) effectively duplicating that sequence (as sketched in 33). This is caused by a misalignment during DNA replication and requires some degree of similarity between the sequences around the crossover point: the more similar the more likely is unequal crossover [START_REF] Graur | Fundamentals of Molecular Evolution[END_REF]. This mechanism has received experimental support for genes [START_REF] Stankiewicz | Genome architecture, rearrangements and genomic disorders[END_REF], and it has been investigated theoretically with a population genetics approach [START_REF] Ohta | On the evolution of multigene families[END_REF].

Here we study a simple effective toy model for repeat array evolution inspired by some mechanism of this sort, where mutations occur on top of repeat duplications and deletions, generalizing the framework of the previous Chapter to allow for arrays with an arbitrary number of repeats. We aim at quantitatively addressing the effects of inter-repeat phylogenetic relationship and their interplay with functional constraints encoded in an evolutionary energy of the form [START_REF] Pack | Reinforcement learning: A survey[END_REF]. Exploiting the same framework we investigate what key ingredients repeat arrays evolutionary models need to reproduce qualitatively the empirical patterns in figure 32.

We could extract information on the qualitative processes underlying repeat array evolution. We could infer quantitatively some features of this evolutionary process such as the functional constraints and the ratio between mutation and dupdel rates. Functional constraints and dupdels, exploiting the discrete translational invariance of repeat proteins, can account for the whole universe of array lengths while keeping the number of parameters limited to the h, J in (90) necessary to model single repeats and coupling between consecutive repeats. Moreover we can reproduce the similarity distribution of first neighbors repeats without the need of the term λ(ID) in ( 106), just fitting the scalar timescale parameter, the rates ratio, to the average similarity. This parameters compression is achieved by replacing the MaxEnt scheme for λ(ID) with a mechanistic model from basic principlesremember the analogy of modeling desk dispositions in 5.2.3?

model

In our evolutionary model for repeat-proteins, we consider an array of N r repeats in tandem, each consisting of an amino-acid sequence of fixed length l r . Repeats are duplicated and deleted with deletion and duplication rates that we assume to be equal µ dup = µ del , so that these events will be captured by a unique parameter µ d . Note that, since these are two independent Poisson processes, the overall size-change process is still Poisson with rate µ cs = µ del + µ dup = 2µ d . The rate at which these event happen at the whole array level depends on the array length through an arbitrary function ,so that the overall array dupdel rate is µ d F(N r ). Unless otherwise noted, in the following we will consider a linear dupdel rate µ d N r , therefore µ d stands for the dupdel rate per repeat. Here duplications always place repeats one next to each other conserving the repeat locality on the array. An underlying assumption in thinking of arrays as composed by a certain number of repeats with fixed length l r is that the dupdel process naturally defines the sites where repeats start and end, which we call the "phase" of repeats in the array. Therefore there is an intrinsic notion of where a repeat starts and ends along the protein.

These size changes undergo selection S(N r ), defined as the probability that a size change leading to an array of length N r is accepted. We assume that S depends only on the number of repeats in the array and not on the amino-acid sequence. The master equation for the probability of N r is

dP(N r ) dt =(P(N r -1)F(N r -1) + P(N r + 1)F(N r + 1))S(N r )µ dup - P(N r )F(N r )(S(N r -1) + S(N r + 1))µ del (115)
where we set S(N r ) so that the equilibrium distribution matches the empirical length distribution P(N r ) in fig. 32A (implementation details in C.3).

Point mutations can occur with rate µ p per amino-acid site, which with dupdels constitute the key events underlying this simple model (fig. 34). After mutations, sequences undergo selection according to some evolutionary energy of the form [START_REF] Pack | Reinforcement learning: A survey[END_REF]. This Hamiltonian is defined by an internal repeat energy E 1 (σ) of the same form acting on single repeats separately, plus an interaction term I i,i+1 between consecutive repeats i, i + 1, consisting of the coupling Js between repeats. For example for a 2 repeats array we have:

E 2 (σ) = - l r i=1 h i (a i ) - i<j<l r J ij (a i , a j ) E 1 (σ 1 )=E 1 1 - l r i=1 h i (a i+l r ) - i<j<l r J ij (a i+l r , a j+l r ) E 2 1 - i<l r <j J ij (a i , a j ) I 1,2 (116)
With these objects we can generalize a discrete translational invariant energy for arrays of arbitrary length N r :

E N r (σ) = N r i=1 E i 1 + N r -1 i=1 I i,i+1 . (117)
This minimal model assumes independent selection on protein lengths and sequences -modulo boundary effects due to the fact that the impact of I 1,2 is lower on terminals. We study it with respect to the ratio of the two rates parameters, µ r = µ d µ p , or equivalently the ratio between the two timescales t r = 1 µ r = t d t p . This scalar parameter sets the relative timescale of the system.

As a side note, we mention that this model is out of equilibrium because microscopically detailed balance is broken by duplications and deletions. Repeat arrays are characterized by joint probability P(σ, N r ) for the sequence σ with N r repeats. As described more in detail in the appendix C.2, if

t d t p
1 we have a separation of timescales between the two processes, so that the mutation process can thermalize between typical dupdel times and multi-repeat amino-acid sequences are almost always at equilibrium with P(σ|N r ) → (1/Z N r )e -E Nr (σ) .

Parameters inference

The dataset we study consists of ∼ 150000 effective (in the sense of phylogenetically independent) arrays of repeat tandems that were found as parts of natural proteins belonging to the Ankyrin family. Each of these arrays contains a variable number N r of repeats, which are amino-acid sequences of given length l r , with the peculiarity of being very similar between them both in sequence and structure, and correspond to the building blocks of tandem arrays. More details on the dataset can be found in C.1.

We apply this basic model combined with the inverse Potts model inference scheme to learn from empirical observables the energy parameters h, J and the ratio between the mutation and dupdel timescales t r = 1 µ r = t d t p . The evolutionary energy parameters h, J are inferred with a gradient ascent algorithm to maximize the likelihood of the empirical frequencies under the model, as described in 5.2.3, to which we add a momentum term introduced in 5.3.1 and detailed in C.4. More precisely we fit h, J in E 1 in [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF] in order to reproduce the one and two sites amino-acid frequencies f i (σ i ) and f ij (σ i , σ j ) computed on all the repeats in the dataset. Analogously we fit J ij in I i,i+1 according to the two sites amino-acid frequencies f ij (σ i , σ j ) between consecutive repeats, therefore where j is on the repeat following the repeat of i.

Finally we fit µ r in order to reproduce the empirical ID emp 1st , that is the average of 32 B. This extra optimization step leaves the learning problem convexity unaffected, because the model ID 1st depends monotonously on the scalar parameter µ r : the higher µ r the higher ID 1st . For example for µ r 1 all repeats on the same array have nearly 100% identity (modulo the gaps) since almost no mutations can occur on the repeats phylogeny between the common ancestor and the current repeats in the array. On the other hand µ r 1 the identity will always have time to thermalize exactly to the minimum baseline dictated by the equilibrium distribution P(σ|N r = 2) → (1/Z 2 )e -E 2 (σ) . This monotonic trend implies that the proper update direction for µ r is proportional to ID 2 site joint amino-acid frequencies within the same repeat, 2 site joint amino-acid frequencies between consecutive repeats, respectively. The color map represents points density (yellow higher density).

results

Once we have inferred the model parameters, we can analyze its prediction by running a Monte-Carlo simulation and comparing the output with data. The following results refer to simulations yielding 150000 sequences independently drawn from the model evolutionary process, unless otherwise stated.

As a first consistency check we show in fig. 35 that the inferred model reproduces both the empirical array length distribution (panel A) and the three amino-acid frequencies sets (panels B,C,D respectively) we used to fit the parameters. The fact that also inter-repeat two site amino-acid frequencies are reproduced proves a posteriori that, in the biologically relevant range of µ r , the multi-repeat sequences are at quasi-equilibrium and the equilibrium inference scheme works all the same. amino-acid frequencies, the color map represents points density (yellow higher density). The model reproduces well higher order statistics that were not used for fitting.

Fig. 36 shows that also 3 point amino-acid frequencies f i,j,k (σ i , σ j , σ k ), including inter-repeat sites, are well reproduced by the model, even though we did not use them to infer the model. This means that the model generalizes well with respect to some higher order statistics that were not used for fitting. In this specific case it suggests that 3-point correlations are well approximated by triplets of pairwise interactions involving the same states.

Figure 37 displays, as a function of the arrays length N r , the rescaled energy defined as

ẼN r (σ) = 1 N r N r i=1 E i 1 + 1 N r -1 N r -1 i=1 I i,i+1 . (118)
It shows how the model reproduces the energies of short arrays, and also the global descending trend despite that no information on the dependence on N r is used to infer the model. On the other hand our statistical model fails to reproduce the fact that there seems to be a transition above which arrays systematically have lower energies, suggesting they are evolutionarily more stable (less diverse). Those large arrays represent just a tiny fraction of the dataset (fig. 32A), so it is not surprising that our model cannot reproduce this change of trend. But this transition is definitely an interesting feature that some future work should investigate.

Figure 38 shows how the model reproduces the whole empirical distribution of ID emp 1st even though we are only fitting its average value with a The model (blue), inferred constraining its average, reproduces the whole empirical distribution (green). single parameter, and we do not have any term in the evolutionary energy explicitly enforcing the whole distribution to be reproduced.

To address the interplay between dupdels and evolutionary constraints we learn sequentially a class of models where couplings J ij are non-zero only if they are closer than a certain interaction range |i -j| < W, relearning the energy parameters together with the times ratio t r for each of them as explained in C.4. Fig. 39 shows the difference between empirical and model generated similarity distributions as the reduced chi-squared score,

χ2 = 1 ν {ID}∈[0,l r ] (P(ID emp )-P(ID)) 2 P(ID)
where ν = l r -2 is the number of degrees of freedom. We see that already turning on J ij within a short interaction range W ∼ 10 is enough to reproduce the whole similarity distribution (note that the mean is reproduced in all of these models since we reinfer t r every time). On the other hand learning a full field for pairs of consecutive repeats without the dynamic ingredient of dupdels cannot reproduce this distribution or its average (not shown) as was already found in [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF] for a different dataset. This result indicates that the observed identity distribution is a result of the combined effects from short-range functional constraints and the self-renewing local dynamics of duplications and deletions. This dynamics determines the phylogenetic relationship between repeats and map it to their relative position in the array, alongside mutations which spark mismatches along this repeat phylogeny.

Thanks to our inference scheme we also learn quantitatively the timescales ratio between dupdels and mutations: t d t p = 1 µ r = 27.28. Therefore on average duplications (the average time for deletions is the same) per repeat happen 27.28 times slower than mutations per site. Putting times in the same relative scale, per repeat, replacing tp = t p l r = t p 33 we have t d tp ∼ 900, therefore duplications are about 3 orders of magnitude rarer than mutations, which also implies that the system is almost at equilibrium. These are the Poisson rates at which the moves are proposed in our Monte-Carlo simulation, therefore "pre-selection". Fig. S11 shows the ratio between average duplication time per repeat and average mutation time per site (always equal to 1 as it defines the model time unit), as a function of W. The more constraints we encode into the evolutionary energy [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF], the slower the inferred dupdel process, since these constraints also impact ID emp 1st typically making repeats more similar.

For this inference to be meaningful to compare with biological data it is better to refer to the post-selection substitution rates. These would be the rates at which some modification in the repeat array would take place and survive natural selection for many generations, enough to be sampled. In our computational scheme these would correspond to the rates at which a modification is accepted (in relative terms since in our model timescales are measured relative to t p ).

When looking at post-selection rates the per-repeat duplication rate is not the same as the deletion rate anymore, their relationship depends on the average number of repeats in an array and can be calculated from the steady state condition. If we compare the post-selection per-repeat duplication rate with the corresponding mutation rate, we have At last we check if our inferred evolutionary energy is related to functional constraints by comparing the contact map of a reference ANK pair of repeats of the protein 1N0R with the strongest couplings J i,j . To do that we apply to the J i,j s an adaptation of the zero-sum gauge to sequences of multiple lengths that maintains the discrete translational invariance of the evolutionary energy, as explained in C.5 , and then we rank the couplings by the Frobenius norm of the submatrices J(•, •). We find that contacts within and between repeats are well represented by couplings, as previously shown in [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF] (fig. 40).

This simple model allows us to infer precisely the evolutionary constraints acting within and between different repeats, and the relative timescale between mutations and dupdels. It reproduces strikingly well the distribution of similarity between consecutive repeats even though only its average is used to infer the model, and it captures some patterns that are not directly used to inform the model, like the decrease of evolutionary energy with array length. Despite the simplicity of its few ingredients it offers a rich variety of insights on the processes underlying repeat tandems evolution and on the interplay between functional constraints and phylogenetic effects. For example it suggests the afore mentioned similarity distribution is a product of the non trivial combination between constraints within the same repeats and the dupdel mechanism, whereas constraints between consecutive repeats counter-intuitively don't play an important role in this aspect. On the other hand fig. 41 shows that this basic model cannot reproduce, even qualitatively, some empirical trends. First, the similarity between consecutive repeats depends more weakly on the array length than in data (panel A). Then the saw-like trend of similarity as a function of neighborhood is totally absent in the model (panel B). When looking at farther repeats in the same array the similarity decays to a value much lower than the data do (panel B). In the following we refer to the asymptotic value of similarity for very far repeats as "baseline". In the following we will investigate what minimal ingredients we need to include in our evolutionary model to reproduce these trends at least qualitatively.

exploring mechanisms behind duplications and deletions

To understand what key ingredients produce different trends, we start by employing the same evolutionary energy learned with the basic model, and study the new models behavior as a function of their parameters. A more rigorous approach would be to learn a new set of energy parameters for every model, while inferring their free dupdels parameters from some empirical statistics at the same time. But this carries a high computational cost and we need to know at least the sign of the likelihood gradient with respect to these parameters. In other words we need to know in which direction to update the parameters, given the outcome of the current model compared to the empirical observables. Therefore we start with the old energy parameters h, J as an approximation to acquire the necessary information to learn the full model.

Multi-repeat duplications and deletions

First we focus on the saw-like trend in fig. 32D. The fact that repeats have systematically higher similarity odd repeats away suggests that the underlying mechanism can duplicate and delete more than one repeat at a time.

Here we study the model behavior when allowing for dupdels of two consecutive repeats with probability p 2 , as well as the duplications of single repeats like before with probability p 1 = 1 -p 2 . Fig. 42 shows that this new ingredient can indeed qualitatively produce a saw trend resembling the empirical one, but the similarity globally decays faster with respect to the neighborhood and to a much lower baseline.

We search systematically the model parameters, i. e. the times ratio t r and p 1 , over a broad range of values. We quantify the trend of consecutive repeat similarity as a function of length as

ID 1 |N r = 11 -ID 1 |N r = 2 ,
that is the difference between the 11th and the 2nd point in fig. 32C. We also quantify the similarity decrease as a function of neighborhood by the difference between the second and fourth point in fig. 32D: ID 2 |N r > 10 -ID 4 |N r > 10 . Fig. 43 shows that that no parameter set can ever reproduce, even qualitatively, the increasing trend of similarity with respect to the array length (panel A) or the fact that the saw-like trend of repeat similarity is almost constant as a function of neighborhood (panel B).

In order to have a unique scalar measure as a quantitative score of how well a given parameters set reproduces all of the relevant empirical observations, we introduce the score

χ = i |x i -y i | e i , (119)
where the index i runs over all the points in fig. 32 C and D, x i is the corresponding empirical value and y i is the measurement on the model generated sequences, while e i is the data standard error. Figure 44 shows the result of this global score for the parameters scan of this model. Each of the p 1 cross sections yields comparable minima, at progressively higher t r increasing p 1 . The overall minimum is about 1200. The value of this score on the basic model where only one repeat at a time can be duplicated gives about 1300, so this new model seems to perform just slightly better. But in the previous case we had actually learnt the evolutionary energy alongside the . The rates depend on the similarity with neighbors on the left and on the right as explicit in [START_REF] Mayer | How a well-adapted immune system is organized[END_REF]. Here we sketch only that on the left for simplicity but in the single repeat case the first neighbor on the right carries an equal contribution. For the same reason in the pair duplication example we sketch only the left-contribution from the second repeat in the duplicated pair (note that in our modeling choice the symmetric rightcontribution of this repeat does not affect the rate), but the first one carries an equivalent contribution to the rate according to the similarity with the second neighbor on the right. Just as a pictorial example on the right we show a cartoon (extracted from [START_REF] Stankiewicz | Genome architecture, rearrangements and genomic disorders[END_REF]) for a basic genetic unequal crossing-over event.

dupdel parameter, whereas here we only scanned the parameters without performing any optimization nor relearning the energy parameters.

Similarity dependent duplications and deletions

The next scenario we consider is the case of dupdel rates that explicitly depend on inter-repeat similarity, as it was proposed to be a plausible trigger for genetic unequal crossing-over [START_REF] Graur | Fundamentals of Molecular Evolution[END_REF]. In this model, the k repeats from r to r + k -1 duplicate or delete with probability p k . The dupdel rate is

µ d p k G [r,r+k) (ID [r,r+k) k
), where ID [r,r+k) k denotes the similarity w.r.t. the kth neighbor repeat either on the left or on the right (if exist) of all the repeats in the set [r, r + k) that are to be duplicated/deleted. The master equation of this process and the implementation details are in C. [START_REF] Altan-Bonnet | Quantitative immunology for physicists[END_REF].

There are infinite possible choices on the functional dependence of these rates on the ID, here we present the results for a linear dependence, but an exponential dependence gave qualitatively similar results (not shown). Therefore the dupdel rates read: where χ(r; 1, N r -k + 1) denotes the characteristic function accounting for the finite number of repeats in an array, and is

G [r,r+k) (ID [r,r+k) k ) = g 0 +χ(r; 1, N r -k + 1) γID r-1,r+k-1 2l r +χ(r; 0, N r -k) γID r,r+k 2l r (120)
1 if r ∈ [1, N r -k + 1
] and 0 otherwise. Here ID r-1,r+k-1 denotes the similarity between the repeat holding position r -1 in the array (not to be duplicated) and the one k neighbors on its right at r + k -1, that is the last duplicated repeat on the right. Note that this modeling choice implies that in single repeat dupdels both right and left IDs contribute to the rate. When duplicating pairs the only contributions come from similarity between the first duplicated repeat and its second neighbor on the right plus similarity between the second duplicated repeat and its second neighbor on the left. Such modeling details depend on the exact underlying molecular mechanism, which is unknown to the best of our knowledge, and will not affect anyways the qualitative results presented here. These rates depend on two meta-parameters, γ and g 0 that set the strength of the dependence on the ID and modulate the overall dupdel rate respectively. Here we study the case k = 2, therefore the units undergoing dupdels are either single or pairs of consecutive repeats, like in the previous section. Fig. 45 sketches a visualization of duplications of 1 and 2 repeats that depend on the ID of the duplicated units with their neighbors, alongside an example of unequal genetic crossing-over that may produce similarity triggered duplication and deletions [START_REF] Graur | Fundamentals of Molecular Evolution[END_REF].

We explore again the outcome of the model varying the time ratio t r and p 1 , while fixing γ = 3, and g 0 = 0.1 so that G( ID emp 1st ) ∼ 1 and the time ratio scale is comparable with the ones in the models explored so far. Fig. 46A shows that now in some parameters range we can qualitatively reproduce the similarity increase with array length. Of course we still manage to reproduce the saw-like trend since we allow for repeat pairs dupdels (not shown). We can never reproduce the slow similarity decay with distance on the array (fig. 46B). These qualitative features do not change when increasing γ.

An effect of these similarity dependent rates is that they introduce an effective superlinear dependence of dupdel rates with array length F(N r ), since longer arrays tend to have more similar repeats which in turn duplicate faster. We tried some effective model with F(N r ) = N 2 r , not specifying the underlying process producing this dependency. We find again that we can reproduce the similarity vs array length trend, but not the level of the baseline for far repeats (not shown).

Asymmetric similarity dependence between duplications and deletions

We study a variant of the previous model that stresses the out-of-equilibrium aspect of the system. We consider duplication rates of the form ( 120), but deletions do not depend on the ID. In this sense we call this model "asymmetric" in comparison with the previous "symmetric" case. This choice strengthens even further the coupling between dupdel dynamics and sequences σ. Sequences with higher similarity will duplicate faster than they delete (and viceversa) creating a stronger bias when conditioning on different array lengths.

Interestingly when the ID dependence is high enough we observe bimodalities both in evolutionary energy defined in eq. ( 118) (fig. S12) and similarity (fig. S13), and a sharp transition between short low similarity arrays and long, stable high similarity ones (fig. S13). This transition for the displayed parameters is more abrupt than the trends we can observe in data. This effect seems to disappear sharply when γ goes below a certain value.

We tune the strength of the dependence on the ID of the duplication rate, γ, to 0.7 in order to soften this abrupt transition that is absent in data. We explore the time ratio t r and p 1 parameters, while keeping g 0 = 0.7. The phase diagrams in fig. S14 seem to portray a similar scenario as the "symmetric model", with the increase in similarity with array length that is captured while the decay with neighborhood is still too large. But in fact fig. 47A, which compares the similarity versus length for the symmetric and asymmetric case, reveals that now the increase resembles much more the data in its linearity, whereas the "symmetric model" displays a plateau after an initial increase (this remains true even increasing γ). This model, unlike all previous ones, produces a significant increase in the baseline for far neighborhood giving similarities on the right scale (fig. 47B), despite the decay in S14B is still always too large.

To have a more quantitative way of comparing the symmetric and asymmetric models we computed the score eq. ( 119) for all scanned parameters. The minimum score obtained for the symmetric model is about χ = 870, whereas in the asymmetric case it gives about χ = 470 confirming the better performance of this model version. The blue and green curves in fig. 47 Comparing with fig. S13 D it is clear that some model parameters would give us the general trend of similarity versus distance, but this may only occur in the regime where the P(ID) is bimodal, not present in data. We scanned two other choices of g 0 and γ, not in the bimodal regime, and we obtained equivalent results.

the road ahead

Fig. 48 shows another interesting empirical finding: when conditioning to different array lengths, the first and the last repeat in an array, called terminals, are significantly more similar in longer arrays despite being farther away. The model presented in sec. 7.4.3 is the only one among those studied so far where we can robustly get the same amount of increase and the same scale. In 48 we show an example of this. The fact that repeats at any distance are more similar in longer arrays suggests that the dupdel process is out of equilibrium, in the sense that the identity of repeats is driven by the "initial condition", the single repeat common ancestor that all repeats in an array originated from. From there the dupdel process spans the possible lengths faster than the thermalization time it takes for mutations to reach equilibrium.

But the ingredient of out-of-equilibrium alone is not enough to reproduce the observation that, apart from the saw-like trend, similarity is almost constant with inter-repeat distance (fig. 32D), as we saw in sec. 7.4.3. This independence of distance points towards some process that breaks the spatial structure given by the map between repeat arrangement, phylogenetic relationship (closer repeats on average originated from a more recent common ancestor) and inter-repeat similarity. The connection to the latter aspect is due to the Poisson process sparking point mutations along the phylogenetic history of repeats -repeats with farther common ancestor, being consequently farther on the array, are less similar because they had more time to accumulate mutations.

One possible mechanism that introduces long modes in the dupdel process is that of duplication bursts where some repeat can be duplicated many times at once, for instance during the same DNA replication event. In addition to these bursts, deletions of single repeats will restore the right steady state length distribution, and at the same time mutations will shape the similarity patterns.

Duplications bursts model

Here I describe the setup of the next future step, not present in this thesis. We will consider an out of equilibrium model where there is a non-zero transition rate T (N o r → N n r ) = T N n r ,N o r with N n r > N o r , and N n r can be N max r = 38 at most being the biggest array length in our dataset, which we will just call N for brevity. In such a duplication event one of the repeats, picked at random, is duplicated N n r -N o r times. Then we assume that deletions involve of 1 repeat at a time, so with

N n r < N o r , T (N o r → N n r ) = T (N o r )δ(N o r -N n r , 1
), again N n r cannot be smaller than 1. In addition we have the usual mutations that undergo selection given by our evolutionary energy defined in eq. ( 117). The master equation governing P(N r ) = P N r then is

dP(N r ) dt = N o r T (N o r → N n r )P(N o r ) -P(N r ) N n r T (N r → N n r ) (121)
or, in matrix notation:

dP dt = T • P (122)
The matrix T has to satisfy some constraints, for normalization the sum over all elements must be 0 k,l T k,l = 0, which is automatically satisfied if we define the diagonal elements as T k,k =l =k T l,k . Now, given the ingredients of the model, we want to find the entries of T that satisfy such constraints and reproduce the empirical array length distribution as steady state distribution:

T • P emp = 0 (123)
The coefficients of T will depend on the deletions rates from l repeat arrays, λ l , where 1 < l N = N max r , and on the duplications rates from l to k repeats as µ l→k , where 1 l < N and l < k N. The stationarity condition yields (details in C.7) the following relationship between deletion and duplication rates

λ n P n = n-1 l=1 N k=n µ l→k P l (124)
As T = T + I must be nonnegative, the duplication rates must satisfy the condition

1 -λ n - N k=n+1 µ n→k 0 ∀n (125)
Replacing λ n according to Eq 124 we have

n-1 l=1 N k=n µ l→k P l P n + N k=n+1 µ n→k 1 ∀n (126)
As before the duplicated unit in a "burst" event can be either a single repeat or a pair of consecutive repeats. Let be s = 1, 2 the length of this superrepeat duplicated unit. We will assume two independent Poisson processes duplicating units of either 1 or 2 repeats, with rates:

µ s l→k =µ d p(k|l, s) =µ d (l -s + 1) [e -γ s k-l s -e -γs s (N-l+1) ] Z -1 (l, s)δ ( k-l s ,N) (127)
where Z(l, s) is a "normalization" that ensures that µ d is a rate per duplicated unit (as it was a rate per repeat before). Therefore it imposes

N k=l+1 µ s l→k = (l -s + 1) N k=2 µ s 1→k = (l -s + 1)µ d (128)
In the definition eq. ( 127) we assume that the bursts rate decrease exponentially with the number of duplications k-l s with scale 1 γ s . Of course k-l s has to be a positive integer, as formally imposed by δ. The second term in the square brackets ensures that µ s l→N+1 = 0 . With γ s = 0 the process is completely non-local in the sense that there is no penalty in duplicating a repeat more times, as the rate becomes independent of the number of duplicated units, µ s l→• = µ d (l -s + 1). Writing Z(l, s) explicitly yields

µ s l→k = µ d (l -s + 1)
[e -γ s k-l s -e -γs s (N-l+1) ]

-N-l s e -γs s (N-l+1) + 1-e -γs N-l s e γs -1 δ ( k-l s ,N) [START_REF] Mirny | How evolution makes proteins fold quickly[END_REF] where • indicates floor rounding operation. For γ s s (N -l) 1 (127) becomes

µ s l→k =µ d (l -s + 1) e -γ s k-l s Z -1 (l, s)δ ( k-l s ,N) =(l -s + 1)e -γ s ( k-l s -1) (1 -e -γ s )δ ( k-l s ,N) (130)
therefore we can realize that, apart from the multiplicative prefactor, the number of duplicated units k-l s is governed by a geometric distribution with probability p = 1 -e -γ s . This gives a formal link with a possible effective "molecular clock" underlying the process: when a burst is triggered, at each duplication there is a probability p of interrupting it, so the total number of units duplications is distributed as the number of trials k-l s until the stop signal is successful. Without taking the big N limit, the elements of the transition matrix µ l→k are determined by summing eq. ( 129) over s. In practice

µ l→k =µ d l [e -γ 1 (k-l) -e -γ 1 (N-l+1) ] -(N -l)e -γ 1 (N-l+1) + 1-e -γ 1 (N-l) e γ 1 -1 + µ d (l -1) [e -γ 2 ( k-l 2 ) -e -γ 2 2 (N-l+1) ] -N-l 2 e -γ 2 2 (N-l+1) + 1-e -γ 2 N-l 2 e γ 2 -1 δ ( k-l 2 ,N) (131)
The results of this model, that will be explored numerically, are not part of this thesis.

conclusions

We show that we can infer from data an evolutionary model for repeat arrays, characterized by selection through functional constraints encoded in an evolutionary energy, and repeat duplications and deletions that determine the phylogenetic relationship between repeats on the same array. Apart from the evolutionary energy this model allows us to infer a single parameter that determines the timescale of dupdels relative to point mutations. The inferred model can reproduce the whole distribution of similarity, as well as other higher order statistics not used for fitting.

Then we use the inferred evolutionary energy as a basis to explore the qualitative behaviors of progressively more complex models. Adding few clear ingredients we can reproduce qualitatively most experimental observations for some parameters sets, and produce better and better models as quantified by a single score, eq. ( 119).

This preliminary qualitative exploration already gives us some important hints on the processes of repeat duplications and deletions. For example it suggests that in a significant fraction of dupdel events the duplicated or deleted unit is a pair of consecutive repeat rather than a single one, which is consistent with the idea that interaction between consecutive repeats is important for the correct folding and function of the tandem array.

Driving the system more out of equilibrium we also can recover trends similar to Fig 48, which suggests that natural arrays are out of equilibrium.

With reasonable parameters none of the models we study reproduces the fact that natural repeat similarity seems to be mostly independent of interrepeat distance. Therefore in the continuation of this work we propose to study a model explicitly out of equilibrium in a way that introduces some long modes in the dupdel process, introduced in sec. 7.5.1.

An underlying assumption in this work is that the evolutionary energy is common to all arrays in the family irrespective of length, and it imposes constraints only on pairs of repeats. If the timescale of the stochastic dupdel process is fast compared to the timescales of natural selection on protein function this assumption is reasonable, and in this work we will keep this perspective. Exploring the scenario of length dependent evolutionary constraints would be an interesting subject of study for future work, but it goes beyond the purpose of the current study.

Another important aspect that is worth investigating in some future study is whether or not there is an intrinsic notion of where repeats start and end on a protein. This could be either due to functional constraints or due to some important detail of the molecular mechanism producing duplications and deletions.

Empirical observations contain a rich variety of behaviors, like the fact that longer arrays seem to be systematically more stable from an evolutionary standpoint. A recent work [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF] found some correlations that suggest that the duplicated units may even be larger than pairs of repeats. Considering that little is known on the molecular mechanisms underlying repeat evolution, it would be too challenging to propose a single simple scheme to reproduce all these many different empirical features. Our inference scheme relies on sequence statistics, therefore the leading behaviors of the model will be determined by the most represented empirical statistics. Without some mechanistic information this class of models cannot reproduce a trend peculiar only to a subleading fraction of the dataset, such as the afore-mentioned finding that the few longer arrays seem to be more stable, or the possibility that in some cases repeats can be duplicated and deleted in triplets. We cannot observe a significant effect of triplets duplications in the summary statistics of repeat similarity as a function of neighborhood, fig. 32D.

Therefore the aim of the second part of this work is not to propose a specific detailed molecular mechanism of repeat arrays evolution to reproduce every detail of the empirical observations. Instead we explore models that treat dupdels mechanisms in a coarse-grained way, comparing radically different scenarios with as few key ingredients as possible that could be linked in an effective fashion to different modes of repeat arrays evolution. Through this comparison we aim at extracting information on the most likely of such scenarios reproducing at least qualitatively as many observations as possible, supported by a significant fraction of empirical statistics. Once a scenario will be selected, we will be able to apply our inference scheme to learn quantitatively some features of the evolutionary mechanism, as we did in sec. 7.3 inferring the functional constraints as well as the ratio of dupdels and mutation timescales.

Part III C O N C L U S I O N S A N D F U T U R E P E R S P E C T I V E S C O N C L U D I N G R E M A R K S

discussion and conclusion

As outlined in Chapter 1 this thesis addressed the role of evolutionary constraints in two systems at different scales: the coevolution between viruses and immune systems, and the evolution of proteins.

In the first context we studied two minimal models, characterized by a different level of coarse-graining, to address how the memory update of immune repertoires constrains virus evolution (Chapters 3 4). These are inspired by viruses that cause acute infections such as flu, but the abstract framework does not make specific assumption about which virus we are trying to model. These models have few simple ingredients accounting for the immune response, the epidemiological and the evolutionary processes coupling viruses and immune systems. We found that viruses in some parameter region sustain a steady state escape dynamics. At the same time they are constrained by immune systems to a few evolutionary patterns, which emerge naturally from the models' ingredients without being directly encoded in these, and which we map on the immune-mediated constraints. We argue that this is the minimum number of ingredients necessary to observe the emergence of these different evolutionary outcomes. These patterns are naturally observed in the evolutionary histories of some viruses such as flu, as influenza A evolves linearly on a single trunk of evolution [START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF][START_REF] Luksza | A predictive fitness model for influenza[END_REF][START_REF] Smith | Mapping the Antigenic and Genetic[END_REF] whereas influenza B split decades ago into independent lineages [START_REF] Paul A Rota | Lineages of Influenza Type B Virus since 1983[END_REF].

In Chapter 3 we studied numerically an agent-based model and we mapped quantitatively the emerging patterns onto the model parameters. This map could be used to get information on the order of magnitude of unknown parameters of some virus showing one of the reported patterns. Otherwise it can be used to compare qualitatively viruses with different evolutionary histories such as influenza A and B. One could try to infer the model parameters from data, even though the mapping from genotype to phenotype is a hard problem that makes it very hard to infer precisely parameters related to our antigenic space. But when hypothetically succeeding in this task we could check the quantitative predictions of this model against measured features of viral evolution (TMRCA, diversity, diffusivity in antigenic space). We are not considering many details that may be important to predict precisely the evolution of specific viruses, so we may likely find that this model is unsuitable to draw quantitative predictions. Nevertheless its qualitative insights may still prove useful to understand what extra ingredients should be added to these few general ones, in order to reproduce some specific observable.

In Chapter 4 we studied a more coarse-grained theoretical model consisting of a system of coupled stochastic differential equations. These describe the evolution of viruses and immune receptors in antigenic space, in a mean-field approximation with respect to what receptors belong to what host. This study allowed us to understand more thoroughly the interplay between the different scales constituting this phylodynamic system. We obtained some analytical insights, validated against numerical simulations, into how immune systems constrain viral evolution in antigenic space while viruses manage to sustain a steady state escape dynamics. Specifically we got quantitative predictions for a number of antigenic observables such as the speed of adaptation, the shape of viral lineage dispersions, and the persistence length of lineage trajectories. Some of these analytical predictions hold only in a diffusive regime in parameters space, but even when this breaks down we obtained numerical predictions.

As we mentioned earlier Chapter 4 was adapted from a work still in preparation. As next steps it would be interesting to see if we can derive some scalings for our model in the regime where evolution is driven by rare and large mutations, where therefore the diffusion approximation breaks down. Then we want to perform analytical first-passage-time calculations to derive the extinction rates, and the transition between one to many co-evolving lineages. This will allow us to reach a more thorough understanding of how immune imposed constraints drive viruses to different pattern, compared to the sort of "phenomenological" intuitive understanding we obtained from the numerical exploration in Chapter 3. Finally we want to validate the analytical result in eq. ( 70) against simulations.

In this model we relaxed some assumptions made in previous models of influenza phylodynamics [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225]. We explicitly consider the capacity of immune repertoire, which was considered infinite in those works. Moreover in the model formulation we don't make any assumption about the antigenic space dimensionality, which is what allows us to address how immune systems shape the organization of viruses in this space.

The idea of addressing the shape of viral evolution in antigenic space was introduced experimentally by antigenic maps of influenza [START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF][START_REF] Smith | Mapping the Antigenic and Genetic[END_REF]. With more data of this type about other viruses one could start by comparing qualitative differences with the predictions of this model. The considerations we made above about the difficulty of precise inference and quantitative prediction testing hold even more for this more abstract model.

In the second Part of this thesis we exploit the available protein sequence data to extract information about the evolutionary constraints acting on families of repeat proteins. We couple a maximum entropy inference scheme to computational models grounded on equilibrium statistical mechanics ideas, which characterize the macroscopic observables arising from a probabilistic description of protein sequences. Through this inference we can infer local constraints on amino-acid sequences, which represent the functional constraints imposed on protein families by evolution.

In Chapter 6 we used this framework to address how functional constraints reduce and shape the global space of repeat protein sequences that survive selection. We obtained an estimate of the number of accessible sequences, and we characterized quantitatively the relative role of different constraints and phylogenetic effects in reducing this space. Our results suggest that the studied repeat protein families are constrained by a rugged landscape shaping the accessible sequence space in multiple clustered subtypes of the same family.

As discussed in Chapter 6, the sequences that correspond to the energy minima of the landscape are not found in the natural dataset. This may be caused by the fact that we have not yet observed these sequences with the minimal energy, although they exist, or that these sequences may not have been sampled by nature -note that for entropic reasons there is no guarantee that these minima will ever be explored within evolutionary relevant timescales. Alternatively, there may be additional functional or biochemical constraints that are not included in our model to avoid these low energy sequences, for instance due to the fact that we decided to ignore correlations higher than second order in the maximum entropy formulation.

This analysis suggests a view in which natural proteins live in a global evolutionary landscape, of which families would be basins, or clusters of basins, with a hierarchical structure [START_REF] Nikolay | Understanding Hierarchical Protein Evolution from First Principles[END_REF]. This multiplicity of valleys is a direct consequence of local and global evolutionary interactions between amino-acid sites. Therefore this study suggests that interactions are fundamental in shaping proteins evolution, and need to be accounted for if we wish to understand the separation into families and subfamilies from an evolutionary standpoint.

As extensively discussed in section 5.2.3 the maximum entropy principle has limitations and the resulting inferred evolutionary energy cannot be taken as a faithful representation of this global evolutionary landscape in any region of the sequence space, especially in undersampled regions. But in many previous work maximum entropy models successfully predicted fitness effects of mutations [START_REF] Contini | A many-body term improves the accuracy of effective potentials based on protein coevolutionary data[END_REF][START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF][START_REF] Figliuzzi | Coevolutionary landscape inference and the context-dependence of mutations in beta-lactamase TEM-1[END_REF][START_REF] Haldane | Structural propensities of kinase family proteins from a Potts model of residue co-variation[END_REF][START_REF] Thomas | Mutation effects predicted from sequence co-variation[END_REF], and even drove the synthesis of new functional proteins [START_REF] Russ | Evolution-based design of chorismate mutase enzymes[END_REF][START_REF] Socolich | Evolutionary information for specifying a protein fold[END_REF][START_REF] Tian | Co-Evolutionary Fitness Landscapes for Sequence Design[END_REF]. This implies that this maximum entropy inference scheme can locally approximate the evolutionary landscape in well sampled regions of the sequence space, which is all we need to draw the conclusions above.

In Chapter 7 we exploit the same framework to address the interplay between evolutionary constraints and phylogenetic correlations in repeat tandem arrays. As a result we inferred quantitatively the parameters of a simple evolutionary model for repeat arrays. These consist of the functional constraints encoded in an evolutionary energy, and of the relative timescale between repeat duplications/deletions and point mutations. This novel model ingredient determines the phylogenetic relationship between repeats on the same array. This inferred model could reproduce many higher order empirical statistics not directly encoded in the model parameters.

We also added ingredients to the inferred evolutionary model to investigate what microscopic evolutionary mechanisms can generate specific interrepeat statistical patterns, which are recurrently observed in data. Adding a few clear ingredients we could reproduce qualitatively most experimental observations for some parameters sets, gaining insights on the process of repeat duplications and deletions. The results of this fruitful qualitative exploration suggest that repeats are often duplicated or deleted in consecutive pairs. An interesting empirical finding was that repeats at the border of the array are more similar in longer arrays. A possible interpretation of this fact is that the identity of repeats as far away as possible (terminals) is driven by what protein they belong to and what repeat was their common ancestor, rather than a common family baseline they are thermalizing to. This reasoning suggests that evolution of repeat tandem arrays is strongly out of equilibrium. Preliminary results of out of equilibrium evolutionary models reproduced better the empirical patterns, supporting this idea.

This Chapter is part of a work currently in progress. With reasonable parameters none of the models we studied reproduced the fact that natural repeat similarity seems to be globally independent of inter-repeat distance. Therefore in the continuation of this work we propose to study a model explicitly out of equilibrium in a way that introduces some long modes in the repeat duplication/deletion process. Once we will find a scenario that qualitatively captures as many empirical patterns as possible, we will apply our inference scheme to learn quantitatively the features of the evolutionary mechanism together with the functional constraints, as we did here for the simplest evolutionary model.

future perspectives

Viral-immune coevolution

In Chapter 3 we assumed an abstract 2D antigenic space, and even if the model formulation in Chapter 4 does not make any dimensionality assumption, its simulations consider a 2D space. Similarly previous work made strong assumptions on the antigenic space dimensionality [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF]225]. The dimensionality of a common effective phenotypic space where antigens and immune receptors live all together is a debated issue. Some works suggested an high-dimensional space [START_REF] Aguas | Predictability of the antigenic evolution of human influenza A H3 viruses[END_REF][START_REF] Moore | High dimensional random walks can appear low dimensional: Application to influenza h3n2 evolution[END_REF][START_REF] Perelson | Theoretical studies of clonal selection minimal antibody repertoire size and reliability of self non self discrimination[END_REF], whereas others that use phenotypic titer experiments suggested that influenza lives in an effectively low-dimensional space [START_REF] Fonville | Antibody landscapes after influenza virus infection or vaccination[END_REF][START_REF] Smith | Mapping the Antigenic and Genetic[END_REF]. This uncertainty originates from the difficulty of mapping genotype to phenotype. To gain at least qualitative insights one could look at this in a more effective way, and compare the dimensiondependent predictions of some evolutionary model in antigenic space with the observed virus evolutionary features. In this perspective it would be interesting in future to try and relax the 2D assumption in Chapter 3 since the framework allows for it, and to extend the work of Chapter 4 to derive predictions for some observable that explicitly depends on the dimension.

Another problem when studying evolution is the reproducibility of some observed phenomenology. As we discussed in Chapter 3, when observing natural histories of viral evolution, we are observing a single realization of a stochastic process. Therefore we can not rule out that, for example, the fact that influenza A is evolving on a single trunk whereas influenza B split into two independent lineages is just due to a stochastic realization rather than to evolutionary forces. This is why bacteria represent a great model system to study evolution: one can produce in the lab many reproducible realizations of evolutionary dynamics, addressing systematically relevant questions to improve our understanding of this phenomenon. In the context of our work on viral-immune coevolution, the qualitative predictions of our models could be tested studying phage-bacteria coevolution, for instance through synthetic CRISPR-phage evolutionary systems [START_REF] Chabas | Evolutionary emergence of infectious diseases in heterogeneous host populations[END_REF]. To do so our general models would need to be adapted to the details of this system. Another possibility to overcome this lack of reproducibility could be to study the within host evolution of viruses and adaptive immune systems in various patients with persistent infections from e. g. HIV. The models studied here are not meant for this within-host scenario, but some model of the same flavor as the one studied in Chapter 4 could be formalized.

In our models for acute infections the timescales of the system allowed us to assume that the immune system updates perfectly to the position of the last infecting viruses. But many interesting evolutionary phenomena happen when the adaptive immune system within each of us responds to present infections, while keeping memory of the past ones and somehow trying to anticipate the statistics of possible future infections. These individual immune dynamics become important when modeling shorter timescales or when studying persistent infections. Together with the immune-driven evolution of pathogens, on which we focused our attention in this work, they constitute the complex viral-immune coevolutionary system as a whole. Some recent works studied how immune systems can dynamically allocate resources exploiting memory in an optimal way in order to cope with varying pathogenic environments [START_REF] Mayer | How a well-adapting immune system remembers[END_REF][START_REF] Oskar | Optimal evolutionary decision-making to store immune memory[END_REF], but in turn they had to assume a stereotyped pathogenic dynamics. The big next step in modeling pathogensimmune coevolution will be to build stochastic models where both players are modeled explicitly, and the evolution of both is an unconstrained outcome of the model. As mentioned above this will be central to address the situation where both pathogens and immune systems evolve on similar timescales.

The main missing ingredient in fully capturing coevolutionary dynamics is the mutual feedback between the stochastic evolution of pathogens and immune systems. Understanding the nature of this feedback will be important to design efficient ways to perturb this system in order to control its outcomes [START_REF] Lässig | Eco-evolutionary control of pathogens[END_REF][START_REF] Nourmohammad | Optimal evolutionary control for artificial selection on molecular phenotypes[END_REF][START_REF] Paarporn | Optimal control policies for evolutionary dynamics with environmental feedback[END_REF][START_REF] Wang | Steering eco-evolutionary game dynamics with manifold control[END_REF]. This research direction will be central to designing optimal vaccine strategies. The importance of feedback goes beyond the specific setting of coevolution between pathogens and immune systems. It applies to any general situation where organisms coevolve with their ecosystem on similar timescales, like the many different bacteria grouped in communities in the gut microbiota.

Protein evolution

As discussed in Chapter 6 the minima of the evolutionary energy we found not only are not present in the natural dataset, but have a way lower evolutionary energy than the consensus sequence, which in repeat proteins was found to be an excellent model of protein design [START_REF] Ykelien | DARPins and other repeat protein scaffolds : advances in engineering and applications[END_REF]. An interesting future perspective would be to study the folding of these sequences explicitly accounting for the biochemical interactions between amino-acids through computational molecular dynamics algorithms. Even more interesting would be to try and synthesize these proteins to test their folding and function experimentally.

Another insight from the work in [START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF] is the important role of interactions between amino-acids in shaping a rugged evolutionary landscape. This implies that interactions carry important information on the separation into distinct protein families. The most commonly adopted bioinformatic classification into families, the PFAM database, uses a local single-site score to perform this classification [START_REF] Bateman | The Pfam protein families database[END_REF][START_REF] Robert D Finn | Pfam: the protein families database[END_REF]. Our results suggest that this classification could be greatly improved by accounting for interactions. A recent work [START_REF] Muntoni | Aligning biological sequences by exploiting residue conservation and coevolution[END_REF] proposed a sequence alignment tool explicitly taking pairwise correlations into consideration, which is a first step in this direction.

Another interesting perspective, following the concept of a rugged landscape, is to explore the possible paths separating local coarse-grained minima, or protein sub-types. In this direction it would be even more interesting to study the evolutionary transition between proteins that have been already proven to have different folds/function. A recent work studied the transitions between two proteins that can switch folds with as little as one point mutation [START_REF] Tian | Exploring the Sequence Fitness Landscape of a Bridge Between Protein Folds[END_REF]. The ultimate challenging goal would be to study generic evolutionary transitions between different families to understand how evolution explores sequence space, how the multitude of protein families is established, and if a certain structure exists in their global organization.

A general issue in the inference of protein sequences is given by the phylogenetic correlations in homologous sequences. In order to exploit the maximum entropy inference scheme which assumes independently drawn samples, data need to be curated. Sequences are reweighted to counteract the phylogenetic effects [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF]. But this a manual hack that has to be done ad-hoc for each dataset. Therefore one of the most relevant future directions in this field of research will be to include a general unique framework that could account for, and give insights on, the propagation of phylogenetic effects in families of homologous sequences [START_REF] Van Nimwegen | Inferring Contacting Residues within and between Proteins: What Do the Probabilities Mean?[END_REF]. Recent work [START_REF] Qin | Power law tails in phylogenetic systems[END_REF][START_REF] Zeng | Inferring epistasis from genomic data by Gaussian closure[END_REF] moved some preliminary step towards this goal. In repeat proteins duplications and deletions spread phylogenetic effects across different parts of the same protein, which can be decoupled from functional constraints. Hence we think that repeat proteins may be in future a useful system to address this issue. This issue of phylogenetic effects is strictly related to the out-of-equilibrium nature of evolution. After reweighting the dataset, the maximum entropy framework, formally connected to equilibrium, works pretty well. But outof-equilibrium effects may be significant to account explicitly for the phylogenetic correlations. Repeat proteins may become a useful system to gain insights on this matter, since repeats' arrangement on a protein carries information on their past evolutionary history, and at the same time correlates with directly measurable similarity patterns. More broadly, in future it would be exciting to quantify how close to equilibrium is the evolution of those protein sequences that survive selection, and how the answer is affected by specific evolutionary constraints.

Part IV

A P P E N D I X A M U LT I -L I N E A G E E V O L U T I O N I N V I R A L P O P U L AT I O N S D R I V E N B Y H O S T I M M U N E S Y S T E M S : S U P P L E M E N TA R Y I N F O R M AT I O N a.1 simulation details a.1.1 Initialization
We initialize all simulations in an immune coverage background that favors the evolution of one dominant antigenic lineage. We draw viral positions uniformly from a rectangle with bottom-left and top-right corners positioned at (-3σP mut , 0) and (3σP mut , σ). Each host is initialized with one immune receptor as a point in antigenic space, which grants localized protection. The initial memory repertoires of the different hosts are drawn uniformly from a rectangle with bottom-left and top-right corners positioned at (-3σP mut , -5 σ fi P mut ) and (3σP mut , 0), where fi is the target fraction of infected hosts, determining the number around which the viral population is stabilized (see Section 3.3.2) and the timescale with which all hosts add (or renew) an immune receptor to their repertoire. In order to lose memory of the artificial initial conditions we let the system evolve until 99% of the host population have been infected by a virus, so that most hosts have added at least one strain to their repertoires before recording any data.

a.1.2 Control of the number of infected hosts

We studied two versions of the same model, one constraining the viral population size strictly, the other letting it fluctuate. In the latter case, we still have to constrain population size for an initial transient in order to reach a well equilibrated initial condition.

We control the virus population size through the fraction of infected hosts around a target value of fi . We modify R 0 -the average number of new hosts that are drawn to be infected in a given transmission event -based on the current fraction of infected hosts f i at each time:

R 0 = 1 p f + fi -f i fi , (132)
where p f is the probability of a successful infection at a transmission event, i.e. the probability that a new host is susceptible to the infecting viral strain. We evaluate its average p f over segments of 1000 transmission events. On average,

f i (t + t I ) ≈ f i (t) R 0 p f . (133)
Using Eq. ( 132), we find that the average fraction of infected hosts f i (t) is governed by a logistic map with fix point fi , effectively producing a process where the viral population growth is limited by an effective carrying capacity N fi .

a.2 detailed mutation model

We present the detailed in-host mutation model, in which we explicitly find the probability of producing a new mutant within an infected host. We assume that the immune system responds only to the first viral strain it sees, and that all viruses see the immune system in the same way, undergoing the same deterministic dynamics, i.e. evolution is neutral within one host. This intra-host neutral selection holds if the characteristic mutation jump size is smaller than the cross reactivity length, σ d, which is the case for our simulations. We consider this mutation-proliferation process up to time t I .

We call the total viral population v tot , the first viral invader, that is the first viral strain infecting one host, v 0 , and the new mutants, appearing with size 1, v j . These three quantities (neglecting the discreteness of the process) grow deterministically as function of time t as:

v tot (t) = e αt , (134)
v 0 (t) = e αt - i 0 e α(t-t i 0 ) Θ(t -t i 0 ) , (135)
v j (t) = e α(t-t j ) - i j e α(t-t i j ) Θ(t -t i j ) , (136)
where i j denotes the indexes of the viral mutants originated from mutant j (if any) and t i j indicates the times at which such mutations arose (Θ(x) is the Heaviside function, = 0 for x < 0 and 1 otherwise). Each mutation jumps to new phenotypic coordinates. From these equations the relative mutants fractions are

x 0 = 1 - i 0 e -αt i 0 Θ(t -t i 0 ) , (137)
x j = e -αt j -

i j e -αt i j Θ(t -t i j ). (138)
The mutation process from any virus present in the viral pool is a non homogeneous Poisson process with rate µe αt . The probability of having n mutations up to the time t is:

P(n, t) = (Λ(t)) n n! e -Λ(t) , (139)
with

Λ(t) = t 0 dt µe αt = µ α (e αt -1) . ( 140
)
The time t 1 of the first mutation event is distributed as:

ρ(t 1 ) = µe αt 1 -Λ(t 1 ) . (141)
In our simulations, we assume that all mutations other than the first are negligible, that is, we can have more than one mutation, but those after the first do not significantly affect the relative fraction, therefore we have only one mutant. The mutant fraction in the population is x 1 (t) = e -αt 1 if t > t 1 . Knowing the distribution of the first mutation times t 1 , we can calculate the probability distribution of the mutant fraction x 1 at the time of the transmission event t I :

ρ(x 1 , t I ) = e -Λ(t I ) δ(x 1 ) + µe -µ α ( 1 x 1 -1) αx 2 1 Θ(x 1 -e -αt I ) . (142)
In the simulations we fixed the growth rate to α = 4 day -1 .

a.3 analysis of simulations a.3.1 Lineage identification

In order to analyze the organization of viruses in phenotypic space, for each saved snapshot we take the positions of a subset of 2000 viruses and then cluster them into separate lineages through the python scikit-learn DB-SCAN algorithm [162] [52] with the minimal number of samples min_samples = 10. The parameter defines the maximum distance between two samples that are considered to be in the neighborhood of each other. We perform the clustering for different values of and select the value that minimizes the variance of the 10th nearest neighbor distance (the clustering results are not sensitive to this choice). From the clustered lineages we can easily obtain a series of related observables, such as the number of lineages and the fraction of time in which viruses are clustered in a single lineage (Fig. 7). A split of a lineage into two new lineages is defined when two clusters are detected where previously there was one, and the two new cluster centroids are farther away than the sum of the maximum distances of all the points in each cluster from the corresponding centroid. We impose this extra requirement in order to reduce the noise from virus subsampling and the clustering algorithm. A cluster extinction is defined when a cluster ceases to be detected from one snapshot to the next.

a.3.2 Turn rate estimation

We estimate the turn rate by detecting turns in the trajectories of lineage centroids in phenotypic space. This is done by calculating the trajectory's angle between subsequent centroid recordings and smoothing it with a 5 year averaging window. A turn is detected when the angle difference with respect to the initial direction reaches 30 degrees, and the time before the turn is recorded as the persistence time. Then the procedure is repeated until the end of the trajectory. In order to have enough timepoints in the trajectory, we limit this analysis to lineages that last more than 20 years. This procedure was carried out for all lineages trajectories in all realizations. Finally to estimate the turn rate we divide the total number of detected turns by the sum of the durations of all the analyzed trajectories.

a.3.3 Phylogenetic tree analysis

From the model simulations we record a subsample of the viral phylogenetic tree. For every recorded strain, apart from some descendants we also save their extinction events. To compute the coalescence time we take all the strains recorded that year that have not yet gone extinct. Then we calculate the time to their most recent common ancestor, and finally we average over all these TMRCAs calculated year after year, for all the realizations. Phylogenetic tree analysis and rendering are done using the python open software ETE Toolkit [START_REF] Huerta-Cepas | ETE 3: Recon-struction, Analysis, and Visualization of Phylogenomic Data[END_REF]. We use a previously curated alignment of pairs of repeats for each family [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF]: ANK (PFAM id PF00023 with a final alignment of 20513 sequences of L = 66 residues each), LRR (PFAM id PF13516 with a final alignment of 18839 sequences of L = 48 residues each) and TPR (PFAM id PF00515 with a final alignment of 10020 sequences of L = 68 residues each). Those multiple sequence alignments of repeats were obtained from PFAM 27.0 [START_REF] Bateman | The Pfam protein families database[END_REF][START_REF] Robert D Finn | Pfam: the protein families database[END_REF]. In order to improve the data obtained from the PFAM database, we used original full protein sequences available in UniProt database [START_REF]UniProt: the universal protein knowledgebase[END_REF] to add available information using the headers of the original alignement. Firstly, to decrease the number of gaps positions, misdetected initial and final amino acids in repeats were completed with residues from full sequences. Secondly, individual repeats which appeared consecutively in natural proteins were joined into pairs. Finally, positions with more than 80% of gaps along the alignment were removed, eliminating in this way insertions.

From the multiple sequence alignement of each family, they were calculated the observables that we use to constrain our statistical model. Particularly, we calculated the marginal frequency f i (σ i ) of an amino acid σ i at position i and the joint frequency f ij (σ i , σ j ) of two amino acids σ i and σ j at two different positions i and j. These quantities were calculated using only sequences selected by clustering at 90% of identity computed with CD-HIT [START_REF] Li | Tolerating some redundancy significantly speeds up clustering of large protein databases[END_REF] and then normalizing by the amount of sequences. In this way, the occurrences of residues in every position are not biased by overrepresentation of proteins in the database. Furthermore, to take into account the repeated nature of the protein families that we are considering, an additional observable was calculated, the distribution of sequence overlap between two consecutive repeats, P(ID(σ)), with ID(σ) = L i=1 δ σ i ,σ i+L .

b.1.2 Model fitting

In order to obtain a model that reproduces the experimentally observed site-dependent amino-acid frequencies, f i (σ i ), correlations between two positions, f ij (σ i , σ j ), and the distribution of Hamming distances between consecutive repeats, P(ID(σ)), we apply a likelihood gradient ascent procedure, starting from an initial guess of the h i (σ i ), J ij (σ i , σ j ) and λ ID (σ) parameters.

At each step, we generate 80000 sequences of length 2L through a Metropolis-Hastings Monte-Carlo sampling procedure. We start from a random aminoacid sequence and we produce many point mutations in any position, one at a time. If a mutation decreases the energy (106) we accept it. If not, we accept the mutation with probability e -∆E , where ∆E is the difference of energy between the original and the mutated sequence. We add one sequence to our final ensemble every 1000 steps. Once we generated the sequence ensemble, we measure its marginals f model i (σ i ) and f model ij (σ i , σ j ), as well as P model (ID(σ)), and update the parameters of Eq. 106 following the gradient of the likelihood. The local field and λ ID (σ) are updated along the gradient of the per-sequence log-likelihood, equal to the difference between model and data averages:

h i (σ i ) t+1 ← h i (σ i ) t + m [f i (σ i ) -f model i (σ i )], (143)
λ ID (σ) t+1 ← λ ID (σ) t -ID [P(ID(σ)) -P(ID(σ)) model ]. (144)
As the number of parameters for the interaction terms J ij is large (= 21 2 L 2 ), we force to 0 those that are not contributing significantly to the model frequencies through a L 1 regularisation γ ij,σ,τ |J ij (σ, τ)| added to the likelihood. This leads to the following rules of maximization:

If J ij (σ i , σ j ) t = 0 and |f ij (σ i , σ j ) -f model ij (σ i , σ j )| < γ J ij (σ i , σ j ) t+1 ← 0. (145)
If J ij (σ i , σ j ) t = 0 and |f ij (σ i , σ j ) -f model ij (σ i , σ j )| > γ J ij (σ i , σ j ) t+1 ← j [f ij (σ i , σ j ) -f model ij (σ i , σ j )- γsign(f ij (σ i , σ j ) -f model ij (σ i , σ j ))]. ( 146
) If J ij (σ i , σ j ) t + j [f ij (σ i , σ j ) -f model ij (σ i , σ j ) -γsign(J ij (σ i , σ j ) t )] J ij (σ i , σ j ) t 0 J ij (σ i , σ j ) t+1 ← J ij (σ i , σ j ) t + j [f ij (σ i , σ j ) -f model ij (σ i , σ j )- γsign(J ij (σ i , σ j ) t )]. ( 147
) If J ij (σ i , σ j ) t + j [f ij (σ i , σ j ) -f model ij (σ i , σ j ) -γsign(J ij (σ i , σ j ) t )] J ij (σ i , σ j ) t < 0 J ij (σ i , σ j ) t+1 ← 0. (148)
The optimization parameters were set to: m = 0.1, j = 0.05, ID = 10, and γ = 0.001.

To estimate the model error, we compute

f i (σ i ) -f model i (σ i ) and f ij (σ i , σ j ) - f model ij (σ i , σ j ).
We also calculate the difference of generated and natural repeat similarity distribution for all the possible repeats Hamming distances, penalized by a factor 5 to better learn the parameter λ ID : 5(P(ID(σ)) -P(ID(σ)) model ). We repeat the procedure above until the maximum of all errors,

|f i (σ i ) -f model i (σ i )|, |f ij (σ i , σ j ) -f model ij (σ i , σ j )|
and 5|P(ID(σ)) -P(ID(σ)) model |, goes below 0.02, as in Ref. [START_REF] Espada | Inferring repeat-protein energetics from evolutionary information[END_REF].

b.1.3 Models with different sets of constraints

Using this procedure we can calculate the model defined in Eq. 106 with different interaction ranges used in the entropy estimation in Fig. 29 A. We start from the independent model h i (σ i ) = log f i (σ i ). We first learn the model in Eq. 106 with J = 0. We then re-learn models with interactions between sites i, j along the linear sequence such that |i -j| W, in a seeded way starting from the previous model. The first and last point of Fig. 29 correspond to the independent site model with λ ID and the full model in Eq. 106

The entropy in Fig. 29B is calculated in the same way as in Fig. 29, but now interactions are turned on progressively according to physical distance in the 3D structure rather than the linear sequence distance. In order to obtain the physical distance between residues we use as a reference structure the first two repeats of a consensus designed ankyrin protein 1n0r [START_REF] Binz | Designing repeat proteins: well-expressed, soluble and stable proteins from combinatorial libraries of consensus ankyrin repeat proteins[END_REF][START_REF] Mosavi | Consensusderived structural determinants of the ankyrin repeat motif[END_REF], which have exactly 66 amino-acids. We define the 3D separation between two residues as the minimum distance between their heavy atoms in the reference structure.

To learn the Potts model without λ ID (E 2 ) we remove λ ID from Eq. 106 and re-learn the Potts field using the full model parameters as initial contition.

To learn the single repeat models with and without λ (E ir and E ir,-, we take as initial condition the model with interactions below the length of a repeat (W = L -1, dashed vertical line in Fig. 29), and then learn a model removing all the J ij terms between different repeats. We also impose that the h i fields and intra-repeats J ij terms are the same in each repeat, and the experimental amino-acid frequencies to be reproduced by the model are the average over the two repeats of the 1-and 2-points intra-repeats frequencies f i (σ i ) and f ij (σ i , σ j ), such that

f i (σ i ) = f i+L (σ i ) = 1 2 f i (σ i ) + f i+L (σ i ) , (149)
and

f ij (σ i , σ j ) = f i+L,j+L (σ i , σ j ) = (150) = 1 2 (f ij (σ i , σ j ) + f i+L,j+L (σ i , σ j )),
if i and j represent sites within the same repeat. In this way we obtain a model for a single repeat that can be extended to both the repeats in the original set of sequences of our dataset.

b.1.4 Entropy estimation

In practice to calculate the entropy S of the protein families we relate it to the internal energy E =log p(σ) and the free energy F =log Z:

S = E -F = σ p(σ)E(p(σ)) + log Z (151)
=σ p(σ) log p(σ) ,

We generate sequences according to the energy function in Eq. 106 and use them to numerically compute E . To calculate the free energy we use the auxilliary energy function:

E α (σ) = - i h i (σ i ) + α - ij J ij (σ i , σ j ) + λ ID , (152)
where the interaction strength across different sites can be tuned through a parameter α that is changed from 0 to 1. We generate protein sequence ensembles with different values of α and use them to calculate F as a function of α, F(1) = F(0) + 1 0 dα dF dα :

F(1) = F(0) + 1 0 dα - ij J ij (σ i , σ j ) + λ ID α , (153)
where the average over α is taken over the sequences generated with a certain value of α, characterized by the ensemble with probability p α (σ) = (1/Z α )e -E α (σ) . F(0) is the free energy for an independent sites model:

F(0) = - i log σ i e h i (σ i ) , (154)
where the first sum is taken over protein sites and the second over all possible amino-acids at a given site. Eq. 154 and Eq. 151 result in the thermodynamic sampling approximation for calculating the entropy [START_REF] Frankel | Understanding Molecular Simulation: From Algorithms to Applications[END_REF]:

S = E + i log σ i e h i (σ i ) - 1 0 dα - ij J ij (σ i , σ j ) + λ ID α . (155)
We generate 80000 sequences using Monte Carlo sampling for the energy in Eq. 152 with 50 different α values, equally spaced between 0 and 1 at a distance of 0.02, and then numerically compute the integral in Eq. 155 using the Simpson rule.

b.1.5 Entropy error

The entropy estimate is subject to three sources of uncertainty: the finitesize of the dataset, convergence of parameter learning, and the noise in the namic integration and in the gradient descent, starting from the same initial conditions and with the same update parameters (see Section B.1.2). The combined noise is smaller than the entropy decrease at 33 residues, showing the decrease is real.

To further check the robustness of the entropy estimation procedure, we generate two synthetic ANK datasets, one with an independent sites model, the other with a model of two non-interacting repeats obtained as explained in the Section B.1.2, and relearn the model from the synthetic datasets. Repeating the learning and entropy estimation procedure on each on the synthetic protein families gives results that are consistent with the model used for the dataset generation. The entropy of the model learned taking an independent sites dataset does not decrease with the interaction range W and the entropy of the model learned taking a non-interacting repeats dataset does not show any drop around the repeat length.

We repeat the procedure described for the LRR and TPR repeat-proteins families reaching similar conclusions (Fig. S6).

b.1.6 Calculating the basins of attraction of the energy landscape

In order to characterize the ruggedness of the inferred energy landscapes and the sequence identity of the local minima, we start from all the sequences in the natural dataset as initial conditions and for each of them we perform a T = 0 quenched Monte-Carlo procedure. Repeating this analysis on sequences synthetically generated from E full yields very similar results (see Fig. S10 for ANK)

We perform this energy landscape exploration learning the parameters of the Hamiltonian in Eq. 106 (refer to Section B.1.2 for the learning procedure), and then set λ ID = 0 in the energy function because we want to investigate the shape of the energy landscape due to selection rather than the phylogenic dependence.

We scan all the possible mutations that decrease the sequence energy and then draw one of them from a uniform random distribution. The possible mutations are all single point mutations. If the same amino-acid is present in the same relative position in the two repeats we allow for double mutations that mutate those two positions to a new amino-acid, that is identical in both repeats, at the same time. We do this so that the phylogenetic biases that are still partially present in the parameters of the model do not result in spurious local minima biasing the quenching results. The Monte-Carlo procedure ends when every proposed move results in a sequence with an increased energy, and the identified sequence is a local minimum of the energy landscape.

To explore how turning on interactions makes the energy landscape more rugged, we perform the same procedure with the Hamiltonian corresponding to two intermediate interaction ranges in Fig. 29 A. That is Eq. 106, in which J ij was allowed to be non-zero only within a certain interaction range W. We picked W = 3 and W = 10.

In order to assess what is the role of the inter-repeat interactions we repeat this T = 0 quenched Monte-Carlo procedure on single repeats, with all the unique repeats in the natural dataset as initial condition. The learning procedure of the Hamiltonian for a single repeat is explained in Section B.1.2. In this single repeat case the possible mutations are just the single point mutations.

Once we have the local minima of the energy landscape, we obtain the coarse-grained minima using the Python Scipy hierarchical clustering algorithm. In this hierarchical clustering the distance between two clusters is calculated as the average Hamming distance between all the possible pairs of sequences belonging each to one cluster. As a result we plot the clustered distance matrix, the clustering dendogram and the basin size corresponding to the distance matrix entries.

In the end we can repeat the quenching procedure described above for LRR and TPR families. The result are sketched in Fig. S7 and Fig. S8 and lead to similar conclusions as for the ANK family.

b.1.7 Kullback-Leibler divergence

The Kullback-Leibler divergence between two families A and B is defined as D KL (A||B) = σ p A (σ) log 2 p B (σ)/p A (σ). We can substitute the sequence ensembles for ANK and TPR in the definition of the probabilities obtaining:

D KL (ANK||T PR) = E TPR -E ANK ANK + F ANK -F TPR , (157)
D KL (T PR||ANK) = E ANK -E TPR TPR + F TPR -F ANK , (158)
where the notation ANK means that the average is calculated over sequences drawn from the ANK ensemble: P(σ) ANK = (1/Z ANK )e -E(σ) ANK . Therefore E TPR ANK is the average TPR energy function evaluated, via the structural alignment between the two families, on 80000 sequences generated through a Monte Carlo sampling of the ANK model ( 106) (and analogously for E ANK TPR ). The terms F ANK and F TPR are calculated in the same way as when estimating the entropy through Eqs. ( 153), [START_REF] Nourmohammad | Host-Pathogen Coevolution and the Emergence of Broadly Neutralizing Antibodies in Chronic Infections[END_REF], as explained in Section B.1.4.

For the control against a random polypeptide of length L we use D KL (FAM||rand) = log Λ -S(FAM), where Λ = 21 L is the total number of possible sequences of length L. We used a sequence dataset for the Ankyrin repeat protein family that organize 1.2 million repeated units in 257703 arrays [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF]. Repeats of l r = 33 amino-acids were obtained scanning the UniprotKB database [START_REF] Boutet | UniProtKB/Swiss-Prot[END_REF] with hmmsearch at default parameters, using structurally-derived Hidden Markov Models (HMM) for internal, C-terminal and N-terminal units [START_REF] Parra | Structural and Energetic Characterization of the Ankyrin Repeat Protein Family[END_REF]. The repeats were later curated, eliminating insertions within repeats (rarely larger than 5 residues [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF]) and replacing detected deletions with the gap character ('-').

The repeats considered as consecutive (less than 67 residues away) along a protein sequence were concatenated together into arrays, hence more than one distinct array is allowed per protein sequence. We consider only the internal units of each array, discarding the terminal repeats which have been characterized as different natural objects [START_REF] Parra | Structural and Energetic Characterization of the Ankyrin Repeat Protein Family[END_REF].

In order to minimize the bias produced by the phylogenetic relationship between sequences and the human sequencing bias, sequences were clustered by similarity using CD-hit with 90% as cutoff parameter [START_REF] Li | Cd-Hit: a Fast Program for Clustering and Comparing Large Sets of Protein or Nucleotide Sequences[END_REF] and a weight w i = 1/n i was assigned to each protein in a cluster i with n i elements. After re-weighting, the dataset counts 153209 effective arrays: 85.5% belong to Eukaryota proteome, 13.0% Bacteria ,1.4% Viruses and 0.1% Archaea, in agreement with previous studies [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF].

The number of arrays decreases roughly exponentially with their length [START_REF] Galpern | Large Ankyrin repeat proteins are formed with similar and energetically favorable units[END_REF], and for the larger tandems the dataset is sparsely populated. We restrain the dataset to arrays with 1 to 38 internal repeats, so that each array length is represented by at least 10 effective arrays.

c.2 quasi-equilibrium

The class of models considered in 7 can be considered at quasi-equilibrium in the sense that, even though microscopically detailed balance is not satisfied, there are two processes with different timescales so that the effective processes obtained by marginalizing one or the other can still be considered at equilibrium. In general the master equation for length and sequence behind the marginalized version [START_REF] Marchi | Multi-lineage evolution in viral populations driven by host immune systems[END_REF] Formally this process does not satisfy detailed balance because deletions remove repeats irrespective of their sequences whereas duplications can only generate two perfectly identical repeats. The amino-acid sequence evolution in single repeats admits detailed balance, therefore single repeat sequences are at equilibrium, modulo subleading interactions with their neighbors through I in [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF]. As far as multirepeat sequences go, if timescales to separate t d t p >> 1 then duplications and deletions give time to the mutation process to equilibrate. In this case we can assume P(σ|N r ) = P(σ), and P(σ, N r ) = P(σ)P(N r ), therefore dP(N r ,σ) dt = P(σ) dP(N r ) dt + P(N r ) dP(σ) dt where dP(σ) dt 0. Summing over all possible σ we recover the Master Equation ( 115) (for k = 1). For t d t p → ∞ microscopic detailed balance is restored and P(σ|N r ) → (1/Z N r )e -E Nr (σ) .

c.3 numerical simulations

In order to simulate our model we use a Metropolis-Hastings Monte Carlo scheme both for changes in array length and in sequence. Therefore we start from a random amino-acid sequence and we produce point mutations with rate µ p = 1 per site, one at a time. If a mutation decreases the evolutionary energy [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF] we accept it. Otherwise we accept the mutation with probability e -∆E , where ∆E is the difference of energy between the original and the mutated sequence.

In parallel, we generate duplications and deletion events with rate µ d per repeat, therefore with absolute rate µ d N r , producing a change of array length N o r → N n r . The resulting array is accepted with probability acc(N o r → N n r ) = min 1,

P emp (N n r )N n r P emp (N o r )N o r , (160)
We estimate the order of magnitude of the limiting process of the model as t lim = max (10 t p , t d ). We skip the first 100t lim sequences, and then we add a sequence every t lim to the final ensemble after checking that these conditions are sufficient to reach thermalization and to draw sequences that are uncorrelated in both processes.

The fact that this procedure reproduces the right equilibrium distribution (shown in 35) can be taken as a numerical proof a posteriori that at the very least this computational equilibrium algorithm reproduces the wanted steady state distributions, even though the system is not formally at equilibrium.

c.4 parameters learning

In order to obtain a model that reproduces the experimentally observed site-dependent amino-acid frequencies, f i (σ i ) and correlations between two positions f ij (σ i , σ j ) within a single repeat and between consecutive repeats, we apply a likelihood gradient ascent procedure, starting from an initial guess of the h i (σ i ), and J ij (σ i , σ j ) parameters. In a similar way at the same time we learn t d t p to reproduce the empirical inter-repeat similarity on average, ID emp 1st . At each step, we generate 150000 sequences of variable length through the Metropolis-Hastings Monte-Carlo sampling described in C.3. Once we generated the sequence ensemble, we measure its marginals f model i (σ i ) and f model ij (σ i , σ j ), the latter at most between consecutive repeat pairs, as well as ID emp 1st , and update the parameters of Eq. 117 and t d t p following the gradient of the likelihood, equal to the difference between model and data averages. In order to speed up the inference we add an inertia term to the gradient ascent mimicking acceleration, as described in [START_REF] Goh | Why Momentum Really Works[END_REF].

The local field is updated as:

h i (σ i ) t+1 ← h i (σ i ) t + m [f i (σ i ) -f model i (σ i )] + I tot (h i (σ i ) t -h i (σ i ) t-1 ), (161)
As the number of parameters for the interaction terms J ij is large, we impose a sparsity constraint via a L 1 regularization γ ij,σ,τ |J ij (σ, τ)| added to the likelihood. This leads to the following rules of maximization: If J ij (σ i , σ j ) t = 0 and |f ij (σ i , σ j ) -

f model ij (σ i , σ j )| < γ J ij (σ i , σ j ) t+1 ← 0. (162)
If J ij (σ i , σ j ) t = 0 and |f ij (σ i , σ j ) -

f model ij (σ i , σ j )| > γ J ij (σ i , σ j ) t+1 ← j [f ij (σ i , σ j ) -f model ij (σ i , σ j )- γsign(f ij (σ i , σ j ) -f model ij (σ i , σ j ))]. (163)
If J ij (σ i , σ j ) t + j [f ij (σ i , σ j ) -f model ij (σ i , σ j ) -γsign(J ij (σ i , σ j ) t )] J ij (σ i , σ j ) t 0 J ij (σ i , σ j ) t+1 ←J ij (σ i , σ j ) t + j [f ij (σ i , σ j ) -f model ij (σ i , σ j ) -γsign(J ij (σ i , σ j ) t )] + I tot (J ij (σ i , σ j ) t -J ij (σ i , σ j ) t-1 ).

(

) 164
If J ij (σ i , σ j ) t + j [f ij (σ i , σ j ) -f model ij (σ i , σ j ) -γsign(J ij (σ i , σ j ) t )] J ij (σ i , σ j ) t < 0 J ij (σ i , σ j ) t+1 ← 0.

(

) 165
The times ratio parameter t r = t d t p is updated according to: To estimate the model error, we compute f i (σ i ) -f model i (σ i ), f ij (σ i , σ j )f model ij (σ i , σ j ). We repeat the procedure above until the maximum of all errors, |f i (σ i ) -f model i (σ i )|, |f ij (σ i , σ j ) -f model ij (σ i , σ j )| , goes below 0.004. The order of magnitude of this threshold value is motivated by the finite size effects from the number of samples in our dataset. The empirical frequencies can be thought as the frequencies of the result of N s Bernoulli trials (each of this trials draws the symbols in a sequence of our sample), and therefore they are distributed according to a multinomial distribution parametrized by some underlying true distribution p(σ). The standard deviation of these measured frequencies will be of order O( 1 √ N s

) that for example for the ∼ 420000 repeats in our dataset is ∼ 0.002, therefore on the same order of magnitude of our threshold. Moreover we require that | ID Using this procedure we calculate the model defined in Eq. 117 with different interaction ranges W for the couplings J ij , exactly as we did in [START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF]. We start from the independent model h i (σ i ) = log f i (σ i ). We first learn the model in Eq. 117 with J = 0, that consists of just learning t r . We then relearn models with interactions between sites i, j along the linear sequence such that |i -j| W, in a seeded way starting from the previous model. We progressively increase W until we reach the full repeat pairs model, W = 66.

The optimization parameters were set to ID = 0.5, and γ = 0.0003, while m ∈ [0.1, 1], j ∈ [0.05, 1], and I tot ∈ [0.7, 0.95] were tuned ad-hoc as a function of W, the first two in a decreasing fashion.

The most important novel feature of this learning procedure is to learn the parameters in [START_REF] Marcotte | A census of protein repeats11Edited by[END_REF] all together with the dupdel timescale t r , for these two classes of parameters are coupled. Fig. S11 shows that the more constraints are included in the evolutionary energy (larger W), the slower the inferred dupdel process with respect to mutations (larger t r ).

c.5 energy gauge for contacts prediction

In figure 40 we used the evolutionary energy couplings J ij to predict contacts. In order to do that we had to give an absolute unambiguous interpretation to such couplings, by fixing a gauge for the evolutionary energy. We adopted a generalization of the widely used zero-sum gauge [START_REF] Cocco | Inverse statistical physics of protein sequences: a key issues review[END_REF] to a case where the sequence length is not fixed and the energy must keep a discrete repeat translational invariance. In this gauge, sequences of random amino-acids have on average 0 energy.

In practice we impose the condition

to the couplings in I i,i+1 . The transformation we applied to the terms in E 1 reads:

hi (σ i ) = h i (σ i ) -1 q a h i (a) + 1 2q

j =i b J ij (σ i , b) + a J ji (a, σ i ) - 2 q a,b J ij (a, b) , (169)
Jij (σ i , σ j ) = J ij (σ i , σ j ) -1 q a J ij (a, σ j ) -

1 q b J ij (σ i , b) + 1 q 2 a,b J ij (a, b), (170)
whereas the inter-repeat couplings in I i,i+1 are transformed as:

Jij (σ i , σ j ) = J ij (σ i , σ j ) - 1 q 2 a,b J ij (a, b). (171)
This parameters transformation shifts E 1 (σ) only by an additive constant C 1 , and the interaction term I i,i+1 (σ i , σ i+1 ) by another constant C 2 , producing the energy E N r (σ| h, J) = E N r (σ|h, J) + N r C 1 + (N r -1)C 2 ∀σ, with

C 1 = 1 q i a h i (a) + 1 2q 2 i,j a,b J ij (a, b), (172)
and [START_REF] Igor | Antigenic evolution of viruses in host populations[END_REF] and recover the empirical length distribution as steady state. In practice in the numerical implementation we estimate these ensemble averages as temporal averages of the last 1000 sequences sampled every t lim /100 by our evolutionary model. Note that these length conditioned ensemble averages •|N r appear because the dupdels rate here explicitly couple sequence and length. Therefore before marginalizing [START_REF] Paul A Rota | Lineages of Influenza Type B Virus since 1983[END_REF] we could not assume P(N r , ID) = P(N r )P(ID) as in the previous sections.

C 2 = 1 q 2 i,

c.6.1 Asymmetric duplications and deletions

In the asymmetric model presented in 7.4.3, when γ is large enough, the model produces bimodal patterns both in energy (fig. S12) and similarity (fig. S13), due to a sharp transition between short, high energy, low similarity This panel stresses further the nature of the bimodality. C) Average similarity conditioned to the array length, as a function of the array length. This model (green) produces a transition from low similarity short arrays to highly similar long arrays, which is more drastic than the one observed in data (red). D) Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics is also conditioned on arrays of at least 10 repeats. Both data (red) and model generated arrays (green) are roughly constant with neighborhood, but the model produces much higher similarities, as an effect of the transition in C). This was the result of a simulation producing 50000 sequences, with parameters t r = 50, p 1 = 0.7, g 0 = 0.1, γ = 3.

arrays and long, low energy, similar arrays. In addition fig. S13D shows that this model is able to reproduce the constant trend of similarity with interrepeat distance, albeit with much higher values.

Figure S14 shows the result of exploring the model parameters t r = 1 µ r and p 1 . The dependence of summary statistics on the model parameters is less smooth, probably because we fixed two of the four free model parameters close to the transition to the bimodal regime, but the transition likely depends on all four parameters coupled in a non-linear way. But we can still appreciate that the increase in similarity with array length is captured for some parameters, while the decay with neighborhood is always too big.

c.7 duplication bursts rates from model definition

Here we explicitly write the matrix T characterizing the Markov chain of the model defined in sec. 7.5.1, and we derive some constraints on the parameters following the steady state condition of eq. [START_REF] Mayer | How a well-adapting immune system remembers[END_REF].

We can write the transition matrix as

T =               -N
              (177)
Evolution constrains organism diversity through natural selection.

Here we build theoretical models to study the effect of evolutionary constraints on two natural systems at different scales: viral-immune coevolution and protein evolution.

First we study how immune systems constrain the evolutionary path of viruses which constantly try to escape immune memory updates. We start by studying numerically a minimal agent based model with a few simple ingredients governing the microscopic interactions between viruses and immune systems in an abstract framework. These ingredients couple processes at different scales -immune response, epidemiology, evolution -that all together determine the evolutionary outcome. We find that the population of immune systems drives viruses to a set of interesting evolutionary patterns, which can also be observed in nature. We map these evolutionary strategies onto model parameters.

Then we study a coarse-grained theoretical model for the evolution of viruses and immune receptors in antigenic space consisting of a system of coupled stochastic differential equations, inspired by the previous agent-based simulations. This study sheds light on the interplay between the different scales constituting this phylodynamic system. We obtain some analytical insights into how immune systems constrain viral evolution in antigenic space while viruses manage to sustain a steady state escape dynamics. We validate the theoretical predictions against numerical simulations.

In the second part of this work we exploit the enormous amount of protein sequence data to extract information about the evolutionary constraints acting on repeat protein families, whose elements are proteins made of many repetitions of conserved portions of amino-acids, called repeats. We couple an inference scheme to computational models, which leverage equilibrium statistical mechanics ideas to characterize the macroscopic observables arising from a probabilistic description of protein sequences.

We use this framework to address how functional constraints reduce and shape the global space of repeat protein sequences that survive selection. We obtain an estimate of the number of accessible sequences, and we characterize quantitatively the relative role of different constraints and phylogenetic effects in reducing this space. Our results suggest that the studied repeat protein families are constrained by a rugged landscape shaping the accessible sequence space in multiple clustered subtypes of the same family.

Then we exploit the same framework to address the interplay between evolutionary constraints and phylogenetic correlations in repeat tandem arrays. As a result we infer quantitatively the functional constraints, together with the relative timescale between repeat duplications/deletions and point mutations. We also investigate and map what microscopic evolutionary mechanisms can generate specific inter-repeats statistical patterns, which are recurrently observed in data. Preliminary results suggest that evolution of repeat tandem arrays is strongly out of equilibrium.

  v P U B L I C AT I O N S This PhD thesis presents the research work I have conducted in the past four years at the Laboratoire de Physique de l'Ecole Normale Superieure, under the supervision of Aleksandra Walczak and Thierry Mora. It includes published as well as ongoing work.

3 . 3 1 . 1 1 . 2 1 . 3 1 . 4 1 . 5 1 . 6

 33111213141516 Phylogenetic tree analysis 146 b size and structure of the sequence space of repeat proteins: supplementary information 151 b.1 Methods 151 b.Data curation 151 b.Model fitting 151 b.Models with different sets of constraints 153 b.Entropy estimation 154 b.Entropy error 154 b.Calculating the basins of attraction of the energy landscape 156 xiv contents b.1.7 Kullback-Leibler divergence 157 c evolutionary model for repeat arrayssupplementary information 165 c.1 Dataset 165 c.2 Quasi-equilibrium 165 c.3 Numerical simulations 166 c.4 Parameters learning 167 c.5 Energy gauge for contacts prediction 169 c.6 Similarity dependent dupdel rates 170 c.6.1 Asymmetric duplications and deletions 171 c.7 Duplication bursts rates from model definition 173 bibliography 1

Figure 1 -

 1 Figure 1 -Viruses and immune receptors embedded in a 2D recognition spaceViruses and immune receptors can be thought as points in an abstract recognition space -in ths case 2D. Viruses can mutate with some rate µ by jumping in a random direction. The jump length is drawn from some distribution of mean σ. The cross-reactivity kernel, here taken to be an exponential function H(r, d) = exp(-r d ), determines the probability that a virus is recognized by a receptor at distance r (shaded area). The dimensionless raio σ/d controls the ability of viruses to escape immunity.

Figure 3 -

 3 Figure 3 -A paradigmatic example for noisy traveling waves are fitness waves arising in simple models of evolution The colored particles represent individuals with characteristic growth rates, or fitnesses (horizontal axis).Individuals can mutate, replicate ("birth"), and be eliminated from the gene pool ("death"), as illustrated. These simple dynamical rules give rise to a distribution of growth rates resembling a bell-like curve at steady state, which propagates toward higher growth rates like a solitary wave. Figure and caption from [82].

  Figure 3 -A paradigmatic example for noisy traveling waves are fitness waves arising in simple models of evolution The colored particles represent individuals with characteristic growth rates, or fitnesses (horizontal axis).Individuals can mutate, replicate ("birth"), and be eliminated from the gene pool ("death"), as illustrated. These simple dynamical rules give rise to a distribution of growth rates resembling a bell-like curve at steady state, which propagates toward higher growth rates like a solitary wave. Figure and caption from [82].

Figure 4 -

 4 Figure 4 -Phenotypic space and key ingredients of the evolutionary model. Dur-ing an infection, a virus attempts to infect on average R 0 hosts, however not all infections are successful. The immune repertories of some hosts can clear the virus (case of host 3) since their cross-reactivity kernels from existing memory receptors confer protection. However if the host does not have protection against the infecting virus (case of host 2), the host becomes infected. After the infection this host acquires immunity against the infecting virus. Since the virus can mutate within a given host (host 1), the infecting virus can be a mutated variant (case of host 2) with probability P mut = 1 -e -µt I and the ancestral strain that infected host 1 with rate 1 -P mut = e -µt I (case of host 3). The cross-reactivity kernel is taken to be an exponential function f(r) = exp(-r d ), meaning that viruses are recognized by receptors if they are closer in phenotypic space. Jumps are in a random direction and their size is distributed according to a Gamma distribution of mean σ and shape parameter 2. The dimensionless ratio σ/d controls the ability of viruses to escape immunity. We assume no selection within one host.

Figure - Figure -

 -- Figure -Modes of antigenic evolution: A) ballistic regime, B) diffusive regime, C) transient splitting regime, and D) stable splitting regime. (i): examples of trajectories of the population in phenotypic space (in units of d); (ii): the time to most recent common ancestor (TMRCA); (iii): phylogenetic tree of the population across time. In (iii) we give the mean TMRCA for the plotted sample trees. When viruses evolve in a single lineage the phylogenetic tree show a single trunk dominating evolution. When viruses split into more lineages, the phylogenetic tree shows different lineages evolving independently. Each lineage diffuses in phenotypic space with a persistence length that depends itself on the model parameters. In these simulations viral population size is not constrained, but parameters are tuned to approach a target fraction of infected hosts, fi = 10 -3 . Parameters are A) µ = 10 -3 , σ/d = 10 -2 , B) µ = 10 -2 , σ/d = 3 • 10 -4 C) µ = 10 -2 , σ/d = 3 • 10 -3 , D) µ = 0.1, σ/d = 10 -4 .

Figure 7 -

 7 Figure 7 -Phase diagram of the single-to multiple lineage transition as a function of mutation rate µ, mutation jump size σ, and fi . (A) Average number of lineages, (B) fraction of time where viruses are organized in a single lineage (C) rate of lineage splitting (per lineage), and (D) average coalescence time. In these simulations viral population size is not constrained, and the target fraction of infected individuals fi is 5 • 10 -4 , 8 • 10 -4 , 10 -3 , 1.2 • 10 -3, from left to right , (panels i to iv). For each parameter point we simulated 100 independent realizations.

Figure 8 -

 8 Figure 8 -The average number of viruses is proportional to the number of independent clusters. The total number of viruses (green curve) and of lineages (red curve) as a function of time for fi = 10 -3 , µ = 10 -2 , σ/d = 3 • 10 -3 . The initial single lineage splits into two lineages at t ≈ 59 years and then into three lineages at t ≈ 67 years (dashed vertical lines), and the number of viruses first doubles and then triples following the lineage splittings.

4 AFigure 9 -

 49 Figure 9 -Speed of adaptation and the within-cluster diversity. Phase diagrams as a function of mutation rate µ and mutation jump size σ for (A) the average speed of the evolving viral lineages and (B) the variance of the size of the cluster in the direction parallel to the direction of instantaneous mean adaptation for different values of the target infected fraction fi = 5 • 10 -4 , 8 • 10 -4 , 10 -3 , and 1.2 • 10 -3 from left to right, (panels i to iv). For each parameter point we simulated 100 independent realizations.

Figure 10 -

 10 Figure 10 -Turn rate. Phase diagrams as a function of mutation rate µ and mutation jump size σ for rate of turns (defined as a change of direction of at least 30 degrees) of the trajectories, for different values of the mean number of infected individuals fi : 5 • 10 -4 , 8 • 10 -4 , 10 -3 , 1.2 • 10 -3 , from left to right, (panels i to iv).

2 Figure 11 -

 211 Figure 11 -Effect of phenotypic space dimensionality on viral evolution. Cumulative average number of neighbours of a given viral strain as a function of phenotypic distance r to that strain for fi = 10 -3 , µ = 10 -2 , σ/d = 3 • 10 -3 . The average number of neighbours depends on the dimension of the phenotypic space as r D where r is the distance and D = 2 the dimension of phenotypic space (dotted line).

Figure 12 -

 12 Figure 12 -Phase diagram for the detailed intra-host mutation model. As a function of the mutation rate µ and mutation jump size σ we plot (A) the mean number of co-existing lineages, (B) the fraction of time with one lineage, (C) the lineage splitting rate and (D) the lineage turn rate. In these simulations viral population size is not constrained, and fi = 10 -3 . For each parameter point we simulated 100 independent realizations.

Figure 13 -

 13 Figure 13 -Phase diagram for speed of adaptation and within cluster diversity of the detailed intra-host mutation model. As a function of the mutation rate µ and mutation jump size σ we plot (A) the mean speed of adaptation, and (B) the variance in the cluster size in the direction parallel to the direction of motion. In these simulations viral population size is not constrained, and fi = 10 -3 . For each parameter point we simulated 100 independent realizations.

Figure 14 -

 14 Figure 14 -Viruses escape the immune systems chase in antigenic space Example of viruses and immune systems disposition in phenotypic space. (A) The immune receptor density N h h (blue colormap) form a long memory trace chasing behind the viruses (red colormap) that form a very compact blob. (B) Inset around the viral population. The viral density n (red colormap) coherently travels quasi-linearly to escape the immune coverage (the arrow represents the direction of motion. The isolines (drawn only where n > 0) portrait the (almost) linear immunegenerated fitness landscape, that drives viral evolution. The transition between continuous and dashed isolines pinpoints the f = 0 curve. The black dots are the top 2% viral strains. The two relevant scale of the antigenic space (in units of δ ), the recognition scale r and the immune memory scale vτ (calculated from eq. (55)), are given for reference. Simulation parameters are µ = 10 -2 , r = 2000, N h = 10 8 , F 0 = 3 and M = 1.

Figure 15 -

 15 Figure 15 -Modes of antigenic evolution. Examples of average trajectories of the viral population in phenotypic space. Also this model produces different evolutionary patterns with viruses that either evolve in a single compact lineage (A) or split into more independent lineages evolving independently (B). Each lineage diffuses in phenotypic space with a persistence length that depends itself on the model parameters. Simulation parameters are A) µ = 10 -4 , r = 70, N h = 10 8 , F 0 = 1 and M = 1, B) µ = 10 -2 , r = 100, N h = 10 8 , F 0 = 1 and M = 5 .

Figure 16 -

 16 Figure 16 -Phase diagram of different observables as a function of mutation rate µ and mutation jump size δ in units of the cross reactivity scale r. (A) Mean viral extinction time (years), (B) mean time (years) the viral population takes to reach N h ("explode") (C) rate of lineage splitting (per lineage), and (D) fraction of time where viruses are organized in a single lineage. Lines are interpolated isolines of the observables. Other simulation parameters are N h = 10 10 , F 0 = 1 and M = 1.

F0 1 . 0 , 12 F0 3 . 0 ,Figure 17 -

 10123017 Figure 17 -Theoretical predictions are accurate for all simulated parameters Numerical check of theoretical predictions. Each point corresponds to agiven parameters set specified in the legend (apart from r that also varies). Antigenic space is measured in units of δ , time is measured in years unless otherwise specified. The gray line represents the identity. On the x-axis the average of the observables time-series estimated on simulation results, on the y-axis the theoretical prediction for that observable given the parameters. A) The strength of selection s (theory predicts eq. (54)). B) The scale of the immune memory trace behind viruses in antigenic space vτ (theory predicts eq. (55)). In all these simulation M = 1.

F0 1 . 0 ,

 10 N h 10 8 F0 1.0, N h 10 10 F0 1.0, N h10 12

F0 3 . 0 ,

 30 N h 10 8 F0 3.0, N h 10 10 F0 3.0, N h 10

F0 1 . 0 , N h 10 8 F0 1 . 0 , N h 10 10 F0 1 . 0 , N h 10 12 F0 3 . 0 , N h 10 8 F0 3 . 0 , N h 10 10 F0 3 . 0 ,

 10810101012308301030

Figure 19 -

 19 Figure 19 -The traveling wave theory prediction for the stable population size is accurate when mutations are frequent Numerical check of theoretical predictions. Each point corresponds to a given parameters set specified in the legend (apart from r that also varies). Antigenic space is measured in units of δ , time is measured in years unless otherwise specified. On the x-axis the average of the time-series of the number of viruses N from the simulation results. On the y-axis the numerical solution of the transcendental equation. (63) derived from the traveling wave theory, given the parameters. The gray line represents the identity. In all these simulation M = 1.

F0 1 . 0 ,

 10 N h 10 8 F0 1.0, N h 10 10 F0 1.0, N h10 12

F0 3 . 0 ,

 30 N h 10 8 F0 3.0, N h 10 10 F0 3.0, N h 10

Figure 20 -

 20 Figure 20 -Viral lineages are concentrated in elliptical blobs in antigenic space.On the x-axis the standard deviation of the lineage density profile in antigenic space in the direction of motion σ multiplied by √ 1.7, on the y-axis the standard deviation of the lineage density profile in antigenic space in the direction perpendicular respect to that of motion σ ⊥ . σs are measured in units of δ for each lineage separately. Each point is the average of the observables time-series for a given parameters set, specified in the legend (apart from r that also varies). The gray line represents the identity. In all these simulation M = 1.

  A L E S : P R O T E I N S , E V O L U T I O N A N D S TAT I S T I C A L P H Y S I C S S TAT I S T I C A L P H Y S I C S F O R P R O T E I N S E Q U E N C E S5.1 background and motivation

Figure 22 -

 22 Figure 22 -Repeat proteins are formed with tandem arrays of repeats, and fold into characteristic accordeon-like folds with defined contacts in and between repeat. The crystal structures of members of different repeat protein families are shown, with the backbone colored according to the repeated units. The molecular surface of the repeat array is drawn in transparent gray. A) ANK family (PDB:1IKN, chain D), B) WD40 family (PDB:1ERJ, chain A), C) TPR family (PDB:4GCO), D) LRR family (PDB:4NKH, chain A), E) ANEX family (PDB:2ZOC, chain A), F) PUF family (PDB:2YJY, chain A), G) HEAT family (PDB:4G3A, chain A), and H) ARM family (PDB:2BCT). Figure from [51]

Figure 23 -

 23 Figure 23 -Repeat proteins show global sequence similarity between repeats, related to inter-repeat phylogeny. This similarity can be quantified as the number of matches between two repeats amino-acid sequences.

Figure 24 -

 24 Figure 24 -Evolution enforces local functional constraints on amino-acid sequences that shape the accessible proteins sequence space. A) These constraints drastically reduce the size of accessible sequence space. It is reasonable to assume that we know only a subsample of this accessible space.B) The local constraints also make the "evolutionary energy landscape" rugged, with local minima, where proteins sequences can get stuck during the evolutionary process, of which the coarse-grained partition into families is a first exampled. The set of sequences that evolve to a given local minimum defines the basin of attraction of that minimum. Panel B from[START_REF] Marchi | Size and structure of the sequence space of repeat proteins[END_REF]

Figure 25 -Figure 26 -

 2526 Figure 25 -Empirical patterns from ANK repeat array statistics. A) Probability distribution of number of repeats in an array. B) Probability distribution of 1st neighborhood (consecutive) repeat similarity. C) Average similarity between 1st neighborhood repeats conditioning on the number of repeats in an array, as a function of the number of repeats. Repeats are more similar in longer arrays. Error bars are standard errors. C) Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics, which shows a clear saw-like trend, is also conditioned on arrays of at least 10 internal repeats. Error bars are standard errors.

Figure 27 -

 27 Figure 27 -Repeat proteins fold into characteristic accordeon-like folds. Example structures of three protein families are shown, ankyrin repeats (ANK), tetratricopeptide repeats (TPR), leucine-rich repeat (LRR), with the repeating unit highlighted in magenta. All show regular folding patterns with defined contacts in and between repeats.

S 1 2 Figure 28 -

 1228 Figure28-Contributions of within-repeat interactions (S 1 -S ir green), repeatrepeat interactions (S ir,--S full , purple), and phylogenic bias between consecutive repeats (S ir -S ir,-, blue), to the entropy reduction from an independent-site model. All three contributions are comparable, but with a larger effect of within-repeat interactions and phylogenic bias in TPR. The fourth bar (orange) quantifies the redundancy between two constraints with overlapping scopes: the constraint on consecutiverepeat similary, and the constraint on repeat-repeat correlations. This redundancy is naturally measured within information theory by the difference of impact (i.e. entropy reduction) of a constraint depending on whether or not the other constraint is already enforced.

Figure 29 -

 29 Figure 29 -Entropy reduction as a function of the range of interactions between residue sites. A) Entropy of two consecutive ANK repeats, as a function of the maximum allowed interaction distance W along the linear sequence. The entropy of the model decreases as more interactions are added and they constrain the space of possible sequences. After a sharp initial decrease at short ranges, the entropy plateaus until interactions between complementary sites in neighbouring repeats lead to a secondary sharp decrease at W = L -1 = 32 (dashed line), due to structural interactions between consecutive repeats. B) Entropy of two consecutive ANK repeats as a function of the maximum allowed threedimensional interaction range. The entropy decreases rapidly until ∼ 10 Angstrom, after which decay becomes slower. In both panels entropies are averaged over 10 realizations of fitting the model; see section B.1.3 and for details of the learning and entropy estimation procedure. Error bars are estimated from fitting errors between the data and the model; see Sec. B.1.5 and Fig. S5 for error bars calculated as standard deviations over 10 realizations of model fitting.

Figure 30 -

 30 Figure 30 -A rugged energy landscape is characterized by the presence of local minima, where proteins sequences can get stuck during the evolutionary process. The set of sequences that evolve to a given local minimum defines the basin of attraction of that mimimum.

Figure 31 -

 31 Figure 31 -Interactions within and between repeats sculpt a rugged energy landscape with many local minima. Local minima were obtained by performing a zero-temperature Monte-Carlo simulation with the energy function in Eq. (106), starting from initial conditions corresponding to naturally occurring sequences of pairs of consecutive ANK repeats. A, bottom) Rank-frequency plot of basin sizes, where basins are defined by the set of sequences falling into a particular minimum. A, top) energy of local minima vs the size-rank of their basin, showing that larger basins often also have lowest energy. Gray line indicates the energy of the consensus sequence, for comparison. B) Pairwise distance between the minima with the largest basins (comprising 90% of natural sequences), organised by hierarchical clustering. The panel right above the matrix shows the size of the basins relative to the minima corresponding to the entries of the distance matrix. A clear block structure emerges, separating different groups of basins with distinct sequences. C-D) Same as A) and B) but for single repeats.Since single repeats are shorter than pairs (length L instead of 2L), they have fewer local energy minima, yet still show a rich multi-basin structure. Equivalent analyses for LRR and TPR are shown in Figs. S7 and S8.

Figure 32 - 25 Figure 33 -Figure 34 -

 32253334 Figure 32 -Empirical patterns from ANK repeat array statistics. A) Probability distribution of number of repeats in an array. B) Probability distribution of 1st neighbor (consecutive) repeat similarity. C) Average similarity between 1st neighbor repeats conditioning on the number of repeats in an array, as a function of the number of repeats. Repeats are more similar in longer arrays. Error bars are standard errors. D) Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics, which shows a clear saw-like trend, is also conditioned on arrays of at least 10 internal repeats. Error bars are standard errors. This is the same figure as 25

emp 1st -Figure 35 -

 1st35 Figure 35 -The inferred model reproduces the desired empirical statistics. A) Probability distribution of number of repeats in an array, data in red and model generated sequences in green. B), C), D) Scatter plot between the empirical and model generated 1 site marginal amino-acid frequencies, 2 site joint amino-acid frequencies within the same repeat, 2 site joint amino-acid frequencies between consecutive repeats, respectively. The color map represents points density (yellow higher density).

Figure 36 -

 36 Figure36-Scatter plot between the empirical and model generated 3 sites joint amino-acid frequencies, the color map represents points density (yellow higher density). The model reproduces well higher order statistics that were not used for fitting.

Figure 37 -

 37 Figure 37 -Average rescaled array energy conditioned to the array length, as a function of the array length. The model captures the global qualitative trend and reproduces the energies of short arrays, which constitute most of the dataset. It does not reproduce the fact that the few larger arrays have a systematic lower evolutionary energy. Error bars are standard errors.

Figure 38 -

 38 Figure 38 -Probability distribution of the first neighbors repeats similarity ID 1st .The model (blue), inferred constraining its average, reproduces the whole empirical distribution (green).

Figure 39 -

 39 Figure 39 -Reduced χ 2 score between the empirical and model generated similarity distributions between consecutive repeats, as a function of the interaction range W below which J ij couplings are non-zero. Only short range couplings are necessary to reproduce well the distribution.

∼ 79 .

 79 This gives us a rough estimate that, given the evolutionary constraints of the ANK family inferred in our model, post-selection duplications are two orders of magnitude slower than mutations, per repeat.

Figure 40 -

 40 Figure 40 -Comparison between the contact map of a pair of repeats of 1N0R (gray shadow), where we define contacts as sites where heavy atoms are closer than 6Å, and the i, j for which the couplings J(•, •) have highest Frobenius norm (red crosses). Most of the highest couplings sites pairs fall into residues in contact or in the equivalent position of a repeat.

Figure 41 -

 41 Figure 41 -Comparison between empirical and model generated patterns A) Average similarity between 1st neighbor repeats conditioning on the number of repeats in an array, as a function of the number of repeats. In data (red) repeats are more similar in longer arrays, whereas the model (green) produce a much weaker dependence on the array length. Error bars are standard errors. B) Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics is also conditioned on arrays of at least 10 repeats. Data (red) show a clear saw-like trend, that is completely absent in the model generated arrays (green) which decay monotonically to a significantly lower baseline. Error bars are standard errors.

Figure 42 -

 42 Figure 42 -Comparison between empirical and model generated patterns, for time ratio t r = 16 and p 1 = 0.4 Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics is also conditioned on arrays of at least 10 repeats. Data (red) show a clear saw-like trend, that is qualitatively reproduced in the model generated arrays (green) which decay to a significantly lower baseline. Error bars are standard errors.

Figure 43 -

 43 Figure 43 -Exploration of the model behavior with respect to the time ratio parameter t r and the probability of dupdel a single repeat p 1 . In each simulation we draw 50000 independent sequences from the model evolutionary dynamics. A) Increase of consecutive repeat similarity with array length, quantified by ID 1 |N r = 11 -ID 1 |N r = 2 , as a function of model parameters. No parameters set approaches the empirical value in fig. 32C (horizontal dashed grey line). B) Decay of repeat similarity with neighborhood, quantified by ID 2 |N r > 10 -ID 4 |N r > 10 , as a function of model parameters. No parameters set approaches the empirical value in fig. 32D (horizontal dashed grey line).

1 Figure 44 -

 144 Figure 44 -Exploration of the model behavior with respect to the time ratio parameter t r and the probability of dupdel a single repeat p 1 . In each simulation we draw 50000 independent sequences from the model evolutionary dynamics. Scalar score evaluating how well each of the parameters set reproduces each point in fig. 32 C and D.

Figure 45 -

 45 Figure 45 -Visualization of similarity dependent duplications. Duplications of single (above) or pairs (below) of repeats happen with rate µ d p k G [r,r+k) (ID [r,r+k) k ) with k = 1, 2, that depends on the similarity of the repeated units with the kth neighbor repeat, ID [r,r+k) k

Figure 46 -

 46 Figure 46 -Exploration of the model behavior with respect to the time ratio parameter t r and the probability of dupdel a single repeat p 1 . In each simulation we draw 50000 independent sequences from the model evolutionary dynamics, with γ = 3, and g 0 = 0.1. A) Increase of consecutive repeat similarity with array length, quantified by ID 1 |N r = 11 -ID 1 |N r = 2 , as a function of model parameters. Now we can match the empirical value in fig. 32C (horizontal dashed grey line) in whole range of parameters. B) Decay of repeat similarity with neighborhood, quantified by ID 2 |N r > 10 -ID 4 |N r > 10 , as a function of model parameters. No parameters set approaches the empirical value in fig. 32D (horizontal dashed grey line).

  correspond to parameters giving scores close to the minimum. Note how both these model score better than the χ = 1200 minimum of sec. 7.4.1.

Figure 47 -

 47 Figure 47 -Comparison between empirical and model-generated patterns A) Average similarity between 1st neighbor repeats conditioning on the number of repeats in an array, as a function of the number of repeats. In data (red) repeats are more similar in longer arrays, and the asymmetric model (green) gives a similar trend both in scale and shape, whereas the symmetric model (blue) matches in strength the initial dependence on the array length, but reaches a plateau at longer arrays. Error bars are standard errors. B) Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics is also conditioned on arrays of at least 10 repeats. Data (red) show a clear saw-like trend, that is qualitatively reproduced both in the symmetric (blue) and asymmetric (green) models. The symmetric model decays consistently to a significantly lower baseline, whereas the asymmetric one produce values on the right scale, but the similarity upper-bound still decreases more than the data. Error bars are standard errors. The panels display simulations of the two models from which we sampled 50000 sequences. The parameters of symmetric and asymmetric models are respectively t r = 11, p 1 = 0.4, g 0 = 0.1, γ = 3 and t r = 81, p 1 = 0.45, g 0 = 0.7, γ = 0.7.

Figure 48 -

 48 Figure 48 -Comparison between empirical and model generated patterns A) Average similarity between terminal repeats in the same array conditioning on the number of repeats in an array, as a function of the number of repeats. In data (red) terminals are more similar in longer arrays despite being farther away. The asymmetric model (green) gives a similar trend, whereas the symmetric model (blue) produces less similar terminals that reach a plateau at longer arrays. Error bars are standard errors. The panels display simulations of the two models from which we sampled 50000 sequences. The parameters of symmetric and asymmetric models are respectively t r = 11, p 1 = 0.4, g 0 = 0.1, γ = 3 and t r = 41, p 1 = 0.55, g 0 = 0.7, γ = 0.7.

Figure S1 -

 S1 Figure S1 -Phase diagram for a fixed population size of the single-to multiple lineage transition, as a function of mutation rate µ and mutation jump size σ. The figure is similar to the one presented in the main text in Fig. 7 but assuming a fixed fraction of infected hosts fi = 8 • 10 -4 , 10 -3 , and 1.5 • 10 -3 (from left to right, panels i to iii). (A) Average number of lineages, (B) fraction of time where viruses are organized in a single lineage, (C) rate of lineage splitting, and (D) the average coalescence time.

4 AFigure S2 -

 4S2 Figure S2 -Speed of adaptation and within-cluster diversity. Same phase diagram as in Fig. 9 of the main text but with a constant fixed fraction of infected hosts fi = 8 • 10 -4 , 10 -3 , and 1.5 • 10 -3 (from left to right, panels i to iii). Phase diagrams as a function of mutation rate µ and mutation jump size σ for (A) the average speed of the evolving viral clusters and (B) the phenotypic variance in the direction parallel to the direction of instantaneous mean adaptation.

Figure S3 - 2 C

 S32 Figure S3 -Persistence time. Same phase diagram as in Fig. 10 of the main text but with constant fixed population size fi = 8 • 10 -4 , 10 -3 , and 1.5 • 10 -3 (from left to right, panels i to iii). Phase diagrams as a function of mutation rate µ and mutation jump size σ for rate of turns of the trajectories.

Figure S4 - 1 . 1

 S411 Figure S4 -Single-to multiple lineage transition a function of rescaled diffusivity µσ 2 . Same quantities as in Fig. 4 of the main text, but as a function of the effecive diffusivity µσ 2 , showing absence of collapse as a function of that parameter for various values of the mutation rate µ. (A) Average number of lineages, (B) fraction of evolution time where viruses are organized in a single lineage, (C) rate of lineage splitting (per lineage), and (D) average coalescence time.

Figure S5 -Figure S6 -Figure S7 -Figure S8 -Figure S9 -

 S5S6S7S8S9 Figure S5 -Reproducibility of entropy estimation. Entropy as a function of the maximum linear interaction range W along the sequence. Green curve: entropy of the ANK family with error bars calculated as standard deviations over 10 model learning realizations, where models are learned by incrementally adding more interaction terms as W is increased, taking the model learned at W -1 as initial condition. This plot is the same as in Fig. 29A but with the different error bar estimates, showing that our results are robust to the details of error estimation. Red curve: entropy obtained after de novo learning for each W, starting from a non-interacting model as initial condition. With those initial conditions the learning gets stuck, leading to systematically overestimating the entropy and missing the second entropy drop at W = L -1. See section B.1.3 for details of the learning and entropy estimation procedure.

Figure S10 -

 S10 Figure S10 -Analysis of local energy minima from generated pairs of consecutive repeats of ANK. Energy minima were obtained by zero-temperature dynamics starting from sequences generated in silico from E full . Sequences falling into a given minimum with these dynamics define its basin of attraction. A, bottom) rank-frequency plot of the sizes of the basins of attraction. A, top) energy minimum of each basin. Gray line shows the energy of the consensus sequence B) Pairwise Hamming distances between energy minima, organised by hierarchical clustering. The panel right above the matrix shows the the size of the basins relative to the minima corresponding to the entries of the distance matrix. C and D) Same analysis as A) and B), but for single ANK repeats.

  reads:dP(N r , σ) dt = k ((P(N r -k, σ )F(N r -k) + P(N r + k, σ )F(N r + k))S(N r )µ d p k --P(N r , σ)F(N r )(S(N r -k) + S(N r + k))µ d p k )

Figure S11 -

 S11 FigureS11-Inferred pre-selection ratio between duplication and mutation times t r , as a function of the interaction range W below which J ij coupling are non-zero. The more constraints are included in the evolutionary energy, the slower the dupdel process needs to be to reproduce ID emp 1st .

1 ,

 1 and this other threshold scale is derived from the empirical difference between first and second neighbors similarity | ID emp 1st -ID emp 2nd | = 0.4.

a

  hi (a) = a Jij (a, σ j ) = b Jij (σ i , b) = 0 ∀i, j, σ i , σ j ,(167)to the terms in E 1 , anda,b Jij (a, b) = 0 ∀i, j,

  j a,b J ij (a, b).(173)c.6 similarity dependent dupdel ratesThe full master equation of the model where dupdel rates depend on similarity, introduced in 7.4.2, reads:dP(N r , ID) dt = k N r -k r P(N r -k, ID)G [r,r+k) r + k, ID)G [r,r+k) (ID [r,r+k) k ) S(N r )µ d p k -P(N r , ID)F(N r )(S(N r -k) + S(N r + k))µ d p k canuse to our advantage the fact that mutations happen fast and sequences almost thermalize to P(σ). Using ID dP(N r ,ID) dt = dP(N r )dt and assuming that the distribution of similarity P(ID) does not depend on the location of the repeats in the array (repeat-translational invariance) we can write:r -k)G [r,r+k) r + k)G [r,r+k) (ID [r,r+k) k ) S(N r )µ d p k -P(N r )F(N r )(S(N r -k) + S(N r + k)) µ d p k N r r ID P(ID|N r )G [r,r+k) (ID [r,r+k) k r -k) G [r,r+k) (ID k )|N r -k + N r +k r P(N r + k) G [r,r+k) (ID k )|N r + k S(N r )µ d p k -P(N r )F(N r )(S(N r -k) + S(N r + k)) µ d p k N r r G [r,r+k) (ID k )|N r (175)where the notation •|N r indicates that the average is taken over the (steady state) ensemble of arrays of length N r .

Figure S12 -

 S12 Figure S12 -The similarity dependent dupdel model, in the asymmetric case, can produce bimodal patterns in the evolutionary energy. A) Probability distribution of number of repeats in an array, data in red and model generated sequences in green. The computational simulation reproduces the right steady state distribution. B) Average rescaled array energy (as in 37) conditioned to the array length, as a function of the array length. This model (green) produces a transition from high energy short arrays to more stable long arrays, which is more drastic than the one observed in data (red). C) The resulting rescaled energy distribution presents a bimodal pattern, where the lower energy mode is entirely due to the energies of longer arrays, as is clear in D) where all the distributions conditioned on the various length are shown (long arrays towards red in the color map). This was the result of a simulation producing 50000 sequences, with parameters t r = 50, p 1 = 0.7, g 0 = 0.1, γ = 3.

Figure S13 -

 S13 Figure S13 -The similarity dependent dupdel model, in the asymmetric case, can produce bimodal patterns in the ID. A) Bimodal probability distribution of first neighbor similarity. B) Similarity distributions conditioned on different array lengths, long arrays towards red in the color map.This panel stresses further the nature of the bimodality. C) Average similarity conditioned to the array length, as a function of the array length. This model (green) produces a transition from low similarity short arrays to highly similar long arrays, which is more drastic than the one observed in data (red). D) Average similarity between repeats contained in the same array, conditioning on the number of other repeats between them (neighborhood), as a function of the neighborhood. The displayed statistics is also conditioned on arrays of at least 10 repeats. Both data (red) and model generated arrays (green) are roughly constant with neighborhood, but the model produces much higher similarities, as an effect of the transition in C). This was the result of a simulation producing 50000 sequences, with parameters t r = 50, p 1 = 0.7, g 0 = 0.1, γ = 3.

Figure S14 -

 S14 Figure S14 -Exploration of the model behavior with respect to the time ratio parameter t r = 1 µ r and the probability of dupdel a single repeat p 1 . In each simulation we draw 50000 independent sequences from the model evolutionary dynamics, with γ = 0.7, and g 0 = 0.7. A) Increase of consecutive repeat similarity with array length, quantified by ID 1 |N r = 11 -ID 1 |N r = 2 , as a function of model parameters. Now we can match the empirical value in fig. 32C (horizontal dashed grey line) for some parameters. B) Decay of repeat similarity with neighborhood, quantified by ID 2 |N r > 10 -ID 4 |N r > 10 , as a function of model parameters. No parameters set approaches the empirical value in fig. 32D (horizontal dashed grey line).

RÉSUMÉL

  'évolution limite la diversité des organismes par la sélection naturelle. Nous construisons ici des modèles théoriques pour étudier l'effet des contraintes évolutives sur deux systèmes biologiques à des échelles différentes: la coévolution virale-immune et l'évolution des protéines.Nous étudions d'abord comment les systèmes immunitaires limitent le parcours évolutif des virus qui tentent constamment d'échapper aux mises à jour de la mémoire immunitaire. Nous commençons par étudier numériquement un modèle agent-based minimal régissant les interactions microscopiques entre les virus et les systèmes immunitaires dans un cadre abstrait. Ces ingrédients couplent des processus biologiques à différentes échelles -réponse immunitaire, épidémiologie, évolution -qui conjointement déterminent le résultat de l'évolution. Nous constatons que la population des systèmes immunitaires pousse les virus vers un ensemble de motifs biologiquement pertinents. Nous caractérisons ces stratégies évolutives en fonction des paramètres du modèle. Ensuite nous étudions un description à gros grains décrivant l'évolution des virus et des récepteurs immunitaires dans l'espace antigénique. Cette approche consistant en un système d'équations différentielles stochastiques couplées permet de clarifier l'interaction entre les différentes échelles qui constituent ce système phylodynamique. Nous obtenons une description analytique de la façon dont les systèmes immunitaires limitent l'évolution des virus dans l'espace antigénique, alors que les virus parviennent à maintenir une dynamique de fuite en régime permanent. Nous validons les prédictions théoriques à l'aide des simulations numériques.Dans la deuxième partie de ce travail, nous exploitons l'énorme quantité de données accessible sur les séquences protéiques pour extraire des informations sur les contraintes évolutives agissant sur les familles de protéines répétées, constituées de nombreuses répétitions de portions conservées d'acides aminés. Nous couplons un schéma d'inférence à des modèles numériques en nous appuyant sur des idées de mécanique statistique à l'équilibre afin caractériser les observables biologiques découlant d'une description probabiliste des séquences de protéines. Nous utilisons ce cadre pour étudier comment les contraintes fonctionnelles réduisent et façonnent l'espace global des séquences protéiques répétées qui survivent à la sélection. Nous obtenons une estimation du nombre de séquences accessibles, et nous caractérisons quantitativement le rôle relatif des différentes contraintes et des effets phylogénétiques dans la réduction de cet espace. Nos résultats suggèrent que les familles de protéines répétées étudiées sont contraintes par un paysage accidenté qui façonne l'espace des séquences accessibles en plusieurs sous-types groupés de la même famille. Nous exploitons ensuite le même cadre pour étudier l'interaction entre les contraintes évolutives et les corrélations phylogénétiques dans les séries de répétitions. Nous déduisons quantitativement les contraintes fonctionnelles, ainsi que l'échelle de temps relative entre les duplications/suppressions des répétitions et les mutations ponctuelles. Nous étudions et caractérisons également les mécanismes évolutifs microscopiques qui peuvent générer des motifs statistiques spécifiques entre répétitions, observés de manière récurrente dans les données. Les résultats préliminaires suggèrent que l'évolution des séries de répétitions est un processus fortement hors équilibre. MOTS CLÉS Mécanique statistique, Systèmes hors d'équilibre, Évolution, Réponse immunitaire KEYWORDS Statistical mechanics, Out of equilibrium systems, Evolution, Immune response

  Equivalence between two definitions of entropies 98 6.3.4 Entropy of repeat protein families 99 6.3.5 Effect of interaction range 100 6.3.6 Multi-basin structure of the energy landscape 101 6.3.7 Distance between repeat families 104

				contents	xiii
	1 modeling evolutionary constraints at different scales 1.1 Some philosophy (of science) 1 6.3.3 6.4 Discussion 106	1
	1.2 Two examples of constraints in evolution 7 evolutionary model for repeat arrays	2 109
		1.3 Statistical mechanics offers a theoretical framework to study 7.1 Introduction 109
		evolution 7.2 Model 111	4
		1.4 Thesis organization 7.2.1 Parameters inference 113 4
		7.3 Results 114
	i	immune systems constrain the evolutionary paths of 7.4 Exploring mechanisms behind duplications and deletions 119
		viruses 7.4.1 Multi-repeat duplications and deletions 120 7
	2 pathogens against immune systems, an arms race across 7.4.2 Similarity dependent duplications and deletions 123
		timescales 7.4.3 Asymmetric similarity dependence between duplica-9
		2.1 Background and motivation tions and deletions 125	9
		2.2 Technical tools: stochastic processes and numerical simula-7.5 The road ahead 126
		tions 7.5.1 Duplications bursts model 128 12
		2.2.1 Markov processes 7.6 Conclusions 130	12
		2.2.2 Fokker-Plank and Langevin equations	14
	2.2.3 Numerical simulations of stochastic processes iii conclusions and future perspectives 133	15
	2.3 Conceptual tools: theoretical models of evolution and epi-8 concluding remarks 135
		demiology 8.1 Discussion and conclusion 135 16
		2.3.1 Diffusion equations for populations evolution 8.2 Future perspectives 138	17
		2.3.2 From genotypes to phenotypes to fitness: cross-reactivity 8.2.1 Viral-immune coevolution 138
		in recognition space 8.2.2 Protein evolution 139	18
		2.3.3 Evolution in structured and fluctuating fitness land-
	iv appendix	scapes 141	20
	2.3.4 Traveling wave theory of adaptation a multi-lineage evolution in viral populations driven 22
		2.3.5 Epidemiological models by host immune systems: supplementary information 24	143
	3 multi-lineage evolution in viral populations driven a.1 Simulation details 143
		by host immune systems a.1.1 Initialization 143	27
		3.1 Abstract a.1.2 Control of the number of infected hosts 143 27
		3.2 Introduction a.2 Detailed mutation model 144 27
		3.3 Methods a.3 Analysis of simulations 145 29
		3.3.1 The model a.3.1 Lineage identification 145 29
		3.3.2 Initial conditions and parameter fine-tuning a.3.2 Turn rate estimation 145	31
		3.3.3 Detailed mutation model a.	32
		3.4 Results	33
		3.4.1 Modes of antigenic evolution	33
		3.4.2 Stability	34
		3.4.3 Phase diagram of evolutionary regimes	34
		3.4.4 Incidence rate	37
		3.4.5 Speed of adaptation and intra-lineage diversity	38
		3.4.6 Antigenic persistence	39
		3.4.7 Dimension of phenotypic space	39
		3.4.8 Robustness to details of intra-host dynamics and pop-
			ulation size control	40
				xi

Table 1 -

 1 List of definitions of the model parameters and relevant equations, described in detail in the text.

	Model variables and equations.
	number of hosts	N
	maximum number of receptors per host	M
	transmission time	t I
	cross-reactivity width	d
	average mutation effect	σ
	mutation rate	µ
	target fraction of infected hosts	fi
	probability of infection after exposure to the virus	p f
	cross-reactivity kernel	f(r) = exp(-r d )
	jump size distribution probability of transmitting a mutated virus	ρ(a → b) = (1/2π)(4r ab /σ 2 )e -2r ab /σ P mut = 1 -e -µt I
	average attempted transmissions per infection	R 0 = 1 p f + fi -f i fi

Table 2 -

 2 List of definitions of the model parameters and relevant equations, described in detail in the text.

	1)
	rτ i

  ± 0.7 141.4 ± 0.3 157.6 ± 0.1 146.9 ± 0.4

	family 2L S rand	S 1	S 2	S full	S ir	S ir,-
	ANK LRR TPR	66 290 181 ± 0.05 169.7 ± 0.6 167.2 ± 0.3 176.7 ± 0.1 48 211 130 ± 0.05 114 ± 0.4 113.2 ± 0.3 123.1 ± 0.1 118.8 ± 0.1 172 ± 0.4 68 299 169 ± 0.1 145.4

Table 3 -

 3 Entropies (in bits, i.e. units of ln(

thermodynamic integration. We estimate the contribution of each of these errors using the independent sites model. In the independent sites model each site i is simply described by a multinomial distribution with weights given by the observed amino-acid frequencies in the datasets. The variance in the estimation of the frequencies from a finite size sample is Var(f i (σ i )) = (p i (σ i )(1 -p i (σ i )))/N s and the covariance between the frequencies of different amino-acids σ and σ at the same site i is Cov(

where N s is the sample size and p i (σ i ) are the weights of the true multinomial distribution sampled. Through error propagation from these quantities we calculate the variance in the entropy of the independent sites model, to first order in 1/N s :

) .

(

Evaluating this equation using the empirical frequencies p = fassuming they are sampled from an underlying multinomial distribution, gives an estimate of the standard deviation of 0.05. We assume that the interaction terms do not change the order of magnitude of this estimation. Also the standard deviation in the averages in Eq. ( 155) scales as 1/ √ N s with N s = 80000. The parameter inference is affected not only by noise, but also by a systematic bias depending on the parameters of the gradient ascent described in Section B.1.2 and the initial condition that we chose to start learning from. Fig. S5 shows the average entropy of 10 realizations of the learning and thermodynamic integration procedure for the ANK family and its standard deviation as error bars. If we learn the models with an increasing W window progressively we get a different profile than learning each point starting from the independent model, and above L these two profiles are more distant than the magnitude of the standard deviation, signalling a systematic bias. Fig. S5 also shows that progressively learning the model results in a better parameters convergence to values that give lower entropy values.

In order to estimate how this bias is reflected in the entropy estimation we take the single-site amino-acid frequencies produced by the inferred energy function in the last Monte-Carlo phase of the learning procedure and calculate the corresponding entropy for this independent-sites model. We compute the absolute value of the difference between this estimate of the entropy and the independent-sites entropy calculated from the dataset. Again in doing this we assume that neglecting the interaction terms does not change the order of magnitude of this error. These procedure results in the errorbars shown in Fig. 29,Fig. 28, Table 3, Fig. S6.

We repeat 10 realizations of both the parameter inference procedure and the entropy estimation, and in Fig. 29 we show the average entropy of these 10 numerical experiments for the ANK family where error bars are estimated as explained above to sketch the order of magnitude of the error coming from systematic bias in the parameters learning. Fig. S5 shows the mean entropy of ANK as in Fig. 29 A with the standard deviations of the realizations entropy as error bars, to give an idea of the combined noise in the thermody-Where we have N 2 +N 2 -1 total parameters. According to eq [START_REF] Mayer | How a well-adapting immune system remembers[END_REF],we have N equations:

. . .

. . .

and we are left with N 2 -N 2 free parameters.