Return an analysis list without duplicated or nested analyses
4412
function _generateUniqueAnalysisList (analysisList) {
  var analysisIds = {};
  return _.reduce(analysisList, function (list, analysis) {
    if (!analysisIds[analysis.get('id')] && !_isAnalysisPartOfOtherAnalyses(analysis, analysisList)) {
      analysisIds[analysis.get('id')] = true; // keep a set of already added analysis.
      list.push(analysis.toJSON());
    }
    return list;
  }, []);
}
337407
def duplicate(self):
        """"""
        return AnalysisPeriod(self.st_month, self.st_day, self.st_hour,
                              self.end_month, self.end_day, self.end_hour,
                              self.timestep, self.is_leap_year)
325953
def addAnalyses(self, analyses):
        
        actions_pool = ActionHandlerPool.get_instance()
        actions_pool.queue_pool()
        for analysis in analyses:
            self.addAnalysis(api.get_object(analysis))
        actions_pool.resume()
487896
def nonmatches(self):
        ''''''
        # For every result, keep a dictionary of mismatches, insertions, and
        # deletions
        report = []
        for result in self.aligned_results:
            report.append(self._analyze_single(self.aligned_reference, result))

        return report
1154838
def list_(runas=None):
    '''
    
    '''
    rubies = []
    output = _rvm(['list'], runas=runas)
    if output:
        regex = re.compile(r'^[= ]([*> ]) ([^- ]+)-([^ ]+) \[ (.*) \]')
        for line in output.splitlines():
            match = regex.match(line)
            if match:
                rubies.append([
                    match.group(2), match.group(3), match.group(1) == '*'
                ])
    return rubies
386250
def get_analysis_type(self, instance):
        
        if IDuplicateAnalysis.providedBy(instance):
            return 'd'
        elif IReferenceAnalysis.providedBy(instance):
            return instance.getReferenceType()
        elif IRoutineAnalysis.providedBy(instance):
            return 'a'
        return None
145930
def get_analyses_at(self, slot):
        

        # ensure we have an integer
        slot = to_int(slot)

        if slot < 1:
            return list()

        analyses = list()
        layout = self.getLayout()

        for pos in layout:
            layout_slot = to_int(pos['position'])
            uid = pos['analysis_uid']
            if layout_slot != slot or not uid:
                continue
            analyses.append(api.get_object_by_uid(uid))

        return analyses
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
752867
def analysis(self):
        
        if self._analysis is not None:
            return self._analysis

        if self.cache_dir is not None:
            path = os.path.join(self.cache_dir, self.checksum)
            try:
                if self.refresh_cache: raise IOError
                with open(path + '.pickle', 'rb') as pickle_file:
                    self._analysis = pickle.load(pickle_file)
            except IOError:
                self._analysis = librosa_analysis.analyze_frames(self.all_as_mono(), self.samplerate)
                with open(path + '.pickle', 'wb') as pickle_file:
                    pickle.dump(self._analysis, pickle_file, pickle.HIGHEST_PROTOCOL)
        else:
            self._analysis = librosa_analysis.analyze_frames(self.all_as_mono(), self.samplerate)
        return self._analysis
1291239
def get_lst(source, extract=None, transform=None):
  """"""
  if extract is None:
    raw_list = source
  else:
    raw_list = extract(source)

  if transform is None:
    return raw_list
  else:
    tlist = []
    for idx, item in enumerate(raw_list):
      try:
        tlist.append(transform(item))
      except Exception as ex:
        raise Exception("An error occurred with item #{0}".format(idx)) from ex
    return tlist
88333
def remove_duplicates(self, ws):
        
        for analysis in ws.objectValues():
            if IDuplicateAnalysis.providedBy(analysis) \
                    and analysis.getAnalysis().UID() == self.UID():
                ws.removeAnalysis(analysis)
670366
def getAnalysis(self):
        
        analysis = None
        ans = self.getLinkedAnalyses()

        if len(ans) > 1:
            # Attachment is assigned to more than one Analysis. This might
            # happen when the AR was invalidated
            an_ids = ", ".join(map(api.get_id, ans))
            logger.info("Attachment assigned to more than one Analysis: [{}]. "
                        "The first Analysis will be returned".format(an_ids))

        if len(ans) >= 1:
            analysis = ans[0]

        return analysis
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
356722
def update_json_analysis(analysis, j):
    
    def _analyze_list(l, parent=""):
        for v in l:
            if isinstance(v, (dict, CaseInsensitiveDict)):
                _analyze_json(v, parent=parent)
            elif isinstance(v, list):
                _analyze_list(v, parent=parent+"[]")
            else:
                analysis[parent].add(v)


    def _analyze_json(d, parent=""):
        for k, v in d.iteritems():
            if parent:
                path = ".".join([parent, k])
            else:
                path = k
            if isinstance(v, (dict, CaseInsensitiveDict)):
                _analyze_json(v, parent=path)
            elif isinstance(v, list):
                _analyze_list(v, parent=path+"[]")
            else:
                analysis[path].add(v)

    if isinstance(j, list):
        _analyze_list(j)
    if isinstance(j, (dict, CaseInsensitiveDict)):
        _analyze_json(j)
746862
def _analyses_data(self, ws):
        
        ans = ws.getAnalyses()
        layout = ws.getLayout()
        pos_count = 0
        prev_pos = 0
        ars = {}

        # mapping of analysis UID -> position in layout
        uid_to_pos_mapping = dict(
            map(lambda row: (row["analysis_uid"], row["position"]), layout))

        for an in ans:
            # Build the analysis-specific dict
            if an.portal_type == "DuplicateAnalysis":
                andict = self._analysis_data(an.getAnalysis())
                andict['id'] = an.getReferenceAnalysesGroupID()
                andict['obj'] = an
                andict['type'] = "DuplicateAnalysis"
                andict['reftype'] = 'd'
            else:
                andict = self._analysis_data(an)

            # Analysis position
            pos = uid_to_pos_mapping.get(an.UID(), 0)

            # compensate for possible bad data (dbw#104)
            if isinstance(pos, (list, tuple)) and pos[0] == 'new':
                pos = prev_pos

            pos = int(pos)
            prev_pos = pos

            # This will allow to sort automatically all the analyses,
            # also if they have the same initial position.
            andict['tmp_position'] = (pos * 100) + pos_count
            andict['position'] = pos
            pos_count += 1

            # Look for the analysis request, client and sample info and
            # group the analyses per Analysis Request
            reqid = andict['request_id']
            if an.portal_type in ("ReferenceAnalysis", "DuplicateAnalysis"):
                reqid = an.getReferenceAnalysesGroupID()

            if reqid not in ars:
                arobj = an.aq_parent
                if an.portal_type == "DuplicateAnalysis":
                    arobj = an.getAnalysis().aq_parent

                ar = self._ar_data(arobj)
                ar['client'] = self._client_data(arobj.aq_parent)
                ar["sample"] = dict()
                if IReferenceSample.providedBy(an):
                    ar['sample'] = self._sample_data(an.getSample())
                else:
                    ar['sample'] = self._sample_data(an.getRequest())
                ar['analyses'] = []
                ar['tmp_position'] = andict['tmp_position']
                ar['position'] = andict['position']
                if an.portal_type in ("ReferenceAnalysis", "DuplicateAnalysis"):
                    ar['id'] = an.getReferenceAnalysesGroupID()
                    ar['url'] = an.absolute_url()
            else:
                ar = ars[reqid]
                if (andict['tmp_position'] < ar['tmp_position']):
                    ar['tmp_position'] = andict['tmp_position']
                    ar['position'] = andict['position']

            # Sort analyses by position
            ans = ar['analyses']
            ans.append(andict)
            ans.sort(lambda x, y: cmp(x.get('tmp_position'), y.get('tmp_position')))
            ar['analyses'] = ans
            ars[reqid] = ar

        ars = [a for a in ars.itervalues()]

        # Sort analysis requests by position
        ars.sort(lambda x, y: cmp(x.get('tmp_position'), y.get('tmp_position')))
        return ars
749053
def analyses():
    """"""
    per_page = int(request.args.get('per_page', 50))
    page = int(request.args.get('page', 1))
    query = store.analyses(status=request.args.get('status'),
                           query=request.args.get('query'),
                           is_visible=request.args.get('is_visible') == 'true' or None)

    query_page = query.paginate(page, per_page=per_page)
    data = []
    for analysis_obj in query_page.items:
        analysis_data = analysis_obj.to_dict()
        analysis_data['user'] = analysis_obj.user.to_dict() if analysis_obj.user else None
        analysis_data['failed_jobs'] = [job_obj.to_dict() for job_obj in analysis_obj.failed_jobs]
        data.append(analysis_data)

    return jsonify(analyses=data)
1144440
def getQCAnalyses(self):
        
        qc_types = ['ReferenceAnalysis', 'DuplicateAnalysis']
        analyses = self.getAnalyses()
        return [a for a in analyses if a.portal_type in qc_types]