(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 11.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 75205, 1622] NotebookOptionsPosition[ 73271, 1555] NotebookOutlinePosition[ 73700, 1574] CellTagsIndexPosition[ 73657, 1571] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Bertels et al., Discovering complete quasispecies in \ bacterial genomes ", FontSlant->"Italic"]], "Title", CellChangeTimes->{{3.690622575229733*^9, 3.6906226229600563`*^9}, 3.6907155469348307`*^9, {3.702809314382259*^9, 3.7028093299369707`*^9}}], Cell[CellGroupData[{ Cell["Supplementary Information", "Chapter", CellChangeTimes->{{3.6906226249745903`*^9, 3.690622644993925*^9}}], Cell[CellGroupData[{ Cell["Defining functions and importing data", "Section", CellChangeTimes->{{3.690026632883399*^9, 3.690026643503405*^9}, { 3.690622535524899*^9, 3.6906225368018436`*^9}}], Cell[CellGroupData[{ Cell["Functions and definitions", "Subsection", CellChangeTimes->{{3.690021195502041*^9, 3.690021196733231*^9}, { 3.690024636479658*^9, 3.69002464135002*^9}}], Cell["\<\ Function that calculates equilibrium frequencies for a given set of fitness \ values and a given mutation matrix\ \>", "Text", CellChangeTimes->{3.690021275808874*^9}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"CalculateEquilibriumFrequencies", "[", RowBox[{"fitness_", ",", "mutmatrix_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"W", ":=", RowBox[{"Transpose", "[", RowBox[{"mutmatrix", " ", "fitness"}], "]"}]}], ";", "\n", RowBox[{"ESys", ":=", RowBox[{"Eigensystem", "[", "W", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"sorted", "=", RowBox[{"Sort", "[", "ESys", "]"}]}], ";", "\n", RowBox[{"Return", "[", RowBox[{ RowBox[{"sorted", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1"}], "\[RightDoubleBracket]"}], "/", RowBox[{"Total", "[", RowBox[{"sorted", "\[LeftDoubleBracket]", RowBox[{"2", ",", "1"}], "\[RightDoubleBracket]"}], "]"}]}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{ 3.690024108929645*^9, {3.700451791998424*^9, 3.700451793334303*^9}}], Cell["\<\ Functions that calculate the mutation matrix. \ \>", "Text", CellChangeTimes->{{3.690021315880033*^9, 3.690021445817608*^9}, { 3.690715358890142*^9, 3.6907153809051228`*^9}, {3.690715456754533*^9, 3.690715484141419*^9}, {3.690715516891671*^9, 3.690715539526024*^9}, { 3.690715573176354*^9, 3.690715625357514*^9}, {3.7026989125463448`*^9, 3.702698981969213*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"(*", RowBox[{ "calculate", " ", "mutation", " ", "rate", " ", "for", " ", "a", " ", "single", " ", "entry", " ", "in", " ", "the", " ", "mutation", " ", "matrix"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"entry", "[", RowBox[{"i_", ",", "j_", ",", "u_", ",", "L_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"backMutation", ",", "forwardMutation", ",", "maintain"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"backMutation", "=", RowBox[{ RowBox[{"(", RowBox[{"i", "-", "1"}], ")"}], "*", RowBox[{"u", "/", "3"}]}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"non", "-", RowBox[{"zero", " ", "back", " ", "mutation", " ", "rate"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"backMutation", "=", "0"}], ";"}], " ", RowBox[{"(*", RowBox[{"0", " ", "back", " ", "mutations"}], "*)"}], "*)"}], "\[IndentingNewLine]", RowBox[{"forwardMutation", "=", RowBox[{ RowBox[{"u", "*", "L"}], "-", RowBox[{ RowBox[{"(", RowBox[{"i", "-", "1"}], ")"}], RowBox[{"u", "/", "3"}]}]}]}], ";", RowBox[{"(*", " ", RowBox[{ RowBox[{ "forward", " ", "mutation", " ", "rate", " ", "with", " ", "non"}], "-", RowBox[{"zero", " ", "back", " ", "mutation", " ", "rate"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"forwardMutation", "=", RowBox[{"u", "*", "L"}]}], ";"}], RowBox[{"(*", RowBox[{"for", " ", "0", " ", "back", " ", "mutations"}], "*)"}], "*)"}], "\[IndentingNewLine]", RowBox[{"maintain", "=", RowBox[{"1", "-", "backMutation", "-", "forwardMutation"}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[Equal]", "j"}], ",", "maintain", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[Equal]", RowBox[{"j", "+", "1"}]}], ",", "backMutation", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[Equal]", RowBox[{"j", "-", "1"}]}], ",", "forwardMutation", ",", "0"}], "]"}]}], "]"}]}], "]"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"makeMutMatrix", "[", RowBox[{"u_", ",", "L_", ",", "mutclasses_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "matrix", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"matrix", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"entry", "[", RowBox[{"i", ",", "j", ",", "u", ",", "L"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "mutclasses"}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "mutclasses"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"matrix", "\[LeftDoubleBracket]", RowBox[{"mutclasses", ",", "mutclasses"}], "\[RightDoubleBracket]"}], "=", RowBox[{"1", "-", RowBox[{"matrix", "\[LeftDoubleBracket]", RowBox[{"mutclasses", ",", RowBox[{"mutclasses", "-", "1"}]}], "\[RightDoubleBracket]"}]}]}], ";"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"matrix", "\[LeftDoubleBracket]", RowBox[{"mutclasses", ",", RowBox[{"mutclasses", "-", "1"}]}], "\[RightDoubleBracket]"}], "=", "0"}], ";", RowBox[{"(*", RowBox[{ "no", " ", "back", " ", "mutations", " ", "for", " ", "the", " ", "last", " ", "mutation", " ", "class"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"matrix", "\[LeftDoubleBracket]", RowBox[{"mutclasses", ",", "mutclasses"}], "\[RightDoubleBracket]"}], "=", "1"}], ";", RowBox[{"(*", RowBox[{ "once", " ", "a", " ", "sequence", " ", "reaches", " ", "the", " ", "last", " ", "mutation", " ", "class", " ", "it", " ", "will", " ", "stay", " ", "there"}], "*)"}], "\[IndentingNewLine]", RowBox[{"Return", "[", "matrix", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]}]}]], "Input", CellChangeTimes->{{3.702698988320113*^9, 3.7026991915160503`*^9}, { 3.702791959872868*^9, 3.7027919943203783`*^9}, {3.702808893148046*^9, 3.7028089421047983`*^9}}], Cell["\<\ Function that calculates the fitness values from the equilibrium frequencies \ with a given mutation matrix. \ \>", "Text", CellChangeTimes->{{3.690021315880033*^9, 3.690021445817608*^9}, { 3.690715358890142*^9, 3.6907153809051228`*^9}, {3.690715456754533*^9, 3.690715484141419*^9}, {3.690715516891671*^9, 3.690715539526024*^9}, { 3.690715573176354*^9, 3.690715625357514*^9}, {3.7026989125463448`*^9, 3.702698981969213*^9}, {3.702699218996615*^9, 3.702699231506707*^9}, { 3.702699296136969*^9, 3.70269930960877*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ RowBox[{"CalculateFitness", "[", RowBox[{ "frequencies_", ",", "mutmatrix_", ",", "mutclasses_", ",", "name_", ",", "u_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "x", ",", "f", ",", "farray", ",", "q", ",", "\[Phi]", ",", "equilibriumEq", ",", "eqs", ",", "s", ",", "min", ",", "fitnessTable", ",", "i", ",", "j"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"x", "=", "frequencies"}], ";", " ", RowBox[{"(*", RowBox[{ "frequencies", " ", "of", " ", "the", " ", "different", " ", "mutation", " ", "classes"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ SubscriptBox["f", RowBox[{"mutclasses", "-", "1"}]], "=", "1"}], ";", " ", RowBox[{"(*", RowBox[{ "set", " ", "the", " ", "frequeny", " ", "of", " ", "the", " ", "lowest", " ", "mutation", " ", "class", " ", "to", " ", "1"}], "*)"}], "\[IndentingNewLine]", RowBox[{"farray", "=", RowBox[{"Table", "[", RowBox[{ SubscriptBox["f", RowBox[{"i", "-", "1"}]], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "mutclasses"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"q", "=", "mutmatrix"}], ";", RowBox[{"(*", RowBox[{ "the", " ", "mutation", " ", "matrix", " ", "is", " ", "called", " ", "q"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Phi]", "[", RowBox[{"x_", ",", "f_"}], "]"}], ":=", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"i", "=", "1"}], "mutclasses"], RowBox[{"(", RowBox[{ RowBox[{ "x", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], " ", RowBox[{ "f", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ")"}]}]}], ";", RowBox[{"(*", RowBox[{ "\[Phi]", " ", "for", " ", "no", " ", "back", " ", "mutations"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"equilibriumEq", "[", "i_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"-", RowBox[{"\[Phi]", "[", RowBox[{"x", ",", "farray"}], "]"}]}], "*", RowBox[{ "x", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "+", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"j", "=", "1"}], "mutclasses"], RowBox[{"(", RowBox[{ RowBox[{ "x", "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], " ", RowBox[{ "farray", "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], RowBox[{"q", "\[LeftDoubleBracket]", RowBox[{"j", ",", "i"}], "\[RightDoubleBracket]"}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"eqs", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"0", "\[Equal]", RowBox[{"equilibriumEq", "[", "i", "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "mutclasses"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Solve", " ", "quasispecies", " ", "model", " ", "for", " ", "fitness"}], "*)"}], "\[IndentingNewLine]", RowBox[{"s", "=", RowBox[{"NSolve", "[", RowBox[{"eqs", ",", RowBox[{"farray", "\[LeftDoubleBracket]", RowBox[{"1", ";;", RowBox[{"mutclasses", "-", "1"}]}], "\[RightDoubleBracket]"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "if", " ", "there", " ", "are", " ", "fitness", " ", "values", " ", "below", " ", "one"}], ";", " ", RowBox[{"scale", " ", "these", " ", "to", " ", "one"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"min", "=", RowBox[{"Min", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ "s", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"mutclasses", "-", "1"}]}], "}"}]}], "]"}], ",", "1"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"fitnessTable", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{ "s", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], "/", "min"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"mutclasses", "-", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"fitnessTable", "=", RowBox[{"Append", "[", RowBox[{"fitnessTable", ",", RowBox[{"1", "/", "min"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "add", " ", "mutation", " ", "rate", " ", "to", " ", "output"}], "*)"}], "\[IndentingNewLine]", RowBox[{"fitnessTable", "=", RowBox[{"Append", "[", RowBox[{"fitnessTable", ",", "u"}], " ", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "add", " ", "observed", " ", "frequencies", " ", "to", " ", "output"}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "\[LessEqual]", " ", "mutclasses"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"fitnessTable", "=", RowBox[{"Append", "[", RowBox[{"fitnessTable", ",", RowBox[{ RowBox[{ "x", "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], "//", "N"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"fitnessTable", "=", RowBox[{"Append", "[", RowBox[{"fitnessTable", ",", "name"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", "fitnessTable", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]"}]], "Input", CellChangeTimes->{{3.6900246599902763`*^9, 3.690024662173811*^9}, { 3.6907156442705803`*^9, 3.690715730829176*^9}, {3.690715786165744*^9, 3.6907157881007767`*^9}, {3.6907762431694803`*^9, 3.6907762722218657`*^9}, {3.690776383757474*^9, 3.690776429484614*^9}, { 3.69077805547278*^9, 3.6907781115508747`*^9}, 3.69077814963169*^9, { 3.690778244318112*^9, 3.6907782671968803`*^9}, {3.6944181394921093`*^9, 3.694418147996437*^9}, {3.695555855089013*^9, 3.695555883190072*^9}, { 3.699854400599078*^9, 3.6998546022171907`*^9}, {3.6998546774704657`*^9, 3.699854812367568*^9}, {3.70029354843598*^9, 3.700293571817068*^9}, { 3.700293605780034*^9, 3.700293661279483*^9}, {3.700293722835187*^9, 3.700293775984542*^9}, {3.700293839957109*^9, 3.700293862612076*^9}, { 3.700293897749836*^9, 3.700293967154114*^9}, {3.7002940175536413`*^9, 3.700294048280765*^9}, {3.700294086648644*^9, 3.700294147791946*^9}, { 3.70036417187815*^9, 3.700364288036209*^9}, {3.7003643257859383`*^9, 3.7003643340341253`*^9}, {3.70036451968329*^9, 3.7003645234861107`*^9}, { 3.7003645751900587`*^9, 3.70036464889036*^9}, {3.700364835175832*^9, 3.7003648680708933`*^9}, {3.700364952813673*^9, 3.700365009924716*^9}, { 3.7003679804684963`*^9, 3.700368090625058*^9}, {3.700368378590055*^9, 3.700368385893605*^9}, {3.700368476549924*^9, 3.700368542962101*^9}, { 3.7003687063611593`*^9, 3.7003687546412573`*^9}, 3.700369902589739*^9, { 3.70037038801987*^9, 3.700370474032015*^9}, {3.7003814874758863`*^9, 3.7003814875768633`*^9}, {3.7003890222932053`*^9, 3.7003891088440332`*^9}, {3.700389184693659*^9, 3.7003892613524103`*^9}, { 3.700389303862958*^9, 3.700389312368779*^9}, {3.700389342704124*^9, 3.7003895304999247`*^9}, {3.7003896090939207`*^9, 3.700389636520602*^9}, { 3.700390355648903*^9, 3.700390357555991*^9}, {3.700391658223702*^9, 3.700391674908063*^9}, 3.700391850810783*^9, 3.700392093759056*^9, { 3.700450587601284*^9, 3.700450599231758*^9}, {3.700450634902714*^9, 3.700450714789847*^9}, {3.700451019524119*^9, 3.700451022285716*^9}, { 3.700451182924383*^9, 3.700451183419998*^9}, {3.700451319395441*^9, 3.700451319841522*^9}, {3.700451394139123*^9, 3.70045147672434*^9}, { 3.700451875973926*^9, 3.700451880302794*^9}, {3.700451915727919*^9, 3.7004519219301453`*^9}, 3.700452042510594*^9, {3.700452191339343*^9, 3.700452240455886*^9}, {3.700452326514451*^9, 3.700452367003375*^9}, { 3.7004523974470177`*^9, 3.700452401794344*^9}, {3.700458504856904*^9, 3.7004585097623796`*^9}, {3.70045870948626*^9, 3.700458713295413*^9}, 3.700458886705028*^9, {3.7004594958901997`*^9, 3.7004594999124002`*^9}, 3.700459635479364*^9, {3.7004680951019087`*^9, 3.700468097035255*^9}, { 3.700468140422112*^9, 3.700468165899192*^9}, 3.700468202357004*^9, 3.7004684072902822`*^9, {3.700472279418007*^9, 3.700472282321446*^9}, { 3.700472430283121*^9, 3.7004724440780783`*^9}, {3.700472480638501*^9, 3.7004725030840054`*^9}, {3.700472545064296*^9, 3.700472578124401*^9}, { 3.700472616501017*^9, 3.7004726299744864`*^9}, {3.700472786855994*^9, 3.700472803335198*^9}, {3.7004728647423363`*^9, 3.700472896509079*^9}, 3.702010839918804*^9, {3.702011588604095*^9, 3.702011765609726*^9}, { 3.702011804396351*^9, 3.7020118137740726`*^9}, {3.702011860653111*^9, 3.702011999019003*^9}, {3.702012035513115*^9, 3.702012160663188*^9}, { 3.702012250284148*^9, 3.702012330136237*^9}, {3.702012599412809*^9, 3.70201270467759*^9}, {3.702012737098393*^9, 3.702012754727909*^9}, { 3.702012787985779*^9, 3.702012906281846*^9}, {3.702013159433628*^9, 3.70201316319276*^9}, {3.702013240948497*^9, 3.70201324166247*^9}, 3.702013306283853*^9, {3.702014796878736*^9, 3.7020148146746273`*^9}, { 3.702698967518064*^9, 3.702698986877557*^9}, {3.7026992386480837`*^9, 3.702699258525395*^9}, {3.7026993798246517`*^9, 3.702699453409606*^9}, 3.702699483775784*^9}], Cell["\<\ Function that processes the input data (i.e. sequence frequencies) and varies \ the frequencies of the last mutation class by \[OpenCurlyDoubleQuote]var\ \[CloseCurlyDoubleQuote]. \ \>", "Text", CellChangeTimes->{{3.690021315880033*^9, 3.690021445817608*^9}, { 3.690715358890142*^9, 3.6907153809051228`*^9}, {3.690715456754533*^9, 3.690715484141419*^9}, {3.690715516891671*^9, 3.690715539526024*^9}, { 3.690715573176354*^9, 3.690715625357514*^9}, {3.7026989125463448`*^9, 3.702698981969213*^9}, {3.702699218996615*^9, 3.702699231506707*^9}, { 3.70269929205895*^9, 3.702699366751734*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"ProcessData", "[", RowBox[{"realFreqs_", ",", "var_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "inner", ",", "realTab", ",", "names", ",", "seqLength", ",", "temp"}], "}"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"j", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"i", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"realTab", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"inner", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"names", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"seqLength", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"i", "<", RowBox[{"Length", "[", "realFreqs", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"i", "++"}], ";", "\[IndentingNewLine]", RowBox[{"j", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"inner", "=", RowBox[{"{", RowBox[{ RowBox[{"realFreqs", "\[LeftDoubleBracket]", RowBox[{"i", "+", "j"}], "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}], "}"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"i", "+", "j"}], "<", RowBox[{"Length", "[", "realFreqs", "]"}]}], " ", "&&", " ", RowBox[{ RowBox[{ RowBox[{"realFreqs", "\[LeftDoubleBracket]", RowBox[{"i", "+", "j"}], "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "==", RowBox[{ RowBox[{"realFreqs", "\[LeftDoubleBracket]", RowBox[{"i", "+", "j", "+", "1"}], "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"j", "++"}], ";", "\[IndentingNewLine]", RowBox[{"inner", "=", RowBox[{"Append", "[", RowBox[{"inner", ",", RowBox[{ RowBox[{"realFreqs", "\[LeftDoubleBracket]", RowBox[{"i", "+", "j"}], "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "if", " ", "there", " ", "is", " ", "not", " ", "enough", " ", "data", " ", "add", " ", "1", "s", " ", "to", " ", "REPIN", " ", "population", " ", "count"}], ",", " ", RowBox[{"CAUTION", ":", " ", RowBox[{ "THIS", " ", "WILL", " ", "SIGNIFICANTLY", " ", "ALTER", " ", "THE", " ", "DATA"}]}], ",", " ", RowBox[{ "WE", " ", "ONLY", " ", "ADDED", " ", "THIS", " ", "FOR", " ", "CONSISTENCY", " ", "REASONS", "\[IndentingNewLine]", "It", " ", "may", " ", "be", " ", "better", " ", "to", " ", "reduce", " ", "the", " ", "number", " ", "of", " ", "mutation", " ", "classes", " ", "if", " ", "this", " ", "is", " ", "an", " ", RowBox[{"issue", "."}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "inner", "]"}], "<", "mutclasses"}], ",", RowBox[{"inner", "=", RowBox[{"Append", "[", RowBox[{"inner", ",", "1"}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "vary", " ", "the", " ", "last", " ", "mutation", " ", "class", " ", "by", " ", "\"\\"", "\[IndentingNewLine]", "This", " ", "demonstrates", " ", "the", " ", "effect", " ", "small", " ", "variations", " ", "in", " ", "the", " ", "last", " ", "mutation", " ", "class", " ", "have", " ", "on", " ", "the", " ", "inferred", " ", "fitness", " ", RowBox[{"values", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"k", "=", RowBox[{"-", "var"}]}], ",", RowBox[{"k", "\[LessEqual]", "var"}], ",", RowBox[{"k", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"temp", "=", "inner"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"temp", "\[LeftDoubleBracket]", RowBox[{"Length", "[", "temp", "]"}], "\[RightDoubleBracket]"}], "=", RowBox[{ RowBox[{"temp", "\[LeftDoubleBracket]", RowBox[{"Length", "[", "temp", "]"}], "\[RightDoubleBracket]"}], "+", "k"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"temp", "\[LeftDoubleBracket]", RowBox[{"Length", "[", "temp", "]"}], "\[RightDoubleBracket]"}], ">", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"realTab", "=", RowBox[{"Append", "[", RowBox[{"realTab", ",", "temp"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"names", "=", RowBox[{"Append", "[", RowBox[{"names", ",", RowBox[{ RowBox[{ "realFreqs", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"seqLength", "=", RowBox[{"Append", "[", RowBox[{"seqLength", ",", RowBox[{ RowBox[{ "realFreqs", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"i", "=", RowBox[{"i", "+", "j"}]}], ";"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"names", "=", RowBox[{"StringReplace", "[", RowBox[{"names", ",", RowBox[{"\"\<_largestCluster\>\"", "\[Rule]", "\"\<\>\""}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"{", RowBox[{"realTab", ",", "seqLength", ",", "names"}], "}"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{ 3.702699265469062*^9, {3.702699508182684*^9, 3.702699617101173*^9}}], Cell[TextData[{ "\nNumber of sequence classes is given by ", StyleBox["mutclasses", "Input", FontSlant->"Italic"], StyleBox[" ", FontSlant->"Italic"] }], "Text", CellChangeTimes->{{3.690021315880033*^9, 3.690021445817608*^9}, { 3.690715358890142*^9, 3.6907153809051228`*^9}, {3.690715456754533*^9, 3.690715484141419*^9}, {3.690715516891671*^9, 3.690715539526024*^9}, { 3.690715573176354*^9, 3.690715620382867*^9}, 3.700459256347851*^9}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"mutclasses", "=", "6"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"var", "=", RowBox[{"0", " ", "is", " ", "the", " ", "default"}]}], ",", " ", RowBox[{ RowBox[{ "which", " ", "will", " ", "only", " ", "infer", " ", "fitness", " ", "values", " ", "for", " ", "the", " ", "provided", " ", "dataset"}], ";", " ", RowBox[{ "larger", " ", "values", " ", "of", " ", "var", " ", "will", " ", "add", " ", "fitness", " ", "inferrences", " ", "to", " ", "the", " ", "results", " ", "where", " ", "all", " ", "integer", " ", "values", " ", "up", " ", "to", " ", "var", " ", "are", " ", "added", " ", "or", " ", RowBox[{"subtracted", "."}]}]}]}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"var", "=", "0"}], ";"}], "\[IndentingNewLine]"}], "Input", CellChangeTimes->{{3.6900246599902763`*^9, 3.690024662173811*^9}, 3.700457594692605*^9, {3.700457627634397*^9, 3.700457627686222*^9}, 3.7004580441554117`*^9, 3.700458566250807*^9, 3.700458759517479*^9, 3.700458800196536*^9, 3.7004591367498913`*^9, 3.7004596068863783`*^9, 3.700461184008463*^9, {3.700467427025796*^9, 3.7004674477196198`*^9}, { 3.70046791804945*^9, 3.700467935455131*^9}, {3.700468511267316*^9, 3.700468526913793*^9}, 3.700468696497301*^9, {3.7004722926539917`*^9, 3.7004723009656677`*^9}, {3.700472664018621*^9, 3.700472672112001*^9}, { 3.7004728103330307`*^9, 3.7004728175240173`*^9}, {3.7004729078289337`*^9, 3.7004729153863*^9}, {3.7005637974889402`*^9, 3.7005638322643223`*^9}, 3.7020076007384443`*^9, {3.702013961349032*^9, 3.702013964709104*^9}, { 3.702014612554935*^9, 3.702014612842308*^9}, {3.70201474557721*^9, 3.702014750158634*^9}, {3.702361700600663*^9, 3.702361703456049*^9}, 3.702368230364664*^9, {3.7023689708322983`*^9, 3.702368979661333*^9}, { 3.702369111557035*^9, 3.70236911882649*^9}, {3.702698864746694*^9, 3.702698866529098*^9}, {3.7026996358137217`*^9, 3.7026997345455523`*^9}, { 3.702699777618024*^9, 3.702699803496477*^9}, 3.702793183107092*^9}], Cell[TextData[{ "Following ", StyleBox["Wielgoss et al. 2011", FontSlant->"Italic"], " the mutation rate in ", StyleBox["E. coli ", FontSlant->"Italic"], "is set to ", StyleBox["u", "Input"], " " }], "Text", CellChangeTimes->{{3.690021593678323*^9, 3.69002160273424*^9}, { 3.690023881817116*^9, 3.6900238982223177`*^9}, {3.690023960822667*^9, 3.690023968508552*^9}, {3.690024009603897*^9, 3.690024010683489*^9}, 3.690710576162188*^9}], Cell[BoxData[ RowBox[{ RowBox[{"u", "=", RowBox[{"8.9", " ", SuperscriptBox["10", RowBox[{"-", "11"}]]}]}], ";"}]], "Input", CellChangeTimes->{{3.6900240297646646`*^9, 3.690024038748827*^9}, { 3.6900246692709913`*^9, 3.690024669871648*^9}, {3.695555904036387*^9, 3.695555909388281*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Importing data", "Subsection", CellChangeTimes->{{3.690021724500193*^9, 3.69002172714017*^9}}], Cell[TextData[{ "Next we import the sequence frequencies from the real data. The format of \ the imported data is in the form of a table with three columns, each \ referring to \n", StyleBox["1. Organism name\n2. Sequence Class\n3. Sequence Frequency", "ItemNumbered"] }], "Text", CellChangeTimes->{{3.6900214707904453`*^9, 3.690021554151413*^9}, { 3.6900217143422203`*^9, 3.690021715100484*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"realFreqs", "=", RowBox[{"Import", "[", RowBox[{ RowBox[{ RowBox[{"NotebookDirectory", "[", "]"}], "<>", "\"\\""}], ",", "\"\\""}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"data", "=", RowBox[{"ProcessData", "[", RowBox[{"realFreqs", ",", "var"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"realTab", "=", RowBox[{"data", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"names", "=", RowBox[{"data", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}], ";"}], RowBox[{"(*", RowBox[{"organism", " ", "names"}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"seqLength", "=", RowBox[{"data", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "calculate", " ", "relative", " ", "frequencies", " ", "from", " ", "absolute", " ", "frequencies"}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"freqs", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ "realTab", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "/", RowBox[{"Total", "[", RowBox[{ "realTab", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "realTab", "]"}]}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"i", "=", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"newf", "=", RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"i", "<", RowBox[{"Length", "[", "freqs", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"i", "++"}], ";", "\[IndentingNewLine]", RowBox[{"j", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"inner", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"j", "<", RowBox[{"mutclasses", "-", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"j", "++"}], ";", "\[IndentingNewLine]", RowBox[{"inner", "=", RowBox[{"Append", "[", RowBox[{"inner", ",", RowBox[{"freqs", "\[LeftDoubleBracket]", RowBox[{"i", ",", "j"}], "\[RightDoubleBracket]"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "if", " ", "there", " ", "are", " ", "more", " ", "entries", " ", "than", " ", "mutation", " ", "classes", " ", "then", " ", "add", " ", "all", " ", "remaining", " ", "entries", " ", "and", " ", "put", " ", "them", " ", "in", " ", "the", " ", "last", " ", "mutation", " ", "class"}], "*)"}], "\[IndentingNewLine]", RowBox[{"last", "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{"freqs", "\[LeftDoubleBracket]", RowBox[{"i", ",", "j"}], "\[RightDoubleBracket]"}], ",", RowBox[{"{", RowBox[{"j", ",", "mutclasses", ",", RowBox[{"Length", "[", RowBox[{ "freqs", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"inner", "=", RowBox[{"Append", "[", RowBox[{"inner", ",", "last"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"newf", "=", RowBox[{"Append", "[", RowBox[{"newf", ",", "inner"}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"freqs", "=", "newf"}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]"}], "\[IndentingNewLine]"}], "Input", CellChangeTimes->{{3.690622457766018*^9, 3.690622470005282*^9}, { 3.694326400185278*^9, 3.6943264323212137`*^9}, {3.694417159644878*^9, 3.694417179082315*^9}, 3.695012940795026*^9, {3.700276672720285*^9, 3.7002767074714317`*^9}, 3.7004515983720913`*^9, 3.7004517166889467`*^9, { 3.700453955536652*^9, 3.700454065521516*^9}, 3.700454097468142*^9, { 3.700454211201406*^9, 3.700454230574574*^9}, {3.700454280565873*^9, 3.700454361950863*^9}, {3.700454430996604*^9, 3.700454547707056*^9}, { 3.700454606681299*^9, 3.700454759939742*^9}, {3.700455927570409*^9, 3.70045594151215*^9}, {3.700456021760067*^9, 3.700456034509652*^9}, { 3.7004561614768467`*^9, 3.7004561921560383`*^9}, {3.700456274563575*^9, 3.700456935518908*^9}, {3.700457019701478*^9, 3.700457090331723*^9}, { 3.700457142123167*^9, 3.700457210111313*^9}, {3.700457242415441*^9, 3.700457242645294*^9}, {3.7004572754891777`*^9, 3.700457407107834*^9}, { 3.700457441718151*^9, 3.700457582561509*^9}, 3.700457830937469*^9, { 3.7004583251174088`*^9, 3.700458326036705*^9}, {3.700458832227872*^9, 3.7004588354103603`*^9}, {3.7004771488970737`*^9, 3.7004771676187353`*^9}, {3.700536544569529*^9, 3.700536593247066*^9}, { 3.7005367259740753`*^9, 3.700536730722933*^9}, {3.700536762467348*^9, 3.700536776443181*^9}, {3.7005369572887087`*^9, 3.700537013695928*^9}, { 3.70053728853132*^9, 3.700537303624275*^9}, 3.70053734876116*^9, { 3.7020109934595957`*^9, 3.702010997308297*^9}, {3.702011037122169*^9, 3.7020110873262167`*^9}, {3.702011217615037*^9, 3.702011244577177*^9}, { 3.70201145566547*^9, 3.702011574597929*^9}, {3.7020123863807783`*^9, 3.702012432275399*^9}, {3.702012513296461*^9, 3.7020125915190573`*^9}, { 3.702012987082773*^9, 3.7020131105506897`*^9}, {3.7020131801273537`*^9, 3.702013213152829*^9}, {3.7020132544378643`*^9, 3.702013257649115*^9}, { 3.702013325299254*^9, 3.702013340382182*^9}, {3.702013946901478*^9, 3.702013956200761*^9}, {3.7026998312262163`*^9, 3.7026999216469173`*^9}, 3.702703584591589*^9}] }, Closed]] }, Open ]], Cell[CellGroupData[{ Cell["Model", "Section", CellChangeTimes->{{3.690026143735654*^9, 3.690026144301979*^9}}], Cell[CellGroupData[{ Cell["\<\ Solving for the equilibrium frequencies of the mutation classes.\ \>", "Subsection", CellChangeTimes->{{3.690026156094469*^9, 3.690026211828141*^9}, 3.690026242867548*^9, {3.6900262764907846`*^9, 3.6900262831945*^9}, { 3.690026324819542*^9, 3.690026364000411*^9}, {3.690026803047749*^9, 3.690026803797744*^9}, 3.690026839268004*^9, {3.702699944172991*^9, 3.702699948932827*^9}}], Cell[TextData[{ "The fitness of the mutation classes is given by the ", StyleBox["fitnessTable", "Input"], ". " }], "Text", CellChangeTimes->{{3.6900268212852287`*^9, 3.69002683356504*^9}, { 3.690710588454186*^9, 3.690710590176021*^9}, {3.70270226835102*^9, 3.702702306876541*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"outputUnscaled", "=", RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", RowBox[{"Length", "[", "freqs", "]"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"L", "=", RowBox[{ "seqLength", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ";", RowBox[{"(*", RowBox[{ RowBox[{"sequence", " ", "length"}], ",", " ", RowBox[{ "which", " ", "is", " ", "different", " ", "for", " ", "different", " ", "data", " ", "sets"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"q", "=", RowBox[{"makeMutMatrix", "[", RowBox[{"u", ",", "L", ",", "mutclasses"}], "]"}]}], ";", RowBox[{"(*", RowBox[{ "the", " ", "mutation", " ", "matrix", " ", "also", " ", "differs", " ", "due", " ", "to", " ", "different", " ", "sequence", " ", "lengths"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"equilibrium", " ", "frequencies", " ", "x"}], "*)"}], "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"freqs", "\[LeftDoubleBracket]", RowBox[{"i", ",", "j"}], "\[RightDoubleBracket]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"Length", "[", RowBox[{ "freqs", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"fitnessTable", "=", RowBox[{"CalculateFitness", "[", RowBox[{ RowBox[{"x", "//", "N"}], ",", "q", ",", "mutclasses", ",", RowBox[{ "names", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", "u"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"fitnessTable", "=", RowBox[{"Append", "[", RowBox[{"fitnessTable", ",", RowBox[{ "seqLength", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"outputUnscaled", "=", RowBox[{"Append", "[", RowBox[{"outputUnscaled", ",", "fitnessTable"}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]"}], "Input", CellChangeTimes->{ 3.690715450973304*^9, 3.69071563989063*^9, {3.6907762788625927`*^9, 3.690776326868642*^9}, {3.690776367187454*^9, 3.690776376395768*^9}, 3.6907764182679853`*^9, 3.690776712997224*^9, {3.6907767439104843`*^9, 3.6907767695562468`*^9}, {3.690776803789168*^9, 3.690776833348311*^9}, { 3.690777707596081*^9, 3.690777717803514*^9}, {3.690778127021413*^9, 3.690778179746684*^9}, {3.6907782578672943`*^9, 3.690778260905492*^9}, { 3.694416834153837*^9, 3.694416834441371*^9}, {3.694417199019133*^9, 3.694417214265733*^9}, {3.6944181827608557`*^9, 3.694418211648871*^9}, { 3.699854849467924*^9, 3.699854867952672*^9}, {3.7003643723123913`*^9, 3.7003643768549757`*^9}, {3.7003644710305758`*^9, 3.700364476700782*^9}, 3.700364534104685*^9, {3.700451663128293*^9, 3.7004516696405773`*^9}, { 3.700451707687789*^9, 3.700451774020958*^9}, 3.7004520009976997`*^9, 3.700452086557005*^9, {3.700452411372122*^9, 3.700452422193088*^9}, { 3.7004527297519073`*^9, 3.700452791227577*^9}, {3.700456967444128*^9, 3.700456980252564*^9}, {3.700458285292292*^9, 3.700458304291388*^9}, { 3.7004583556410646`*^9, 3.700458369347102*^9}, {3.7004584185403137`*^9, 3.700458435881748*^9}, {3.700458586375732*^9, 3.700458597030632*^9}, 3.7004586337784443`*^9, {3.700458783581643*^9, 3.700458784394556*^9}, { 3.70045884010798*^9, 3.700458841788333*^9}, {3.700459178367062*^9, 3.700459203980768*^9}, {3.7004592811494617`*^9, 3.7004592853070383`*^9}, { 3.700459346035428*^9, 3.70045937156889*^9}, {3.700459430115387*^9, 3.7004594339042397`*^9}, {3.7004595090416327`*^9, 3.700459550752235*^9}, { 3.700459649879489*^9, 3.7004596553500423`*^9}, 3.700467709018629*^9, { 3.700468192251254*^9, 3.700468192673143*^9}, {3.700477170615115*^9, 3.700477179992405*^9}, 3.700479420529204*^9, {3.700536673988163*^9, 3.700536681259656*^9}, 3.700537019588435*^9, {3.702702315973567*^9, 3.702702357884775*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Exporting raw output and scaled with mutation rate", "Subsection", CellChangeTimes->{{3.6900264280469437`*^9, 3.690026445710328*^9}, { 3.690026498940838*^9, 3.6900265144847927`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"Export", "[", RowBox[{ RowBox[{ RowBox[{"NotebookDirectory", "[", "]"}], "<>", "\"\\"", "<>", RowBox[{"ToString", "[", "mutclasses", "]"}], "<>", "\"\<_\>\"", "<>", RowBox[{"ToString", "[", "var", "]"}], "<>", "\"\<.txt\>\""}], ",", " ", "outputUnscaled", ",", "\"\\""}], "]"}], ";"}]], "Input", CellChangeTimes->{ 3.690026538684276*^9, {3.6931397925421886`*^9, 3.693139793676897*^9}, { 3.700457668134441*^9, 3.700457678198996*^9}, {3.700457761062108*^9, 3.700457771254779*^9}, {3.700457814796782*^9, 3.700457818555853*^9}, 3.700468497301626*^9, {3.702013922748564*^9, 3.70201393480648*^9}, { 3.702014700410396*^9, 3.7020147022155647`*^9}}], Cell[CellGroupData[{ Cell["What does scaling do?", "Subsubsection", CellChangeTimes->{{3.690026560283193*^9, 3.6900265640503893`*^9}, { 3.690026659979251*^9, 3.690026682610526*^9}}], Cell["\<\ If we want to determine the fitness values that give us comparable results \ but for a higher mutation rate then we need to do the following: \ \>", "Text", CellChangeTimes->{{3.6900266899683867`*^9, 3.6900266987041893`*^9}, { 3.6900866533431263`*^9, 3.690086700371307*^9}, {3.6900867314907103`*^9, 3.690086736907812*^9}}], Cell[TextData[StyleBox["1. Calculate the number of generations one time step \ at the new mutation rate corresponds to under the old mutation rate.", FontWeight->"Plain"]], "Text", CellChangeTimes->{{3.6900266899683867`*^9, 3.6900266987041893`*^9}, { 3.6900866533431263`*^9, 3.690086700371307*^9}, {3.6900867314907103`*^9, 3.690086736907812*^9}, {3.690776886916007*^9, 3.690776900427383*^9}, { 3.6907770340244513`*^9, 3.69077711607657*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"(*", RowBox[{ "scale", " ", "results", " ", "for", " ", "a", " ", "mutation", " ", "rate", " ", "of", " ", SuperscriptBox["10", RowBox[{"-", "4"}]]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"newU", "=", SuperscriptBox["10", RowBox[{"-", "4"}]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gens", "=", RowBox[{"newU", "/", "u"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"calculate", " ", "new", " ", "fitness", " ", "values"}], "*)"}], "\[IndentingNewLine]"}]}]], "Input", CellChangeTimes->{{3.686312779686659*^9, 3.6863127836748857`*^9}, { 3.686312933708147*^9, 3.686312934513651*^9}, {3.6863130306962013`*^9, 3.686313145837989*^9}, {3.686313326226014*^9, 3.68631335460006*^9}, 3.686313406522336*^9, {3.688136813962337*^9, 3.6881368824060307`*^9}, { 3.688136921443454*^9, 3.688137065746949*^9}, {3.68819246769683*^9, 3.6881925712581787`*^9}, {3.688192620490706*^9, 3.688192696593978*^9}, { 3.688192752936054*^9, 3.688192857573505*^9}, {3.6881929294372168`*^9, 3.688192936836157*^9}, {3.688193075508675*^9, 3.688193078082035*^9}, { 3.688193145531201*^9, 3.68819317966425*^9}, {3.688193211739992*^9, 3.6881932222723913`*^9}, {3.688193334901696*^9, 3.688193377851647*^9}, { 3.6881934335487003`*^9, 3.688193446141795*^9}, {3.688193539923545*^9, 3.688193540051264*^9}, {3.688193691006092*^9, 3.688193704143471*^9}, { 3.688193763913682*^9, 3.688193826125889*^9}, 3.6881939017783737`*^9, { 3.688193933413761*^9, 3.688193962363928*^9}, {3.688278693146368*^9, 3.688278696566835*^9}, {3.688361025932762*^9, 3.688361084734771*^9}, { 3.688361135159213*^9, 3.6883611982681026`*^9}, {3.68836123309415*^9, 3.688361295234538*^9}, {3.688361340492219*^9, 3.688361486887808*^9}, { 3.688361534793385*^9, 3.688361546143691*^9}, {3.688361587102516*^9, 3.688361665518302*^9}, {3.68836173645275*^9, 3.688361814780212*^9}, { 3.688361845538513*^9, 3.6883618747456913`*^9}, 3.6883619913097897`*^9, { 3.688362031486649*^9, 3.68836219799837*^9}, {3.6883624338343763`*^9, 3.68836259719858*^9}, {3.6883626423001137`*^9, 3.688362751876074*^9}, { 3.6883640815267353`*^9, 3.688364103392716*^9}, 3.688364201041992*^9, { 3.688364266266761*^9, 3.688364279684598*^9}, {3.688364327472629*^9, 3.688364404977871*^9}, {3.688364440068295*^9, 3.6883644414988403`*^9}, { 3.6888149149149237`*^9, 3.68881494177318*^9}, {3.6888150050309362`*^9, 3.6888150488514147`*^9}, {3.688815094005542*^9, 3.6888151318580923`*^9}, { 3.688815167137295*^9, 3.688815247456152*^9}, {3.6888153129194736`*^9, 3.688815332370713*^9}, {3.689316457076325*^9, 3.6893164941688128`*^9}, { 3.6893165287940598`*^9, 3.689316560864029*^9}, 3.6893166132811413`*^9, { 3.6893174933594112`*^9, 3.689317664615466*^9}, {3.689317706199317*^9, 3.6893177187339373`*^9}, {3.689317762165682*^9, 3.68931781811528*^9}, { 3.689317866485346*^9, 3.689317967423503*^9}, {3.689318032723822*^9, 3.689318049121161*^9}, 3.68931808915357*^9, {3.6893181294223537`*^9, 3.689318195868187*^9}, {3.689318229004224*^9, 3.689318330257516*^9}, { 3.689318366918085*^9, 3.689318423129676*^9}, {3.689318491471566*^9, 3.689318569613056*^9}, {3.689318609111421*^9, 3.689318639028376*^9}, { 3.689318687989781*^9, 3.6893187389230423`*^9}, {3.6893187749461107`*^9, 3.68931878572104*^9}, {3.6893188169860888`*^9, 3.689318908394405*^9}, { 3.689319015591426*^9, 3.689319036536147*^9}, {3.6893190853720922`*^9, 3.689319123452591*^9}, {3.6893194732734547`*^9, 3.689319546116889*^9}, { 3.689319601397596*^9, 3.6893197548909388`*^9}, {3.689319806212854*^9, 3.689319831489183*^9}, {3.68931988351196*^9, 3.689319973701537*^9}, { 3.689320094099832*^9, 3.689320135658744*^9}, 3.6893201682975883`*^9, { 3.6893203635985823`*^9, 3.689320413872054*^9}, {3.689320556687022*^9, 3.689320565931828*^9}, {3.689320696098165*^9, 3.689320745423152*^9}, { 3.6893207802705584`*^9, 3.6893209165183887`*^9}, {3.689320973033746*^9, 3.6893209734385138`*^9}, {3.68932101243256*^9, 3.6893210188537617`*^9}, { 3.689321050553029*^9, 3.68932105627885*^9}, {3.689321093520377*^9, 3.6893211050176277`*^9}, {3.689321246324709*^9, 3.689321272836873*^9}, { 3.689321306251243*^9, 3.689321542425222*^9}, {3.68932197013457*^9, 3.6893220515483913`*^9}, {3.689322089531638*^9, 3.689322108092111*^9}, { 3.6893221662954063`*^9, 3.6893221847722692`*^9}, {3.689322226500692*^9, 3.6893222315563993`*^9}, {3.689325683934207*^9, 3.6893257198519783`*^9}, 3.689325778079419*^9, {3.689326103367578*^9, 3.6893261320245523`*^9}, { 3.6893263930479317`*^9, 3.689326413318061*^9}, {3.689326983291038*^9, 3.68932704330896*^9}, {3.689336316133583*^9, 3.689336451451892*^9}, { 3.689336501083947*^9, 3.68933650453929*^9}, {3.689354117425165*^9, 3.689354172076281*^9}, {3.68935427969814*^9, 3.689354315785864*^9}, { 3.689354369276455*^9, 3.6893543696053057`*^9}, {3.689354405589511*^9, 3.689354406738469*^9}, {3.689354540282134*^9, 3.6893545487163267`*^9}, { 3.689356753823598*^9, 3.6893567567174387`*^9}, {3.6900102812019587`*^9, 3.69001031407333*^9}, {3.690014275272162*^9, 3.690014283225862*^9}, { 3.690014433662407*^9, 3.690014433724465*^9}, {3.690014531821363*^9, 3.690014568066258*^9}, {3.690014608490662*^9, 3.690014791390048*^9}, { 3.690014883817154*^9, 3.690014925547941*^9}, {3.690014993655266*^9, 3.690015030877501*^9}, {3.690015129316606*^9, 3.690015265664569*^9}, { 3.6900153228566647`*^9, 3.690015367005727*^9}, {3.690015449572548*^9, 3.6900155336123047`*^9}, {3.690015613539809*^9, 3.690015634513668*^9}, { 3.690015673756105*^9, 3.690015734720138*^9}, {3.6900159276907997`*^9, 3.690015959321364*^9}, {3.690016052702888*^9, 3.690016085270166*^9}, 3.6900161541875668`*^9, 3.690016397904635*^9, {3.6900164586005373`*^9, 3.690016465076882*^9}, {3.690016497225245*^9, 3.6900165684596043`*^9}, { 3.690016600198985*^9, 3.690016647551776*^9}, {3.690018263474236*^9, 3.690018566278912*^9}, {3.6900186322608624`*^9, 3.690018676946314*^9}, { 3.6900187631460247`*^9, 3.6900189280642033`*^9}, {3.6900189788699017`*^9, 3.690019028016082*^9}, {3.690019069562779*^9, 3.690019192607036*^9}, { 3.690021211243012*^9, 3.690021236260908*^9}, {3.690021292999816*^9, 3.690021298700183*^9}, {3.69002146390516*^9, 3.690021467920192*^9}, { 3.690021560599689*^9, 3.69002158214142*^9}, 3.690024000032761*^9, { 3.690024052188675*^9, 3.6900240532266493`*^9}, {3.690024689771368*^9, 3.690024690249024*^9}, {3.6900261486601963`*^9, 3.690026153587755*^9}, 3.690026409390676*^9, {3.6900264517198973`*^9, 3.690026484671687*^9}, { 3.690026523231735*^9, 3.690026534308647*^9}, {3.69002670620866*^9, 3.690026716595186*^9}, {3.6900867453285713`*^9, 3.6900870369743423`*^9}, { 3.690715099937725*^9, 3.690715110593443*^9}, {3.6907151964099817`*^9, 3.690715226029293*^9}, 3.690776562233994*^9, {3.690776606376223*^9, 3.690776611552046*^9}, {3.6907768841406727`*^9, 3.690776962963436*^9}, 3.690777007703939*^9, 3.690777113317596*^9, {3.6955560280594482`*^9, 3.695556030851334*^9}, {3.699854978389835*^9, 3.699854981493453*^9}}], Cell[TextData[StyleBox["2. Scale up each fitness value by the number of \ generations we calculated above and calculate the new equilibrium frequencies \ for the new mutation rate.", FontWeight->"Plain"]], "Text", CellChangeTimes->{{3.6900266899683867`*^9, 3.6900266987041893`*^9}, { 3.6900866533431263`*^9, 3.690086700371307*^9}, {3.6900867314907103`*^9, 3.690086736907812*^9}, {3.690776886916007*^9, 3.690776900427383*^9}, { 3.6907770340244513`*^9, 3.6907771087408113`*^9}, {3.6907772504767847`*^9, 3.690777254658684*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"output", "=", "outputUnscaled"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "<=", RowBox[{"Length", "[", "freqs", "]"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"fitness", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "<=", "mutclasses"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"newFit", "=", SuperscriptBox[ RowBox[{ RowBox[{ "output", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], "gens"]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ "output", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], "=", "newFit"}], ";", "\[IndentingNewLine]", RowBox[{"fitness", "=", RowBox[{"Append", "[", RowBox[{"fitness", ",", "newFit"}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"output", "[", RowBox[{"[", "i", "]"}], "]"}], "[", RowBox[{"[", RowBox[{"mutclasses", "+", "1"}], "]"}], "]"}], "=", RowBox[{"newU", "//", "N"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "calculate", " ", "new", " ", "equilibrium", " ", "frequencies", " ", "for", " ", "the", " ", "new", " ", "fitness", " ", "values"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"eqfreqs", "=", RowBox[{"CalculateEquilibriumFrequencies", "[", RowBox[{"fitness", ",", RowBox[{"makeMutMatrix", "[", RowBox[{"newU", ",", RowBox[{ "seqLength", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", "mutclasses"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "<=", "mutclasses"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "=", RowBox[{"mutclasses", "+", "1"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ "output", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", RowBox[{"k", "+", "j"}], "\[RightDoubleBracket]"}], "=", RowBox[{ "eqfreqs", "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "output", " ", "the", " ", "scaled", " ", "fitness", " ", "values", " ", "and", " ", "equilibrium", " ", "frequencies"}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Export", "[", RowBox[{ RowBox[{ RowBox[{"NotebookDirectory", "[", "]"}], "<>", "\"\\"", "<>", RowBox[{"ToString", "[", "mutclasses", "]"}], "<>", "\"\<_\>\"", "<>", RowBox[{"ToString", "[", "var", "]"}], "<>", "\"\<.txt\>\""}], ",", "output", ",", "\"\\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.686312779686659*^9, 3.6863127836748857`*^9}, { 3.686312933708147*^9, 3.686312934513651*^9}, {3.6863130306962013`*^9, 3.686313145837989*^9}, {3.686313326226014*^9, 3.68631335460006*^9}, 3.686313406522336*^9, {3.688136813962337*^9, 3.6881368824060307`*^9}, { 3.688136921443454*^9, 3.688137065746949*^9}, {3.68819246769683*^9, 3.6881925712581787`*^9}, {3.688192620490706*^9, 3.688192696593978*^9}, { 3.688192752936054*^9, 3.688192857573505*^9}, {3.6881929294372168`*^9, 3.688192936836157*^9}, {3.688193075508675*^9, 3.688193078082035*^9}, { 3.688193145531201*^9, 3.68819317966425*^9}, {3.688193211739992*^9, 3.6881932222723913`*^9}, {3.688193334901696*^9, 3.688193377851647*^9}, { 3.6881934335487003`*^9, 3.688193446141795*^9}, {3.688193539923545*^9, 3.688193540051264*^9}, {3.688193691006092*^9, 3.688193704143471*^9}, { 3.688193763913682*^9, 3.688193826125889*^9}, 3.6881939017783737`*^9, { 3.688193933413761*^9, 3.688193962363928*^9}, {3.688278693146368*^9, 3.688278696566835*^9}, {3.688361025932762*^9, 3.688361084734771*^9}, { 3.688361135159213*^9, 3.6883611982681026`*^9}, {3.68836123309415*^9, 3.688361295234538*^9}, {3.688361340492219*^9, 3.688361486887808*^9}, { 3.688361534793385*^9, 3.688361546143691*^9}, {3.688361587102516*^9, 3.688361665518302*^9}, {3.68836173645275*^9, 3.688361814780212*^9}, { 3.688361845538513*^9, 3.6883618747456913`*^9}, 3.6883619913097897`*^9, { 3.688362031486649*^9, 3.68836219799837*^9}, {3.6883624338343763`*^9, 3.68836259719858*^9}, {3.6883626423001137`*^9, 3.688362751876074*^9}, { 3.6883640815267353`*^9, 3.688364103392716*^9}, 3.688364201041992*^9, { 3.688364266266761*^9, 3.688364279684598*^9}, {3.688364327472629*^9, 3.688364404977871*^9}, {3.688364440068295*^9, 3.6883644414988403`*^9}, { 3.6888149149149237`*^9, 3.68881494177318*^9}, {3.6888150050309362`*^9, 3.6888150488514147`*^9}, {3.688815094005542*^9, 3.6888151318580923`*^9}, { 3.688815167137295*^9, 3.688815247456152*^9}, {3.6888153129194736`*^9, 3.688815332370713*^9}, {3.689316457076325*^9, 3.6893164941688128`*^9}, { 3.6893165287940598`*^9, 3.689316560864029*^9}, 3.6893166132811413`*^9, { 3.6893174933594112`*^9, 3.689317664615466*^9}, {3.689317706199317*^9, 3.6893177187339373`*^9}, {3.689317762165682*^9, 3.68931781811528*^9}, { 3.689317866485346*^9, 3.689317967423503*^9}, {3.689318032723822*^9, 3.689318049121161*^9}, 3.68931808915357*^9, {3.6893181294223537`*^9, 3.689318195868187*^9}, {3.689318229004224*^9, 3.689318330257516*^9}, { 3.689318366918085*^9, 3.689318423129676*^9}, {3.689318491471566*^9, 3.689318569613056*^9}, {3.689318609111421*^9, 3.689318639028376*^9}, { 3.689318687989781*^9, 3.6893187389230423`*^9}, {3.6893187749461107`*^9, 3.68931878572104*^9}, {3.6893188169860888`*^9, 3.689318908394405*^9}, { 3.689319015591426*^9, 3.689319036536147*^9}, {3.6893190853720922`*^9, 3.689319123452591*^9}, {3.6893194732734547`*^9, 3.689319546116889*^9}, { 3.689319601397596*^9, 3.6893197548909388`*^9}, {3.689319806212854*^9, 3.689319831489183*^9}, {3.68931988351196*^9, 3.689319973701537*^9}, { 3.689320094099832*^9, 3.689320135658744*^9}, 3.6893201682975883`*^9, { 3.6893203635985823`*^9, 3.689320413872054*^9}, {3.689320556687022*^9, 3.689320565931828*^9}, {3.689320696098165*^9, 3.689320745423152*^9}, { 3.6893207802705584`*^9, 3.6893209165183887`*^9}, {3.689320973033746*^9, 3.6893209734385138`*^9}, {3.68932101243256*^9, 3.6893210188537617`*^9}, { 3.689321050553029*^9, 3.68932105627885*^9}, {3.689321093520377*^9, 3.6893211050176277`*^9}, {3.689321246324709*^9, 3.689321272836873*^9}, { 3.689321306251243*^9, 3.689321542425222*^9}, {3.68932197013457*^9, 3.6893220515483913`*^9}, {3.689322089531638*^9, 3.689322108092111*^9}, { 3.6893221662954063`*^9, 3.6893221847722692`*^9}, {3.689322226500692*^9, 3.6893222315563993`*^9}, {3.689325683934207*^9, 3.6893257198519783`*^9}, 3.689325778079419*^9, {3.689326103367578*^9, 3.6893261320245523`*^9}, { 3.6893263930479317`*^9, 3.689326413318061*^9}, {3.689326983291038*^9, 3.68932704330896*^9}, {3.689336316133583*^9, 3.689336451451892*^9}, { 3.689336501083947*^9, 3.68933650453929*^9}, {3.689354117425165*^9, 3.689354172076281*^9}, {3.68935427969814*^9, 3.689354315785864*^9}, { 3.689354369276455*^9, 3.6893543696053057`*^9}, {3.689354405589511*^9, 3.689354406738469*^9}, {3.689354540282134*^9, 3.6893545487163267`*^9}, { 3.689356753823598*^9, 3.6893567567174387`*^9}, {3.6900102812019587`*^9, 3.69001031407333*^9}, {3.690014275272162*^9, 3.690014283225862*^9}, { 3.690014433662407*^9, 3.690014433724465*^9}, {3.690014531821363*^9, 3.690014568066258*^9}, {3.690014608490662*^9, 3.690014791390048*^9}, { 3.690014883817154*^9, 3.690014925547941*^9}, {3.690014993655266*^9, 3.690015030877501*^9}, {3.690015129316606*^9, 3.690015265664569*^9}, { 3.6900153228566647`*^9, 3.690015367005727*^9}, {3.690015449572548*^9, 3.6900155336123047`*^9}, {3.690015613539809*^9, 3.690015634513668*^9}, { 3.690015673756105*^9, 3.690015734720138*^9}, {3.6900159276907997`*^9, 3.690015959321364*^9}, {3.690016052702888*^9, 3.690016085270166*^9}, 3.6900161541875668`*^9, 3.690016397904635*^9, {3.6900164586005373`*^9, 3.690016465076882*^9}, {3.690016497225245*^9, 3.6900165684596043`*^9}, { 3.690016600198985*^9, 3.690016647551776*^9}, {3.690018263474236*^9, 3.690018566278912*^9}, {3.6900186322608624`*^9, 3.690018676946314*^9}, { 3.6900187631460247`*^9, 3.6900189280642033`*^9}, {3.6900189788699017`*^9, 3.690019028016082*^9}, {3.690019069562779*^9, 3.690019192607036*^9}, { 3.690021211243012*^9, 3.690021236260908*^9}, {3.690021292999816*^9, 3.690021298700183*^9}, {3.69002146390516*^9, 3.690021467920192*^9}, { 3.690021560599689*^9, 3.69002158214142*^9}, 3.690024000032761*^9, { 3.690024052188675*^9, 3.6900240532266493`*^9}, {3.690024689771368*^9, 3.690024690249024*^9}, {3.6900261486601963`*^9, 3.690026153587755*^9}, 3.690026409390676*^9, {3.6900264517198973`*^9, 3.690026484671687*^9}, { 3.690026523231735*^9, 3.690026534308647*^9}, {3.69002670620866*^9, 3.690026716595186*^9}, {3.6900867453285713`*^9, 3.6900870369743423`*^9}, { 3.690715099937725*^9, 3.690715110593443*^9}, {3.6907151964099817`*^9, 3.690715226029293*^9}, 3.690776562233994*^9, {3.690776606376223*^9, 3.690776611552046*^9}, {3.6907768841406727`*^9, 3.690776962963436*^9}, { 3.690777007703939*^9, 3.690777017959713*^9}, 3.690777123749424*^9, { 3.69077723846877*^9, 3.690777238803846*^9}, {3.690777741908958*^9, 3.6907777523702183`*^9}, {3.690777813379579*^9, 3.690777825625977*^9}, { 3.694429652900467*^9, 3.694429702445593*^9}, {3.699854942496099*^9, 3.699854964303466*^9}, {3.700276643280293*^9, 3.7002766539921*^9}, { 3.7004580839366617`*^9, 3.700458099479884*^9}, {3.700459677548201*^9, 3.700459691282785*^9}, {3.70201386210637*^9, 3.702013870424161*^9}, 3.70201390992305*^9, {3.702361610204623*^9, 3.702361644538759*^9}}], Cell[TextData[{ StyleBox["Calculate error thresholds\n", "Subsection"], "For each species we will calculate the fitness value, at which the \ frequency of the master sequence drops below 1% by depressing the whole \ fitness landscape in increments of ", Cell[BoxData[ FormBox[ SuperscriptBox["10", RowBox[{"-", "12"}]], TraditionalForm]]], "." }], "Text", CellChangeTimes->{{3.6900266899683867`*^9, 3.6900266987041893`*^9}, { 3.6900866533431263`*^9, 3.690086700371307*^9}, {3.6900867314907103`*^9, 3.690086736907812*^9}, {3.690776886916007*^9, 3.690776900427383*^9}, { 3.6907770340244513`*^9, 3.6907771087408113`*^9}, {3.6907772504767847`*^9, 3.690777254658684*^9}, {3.690777394778377*^9, 3.690777483983303*^9}, 3.690778513068492*^9, {3.6908825964321413`*^9, 3.690882621903446*^9}, { 3.695555829385159*^9, 3.6955558327615*^9}, {3.702702404812491*^9, 3.7027024049652576`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"error", "=", "outputUnscaled"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", RowBox[{"Length", "[", "freqs", "]"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"equilibrium", " ", "frequencies"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"q", "=", RowBox[{"makeMutMatrix", "[", RowBox[{"u", ",", RowBox[{ "seqLength", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", "mutclasses"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"f", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ "outputUnscaled", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "mutclasses"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"start", "=", RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"f", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "-", "1"}], ")"}], "*", RowBox[{"10", "^", "12"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"threshold", "=", "0.01"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "<", "start"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"fint", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"IntegerPart", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ "f", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "-", "1"}], ")"}], "*", RowBox[{"10", "^", "12"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "mutclasses"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"k", "=", "2"}], ",", RowBox[{"k", "\[LessEqual]", " ", "mutclasses"}], ",", RowBox[{"k", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ "fint", "\[LeftDoubleBracket]", "k", "\[RightDoubleBracket]"}], ">", "0"}], ",", RowBox[{ RowBox[{ "f", "\[LeftDoubleBracket]", "k", "\[RightDoubleBracket]"}], "=", RowBox[{"1", "+", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ "fint", "\[LeftDoubleBracket]", "k", "\[RightDoubleBracket]"}], "-", "1"}], ")"}], "*", RowBox[{"10", "^", RowBox[{"-", "12"}]}]}]}]}]}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"f", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "=", RowBox[{"1", "+", RowBox[{ RowBox[{"(", RowBox[{"start", "-", "j"}], ")"}], SuperscriptBox["10", RowBox[{"-", "12"}]]}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"effreqs", "=", RowBox[{"CalculateEquilibriumFrequencies", "[", RowBox[{"f", ",", "q"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ "effreqs", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "<", "threshold"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"j", "=", "start"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "<", RowBox[{"Length", "[", "f", "]"}]}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{ "error", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], "=", RowBox[{ RowBox[{"f", "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}], " ", "//", "N"}]}], ";"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "<=", "mutclasses"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "=", RowBox[{"mutclasses", "+", "1"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ "error", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", RowBox[{"k", "+", "j"}], "\[RightDoubleBracket]"}], "=", RowBox[{ "effreqs", "\[LeftDoubleBracket]", "j", "\[RightDoubleBracket]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Export", "[", RowBox[{ RowBox[{ RowBox[{"NotebookDirectory", "[", "]"}], "<>", "\"\\"", "<>", RowBox[{"ToString", "[", "mutclasses", "]"}], "<>", "\"\<_\>\"", "<>", RowBox[{"ToString", "[", "var", "]"}], "<>", "\"\<.txt\>\""}], ",", "error", ",", "\"\\""}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.690777506952075*^9, 3.690777518385991*^9}, { 3.690777574862831*^9, 3.690777648811405*^9}, {3.6907779046567802`*^9, 3.6907780006709967`*^9}, {3.6907785232780657`*^9, 3.690778581292445*^9}, { 3.690778663909189*^9, 3.690778667451537*^9}, {3.690778705362577*^9, 3.690778724714971*^9}, {3.690778771819422*^9, 3.690778804682802*^9}, { 3.690778841880958*^9, 3.6907788421449614`*^9}, {3.690779076518959*^9, 3.6907790766197243`*^9}, {3.690785593685339*^9, 3.690785941694025*^9}, { 3.690785975556501*^9, 3.690785986331049*^9}, {3.6907860675175333`*^9, 3.690786072668462*^9}, {3.6907861161866207`*^9, 3.6907862363775787`*^9}, { 3.69078630760909*^9, 3.690786323752967*^9}, {3.690786376600691*^9, 3.690786431686191*^9}, {3.690786496388328*^9, 3.690786539964107*^9}, { 3.6907866281572523`*^9, 3.690786654132812*^9}, 3.690786699944112*^9, 3.6907867465851383`*^9, {3.690786807318619*^9, 3.690786886086828*^9}, { 3.690786926869684*^9, 3.6907869830781507`*^9}, {3.693139895461586*^9, 3.693139900332549*^9}, 3.693139948772622*^9, {3.6931409261778708`*^9, 3.693140931801476*^9}, {3.693141007867782*^9, 3.693141011031567*^9}, { 3.693141124874672*^9, 3.693141133598893*^9}, {3.6931412401286783`*^9, 3.693141276092708*^9}, {3.693141513188201*^9, 3.6931415181917458`*^9}, { 3.6931415648965883`*^9, 3.693141674238106*^9}, {3.693141707893241*^9, 3.693141712950396*^9}, {3.693141793092668*^9, 3.693141817985427*^9}, 3.6931419047026453`*^9, {3.6931419788858128`*^9, 3.693141985482654*^9}, { 3.6931420677623787`*^9, 3.693142102293478*^9}, {3.693142165865349*^9, 3.693142175056369*^9}, {3.693142424569418*^9, 3.693142443784318*^9}, { 3.693142591572915*^9, 3.69314260398908*^9}, {3.6944178925031023`*^9, 3.6944179002406282`*^9}, {3.695556053086288*^9, 3.6955561040225267`*^9}, { 3.7002765340474777`*^9, 3.7002766314576683`*^9}, {3.700458112447316*^9, 3.700458123365725*^9}, {3.700458172652842*^9, 3.7004581844943047`*^9}, { 3.7004597690024548`*^9, 3.7004598673874397`*^9}, {3.700460176092154*^9, 3.700460210458797*^9}, {3.7004603552723913`*^9, 3.700460447869528*^9}, 3.700460484334354*^9, {3.700460516796645*^9, 3.7004607068095207`*^9}, { 3.700460795930235*^9, 3.700460830096644*^9}, {3.700460873826313*^9, 3.700460903073041*^9}, 3.7004609487548733`*^9, {3.700460986403757*^9, 3.700461086103119*^9}, {3.700461128890839*^9, 3.700461177606801*^9}, { 3.7020138445638933`*^9, 3.702013891566616*^9}, 3.702702481396962*^9}] }, Open ]] }, Closed]] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{Full, Full}, WindowMargins->{{24, Automatic}, {Automatic, 0}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, Magnification->1.5, FrontEndVersion->"10.2 for Mac OS X x86 (32-bit, 64-bit Kernel) (July 29, \ 2015)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 276, 4, 137, "Title"], Cell[CellGroupData[{ Cell[881, 30, 112, 1, 96, "Chapter"], Cell[CellGroupData[{ Cell[1018, 35, 173, 2, 95, "Section"], Cell[CellGroupData[{ Cell[1216, 41, 161, 2, 65, "Subsection"], Cell[1380, 45, 178, 4, 46, "Text"], Cell[1561, 51, 1083, 26, 194, "Input"], Cell[2647, 79, 383, 9, 105, "Text"], Cell[3033, 90, 5000, 124, 419, "Input"], Cell[8036, 216, 540, 11, 105, "Text"], Cell[8579, 229, 11126, 231, 1060, "Input"], Cell[19708, 462, 612, 12, 105, "Text"], Cell[20323, 476, 7437, 161, 1094, "Input"], Cell[27763, 639, 454, 10, 76, "Text"], Cell[28220, 651, 2155, 37, 144, "Input"], Cell[30378, 690, 457, 14, 46, "Text"], Cell[30838, 706, 310, 8, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[31185, 719, 101, 1, 51, "Subsection"], Cell[31289, 722, 404, 8, 138, "Text"], Cell[31696, 732, 6017, 132, 719, "Input"] }, Closed]] }, Open ]], Cell[CellGroupData[{ Cell[37762, 870, 90, 1, 95, "Section"], Cell[CellGroupData[{ Cell[37877, 875, 404, 7, 65, "Subsection"], Cell[38284, 884, 290, 7, 46, "Text"], Cell[38577, 893, 4448, 90, 419, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[43062, 988, 191, 2, 51, "Subsection"], Cell[43256, 992, 769, 15, 44, "Input"], Cell[CellGroupData[{ Cell[44050, 1011, 163, 2, 52, "Subsubsection"], Cell[44216, 1015, 338, 6, 46, "Text"], Cell[44557, 1023, 449, 6, 46, "Text"], Cell[45009, 1031, 7279, 108, 149, "Input"], Cell[52291, 1141, 536, 8, 46, "Text"], Cell[52830, 1151, 10686, 185, 544, "Input"], Cell[63519, 1338, 915, 18, 87, "Text"], Cell[64437, 1358, 8770, 190, 1099, "Input"] }, Open ]] }, Closed]] }, Open ]] }, Open ]] }, Open ]] } ] *)