Ejemplo n.º 1
0
def set_matching_peaks(library_spectrum, query_spectrum):
    peak_matches = spectrum_match.get_best_match(query_spectrum,
                                                 [library_spectrum],
                                                 config.fragment_mz_tolerance,
                                                 config.allow_peak_shifts)[2]
    query_spectrum.annotation = np.full_like(query_spectrum.mz, None, object)
    for peak_match in peak_matches:
        library_annotation = library_spectrum.annotation[peak_match[1]]
        if library_annotation is not None and library_annotation.ion_type in 'by':
            query_spectrum.annotation[peak_match[0]] = library_annotation
Ejemplo n.º 2
0
def get_matching_peaks(library_spectrum, query_spectrum):
    _, score, peak_matches = spectrum_match.get_best_match(
        query_spectrum, [library_spectrum],
        allow_shift=config.allow_peak_shifts)
    library_matches, query_matches = {}, {}
    for peak_match in peak_matches:
        query_matches[peak_match[0]] = library_matches[peak_match[1]] = (
            'unknown' if library_spectrum.annotations[peak_match[1]] is None
            else library_spectrum.annotations[peak_match[1]][0][0])

    return library_matches, query_matches, score
Ejemplo n.º 3
0
def set_matching_peaks(library_spectrum, query_spectrum):
    peak_matches = spectrum_match.get_best_match(
        query_spectrum, [library_spectrum],
        config.fragment_mz_tolerance, config.allow_peak_shifts)[2]
    query_spectrum.annotation = np.full_like(query_spectrum.mz, None, object)
    for peak_match in peak_matches:
        library_annotation = library_spectrum.annotation[peak_match[1]]
        if library_annotation is not None:
            query_spectrum.annotation[peak_match[0]] = library_annotation
        else:
            fragment_annotation = PeptideFragmentAnnotation(1, 1, 'z', 0)
            fragment_annotation.ion_type = 'unknown'
            query_spectrum.annotation[peak_match[0]] =\
                library_spectrum.annotation[peak_match[1]] =\
                fragment_annotation
Ejemplo n.º 4
0
    def _find_match(self, query, tol_mass, tol_mode):
        """
        Identifies the given query Spectrum.

        Args:
            query: The query Spectrum to be identified.

        Returns:
            A SpectrumMatch identification. If the query couldn't be
            identified SpectrumMatch.sequence will be None.
        """
        # discard low-quality spectra
        if not query.is_valid():
            return spectrum.SpectrumMatch(query)

        start_total = start_candidates = time.time()

        # find all candidate library spectra
        # for which a match has to be computed
        candidates = self._filter_library_candidates(query, tol_mass, tol_mode)

        stop_candidates = start_match = time.time()

        if len(candidates) > 0:
            # find the best matching candidate spectrum
            match_candidate, match_score, _ = spectrum_match.get_best_match(
                query, candidates)
            identification = spectrum.SpectrumMatch(query, match_candidate,
                                                    match_score)
        else:
            identification = spectrum.SpectrumMatch(query)

        stop_match = stop_total = time.time()

        # store performance data
        identification.num_candidates = len(candidates)
        identification.time_candidates = stop_candidates - start_candidates
        identification.time_match = stop_match - start_match
        identification.time_total = stop_total - start_total

        return identification
Ejemplo n.º 5
0
    def _search_batch(self, query_spectra: List[MsmsSpectrum],
                      charge: int, mode: str)\
            -> Iterator[SpectrumSpectrumMatch]:
        """
        Generate spectrum-spectrum matches for a batch of query spectra with
        the same precursor charge.

        Parameters
        ----------
        query_spectra : List[Spectrum]
            The query spectra for which spectrum-spectrum matches are
            generated.
        charge : int
            The precursor charge of the query spectra.
        mode : {'std', 'open'}
            The search mode. Either 'std' for a standard search with a small
            precursor mass window, or 'open' for an open search with a wide
            precursor mass window.

        Returns
        -------
        Iterator[SpectrumSpectrumMatch]
            An iterator of spectrum-spectrum matches for every query spectrum
            that could be successfully matched to its most similar library
            spectrum.
        """
        # Find all library candidates for each query spectrum.
        for query_spectrum, library_candidates in zip(
                query_spectra,
                self._get_library_candidates(query_spectra, charge, mode)):
            # Find the best match candidate.
            if library_candidates:
                library_match, score, _ = spectrum_match.get_best_match(
                    query_spectrum, library_candidates,
                    config.fragment_mz_tolerance, config.allow_peak_shifts)
                yield SpectrumSpectrumMatch(
                    query_spectrum,
                    library_match,
                    score,
                    num_candidates=len(library_candidates))