def ilookup(self, m, tolerance=None): """ Note: all lookups in this module relies on this method, this is the only method where methods from the ``lipyd.lookup`` module called. Parameters ---------- m : float Exact mass to lookup. tolerance : int,float Tolerance in ppm or in Daltons if attribute ``_daltons_tolerance`` is True. Returns ------- Array of database array indices. """ if tolerance and self._daltons_tolerance: tolerance = _lookup.absolute_tolerance(tolerance, m) return _lookup.findall( self.masses, m, t=tolerance or self.tolerance, )
def lookup(self, mz, nl=False, tolerance=None): """Searches for fragments in the database matching the `mz` within the actual range of tolerance. To change the tolerance set the `tolerance` attribute to the desired ppm value. Args ---- Parameters ---------- bool : nl: The m/z is a neutral loss. mz : nl : (Default value = False) tolerance : (Default value = None) Returns ------- """ idx = lookup_.findall(self.fragments[:, 0], mz, tolerance or self.tolerance) # filtering for NL or not NL idx = [ i for i in idx if (nl and self.fragments[i, 6] == 0) or ( not nl and self.fragments[i, 6] != 0) ] return self.fragments[idx, :]
def align(*arrays, tolerance=5): narrays = len(arrays) array = np.concatenate(arrays) # indices within arrays idx = np.concatenate(tuple(np.arange(len(a)) for a in arrays)) # which array the value belongs to iarray = np.concatenate( tuple(np.full(a.shape, i) for i, a in enumerate(arrays))) # keep track if elements have been used already used = np.full(iarray.shape, False) # sort all arrays by values isort = array.argsort() array = array[isort] idx = idx[isort] iarray = iarray[isort] # here we collect the lines of the result array result = [] # these are the array memberships for i, val in enumerate(array): partners = lookup.findall(array, val) result.append((i, partners)) return array, result
intensity = v else: continue # RT in seconds convert into minutes: feature_list.append( (float(MZ), float(RT)/60., float(intensity)) ) feature_list.sort() intersection_dic = {} for e in feature_list: #closest_index = lookup.find( result_list = lookup.findall( samples.mzs_by_sample[ :,samples.attrs.sample_id_to_index[('A', 10)] ], # all masses in the sample e[0], # mass to search for t = 10 # tolerance in ppm ) if len( result_list ): for closest_index in result_list: intersection_dic[(e[0], e[1], e[2])] = \ ((mzs[closest_index], rts[closest_index], intens[closest_index], (e[0]/mzs[closest_index]-1)*1e6 ) ) else: intersection_dic[(e[0], e[1], e[2])] = (result_list, None)
def lookup(self, mz, rt=None, tolerance=None): """ Looks up an MS1 m/z and returns the indices of MS2 scans in the MGF file. Returns 2 numpy arrays of the same length: first one with the indices, second one with the RT differences. Parameters ---------- mz : rt : (Default value = None) tolerance : (Default value = None) Returns ------- """ if self._log_verbosity > 4: self._log.msg('Recalibrated m/z: %.08f; drift = %.08f; ' 'measured m/z: %.08f' % (mz, self.drift, mz / self.drift)) rt = rt or np.nan mz_uncorr = mz / self.drift idx = np.array( lookup.findall(self.mgfindex[:, 0], mz_uncorr, tolerance or self.tolerance)) rtdiff = np.array([self.mgfindex[i, 2] - rt for i in idx]) if self._log_verbosity > 4: self._log('Looking up MS1 m/z %.08f. ' 'MS2 scans with matching precursor mass: %u' % ( mz_uncorr, len(idx), )) if self.ms2_rt_within_range: if np.isnan(rt): self._log('No MS1 RT provided, could not check RT ' 'difference of MS2 scans.') idx = idx[np.logical_or(np.isnan(rtdiff), np.abs(rtdiff) < self.rt_tolerance)] if self._log_verbosity > 4: self._log('RT range: %.03f--%.03f; ' 'Matching MS2 scans within this range: %u' % ( rtlower, rtupper, len(idx), )) elif self._log_verbosity > 4: self._log('Not checking RT.') return idx, rtdiff