Пример #1
0
    def _init_iter(self):
        if self.first_run_slice_bb is None:
            raise StopIteration
        self.curr_scan_slices = bb_to_scan_slices(
            bytes(self.first_run_slice_bb.data), self.first_run_slice_bb.run_slice_id, self.reader.struct_by_scan_id)

        while 1:
            row = self.cursor.fetchone()
            if row is None:
                self.first_run_slice_bb = None
                break
            bb = BoundingBox._make(row)
            if bb.run_slice_id == self.first_run_slice_bb.run_slice_id:
                self.curr_scan_slices += bb_to_scan_slices(
                    bytes(bb.data), bb.run_slice_id, self.reader.struct_by_scan_id)
            else:
                self.first_run_slice_bb = bb
                break
Пример #2
0
    def get_xic(self, min_mz, max_mz, min_rt=0.0, max_rt=0.0, ms_level=1):
        """
        eXtracted Ion Chromatogram

        :param min_mz:
        :param max_mz:
        :param min_rt:
        :param max_rt:
        :param ms_level:
        :return:
        """
        min_mz_rs = self.run_slices_begin_mz[bisect_left(self.run_slices_begin_mz, min_mz) - 1]
        max_mz_rs = self.run_slices_begin_mz[bisect_left(self.run_slices_begin_mz, max_mz) - 1]

        # print "min max rs", min_mz_rs, max_mz_rs

        if min_mz_rs == max_mz_rs:
            sql_query = """SELECT bounding_box.id, data, run_slice_id, first_spectrum_id
                             FROM bounding_box, run_slice WHERE run_slice.ms_level = ?
                             AND bounding_box.run_slice_id = run_slice.id
                             AND run_slice.begin_mz = ?;"""

            self.cursor.execute(sql_query, (ms_level, min_mz_rs))
        else:
            sql_query = """SELECT bounding_box.id, data, run_slice_id, first_spectrum_id
                             FROM bounding_box, run_slice WHERE run_slice.ms_level = ?
                             AND bounding_box.run_slice_id = run_slice.id
                             AND (run_slice.begin_mz = ? OR run_slice.begin_mz = ?);"""
            self.cursor.execute(sql_query, (ms_level, min_mz_rs, max_mz_rs))

        intensities_by_scan_time = ddict(int)

        for row in self.cursor:
            scan_slices = bb_to_scan_slices(row[1][:], row[2], self.struct_by_scan_id)
            for ss in scan_slices:
                time = self.rt_by_scan_id_by_ms_level[ms_level][ss.scan_id]
                mzs = ss.mzs
                min_idx = bisect_left(mzs, min_mz)
                max_idx = bisect_left(mzs, max_mz)

                ints = ss.ints[min_idx: max_idx]

                if not ints:
                    continue

                m = max(ints)

                # if m > intensities_by_scan_time[time]:
                intensities_by_scan_time[time] = m

        times = sorted(intensities_by_scan_time.viewkeys())
        intensities = [intensities_by_scan_time[t] for t in times]
        return times, intensities
Пример #3
0
    def get_scan(self, scan_id):
        first_scan_id = self._get_bb_first_scan_id(scan_id)
        print first_scan_id
        sql_query = "SELECT id, data, run_slice_id FROM bounding_box WHERE bounding_box.first_spectrum_id = ?"
        self.cursor.execute(sql_query, (first_scan_id,))

        mzs, ints = [], []
        for row in self.cursor:
            scan_slices = bb_to_scan_slices(row[1][:], row[2], self.struct_by_scan_id)
            for s in scan_slices:
                if s.scan_id == scan_id:
                    mzs += s.mzs
                    ints += s.ints
                    break
        return scan_id, mzs, ints