def median_bounds(im, peak, shared=True): """ @Summary: Calculates the median of the left and right bounds found for each apexing peak mass @param im: The originating IntensityMatrix object @type im: pyms.GCMS.Class.IntensityMatrix @param peak: The Peak object @type peak: pyms.Peak.Class.Peak @param shared: Include shared ions shared with neighbouring peak @type shared: BooleanType @return: median left and right boundary offset in points @rtype: TupleType @author: Andrew Isaac """ mat = im.get_matrix_list() ms = peak.get_mass_spectrum() rt = peak.get_rt() apex = im.get_index_at_time(rt) # check if RT based index is simmilar to stored index tmp = peak.get_pt_bounds() if is_list(tmp) and apex-1 < tmp[1] and tmp[1] < apex+1: apex = tmp[1] # get peak masses with non-zero intensity mass_ii = [ ii for ii in xrange(len(ms.mass_list)) \ if ms.mass_spec[ii] > 0 ] # get stats on boundaries left_list = [] right_list = [] for ii in mass_ii: # get ion chromatogram as list ia = [ mat[scan][ii] for scan in xrange(len(mat)) ] area, left, right, l_share, r_share = ion_area(ia, apex) if shared or not l_share: left_list.append(left) if shared or not r_share: right_list.append(right) # return medians # NB if shared=True, lists maybe empty l_med = 0 r_med = 0 if len(left_list) > 0: l_med = median(left_list) if len(right_list) > 0: r_med = median(right_list) return l_med, r_med
def median_bounds(im, peak, shared=True): """ @Summary: Calculates the median of the left and right bounds found for each apexing peak mass @param im: The originating IntensityMatrix object @type im: pyms.GCMS.Class.IntensityMatrix @param peak: The Peak object @type peak: pyms.Peak.Class.Peak @param shared: Include shared ions shared with neighbouring peak @type shared: BooleanType @return: median left and right boundary offset in points @rtype: TupleType @author: Andrew Isaac """ mat = im.get_matrix_list() ms = peak.get_mass_spectrum() rt = peak.get_rt() apex = im.get_index_at_time(rt) # check if RT based index is simmilar to stored index tmp = peak.get_pt_bounds() if is_list(tmp) and apex - 1 < tmp[1] and tmp[1] < apex + 1: apex = tmp[1] # get peak masses with non-zero intensity mass_ii = [ ii for ii in xrange(len(ms.mass_list)) \ if ms.mass_spec[ii] > 0 ] # get stats on boundaries left_list = [] right_list = [] for ii in mass_ii: # get ion chromatogram as list ia = [mat[scan][ii] for scan in xrange(len(mat))] area, left, right, l_share, r_share = ion_area(ia, apex) if shared or not l_share: left_list.append(left) if shared or not r_share: right_list.append(right) # return medians # NB if shared=True, lists maybe empty l_med = 0 r_med = 0 if len(left_list) > 0: l_med = median(left_list) if len(right_list) > 0: r_med = median(right_list) return l_med, r_med
def info(self, print_scan_n=False): """ @summary: Prints some information about the data @param print_scan_n: If set to True will print the number of m/z values in each scan @type print_scan_n: BooleanType @author: Vladimir Likic """ # print the summary of simply attributes print " Data retention time range: %.3f min -- %.3f min" % \ (self.__min_rt/60.0, self.__max_rt/60) print " Time step: %.3f s (std=%.3f s)" % ( self.__time_step, \ self.__time_step_std ) print " Number of scans: %d" % ( len(self.__scan_list) ) print " Minimum m/z measured: %.3f" % ( self.__min_mass ) print " Maximum m/z measured: %.3f" % ( self.__max_mass ) # calculate median number of m/z values measured per scan n_list = [] for ii in range(len(self.__scan_list)): scan = self.__scan_list[ii] n = len(scan) n_list.append(n) if print_scan_n: print n mz_mean = mean(n_list) mz_median = median(n_list) print " Mean number of m/z values per scan: %d" % ( mz_mean ) print " Median number of m/z values per scan: %d" % ( mz_median )
def __median_window(ia, wing_length): """ @summary: Applies median-window averaging on the array of intensities. @param ia: Intensity array @type ia: nympy.core.ndarray @param wing_length: An integer value representing the number of points on either side of a point in the ion chromatogram @type wing_length: IntType @return: Smoothed intensity array @rtype: nympy.core.ndarray @author: Vladimir Likic """ #print " -> Window smoothing (median): the wing is %d point(s)" % (wing_length) ia_denoise = numpy.repeat([0], ia.size) index = 0 end = ia.size - 1 while index <= end: left = index - wing_length right = index + wing_length + 1 if left < 0: left = 0 slice = ia[left:right] ia_denoise[index] = median(slice) index = index + 1 return ia_denoise