<div dir="ltr"><div>Hi Adil,</div><div><br></div><div>Are you still thinking of putting this under the Scripts/ folder,</div><div>or Doc/examples maybe?</div><div><br></div><div>Either way, since your script has doctests we ought to be able</div><div>to hook that into the main test suite via our run_tests.py - I</div><div>would guess something like a little file Tests/test_testseq.py</div><div>which runs your doctests would work for this?</div><div><br></div>One thing to watch out for with doctests is they often show<div>up subtle differences cross platform (e.g. Windows vs Linux,</div><div>Python 2.7 vs 3.3 vs 3.6, or C Python vs PyPy vs Jython).</div><div><br></div><div>A pull request sounds good :)</div><div><br></div><div>Peter</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 1, 2017 at 10:18 PM, Adil Iqbal <span dir="ltr"><<a href="mailto:aiqbal85@gmail.com" target="_blank">aiqbal85@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Hello again!</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I've detailed the changes below. You can view updated version of my code here: <a href="https://github.com/Adil-Iqbal/Personal-Projects/blob/master/Test%20Sequence/testseq.py" target="_blank">https://github.com/Adil-<wbr>Iqbal/Personal-Projects/blob/<wbr>master/Test%20Sequence/<wbr>testseq.py</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I believe I have found a satisfactory solution based on Andrew's suggestion.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Before I talk about the solution, I'd like to quickly recap what I discussed in an earlier email; once the global instance of the random.Random class is seeded, it cannot be reverted to its original behavior (which is to re-seed itself with every function call). Instead what happens is that the Random class seeds based on the system date/time -- which means it can only generate one new sequence ever few milliseconds. That is undesirable since I would like the function to be able to produce a unique sequence with every function call if desired by the user. In cases involving for-loops, the function would fail if seeded using the system date/time.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I tried using a global variable named "shuffle_seed" to seed the RNG, which I would incremented with every call, but that would require biopython to use memory to track how many times the user ran the function. That was not ideal since the user's code should be allowed to proceed as independently as possible. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I then tried to implement Andrew's most recent suggestion verbatim. Which was to instantiate the random.Random class outside of the function definition and seed it within the function only if the seed was declared as an argument. The benefit of this method was that I was only creating one instance of the Random class and not having to track the user's function calls. Unfortunately, once the global instance was seeded, it began to generate sequences based on date/time again. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">The solution that works well is that I created 2 global instances of the random class called "seeded_instance" and "anchor_instance." The seeded instance will be seeded with the "rand_seed" argument every function call. If a seed is not declared, the anchor_instance will be invoked to assign a random value to "rand_seed." Since anchor_instance is never seeded, it retains the original desired behavior that I was after.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">This method is efficient, in that only two instances of the Random class are required and generated upon loading the module. It's also entirely independent of the users code AND the rest of biopython, since everything is instantiated. Most importantly, it works perfectly. You may not be able to see it on my github code, but I have been running doctests on my local copy of the code and everything checks out.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I'm open to any other suggestions. Are there any other things that I should do? Would this code be ready for a pull request?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Best, </div><span class="HOEnZb"><font color="#888888"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Adil Iqbal</div></font></span></div>
<br>______________________________<wbr>_________________<br>
Biopython-dev mailing list<br>
<a href="mailto:Biopython-dev@mailman.open-bio.org">Biopython-dev@mailman.open-<wbr>bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython-dev" rel="noreferrer" target="_blank">http://mailman.open-bio.org/<wbr>mailman/listinfo/biopython-dev</a><br></blockquote></div><br></div>