Fills the analysis' uncertainty to the item passed in.

        :param analysis_brain: Brain that represents an analysis
        :param item: analysis' dictionary counterpart that represents a row
2034
def _folder_item_uncertainty(self, analysis_brain, item):
        

        item["Uncertainty"] = ""

        if not self.has_permission(ViewResults, analysis_brain):
            return

        result = analysis_brain.getResult

        obj = self.get_object(analysis_brain)
        formatted = format_uncertainty(obj, result, decimalmark=self.dmk,
                                       sciformat=int(self.scinot))
        if formatted:
            item["Uncertainty"] = formatted
        else:
            item["Uncertainty"] = obj.getUncertainty(result)

        if self.is_uncertainty_edition_allowed(analysis_brain):
            item["allow_edit"].append("Uncertainty")
863218
def get_object(brain_or_object):
    
    if not is_object(brain_or_object):
        fail("{} is not supported.".format(repr(brain_or_object)))
    if is_brain(brain_or_object):
        return brain_or_object.getObject()
    return brain_or_object
9580
def append(self, item):
        
        if not self.items:        # was list empty ?
            self.items = item     # then this is the new head
        item.insert(self.items)
1057723
def is_result_edition_allowed(self, analysis_brain):
        

        # Always check general edition first
        if not self.is_analysis_edition_allowed(analysis_brain):
            return False

        # Get the ananylsis object
        obj = api.get_object(analysis_brain)

        if not obj.getDetectionLimitOperand():
            # This is a regular result (not a detection limit)
            return True

        # Detection limit selector is enabled in the Analysis Service
        if obj.getDetectionLimitSelector():
            # Manual detection limit entry is *not* allowed
            if not obj.getAllowManualDetectionLimit():
                return False

        return True
982729
def sorted_analyses(self, analyses):
        
        analyses = sorted(analyses, key=lambda an: an.getRequestID())

        def sorted_by_sortkey(objs):
            return sorted(objs, key=lambda an: an.getPrioritySortkey())

        # Now, we need the analyses within a request ID to be sorted by
        # sortkey (sortable_title index), so it will appear in the same
        # order as they appear in Analyses list from AR view
        current_sample_id = None
        current_analyses = []
        sorted_analyses = []
        for analysis in analyses:
            sample_id = analysis.getRequestID()
            if sample_id and current_sample_id != sample_id:
                # Sort the brains we've collected until now, that
                # belong to the same Analysis Request
                current_analyses = sorted_by_sortkey(current_analyses)
                sorted_analyses.extend(current_analyses)
                current_sample_id = sample_id
                current_analyses = []

            # Now we are inside the same AR
            current_analyses.append(analysis)
            continue

        # Sort the last set of brains we've collected
        current_analyses = sorted_by_sortkey(current_analyses)
        sorted_analyses.extend(current_analyses)
        return sorted_analyses
246857
def check_paired_problems(items):
    
    # ensure we're in a paired batch
    if not get_paired(items):
        return
    num_tumor = len([x for x in items if dd.get_phenotype(x).lower() == "tumor"])
    if num_tumor > 1:
        raise ValueError("Unsupported configuration: found multiple tumor samples in batch %s: %s" %
                         (tz.get_in(["metadata", "batch"], items[0]),
                          [dd.get_sample_name(data) for data in items]))
    elif num_tumor == 0 and any(dd.get_phenotype(data).lower() == "normal" for data in items):
        raise ValueError("Found normal sample without tumor in batch %s: %s" %
                         (tz.get_in(["metadata", "batch"], items[0]),
                          [dd.get_sample_name(data) for data in items]))
    else:
        vcs = get_somatic_variantcallers(items)
        if "mutect" in vcs or "mutect2" in vcs or "strelka2" in vcs:
            paired = get_paired(items)
            if not (paired.normal_data or paired.normal_panel):
                raise ValueError("MuTect, MuTect2 and Strelka2 somatic calling requires normal sample or panel: %s" %
                                 [dd.get_sample_name(data) for data in items])
642330
def copy_analysis_dict( analysis ):
    '''  '''
    assert isinstance(analysis, dict), "(!) Input 'analysis' should be a dict!"
    new_dict = { POSTAG: analysis[POSTAG],\
                 ROOT: analysis[ROOT],\
                 FORM: analysis[FORM],\
                 CLITIC: analysis[CLITIC],\
                 ENDING: analysis[ENDING] }
    if LEMMA in analysis:
       new_dict[LEMMA] = analysis[LEMMA]
    if ROOT_TOKENS in analysis:
       new_dict[ROOT_TOKENS] = analysis[ROOT_TOKENS]
    return new_dict
1140956
def _folder_item_specifications(self, analysis_brain, item):
        """"""
        # Everyone can see valid-ranges
        item['Specification'] = ''
        results_range = analysis_brain.getResultsRange
        if not results_range:
            return

        # Display the specification interval
        item["Specification"] = get_formatted_interval(results_range, "")

        # Show an icon if out of range
        out_range, out_shoulders = is_out_of_range(analysis_brain)
        if not out_range:
            return
        # At least is out of range
        img = get_image("exclamation.png", title=_("Result out of range"))
        if not out_shoulders:
            img = get_image("warning.png", title=_("Result in shoulder range"))
        self._append_html_element(item, "Result", img)
1217147
def gather(self, analysis, node):
        "'"
        assert issubclass(analysis, Analysis)
        a = analysis()
        a.attach(self)
        return a.run(node)
1327802
def compute(self, data, fill_value=None, **kwargs):
        """"""
        del kwargs

        if fill_value is None:
            fill_value = data.attrs.get('_FillValue')
        target_shape = self.target_geo_def.shape

        res = self.resampler.get_sample_from_bil_info(data,
                                                      fill_value=fill_value,
                                                      output_shape=target_shape)

        return res
812239
def set_item(self, index, new_item):
        
        row = index.row() if hasattr(index, "row") else index
        self.collection[row] = new_item
        self.dataChanged.emit(self.index(
            row, 0), self.index(row, self.rowCount() - 1))
759064
def combined_analysis(using):
    
    python_analysis = collect_analysis(using)
    es_analysis = existing_analysis(using)
    if es_analysis == DOES_NOT_EXIST:
        return python_analysis

    # we want to ensure everything defined in Python land is added, or
    # overrides the things defined in ES
    for section in python_analysis:
        if section not in es_analysis:
            es_analysis[section] = python_analysis[section]

        subdict_python = python_analysis[section]
        subdict_es = es_analysis[section]
        for name in subdict_python:
            subdict_es[name] = subdict_python[name]

    return es_analysis
1275533
def reinforce(self, **kwargs):
        
        results = reinforce_grid(
            self, max_while_iterations=kwargs.get(
                'max_while_iterations', 10),
            copy_graph=kwargs.get('copy_graph', False),
            timesteps_pfa=kwargs.get('timesteps_pfa', None),
            combined_analysis=kwargs.get('combined_analysis', False))

        # add measure to Results object
        if not kwargs.get('copy_graph', False):
            self.network.results.measures = 'grid_expansion'

        return results
1168936
def _folder_item_detection_limits(self, analysis_brain, item):
        
        item["DetectionLimitOperand"] = ""

        if not self.is_analysis_edition_allowed(analysis_brain):
            # Return immediately if the we are not in edit mode
            return

        # TODO: Performance, we wake-up the full object here
        obj = self.get_object(analysis_brain)

        # No Detection Limit Selection
        if not obj.getDetectionLimitSelector():
            return None

        # Show Detection Limit Operand Selector
        item["DetectionLimitOperand"] = obj.getDetectionLimitOperand()
        item["allow_edit"].append("DetectionLimitOperand")
        self.columns["DetectionLimitOperand"]["toggle"] = True

        # Prepare selection list for LDL/UDL
        choices = [
            {"ResultValue": "", "ResultText": ""},
            {"ResultValue": LDL, "ResultText": LDL},
            {"ResultValue": UDL, "ResultText": UDL}
        ]
        # Set the choices to the item
        item["choices"]["DetectionLimitOperand"] = choices
1331925
def _pick_lead_item(items):
    
    paired = vcfutils.get_paired(items)
    if paired:
        return paired.tumor_data
    else:
        return list(items)[0]
49650
def _write_items(self, row_lookup, col_lookup, item):
        
        self.qc.write_items(row_lookup, col_lookup, item)
740604
def brain(
    draw=True, show=True, fiducial=True, flat=True, inflated=True, subject='S1', interval=1000, uv=True, color=None
):
    
    import ipyvolume as ipv

    try:
        import cortex
    except:
        warnings.warn("it seems pycortex is not installed, which is needed for this example")
        raise
    xlist, ylist, zlist = [], [], []
    polys_list = []

    def add(pts, polys):
        xlist.append(pts[:, 0])
        ylist.append(pts[:, 1])
        zlist.append(pts[:, 2])
        polys_list.append(polys)

    def n(x):
        return (x - x.min()) / x.ptp()

    if fiducial or color is True:
        pts, polys = cortex.db.get_surf('S1', 'fiducial', merge=True)
        x, y, z = pts.T
        r = n(x)
        g = n(y)
        b = n(z)
        if color is True:
            color = np.array([r, g, b]).T.copy()
        else:
            color = None
        if fiducial:
            add(pts, polys)
    else:
        if color is False:
            color = None
    if inflated:
        add(*cortex.db.get_surf('S1', 'inflated', merge=True, nudge=True))
    u = v = None
    if flat or uv:
        pts, polys = cortex.db.get_surf('S1', 'flat', merge=True, nudge=True)
        x, y, z = pts.T
        u = n(x)
        v = n(y)
        if flat:
            add(pts, polys)

    polys_list.sort(key=lambda x: len(x))
    polys = polys_list[0]
    if draw:
        if color is None:
            mesh = ipv.plot_trisurf(xlist, ylist, zlist, polys, u=u, v=v)
        else:
            mesh = ipv.plot_trisurf(xlist, ylist, zlist, polys, color=color, u=u, v=v)
        if show:
            if len(x) > 1:
                ipv.animation_control(mesh, interval=interval)
            ipv.squarelim()
            ipv.show()
        return mesh
    else:
        return xlist, ylist, zlist, polys