def _merge(spectra, mz_tolerance=1.3e-3, only_common_peaks=False, verbose=True): """merges a list of spectra to one spetrum. *mz_tolerance* : binning size for grouping peaks. *only_common_peaks*: if this value is true the resulting spectrum only consists of dominant peaks which are present in every input spectrum *verbose*: print diagnosis messages if this value is True """ if not spectra: return None if len(spectra) == 1: return spectra[0] alignments = Spectrum.compute_alignments(spectra, mz_tolerance) common = _botton_up_common(alignments) mz_vecs = [s.peaks[:, 0] for s in spectra] intensity_vecs = [s.peaks[:, 1] for s in spectra] if only_common_peaks: mz_last = mz_vecs[-1] ii_last = intensity_vecs[-1] peaks = [(mz_last[i], ii_last[i]) for i in common] return _final_spectrum(peaks, spectra) scalings = _determine_scaling_factors(mz_vecs, intensity_vecs, alignments, common) if scalings is not None: peaks = _overlay(mz_vecs, intensity_vecs, scalings, mz_tolerance, verbose, len(common)) else: peaks = [np.empty((0, 2))] return _final_spectrum(peaks, spectra)