Example #1
0
 def _collect(self):
     match_type_getter = attrgetter('match_type')
     groups = collectiontools.groupby(self.spectrum_matches,
                                      match_type_getter)
     by_scan_groups = {}
     for group, members in groups.items():
         acc = []
         for by_scan in collectiontools.groupby(
                 members, lambda x: x.scan.id).values():
             scan = by_scan[0].scan
             self.spectrum_ids.add(scan.scan_id)
             ss = MultiScoreSpectrumSolutionSet(scan, by_scan)
             ss.sort()
             acc.append(ss)
         acc.sort(key=lambda x: x.scan.id)
         by_scan_groups[group] = acc
     return by_scan_groups
Example #2
0
 def load(cls, fh, session=None, hypothesis_id=1, fuzzy=True):
     site_models = GlycosylationSiteModel.load(fh)
     if session is not None:
         return cls.bind_to_hypothesis(session, site_models, hypothesis_id,
                                       fuzzy)
     by_protein_name = groupby(site_models, lambda x: x.protein_name)
     result = []
     for name, models in by_protein_name.items():
         result.append(cls(ProteinStub(name), models))
     return result
Example #3
0
def sort_peak_match_pairs(pairs):
    series = groupby(pairs, key_fn=lambda x: x.fragment.series)
    segments = []
    for key in sorted(series, key=lambda x: x.int_code):
        segment = series[key]
        if hasattr(segment[0].fragment, "position"):
            segment.sort(key=lambda x: x.fragment.position)
        else:
            segment.sort(key=lambda x: x.fragment.mass)
        segments.extend(segment)
    return segments
Example #4
0
 def _by_scan_id(self):
     acc = []
     for by_scan in collectiontools.groupby(self.spectrum_matches,
                                            lambda x: x.scan.id).values():
         scan = by_scan[0].scan
         self.spectrum_ids.add(scan.scan_id)
         ss = MultiScoreSpectrumSolutionSet(scan, by_scan)
         ss.sort()
         acc.append(ss)
     acc.sort(key=lambda x: x.scan.id)
     return acc
Example #5
0
 def _exclusive(self, score_getter=None, min_value=0):
     if score_getter is None:
         score_getter = attrgetter('score')
     groups = collectiontools.groupby(self.spectrum_matches,
                                      lambda x: x.scan.id)
     by_match_type = defaultdict(list)
     for _scan_id, members in groups.items():
         top_match = max(members, key=score_getter)
         top_score = score_getter(top_match)
         seen = set()
         for match in members:
             if isclose(top_score, score_getter(match)) and score_getter(
                     match) > 0 and match.match_type not in seen:
                 seen.add(match.match_type)
                 by_match_type[match.match_type].append(match)
     for _group_label, matches in by_match_type.items():
         matches.sort(key=lambda x: (x.scan.id, score_getter(x)))
     return by_match_type