Example #1
0
def printHelp(xmldict, exit=True):
    """
        print out help info for a function with XML file
        """
    paramlist = xmldict.keys()
    paramlist.sort()
    maxlen = 0
    maxlentype = 0
    for param in paramlist:
        if len(param) > maxlen:
            maxlen = len(param)
        if 'type' in xmldict[param] and len(
                xmldict[param]['type']) > maxlentype:
            maxlentype = len(xmldict[param]['type'])
    for param in paramlist:
        if not 'alias' in xmldict[param] and \
                (not 'modify' in xmldict[param] or str2bool(xmldict[param]['modify']) == True):
            outstr = " "
            outstr += apDisplay.color(apDisplay.rightPadString(param, maxlen),
                                      "green")
            outstr += " :"
            if 'type' in xmldict[param] and xmldict[param]['type'] != None:
                outstr += " (" + apDisplay.rightPadString(
                    xmldict[param]['type'] + ")", maxlentype + 1)
                outstr += " :"
            if 'required' in xmldict[param] and str2bool(
                    xmldict[param]['required']) == True:
                outstr += apDisplay.color(" REQ", "red")
            if 'description' in xmldict[
                    param] and xmldict[param]['description'] != None:
                outstr += " " + xmldict[param]['description']
            elif 'name' in xmldict[param] and xmldict[param]['name'] != None:
                outstr += " " + xmldict[param]['name']
            if 'default' in xmldict[
                    param] and xmldict[param]['default'] != None:
                if 'nargs' in xmldict[param] and xmldict[param][
                        'nargs'] is not None and xmldict[param]['nargs'] > 1:
                    defstr = " (default: "
                    for i in range(len(xmldict[param]['default'])):
                        defstr += str(xmldict[param]['default'][i]) + ","
                    defstr = defstr[:-1] + ")"
                    outstr += apDisplay.color(defstr, "cyan")
                else:
                    outstr += apDisplay.color(
                        " (default: " + str(xmldict[param]['default']) + ")",
                        "cyan")
            if 'example' in xmldict[
                    param] and xmldict[param]['example'] != None:
                outstr += " (example: " + str(xmldict[param]['example']) + ")"
            print outstr
    if exit is True:
        sys.exit(1)
def printHelp(xmldict, exit=True):
	"""
	print out help info for a function with XML file
	"""
	paramlist = xmldict.keys()
	paramlist.sort()
	maxlen = 0
	maxlentype = 0
	for param in paramlist:
		if len(param) > maxlen: 
			maxlen = len(param)
		if 'type' in xmldict[param] and len(xmldict[param]['type']) > maxlentype: 
			maxlentype = len(xmldict[param]['type'])
	for param in paramlist:
		if not 'alias' in xmldict[param] and \
			(not 'modify' in xmldict[param] or str2bool(xmldict[param]['modify']) == True):
			outstr = " "
			outstr += apDisplay.color(apDisplay.rightPadString(param,maxlen),"green")
			outstr += " :"
			if 'type' in xmldict[param] and xmldict[param]['type'] != None:
				outstr += " ("+apDisplay.rightPadString(xmldict[param]['type']+")",maxlentype+1)
				outstr += " :"
			if 'required' in xmldict[param] and str2bool(xmldict[param]['required']) == True:
				outstr += apDisplay.color(" REQ","red")
			if 'description' in xmldict[param] and xmldict[param]['description'] != None:
				outstr += " "+xmldict[param]['description']
			elif 'name' in xmldict[param] and xmldict[param]['name'] != None:
				outstr += " "+xmldict[param]['name']
			if 'default' in xmldict[param] and xmldict[param]['default'] != None:
				if 'nargs' in xmldict[param] and xmldict[param]['nargs'] is not None and xmldict[param]['nargs'] > 1:
					defstr = " (default: "
					for i in range(len(xmldict[param]['default'])):
						defstr += str(xmldict[param]['default'][i])+","
					defstr = defstr[:-1]+")"
					outstr += apDisplay.color(defstr,"cyan")
				else:
					outstr += apDisplay.color(" (default: "+str(xmldict[param]['default'])+")","cyan")
			if 'example' in xmldict[param] and xmldict[param]['example'] != None:
				outstr += " (example: "+str(xmldict[param]['example'])+")"
			print outstr
	if exit is True:
		sys.exit(1)
def printCtfSummary(params, imgtree):
    """
        prints a histogram of the best ctfvalues for the session
        """

    # if there are no images in the imgtree, there was no new processing done, so exit this function early.
    if not imgtree:
        apDisplay.printWarning("There are no new results to summarize.")
        return

    sys.stderr.write("processing CTF histogram...\n")

    ### get best ctf values for each image
    ctfhistconf = []
    ctfhistval = []
    for imgdata in imgtree:
        if params[
                'norejects'] is True and apDatabase.getSiblingImgAssessmentStatus(
                    imgdata) is False:
            continue

        ctfq = appiondata.ApCtfData()
        ctfq['image'] = imgdata
        ctfvalues = ctfq.query()

        ### check if it has values
        if ctfvalues is None:
            continue

        ### find the best values
        bestconf = 0.0
        bestctfvalue = None
        for ctfvalue in ctfvalues:
            conf = calculateConfidenceScore(ctfvalue, False)
            if conf > bestconf:
                bestconf = conf
                bestctfvalue = ctfvalue
        ctfhistconf.append(bestconf)
        ctfhistval.append(bestctfvalue)

    ctfhistconf.sort()
    confhist = {}
    yspan = 20.0
    minconf = ctfhistconf[0]
    maxconf = ctfhistconf[len(ctfhistconf) - 1]
    maxcount = 0
    for conf in ctfhistconf:
        c2 = round(conf * yspan, 0) / float(yspan)
        if c2 in confhist:
            confhist[c2] += 1
            if confhist[c2] > maxcount:
                maxcount = confhist[c2]
        else:
            confhist[c2] = 1
    if maxcount > 70:
        scale = 70.0 / float(maxcount)
        sys.stderr.write(" * = " + str(round(scale, 1)) + " images\n")
    else:
        scale = 1.0

    colorstr = {}
    for i in range(int(yspan + 1)):
        j = float(i) / yspan
        if j < 0.5:
            colorstr[j] = "red"
        elif j < 0.8:
            colorstr[j] = "yellow"
        else:
            colorstr[j] = "green"

    sys.stderr.write("Confidence histogram:\n")
    for i in range(int(yspan + 1)):
        j = float(i) / yspan
        if j < minconf - 1.0 / yspan:
            continue
        jstr = "%1.2f" % j
        jstr = apDisplay.rightPadString(jstr, 5)
        sys.stderr.write(jstr + "> ")
        if j in confhist:
            for k in range(int(confhist[j] * scale)):
                sys.stderr.write(apDisplay.color("*", colorstr[j]))
        sys.stderr.write("\n")
def printCtfSummary(params, imgtree):
        """
        prints a histogram of the best ctfvalues for the session
        """
        
        # if there are no images in the imgtree, there was no new processing done, so exit this function early.
        if not imgtree:
                apDisplay.printWarning("There are no new results to summarize.")
                return
        
        sys.stderr.write("processing CTF histogram...\n")

        ### get best ctf values for each image
        ctfhistconf = []
        ctfhistval = []
        for imgdata in imgtree:
                if params['norejects'] is True and apDatabase.getSiblingImgAssessmentStatus(imgdata) is False:
                        continue

                ctfq = appiondata.ApCtfData()
                ctfq['image'] = imgdata
                ctfvalues = ctfq.query()

                ### check if it has values
                if ctfvalues is None:
                        continue

                ### find the best values
                bestconf = 0.0
                bestctfvalue = None
                for ctfvalue in ctfvalues:
                        conf = calculateConfidenceScore(ctfvalue,False)
                        if conf > bestconf:
                                bestconf = conf
                                bestctfvalue = ctfvalue
                ctfhistconf.append(bestconf)
                ctfhistval.append(bestctfvalue)

        ctfhistconf.sort()
        confhist = {}
        yspan = 20.0
        minconf = ctfhistconf[0]
        maxconf = ctfhistconf[len(ctfhistconf)-1]
        maxcount = 0
        for conf in ctfhistconf:
                c2 = round(conf*yspan,0)/float(yspan)
                if c2 in confhist:
                        confhist[c2] += 1
                        if confhist[c2] > maxcount:
                                maxcount = confhist[c2]
                else:
                        confhist[c2] = 1
        if maxcount > 70:
                scale = 70.0/float(maxcount)
                sys.stderr.write(" * = "+str(round(scale,1))+" images\n")
        else:
                scale = 1.0

        colorstr = {}
        for i in range(int(yspan+1)):
                j = float(i)/yspan
                if j < 0.5:
                        colorstr[j] = "red"
                elif j < 0.8:
                        colorstr[j] = "yellow"
                else:
                        colorstr[j] = "green"

        sys.stderr.write("Confidence histogram:\n")
        for i in range(int(yspan+1)):
                j = float(i)/yspan
                if j < minconf-1.0/yspan:
                        continue
                jstr = "%1.2f" % j
                jstr = apDisplay.rightPadString(jstr,5)
                sys.stderr.write(jstr+"> ")
                if j in confhist:
                        for k in range(int(confhist[j]*scale)):
                                sys.stderr.write(apDisplay.color("*",colorstr[j]))
                sys.stderr.write("\n")