Skip to content

Commit d85a229

Browse files
committed
recipe 16.12 now uses asMatrix()
1 parent 8191252 commit d85a229

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

QtSLiM/recipes/Recipe 16.12 - Forcing a specific pedigree in a nonWF model II.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Keywords: nonWF, non-Wright-Fisher
22

3-
function (i)readIntTable(s$ path)
3+
function (+)readMatrix(s$ path, [string$ sep = ","])
44
{
55
if (!fileExists(path))
6-
stop("readIntTable(): File not found at path " + path);
7-
l = readFile(path);
8-
m = sapply(l, "asInteger(strsplit(applyValue));", simplify="matrix");
9-
return t(m);
6+
stop("readMatrix(): File not found at path " + path);
7+
df = readCSV(path, colNames=F, sep=sep);
8+
m = df.asMatrix();
9+
return m;
1010
}
1111

1212
initialize() {
@@ -21,8 +21,8 @@ initialize() {
2121
initializeRecombinationRate(1e-8);
2222

2323
// read in the pedigree log files
24-
defineConstant("M", readIntTable("mating.txt"));
25-
defineConstant("D", readIntTable("death.txt"));
24+
defineConstant("M", readMatrix("mating.txt", sep=""));
25+
defineConstant("D", readMatrix("death.txt", sep=""));
2626

2727
// extract the ticks for quick lookup
2828
defineConstant("Mt", drop(M[,0]));

SLiMgui/Recipes/Recipe 16.12 - Forcing a specific pedigree in a nonWF model II.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Keywords: nonWF, non-Wright-Fisher
22

3-
function (i)readIntTable(s$ path)
3+
function (+)readMatrix(s$ path, [string$ sep = ","])
44
{
55
if (!fileExists(path))
6-
stop("readIntTable(): File not found at path " + path);
7-
l = readFile(path);
8-
m = sapply(l, "asInteger(strsplit(applyValue));", simplify="matrix");
9-
return t(m);
6+
stop("readMatrix(): File not found at path " + path);
7+
df = readCSV(path, colNames=F, sep=sep);
8+
m = df.asMatrix();
9+
return m;
1010
}
1111

1212
initialize() {
@@ -21,8 +21,8 @@ initialize() {
2121
initializeRecombinationRate(1e-8);
2222

2323
// read in the pedigree log files
24-
defineConstant("M", readIntTable("mating.txt"));
25-
defineConstant("D", readIntTable("death.txt"));
24+
defineConstant("M", readMatrix("mating.txt", sep=""));
25+
defineConstant("D", readMatrix("death.txt", sep=""));
2626

2727
// extract the ticks for quick lookup
2828
defineConstant("Mt", drop(M[,0]));

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ development head (in the master branch):
1919
the color property on Individual no longer guarantees that the value read equals the value set; when a color is set, it is now converted to RGB, so named colors do not round-trip
2020
add a meanParentAge property, to make calculating generation length simpler; unavailable in WF models (like age), 0 for parentless individuals
2121
add DataFrame asMatrix() method to convert a DataFrame into a matrix, if all columns are the same type/class
22+
modify recipe 16.12 II to use asMatrix() to read the mating and death files more elegantly
2223

2324

2425
version 4.0 (Eidos version 3.0):

eidos/eidos_class_DataFrame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ EidosValue_SP EidosDataFrame::ExecuteInstanceMethod(EidosGlobalStringID p_method
367367
}
368368
}
369369

370-
// ********************* - (void)asMatrix()
370+
// ********************* - (void)asMatrix(void)
371371
//
372372
EidosValue_SP EidosDataFrame::ExecuteMethod_asMatrix(EidosGlobalStringID p_method_id, const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter)
373373
{
374-
#pragma unused (p_method_id, p_interpreter)
374+
#pragma unused (p_method_id, p_arguments, p_interpreter)
375375
// First determine what type the matrix would be, and check that all columns match that type
376376
int64_t nrow = RowCount();
377377
const EidosDictionaryHashTable *symbols = DictionarySymbols();

0 commit comments

Comments
 (0)