66import beast .base .core .Description ;
77import beast .base .core .Input ;
88import beast .base .core .Input .Validate ;
9+ import beast .base .core .Log ;
910import beast .base .evolution .alignment .Alignment ;
1011import beast .base .evolution .alignment .Sequence ;
1112import 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