def get_tree(self): matrix = matrixRepresentation(self.trees) if (len(matrix[0]) == 0 or len(matrix[1]) == 0): return (str(Tree())) f = tempfile.NamedTemporaryFile() prefix = f.name f.close() f = open(prefix, 'w') writeRatchetInputFile(matrix, f, filePrefix=prefix, numRatchetIterations=self.numIters) f.close() pipe = Popen("paup -n %s" % prefix, shell=True, stdout=PIPE, stderr=PIPE) (out, err) = pipe.communicate() if self.mrpType == 'gmrp': trees = getConsensusTreesFromPaupFiles(prefix) output = trees['gmrp'] elif self.mrpType == 'rmrp': mpTrees = readTreesFromRatchet(prefix + '.tre') output = random.choice(mpTrees) os.remove(prefix) os.remove(prefix + ".log") os.remove(prefix + ".gmrp") os.remove(prefix + ".smrp") os.remove(prefix + ".mmrp") os.remove(prefix + ".tre") os.remove(prefix + ".tre.nex") return output
## You should have received a copy of the GNU General Public License ## along with spruce. If not, see <http://www.gnu.org/licenses/>. ########################################################################### from optparse import OptionParser from spruce.unrooted import * from spruce.metrics import * from spruce.mrp import readTreesFromRatchet, getGreedyConsensus from newick_modified.lexer import LexerError desc = ' '.join(['This script prints the greedy consensus of a set of trees, as', 'calculated by PAUP*. Trees must be specified in Newick', 'format.']) parser = OptionParser(usage = "usage: %prog [options]", description = desc) parser.add_option("-t", "--trees", dest = "estimate_tree", help = "read supertrees from FILE", metavar = "FILE") parser.add_option("-s", "--sources", dest = "sources_file", help = "read source trees from FILE", metavar = "FILE") (options, args) = parser.parse_args() if (options.estimate_tree == None or options.sources_file == None): parser.error("values for both options must be specified\ntry running with the --help flag") sourceTrees = [parse_tree(source) for source in readMultipleTreesFromFile(options.sources_file)] try: supertrees = [parse_tree(estimate) for estimate in readMultipleTreesFromFile(options.estimate_tree)] except LexerError: supertrees = [parse_tree(estimate) for estimate in readTreesFromRatchet(options.estimate_tree)] lines = getGreedyConsensus(sourceTrees, supertrees, rooted = True) print ''.join(lines), '\n'
parser = OptionParser(usage="usage: %prog [options]", description=desc) parser.add_option("-t", "--true", dest="true_tree", help="read true tree from FILE", metavar="FILE") parser.add_option("-e", "--estimate", dest="estimate_tree", help="read estimate tree from FILE", metavar="FILE") (options, args) = parser.parse_args() if (options.estimate_tree == None or options.true_tree == None): parser.error( "values for both options must be specified\ntry running with the --help flag" ) try: trueTree = readNewickFile(options.true_tree) except: trueTree = parse_tree(readTreesFromRatchet(options.true_tree)[0]) try: estimateTree = readNewickFile(options.estimate_tree) except: estimateTree = parse_tree(readTreesFromRatchet(options.estimate_tree)[0]) print getFpFnRfRates(trueTree, estimateTree)
metavar="FILE") parser.add_option("-s", "--sources", dest="sources_file", help="read source trees from FILE", metavar="FILE") (options, args) = parser.parse_args() if (options.estimate_tree == None or options.sources_file == None): parser.error( "values for both options must be specified\ntry running with the --help flag" ) sourceTrees = [ parse_tree(source) for source in readMultipleTreesFromFile(options.sources_file) ] try: supertrees = [ parse_tree(estimate) for estimate in readMultipleTreesFromFile(options.estimate_tree) ] except LexerError: supertrees = [ parse_tree(estimate) for estimate in readTreesFromRatchet(options.estimate_tree) ] lines = getGreedyConsensus(sourceTrees, supertrees, rooted=True) print ''.join(lines), '\n'
from optparse import OptionParser from spruce.unrooted import * from spruce.metrics import * from spruce.mrp import readTreesFromRatchet from newick_modified import parse_tree desc = ' '.join(['This script prints the FP rate, FN rate, and Robinson-Foulds', 'distance between a pair of trees. Each tree must be', 'specified in Newick format.']) parser = OptionParser(usage = "usage: %prog [options]", description = desc) parser.add_option("-t", "--true", dest = "true_tree", help = "read true tree from FILE", metavar = "FILE") parser.add_option("-e", "--estimate", dest = "estimate_tree", help = "read estimate tree from FILE", metavar = "FILE") (options, args) = parser.parse_args() if (options.estimate_tree == None or options.true_tree == None): parser.error("values for both options must be specified\ntry running with the --help flag") try: trueTree = readNewickFile(options.true_tree) except: trueTree = parse_tree(readTreesFromRatchet(options.true_tree)[0]) try: estimateTree = readNewickFile(options.estimate_tree) except: estimateTree = parse_tree(readTreesFromRatchet(options.estimate_tree)[0]) print getFpFnRfRates(trueTree, estimateTree)