Exemplo n.º 1
0
 def test_anonymise_taxa(self):
     filename = os.path.join(EXAMPLE_DIR, 'example.nex')
     nex = anonymise(NexusReader(filename), salt="test")
     for old_taxon in ['Harry', 'Simon', 'Betty', 'Louise']:
         assert old_taxon not in nex.data.matrix, \
             '%s should have been anonymised' % old_taxon
     
     assert nex.data.matrix[hash("test", "Betty")] == \
         ['1', '0']
     assert nex.data.matrix[hash("test", "Harry")] == \
         ['0', '0']
     assert nex.data.matrix[hash("test", "Simon")] == \
         ['0', '1']
     assert nex.data.matrix[hash("test", "Louise")] == \
         ['1', '1']
Exemplo n.º 2
0
    def test_anonymise_taxa(self):
        filename = os.path.join(EXAMPLE_DIR, 'example.nex')
        nex = anonymise(NexusReader(filename), salt="test")
        for old_taxon in ['Harry', 'Simon', 'Betty', 'Louise']:
            assert old_taxon not in nex.data.matrix, \
                '%s should have been anonymised' % old_taxon

        assert nex.data.matrix[hash("test", "Betty")] == \
            ['1', '0']
        assert nex.data.matrix[hash("test", "Harry")] == \
            ['0', '0']
        assert nex.data.matrix[hash("test", "Simon")] == \
            ['0', '1']
        assert nex.data.matrix[hash("test", "Louise")] == \
            ['1', '1']
Exemplo n.º 3
0
 def test_anonymise_characters(self):
     nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example-characters.nex'))
     nex = anonymise(nex)
     
     expected_taxa = ['A', 'B', 'C', 'D', 'E']
     # check taxa block
     for taxon in expected_taxa:
         assert taxon not in nex.taxa.taxa, '%s should have been anonymised' % taxon
         hashtaxon = hash(os.path.join(EXAMPLE_DIR, 'example-characters.nex'), taxon)
         assert hashtaxon in nex.taxa.taxa
     
     # check characters block
     for taxon in expected_taxa:
         assert taxon not in nex.data.taxa, '%s should have been anonymised' % taxon
         hashtaxon = hash(os.path.join(EXAMPLE_DIR, 'example-characters.nex'), taxon)
         assert hashtaxon in nex.data.taxa
Exemplo n.º 4
0
 def test_anonymise_translated_trees(self):
     nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example-translated.trees'))
     nex = anonymise(nex)
     expected = ['Chris', 'Bruce', 'Tom', 'Henry', 'Timothy', 'Mark', 'Simon', 'Fred', 'Kevin', 'Roger', 'Michael', 'Andrew', 'David']
     assert len(nex.trees.taxa) == len(expected)
     for taxon in expected:
         hashtaxon = hash(os.path.join(EXAMPLE_DIR, 'example-translated.trees'), taxon)
         assert hashtaxon in nex.trees.taxa
Exemplo n.º 5
0
 def test_anonymise_data_with_interleave(self):
     filename = os.path.join(EXAMPLE_DIR, 'example3.nex')
     nex = anonymise(NexusReader(filename), salt="test")
     for old_taxon in ['Harry', 'Simon']:
         assert old_taxon not in nex.data.matrix, \
             '%s should have been anonymised' % old_taxon
         h = hash("test", old_taxon)
         assert h in nex.data.matrix
         assert h in nex.data.taxa
         assert nex.data.matrix[h] == ['0', '1', '2', '3', '4', '5']
Exemplo n.º 6
0
 def test_anonymise_data_with_interleave(self):
     filename = os.path.join(EXAMPLE_DIR, 'example3.nex')
     nex = anonymise(NexusReader(filename), salt="test")
     for old_taxon in ['Harry', 'Simon']:
         assert old_taxon not in nex.data.matrix, \
             '%s should have been anonymised' % old_taxon
         h = hash("test", old_taxon)
         assert h in nex.data.matrix
         assert h in nex.data.taxa
         assert nex.data.matrix[h] == ['0', '1', '2', '3', '4', '5']
Exemplo n.º 7
0
 def test_anonymise_beast_treefile(self):
     nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example-beast.trees'))
     nex = anonymise(nex)
     expected = [
         "R1", "B2", "S3", "T4", "A5", "E6", "U7", "T8", "T9", "F10", "U11", 
         "T12", "N13", "F14", "K15", "N16", "I17", "L18", "S19", "T20", "V21", 
         "R22", "M23", "H24", "M25", "M26", "M27", "R28", "T29", "M30", "P31", 
         "T32", "R33", "P34", "R35", "W36", "F37", "F38"
     ]
     # check taxa block
     for taxon in expected:
         assert taxon not in nex.taxa.taxa, '%s should have been anonymised' % taxon
         hashtaxon = hash(os.path.join(EXAMPLE_DIR, 'example-beast.trees'), taxon)
         assert hashtaxon in nex.taxa.taxa
     
     # check trees block
     for taxon in expected:
         assert taxon not in nex.trees.taxa, '%s should have been anonymised' % taxon
         hashtaxon = hash(os.path.join(EXAMPLE_DIR, 'example-beast.trees'), taxon)
         assert hashtaxon in nex.trees.taxa
Exemplo n.º 8
0
 def test_anonymise_data_with_labels(self):
     filename = os.path.join(EXAMPLE_DIR, 'example2.nex')
     nex = anonymise(NexusReader(filename),  salt="test")
     for old_taxon in ['John', 'Paul', 'George', 'Ringo']:
         assert old_taxon not in nex.data.matrix, \
             '%s should have been anonymised' % old_taxon
         h = hash("test", old_taxon)
         # check data block
         assert h in nex.data.matrix, "Missing %s" % h
         assert nex.data.matrix[h] == ['a', 'c', 't', 'g']
         # check taxa block
         assert h in nex.taxa.taxa
Exemplo n.º 9
0
 def test_anonymise_data_with_labels(self):
     filename = os.path.join(EXAMPLE_DIR, 'example2.nex')
     nex = anonymise(NexusReader(filename), salt="test")
     for old_taxon in ['John', 'Paul', 'George', 'Ringo']:
         assert old_taxon not in nex.data.matrix, \
             '%s should have been anonymised' % old_taxon
         h = hash("test", old_taxon)
         # check data block
         assert h in nex.data.matrix, "Missing %s" % h
         assert nex.data.matrix[h] == ['a', 'c', 't', 'g']
         # check taxa block
         assert h in nex.taxa.taxa
Exemplo n.º 10
0
    def test_anonymise_characters(self):
        filename = os.path.join(EXAMPLE_DIR, 'example-characters.nex')
        nex = anonymise(NexusReader(filename), salt="test")
        
        expected_taxa = ['A', 'B', 'C', 'D', 'E']
        for taxon in expected_taxa:
            h = hash("test", taxon)
            # check taxa block
            assert taxon not in nex.taxa.taxa, \
                '%s should have been anonymised' % taxon
            assert h in nex.taxa.taxa

            # check characters block
            assert taxon not in nex.data.taxa, \
                '%s should have been anonymised' % taxon
            assert h in nex.data.taxa
Exemplo n.º 11
0
    def test_anonymise_characters(self):
        filename = os.path.join(EXAMPLE_DIR, 'example-characters.nex')
        nex = anonymise(NexusReader(filename), salt="test")

        expected_taxa = ['A', 'B', 'C', 'D', 'E']
        for taxon in expected_taxa:
            h = hash("test", taxon)
            # check taxa block
            assert taxon not in nex.taxa.taxa, \
                '%s should have been anonymised' % taxon
            assert h in nex.taxa.taxa

            # check characters block
            assert taxon not in nex.data.taxa, \
                '%s should have been anonymised' % taxon
            assert h in nex.data.taxa
Exemplo n.º 12
0
 def test_anonymise_beast_treefile(self):
     filename = os.path.join(EXAMPLE_DIR, 'example-beast.trees')
     nex = anonymise(NexusReader(filename), salt="test")
     expected = [
         "R1", "B2", "S3", "T4", "A5", "E6", "U7", "T8", "T9", "F10", "U11",
         "T12", "N13", "F14", "K15", "N16", "I17", "L18", "S19", "T20",
         "V21", "R22", "M23", "H24", "M25", "M26", "M27", "R28", "T29",
         "M30", "P31", "T32", "R33", "P34", "R35", "W36", "F37", "F38"
     ]
     for taxon in expected:
         h = hash("test", taxon)
         # check taxa block
         assert taxon not in nex.taxa.taxa, \
             '%s should have been anonymised' % taxon
         assert h in nex.taxa.taxa
         
         # check trees block
         assert taxon not in nex.trees.taxa, \
             '%s should have been anonymised' % taxon
         assert h in nex.trees.taxa
Exemplo n.º 13
0
    def test_anonymise_beast_treefile(self):
        filename = os.path.join(EXAMPLE_DIR, 'example-beast.trees')
        nex = anonymise(NexusReader(filename), salt="test")
        expected = [
            "R1", "B2", "S3", "T4", "A5", "E6", "U7", "T8", "T9", "F10", "U11",
            "T12", "N13", "F14", "K15", "N16", "I17", "L18", "S19", "T20",
            "V21", "R22", "M23", "H24", "M25", "M26", "M27", "R28", "T29",
            "M30", "P31", "T32", "R33", "P34", "R35", "W36", "F37", "F38"
        ]
        for taxon in expected:
            h = hash("test", taxon)
            # check taxa block
            assert taxon not in nex.taxa.taxa, \
                '%s should have been anonymised' % taxon
            assert h in nex.taxa.taxa

            # check trees block
            assert taxon not in nex.trees.taxa, \
                '%s should have been anonymised' % taxon
            assert h in nex.trees.taxa