Example #1
0
	def combine_max_LLH(self, bestpar, tpartitions, pmap, spe_setting = None, fo = "", plot = True):
		idxpar = self._convert2idx(bestpar)
		bestsupport = [0.0] * self.numtaxa
		for par in idxpar:
			w = pmap.get(par, 0.0)
			for idx in par:
				bestsupport[idx] = float(w)/float(len(tpartitions))
		
		self.meansupport = numpy.mean(bestsupport)
		spes, support = self._partition2names(bestpar, bestsupport)
		
		if spe_setting != None and plot:
			spe_setting = add_bayesain_support(delimitation = spe_setting, pmap = pmap, taxaorder =self.taxaorder, numpar = len(tpartitions))
			spe_setting.root.write(features = ["bs"], outfile = fo + ".ml.tre", format = 0)
			showTree(delimitation = spe_setting, scale = self.scale, render = True, fout = fo, form = "svg", show_support = True)
			showTree(delimitation = spe_setting, scale = self.scale, render = True, fout = fo, form = "png", show_support = True)
		
		fo_bestpar = open(fo, "w")
		fo_bestpar.write("# Max likilhood partition \n")
		for i in range(len(spes)):
			spe = spes[i]
			sup = support[i]
			fo_bestpar.write("Species " + str(i+1) + " (support = " + "{0:.3f}".format(sup) + ")\n")
			fo_bestpar.write("     " + self._print_list(spe) + "\n")
		fo_bestpar.close()
Example #2
0
    def combine_max_LLH(self,
                        bestpar,
                        tpartitions,
                        pmap,
                        spe_setting=None,
                        fo="",
                        plot=True):
        idxpar = self._convert2idx(bestpar)
        bestsupport = [0.0] * self.numtaxa
        for par in idxpar:
            w = pmap.get(par, 0.0)
            for idx in par:
                bestsupport[idx] = float(w) / float(len(tpartitions))

        self.meansupport = numpy.mean(bestsupport)
        spes, support = self._partition2names(bestpar, bestsupport)

        if spe_setting != None and plot:
            spe_setting = add_bayesain_support(delimitation=spe_setting,
                                               pmap=pmap,
                                               taxaorder=self.taxaorder,
                                               numpar=len(tpartitions))
            spe_setting.root.write(features=["bs"],
                                   outfile=fo + ".ml.tre",
                                   format=0)
            showTree(delimitation=spe_setting,
                     scale=self.scale,
                     render=True,
                     fout=fo,
                     form="svg",
                     show_support=True)
            showTree(delimitation=spe_setting,
                     scale=self.scale,
                     render=True,
                     fout=fo,
                     form="png",
                     show_support=True)

        fo_bestpar = open(fo, "w")
        fo_bestpar.write("# Max likilhood partition \n")
        for i in range(len(spes)):
            spe = spes[i]
            sup = support[i]
            fo_bestpar.write("Species " + str(i + 1) + " (support = " +
                             "{0:.3f}".format(sup) + ")\n")
            fo_bestpar.write("     " + self._print_list(spe) + "\n")
        fo_bestpar.close()
Example #3
0
	def combine_simple_heuristic(self, tpartitions, pmap, idxpars, fo, sp_setting = [], plot = True):
		maxw = 0
		bestpar = None
		bestsupport = None
		
		for i in range(len(tpartitions)): 
			partition = tpartitions[i]
			pars = idxpars[i]
			support = [0.0] * self.numtaxa
			sumw = 0.0
			for par in pars:
				w = pmap.get(par, 0.0)
				for idx in par:
					support[idx] = float(w)/float(len(tpartitions))
					sumw = sumw + w 
			if sumw > maxw:
				maxw = sumw
				bestpar = i
				bestsupport = support
		
		self.meansupport = numpy.mean(bestsupport)
		spes, support = self._partition2names(tpartitions[bestpar], bestsupport)
		spe_setting = sp_setting[bestpar]
		
		if plot:
			spe_setting = add_bayesain_support(delimitation = spe_setting, pmap = pmap, taxaorder =self.taxaorder, numpar = len(tpartitions))
			spe_setting.root.write(features = ["bs"], outfile = fo + ".sh.tre", format = 0)
			showTree(delimitation = spe_setting, scale = self.scale, render = True, fout = fo, form = "svg", show_support = True)
			showTree(delimitation = spe_setting, scale = self.scale, render = True, fout = fo, form = "png", show_support = True)
		
		fo_bestpar = open(fo, "w")
		fo_bestpar.write("# Most supported partition found by simple heuristic search\n")
		for i in range(len(spes)):
			spe = spes[i]
			sup = support[i]
			fo_bestpar.write("Species " + str(i+1) + " (support = " + "{0:.3f}".format(sup) + ")\n")
			fo_bestpar.write("     " + self._print_list(spe) + "\n")
		fo_bestpar.close()
		
		return tpartitions[bestpar]
Example #4
0
    def combine_simple_heuristic(self,
                                 tpartitions,
                                 pmap,
                                 idxpars,
                                 fo,
                                 sp_setting=[],
                                 plot=True):
        maxw = 0
        bestpar = None
        bestsupport = None

        for i in range(len(tpartitions)):
            partition = tpartitions[i]
            pars = idxpars[i]
            support = [0.0] * self.numtaxa
            sumw = 0.0
            for par in pars:
                w = pmap.get(par, 0.0)
                for idx in par:
                    support[idx] = float(w) / float(len(tpartitions))
                    sumw = sumw + w
            if sumw > maxw:
                maxw = sumw
                bestpar = i
                bestsupport = support

        self.meansupport = numpy.mean(bestsupport)
        spes, support = self._partition2names(tpartitions[bestpar],
                                              bestsupport)
        spe_setting = sp_setting[bestpar]

        if plot:
            spe_setting = add_bayesain_support(delimitation=spe_setting,
                                               pmap=pmap,
                                               taxaorder=self.taxaorder,
                                               numpar=len(tpartitions))
            spe_setting.root.write(features=["bs"],
                                   outfile=fo + ".sh.tre",
                                   format=0)
            showTree(delimitation=spe_setting,
                     scale=self.scale,
                     render=True,
                     fout=fo,
                     form="svg",
                     show_support=True)
            showTree(delimitation=spe_setting,
                     scale=self.scale,
                     render=True,
                     fout=fo,
                     form="png",
                     show_support=True)

        fo_bestpar = open(fo, "w")
        fo_bestpar.write(
            "# Most supported partition found by simple heuristic search\n")
        for i in range(len(spes)):
            spe = spes[i]
            sup = support[i]
            fo_bestpar.write("Species " + str(i + 1) + " (support = " +
                             "{0:.3f}".format(sup) + ")\n")
            fo_bestpar.write("     " + self._print_list(spe) + "\n")
        fo_bestpar.close()

        return tpartitions[bestpar]