Skip to content

Commit

Permalink
improve SLiM unit test coverage, minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Dec 1, 2023
1 parent 0cfd227 commit 46ef799
Show file tree
Hide file tree
Showing 11 changed files with 1,303 additions and 494 deletions.
110 changes: 86 additions & 24 deletions SLiMgui/SLiMHelpClasses.rtf
Original file line number Diff line number Diff line change
Expand Up @@ -3025,18 +3025,16 @@ See the description of the
\f4 This method is provided primarily for speed; it executes much faster than the Eidos equivalent above. Indeed, it is faster than just
\f3\fs18 individual.genomes.mutations
\f4\fs20 , and gives uniquing and sorting on top of that, so it is advantageous unless duplicate entries for homozygous mutations are actually needed.\
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf0 x <\'96> (float$)\
\pard\pardeftab720\li547\ri720\sb60\sa60\partightenfactor0
\f3\fs18 \cf2 x <\'96> (float$)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf0 A user-defined
\f4\fs20 \cf2 A user-defined
\f3\fs18 float
\f4\fs20 value. The value of
\f3\fs18 x
\f4\fs20 is initially undefined (i.e., has an effectively random value that could be different every time you run your model); if you wish it to have a defined value, you must arrange that yourself by explicitly setting its value prior to using it elsewhere in your code, typically in a
\f3\fs18 modifyChild()
\f4\fs20 callback. The value of
\f4\fs20 is initially undefined (i.e., has an effectively random value that could be different every time you run your model); if you wish it to have a defined value, you must arrange that yourself by explicitly setting its value prior to using it elsewhere in your code. The value of
\f3\fs18 x
\f4\fs20 is not used by SLiM unless the optional \'93continuous space\'94 facility is enabled with the
\f3\fs18 dimensionality
Expand All @@ -3050,19 +3048,69 @@ See the description of the
\f3\fs18 x
\f4\fs20 as an additional tag value of type
\f3\fs18 float
\f5\fs20 .\
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f4\fs20 .\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf0 y <\'96> (float$)\
\pard\pardeftab720\li547\ri720\sb60\sa60\partightenfactor0
\f3\fs18 \cf2 xy => (float)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf0 A user-defined
\f4\fs20 \cf2 This property provides joint read-only access to the
\f3\fs18 x
\f4\fs20 and
\f3\fs18 y
\f4\fs20 properties; they are returned as a two-element
\f3\fs18 float
\f4\fs20 vector. This can be useful in complex spatial models in which the spatiality of interactions/maps differs from the overall dimensionality of the model. See the documentation for the separate properties
\f3\fs18 x
\f4\fs20 and
\f3\fs18 y
\f4\fs20 for further comments.\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf2 xyz => (float)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf2 This property provides joint read-only access to the
\f3\fs18 x
\f4\fs20 ,
\f3\fs18 y
\f4\fs20 , and
\f3\fs18 z
\f4\fs20 properties; they are returned as a three-element
\f3\fs18 float
\f4\fs20 vector. This can be useful in complex spatial models in which the spatiality of interactions/maps differs from the overall dimensionality of the model. See the documentation for the separate properties
\f3\fs18 x
\f4\fs20 ,
\f3\fs18 y
\f4\fs20 , and
\f3\fs18 z
\f4\fs20 for further comments.\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf2 xz => (float)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf2 This property provides joint read-only access to the
\f3\fs18 x
\f4\fs20 and
\f3\fs18 z
\f4\fs20 properties; they are returned as a two-element
\f3\fs18 float
\f4\fs20 vector. This can be useful in complex spatial models in which the spatiality of interactions/maps differs from the overall dimensionality of the model. See the documentation for the separate properties
\f3\fs18 x
\f4\fs20 and
\f3\fs18 z
\f4\fs20 for further comments.\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf2 y <\'96> (float$)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf2 A user-defined
\f3\fs18 float
\f4\fs20 value. The value of
\f3\fs18 y
\f4\fs20 is initially undefined (i.e., has an effectively random value that could be different every time you run your model); if you wish it to have a defined value, you must arrange that yourself by explicitly setting its value prior to using it elsewhere in your code, typically in a
\f3\fs18 modifyChild()
\f4\fs20 callback. The value of
\f4\fs20 is initially undefined (i.e., has an effectively random value that could be different every time you run your model); if you wish it to have a defined value, you must arrange that yourself by explicitly setting its value prior to using it elsewhere in your code. The value of
\f3\fs18 y
\f4\fs20 is not used by SLiM unless the optional \'93continuous space\'94 facility is enabled with the
\f3\fs18 dimensionality
Expand All @@ -3084,19 +3132,33 @@ See the description of the
\f3\fs18 y
\f4\fs20 as an additional tag value of type
\f3\fs18 float
\f5\fs20 .\
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f4\fs20 .\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf0 z <\'96> (float$)\
\pard\pardeftab720\li547\ri720\sb60\sa60\partightenfactor0
\f3\fs18 \cf2 yz => (float)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf0 A user-defined
\f4\fs20 \cf2 This property provides joint read-only access to the
\f3\fs18 y
\f4\fs20 and
\f3\fs18 z
\f4\fs20 properties; they are returned as a two-element
\f3\fs18 float
\f4\fs20 vector. This can be useful in complex spatial models in which the spatiality of interactions/maps differs from the overall dimensionality of the model. See the documentation for the separate properties
\f3\fs18 y
\f4\fs20 and
\f3\fs18 z
\f4\fs20 for further comments.\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf2 z <\'96> (float$)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf2 A user-defined
\f3\fs18 float
\f4\fs20 value. The value of
\f3\fs18 z
\f4\fs20 is initially undefined (i.e., has an effectively random value that could be different every time you run your model); if you wish it to have a defined value, you must arrange that yourself by explicitly setting its value prior to using it elsewhere in your code, typically in a
\f3\fs18 modifyChild()
\f4\fs20 callback. The value of
\f4\fs20 is initially undefined (i.e., has an effectively random value that could be different every time you run your model); if you wish it to have a defined value, you must arrange that yourself by explicitly setting its value prior to using it elsewhere in your code. The value of
\f3\fs18 z
\f4\fs20 is not used by SLiM unless the optional \'93continuous space\'94 facility is enabled with the
\f3\fs18 dimensionality
Expand All @@ -3114,7 +3176,7 @@ See the description of the
\f3\fs18 z
\f4\fs20 as an additional tag value of type
\f3\fs18 float
\f5\fs20 .\
\f4\fs20 .\
\pard\pardeftab397\ri720\sb120\sa60\partightenfactor0
\f1\i\fs22 \cf0 5.7.2
Expand Down
1 change: 1 addition & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ development head (in the master branch):
modify recipes that use addRecombinant() to use randomizeStrands=T where appropriate: 16.17, 16.25
add lowerTri(), upperTri(), and diag(); thanks to Nick O'Brien (@nobrien97) for this contribution
modify recipes to use count= parameter to addCrossed() etc., where appropriate: 16.3, 16.23
add xy, xz, yz, and xyz properties to Individual that allow joint access to the x/y/z properties, for easier spatiality operations in complex spatial models (and to support some unit testing additions)


version 4.0.1 (Eidos version 3.0.1):
Expand Down
54 changes: 24 additions & 30 deletions core/individual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,36 +608,6 @@ EidosValue_SP Individual::GetProperty(EidosGlobalStringID p_property_id)
}

return result_SP;
/*
The code above for uniqueMutations can be tested with the simple SLiM script below. Positions are tested with
identical() instead of the mutation vectors themselves, only because the sorted order of mutations at exactly
the same position may differ; identical(um1, um2) will occasionally flag these as false positives.
initialize() {
initializeMutationRate(1e-5);
initializeMutationType("m1", 0.5, "f", 0.0);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99999);
initializeRecombinationRate(1e-8);
}
1 early() {
sim.addSubpop("p1", 500);
}
1:20000 late() {
for (i in p1.individuals)
{
um1 = i.uniqueMutations;
um2 = sortBy(unique(i.genomes.mutations), "position");
if (!identical(um1.position, um2.position))
{
print("Mismatch!");
print(um1.position);
print(um2.position);
}
}
}
*/
}

// variables
Expand Down Expand Up @@ -723,6 +693,25 @@ EidosValue_SP Individual::GetProperty(EidosGlobalStringID p_property_id)
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float_singleton(spatial_z_));
}

// These properties are presently undocumented, used for testing purposes, but maybe they are useful to others?
// They provide x/y/z as pairs or a triplet, whether the model is spatial or not, regardless of dimensionality
case gEidosID_xy:
{
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float_vector({spatial_x_, spatial_y_}));
}
case gEidosID_xz:
{
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float_vector({spatial_x_, spatial_z_}));
}
case gEidosID_yz:
{
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float_vector({spatial_y_, spatial_z_}));
}
case gEidosID_xyz:
{
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float_vector({spatial_x_, spatial_y_, spatial_z_}));
}

// all others, including gID_none
default:
return super::GetProperty(p_property_id);
Expand Down Expand Up @@ -1045,6 +1034,7 @@ EidosValue *Individual::GetProperty_Accelerated_spatialPosition(EidosObject **p_
else
{
// Mixed-species group, so we have to figure out the dimensionality for each individual separately
// FIXME: Do we really want to allow this? seems crazy - how would the user actually use this?
float_result = (new (gEidosValuePool->AllocateChunk()) EidosValue_Float_vector());

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
Expand Down Expand Up @@ -2220,6 +2210,10 @@ const std::vector<EidosPropertySignature_CSP> *Individual_Class::Properties(void
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_x, false, kEidosValueMaskFloat | kEidosValueMaskSingleton))->DeclareAcceleratedGet(Individual::GetProperty_Accelerated_x)->DeclareAcceleratedSet(Individual::SetProperty_Accelerated_x));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_y, false, kEidosValueMaskFloat | kEidosValueMaskSingleton))->DeclareAcceleratedGet(Individual::GetProperty_Accelerated_y)->DeclareAcceleratedSet(Individual::SetProperty_Accelerated_y));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_z, false, kEidosValueMaskFloat | kEidosValueMaskSingleton))->DeclareAcceleratedGet(Individual::GetProperty_Accelerated_z)->DeclareAcceleratedSet(Individual::SetProperty_Accelerated_z));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_xy, true, kEidosValueMaskFloat)));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_xz, true, kEidosValueMaskFloat)));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_yz, true, kEidosValueMaskFloat)));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gEidosStr_xyz, true, kEidosValueMaskFloat)));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gStr_age, false, kEidosValueMaskInt | kEidosValueMaskSingleton))->DeclareAcceleratedGet(Individual::GetProperty_Accelerated_age)->DeclareAcceleratedSet(Individual::SetProperty_Accelerated_age));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gStr_meanParentAge, true, kEidosValueMaskFloat | kEidosValueMaskSingleton)));
properties->emplace_back((EidosPropertySignature *)(new EidosPropertySignature(gStr_pedigreeID, true, kEidosValueMaskInt | kEidosValueMaskSingleton))->DeclareAcceleratedGet(Individual::GetProperty_Accelerated_pedigreeID));
Expand Down
4 changes: 2 additions & 2 deletions core/interaction_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5703,8 +5703,8 @@ EidosValue_SP InteractionType::ExecuteMethod_neighborCountOfPoint(EidosGlobalStr
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Int_singleton(neighborCount));
}

// ********************* - (void)setConstraints(string$ who, [Ns$ sex = NULL], [Ni$ tag = NULL], [Ni$ minAge = NULL], [Ni$ maxAge = NULL], [Nl$ migrant = NULL],
// [Nl$ tagL0 = NULL], [Nl$ tagL1 = NULL], [Nl$ tagL2 = NULL], [Nl$ tagL3 = NULL], [Nl$ tagL4 = NULL])
// ********************* - (void)setConstraints(string$ who, [Ns$ sex = NULL], [Ni$ tag = NULL], [Ni$ minAge = NULL], [Ni$ maxAge = NULL], [Nl$ migrant = NULL],
// [Nl$ tagL0 = NULL], [Nl$ tagL1 = NULL], [Nl$ tagL2 = NULL], [Nl$ tagL3 = NULL], [Nl$ tagL4 = NULL])
//
EidosValue_SP InteractionType::ExecuteMethod_setConstraints(EidosGlobalStringID p_method_id, const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter)
{
Expand Down
Loading

0 comments on commit 46ef799

Please sign in to comment.