Exemplo n.º 1
0
 def merge(self, other):
     min_mz = min(self[0].start, other[0].start)
     max_mz = max(self[0].end, other[0].end)
     min_rt = min(self[1].start, other[1].start)
     max_rt = max(self[1].end, other[1].end)
     return self.__class__(Interval(min_mz, max_mz),
                           Interval(min_rt, max_rt))
Exemplo n.º 2
0
 def load_contained(interval_list):
     out = []
     for item in interval_list:
         inner = [Interval(**i) for i in item['members']]
         out.append(
             Interval(start=item['start'],
                      end=item['end'],
                      members=inner))
     return out
def extract_intervals(scan_iterator, time_radius=5., mz_lower=2., mz_higher=3.):
    intervals = []
    for scan, products in scan_iterator:
        for product in products:
            intervals.append(BoundingBox(
                Interval(max(0, product.precursor_information.mz - mz_lower),
                         product.precursor_information.mz + mz_higher),
                Interval(max(0, product.scan_time - time_radius),
                         product.scan_time + time_radius)))
    return intervals
Exemplo n.º 4
0
    def _locate_pasef_precursor_for(self, scan):
        if scan.is_combined():
            # raise ValueError("Cannot determine precursor for combined spectra yet")
            query_interval = Interval(scan.start_scan, scan.end_scan)
            matches = []
            for precursor in scan.frame.pasef_precursors:
                if query_interval.overlaps(Interval(precursor.start_scan, precursor.end_scan)):
                    matches.append(precursor)
            n_matches = len(matches)
            if n_matches == 0:
                return None
            elif n_matches > 1:
                raise ValueError("Multiple precursors found for scan interval!")
            else:
                return matches[0]

        else:
            scan_number = scan.start_scan
            for precursor in scan.frame.pasef_precursors:
                if precursor.start_scan <= scan_number < precursor.end_scan:
                    return precursor
            return None
Exemplo n.º 5
0
 def to_deconvoluted_peak_set(self, time_bound=None):
     if self.deconvoluted_features is None:
         raise ValueError(
             "Must first deconvolute IMS features before converting to a time-binned peak set!"
         )
     if time_bound is not None:
         cft = IntervalTreeNode.build([
             Interval(f.start_time, f.end_time, [f])
             for f in self.deconvoluted_features
         ])
         features = chain.from_iterable(cft.overlaps(*time_bound))
     else:
         features = self.deconvoluted_features
     return features_to_peak_set(features)
Exemplo n.º 6
0
def combine_intervals(a, b):
    min_mz = min(a[0].start, b[0].start)
    max_mz = max(a[0].end, b[0].end)
    min_rt = min(a[1].start, b[1].start)
    max_rt = max(a[1].end, b[1].end)
    return (Interval(min_mz, max_mz), Interval(min_rt, max_rt))