Skip to content

Commit c336719

Browse files
authored
Merge pull request #103 from Lars-B/feature/alignment-gen-seed
Adding option to set seed for alignment generation
2 parents 4067f1c + 64b836e commit c336719

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/beastfx/app/seqgen/SimulatedAlignment.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import beast.base.core.Description;
77
import beast.base.core.Input;
88
import beast.base.core.Input.Validate;
9+
import beast.base.core.Log;
910
import beast.base.evolution.alignment.Alignment;
1011
import beast.base.evolution.alignment.Sequence;
1112
import beast.base.evolution.branchratemodel.BranchRateModel;
@@ -32,7 +33,12 @@ public class SimulatedAlignment extends Alignment {
3233
final public Input<Integer> m_sequenceLengthInput = new Input<>("sequencelength", "nr of samples to generate (default 1000).", 1000);
3334
final public Input<String> m_outputFileNameInput = new Input<>(
3435
"outputFileName",
35-
"If provided, simulated alignment is additionally written to this file.");
36+
"If provided, simulated alignment is additionally written to this file.");
37+
final public Input<Long> localSeedInput = new Input<>(
38+
"seed",
39+
"Optional local random seed for simulating this alignment. If not set, global seed is used.",
40+
Input.Validate.OPTIONAL
41+
);
3642

3743
/**
3844
* nr of samples to generate *
@@ -87,9 +93,24 @@ public void initAndValidate() {
8793
m_outputFileName = m_outputFileNameInput.get();
8894

8995
sequenceInput.get().clear();
90-
91-
simulate();
92-
96+
97+
Long customSeed = localSeedInput.get();
98+
long originalSeed = Randomizer.getSeed();
99+
long seedToUse = customSeed != null ? customSeed : originalSeed;
100+
101+
if (customSeed != null) {
102+
Log.info.println();
103+
Log.info.println("Random number seed for alignment simulation: " + customSeed);
104+
Log.info.println();
105+
}
106+
107+
try {
108+
Randomizer.setSeed(seedToUse);
109+
simulate();
110+
} finally {
111+
Randomizer.setSeed(originalSeed);
112+
}
113+
93114
// Write simulated alignment to disk if requested:
94115
if (m_outputFileName != null) {
95116
PrintStream pstream;

0 commit comments

Comments
 (0)