-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathslim_globals.cpp
2678 lines (2194 loc) · 156 KB
/
slim_globals.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_globals.cpp
// SLiM
//
// Created by Ben Haller on 1/4/15.
// Copyright (c) 2015-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_globals.h"
#include "chromosome.h"
#include "individual.h"
#include "interaction_type.h"
#include "haplosome.h"
#include "genomic_element.h"
#include "genomic_element_type.h"
#include "log_file.h"
#include "mutation.h"
#include "mutation_type.h"
#include "slim_eidos_block.h"
#include "community.h"
#include "spatial_map.h"
#include "species.h"
#include "substitution.h"
#include "subpopulation.h"
#include "mutation_run.h"
#include <string>
#include <vector>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include "json.hpp"
// Require 64-bit; apparently there are some issues on 32-bit, and nobody should be doing that anyway
static_assert(sizeof(char *) == 8, "SLiM must be built for 64-bit, not 32-bit.");
EidosValue_String_SP gStaticEidosValue_StringA;
EidosValue_String_SP gStaticEidosValue_StringC;
EidosValue_String_SP gStaticEidosValue_StringG;
EidosValue_String_SP gStaticEidosValue_StringT;
const std::string gStr_strand1("strand1");
const std::string gStr_strand2("strand2");
const std::string gStr_breaks1("breaks1");
const std::string gStr_strand3("strand3");
const std::string gStr_strand4("strand4");
const std::string gStr_breaks2("breaks2");
void SLiM_WarmUp(void)
{
THREAD_SAFETY_IN_ANY_PARALLEL("SLiM_WarmUp(): illegal when parallel");
static bool been_here = false;
if (!been_here)
{
been_here = true;
// Create the global class objects for all SLiM Eidos classes, from superclass to subclass
// This breaks encapsulation, kind of, but it needs to be done here, in order, so that superclass objects exist,
// and so that the global string names for the classes have already been set up by C++'s static initialization
gSLiM_Chromosome_Class = new Chromosome_Class( gStr_Chromosome, gEidosDictionaryRetained_Class);
gSLiM_Individual_Class = new Individual_Class( gEidosStr_Individual, gEidosDictionaryUnretained_Class);
gSLiM_InteractionType_Class = new InteractionType_Class( gStr_InteractionType, gEidosDictionaryUnretained_Class);
gSLiM_Haplosome_Class = new Haplosome_Class( gEidosStr_Haplosome, gEidosObject_Class);
gSLiM_GenomicElement_Class = new GenomicElement_Class( gStr_GenomicElement, gEidosObject_Class);
gSLiM_GenomicElementType_Class = new GenomicElementType_Class( gStr_GenomicElementType, gEidosDictionaryUnretained_Class);
gSLiM_LogFile_Class = new LogFile_Class( gStr_LogFile, gEidosDictionaryRetained_Class);
gSLiM_Mutation_Class = new Mutation_Class( gEidosStr_Mutation, gEidosDictionaryRetained_Class);
gSLiM_MutationType_Class = new MutationType_Class( gStr_MutationType, gEidosDictionaryUnretained_Class);
gSLiM_SLiMEidosBlock_Class = new SLiMEidosBlock_Class( gStr_SLiMEidosBlock, gEidosDictionaryUnretained_Class);
gSLiM_Community_Class = new Community_Class( gStr_Community, gEidosDictionaryUnretained_Class);
gSLiM_SpatialMap_Class = new SpatialMap_Class( gStr_SpatialMap, gEidosDictionaryRetained_Class);
gSLiM_Species_Class = new Species_Class( gStr_Species, gEidosDictionaryUnretained_Class);
gSLiM_Substitution_Class = new Substitution_Class( gStr_Substitution, gEidosDictionaryRetained_Class);
gSLiM_Subpopulation_Class = new Subpopulation_Class( gStr_Subpopulation, gEidosDictionaryUnretained_Class);
// Tell all registered classes to initialize their dispatch tables; doing this here saves a flag check later
// Note that this can't be done in the EidosClass constructor because the vtable is not set up for the subclass yet
for (EidosClass *eidos_class : EidosClass::RegisteredClasses(true, true))
eidos_class->CacheDispatchTables();
// Set up our shared pool for Mutation objects
SLiM_CreateMutationBlock();
// Configure the Eidos context information
SLiM_ConfigureContext();
// Allocate global permanents
gStaticEidosValue_StringA = EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String(gStr_A));
gStaticEidosValue_StringC = EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String(gStr_C));
gStaticEidosValue_StringG = EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String(gStr_G));
gStaticEidosValue_StringT = EidosValue_String_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String(gStr_T));
#if DO_MEMORY_CHECKS
// Check for a memory limit and prepare for memory-limit testing
Eidos_CheckRSSAgainstMax("SLiM_WarmUp()", "This internal check should never fail!");
#endif
//std::cout << "sizeof(Individual) == " << sizeof(Individual) << std::endl;
//std::cout << "sizeof(Mutation) == " << sizeof(Mutation) << std::endl;
//std::cout << "sizeof(int) == " << sizeof(int) << std::endl;
//std::cout << "sizeof(long) == " << sizeof(long) << std::endl;
//std::cout << "sizeof(size_t) == " << sizeof(size_t) << std::endl;
// Test that our tskit metadata schemas are valid JSON, and print them out formatted for debugging purposes if desired
nlohmann::json top_level_schema, edge_schema, site_schema, mutation_schema, node_schema, individual_schema, population_schema;
try {
top_level_schema = nlohmann::json::parse(gSLiM_tsk_metadata_schema);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_metadata_schema must be a JSON string." << EidosTerminate();
}
try {
if (gSLiM_tsk_edge_metadata_schema.length())
edge_schema = nlohmann::json::parse(gSLiM_tsk_edge_metadata_schema);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_edge_metadata_schema must be a JSON string." << EidosTerminate();
}
try {
if (gSLiM_tsk_site_metadata_schema.length())
site_schema = nlohmann::json::parse(gSLiM_tsk_site_metadata_schema);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_site_metadata_schema must be a JSON string." << EidosTerminate();
}
try {
mutation_schema = nlohmann::json::parse(gSLiM_tsk_mutation_metadata_schema);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_mutation_metadata_schema must be a JSON string." << EidosTerminate();
}
try {
node_schema = nlohmann::json::parse(gSLiM_tsk_node_metadata_schema_FORMAT);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_node_metadata_schema_FORMAT must be a JSON string." << EidosTerminate();
}
try {
individual_schema = nlohmann::json::parse(gSLiM_tsk_individual_metadata_schema);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_individual_metadata_schema must be a JSON string." << EidosTerminate();
}
try {
population_schema = nlohmann::json::parse(gSLiM_tsk_population_metadata_schema);
} catch (...) {
EIDOS_TERMINATION << "ERROR (SLiM_WarmUp): (internal error) gSLiM_tsk_population_metadata_schema must be a JSON string." << EidosTerminate();
}
#if 0
#warning printing of JSON schemas should be disabled in a production build
std::cout << "gSLiM_tsk_metadata_schema == " << std::endl << top_level_schema.dump(4) << std::endl << std::endl;
std::cout << "gSLiM_tsk_edge_metadata_schema == " << std::endl << edge_schema.dump(4) << std::endl << std::endl;
std::cout << "gSLiM_tsk_site_metadata_schema == " << std::endl << site_schema.dump(4) << std::endl << std::endl;
std::cout << "gSLiM_tsk_mutation_metadata_schema == " << std::endl << mutation_schema.dump(4) << std::endl << std::endl;
std::cout << "gSLiM_tsk_node_metadata_schema_FORMAT == " << std::endl << node_schema.dump(4) << std::endl << std::endl;
std::cout << "gSLiM_tsk_individual_metadata_schema == " << std::endl << individual_schema.dump(4) << std::endl << std::endl;
std::cout << "gSLiM_tsk_population_metadata_schema == " << std::endl << population_schema.dump(4) << std::endl << std::endl;
#endif
}
}
// ostringstreams for SLiM output; see the header for details
std::ostringstream gSLiMOut;
std::ostringstream gSLiMError;
#ifdef SLIMGUI
std::ostringstream gSLiMScheduling;
#endif
#pragma mark -
#pragma mark Types and max values
#pragma mark -
// Functions for casting from Eidos ints (int64_t) to SLiM int types safely
void SLiM_RaiseTickRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaiseTickRangeError): value " << p_long_value << " for a tick index or duration is out of range." << EidosTerminate();
}
void SLiM_RaiseAgeRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaiseAgeRangeError): value " << p_long_value << " for an individual age is out of range." << EidosTerminate();
}
void SLiM_RaisePositionRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaisePositionRangeError): value " << p_long_value << " for a chromosome position or length is out of range." << EidosTerminate();
}
void SLiM_RaisePedigreeIDRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaisePedigreeIDRangeError): value " << p_long_value << " for an individual pedigree ID is out of range." << EidosTerminate();
}
void SLiM_RaiseObjectidRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaiseObjectidRangeError): value " << p_long_value << " for a SLiM object identifier value is out of range." << EidosTerminate();
}
void SLiM_RaisePopsizeRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaisePopsizeRangeError): value " << p_long_value << " for a subpopulation size, individual index, or haplosome index is out of range." << EidosTerminate();
}
void SLiM_RaiseUsertagRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaiseUsertagRangeError): value " << p_long_value << " for a user-supplied tag is out of range." << EidosTerminate();
}
void SLiM_RaisePolymorphismidRangeError(int64_t p_long_value)
{
EIDOS_TERMINATION << "ERROR (SLiM_RaisePolymorphismidRangeError): value " << p_long_value << " for a polymorphism identifier is out of range." << EidosTerminate();
}
Community &SLiM_GetCommunityFromInterpreter(EidosInterpreter &p_interpreter)
{
#if DEBUG
// Use dynamic_cast<> only in DEBUG since it is hella slow
Community *community = dynamic_cast<Community *>(p_interpreter.Context());
#else
Community *community = (Community *)(p_interpreter.Context());
#endif
if (!community)
EIDOS_TERMINATION << "ERROR (SLiM_GetCommunityFromInterpreter): (internal error) the community is not registered as the context pointer." << EidosTerminate();
return *community;
}
slim_objectid_t SLiM_ExtractObjectIDFromEidosValue_is(EidosValue *p_value, int p_index, char p_prefix_char)
{
return (p_value->Type() == EidosValueType::kValueInt) ? SLiMCastToObjectidTypeOrRaise(p_value->IntAtIndex_NOCAST(p_index, nullptr)) : SLiMEidosScript::ExtractIDFromStringWithPrefix(p_value->StringAtIndex_NOCAST(p_index, nullptr), p_prefix_char, nullptr);
}
MutationType *SLiM_ExtractMutationTypeFromEidosValue_io(EidosValue *p_value, int p_index, Community *p_community, Species *p_species, const char *p_method_name)
{
MutationType *found_muttype = nullptr;
if (p_value->Type() == EidosValueType::kValueInt)
{
slim_objectid_t mutation_type_id = SLiMCastToObjectidTypeOrRaise(p_value->IntAtIndex_NOCAST(p_index, nullptr));
if (p_species)
{
// Look in the species, if one was supplied
found_muttype = p_species->MutationTypeWithID(mutation_type_id);
if (!found_muttype)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractMutationTypeFromEidosValue_io): " << p_method_name << " mutation type m" << mutation_type_id << " not defined in the focal species." << EidosTerminate();
}
else
{
// Otherwise, look in all species in the community
for (Species *species : p_community->AllSpecies())
{
found_muttype = species->MutationTypeWithID(mutation_type_id);
if (found_muttype)
break;
}
if (!found_muttype)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractMutationTypeFromEidosValue_io): " << p_method_name << " mutation type m" << mutation_type_id << " not defined." << EidosTerminate();
}
}
else
{
#if DEBUG
// Use dynamic_cast<> only in DEBUG since it is hella slow
// the class of the object here should be guaranteed by the caller anyway
found_muttype = dynamic_cast<MutationType *>(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#else
found_muttype = (MutationType *)(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#endif
if (!found_muttype)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractMutationTypeFromEidosValue_io): (internal error) " << p_method_name << " was passed an object that is not a mutation type." << EidosTerminate();
if (p_species && (&found_muttype->species_ != p_species))
EIDOS_TERMINATION << "ERROR (SLiM_ExtractMutationTypeFromEidosValue_io): " << p_method_name << " mutation type m" << found_muttype->mutation_type_id_ << " not defined in the focal species." << EidosTerminate();
}
return found_muttype;
}
GenomicElementType *SLiM_ExtractGenomicElementTypeFromEidosValue_io(EidosValue *p_value, int p_index, Community *p_community, Species *p_species, const char *p_method_name)
{
GenomicElementType *found_getype = nullptr;
if (p_value->Type() == EidosValueType::kValueInt)
{
slim_objectid_t getype_id = SLiMCastToObjectidTypeOrRaise(p_value->IntAtIndex_NOCAST(p_index, nullptr));
if (p_species)
{
// Look in the species, if one was supplied
found_getype = p_species->GenomicElementTypeWithID(getype_id);
if (!found_getype)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractGenomicElementTypeFromEidosValue_io): " << p_method_name << " genomic element type g" << getype_id << " not defined in the focal species." << EidosTerminate();
}
else
{
// Otherwise, look in all species in the community
for (Species *species : p_community->AllSpecies())
{
found_getype = species->GenomicElementTypeWithID(getype_id);
if (found_getype)
break;
}
if (!found_getype)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractGenomicElementTypeFromEidosValue_io): " << p_method_name << " genomic element type g" << getype_id << " not defined." << EidosTerminate();
}
}
else
{
#if DEBUG
// Use dynamic_cast<> only in DEBUG since it is hella slow
// the class of the object here should be guaranteed by the caller anyway
found_getype = dynamic_cast<GenomicElementType *>(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#else
found_getype = (GenomicElementType *)(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#endif
if (!found_getype)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractGenomicElementTypeFromEidosValue_io): (internal error) " << p_method_name << " was passed an object that is not a genomic element type." << EidosTerminate();
if (p_species && (&found_getype->species_ != p_species))
EIDOS_TERMINATION << "ERROR (SLiM_ExtractGenomicElementTypeFromEidosValue_io): " << p_method_name << " genomic element type g" << found_getype->genomic_element_type_id_ << " not defined in the focal species." << EidosTerminate();
}
return found_getype;
}
Subpopulation *SLiM_ExtractSubpopulationFromEidosValue_io(EidosValue *p_value, int p_index, Community *p_community, Species *p_species, const char *p_method_name)
{
Subpopulation *found_subpop = nullptr;
if (p_value->Type() == EidosValueType::kValueInt)
{
slim_objectid_t source_subpop_id = SLiMCastToObjectidTypeOrRaise(p_value->IntAtIndex_NOCAST(p_index, nullptr));
if (p_species)
{
// Look in the species, if one was supplied
found_subpop = p_species->SubpopulationWithID(source_subpop_id);
if (!found_subpop)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSubpopulationFromEidosValue_io): " << p_method_name << " subpopulation p" << source_subpop_id << " not defined in the focal species." << EidosTerminate();
}
else
{
// Otherwise, look in all species in the community
for (Species *species : p_community->AllSpecies())
{
found_subpop = species->SubpopulationWithID(source_subpop_id);
if (found_subpop)
break;
}
if (!found_subpop)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSubpopulationFromEidosValue_io): " << p_method_name << " subpopulation p" << source_subpop_id << " not defined." << EidosTerminate();
}
}
else
{
#if DEBUG
// Use dynamic_cast<> only in DEBUG since it is hella slow
// the class of the object here should be guaranteed by the caller anyway
found_subpop = dynamic_cast<Subpopulation *>(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#else
found_subpop = (Subpopulation *)(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#endif
if (!found_subpop)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSubpopulationFromEidosValue_io): (internal error) " << p_method_name << " was passed an object that is not a subpopulation." << EidosTerminate();
if (p_species && (&found_subpop->species_ != p_species))
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSubpopulationFromEidosValue_io): " << p_method_name << " subpopulation p" << found_subpop->subpopulation_id_ << " not defined in the focal species." << EidosTerminate();
}
return found_subpop;
}
SLiMEidosBlock *SLiM_ExtractSLiMEidosBlockFromEidosValue_io(EidosValue *p_value, int p_index, Community *p_community, Species *p_species, const char *p_method_name)
{
SLiMEidosBlock *found_block = nullptr;
if (p_value->Type() == EidosValueType::kValueInt)
{
slim_objectid_t block_id = SLiMCastToObjectidTypeOrRaise(p_value->IntAtIndex_NOCAST(p_index, nullptr));
std::vector<SLiMEidosBlock*> &script_blocks = p_community->AllScriptBlocks();
for (SLiMEidosBlock *temp_found_block : script_blocks)
if (temp_found_block->block_id_ == block_id)
{
found_block = temp_found_block;
break;
}
if (!found_block)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSLiMEidosBlockFromEidosValue_io): " << p_method_name << " SLiMEidosBlock s" << block_id << " not defined." << EidosTerminate();
}
else
{
#if DEBUG
// Use dynamic_cast<> only in DEBUG since it is hella slow
// the class of the object here should be guaranteed by the caller anyway
found_block = dynamic_cast<SLiMEidosBlock *>(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#else
found_block = (SLiMEidosBlock *)(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#endif
if (!found_block)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSLiMEidosBlockFromEidosValue_io): (internal error) " << p_method_name << " was passed an object that is not a SLiMEidosBlock." << EidosTerminate();
}
if (p_species && (found_block->species_spec_ != p_species))
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSLiMEidosBlockFromEidosValue_io): " << p_method_name << " SLiMEidosBlock s" << found_block->block_id_ << " not defined in the focal species." << EidosTerminate();
return found_block;
}
Species *SLiM_ExtractSpeciesFromEidosValue_No(EidosValue *p_value, int p_index, Community *p_community, const char *p_method_name)
{
Species *found_species = nullptr;
if (p_value->Type() == EidosValueType::kValueNULL)
{
const std::vector<Species *> &all_species = p_community->AllSpecies();
if (all_species.size() == 1)
found_species = all_species[0];
else
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSpeciesFromEidosValue_No): " << p_method_name << " requires a species to be supplied in multispecies models." << EidosTerminate();
}
else
{
#if DEBUG
// Use dynamic_cast<> only in DEBUG since it is hella slow
// the class of the object here should be guaranteed by the caller anyway
found_species = dynamic_cast<Species *>(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#else
found_species = (Species *)(p_value->ObjectElementAtIndex_NOCAST(p_index, nullptr));
#endif
if (!found_species)
EIDOS_TERMINATION << "ERROR (SLiM_ExtractSpeciesFromEidosValue_No): (internal error) " << p_method_name << " was passed an object that is not a Species." << EidosTerminate();
}
return found_species;
}
#pragma mark -
#pragma mark Memory management
#pragma mark -
void SumUpMemoryUsage_Species(SLiMMemoryUsage_Species &p_usage)
{
p_usage.totalMemoryUsage =
p_usage.chromosomeObjects +
p_usage.chromosomeMutationRateMaps +
p_usage.chromosomeRecombinationRateMaps +
p_usage.chromosomeAncestralSequence +
p_usage.haplosomeObjects +
p_usage.haplosomeExternalBuffers +
p_usage.haplosomeUnusedPoolSpace +
p_usage.haplosomeUnusedPoolBuffers +
p_usage.genomicElementObjects +
p_usage.genomicElementTypeObjects +
p_usage.individualObjects +
p_usage.individualJunkyardAndHaplosomes +
p_usage.individualHaplosomeVectors +
p_usage.individualUnusedPoolSpace +
p_usage.mutationObjects +
p_usage.mutationRunObjects +
p_usage.mutationRunExternalBuffers +
p_usage.mutationRunNonneutralCaches +
p_usage.mutationRunUnusedPoolSpace +
p_usage.mutationRunUnusedPoolBuffers +
p_usage.mutationTypeObjects +
p_usage.speciesObjects +
p_usage.speciesTreeSeqTables +
p_usage.subpopulationObjects +
p_usage.subpopulationFitnessCaches +
p_usage.subpopulationParentTables +
p_usage.subpopulationSpatialMaps +
p_usage.subpopulationSpatialMapsDisplay +
p_usage.substitutionObjects;
}
void SumUpMemoryUsage_Community(SLiMMemoryUsage_Community &p_usage)
{
p_usage.totalMemoryUsage =
p_usage.communityObjects +
p_usage.mutationRefcountBuffer +
p_usage.mutationUnusedPoolSpace +
p_usage.interactionTypeObjects +
p_usage.interactionTypeKDTrees +
p_usage.interactionTypePositionCaches +
p_usage.interactionTypeSparseVectorPool +
p_usage.eidosASTNodePool +
p_usage.eidosSymbolTablePool +
p_usage.eidosValuePool +
p_usage.fileBuffers;
}
void AccumulateMemoryUsageIntoTotal_Species(SLiMMemoryUsage_Species &p_usage, SLiMMemoryUsage_Species &p_total)
{
// p_total += p_usage;
p_total.chromosomeObjects_count += p_usage.chromosomeObjects_count;
p_total.chromosomeObjects += p_usage.chromosomeObjects;
p_total.chromosomeMutationRateMaps += p_usage.chromosomeMutationRateMaps;
p_total.chromosomeRecombinationRateMaps += p_usage.chromosomeRecombinationRateMaps;
p_total.chromosomeAncestralSequence += p_usage.chromosomeAncestralSequence;
p_total.haplosomeObjects_count += p_usage.haplosomeObjects_count;
p_total.haplosomeObjects += p_usage.haplosomeObjects;
p_total.haplosomeExternalBuffers += p_usage.haplosomeExternalBuffers;
p_total.haplosomeUnusedPoolSpace += p_usage.haplosomeUnusedPoolSpace;
p_total.haplosomeUnusedPoolBuffers += p_usage.haplosomeUnusedPoolBuffers;
p_total.genomicElementObjects_count += p_usage.genomicElementObjects_count;
p_total.genomicElementObjects += p_usage.genomicElementObjects;
p_total.genomicElementTypeObjects_count += p_usage.genomicElementTypeObjects_count;
p_total.genomicElementTypeObjects += p_usage.genomicElementTypeObjects;
p_total.individualObjects_count += p_usage.individualObjects_count;
p_total.individualObjects += p_usage.individualObjects;
p_total.individualHaplosomeVectors += p_usage.individualHaplosomeVectors;
p_total.individualJunkyardAndHaplosomes += p_usage.individualJunkyardAndHaplosomes;
p_total.individualUnusedPoolSpace += p_usage.individualUnusedPoolSpace;
p_total.mutationObjects_count += p_usage.mutationObjects_count;
p_total.mutationObjects += p_usage.mutationObjects;
p_total.mutationRunObjects_count += p_usage.mutationRunObjects_count;
p_total.mutationRunObjects += p_usage.mutationRunObjects;
p_total.mutationRunExternalBuffers += p_usage.mutationRunExternalBuffers;
p_total.mutationRunNonneutralCaches += p_usage.mutationRunNonneutralCaches;
p_total.mutationRunUnusedPoolSpace += p_usage.mutationRunUnusedPoolSpace;
p_total.mutationRunUnusedPoolBuffers += p_usage.mutationRunUnusedPoolBuffers;
p_total.mutationTypeObjects_count += p_usage.mutationTypeObjects_count;
p_total.mutationTypeObjects += p_usage.mutationTypeObjects;
p_total.speciesObjects_count += p_usage.speciesObjects_count;
p_total.speciesObjects += p_usage.speciesObjects;
p_total.speciesTreeSeqTables += p_usage.speciesTreeSeqTables;
p_total.subpopulationObjects_count += p_usage.subpopulationObjects_count;
p_total.subpopulationObjects += p_usage.subpopulationObjects;
p_total.subpopulationFitnessCaches += p_usage.subpopulationFitnessCaches;
p_total.subpopulationParentTables += p_usage.subpopulationParentTables;
p_total.subpopulationSpatialMaps += p_usage.subpopulationSpatialMaps;
p_total.subpopulationSpatialMapsDisplay += p_usage.subpopulationSpatialMapsDisplay;
p_total.substitutionObjects_count += p_usage.substitutionObjects_count;
p_total.substitutionObjects += p_usage.substitutionObjects;
p_total.totalMemoryUsage += p_usage.totalMemoryUsage;
}
void AccumulateMemoryUsageIntoTotal_Community(SLiMMemoryUsage_Community &p_usage, SLiMMemoryUsage_Community &p_total)
{
// p_total += p_usage;
p_total.communityObjects_count += p_usage.communityObjects_count;
p_total.communityObjects += p_usage.communityObjects;
p_total.mutationRefcountBuffer += p_usage.mutationRefcountBuffer;
p_total.mutationUnusedPoolSpace += p_usage.mutationUnusedPoolSpace;
p_total.interactionTypeObjects_count += p_usage.interactionTypeObjects_count;
p_total.interactionTypeObjects += p_usage.interactionTypeObjects;
p_total.interactionTypeKDTrees += p_usage.interactionTypeKDTrees;
p_total.interactionTypePositionCaches += p_usage.interactionTypePositionCaches;
p_total.interactionTypeSparseVectorPool += p_usage.interactionTypeSparseVectorPool;
p_total.eidosASTNodePool += p_usage.eidosASTNodePool;
p_total.eidosSymbolTablePool += p_usage.eidosSymbolTablePool;
p_total.eidosValuePool += p_usage.eidosValuePool;
p_total.fileBuffers += p_usage.fileBuffers;
p_total.totalMemoryUsage += p_usage.totalMemoryUsage;
}
#pragma mark -
#pragma mark Shared SLiM types and enumerations
#pragma mark -
// Verbosity, from the command-line option -l[ong]; defaults to 1 if -l[ong] is not used
int64_t SLiM_verbosity_level = 1;
// stream output for cycle stages
std::string StringForSLiMCycleStage(SLiMCycleStage p_stage)
{
switch (p_stage)
{
// some of these are not user-visible
case SLiMCycleStage::kStagePreCycle: return "begin";
case SLiMCycleStage::kWFStage0ExecuteFirstScripts: return "first";
case SLiMCycleStage::kWFStage1ExecuteEarlyScripts: return "early";
case SLiMCycleStage::kWFStage2GenerateOffspring: return "reproduction";
case SLiMCycleStage::kWFStage3SwapGenerations: return "swap";
case SLiMCycleStage::kWFStage4RemoveFixedMutations: return "tally";
case SLiMCycleStage::kWFStage5ExecuteLateScripts: return "late";
case SLiMCycleStage::kWFStage6CalculateFitness: return "fitness";
case SLiMCycleStage::kWFStage7AdvanceTickCounter: return "end";
case SLiMCycleStage::kNonWFStage0ExecuteFirstScripts: return "first";
case SLiMCycleStage::kNonWFStage1GenerateOffspring: return "reproduction";
case SLiMCycleStage::kNonWFStage2ExecuteEarlyScripts: return "early";
case SLiMCycleStage::kNonWFStage3CalculateFitness: return "fitness";
case SLiMCycleStage::kNonWFStage4SurvivalSelection: return "survival";
case SLiMCycleStage::kNonWFStage5RemoveFixedMutations: return "tally";
case SLiMCycleStage::kNonWFStage6ExecuteLateScripts: return "late";
case SLiMCycleStage::kNonWFStage7AdvanceTickCounter: return "end";
case SLiMCycleStage::kStagePostCycle: return "console";
}
EIDOS_TERMINATION << "ERROR (StringForSLiMCycleStage): (internal) unrecognized cycle stage." << EidosTerminate();
}
// stream output for enumerations
std::string StringForChromosomeType(ChromosomeType p_chromosome_type)
{
switch (p_chromosome_type)
{
case ChromosomeType::kA_DiploidAutosome: return gStr_A;
case ChromosomeType::kH_HaploidAutosome: return gStr_H;
case ChromosomeType::kX_XSexChromosome: return gStr_X;
case ChromosomeType::kY_YSexChromosome: return gStr_Y;
case ChromosomeType::kZ_ZSexChromosome: return gStr_Z;
case ChromosomeType::kW_WSexChromosome: return gStr_W;
case ChromosomeType::kHF_HaploidFemaleInherited: return gStr_HF;
case ChromosomeType::kFL_HaploidFemaleLine: return gStr_FL;
case ChromosomeType::kHM_HaploidMaleInherited: return gStr_HM;
case ChromosomeType::kML_HaploidMaleLine: return gStr_ML;
case ChromosomeType::kHNull_HaploidAutosomeWithNull: return gStr_H_; // "H-"
case ChromosomeType::kNullY_YSexChromosomeWithNull: return gStr__Y; // "-Y"
}
EIDOS_TERMINATION << "ERROR (StringForChromosomeType): (internal error) unexpected p_chromosome_type value." << EidosTerminate();
}
ChromosomeType ChromosomeTypeForString(std::string type)
{
if (type == gStr_A) return ChromosomeType::kA_DiploidAutosome;
else if (type == gStr_H) return ChromosomeType::kH_HaploidAutosome;
else if (type == gStr_X) return ChromosomeType::kX_XSexChromosome;
else if (type == gStr_Y) return ChromosomeType::kY_YSexChromosome;
else if (type == gStr_Z) return ChromosomeType::kZ_ZSexChromosome;
else if (type == gStr_W) return ChromosomeType::kW_WSexChromosome;
else if (type == gStr_HF) return ChromosomeType::kHF_HaploidFemaleInherited;
else if (type == gStr_FL) return ChromosomeType::kFL_HaploidFemaleLine;
else if (type == gStr_HM) return ChromosomeType::kHM_HaploidMaleInherited;
else if (type == gStr_ML) return ChromosomeType::kML_HaploidMaleLine;
else if (type == gStr_H_) return ChromosomeType::kHNull_HaploidAutosomeWithNull;
else if (type == gStr__Y) return ChromosomeType::kNullY_YSexChromosomeWithNull;
else
EIDOS_TERMINATION << "ERROR (ChromosomeTypeForString): unrecognized chromosome type '" << type << "'." << EidosTerminate();
}
std::ostream& operator<<(std::ostream& p_out, ChromosomeType p_chromosome_type)
{
p_out << StringForChromosomeType(p_chromosome_type);
return p_out;
}
std::string StringForIndividualSex(IndividualSex p_sex)
{
switch (p_sex)
{
case IndividualSex::kUnspecified: return "*";
case IndividualSex::kHermaphrodite: return "H";
case IndividualSex::kFemale: return "F"; // SEX ONLY
case IndividualSex::kMale: return "M"; // SEX ONLY
}
EIDOS_TERMINATION << "ERROR (StringForIndividualSex): (internal error) unexpected p_sex value." << EidosTerminate();
}
std::ostream& operator<<(std::ostream& p_out, IndividualSex p_sex)
{
p_out << StringForIndividualSex(p_sex);
return p_out;
}
const char gSLiM_Nucleotides[4] = {'A', 'C', 'G', 'T'};
#pragma mark -
#pragma mark NucleotideArray
#pragma mark -
NucleotideArray::NucleotideArray(std::size_t p_length, const int64_t *p_int_buffer) : length_(p_length)
{
buffer_ = (uint64_t *)malloc(((length_ + 31) / 32) * sizeof(uint64_t));
if (!buffer_)
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideArray): allocation failed; you may need to raise the memory limit for SLiM." << EidosTerminate();
// Eat 32 nucleotides at a time if we can
std::size_t index = 0, buf_index = 0;
for ( ; index < length_; index += 32)
{
uint64_t accumulator = 0;
for (std::size_t i = 0; i < 32; )
{
uint64_t nuc = (uint64_t)p_int_buffer[index + i];
if (nuc > 3) // values < 0 will becomes > 3 after casting above
{
free(buffer_);
buffer_ = nullptr;
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideArray): integer nucleotide value " << p_int_buffer[index + i] << " must be 0 (A), 1 (C), 2 (G), or 3 (T)." << EidosTerminate();
}
accumulator |= (nuc << (i * 2));
if (index + ++i == length_)
break;
}
buffer_[buf_index++] = accumulator;
}
}
uint8_t *NucleotideArray::NucleotideCharToIntLookup(void)
{
// set up a lookup table for speed
static uint8_t *nuc_lookup = nullptr;
if (!nuc_lookup)
{
THREAD_SAFETY_IN_ACTIVE_PARALLEL("NucleotideArray::NucleotideCharToIntLookup(): usage of statics");
nuc_lookup = (uint8_t *)malloc(256 * sizeof(uint8_t));
if (!nuc_lookup)
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideCharToIntLookup): allocation failed; you may need to raise the memory limit for SLiM." << EidosTerminate();
for (int i = 0; i < 256; ++i)
nuc_lookup[i] = 4; // placeholder illegal value
nuc_lookup[(int)('A')] = 0;
nuc_lookup[(int)('C')] = 1;
nuc_lookup[(int)('G')] = 2;
nuc_lookup[(int)('T')] = 3;
}
return nuc_lookup;
}
NucleotideArray::NucleotideArray(std::size_t p_length, const char *p_char_buffer) : length_(p_length)
{
uint8_t *nuc_lookup = NucleotideArray::NucleotideCharToIntLookup();
buffer_ = (uint64_t *)malloc(((length_ + 31) / 32) * sizeof(uint64_t));
if (!buffer_)
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideArray): allocation failed; you may need to raise the memory limit for SLiM." << EidosTerminate();
// Eat 32 nucleotides at a time if we can
std::size_t index = 0, buf_index = 0;
for ( ; index < length_; index += 32)
{
uint64_t accumulator = 0;
for (std::size_t i = 0; i < 32; )
{
char nuc_char = p_char_buffer[index + i];
uint64_t nuc = nuc_lookup[(int)(unsigned char)(nuc_char)];
if (nuc > 3)
{
free(buffer_);
buffer_ = nullptr;
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideArray): character nucleotide value '" << nuc_char << "' must be 'A', 'C', 'G', or 'T'." << EidosTerminate();
}
accumulator |= (nuc << (i * 2));
if (index + ++i == length_)
break;
}
buffer_[buf_index++] = accumulator;
}
}
NucleotideArray::NucleotideArray(std::size_t p_length, const std::string p_string_vector[]) : length_(p_length)
{
buffer_ = (uint64_t *)malloc(((length_ + 31) / 32) * sizeof(uint64_t));
if (!buffer_)
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideArray): allocation failed; you may need to raise the memory limit for SLiM." << EidosTerminate();
// Eat 32 nucleotides at a time if we can
std::size_t index = 0, buf_index = 0;
for ( ; index < length_; index += 32)
{
uint64_t accumulator = 0;
for (std::size_t i = 0; i < 32; )
{
const std::string &nuc_string = p_string_vector[index + i];
uint64_t nuc;
if (nuc_string == gStr_A) nuc = 0;
else if (nuc_string == gStr_C) nuc = 1;
else if (nuc_string == gStr_G) nuc = 2;
else if (nuc_string == gStr_T) nuc = 3;
else
{
free(buffer_);
buffer_ = nullptr;
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotideArray): string nucleotide character '" << nuc_string << "' must be 'A', 'C', 'G', or 'T'." << EidosTerminate();
}
accumulator |= (nuc << (i * 2));
if (index + ++i == length_)
break;
}
buffer_[buf_index++] = accumulator;
}
}
void NucleotideArray::SetNucleotideAtIndex(std::size_t p_index, uint64_t p_nuc)
{
if (p_nuc > 3)
EIDOS_TERMINATION << "ERROR (NucleotideArray::SetNucleotideAtIndex): integer nucleotide values must be 0 (A), 1 (C), 2 (G), or 3 (T)." << EidosTerminate();
uint64_t &chunk = buffer_[p_index / 32];
int shift = ((p_index % 32) * 2);
uint64_t mask = ((uint64_t)0x03) << shift;
uint64_t nucbits = (uint64_t)p_nuc << shift;
chunk = (chunk & ~mask) | nucbits;
}
EidosValue_SP NucleotideArray::NucleotidesAsIntegerVector(int64_t start, int64_t end)
{
int64_t length = end - start + 1;
if (length == 1)
{
switch (NucleotideAtIndex(start))
{
case 0: return gStaticEidosValue_Integer0;
case 1: return gStaticEidosValue_Integer1;
case 2: return gStaticEidosValue_Integer2;
case 3: return gStaticEidosValue_Integer3;
default:
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotidesAsIntegerVector): nucleotide value out of range." << EidosTerminate();
}
}
else
{
// return a vector of integers, 3 0 3 0
EidosValue_Int *int_result = (new (gEidosValuePool->AllocateChunk()) EidosValue_Int())->resize_no_initialize((int)length);
for (int value_index = 0; value_index < length; ++value_index)
int_result->set_int_no_check(NucleotideAtIndex(start + value_index), value_index);
return EidosValue_SP(int_result);
}
return gStaticEidosValueNULL;
}
EidosValue_SP NucleotideArray::NucleotidesAsCodonVector(int64_t start, int64_t end, bool p_force_vector)
{
int64_t length = end - start + 1;
if ((length == 3) && !p_force_vector)
{
int nuc1 = NucleotideAtIndex(start);
int nuc2 = NucleotideAtIndex(start + 1);
int nuc3 = NucleotideAtIndex(start + 2);
int codon = nuc1 * 16 + nuc2 * 4 + nuc3; // 0..63
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Int(codon));
}
else
{
// return a vector of codons: nucleotide triplets compacted into a single integer value
int64_t length_3 = length / 3;
if (length % 3 != 0)
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotidesAsCodonVector): to obtain codons, the requested sequence length must be a multiple of 3." << EidosTerminate();
EidosValue_Int *int_result = (new (gEidosValuePool->AllocateChunk()) EidosValue_Int())->resize_no_initialize((int)length_3);
for (int64_t value_index = 0; value_index < length_3; ++value_index)
{
int64_t codon_base = start + value_index * 3;
int nuc1 = NucleotideAtIndex(codon_base);
int nuc2 = NucleotideAtIndex(codon_base + 1);
int nuc3 = NucleotideAtIndex(codon_base + 2);
int codon = nuc1 * 16 + nuc2 * 4 + nuc3; // 0..63
int_result->set_int_no_check(codon, value_index);
}
return EidosValue_SP(int_result);
}
}
EidosValue_SP NucleotideArray::NucleotidesAsStringVector(int64_t start, int64_t end)
{
int64_t length = end - start + 1;
if (length == 1)
{
switch (NucleotideAtIndex(start))
{
case 0: return gStaticEidosValue_StringA;
case 1: return gStaticEidosValue_StringC;
case 2: return gStaticEidosValue_StringG;
case 3: return gStaticEidosValue_StringT;
default:
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotidesAsStringVector): nucleotide value out of range." << EidosTerminate();
}
}
else
{
// return a vector of one-character strings, "T" "A" "T" "A"
EidosValue_String *string_result = (new (gEidosValuePool->AllocateChunk()) EidosValue_String())->Reserve((int)length);
for (int value_index = 0; value_index < length; ++value_index)
{
switch (NucleotideAtIndex(start + value_index))
{
case 0: string_result->PushString(gStr_A); break;
case 1: string_result->PushString(gStr_C); break;
case 2: string_result->PushString(gStr_G); break;
case 3: string_result->PushString(gStr_T); break;
default:
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotidesAsStringVector): nucleotide value out of range." << EidosTerminate();
}
}
return EidosValue_SP(string_result);
}
return gStaticEidosValueNULL;
}
EidosValue_SP NucleotideArray::NucleotidesAsStringSingleton(int64_t start, int64_t end)
{
int64_t length = end - start + 1;
if (length == 1)
{
switch (NucleotideAtIndex(start))
{
case 0: return gStaticEidosValue_StringA;
case 1: return gStaticEidosValue_StringC;
case 2: return gStaticEidosValue_StringG;
case 3: return gStaticEidosValue_StringT;
default:
EIDOS_TERMINATION << "ERROR (NucleotideArray::NucleotidesAsStringSingleton): nucleotide value out of range." << EidosTerminate();
}
}
else
{
// return a singleton string for the whole sequence, "TATA"; we munge the std::string inside the EidosValue to avoid memory copying, very naughty