def test_write_to_file(self): tmp = NamedTemporaryFile(delete=False, suffix=".nex") tmp.close() nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex')) nex.write_to_file(tmp.name) assert os.path.isfile(tmp.name) n2 = NexusReader(tmp.name) assert n2.data.matrix == nex.data.matrix assert sorted(n2.data.taxa) == sorted(nex.data.taxa) os.unlink(tmp.name) # cleanup
def hash(salt, value): return hashlib.md5(("%s-%s" % (salt, value)).encode('ascii')).hexdigest() if __name__ == '__main__': # pragma: no cover from optparse import OptionParser parser = OptionParser(usage="usage: %prog fudge.nex output.nex") options, args = parser.parse_args() try: nexusname = args[0] except IndexError: print(__doc__) print("Author: %s\n" % __author__) parser.print_help() sys.exit() try: newnexus = args[1] except IndexError: newnexus = None nexus = NexusReader(nexusname) nexus = anonymise(nexus) if newnexus is not None: nexus.write_to_file(newnexus) print("New nexus written to %s" % newnexus) else: print(nexus.write_to_file(hash('filename', nexusname)))