-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathslim_functions.cpp
2472 lines (2014 loc) · 103 KB
/
slim_functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// slim_functions.cpp
// SLiM
//
// Created by Ben Haller on 2/15/19.
// Copyright (c) 2014-2025 Philipp Messer. All rights reserved.
// A product of the Messer Lab, http://messerlab.org/slim/
//
// This file is part of SLiM.
//
// SLiM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// SLiM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with SLiM. If not, see <http://www.gnu.org/licenses/>.
#include "slim_functions.h"
#include "slim_globals.h"
#include "community.h"
#include "species.h"
#include "subpopulation.h"
#include "haplosome.h"
#include "mutation.h"
#include "mutation_type.h"
#include "individual.h"
#include "eidos_rng.h"
#include "json.hpp"
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
extern const char *gSLiMSourceCode_calcFST;
extern const char *gSLiMSourceCode_calcVA;
extern const char *gSLiMSourceCode_calcMeanFroh;
extern const char *gSLiMSourceCode_calcPairHeterozygosity;
extern const char *gSLiMSourceCode_calcHeterozygosity;
extern const char *gSLiMSourceCode_calcWattersonsTheta;
extern const char *gSLiMSourceCode_calcInbreedingLoad;
extern const char *gSLiMSourceCode_calcPi;
extern const char *gSLiMSourceCode_calcSFS;
extern const char *gSLiMSourceCode_calcTajimasD;
extern const char *gSLiMSourceCode_initializeMutationRateFromFile;
extern const char *gSLiMSourceCode_initializeRecombinationRateFromFile;
const std::vector<EidosFunctionSignature_CSP> *Community::SLiMFunctionSignatures(void)
{
// Allocate our own EidosFunctionSignature objects
static std::vector<EidosFunctionSignature_CSP> sim_func_signatures_;
if (!sim_func_signatures_.size())
{
THREAD_SAFETY_IN_ANY_PARALLEL("Community::SLiMFunctionSignatures(): not warmed up");
// Nucleotide utilities
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("codonsToAminoAcids", SLiM_ExecuteFunction_codonsToAminoAcids, kEidosValueMaskString | kEidosValueMaskInt, "SLiM"))->AddInt("codons")->AddArgWithDefault(kEidosValueMaskLogical | kEidosValueMaskInt | kEidosValueMaskOptional | kEidosValueMaskSingleton, "long", nullptr, gStaticEidosValue_LogicalF)->AddLogical_OS("paste", gStaticEidosValue_LogicalT));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("codonsToNucleotides", SLiM_ExecuteFunction_codonsToNucleotides, kEidosValueMaskInt | kEidosValueMaskString, "SLiM"))->AddInt("codons")->AddString_OS("format", EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String("string"))));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("mm16To256", SLiM_ExecuteFunction_mm16To256, kEidosValueMaskFloat, "SLiM"))->AddFloat("mutationMatrix16"));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("mmJukesCantor", SLiM_ExecuteFunction_mmJukesCantor, kEidosValueMaskFloat, "SLiM"))->AddFloat_S("alpha"));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("mmKimura", SLiM_ExecuteFunction_mmKimura, kEidosValueMaskFloat, "SLiM"))->AddFloat_S("alpha")->AddFloat_S("beta"));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("nucleotideCounts", SLiM_ExecuteFunction_nucleotideCounts, kEidosValueMaskInt, "SLiM"))->AddIntString("sequence"));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("nucleotideFrequencies", SLiM_ExecuteFunction_nucleotideFrequencies, kEidosValueMaskFloat, "SLiM"))->AddIntString("sequence"));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("nucleotidesToCodons", SLiM_ExecuteFunction_nucleotidesToCodons, kEidosValueMaskInt, "SLiM"))->AddIntString("sequence"));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("randomNucleotides", SLiM_ExecuteFunction_randomNucleotides, kEidosValueMaskInt | kEidosValueMaskString, "SLiM"))->AddInt_S("length")->AddNumeric_ON("basis", gStaticEidosValueNULL)->AddString_OS("format", EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String("string"))));
// Population genetics utilities (implemented with Eidos code)
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcFST", gSLiMSourceCode_calcFST, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("haplosomes1", gSLiM_Haplosome_Class)->AddObject("haplosomes2", gSLiM_Haplosome_Class)->AddObject_ON("muts", gSLiM_Mutation_Class, gStaticEidosValueNULL)->AddInt_OSN("start", gStaticEidosValueNULL)->AddInt_OSN("end", gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcVA", gSLiMSourceCode_calcVA, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("individuals", gSLiM_Individual_Class)->AddIntObject_S("mutType", gSLiM_MutationType_Class));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcMeanFroh", gSLiMSourceCode_calcMeanFroh, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("individuals", gSLiM_Individual_Class)->AddInt_OS("minimumLength", EidosValue_Int_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Int(1000000)))->AddArgWithDefault(kEidosValueMaskNULL | kEidosValueMaskInt | kEidosValueMaskString | kEidosValueMaskObject | kEidosValueMaskOptional | kEidosValueMaskSingleton, "chromosome", gSLiM_Chromosome_Class, gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcPairHeterozygosity", gSLiMSourceCode_calcPairHeterozygosity, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject_S("haplosome1", gSLiM_Haplosome_Class)->AddObject_S("haplosome2", gSLiM_Haplosome_Class)->AddInt_OSN("start", gStaticEidosValueNULL)->AddInt_OSN("end", gStaticEidosValueNULL)->AddLogical_OS("infiniteSites", gStaticEidosValue_LogicalT));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcHeterozygosity", gSLiMSourceCode_calcHeterozygosity, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("haplosomes", gSLiM_Haplosome_Class)->AddObject_ON("muts", gSLiM_Mutation_Class, gStaticEidosValueNULL)->AddInt_OSN("start", gStaticEidosValueNULL)->AddInt_OSN("end", gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcWattersonsTheta", gSLiMSourceCode_calcWattersonsTheta, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("haplosomes", gSLiM_Haplosome_Class)->AddObject_ON("muts", gSLiM_Mutation_Class, gStaticEidosValueNULL)->AddInt_OSN("start", gStaticEidosValueNULL)->AddInt_OSN("end", gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcInbreedingLoad", gSLiMSourceCode_calcInbreedingLoad, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("haplosomes", gSLiM_Haplosome_Class)->AddIntObject_OSN("mutType", gSLiM_MutationType_Class, gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcPi", gSLiMSourceCode_calcPi, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("haplosomes", gSLiM_Haplosome_Class)->AddObject_ON("muts", gSLiM_Mutation_Class, gStaticEidosValueNULL)->AddInt_OSN("start", gStaticEidosValueNULL)->AddInt_OSN("end", gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcSFS", gSLiMSourceCode_calcSFS, kEidosValueMaskNumeric, "SLiM"))->AddInt_OSN("binCount", gStaticEidosValueNULL)->AddObject_ON("haplosomes", gSLiM_Haplosome_Class, gStaticEidosValueNULL)->AddObject_ON("muts", gSLiM_Mutation_Class, gStaticEidosValueNULL)->AddString_OS("metric", EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String("density")))->AddLogical_OS("fold", gStaticEidosValue_LogicalF));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("calcTajimasD", gSLiMSourceCode_calcTajimasD, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM"))->AddObject("haplosomes", gSLiM_Haplosome_Class)->AddObject_ON("muts", gSLiM_Mutation_Class, gStaticEidosValueNULL)->AddInt_OSN("start", gStaticEidosValueNULL)->AddInt_OSN("end", gStaticEidosValueNULL));
// Other built-in SLiM functions
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("summarizeIndividuals", SLiM_ExecuteFunction_summarizeIndividuals, kEidosValueMaskFloat, "SLiM"))->AddObject("individuals", gSLiM_Individual_Class)->AddInt("dim")->AddNumeric("spatialBounds")->AddString_S("operation")->AddLogicalEquiv_OSN("empty", gStaticEidosValue_Float0)->AddLogical_OS("perUnitArea", gStaticEidosValue_LogicalF)->AddString_OSN("spatiality", gStaticEidosValueNULL));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("treeSeqMetadata", SLiM_ExecuteFunction_treeSeqMetadata, kEidosValueMaskObject | kEidosValueMaskSingleton, gEidosDictionaryRetained_Class, "SLiM"))->AddString_S("filePath")->AddLogical_OS("userData", gStaticEidosValue_LogicalT));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("initializeMutationRateFromFile", gSLiMSourceCode_initializeMutationRateFromFile, kEidosValueMaskVOID, "SLiM"))->AddString_S("path")->AddInt_S("lastPosition")->AddFloat_OS("scale", EidosValue_Float_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float(1e-8)))->AddString_OS("sep", gStaticEidosValue_StringTab)->AddString_OS("dec", gStaticEidosValue_StringPeriod));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("initializeRecombinationRateFromFile", gSLiMSourceCode_initializeRecombinationRateFromFile, kEidosValueMaskVOID, "SLiM"))->AddString_S("path")->AddInt_S("lastPosition")->AddFloat_OS("scale", EidosValue_Float_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float(1e-8)))->AddString_OS("sep", gStaticEidosValue_StringTab)->AddString_OS("dec", gStaticEidosValue_StringPeriod));
// Internal SLiM functions
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("_startBenchmark", SLiM_ExecuteFunction__startBenchmark, kEidosValueMaskVOID, "SLiM"))->AddString_S(gEidosStr_type));
sim_func_signatures_.emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("_stopBenchmark", SLiM_ExecuteFunction__stopBenchmark, kEidosValueMaskFloat | kEidosValueMaskSingleton, "SLiM")));
// ************************************************************************************
//
// object instantiation – add in constructors for SLiM classes that have them
// see also EidosInterpreter::BuiltInFunctions(), which this extends
//
const std::vector<EidosFunctionSignature_CSP> *class_functions = gSLiM_SpatialMap_Class->Functions();
sim_func_signatures_.insert(sim_func_signatures_.end(), class_functions->begin(), class_functions->end());
}
return &sim_func_signatures_;
}
// ************************************************************************************
//
// population genetics utilities
//
#pragma mark -
#pragma mark Population genetics utilities
#pragma mark -
// These are implemented in Eidos, for transparency/modifiability. These strings are globals mostly so the
// formatting of the code looks nice in Xcode; they are used only by Community::SLiMFunctionSignatures().
#pragma mark (float$)calcFST(object<Haplosome> haplosomes1, object<Haplosome> haplosomes2, [No<Mutation> muts = NULL], [Ni$ start = NULL], [Ni$ end = NULL])
const char *gSLiMSourceCode_calcFST =
R"V0G0N({
if ((haplosomes1.length() == 0) | (haplosomes2.length() == 0))
stop("ERROR (calcFST): haplosomes1 and haplosomes2 must both be non-empty.");
species = haplosomes1[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(c(haplosomes1, haplosomes2).individual.subpopulation.species != species))
stop("ERROR (calcFST): all haplosomes must belong to the same species.");
if (!isNULL(muts))
if (any(muts.mutationType.species != species))
stop("ERROR (calcFST): all mutations must belong to the same species as the haplosomes.");
}
chromosome = haplosomes1[0].chromosome;
if (species.chromosomes.length() > 1)
{
if (any(c(haplosomes1, haplosomes2).chromosome != chromosome))
stop("ERROR (calcFST): all haplosomes must be associated with the same chromosome.");
if (!isNULL(muts))
if (any(muts.chromosome != chromosome))
stop("ERROR (calcFST): all mutations must be associated with the same chromosome as the haplosomes.");
}
if (isNULL(muts))
muts = species.subsetMutations(chromosome=chromosome);
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcFST): start must be less than or equal to end.");
if ((start < 0) | (end >= length))
stop("ERROR (calcFST): start and end must be within the bounds of the focal chromosome");
mpos = muts.position;
muts = muts[(mpos >= start) & (mpos <= end)];
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcFST): start and end must both be NULL or both be non-NULL.");
}
// do the calculation; if the FST is undefined, return NULL
p1_p = haplosomes1.mutationFrequenciesInHaplosomes(muts);
p2_p = haplosomes2.mutationFrequenciesInHaplosomes(muts);
mean_p = (p1_p + p2_p) / 2.0;
H_t = 2.0 * mean_p * (1.0 - mean_p);
H_s = p1_p * (1.0 - p1_p) + p2_p * (1.0 - p2_p);
mean_H_t = mean(H_t);
if (isNULL(mean_H_t)) // occurs if muts is zero-length
return NAN;
if (mean_H_t == 0) // occurs if muts is not zero-length but all frequencies are zero
return NAN;
fst = 1.0 - mean(H_s) / mean_H_t;
return fst;
})V0G0N";
#pragma mark (float$)calcVA(object<Individual> individuals, io<MutationType>$ mutType)
const char *gSLiMSourceCode_calcVA =
R"V0G0N({
if (individuals.length() < 2)
stop("ERROR (calcVA): individuals must contain at least two elements.");
// look up an integer mutation type id from the community
if (type(mutType) == "integer") {
mutTypes = community.allMutationTypes;
mutTypeForID = mutTypes[mutTypes.id == mutType];
assert(length(mutTypeForID) == 1, "calcVA() did not find a mutation type with id " + mutType);
mutType = mutTypeForID;
}
// the mutation type dictates the focal species
species = mutType.species;
// all individuals must belong to the focal species
if (community.allSpecies.length() > 1)
if (!all(individuals.subpopulation.species == species))
stop("ERROR (calcVA): all individuals must belong to the same species as mutType.");
return var(individuals.sumOfMutationsOfType(mutType));
})V0G0N";
#pragma mark (float$)calcMeanFroh(object<Individual> individuals, [integer$ minimumLength = 1e6], [Niso<Chromosome>$ chromosome = NULL])
const char *gSLiMSourceCode_calcMeanFroh =
R"V0G0N({
// With zero individuals, we return NAN; it's good to be flexible on
// this, so models don't error out on local extinction and such.
if (length(individuals) == 0)
return NAN;
species = individuals[0].subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(individuals.subpopulation.species != species))
stop("ERROR (calcMeanFroh): calcMeanFroh() requires that all individuals belong to a single species.");
}
if (minimumLength < 0)
stop("ERROR (calcMeanFroh): calcMeanFroh() requires minimumLength >= 0 (" + minimumLength + " supplied).");
// get the chromosomes we will operate over
if (isNULL(chromosome))
{
chromosomes = species.chromosomes;
chromosomes = chromosomes[chromosomes.intrinsicPloidy == 2];
}
else
{
if (type(chromosome) == "integer")
chromosome = species.chromosomesWithIDs(chromosome);
else if (type(chromosome) == "string")
chromosome = species.chromosomesWithSymbols(chromosome);
if (chromosome.species != species)
stop("ERROR (calcMeanFroh): calcMeanFroh() requires that chromosome belong to the same species as individual.");
if (chromosome.intrinsicPloidy != 2)
stop("ERROR (calcMeanFroh): calcMeanFroh() requires that chromosome have intrinsic ploidy 2.");
chromosomes = chromosome;
}
if (chromosomes.length() == 0)
stop("ERROR (calcMeanFroh): no chromosomes with intrinsic ploidy 2 in calcMeanFroh().");
// average over the individuals supplied; some might be skipped over,
// if they have no diploid haplosomes (due to null haplosomes)
total_individuals = 0;
total_froh = 0;
for (individual in individuals)
{
// do the calculation
total_chr_length = 0;
total_roh_length = 0;
for (chr in chromosomes)
{
// get the haplosomes we will operate over
haplosomes = individual.haplosomesForChromosomes(chr, includeNulls=F);
if (haplosomes.length() != 2)
next;
het_pos = individual.mutationsFromHaplosomes("heterozygous").position;
het_pos_1 = c(-1, het_pos);
het_pos_2 = c(het_pos, chr.lastPosition + 1);
roh = (het_pos_2 - het_pos_1) - 1;
// filter the ROH we found by the threshold length passed in
if (minimumLength > 0)
roh = roh[roh >= minimumLength];
total_roh_length = total_roh_length + sum(roh);
total_chr_length = total_chr_length + chr.length;
}
// if total_chr_length is zero, the individual has no chromosome for which
// it is actually diploid, so we can't calculate F_ROH; we skip it
if (total_chr_length == 0)
next;
// we calculate F_ROH as the total ROH lengths divided by the total length
// we add that in to our running total, to average over the individuals
total_froh = total_froh + (total_roh_length / total_chr_length);
total_individuals = total_individuals + 1;
}
// if we got zero individuals that we could actually calculate F_ROH for, we
// return NAN, because it seems like we want to be tolerant of this case;
// the user can handle it as they wish
if (total_individuals == 0)
return NAN;
// return the average F_ROH across individuals it could be calculated for
return total_froh / total_individuals;
})V0G0N";
#pragma mark (float$)calcPairHeterozygosity(object<Haplosome>$ haplosome1, object<Haplosome>$ haplosome2, [Ni$ start = NULL], [Ni$ end = NULL], [l$ infiniteSites = T])
const char *gSLiMSourceCode_calcPairHeterozygosity =
R"V0G0N({
species = haplosome1.individual.subpopulation.species;
if (haplosome2.individual.subpopulation.species != species)
stop("ERROR (calcPairHeterozygosity): haplosome1 and haplosome2 must belong to the same species.");
chromosome = haplosome1.chromosome;
if (haplosome2.chromosome != chromosome)
stop("ERROR (calcPairHeterozygosity): haplosome1 and haplosome2 must belong to the same chromosome.");
muts1 = haplosome1.mutations;
muts2 = haplosome2.mutations;
length = chromosome.length;
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcPairHeterozygosity): start must be less than or equal to end.");
if ((start < 0) | (end >= length))
stop("ERROR (calcPairHeterozygosity): start and end must be within the bounds of the focal chromosome");
m1pos = muts1.position;
m2pos = muts2.position;
muts1 = muts1[(m1pos >= start) & (m1pos <= end)];
muts2 = muts2[(m2pos >= start) & (m2pos <= end)];
length = end - start + 1;
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcPairHeterozygosity): start and end must both be NULL or both be non-NULL.");
}
// do the calculation
unshared = setSymmetricDifference(muts1, muts2);
if (!infiniteSites)
unshared = unique(unshared.position, preserveOrder=F);
return size(unshared) / length;
})V0G0N";
#pragma mark (float$)calcHeterozygosity(o<Haplosome> haplosomes, [No<Mutation> muts = NULL], [Ni$ start = NULL], [Ni$ end = NULL])
const char *gSLiMSourceCode_calcHeterozygosity =
R"V0G0N({
if (haplosomes.length() == 0)
stop("ERROR (calcHeterozygosity): haplosomes must be non-empty.");
species = haplosomes[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(haplosomes.individual.subpopulation.species != species))
stop("ERROR (calcHeterozygosity): all haplosomes must belong to the same species.");
if (!isNULL(muts))
if (any(muts.mutationType.species != species))
stop("ERROR (calcHeterozygosity): all mutations must belong to the same species as the haplosomes.");
}
chromosome = haplosomes[0].chromosome;
if (species.chromosomes.length() > 1)
{
if (any(haplosomes.chromosome != chromosome))
stop("ERROR (calcHeterozygosity): all haplosomes must be associated with the same chromosome.");
if (!isNULL(muts))
if (any(muts.chromosome != chromosome))
stop("ERROR (calcHeterozygosity): all mutations must be associated with the same chromosome as the haplosomes.");
}
length = chromosome.length;
if (isNULL(muts))
muts = species.subsetMutations(chromosome=chromosome);
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcHeterozygosity): start must be less than or equal to end.");
if ((start < 0) | (end >= length))
stop("ERROR (calcHeterozygosity): start and end must be within the bounds of the focal chromosome");
mpos = muts.position;
muts = muts[(mpos >= start) & (mpos <= end)];
length = end - start + 1;
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcHeterozygosity): start and end must both be NULL or both be non-NULL.");
}
// do the calculation
p = haplosomes.mutationFrequenciesInHaplosomes(muts);
heterozygosity = 2 * sum(p * (1 - p)) / length;
return heterozygosity;
})V0G0N";
#pragma mark (float$)calcWattersonsTheta(o<Haplosome> haplosomes, [No<Mutation> muts = NULL], [Ni$ start = NULL], [Ni$ end = NULL])
const char *gSLiMSourceCode_calcWattersonsTheta =
R"V0G0N({
if (haplosomes.length() == 0)
stop("ERROR (calcWattersonsTheta): haplosomes must be non-empty.");
species = haplosomes[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(haplosomes.individual.subpopulation.species != species))
stop("ERROR (calcWattersonsTheta): all haplosomes must belong to the same species.");
if (!isNULL(muts))
if (any(muts.mutationType.species != species))
stop("ERROR (calcWattersonsTheta): all mutations must belong to the same species as the haplosomes.");
}
chromosome = haplosomes[0].chromosome;
if (species.chromosomes.length() > 1)
{
if (any(haplosomes.chromosome != chromosome))
stop("ERROR (calcWattersonsTheta): all haplosomes must be associated with the same chromosome.");
if (!isNULL(muts))
if (any(muts.chromosome != chromosome))
stop("ERROR (calcWattersonsTheta): all mutations must be associated with the same chromosome as the haplosomes.");
}
length = chromosome.length;
if (isNULL(muts))
muts = species.subsetMutations(chromosome=chromosome);
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcWattersonsTheta): start must be less than or equal to end.");
if ((start < 0) | (end >= length))
stop("ERROR (calcWattersonsTheta): start and end must be within the bounds of the focal chromosome");
mpos = muts.position;
muts = muts[(mpos >= start) & (mpos <= end)];
length = end - start + 1;
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcWattersonsTheta): start and end must both be NULL or both be non-NULL.");
}
// narrow down to the mutations that are actually present in the haplosomes and aren't fixed
p = haplosomes.mutationFrequenciesInHaplosomes(muts);
muts = muts[(p != 0.0) & (p != 1.0)];
// do the calculation
k = size(muts);
n = haplosomes.size();
a_n = sum(1 / 1:(n-1));
theta = (k / a_n) / length;
return theta;
})V0G0N";
#pragma mark (float$)calcInbreedingLoad(object<Haplosome> haplosomes, [Nio<MutationType>$ mutType = NULL])
const char *gSLiMSourceCode_calcInbreedingLoad =
R"V0G0N({
// look up an integer mutation type id from the community
if (type(mutType) == "integer") {
mutTypes = community.allMutationTypes;
mutTypeForID = mutTypes[mutTypes.id == mutType];
assert(length(mutTypeForID) == 1, "calcInbreedingLoad() did not find a mutation type with id " + mutType);
mutType = mutTypeForID;
}
if (haplosomes.length() == 0)
stop("ERROR (calcInbreedingLoad): haplosomes must be non-empty.");
species = haplosomes[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(haplosomes.individual.subpopulation.species != species))
stop("ERROR (calcInbreedingLoad): all haplosomes must belong to the same species.");
if (!isNULL(mutType))
if (mutType.species != species)
stop("ERROR (calcInbreedingLoad): mutType must belong to the same species as the haplosomes.");
}
chromosome = haplosomes[0].chromosome;
if (species.chromosomes.length() > 1)
{
if (any(haplosomes.chromosome != chromosome))
stop("ERROR (calcInbreedingLoad): all haplosomes must be associated with the same chromosome.");
}
// get the focal mutations and narrow down to those that are deleterious
if (isNULL(mutType))
muts = species.subsetMutations(chromosome=chromosome);
else
muts = species.subsetMutations(mutType=mutType, chromosome=chromosome);
muts = muts[muts.selectionCoeff < 0.0];
// get frequencies and focus on those that are in the haplosomes
q = haplosomes.mutationFrequenciesInHaplosomes(muts);
inHaplosomes = (q > 0);
muts = muts[inHaplosomes];
q = q[inHaplosomes];
// fetch selection coefficients; note that we use the negation of
// SLiM's selection coefficient, following Morton et al. 1956's usage
s = -muts.selectionCoeff;
// replace s > 1.0 with s == 1.0; a mutation can't be more lethal
// than lethal (this can happen when drawing from a gamma distribution)
s[s > 1.0] = 1.0;
// get h for each mutation; note that this will not work if changing
// h using mutationEffect() callbacks or other scripted approaches
h = muts.mutationType.dominanceCoeff;
// calculate number of haploid lethal equivalents (B or inbreeding load)
// this equation is from Morton et al. 1956
return (sum(q*s) - sum(q^2*s) - 2*sum(q*(1-q)*s*h));
})V0G0N";
#pragma mark (float$)calcPi(object<Haplosome> haplosomes, [No<Mutation> muts = NULL], [Ni$ start = NULL], [Ni$ end = NULL])
const char *gSLiMSourceCode_calcPi =
R"V0G0N({
if (haplosomes.length() < 2)
stop("ERROR (calcPi): haplosomes must contain at least two elements.");
species = haplosomes[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(haplosomes.individual.subpopulation.species != species))
stop("ERROR (calcPi): all haplosomes must belong to the same species.");
if (!isNULL(muts))
if (any(muts.mutationType.species != species))
stop("ERROR (calcPi): all mutations must belong to the same species as the haplosomes.");
}
chromosome = haplosomes[0].chromosome;
if (species.chromosomes.length() > 1)
{
if (any(haplosomes.chromosome != chromosome))
stop("ERROR (calcPi): all haplosomes must be associated with the same chromosome.");
if (!isNULL(muts))
if (any(muts.chromosome != chromosome))
stop("ERROR (calcPi): all mutations must be associated with the same chromosome as the haplosomes.");
}
length = chromosome.length;
if (isNULL(muts))
muts = species.subsetMutations(chromosome=chromosome);
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcPi): start must be less than or equal to end.");
if ((start < 0) | (end >= length))
stop("ERROR (calcPi): start and end must be within the bounds of the focal chromosome");
mpos = muts.position;
muts = muts[(mpos >= start) & (mpos <= end)];
length = end - start + 1;
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcPi): start and end must both be NULL or both be non-NULL.");
}
// narrow down to the mutations that are actually present in the haplosomes and aren't fixed
p = haplosomes.mutationFrequenciesInHaplosomes(muts);
muts = muts[(p != 0.0) & (p != 1.0)];
// do the calculation
// obtain counts of variant sequences for all segregating sites
varCount = haplosomes.mutationCountsInHaplosomes(muts);
// total count of sequences minus count of variant sequences equals count of invariant sequences
invarCount = haplosomes.size() - varCount;
// count of pairwise differences per site is the product of counts of both alleles
// (equation 1 in Korunes and Samuk 2021); this is then summed for all sites
diffs = sum(varCount * invarCount);
// pi is the ratio of pairwise differences to number of possible combinations of the given sequences
pi = diffs / ((haplosomes.size() * (haplosomes.size() - 1)) / 2);
// pi is conventionally averaged per site (consistent with SLiM's calculation of Watterson's theta)
avg_pi = pi / length;
return avg_pi;
})V0G0N";
#pragma mark (numeric)calcSFS([Ni$ binCount = NULL], [No<Haplosome> haplosomes = NULL], [No<Mutation> muts = NULL], [string$ metric = "density"], [logical$ fold = F])
const char *gSLiMSourceCode_calcSFS =
R"V0G0N({
// first determine the haplosomes and the species
if (isNULL(haplosomes)) {
if (community.allSpecies.length() != 1)
stop("ERROR (): calcSFS() can only infer the value of haplosomes in a single-species model; otherwise, you need to supply the specific haplosomes to be used.");
species = community.allSpecies;
haplosomes = sim.subpopulations.haplosomesNonNull;
}
else
{
if (haplosomes.length() == 0)
stop("ERROR (calcSFS): haplosomes must be non-empty.");
species = haplosomes[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(haplosomes.individual.subpopulation.species != species))
stop("ERROR (calcSFS): all haplosomes must belong to the same species.");
}
// exclude null haplosomes silently
haplosomes = haplosomes[!haplosomes.isNullHaplosome];
}
// validate binCount
if (!isNULL(binCount))
if ((binCount <= 0) | (binCount > 100000))
stop("ERROR (calcSFS): binCount must be in the range [1, 100000], or NULL.");
// if no haplosomes are supplied, we don't want to error (we want to work
// even when called on an empty simulation, for ease of use), so we just
// return zeros; note after this point haplosomes is guaranteed non-empty
if (haplosomes.length() == 0)
{
if (isNULL(binCount))
return integer(0);
return float(binCount);
}
// a NULL binCount means: each haplosome is a sample, and bins should be
// counts, not frequency bins; with N samples, we have bins for the counts
// from 1 to N-1 (here we do 0 to N, we will remove the end bins downstream)
// note for this mode we do require that all haplosomes belong to a single
// chromosome; counts combined across different haplosomes are not valid
// in the general case.
binsAreSampleCounts = F;
if (isNULL(binCount))
{
chromosome = haplosomes[0].chromosome;
if (any(haplosomes.chromosome != chromosome))
stop("ERROR (calcSFS): when binCount is NULL, all haplosomes must be associated with the same chromosome; counts should be within a single chromosome, since a different number of haplosomes could be present for different chromosomes.");
binCount = haplosomes.length() + 1; // 0 to number of haplosomes
binsAreSampleCounts = T;
}
// apart from the case above, we do not need to require a single chromosome;
// we work with all mutations in the model, even if the haplosomes supplied
// belong to a single chromosome. this works because mutations that are not
// present in any of the supplied haplosomes will have a frequency of zero,
// and those will be filtered out below.
if (isNULL(muts))
{
muts = species.mutations;
}
else
{
if (any(muts.chromosome.species != species))
stop("ERROR (calcSFS): all mutations in muts must belong to the same species as the haplosomes; an SFS can be calculated only within a single species.");
}
if (!binsAreSampleCounts)
{
// get the frequencies; note mutationFrequenciesInHaplosomes() is smart enough
// to assess the frequency of each mutation only within the haplosomes that
// are associated with the same chromosome as the mutation, so this should do
// the right thing even in multichrom models.
freqs = haplosomes.mutationFrequenciesInHaplosomes(muts);
// filter out frequencies of zero; they should not influence the SFS.
freqs = freqs[freqs != 0.0];
// discretize the frequencies into the specified number of bins
bins = pmin(asInteger(floor(freqs * binCount)), binCount - 1);
// tabulate the number of mutations in each frequency bin to make a histogram
tallies = tabulate(bins, maxbin=binCount-1);
}
else
{
// this is the "binCount=NULL" case, where each bin is an integer count
// we handle this separately to avoid possible float numerical error
counts = haplosomes.mutationCountsInHaplosomes(muts);
// filter out counts of zero; they should not influence the SFS.
counts = counts[counts != 0.0];
// tabulate the number of mutations in each count bin to make a histogram
tallies = tabulate(counts, maxbin=binCount-1);
// unlike above (frequency bins), with count bins we discard the bottom
// and top bins; count bins span [1, N-1]; the top bin might contain fixed
// mutations in SLiM, but they are not empirically observable
if (binsAreSampleCounts)
tallies = tallies[1:(length(tallies)-2)];
}
// "fold" the SFS if requested, combining the first and last value, and on
// to the center; this is often done empirically because you don't know
// which allele is ancestral and which is derived. the tricky thing is
// what to do with the central bin, if there is an odd number of bins; we
// add it to itself, but the central bin could be handled other ways too,
// such as excluding that data point (which the user can do after).
if (fold & (size(tallies) >= 2))
{
midpoint = (length(tallies) - 1) / 2;
leftSeq = asInteger(seq(from=0, to=midpoint));
rightSeq = asInteger(seq(from=length(tallies)-1, to=midpoint));
tallies = tallies[leftSeq] + tallies[rightSeq];
}
// return either counts or densities, as requested; note that you can have
// binsAreSampleCounts be T, and yet return density values, that is legal,
// and just means that you want densities for singletons, doubletons, etc.
if (metric == "count")
return tallies;
else if (metric == "density")
return tallies / sum(tallies);
else
stop("ERROR (calcSFS): unrecognized value '" + metric + "' for parameter metric.");
})V0G0N";
#pragma mark (float$)calcTajimasD(object<Haplosome> haplosomes, [No<Mutation> muts = NULL], [Ni$ start = NULL], [Ni$ end = NULL])
const char *gSLiMSourceCode_calcTajimasD =
R"V0G0N({
if (haplosomes.length() < 4)
stop("ERROR (calcTajimasD): haplosomes must contain at least four elements.");
species = haplosomes[0].individual.subpopulation.species;
if (community.allSpecies.length() > 1)
{
if (any(haplosomes.individual.subpopulation.species != species))
stop("ERROR (calcTajimasD): all haplosomes must belong to the same species.");
if (!isNULL(muts))
if (any(muts.mutationType.species != species))
stop("ERROR (calcTajimasD): all mutations must belong to the same species as the haplosomes.");
}
chromosome = haplosomes[0].chromosome;
if (species.chromosomes.length() > 1)
{
if (any(haplosomes.chromosome != chromosome))
stop("ERROR (calcTajimasD): all haplosomes must be associated with the same chromosome.");
if (!isNULL(muts))
if (any(muts.chromosome != chromosome))
stop("ERROR (calcTajimasD): all mutations must be associated with the same chromosome as the haplosomes.");
}
length = chromosome.length;
if (isNULL(muts))
muts = species.subsetMutations(chromosome=chromosome);
// handle windowing
if (!isNULL(start) & !isNULL(end))
{
if (start > end)
stop("ERROR (calcTajimasD): start must be less than or equal to end.");
if ((start < 0) | (end >= length))
stop("ERROR (calcTajimasD): start and end must be within the bounds of the focal chromosome");
mpos = muts.position;
muts = muts[(mpos >= start) & (mpos <= end)];
length = end - start + 1;
}
else if (!isNULL(start) | !isNULL(end))
{
stop("ERROR (calcTajimasD): start and end must both be NULL or both be non-NULL.");
}
// narrow down to the mutations that are actually present in the haplosomes and aren't fixed
p = haplosomes.mutationFrequenciesInHaplosomes(muts);
muts = muts[(p != 0.0) & (p != 1.0)];
// do the calculation
// Pi and Watterson's theta functions divide by sequence length so this must be undone in Tajima's D
// Sequence length is constant (i.e. no missing data or indels) so this can be applied equally over both metrics
diff = (calcPi(haplosomes, muts, start, end) - calcWattersonsTheta(haplosomes, muts, start, end)) * length;
// calculate standard deviation of covariance of pi and Watterson's theta
// note that first 3 variables defined below are sufficient for Watterson's theta calculation as well,
// although the calcWattersonsTheta() function is used above for proper interval handling and clarity
k = size(muts);
n = haplosomes.size();
a_1 = sum(1 / 1:(n - 1));
a_2 = sum(1 / (1:(n - 1)) ^ 2);
b_1 = (n + 1) / (3 * (n - 1));
b_2 = 2 * (n ^ 2 + n + 3) / (9 * n * (n - 1));
c_1 = b_1 - 1 / a_1;
c_2 = b_2 - (n + 2) / (a_1 * n) + a_2 / a_1 ^ 2;
e_1 = c_1 / a_1;
e_2 = c_2 / (a_1 ^ 2 + a_2);
covar = e_1 * k + e_2 * k * (k - 1);
stdev = sqrt(covar);
tajima_d = diff / stdev;
return tajima_d;
})V0G0N";
// ************************************************************************************
//
// other built-in functions
//
#pragma mark -
#pragma mark Other built-in functions
#pragma mark -
#pragma mark (void)initializeMutationRateFromFile(s$ path, i$ lastPosition, [f$ scale=1e-8], [s$ sep="\t"], [s$ dec="."])
const char *gSLiMSourceCode_initializeMutationRateFromFile =
R"V0G0N({
errbase = "ERROR (initializeMutationRateFromFile): ";
udf = errbase + "unexpected data format; the file cannot be read.";
if ((scale <= 0.0) | (scale > 1.0))
stop(errbase + "scale must be in (0.0, 1.0].");
if (!fileExists(path))
stop(errbase + "file not found at path '" + path + "'.");
map = readCSV(path, colNames=c("ends", "rates"), sep=sep, dec=dec);
if (length(map) == 0)
stop(udf);
if (length(map.allKeys) != 2)
stop(udf);
ends = map.getValue("ends");
rates = map.getValue("rates");
if (!isInteger(ends) | !isFloat(rates) | (length(ends) == 0))
stop(udf);
// We expect the first column to be start positions, not end positions.
// The first value in that column therefore tells us whether the data
// is zero-based or one-based; we require one or the other. There is
// another -1 applied to the positions because we convert them from
// start positions to end positions; each segment ends at the base
// previous to the start of the next segment.
base = ends[0];
if ((base != 0) & (base != 1))
stop(errbase + "the first position in the file must be 0 (for 0-based positions) or 1 (for 1-based positions).");
if (length(ends) == 1)
ends = lastPosition; // only the first start position is present
else
ends = c(ends[1:(size(ends)-1)] - base - 1, lastPosition);
initializeMutationRate(rates * scale, ends);
})V0G0N";
#pragma mark (void)initializeRecombinationRateFromFile(s$ path, i$ lastPosition, [f$ scale=1e-8], [s$ sep="\t"], [s$ dec="."])
const char *gSLiMSourceCode_initializeRecombinationRateFromFile =
R"V0G0N({
errbase = "ERROR (initializeRecombinationRateFromFile): ";
udf = errbase + "unexpected data format; the file cannot be read.";
if ((scale <= 0.0) | (scale > 1.0))
stop(errbase + "scale must be in (0.0, 1.0].");
if (!fileExists(path))
stop(errbase + "file not found at path '" + path + "'.");
map = readCSV(path, colNames=c("ends", "rates"), sep=sep, dec=dec);
if (length(map) == 0)
stop(udf);
if (length(map.allKeys) != 2)
stop(udf);
ends = map.getValue("ends");
rates = map.getValue("rates");
if (!isInteger(ends) | !isFloat(rates) | (length(ends) == 0))
stop(udf);
// We expect the first column to be start positions, not end positions.
// The first value in that column therefore tells us whether the data
// is zero-based or one-based; we require one or the other. There is
// another -1 applied to the positions because we convert them from
// start positions to end positions; each segment ends at the base
// previous to the start of the next segment.
base = ends[0];
if ((base != 0) & (base != 1))
stop(errbase + "the first position in the file must be 0 (for 0-based positions) or 1 (for 1-based positions).");
if (length(ends) == 1)
ends = lastPosition; // only the first start position is present
else
ends = c(ends[1:(size(ends)-1)] - base - 1, lastPosition);
initializeRecombinationRate(rates * scale, ends);
})V0G0N";
// ************************************************************************************
//
// codon tables
//
#pragma mark -
#pragma mark Codon tables
#pragma mark -
static std::string codon2aa_short[64] = {
/* AAA */ "K",
/* AAC */ "N",
/* AAG */ "K",
/* AAT */ "N",
/* ACA */ "T",
/* ACC */ "T",
/* ACG */ "T",
/* ACT */ "T",
/* AGA */ "R",
/* AGC */ "S",
/* AGG */ "R",
/* AGT */ "S",
/* ATA */ "I",
/* ATC */ "I",
/* ATG */ "M",
/* ATT */ "I",
/* CAA */ "Q",
/* CAC */ "H",
/* CAG */ "Q",
/* CAT */ "H",
/* CCA */ "P",
/* CCC */ "P",
/* CCG */ "P",
/* CCT */ "P",
/* CGA */ "R",
/* CGC */ "R",
/* CGG */ "R",
/* CGT */ "R",
/* CTA */ "L",
/* CTC */ "L",
/* CTG */ "L",
/* CTT */ "L",
/* GAA */ "E",
/* GAC */ "D",
/* GAG */ "E",
/* GAT */ "D",
/* GCA */ "A",
/* GCC */ "A",
/* GCG */ "A",
/* GCT */ "A",
/* GGA */ "G",
/* GGC */ "G",
/* GGG */ "G",
/* GGT */ "G",
/* GTA */ "V",
/* GTC */ "V",
/* GTG */ "V",
/* GTT */ "V",
/* TAA */ "X",
/* TAC */ "Y",
/* TAG */ "X",
/* TAT */ "Y",
/* TCA */ "S",
/* TCC */ "S",
/* TCG */ "S",
/* TCT */ "S",
/* TGA */ "X",
/* TGC */ "C",
/* TGG */ "W",
/* TGT */ "C",
/* TTA */ "L",
/* TTC */ "F",
/* TTG */ "L",
/* TTT */ "F"
};
static std::string codon2aa_long[64] = {
/* AAA */ "Lys",
/* AAC */ "Asn",
/* AAG */ "Lys",
/* AAT */ "Asn",
/* ACA */ "Thr",
/* ACC */ "Thr",
/* ACG */ "Thr",
/* ACT */ "Thr",
/* AGA */ "Arg",
/* AGC */ "Ser",
/* AGG */ "Arg",
/* AGT */ "Ser",
/* ATA */ "Ile",
/* ATC */ "Ile",
/* ATG */ "Met",
/* ATT */ "Ile",
/* CAA */ "Gln",
/* CAC */ "His",
/* CAG */ "Gln",
/* CAT */ "His",
/* CCA */ "Pro",
/* CCC */ "Pro",
/* CCG */ "Pro",
/* CCT */ "Pro",
/* CGA */ "Arg",
/* CGC */ "Arg",
/* CGG */ "Arg",
/* CGT */ "Arg",
/* CTA */ "Leu",
/* CTC */ "Leu",
/* CTG */ "Leu",
/* CTT */ "Leu",
/* GAA */ "Glu",
/* GAC */ "Asp",
/* GAG */ "Glu",
/* GAT */ "Asp",
/* GCA */ "Ala",
/* GCC */ "Ala",
/* GCG */ "Ala",