From e8b5491aa19fdf8aca2f22889db8521b3fb905a1 Mon Sep 17 00:00:00 2001 From: Jaime Ashander Date: Thu, 26 Jan 2017 09:29:23 -0800 Subject: [PATCH 1/2] Example of test failure output; occurs 1/10 times or so --- devel/occasional_error.txt | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 devel/occasional_error.txt diff --git a/devel/occasional_error.txt b/devel/occasional_error.txt new file mode 100644 index 0000000..d6e4b8b --- /dev/null +++ b/devel/occasional_error.txt @@ -0,0 +1,85 @@ +============================= test session starts ============================== +platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.32, pluggy-0.4.0 +rootdir: /home/jaime/lib/ftprime, inifile: pytest.ini +plugins: cov-2.4.0 +collected 6 items + +tests/test_forwards_algorithm.py . +tests/test_ftprime_with_simuPOP.py . +tests/test_merge_records_with_wf.py ...F + +=================================== FAILURES =================================== +_____________________________ test_simulation_runs _____________________________ + + def test_simulation_runs(): + + records = wf(N=5,ngens=5,nsamples=5,survival=0.5) + + for x in records.dump_records(): + print(x) + + samples = [ (0,0) for _ in range(5) ] +> ts = records.tree_sequence(samples=samples) + +tests/test_merge_records_with_wf.py:63: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +self = ARGrecorder([(5, (6, [])), (6, (6, [CoalescenceRecord(left=0.8212435323883007, right=1.0, node=6, children=(12,), time..., population=0)])), (21, (1, [CoalescenceRecord(left=0.0, right=1.0, node=21, children=(1,), time=1, population=0)]))]) +samples = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)], mutations = None + + def tree_sequence(self,samples,mutations=None): + ''' + Produce a tree sequence from the ARG. + ''' + ts = _msprime.TreeSequence() + ts.load_records( + coalescence_records=list(self.dump_records()), +> samples=samples) +E _msprime.LibraryError: Bad coalescence records in file: Samples must be labeled 0...n-1 and not be internal nodes. + +ftprime/argrecorder.py:60: LibraryError +----------------------------- Captured stdout call ----------------------------- +t: 0 +pop: [5, 6, 7, 8, 9] +10 9 5 1.0 +11 9 7 0.0 +12 8 6 0.8212435323883007 +t: 1 +pop: [10, 11, 7, 12, 9] +13 10 9 0.0 +14 11 9 0.2806010848256748 +15 10 10 0.4513042068306792 +t: 2 +pop: [10, 11, 13, 14, 15] +16 14 14 0.01065709031372597 +17 13 15 0.32783380914661153 +t: 3 +pop: [10, 11, 13, 16, 17] +18 17 17 0.0 +19 10 16 0.6414868623681791 +t: 4 +pop: [18, 11, 13, 19, 17] +20 19 18 0.10754762965969111 +21 11 11 0.0 +CoalescenceRecord(left=0.0, right=1.0, node=21, children=(1,), time=1, population=0) +CoalescenceRecord(left=0.0, right=1.0, node=20, children=(3,), time=1, population=0) +CoalescenceRecord(left=0.0, right=0.10754762965969111, node=19, children=(20,), time=2, population=0) +CoalescenceRecord(left=0.0, right=0.10754762965969111, node=18, children=(4,), time=2, population=0) +CoalescenceRecord(left=0.10754762965969111, right=1.0, node=18, children=(4, 20), time=2, population=0) +CoalescenceRecord(left=0.0, right=1.0, node=17, children=(2, 18), time=3, population=0) +CoalescenceRecord(left=0.6414868623681791, right=1.0, node=16, children=(19,), time=3, population=0) +CoalescenceRecord(left=0.32783380914661153, right=1.0, node=15, children=(17,), time=4, population=0) +CoalescenceRecord(left=0.0, right=0.01065709031372597, node=14, children=(16,), time=4, population=0) +CoalescenceRecord(left=0.01065709031372597, right=1.0, node=14, children=(16,), time=4, population=0) +CoalescenceRecord(left=0.0, right=0.32783380914661153, node=13, children=(17,), time=4, population=0) +CoalescenceRecord(left=0.0, right=0.2806010848256748, node=11, children=(0, 14, 21), time=5, population=0) +CoalescenceRecord(left=0.2806010848256748, right=1.0, node=11, children=(0, 21), time=5, population=0) +CoalescenceRecord(left=0.0, right=0.4513042068306792, node=10, children=(15, 19), time=5, population=0) +CoalescenceRecord(left=0.6414868623681791, right=1.0, node=10, children=(15,), time=5, population=0) +CoalescenceRecord(left=0.4513042068306792, right=0.6414868623681791, node=10, children=(15, 19), time=5, population=0) +CoalescenceRecord(left=0.0, right=0.2806010848256748, node=9, children=(10, 13), time=6, population=0) +CoalescenceRecord(left=0.2806010848256748, right=1.0, node=9, children=(10, 13, 14), time=6, population=0) +CoalescenceRecord(left=0.0, right=0.8212435323883007, node=8, children=(12,), time=6, population=0) +CoalescenceRecord(left=0.0, right=1.0, node=7, children=(11,), time=6, population=0) +CoalescenceRecord(left=0.8212435323883007, right=1.0, node=6, children=(12,), time=6, population=0) +====================== 1 failed, 5 passed in 0.19 seconds ====================== From 808cee1cfec8973e414949fb0eaadbb4f2cff9c2 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 27 Jan 2017 00:16:22 -0800 Subject: [PATCH 2/2] an ordering bug fixed; changed wf so min node always has offspring. --- ftprime/argrecorder.py | 4 ++-- tests/test_merge_records_with_wf.py | 6 ++++++ tests/wf/__init__.py | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ftprime/argrecorder.py b/ftprime/argrecorder.py index 2d4ac37..e6845f1 100644 --- a/ftprime/argrecorder.py +++ b/ftprime/argrecorder.py @@ -132,9 +132,9 @@ def merge_records(new,existing) : children=children, time=time, population=population) - existing[k]=mod_rec + existing[k]=combined_rec k+=1 - existing.insert(k,combined_rec) + existing.insert(k,mod_rec) k+=1 else: # print("dangling right") diff --git a/tests/test_merge_records_with_wf.py b/tests/test_merge_records_with_wf.py index 8aca4e5..f5942db 100644 --- a/tests/test_merge_records_with_wf.py +++ b/tests/test_merge_records_with_wf.py @@ -2,6 +2,9 @@ import msprime from wf import wf +def cr(l,r,n,ch,t,pop=0): + msprime.CoalescenceRecord(left=l, right=r, node=n, children=ch, time=t, population=pop) + def test_1(): new_rec=msprime.CoalescenceRecord(left=0.8, right=1.0, node=18, children=(22,), time=2, population=0) @@ -68,3 +71,6 @@ def test_simulation_runs(): print("Mean pairwise diversity:",ts.get_pairwise_diversity()) print("(should be zero)") assert ts.get_pairwise_diversity() == 0.0 + + tss=ts.simplify() + assert tss.get_pairwise_diversity() == 0.0 diff --git a/tests/wf/__init__.py b/tests/wf/__init__.py index 339d236..6c6053f 100644 --- a/tests/wf/__init__.py +++ b/tests/wf/__init__.py @@ -51,6 +51,14 @@ def wf(N,ngens,nsamples,survival=0.0) : records.add_record( left=bp, right=1.0, parent=rparent, children=(offspring,)) # print(records) + # Hackishly, add imaginary entry so smallest internal node is equal to number of samples + for ind in records.keys(): + print("ind:",ind) + if len(records[ind][1])>0: + if ind > nsamples: + records.add_record(left=0.0,right=1.0,parent=nsamples,children=(next(labels),)) + break + # add phony records that stand in for sampling samples=random.sample(pop,nsamples) records.add_samples(samples=samples,length=1.0)