#! /usr/bin/env python from cipres_boilerplate import * import os, sys from optparse import OptionParser from PIPRes.util.client_import import * _LOG = cipresGetLogger('Rec-I-DCM-Runner.py') parser = OptionParser() parser.add_option("-p", "--param", dest="paramfile", help="FILE with commands (preempts the use of stdin)", metavar="FILE") parser.add_option("-d", "--debug", dest="debugging", action="store_true", default=False, help="run in debug mode") (options, dataFiles) = parser.parse_args() if options.paramfile is None: print >>sys.stderr, """Enter the commands to pass to the Rec-I-DCM implementation in = Enter an EOF (the Control-%s key combination on a newline) to finish. """ % (sys.platform is 'win32' and 'Z' or 'D') params = sys.stdin.read() print params sys.exit(0) if dataFiles: for file in dataFiles: # getContentFromNexus returns a list of triples of character data, trees, # and taxa labels that were found in the same file # Within each element of this content list, the taxa are the same content = getContentFromNexus(file, treatStringAsPath = True) if len(content) > 1: _LOG.warn('Multiple sets of taxa found in %s. Only the first will be used' % file) elif not content: sys.exit('No taxa/data found in %s' % file) firstCDAT = content[0] # We'll just use the first tree treeList = firstCDAT.treeList if len(treeList) > 1: _LOG.warn('Multiple trees found in %s. Only the first will be used' % file) elif not content: sys.exit('No trees found in %s' % file) startingTree = treeList[0] # We'll just use the first matrix matrixList = firstCDAT.matrixList if len(matrixList) > 1: _LOG.warn('Multiple data matrices found in %s. Only the first will be used' % file) elif not content: sys.exit('No characters (DATA/CHARACTER blocks) found in %s' % file) matrix = matrixList[0] else: if options.debugging: startingTree = CipresTree('(1:1,(2:2,3:3):2,4:3)') matrix = dnaToCipresMatrix([ 'RCGTCACGTG', 'ACGT-ACTTC', 'ATGCAG?TTC', 'ATG-ACGNTC' ], aligned=True) else: sys.exit('Expecting paths to a NEXUS file as an argument') recidcmImpl = getFirstCipresService(interface=CipresIDL_api1.Rid3TreeImprove, applicationName='recidcm3') try: pass finally: recidcmImpl.release()