def match_decon2ls_isos(spectrum_db, hypothesis, adducts=None, ms1_match_tolerance=1e-5, output_path=None):
    if adducts is None:
        adducts = [NoShift]

    results = RecordDatabase(output_path, record_type=hypothesis.record_type)
    results.apply_schema()

    for composition in hypothesis:
        matches = []
        scans_searched = set()
        charge_states = set()
        for adduct in adducts:
            for spectrum in spectrum_db.ppm_match_tolerance_search(
                    composition.intact_mass + adduct.mass, ms1_match_tolerance):
                match_ppm = ppm_error(composition.intact_mass + adduct.mass, spectrum.neutral_mass)
                match = PrecursorMatch(
                    str(composition.id) + ":" + adduct.name, spectrum.neutral_mass, match_ppm,
                    spectrum.get("abundance"), spectrum.charge, spectrum.other_data,
                    spectrum.scan_ids[0])
                matches.append(match)
                scans_searched.update(spectrum.scan_ids)
                charge_states.add(spectrum.charge)

        groups = groupby(matches, match_key_getter)

        composition.precursor_matches = {key: combine_results(group) for key, group in groups.items()}
        composition.precursor_scans_searched = scans_searched
        composition.precursor_scan_density = density(scans_searched)
        composition.precursor_charge_states = charge_states
        results.load_data([composition], set_id=False, cast=True, commit=False)
    results.commit()
    results.apply_indices()
    return results
示例#2
0
def distinct_fragments(self, other, fragmentation_parameters=None):
    """Compute the set of distinct masses observed between two structures

    Parameters
    ----------
    self: Glycan or list
    other : Glycan or list
        Glycan objects whose fragments will be compared or lists of Fragment
        to compare.
    fragmentation_parameters : dict, optional
        If `self` and `other` are |Glycan| objects, these parameters will be used
        to call :meth:`Glycan.fragments`.

    Returns
    -------
    set: The distinct fragment masses of `self`
    set: The distinct fragment masses of `other`
    """
    self_fragments = []
    other_fragments = []
    if isinstance(self, (tuple, list)):
        self_fragments = self
        other_fragments = other
    else:
        if fragmentation_parameters is None:
            fragmentation_parameters = dict(kind="BY", max_cleavages=1, average=False, charge=0)
        self_fragments = list(self.fragments(**fragmentation_parameters))
        other_fragments = list(other.fragments(**fragmentation_parameters))

    def grouper(fragment):
        return round(fragment.mass, 4)

    self_masses = set(groupby(self_fragments, grouper))
    other_masses = set(groupby(other_fragments, grouper))
    self_unique = self_masses - other_masses
    other_unique = other_masses - self_masses
    return self_unique, other_unique