Esempio n. 1
0
 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
Esempio n. 2
0
        print("%d trees found with %d translated taxa" %
              (nexus.trees.ntrees, len(nexus.trees.translators)))

    # Delete trees
    if options.deltree:
        nexus = run_deltree(options.deltree, nexus, options.quiet)

    # Resample trees
    if options.resample:
        nexus = run_resample(options.resample, nexus, options.quiet)

    # Randomly sample trees
    if options.random:
        nexus = run_random(options.random, nexus, options.quiet)

    # remove comments
    if options.removecomments:
        nexus = run_removecomments(nexus, options.quiet)

    # detranslate
    if options.detranslate:
        nexus = run_detranslate(nexus)

    if newnexus is not None:
        nexus.write_to_file(newnexus)
        if not options.quiet:
            print("New nexus with %d trees written to %s" %
                  (nexus.trees.ntrees, newnexus))
    else:
        print(nexus.write())
        sys.exit("No trees found in found %s!" % nexusname)
    if options.quiet is False:
        print "%d trees found with %d translated taxa" % (nexus.trees.ntrees, len(nexus.trees.translators))

    # Delete trees
    if options.deltree:
        nexus = run_deltree(options.deltree, nexus, options.quiet)

    # Resample trees
    if options.resample:
        nexus = run_resample(options.resample, nexus, options.quiet)

    # Randomly sample trees
    if options.random:
        nexus = run_random(options.random, nexus, options.quiet)

    # remove comments
    if options.removecomments:
        nexus = run_removecomments(nexus, options.quiet)

    # detranslate
    if options.detranslate:
        nexus = run_detranslate(nexus, options.quiet)

    if newnexus is not None:
        nexus.write_to_file(newnexus)
        if options.quiet is False:
            print "New nexus with %d trees written to %s" % (nexus.trees.ntrees, newnexus)
    else:
        print nexus.write()
Esempio n. 4
0
def hash(salt, taxon):
    return hashlib.md5("%s-%s" % (salt, taxon)).hexdigest()

if __name__ == '__main__':
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog fudge.nex output.nex")
    options, nexuslist = 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', filename)))
Esempio n. 5
0

def hash(salt, taxon):
    return hashlib.md5("%s-%s" % (salt, taxon)).hexdigest()

if __name__ == '__main__':
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog fudge.nex output.nex")
    options, nexuslist = 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', filename))