public static bool DissociationTypeContainETD(DissociationType dissociationType) { if (dissociationType == DissociationType.ETD || dissociationType == DissociationType.EThcD) { return(true); } return(false); }
public ModernSearchEngine(PeptideSpectralMatch[] globalPsms, Ms2ScanWithSpecificMass[] listOfSortedms2Scans, List <PeptideWithSetModifications> peptideIndex, List <int>[] fragmentIndex, int currentPartition, CommonParameters commonParameters, MassDiffAcceptor massDiffAcceptor, double maximumMassThatFragmentIonScoreIsDoubled, List <string> nestedIds) : base(commonParameters, nestedIds) { PeptideSpectralMatches = globalPsms; ListOfSortedMs2Scans = listOfSortedms2Scans; PeptideIndex = peptideIndex; FragmentIndex = fragmentIndex; CurrentPartition = currentPartition + 1; MassDiffAcceptor = massDiffAcceptor; DissociationType = commonParameters.DissociationType; MaxMassThatFragmentIonScoreIsDoubled = maximumMassThatFragmentIonScoreIsDoubled; }
/// <summary> /// Generates theoretical fragments for given dissociation type for this peptide /// </summary> public IEnumerable <Product> Fragment(DissociationType dissociationType, FragmentationTerminus fragmentationTerminus) { // molecular ion //yield return new Product(ProductType.M, new NeutralTerminusFragment(FragmentationTerminus.None, this.MonoisotopicMass, Length, Length), 0); var productCollection = TerminusSpecificProductTypes.ProductIonTypesFromSpecifiedTerminus[fragmentationTerminus].Intersect(DissociationTypeCollection.ProductsFromDissociationType[dissociationType]); List <(ProductType, int)> skippers = new List <(ProductType, int)>(); foreach (var product in productCollection.Where(f => f != ProductType.zPlusOne)) { skippers.Add((product, BaseSequence.Length)); } switch (dissociationType) { case DissociationType.CID: skippers.Add((ProductType.b, 1)); break; case DissociationType.ETD: case DissociationType.ECD: case DissociationType.EThcD: skippers.AddRange(GetProlineZIonIndicies()); break; } foreach (var productType in productCollection) { // we're separating the N and C terminal masses and computing a separate compact peptide for each one // this speeds calculations up without producing unnecessary terminus fragment info FragmentationTerminus temporaryFragmentationTerminus = TerminusSpecificProductTypes.ProductTypeToFragmentationTerminus[productType]; NeutralTerminusFragment[] terminalMasses = CompactPeptide(temporaryFragmentationTerminus).TerminalMasses; for (int f = 0; f < terminalMasses.Length; f++) { // fragments with neutral loss if (AllModsOneIsNterminus.TryGetValue(terminalMasses[f].AminoAcidPosition + 1, out Modification mod) && mod.NeutralLosses != null && mod.NeutralLosses.TryGetValue(dissociationType, out List <double> neutralLosses)) { foreach (double neutralLoss in neutralLosses) { if (neutralLoss == 0) { continue; } for (int n = f; n < terminalMasses.Length; n++) { if (!skippers.Contains((productType, terminalMasses[n].FragmentNumber)))
public DissociationType GetDissociationType() { if (_dissociationType == DissociationType.UnKnown) { if (ParentFile.IsOpen) { _dissociationType = ParentFile.GetDissociationType(SpectrumNumber); } else { throw new ArgumentException("The parent data file is closed"); } } return(_dissociationType); }
//TO THINK: filter reasonable fragments here. The final solution is to change mzLib.Proteomics.PeptideWithSetModifications.Fragment public static List <Product> OGlyGetTheoreticalFragments(DissociationType dissociationType, PeptideWithSetModifications peptide, PeptideWithSetModifications modPeptide) { List <Product> theoreticalProducts = new List <Product>(); HashSet <double> masses = new HashSet <double>(); List <Product> products = new List <Product>(); if (dissociationType == DissociationType.HCD || dissociationType == DissociationType.CID) { List <Product> diag = new List <Product>(); modPeptide.Fragment(dissociationType, FragmentationTerminus.Both, diag); peptide.Fragment(dissociationType, FragmentationTerminus.Both, products); products = products.Concat(diag.Where(p => p.ProductType != ProductType.b && p.ProductType != ProductType.y)).ToList(); } else if (dissociationType == DissociationType.ETD) { modPeptide.Fragment(dissociationType, FragmentationTerminus.Both, products); } else if (dissociationType == DissociationType.EThcD) { List <Product> diag = new List <Product>(); modPeptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, diag); peptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, products); products = products.Concat(diag.Where(p => p.ProductType != ProductType.b && p.ProductType != ProductType.y)).ToList(); List <Product> etdProducts = new List <Product>(); modPeptide.Fragment(DissociationType.ETD, FragmentationTerminus.Both, etdProducts); products = products.Concat(etdProducts.Where(p => p.ProductType != ProductType.y)).ToList(); } foreach (var fragment in products) { if (!masses.Contains(fragment.NeutralMass)) { masses.Add(fragment.NeutralMass); theoreticalProducts.Add(fragment); } } return(theoreticalProducts); }
//TO DO: A better method can be implemented in mzLib. public static bool DissociationTypeGenerateSameTypeOfIons(DissociationType d, DissociationType childD) { if (d == childD) { return(true); } if (d == DissociationType.CID && childD == DissociationType.HCD) { return(true); } if (d == DissociationType.HCD && childD == DissociationType.CID) { return(true); } if (d == DissociationType.ETD && childD == DissociationType.ECD) { return(true); } if (d == DissociationType.ECD && childD == DissociationType.ETD) { return(true); } return(false); }
private void SaveButton_Click(object sender, RoutedEventArgs e) { string fieldNotUsed = "1"; if (!GlobalGuiSettings.CheckTaskSettingsValidity(PrecursorMassToleranceTextBox.Text, ProductMassToleranceTextBox.Text, MissedCleavagesTextBox.Text, MaxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, MaxThreadsTextBox.Text, MinScoreAllowed.Text, fieldNotUsed, fieldNotUsed, DeconvolutionMaxAssumedChargeStateTextBox.Text, NumberOfPeaksToKeepPerWindowTextBox.Text, MinimumAllowedIntensityRatioToBasePeakTexBox.Text, null, null, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed)) { return; } Protease protease = (Protease)ProteaseComboBox.SelectedItem; int maxMissedCleavages = string.IsNullOrEmpty(MissedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(MissedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int minPeptideLength = int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxPeptideLength = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int minVariantDepth = int.Parse(MinVariantDepthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxHeterozygousVariants = int.Parse(MaxHeterozygousVariantsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxModificationIsoforms = int.Parse(MaxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture); int maxModsPerPeptide = int.Parse(MaxModsPerPeptideTextBox.Text, CultureInfo.InvariantCulture); InitiatorMethionineBehavior initiatorMethionineBehavior = (InitiatorMethionineBehavior)InitiatorMethionineBehaviorComboBox.SelectedIndex; DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()]; CustomFragmentationWindow.Close(); Tolerance productMassTolerance; if (ProductMassToleranceComboBox.SelectedIndex == 0) { productMassTolerance = new AbsoluteTolerance(double.Parse(ProductMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { productMassTolerance = new PpmTolerance(double.Parse(ProductMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } Tolerance precursorMassTolerance; if (PrecursorMassToleranceComboBox.SelectedIndex == 0) { precursorMassTolerance = new AbsoluteTolerance(double.Parse(PrecursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { precursorMassTolerance = new PpmTolerance(double.Parse(PrecursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } List <(string, string)> listOfModsVariable = new List <(string, string)>(); foreach (var heh in variableModTypeForTreeViewObservableCollection) { listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable)) { return; } bool TrimMs1Peaks = TrimMs1.IsChecked.Value; bool TrimMsMsPeaks = TrimMsMs.IsChecked.Value; int?numPeaksToKeep = null; if (!string.IsNullOrWhiteSpace(NumberOfPeaksToKeepPerWindowTextBox.Text)) { if (int.TryParse(NumberOfPeaksToKeepPerWindowTextBox.Text, out int numberOfPeaksToKeeep)) { numPeaksToKeep = numberOfPeaksToKeeep; } else { MessageBox.Show("The value that you entered for number of peaks to keep is not acceptable. Try again."); return; } } double?minimumAllowedIntensityRatioToBasePeak = null; if (!string.IsNullOrWhiteSpace(MinimumAllowedIntensityRatioToBasePeakTexBox.Text)) { if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, out double minimumAllowedIntensityRatio)) { minimumAllowedIntensityRatioToBasePeak = minimumAllowedIntensityRatio; } else { MessageBox.Show("The value that you entered for minimum allowed intensity ratio to keep is not acceptable. Try again."); return; } } List <(string, string)> listOfModsFixed = new List <(string, string)>(); foreach (var heh in fixedModTypeForTreeViewObservableCollection) { listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } bool parseMaxThreadsPerFile = int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) <= Environment.ProcessorCount && int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) > 0; CommonParameters commonParamsToSave = new CommonParameters( useProvidedPrecursorInfo: UseProvidedPrecursor.IsChecked.Value, deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture), doPrecursorDeconvolution: DeconvolutePrecursors.IsChecked.Value, taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "GPTMDTask", maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile, digestionParams: new DigestionParams( protease: protease.Name, maxMissedCleavages: maxMissedCleavages, minPeptideLength: minPeptideLength, maxPeptideLength: maxPeptideLength, maxModificationIsoforms: maxModificationIsoforms, maxModsForPeptides: maxModsPerPeptide, initiatorMethionineBehavior: initiatorMethionineBehavior), dissociationType: dissociationType, scoreCutoff: double.Parse(MinScoreAllowed.Text, CultureInfo.InvariantCulture), precursorMassTolerance: precursorMassTolerance, productMassTolerance: productMassTolerance, trimMs1Peaks: TrimMs1Peaks, trimMsMsPeaks: TrimMsMsPeaks, numberOfPeaksToKeepPerWindow: numPeaksToKeep, minimumAllowedIntensityRatioToBasePeak: minimumAllowedIntensityRatioToBasePeak, listOfModsFixed: listOfModsFixed, listOfModsVariable: listOfModsVariable, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down", addCompIons: AddCompIonCheckBox.IsChecked.Value, minVariantDepth: minVariantDepth, maxHeterozygousVariants: maxHeterozygousVariants); TheTask.GptmdParameters.ListOfModsGptmd = new List <(string, string)>(); foreach (var heh in gptmdModTypeForTreeViewObservableCollection) { TheTask.GptmdParameters.ListOfModsGptmd.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } TheTask.CommonParameters = commonParamsToSave; DialogResult = true; }
/// <summary> /// Generates theoretical fragments for given dissociation type for this peptide. /// The "products" parameter is filled with these fragments. /// </summary> public void Fragment(DissociationType dissociationType, FragmentationTerminus fragmentationTerminus, List <Product> products) { // This code is specifically written to be memory- and CPU -efficient because it is // called millions of times for a typical search (i.e., at least once per peptide). // If you modify this code, BE VERY CAREFUL about allocating new memory, especially // for new collections. This code also deliberately avoids using "yield return", again // for performance reasons. Be sure to benchmark any changes with a parallelized // fragmentation of every peptide in a database (i.e., test for speed decreases and // memory issues). products.Clear(); var massCaps = DissociationTypeCollection.GetNAndCTerminalMassShiftsForDissociationType(dissociationType); double cTermMass = 0; double nTermMass = 0; List <ProductType> nTermProductTypes = DissociationTypeCollection.GetTerminusSpecificProductTypesFromDissociation(dissociationType, FragmentationTerminus.N); List <ProductType> cTermProductTypes = DissociationTypeCollection.GetTerminusSpecificProductTypesFromDissociation(dissociationType, FragmentationTerminus.C); bool calculateNTermFragments = fragmentationTerminus == FragmentationTerminus.N || fragmentationTerminus == FragmentationTerminus.Both; bool calculateCTermFragments = fragmentationTerminus == FragmentationTerminus.C || fragmentationTerminus == FragmentationTerminus.Both; //From http://www.matrixscience.com/help/fragmentation_help.html //Low Energy CID -- In low energy CID(i.e.collision induced dissociation in a triple quadrupole or an ion trap) a peptide carrying a positive charge fragments mainly along its backbone, //generating predominantly b and y ions. In addition, for fragments containing RKNQ, peaks are seen for ions that have lost ammonia (-17 Da) denoted a*, b* and y*. For fragments containing //STED, loss of water(-18 Da) is denoted a°, b° and y°. Satellite ions from side chain cleavage are not observed. bool haveSeenNTermDegreeIon = false; bool haveSeenNTermStarIon = false; bool haveSeenCTermDegreeIon = false; bool haveSeenCTermStarIon = false; // these two collections keep track of the neutral losses observed so far on the n-term or c-term. // they are apparently necessary, but allocating memory for collections in this function results in // inefficient memory usage and thus frequent garbage collection. // TODO: If you can think of a way to remove these collections and still maintain correct // fragmentation, please do so. HashSet <double> nTermNeutralLosses = null; HashSet <double> cTermNeutralLosses = null; // n-terminus mod if (calculateNTermFragments) { if (AllModsOneIsNterminus.TryGetValue(1, out Modification mod)) { nTermMass += mod.MonoisotopicMass.Value; } } // c-terminus mod if (calculateCTermFragments) { if (AllModsOneIsNterminus.TryGetValue(BaseSequence.Length + 2, out Modification mod)) { cTermMass += mod.MonoisotopicMass.Value; } } for (int r = 0; r < BaseSequence.Length - 1; r++) { // n-term fragments if (calculateNTermFragments) { char nTermResidue = BaseSequence[r]; // get n-term residue mass if (Residue.TryGetResidue(nTermResidue, out Residue residue)) { nTermMass += residue.MonoisotopicMass; } else { nTermMass = double.NaN; } // add side-chain mod if (AllModsOneIsNterminus.TryGetValue(r + 2, out Modification mod)) { nTermMass += mod.MonoisotopicMass.Value; } // handle star and degree ions for low-res CID if (dissociationType == DissociationType.LowCID) { if (nTermResidue == 'R' || nTermResidue == 'K' || nTermResidue == 'N' || nTermResidue == 'Q') { haveSeenNTermStarIon = true; } if (nTermResidue == 'S' || nTermResidue == 'T' || nTermResidue == 'E' || nTermResidue == 'D') { haveSeenNTermDegreeIon = true; } } // skip first N-terminal fragment (b1, aDegree1, ...) for CID if (r == 0 && (dissociationType == DissociationType.CID || dissociationType == DissociationType.LowCID)) { goto CTerminusFragments; } // generate products for (int i = 0; i < nTermProductTypes.Count; i++) { if (dissociationType == DissociationType.LowCID) { if (!haveSeenNTermStarIon && (nTermProductTypes[i] == ProductType.aStar || nTermProductTypes[i] == ProductType.bStar)) { continue; } if (!haveSeenNTermDegreeIon && (nTermProductTypes[i] == ProductType.aDegree || nTermProductTypes[i] == ProductType.bDegree)) { continue; } } products.Add(new Product( nTermProductTypes[i], FragmentationTerminus.N, nTermMass + massCaps.Item1[i], r + 1, r + 1, 0)); if (mod != null && mod.NeutralLosses != null && mod.NeutralLosses.TryGetValue(dissociationType, out List <double> neutralLosses)) { foreach (double neutralLoss in neutralLosses.Where(p => p != 0)) { if (nTermNeutralLosses == null) { nTermNeutralLosses = new HashSet <double>(); } nTermNeutralLosses.Add(neutralLoss); } } if (nTermNeutralLosses != null) { foreach (double neutralLoss in nTermNeutralLosses) { products.Add(new Product( nTermProductTypes[i], FragmentationTerminus.N, nTermMass + massCaps.Item1[i] - neutralLoss, r + 1, r + 1, neutralLoss)); } } } } // c-term fragments CTerminusFragments: if (calculateCTermFragments) { char cTermResidue = BaseSequence[BaseSequence.Length - r - 1]; // get c-term residue mass if (Residue.TryGetResidue(cTermResidue, out Residue residue)) { cTermMass += residue.MonoisotopicMass; } else { cTermMass = double.NaN; } // add side-chain mod if (AllModsOneIsNterminus.TryGetValue(BaseSequence.Length - r + 1, out Modification mod)) { cTermMass += mod.MonoisotopicMass.Value; } // handle star and degree ions for low-res CID if (dissociationType == DissociationType.LowCID) { if (cTermResidue == 'R' || cTermResidue == 'K' || cTermResidue == 'N' || cTermResidue == 'Q') { haveSeenCTermStarIon = true; } if (cTermResidue == 'S' || cTermResidue == 'T' || cTermResidue == 'E' || cTermResidue == 'D') { haveSeenCTermDegreeIon = true; } } // generate products for (int i = 0; i < cTermProductTypes.Count; i++) { // skip zDot ions for proline residues for ETD/ECD/EThcD if (cTermResidue == 'P' && (dissociationType == DissociationType.ECD || dissociationType == DissociationType.ETD || dissociationType == DissociationType.EThcD) && cTermProductTypes[i] == ProductType.zDot) { continue; } if (dissociationType == DissociationType.LowCID) { if (!haveSeenCTermStarIon && cTermProductTypes[i] == ProductType.yStar) { continue; } if (!haveSeenCTermDegreeIon && cTermProductTypes[i] == ProductType.yDegree) { continue; } } products.Add(new Product( cTermProductTypes[i], FragmentationTerminus.C, cTermMass + massCaps.Item2[i], r + 1, BaseSequence.Length - r, 0)); if (mod != null && mod.NeutralLosses != null && mod.NeutralLosses.TryGetValue(dissociationType, out List <double> neutralLosses)) { foreach (double neutralLoss in neutralLosses.Where(p => p != 0)) { if (cTermNeutralLosses == null) { cTermNeutralLosses = new HashSet <double>(); } cTermNeutralLosses.Add(neutralLoss); } } if (cTermNeutralLosses != null) { foreach (double neutralLoss in cTermNeutralLosses) { products.Add(new Product( cTermProductTypes[i], FragmentationTerminus.C, cTermMass + massCaps.Item2[i] - neutralLoss, r + 1, BaseSequence.Length - r, neutralLoss)); } } } } } // zDot generates one more ion... if (cTermProductTypes.Contains(ProductType.zDot) && BaseSequence[0] != 'P') { // get c-term residue mass if (Residue.TryGetResidue(BaseSequence[0], out Residue residue)) { cTermMass += residue.MonoisotopicMass; } else { cTermMass = double.NaN; } // add side-chain mod if (AllModsOneIsNterminus.TryGetValue(1, out Modification mod)) { cTermMass += mod.MonoisotopicMass.Value; } // generate zDot product products.Add(new Product( ProductType.zDot, FragmentationTerminus.C, cTermMass + DissociationTypeCollection.GetMassShiftFromProductType(ProductType.zDot), BaseSequence.Length, 1, 0)); if (mod != null && mod.NeutralLosses != null && mod.NeutralLosses.TryGetValue(dissociationType, out List <double> neutralLosses)) { foreach (double neutralLoss in neutralLosses.Where(p => p != 0)) { products.Add(new Product( ProductType.zDot, FragmentationTerminus.C, cTermMass + DissociationTypeCollection.GetMassShiftFromProductType(ProductType.zDot) - neutralLoss, BaseSequence.Length, 1, neutralLoss)); } } } foreach (var mod in AllModsOneIsNterminus.Where(p => p.Value.NeutralLosses != null)) { // molecular ion minus neutral losses if (mod.Value.NeutralLosses.TryGetValue(dissociationType, out List <double> losses)) { foreach (double neutralLoss in losses.Where(p => p != 0)) { if (neutralLoss != 0) { products.Add(new Product(ProductType.M, FragmentationTerminus.Both, MonoisotopicMass - neutralLoss, 0, 0, neutralLoss)); } } } } // generate diagnostic ions // TODO: this code is memory-efficient but sort of CPU inefficient; it can be further optimized. // however, diagnostic ions are fairly rare so it's probably OK for now foreach (double diagnosticIon in AllModsOneIsNterminus.Where(p => p.Value.DiagnosticIons != null && p.Value.DiagnosticIons.ContainsKey(dissociationType)).SelectMany(p => p.Value.DiagnosticIons[dissociationType]).Distinct()) { int diagnosticIonLabel = (int)Math.Round(diagnosticIon.ToMz(1), 0); // the diagnostic ion is assumed to be annotated in the mod info as the *neutral mass* of the diagnostic ion, not the ionized species products.Add(new Product(ProductType.D, FragmentationTerminus.Both, diagnosticIon, diagnosticIonLabel, 0, 0)); } }
private static MsDataScan GetMsDataOneBasedScanFromConnection(Generated.mzMLType _mzMLConnection, int oneBasedIndex, IFilteringParams filterParams) { // Read in the instrument configuration types from connection (in mzml it's at the start) Generated.InstrumentConfigurationType[] configs = new Generated.InstrumentConfigurationType[_mzMLConnection.instrumentConfigurationList.instrumentConfiguration.Length]; for (int i = 0; i < _mzMLConnection.instrumentConfigurationList.instrumentConfiguration.Length; i++) { configs[i] = _mzMLConnection.instrumentConfigurationList.instrumentConfiguration[i]; } var defaultInstrumentConfig = _mzMLConnection.run.defaultInstrumentConfigurationRef; // May be null! var scanSpecificInsturmentConfig = _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].instrumentConfigurationRef; MZAnalyzerType analyzer = default(MZAnalyzerType); // use default if (scanSpecificInsturmentConfig == null || scanSpecificInsturmentConfig == defaultInstrumentConfig) { if (configs[0].componentList == null) { analyzer = default(MZAnalyzerType); } else if (analyzerDictionary.TryGetValue(configs[0].componentList.analyzer[0].cvParam[0].accession, out MZAnalyzerType returnVal)) { analyzer = returnVal; } } // use scan-specific else { for (int i = 0; i < _mzMLConnection.instrumentConfigurationList.instrumentConfiguration.Length; i++) { if (configs[i].id.Equals(scanSpecificInsturmentConfig)) { analyzerDictionary.TryGetValue(configs[i].componentList.analyzer[0].cvParam[0].accession, out MZAnalyzerType returnVal); analyzer = returnVal; } } } string nativeId = _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].id; int? msOrder = null; bool? isCentroid = null; Polarity polarity = Polarity.Unknown; double tic = double.NaN; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].cvParam) { if (cv.accession.Equals(_msnOrderAccession)) { msOrder = int.Parse(cv.value); } if (cv.accession.Equals(_centroidSpectrum)) { isCentroid = true; } if (cv.accession.Equals(_profileSpectrum)) { throw new MzLibException("Reading profile mode mzmls not supported"); } if (cv.accession.Equals(_totalIonCurrent)) { tic = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (polarity.Equals(Polarity.Unknown)) { polarityDictionary.TryGetValue(cv.accession, out polarity); } } if (!msOrder.HasValue || !isCentroid.HasValue) { throw new MzLibException("!msOrder.HasValue || !isCentroid.HasValue"); } double[] masses = new double[0]; double[] intensities = new double[0]; foreach (Generated.BinaryDataArrayType binaryData in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].binaryDataArrayList.binaryDataArray) { bool compressed = false; bool mzArray = false; bool intensityArray = false; bool is32bit = true; foreach (Generated.CVParamType cv in binaryData.cvParam) { compressed |= cv.accession.Equals(_zlibCompression); is32bit &= !cv.accession.Equals(_64bit); is32bit |= cv.accession.Equals(_32bit); mzArray |= cv.accession.Equals(_mzArray); intensityArray |= cv.accession.Equals(_intensityArray); } double[] data = ConvertBase64ToDoubles(binaryData.binary, compressed, is32bit); if (mzArray) { masses = data; } if (intensityArray) { intensities = data; } } double high = double.NaN; double low = double.NaN; var aScanWindowList = _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].scanWindowList; if (aScanWindowList != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].scanWindowList.scanWindow[0].cvParam) { if (cv.accession.Equals(_scanWindowLowerLimit)) { low = double.Parse(cv.value, CultureInfo.InvariantCulture); } else if (cv.accession.Equals(_scanWindowUpperLimit)) { high = double.Parse(cv.value, CultureInfo.InvariantCulture); } } } if (filterParams != null && intensities.Length > 0 && ((filterParams.ApplyTrimmingToMs1 && msOrder.Value == 1) || (filterParams.ApplyTrimmingToMsMs && msOrder.Value > 1))) { WindowModeHelper(ref intensities, ref masses, filterParams, low, high); } Array.Sort(masses, intensities); var mzmlMzSpectrum = new MzSpectrum(masses, intensities, false); double rtInMinutes = double.NaN; string scanFilter = null; double?injectionTime = null; int oneBasedScanNumber = oneBasedIndex; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].cvParam != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].cvParam) { if (cv.accession.Equals(_retentionTime)) { rtInMinutes = double.Parse(cv.value, CultureInfo.InvariantCulture); if (cv.unitName == "second") { rtInMinutes /= 60; } } if (cv.accession.Equals(_filterString)) { scanFilter = cv.value; } if (cv.accession.Equals(_ionInjectionTime)) { injectionTime = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_oneBasedScanNumber)) //get the real one based spectrum number (if available), the other assumes they are in order. This is present in .mgf->.mzml conversions from MSConvert { oneBasedScanNumber = int.Parse(cv.value); } } } if (msOrder.Value == 1) { return(new MsDataScan( mzmlMzSpectrum, oneBasedScanNumber, msOrder.Value, isCentroid.Value, polarity, rtInMinutes, new MzRange(low, high), scanFilter, analyzer, tic, injectionTime, null, nativeId)); } double selectedIonMz = double.NaN; int? selectedIonCharge = null; double?selectedIonIntensity = null; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].selectedIonList.selectedIon[0].cvParam) { if (cv.accession.Equals(_selectedIonMz)) { selectedIonMz = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_precursorCharge)) { selectedIonCharge = int.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_peakIntensity)) { selectedIonIntensity = double.Parse(cv.value, CultureInfo.InvariantCulture); } } double?isolationMz = null; double lowIsolation = double.NaN; double highIsolation = double.NaN; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].isolationWindow != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].isolationWindow.cvParam) { if (cv.accession.Equals(_isolationWindowTargetMZ)) { isolationMz = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_isolationWindowLowerOffset)) { lowIsolation = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_isolationWindowUpperOffset)) { highIsolation = double.Parse(cv.value, CultureInfo.InvariantCulture); } } } DissociationType dissociationType = DissociationType.Unknown; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].activation.cvParam != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].activation.cvParam) { dissociationDictionary.TryGetValue(cv.accession, out dissociationType); } } double?monoisotopicMz = null; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].userParam != null) { foreach (var userParam in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].userParam) { if (userParam.name.EndsWith("Monoisotopic M/Z:")) { monoisotopicMz = double.Parse(userParam.value, CultureInfo.InvariantCulture); } } } int?precursorScanNumber; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].spectrumRef == null) { precursorScanNumber = null; } else { precursorScanNumber = GetOneBasedPrecursorScanNumber(_mzMLConnection, oneBasedIndex); } return(new MsDataScan( mzmlMzSpectrum, oneBasedIndex, msOrder.Value, isCentroid.Value, polarity, rtInMinutes, new MzRange(low, high), scanFilter, analyzer, tic, injectionTime, null, nativeId, selectedIonMz, selectedIonCharge, selectedIonIntensity, isolationMz, lowIsolation + highIsolation, dissociationType, precursorScanNumber, monoisotopicMz )); }
public static List <ProductType> GetTerminusSpecificProductTypesFromDissociation(DissociationType dissociationType, FragmentationTerminus fragmentationTerminus) { if (!TerminusSpecificProductTypesFromDissociation.TryGetValue((dissociationType, fragmentationTerminus), out List <ProductType> productTypes)) { lock (TerminusSpecificProductTypesFromDissociation) { var productCollection = TerminusSpecificProductTypes.ProductIonTypesFromSpecifiedTerminus[fragmentationTerminus] .Intersect(DissociationTypeCollection.ProductsFromDissociationType[dissociationType]); if (!TerminusSpecificProductTypesFromDissociation.TryGetValue((dissociationType, fragmentationTerminus), out productTypes)) { productTypes = productCollection.ToList(); TerminusSpecificProductTypesFromDissociation.Add((dissociationType, fragmentationTerminus), productTypes); } } } return(productTypes); }
public static double[] ScanOxoniumIonFilter(Ms2ScanWithSpecificMass theScan, MassDiffAcceptor massDiffAcceptor, DissociationType dissociationType) { double[] oxoniumIonsintensities = new double[Glycan.AllOxoniumIons.Length]; if (dissociationType != DissociationType.HCD && dissociationType != DissociationType.CID && dissociationType != DissociationType.EThcD) { return(oxoniumIonsintensities); } for (int i = 0; i < Glycan.AllOxoniumIons.Length; i++) { var oxoMass = ((double)Glycan.AllOxoniumIons[i] / 1E5).ToMass(1); var envelope = theScan.GetClosestExperimentalIsotopicEnvelope(oxoMass); if (massDiffAcceptor.Accepts(envelope.MonoisotopicMass, oxoMass) >= 0) { oxoniumIonsintensities[i] = envelope.TotalIntensity; } } return(oxoniumIonsintensities); }
protected void IndexedScoring(List <int> binsToSearch, byte[] scoringTable, byte byteScoreCutoff, List <int> idsOfPeptidesPossiblyObserved, double scanPrecursorMass, double lowestMassPeptideToLookFor, double highestMassPeptideToLookFor, List <PeptideWithSetModifications> peptideIndex, MassDiffAcceptor massDiffAcceptor, double maxMassThatFragmentIonScoreIsDoubled, DissociationType dissociationType) { // get all theoretical fragments this experimental fragment could be for (int i = 0; i < binsToSearch.Count; i++) { List <int> peptideIdsInThisBin = FragmentIndex[binsToSearch[i]]; //get index for minimum monoisotopic allowed int lowestPeptideMassIndex = Double.IsInfinity(lowestMassPeptideToLookFor) ? 0 : BinarySearchBinForPrecursorIndex(peptideIdsInThisBin, lowestMassPeptideToLookFor, peptideIndex); // get index for highest mass allowed int highestPeptideMassIndex = peptideIdsInThisBin.Count - 1; if (!Double.IsInfinity(highestMassPeptideToLookFor)) { highestPeptideMassIndex = BinarySearchBinForPrecursorIndex(peptideIdsInThisBin, highestMassPeptideToLookFor, peptideIndex); for (int j = highestPeptideMassIndex; j < peptideIdsInThisBin.Count; j++) { int nextId = peptideIdsInThisBin[j]; var nextPep = peptideIndex[nextId]; if (nextPep.MonoisotopicMass < highestMassPeptideToLookFor) { highestPeptideMassIndex = j; } else { break; } } } if (dissociationType == DissociationType.LowCID) { // add intensity for each peptide candidate in the scoring table up to the maximum allowed precursor mass for (int j = lowestPeptideMassIndex; j <= highestPeptideMassIndex; j++) { int id = peptideIdsInThisBin[j]; // add possible search results to the hashset of id's (only once) if (scoringTable[id] == 0 && massDiffAcceptor.Accepts(scanPrecursorMass, peptideIndex[id].MonoisotopicMass) >= 0) { idsOfPeptidesPossiblyObserved.Add(id); } // mark the peptide as potentially observed so it doesn't get added more than once scoringTable[id] = 1; } } else { // add +1 score for each peptide candidate in the scoring table up to the maximum allowed precursor mass for (int j = lowestPeptideMassIndex; j <= highestPeptideMassIndex; j++) { int id = peptideIdsInThisBin[j]; scoringTable[id]++; // add possible search results to the hashset of id's if (scoringTable[id] == byteScoreCutoff && massDiffAcceptor.Accepts(scanPrecursorMass, peptideIndex[id].MonoisotopicMass) >= 0) { idsOfPeptidesPossiblyObserved.Add(id); } } } } }
public CommonParameters(string taskDescriptor = null, DissociationType dissociationType = DissociationType.HCD, DissociationType childScanDissociationType = DissociationType.Unknown, bool doPrecursorDeconvolution = true, bool useProvidedPrecursorInfo = true, double deconvolutionIntensityRatio = 3, int deconvolutionMaxAssumedChargeState = 12, bool reportAllAmbiguity = true, bool addCompIons = false, int totalPartitions = 1, double scoreCutoff = 5, int topNpeaks = 200, double minRatio = 0.01, bool trimMs1Peaks = false, bool trimMsMsPeaks = true, bool useDeltaScore = false, bool calculateEValue = false, Tolerance productMassTolerance = null, Tolerance precursorMassTolerance = null, Tolerance deconvolutionMassTolerance = null, int maxThreadsToUsePerFile = -1, DigestionParams digestionParams = null, IEnumerable <(string, string)> listOfModsVariable = null, IEnumerable <(string, string)> listOfModsFixed = null, double qValueOutputFilter = 1.0,
private void SaveButton_Click(object sender, RoutedEventArgs e) { string fieldNotUsed = "1"; if (!GlobalGuiSettings.CheckTaskSettingsValidity(XLPrecusorMsTlTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text, maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed, TopNPeaksTextBox.Text, MinRatioTextBox.Text, null, null, numberOfDatabaseSearchesTextBox.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed)) { return; } DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()]; DissociationType childDissociationType = DissociationType.Unknown; if (ChildScanDissociationTypeComboBox.SelectedItem != null) { childDissociationType = GlobalVariables.AllSupportedDissociationTypes[ChildScanDissociationTypeComboBox.SelectedItem.ToString()]; } CustomFragmentationWindow.Close(); //TheTask.XlSearchParameters.SearchGlyco = RbSearchGlyco.IsChecked.Value; //TheTask.XlSearchParameters.SearchGlycoWithBgYgIndex = CkbSearchGlycoWithBgYgIndex.IsChecked.Value; TheTask.XlSearchParameters.RestrictToTopNHits = ckbXLTopNum.IsChecked.Value; TheTask.XlSearchParameters.CrosslinkSearchTopNum = int.Parse(txtXLTopNum.Text, CultureInfo.InvariantCulture); TheTask.XlSearchParameters.CrosslinkAtCleavageSite = ckbCrosslinkAtCleavageSite.IsChecked.Value; TheTask.XlSearchParameters.Crosslinker = (Crosslinker)cbCrosslinkers.SelectedItem; TheTask.XlSearchParameters.XlQuench_H2O = ckbQuenchH2O.IsChecked.Value; TheTask.XlSearchParameters.XlQuench_NH2 = ckbQuenchNH2.IsChecked.Value; TheTask.XlSearchParameters.XlQuench_Tris = ckbQuenchTris.IsChecked.Value; TheTask.XlSearchParameters.DecoyType = checkBoxDecoy.IsChecked.Value ? DecoyType.Reverse : DecoyType.None; Protease protease = (Protease)proteaseComboBox.SelectedItem; int MaxMissedCleavages = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MinPeptideLength = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MaxPeptideLength = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MaxModificationIsoforms = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture)); InitiatorMethionineBehavior InitiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex); DigestionParams digestionParamsToSave = new DigestionParams( protease: protease.Name, maxMissedCleavages: MaxMissedCleavages, minPeptideLength: MinPeptideLength, maxPeptideLength: MaxPeptideLength, maxModificationIsoforms: MaxModificationIsoforms, initiatorMethionineBehavior: InitiatorMethionineBehavior); Tolerance ProductMassTolerance; if (productMassToleranceComboBox.SelectedIndex == 0) { ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } Tolerance PrecursorMassTolerance; if (cbbXLprecusorMsTl.SelectedIndex == 0) { PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(XLPrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture)); } else { PrecursorMassTolerance = new PpmTolerance(double.Parse(XLPrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture)); } TheTask.XlSearchParameters.WriteOutputForPercolator = ckbPercolator.IsChecked.Value; TheTask.XlSearchParameters.WritePepXml = ckbPepXML.IsChecked.Value; var listOfModsVariable = new List <(string, string)>(); foreach (var heh in VariableModTypeForTreeViewObservableCollection) { listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } var listOfModsFixed = new List <(string, string)>(); foreach (var heh in FixedModTypeForTreeViewObservableCollection) { listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } CommonParameters commonParamsToSave = new CommonParameters( precursorMassTolerance: PrecursorMassTolerance, taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "XLSearchTask", productMassTolerance: ProductMassTolerance, doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value, useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value, digestionParams: digestionParamsToSave, trimMs1Peaks: trimMs1.IsChecked.Value, trimMsMsPeaks: trimMsMs.IsChecked.Value, numberOfPeaksToKeepPerWindow: int.Parse(TopNPeaksTextBox.Text), minimumAllowedIntensityRatioToBasePeak: double.Parse(MinRatioTextBox.Text, CultureInfo.InvariantCulture), dissociationType: dissociationType, childScanDissociationType: childDissociationType, scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture), totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture), listOfModsVariable: listOfModsVariable, listOfModsFixed: listOfModsFixed, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down"); TheTask.CommonParameters = commonParamsToSave; DialogResult = true; }
public static MsDataScan GetOneBasedScan(IRawDataPlus rawFile, IFilteringParams filteringParams, int scanNumber) { var filter = rawFile.GetFilterForScanNumber(scanNumber); string scanFilterString = filter.ToString(); int msOrder = (int)filter.MSOrder; if (msOrder < 1 || msOrder > 10) { throw new MzLibException("Unknown MS Order (" + msOrder + ") for scan number " + scanNumber); } string nativeId = "controllerType=0 controllerNumber=1 scan=" + scanNumber; MzSpectrum spectrum = GetSpectrum(rawFile, filteringParams, scanNumber, scanFilterString, msOrder); var scanStats = rawFile.GetScanStatsForScanNumber(scanNumber); double scanRangeHigh = scanStats.HighMass; double scanRangeLow = scanStats.LowMass; MzRange scanWindowRange = new MzRange(scanRangeLow, scanRangeHigh); double? ionInjectionTime = null; double? precursorSelectedMonoisotopicIonMz = null; int? selectedIonChargeState = null; double? ms2IsolationWidth = null; int? precursorScanNumber = null; double? isolationMz = null; string HcdEnergy = null; ActivationType activationType = ActivationType.Any; // thermo enum DissociationType dissociationType = DissociationType.Unknown; // mzLib enum var trailer = rawFile.GetTrailerExtraInformation(scanNumber); string[] labels = trailer.Labels; string[] values = trailer.Values; for (int i = 0; i < trailer.Labels.Length; i++) { if (labels[i].StartsWith("Ion Injection Time (ms)", StringComparison.Ordinal)) { ionInjectionTime = double.Parse(values[i], CultureInfo.InvariantCulture) == 0 ? (double?)null : double.Parse(values[i], CultureInfo.InvariantCulture); } if (msOrder < 2) { continue; } if (labels[i].StartsWith("MS" + msOrder + " Isolation Width", StringComparison.Ordinal)) { ms2IsolationWidth = double.Parse(values[i], CultureInfo.InvariantCulture) == 0 ? (double?)null : double.Parse(values[i], CultureInfo.InvariantCulture); } if (labels[i].StartsWith("Monoisotopic M/Z", StringComparison.Ordinal)) { precursorSelectedMonoisotopicIonMz = double.Parse(values[i], CultureInfo.InvariantCulture) == 0 ? (double?)null : double.Parse(values[i], CultureInfo.InvariantCulture); } if (labels[i].StartsWith("Charge State", StringComparison.Ordinal)) { selectedIonChargeState = int.Parse(values[i], CultureInfo.InvariantCulture) == 0 ? (int?)null : int.Parse(values[i], CultureInfo.InvariantCulture); } if (labels[i].StartsWith("Master Scan Number", StringComparison.Ordinal) || labels[i].StartsWith("Master Index", StringComparison.Ordinal)) { precursorScanNumber = int.Parse(values[i], CultureInfo.InvariantCulture) <= 1 ? (int?)null : int.Parse(values[i], CultureInfo.InvariantCulture); } if (labels[i].StartsWith("HCD Energy:", StringComparison.Ordinal)) { HcdEnergy = values[i]; } } if (msOrder > 1) { var scanEvent = rawFile.GetScanEventForScanNumber(scanNumber); var reaction = scanEvent.GetReaction(0); isolationMz = reaction.PrecursorMass; activationType = reaction.ActivationType; dissociationType = GetDissociationType(activationType); // thermo does not have an enum value for ETHcD, so this needs to be detected from the scan filter if (scanFilterString.Contains("@etd", StringComparison.OrdinalIgnoreCase) && scanFilterString.Contains("@hcd", StringComparison.OrdinalIgnoreCase)) { dissociationType = DissociationType.EThcD; } if (ms2IsolationWidth == null) { ms2IsolationWidth = reaction.IsolationWidth; } if (precursorScanNumber == null) { // we weren't able to get the precursor scan number, so we'll have to guess; // loop back to find precursor scan // (assumed to be the first scan before this scan with an MS order of this scan's MS order - 1) // e.g., if this is an MS2 scan, find the first MS1 scan before this and assume that's the precursor scan for (int i = scanNumber; i >= 1; i--) { var possiblePrecursorScanFilter = rawFile.GetFilterForScanNumber(i); int order = (int)possiblePrecursorScanFilter.MSOrder; if (order == msOrder - 1) { precursorScanNumber = i; break; } } if (precursorScanNumber == null) { throw new MzLibException("Could not get precursor for scan #" + scanNumber); } } } // at this point, we have the m/z value of the species that got fragmented, from the scan header // this section of the code finds that peak in the spectrum (it's actual intensity and centroided m/z values) // the intention is to remove any rounding issues caused by what is in the scan header and what is observable in the spectrum double?selectedIonIntensity = null; if (isolationMz.HasValue) { if (spectrum.Size != 0) { int closest = spectrum.GetClosestPeakIndex(isolationMz.Value); double mz = spectrum.XArray[closest]; double intensity = spectrum.YArray[closest]; if (Math.Abs(mz - isolationMz.Value) < 0.1) { selectedIonIntensity = intensity; isolationMz = mz; } } } return(new MsDataScan( massSpectrum: spectrum, oneBasedScanNumber: scanNumber, msnOrder: msOrder, isCentroid: true, polarity: GetPolarity(filter.Polarity), retentionTime: rawFile.RetentionTimeFromScanNumber(scanNumber), scanWindowRange: scanWindowRange, scanFilter: scanFilterString, mzAnalyzer: GetMassAnalyzerType(filter.MassAnalyzer), totalIonCurrent: spectrum.SumOfAllY, injectionTime: ionInjectionTime, noiseData: null, //TODO: implement reading noise data. it's unused right now, so it's just left as null nativeId: nativeId, selectedIonMz: isolationMz, selectedIonChargeStateGuess: selectedIonChargeState, selectedIonIntensity: selectedIonIntensity, isolationMZ: isolationMz, isolationWidth: ms2IsolationWidth, dissociationType: dissociationType, oneBasedPrecursorScanNumber: precursorScanNumber, selectedIonMonoisotopicGuessMz: precursorSelectedMonoisotopicIonMz, hcdEnergy: HcdEnergy)); }
public static IEnumerable <Tuple <int, List <Product> > > XlGetTheoreticalFragments(DissociationType dissociationType, Crosslinker crosslinker, List <int> possibleCrosslinkerPositions, double otherPeptideMass, PeptideWithSetModifications peptide) { List <double> massesToLocalize = new List <double>(); if (crosslinker.Cleavable && crosslinker.CleaveDissociationTypes.Contains(dissociationType)) { massesToLocalize.Add(crosslinker.CleaveMassShort); massesToLocalize.Add(crosslinker.CleaveMassLong); } else { massesToLocalize.Add(crosslinker.TotalMass + otherPeptideMass); } var fragments = new List <Product>(); HashSet <double> masses = new HashSet <double>(); foreach (int crosslinkerPosition in possibleCrosslinkerPositions) { List <Product> theoreticalProducts = new List <Product>(); //need a new one each time to pass as a reference, don't clear masses.Clear(); foreach (double massToLocalize in massesToLocalize) { Dictionary <int, Modification> testMods = new Dictionary <int, Modification> { { crosslinkerPosition + 1, new Modification(_monoisotopicMass: massToLocalize) } }; foreach (var mod in peptide.AllModsOneIsNterminus) { testMods.Add(mod.Key, mod.Value); } var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); testPeptide.Fragment(dissociationType, FragmentationTerminus.Both, fragments); // add fragmentation ions for this crosslinker position guess foreach (var fragment in fragments) { if (!masses.Contains(fragment.NeutralMass)) { theoreticalProducts.Add(fragment); masses.Add(fragment.NeutralMass); } } // add signature ions if (crosslinker.Cleavable) { theoreticalProducts.Add(new Product(ProductType.M, FragmentationTerminus.None, peptide.MonoisotopicMass + massToLocalize, peptide.Length, peptide.Length, 0)); } } yield return(new Tuple <int, List <Product> >(crosslinkerPosition, theoreticalProducts)); } }
public static Dictionary <Tuple <int, int>, List <Product> > XlLoopGetTheoreticalFragments(DissociationType dissociationType, Modification loopMass, List <int> modPos, PeptideWithSetModifications peptide) { Dictionary <Tuple <int, int>, List <Product> > AllTheoreticalFragmentsLists = new Dictionary <Tuple <int, int>, List <Product> >(); var originalFragments = new List <Product>(); peptide.Fragment(dissociationType, FragmentationTerminus.Both, originalFragments); var loopProducts = new List <Product>(); foreach (int position1 in modPos) { foreach (int position2 in modPos) { if (position2 <= position1) { continue; } // add N and C terminal fragments that do not contain the loop Tuple <int, int> loopPositions = new Tuple <int, int>(position1, position2); List <Product> loopFragments = originalFragments .Where(p => p.Terminus == FragmentationTerminus.N && p.AminoAcidPosition <position1 || p.Terminus == FragmentationTerminus.C && p.AminoAcidPosition> position2).ToList(); // add N-terminal fragments containing the loop Dictionary <int, Modification> modDict = new Dictionary <int, Modification>(); if (peptide.AllModsOneIsNterminus.Any()) { double combinedModMass = loopMass.MonoisotopicMass.Value + peptide.AllModsOneIsNterminus.Where(v => v.Key <= position2 + 1).Sum(p => p.Value.MonoisotopicMass.Value); Modification combined = new Modification(_monoisotopicMass: combinedModMass); modDict.Add(position1 + 1, combined); foreach (var mod in peptide.AllModsOneIsNterminus.Where(m => m.Key > position2 + 1)) { modDict.Add(mod.Key, mod.Value); } } else { modDict.Add(position1 + 1, loopMass); } PeptideWithSetModifications peptideWithLoop = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, modDict, peptide.NumFixedMods); peptideWithLoop.Fragment(dissociationType, FragmentationTerminus.Both, loopProducts); loopFragments.AddRange(loopProducts.Where(p => p.Terminus == FragmentationTerminus.N && p.AminoAcidPosition >= position2)); // add C-terminal fragments containing the loop modDict.Clear(); if (peptide.AllModsOneIsNterminus.Any()) { double combinedModMass = loopMass.MonoisotopicMass.Value + peptide.AllModsOneIsNterminus.Where(v => v.Key >= position1 + 1).Sum(p => p.Value.MonoisotopicMass.Value); Modification combined = new Modification(_monoisotopicMass: combinedModMass); modDict.Add(position2 + 1, combined); foreach (var mod in peptide.AllModsOneIsNterminus.Where(m => m.Key < position1 + 1)) { modDict.Add(mod.Key, mod.Value); } } else { modDict.Add(position2 + 1, loopMass); } peptideWithLoop = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, modDict, peptide.NumFixedMods); peptideWithLoop.Fragment(dissociationType, FragmentationTerminus.Both, loopProducts); loopFragments.AddRange( loopProducts.Where(p => p.Terminus == FragmentationTerminus.C && p.AminoAcidPosition <= position1)); AllTheoreticalFragmentsLists.Add(loopPositions, loopFragments); } } return(AllTheoreticalFragmentsLists); }
protected MsDataScanWithPrecursor(TSpectrum massSpectrum, int ScanNumber, int MsnOrder, bool isCentroid, Polarity Polarity, double RetentionTime, MzRange MzRange, string ScanFilter, MZAnalyzerType MzAnalyzer, double TotalIonCurrent, double selectedIonMZ, int?selectedIonChargeStateGuess, double?selectedIonIntensity, double?isolationMZ, double?isolationWidth, DissociationType dissociationType, int?oneBasedPrecursorScanNumber, double?selectedIonMonoisotopicGuessMz, double?injectionTime, double[,] noiseData, string nativeId) : base(massSpectrum, ScanNumber, MsnOrder, isCentroid, Polarity, RetentionTime, MzRange, ScanFilter, MzAnalyzer, TotalIonCurrent, injectionTime, noiseData, nativeId) { this.OneBasedPrecursorScanNumber = oneBasedPrecursorScanNumber; this.IsolationMz = isolationMZ; this.IsolationWidth = isolationWidth; this.DissociationType = dissociationType; this.SelectedIonMZ = selectedIonMZ; this.SelectedIonIntensity = selectedIonIntensity; this.SelectedIonChargeStateGuess = selectedIonChargeStateGuess; this.SelectedIonMonoisotopicGuessMz = selectedIonMonoisotopicGuessMz; }
private void SaveButton_Click(object sender, RoutedEventArgs e) { CleavageSpecificity searchModeType = CleavageSpecificity.Full; //classic and modern by default if (semiSpecificSearchRadioButton.IsChecked.Value) //semi { searchModeType = CleavageSpecificity.Semi; } else if (nonSpecificSearchRadioButton.IsChecked.Value) //non { searchModeType = CleavageSpecificity.None; } //else it's the default of full if (searchModeType != CleavageSpecificity.Full) { if (((Protease)proteaseComboBox.SelectedItem).Name.Contains("non-specific")) { searchModeType = CleavageSpecificity.None; //prevents an accidental semi attempt of a non-specific protease if (cTerminalIons.IsChecked.Value) { Protease singleC = ProteaseDictionary.Dictionary["singleC"]; proteaseComboBox.SelectedItem = singleC; } else //we're not allowing no ion types. It must have N if it doesn't have C. { Protease singleN = ProteaseDictionary.Dictionary["singleN"]; proteaseComboBox.SelectedItem = singleN; } } if (!addCompIonCheckBox.IsChecked.Value) { MessageBox.Show("Warning: Complementary ions are strongly recommended when using this algorithm."); } //only use N or C termini, not both if (cTerminalIons.IsChecked.Value) { nTerminalIons.IsChecked = false; } else { nTerminalIons.IsChecked = true; } } if (!GlobalGuiSettings.CheckTaskSettingsValidity(precursorMassToleranceTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text, maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text, peakFindingToleranceTextBox.Text, histogramBinWidthTextBox.Text, DeconvolutionMaxAssumedChargeStateTextBox.Text, NumberOfPeaksToKeepPerWindowTextBox.Text, MinimumAllowedIntensityRatioToBasePeakTexBox.Text, WindowWidthThomsonsTextBox.Text, NumberOfWindowsTextBox.Text, numberOfDatabaseSearchesTextBox.Text, MaxModNumTextBox.Text, MaxFragmentMassTextBox.Text, QValueTextBox.Text)) { return; } Protease protease = (Protease)proteaseComboBox.SelectedItem; DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[dissociationTypeComboBox.SelectedItem.ToString()]; CustomFragmentationWindow.Close(); FragmentationTerminus fragmentationTerminus = FragmentationTerminus.Both; if (nTerminalIons.IsChecked.Value && !cTerminalIons.IsChecked.Value) { fragmentationTerminus = FragmentationTerminus.N; } else if (!nTerminalIons.IsChecked.Value && cTerminalIons.IsChecked.Value) { fragmentationTerminus = FragmentationTerminus.C; } else if (!nTerminalIons.IsChecked.Value && !cTerminalIons.IsChecked.Value) //why would you want this { fragmentationTerminus = FragmentationTerminus.None; MessageBox.Show("Warning: No ion types were selected. MetaMorpheus will be unable to search MS/MS spectra."); } //else both int maxMissedCleavages = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int minPeptideLengthValue = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int maxPeptideLengthValue = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MinVariantDepth = int.Parse(MinVariantDepthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int MaxHeterozygousVariants = int.Parse(MaxHeterozygousVariantsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxModificationIsoformsValue = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture)); int maxModsForPeptideValue = (int.Parse(MaxModNumTextBox.Text, CultureInfo.InvariantCulture)); InitiatorMethionineBehavior initiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex); DigestionParams digestionParamsToSave = new DigestionParams( protease: protease.Name, maxMissedCleavages: maxMissedCleavages, minPeptideLength: minPeptideLengthValue, maxPeptideLength: maxPeptideLengthValue, maxModificationIsoforms: maxModificationIsoformsValue, initiatorMethionineBehavior: initiatorMethionineBehavior, maxModsForPeptides: maxModsForPeptideValue, searchModeType: searchModeType, fragmentationTerminus: fragmentationTerminus, generateUnlabeledProteinsForSilac: CheckBoxQuantifyUnlabeledForSilac.IsChecked.Value); Tolerance ProductMassTolerance; if (productMassToleranceComboBox.SelectedIndex == 0) { ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } Tolerance PrecursorMassTolerance; if (precursorMassToleranceComboBox.SelectedIndex == 0) { PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { PrecursorMassTolerance = new PpmTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } TheTask.SearchParameters.MaxFragmentSize = Double.Parse(MaxFragmentMassTextBox.Text, CultureInfo.InvariantCulture); var listOfModsVariable = new List <(string, string)>(); foreach (var heh in VariableModTypeForTreeViewObservableCollection) { listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } var listOfModsFixed = new List <(string, string)>(); foreach (var heh in FixedModTypeForTreeViewObservableCollection) { listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable)) { return; } bool TrimMs1Peaks = trimMs1.IsChecked.Value; bool TrimMsMsPeaks = trimMsMs.IsChecked.Value; int?numPeaksToKeep = null; if (int.TryParse(NumberOfPeaksToKeepPerWindowTextBox.Text, out int numberOfPeaksToKeeep)) { numPeaksToKeep = numberOfPeaksToKeeep; } double?minimumAllowedIntensityRatioToBasePeak = null; if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, out double minimumAllowedIntensityRatio)) { minimumAllowedIntensityRatioToBasePeak = minimumAllowedIntensityRatio; } double?windowWidthThompsons = null; if (double.TryParse(WindowWidthThomsonsTextBox.Text, out double windowWidth)) { windowWidthThompsons = windowWidth; } int?numberOfWindows = null; if (int.TryParse(NumberOfWindowsTextBox.Text, out int numWindows)) { numberOfWindows = numWindows; } bool normalizePeaksAccrossAllWindows = normalizePeaksInWindowCheckBox.IsChecked.Value; bool parseMaxThreadsPerFile = !maxThreadsTextBox.Text.Equals("") && (int.Parse(maxThreadsTextBox.Text) <= Environment.ProcessorCount && int.Parse(maxThreadsTextBox.Text) > 0); CommonParameters commonParamsToSave = new CommonParameters( taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "SearchTask", maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile, useDeltaScore: deltaScoreCheckBox.IsChecked.Value, reportAllAmbiguity: allAmbiguity.IsChecked.Value, deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture), totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture), doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value, useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value, scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture), listOfModsFixed: listOfModsFixed, listOfModsVariable: listOfModsVariable, dissociationType: dissociationType, precursorMassTolerance: PrecursorMassTolerance, productMassTolerance: ProductMassTolerance, digestionParams: digestionParamsToSave, trimMs1Peaks: TrimMs1Peaks, trimMsMsPeaks: TrimMsMsPeaks, numberOfPeaksToKeepPerWindow: numPeaksToKeep, minimumAllowedIntensityRatioToBasePeak: minimumAllowedIntensityRatioToBasePeak, windowWidthThomsons: windowWidthThompsons, numberOfWindows: numberOfWindows, //maybe change this some day normalizePeaksAccrossAllWindows: normalizePeaksAccrossAllWindows, //maybe change this some day addCompIons: addCompIonCheckBox.IsChecked.Value, qValueOutputFilter: QValueCheckBox.IsChecked.Value ? double.Parse(QValueTextBox.Text, CultureInfo.InvariantCulture) : 1.0, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down", minVariantDepth: MinVariantDepth, maxHeterozygousVariants: MaxHeterozygousVariants); if (classicSearchRadioButton.IsChecked.Value) { TheTask.SearchParameters.SearchType = SearchType.Classic; } else if (modernSearchRadioButton.IsChecked.Value) { TheTask.SearchParameters.SearchType = SearchType.Modern; } else //both semi and nonspecific are termed "nonspecific", because they both contain at least one nonspecific cleavage and they share the same algorithm { TheTask.SearchParameters.SearchType = SearchType.NonSpecific; } TheTask.SearchParameters.DoParsimony = checkBoxParsimony.IsChecked.Value; TheTask.SearchParameters.NoOneHitWonders = checkBoxNoOneHitWonders.IsChecked.Value; TheTask.SearchParameters.DoQuantification = !checkBoxNoQuant.IsChecked.Value; //SilacLabel deconvolution { if (StaticSilacLabelsObservableCollection.Count == 0) { TheTask.SearchParameters.SilacLabels = null; } else { List <Proteomics.SilacLabel> labelsToSave = new List <Proteomics.SilacLabel>(); foreach (SilacInfoForDataGrid info in StaticSilacLabelsObservableCollection) { Proteomics.SilacLabel labelToAdd = info.SilacLabel[0]; //This is needed to prevent double adding of additional labels. //A quick test is to create a silac condition with two labels, save, reopen the task, save, and reopen again. //Without this line, the second label will be doubled (K+8)&(R+10)&(R+10) if (labelToAdd.AdditionalLabels != null) { labelToAdd.AdditionalLabels.Clear(); } for (int infoIndex = 1; infoIndex < info.SilacLabel.Count; infoIndex++) { labelToAdd.AddAdditionalSilacLabel(info.SilacLabel[infoIndex]); } labelsToSave.Add(labelToAdd); } TheTask.SearchParameters.SilacLabels = labelsToSave; } } TheTask.SearchParameters.Normalize = checkBoxNormalize.IsChecked.Value; TheTask.SearchParameters.MatchBetweenRuns = checkBoxMatchBetweenRuns.IsChecked.Value; TheTask.SearchParameters.ModPeptidesAreDifferent = modPepsAreUnique.IsChecked.Value; TheTask.SearchParameters.QuantifyPpmTol = double.Parse(peakFindingToleranceTextBox.Text, CultureInfo.InvariantCulture); TheTask.SearchParameters.SearchTarget = checkBoxTarget.IsChecked.Value; TheTask.SearchParameters.WriteMzId = ckbMzId.IsChecked.Value; TheTask.SearchParameters.WriteDecoys = writeDecoyCheckBox.IsChecked.Value; TheTask.SearchParameters.WriteContaminants = writeContaminantCheckBox.IsChecked.Value; //TheTask.SearchParameters.OutPepXML = ckbPepXML.IsChecked.Value; if (checkBoxDecoy.IsChecked.Value) { if (radioButtonReverseDecoy.IsChecked.Value) { TheTask.SearchParameters.DecoyType = DecoyType.Reverse; } else //if (radioButtonSlideDecoy.IsChecked.Value) { TheTask.SearchParameters.DecoyType = DecoyType.Slide; } } else { TheTask.SearchParameters.DecoyType = DecoyType.None; } if (massDiffAcceptExact.IsChecked.HasValue && massDiffAcceptExact.IsChecked.Value) { TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Exact; } if (massDiffAccept1mm.IsChecked.HasValue && massDiffAccept1mm.IsChecked.Value) { TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.OneMM; } if (massDiffAccept2mm.IsChecked.HasValue && massDiffAccept2mm.IsChecked.Value) { TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.TwoMM; } if (massDiffAccept3mm.IsChecked.HasValue && massDiffAccept3mm.IsChecked.Value) { TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.ThreeMM; } if (massDiffAccept187.IsChecked.HasValue && massDiffAccept187.IsChecked.Value) { TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.ModOpen; } if (massDiffAcceptOpen.IsChecked.HasValue && massDiffAcceptOpen.IsChecked.Value) { TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Open; } if (massDiffAcceptCustom.IsChecked.HasValue && massDiffAcceptCustom.IsChecked.Value) { try { MassDiffAcceptor customMassDiffAcceptor = SearchTask.GetMassDiffAcceptor(null, MassDiffAcceptorType.Custom, customkMdacTextBox.Text); } catch (Exception ex) { MessageBox.Show("Could not parse custom mass difference acceptor: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } TheTask.SearchParameters.MassDiffAcceptorType = MassDiffAcceptorType.Custom; TheTask.SearchParameters.CustomMdac = customkMdacTextBox.Text; } //determine if semi or nonspecific with a specific protease. if (searchModeType == CleavageSpecificity.Semi || protease.CleavageSpecificity == CleavageSpecificity.Semi) { TheTask.SearchParameters.LocalFdrCategories = new List <FdrCategory> { FdrCategory.FullySpecific, FdrCategory.SemiSpecific }; } else if (searchModeType == CleavageSpecificity.None && protease.CleavageSpecificity != CleavageSpecificity.None) { TheTask.SearchParameters.LocalFdrCategories = new List <FdrCategory> { FdrCategory.FullySpecific, FdrCategory.SemiSpecific, FdrCategory.NonSpecific }; } else { TheTask.SearchParameters.LocalFdrCategories = new List <FdrCategory> { FdrCategory.FullySpecific }; } // displays warning if classic search is enabled with an open search mode if (TheTask.SearchParameters.SearchType == SearchType.Classic && (TheTask.SearchParameters.MassDiffAcceptorType == MassDiffAcceptorType.ModOpen || TheTask.SearchParameters.MassDiffAcceptorType == MassDiffAcceptorType.Open)) { MessageBoxResult result = MessageBox.Show("Modern Search mode is recommended when conducting open precursor mass searches to reduce search time.\n\n" + "Continue anyway?", "Modern search recommended", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } } TheTask.SearchParameters.DoHistogramAnalysis = checkBoxHistogramAnalysis.IsChecked.Value; TheTask.SearchParameters.HistogramBinTolInDaltons = double.Parse(histogramBinWidthTextBox.Text, CultureInfo.InvariantCulture); TheTask.SearchParameters.WritePrunedDatabase = writePrunedDBCheckBox.IsChecked.Value; SetModSelectionForPrunedDB(); TheTask.CommonParameters = commonParamsToSave; DialogResult = true; }
public MzmlScanWithPrecursor(int ScanNumber, MzmlMzSpectrum massSpectrum, int MsnOrder, bool isCentroid, Polarity Polarity, double RetentionTime, MzRange MzRange, string ScanFilter, MZAnalyzerType MzAnalyzer, double TotalIonCurrent, double selectedIonMz, int?selectedIonChargeStateGuess, double?selectedIonIntensity, double isolationMZ, double?isolationWidth, DissociationType dissociationType, int oneBasedPrecursorScanNumber, double?selectedIonGuessMonoisotopicMZ, double?injectionTime) : base(ScanNumber, MsnOrder, isCentroid, Polarity, RetentionTime, MzRange, ScanFilter, MzAnalyzer, TotalIonCurrent, selectedIonMz, selectedIonChargeStateGuess, selectedIonIntensity, isolationMZ, isolationWidth, dissociationType, oneBasedPrecursorScanNumber, selectedIonGuessMonoisotopicMZ, injectionTime, null) { this.MassSpectrum = massSpectrum; }
public static void MatchInternalFragmentIons(PeptideSpectralMatch[] fileSpecificPsms, Ms2ScanWithSpecificMass[] arrayOfMs2ScansSortedByMass, CommonParameters combinedParams, int minInternalFragmentLength) { //for each PSM with an ID for (int index = 0; index < fileSpecificPsms.Length; index++) { PeptideSpectralMatch psm = fileSpecificPsms[index]; if (psm != null && psm.BestMatchingPeptides.Count() > 0) { //Get the scan Ms2ScanWithSpecificMass scanForThisPsm = arrayOfMs2ScansSortedByMass[index]; DissociationType dissociationType = combinedParams.DissociationType == DissociationType.Autodetect ? scanForThisPsm.TheScan.DissociationType.Value : combinedParams.DissociationType; //Get the theoretical peptides List <PeptideWithSetModifications> ambiguousPeptides = new List <PeptideWithSetModifications>(); List <int> notches = new List <int>(); foreach (var(Notch, Peptide) in psm.BestMatchingPeptides) { ambiguousPeptides.Add(Peptide); notches.Add(Notch); } //get matched ions for each peptide List <List <MatchedFragmentIon> > matchedIonsForAllAmbiguousPeptides = new List <List <MatchedFragmentIon> >(); List <Product> internalFragments = new List <Product>(); foreach (PeptideWithSetModifications peptide in ambiguousPeptides) { internalFragments.Clear(); peptide.FragmentInternally(combinedParams.DissociationType, minInternalFragmentLength, internalFragments); //TODO: currently, internal and terminal ions can match to the same observed peaks (much like how b- and y-ions can match to the same peaks). Investigate if we should change that... matchedIonsForAllAmbiguousPeptides.Add(MetaMorpheusEngine.MatchFragmentIons(scanForThisPsm, internalFragments, combinedParams)); } //Find the max number of matched ions int maxNumMatchedIons = matchedIonsForAllAmbiguousPeptides.Max(x => x.Count); //remove peptides if they have fewer than max-1 matched ions, thus requiring at least two internal ions to disambiguate an ID //if not removed, then add the matched internal ions HashSet <PeptideWithSetModifications> PeptidesToMatchingInternalFragments = new HashSet <PeptideWithSetModifications>(); for (int peptideIndex = 0; peptideIndex < ambiguousPeptides.Count; peptideIndex++) { //if we should remove the theoretical, remove it if (matchedIonsForAllAmbiguousPeptides[peptideIndex].Count + 1 < maxNumMatchedIons) { psm.RemoveThisAmbiguousPeptide(notches[peptideIndex], ambiguousPeptides[peptideIndex]); } // otherwise add the matched internal ions to the total ions else { PeptideWithSetModifications currentPwsm = ambiguousPeptides[peptideIndex]; //check that we haven't already added the matched ions for this peptide if (!PeptidesToMatchingInternalFragments.Contains(currentPwsm)) { PeptidesToMatchingInternalFragments.Add(currentPwsm); //record that we've seen this peptide psm.PeptidesToMatchingFragments[currentPwsm].AddRange(matchedIonsForAllAmbiguousPeptides[peptideIndex]); //add the matched ions } } } } } }
private static MsDataScan GetMsDataOneBasedScanFromConnection(Generated.mzMLType _mzMLConnection, int oneBasedIndex, IFilteringParams filterParams) { // Read in the instrument configuration types from connection (in mzml it's at the start) Generated.InstrumentConfigurationType[] configs = new Generated.InstrumentConfigurationType[_mzMLConnection.instrumentConfigurationList.instrumentConfiguration.Length]; for (int i = 0; i < _mzMLConnection.instrumentConfigurationList.instrumentConfiguration.Length; i++) { configs[i] = _mzMLConnection.instrumentConfigurationList.instrumentConfiguration[i]; } var defaultInstrumentConfig = _mzMLConnection.run.defaultInstrumentConfigurationRef; // May be null! var scanSpecificInsturmentConfig = _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].instrumentConfigurationRef; MZAnalyzerType analyzer = default(MZAnalyzerType); // use default if (scanSpecificInsturmentConfig == null || scanSpecificInsturmentConfig == defaultInstrumentConfig) { if (configs[0].componentList == null) { analyzer = default(MZAnalyzerType); } else if (AnalyzerDictionary.TryGetValue(configs[0].componentList.analyzer[0].cvParam[0].accession, out MZAnalyzerType returnVal)) { analyzer = returnVal; } } // use scan-specific else { for (int i = 0; i < _mzMLConnection.instrumentConfigurationList.instrumentConfiguration.Length; i++) { if (configs[i].id.Equals(scanSpecificInsturmentConfig)) { AnalyzerDictionary.TryGetValue(configs[i].componentList.analyzer[0].cvParam[0].accession, out MZAnalyzerType returnVal); analyzer = returnVal; } } } string nativeId = _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].id; int? msOrder = null; bool? isCentroid = null; Polarity polarity = Polarity.Unknown; double tic = double.NaN; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].cvParam) { if (cv.accession.Equals(_msnOrderAccession)) { msOrder = int.Parse(cv.value); } if (cv.accession.Equals(_centroidSpectrum)) { isCentroid = true; } if (cv.accession.Equals(_profileSpectrum)) { throw new MzLibException("Reading profile mode mzmls not supported"); } if (cv.accession.Equals(_totalIonCurrent)) { tic = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (polarity.Equals(Polarity.Unknown)) { PolarityDictionary.TryGetValue(cv.accession, out polarity); } } double rtInMinutes = double.NaN; string scanFilter = null; double?injectionTime = null; int oneBasedScanNumber = oneBasedIndex; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].cvParam != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].cvParam) { if (cv.accession.Equals(_retentionTime)) { rtInMinutes = double.Parse(cv.value, CultureInfo.InvariantCulture); if (cv.unitName == "second") { rtInMinutes /= 60; } } if (cv.accession.Equals(_filterString)) { scanFilter = cv.value; } if (cv.accession.Equals(_ionInjectionTime)) { injectionTime = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_oneBasedScanNumber)) //get the real one based spectrum number (if available), the other assumes they are in order. This is present in .mgf->.mzml conversions from MSConvert { oneBasedScanNumber = int.Parse(cv.value); } } } if (!msOrder.HasValue || !isCentroid.HasValue) { //one instance when this if statment is true (i.e. not false) is when there is no mz/intensity data //so, we return the MsDataScan object with a null spectrum //scans w/ null spectra are checked later and the scan numbers associated w those scans are returned to the reader. return(new MsDataScan( null, oneBasedScanNumber, msOrder.Value, false, //have to return a value here b/c it is not nullable polarity, rtInMinutes, null, scanFilter, analyzer, tic, injectionTime, null, nativeId)); } double[] masses = new double[0]; double[] intensities = new double[0]; foreach (Generated.BinaryDataArrayType binaryData in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].binaryDataArrayList.binaryDataArray) { bool compressed = false; bool mzArray = false; bool intensityArray = false; bool is32bit = true; foreach (Generated.CVParamType cv in binaryData.cvParam) { compressed |= cv.accession.Equals(_zlibCompression); is32bit &= !cv.accession.Equals(_64bit); is32bit |= cv.accession.Equals(_32bit); mzArray |= cv.accession.Equals(_mzArray); intensityArray |= cv.accession.Equals(_intensityArray); } //in the futurem we may see scass w/ no data and there will be a crash here. if that happens, you can retrun an MsDataScan with null as the mzSpectrum //the scans with no spectra will be reported to the reader and left out of the scan list. double[] data = ConvertBase64ToDoubles(binaryData.binary, compressed, is32bit); if (mzArray) { masses = data; } if (intensityArray) { intensities = data; } } double high = double.NaN; double low = double.NaN; var aScanWindowList = _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].scanWindowList; if (aScanWindowList != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].scanWindowList.scanWindow[0].cvParam) { if (cv.accession.Equals(_scanWindowLowerLimit)) { low = double.Parse(cv.value, CultureInfo.InvariantCulture); } else if (cv.accession.Equals(_scanWindowUpperLimit)) { high = double.Parse(cv.value, CultureInfo.InvariantCulture); } } } //Remove Zero Intensity Peaks double zeroEquivalentIntensity = 0.01; int zeroIntensityCount = intensities.Count(i => i < zeroEquivalentIntensity); int intensityValueCount = intensities.Count(); if (zeroIntensityCount > 0 && zeroIntensityCount < intensityValueCount) { Array.Sort(intensities, masses); double[] nonZeroIntensities = new double[intensityValueCount - zeroIntensityCount]; double[] nonZeroMzs = new double[intensityValueCount - zeroIntensityCount]; intensities = intensities.SubArray(zeroIntensityCount, intensityValueCount - zeroIntensityCount); masses = masses.SubArray(zeroIntensityCount, intensityValueCount - zeroIntensityCount); Array.Sort(masses, intensities); } if (filterParams != null && intensities.Length > 0 && ((filterParams.ApplyTrimmingToMs1 && msOrder.Value == 1) || (filterParams.ApplyTrimmingToMsMs && msOrder.Value > 1))) { WindowModeHelper(ref intensities, ref masses, filterParams, low, high); } Array.Sort(masses, intensities); var mzmlMzSpectrum = new MzSpectrum(masses, intensities, false); if (msOrder.Value == 1) { return(new MsDataScan( mzmlMzSpectrum, oneBasedScanNumber, msOrder.Value, isCentroid.Value, polarity, rtInMinutes, new MzRange(low, high), scanFilter, analyzer, tic, injectionTime, null, nativeId)); } double selectedIonMz = double.NaN; int? selectedIonCharge = null; double?selectedIonIntensity = null; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].selectedIonList.selectedIon[0].cvParam) { if (cv.accession.Equals(_selectedIonMz)) { selectedIonMz = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_precursorCharge)) { selectedIonCharge = int.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_peakIntensity)) { selectedIonIntensity = double.Parse(cv.value, CultureInfo.InvariantCulture); } } double?isolationMz = null; double lowIsolation = double.NaN; double highIsolation = double.NaN; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].isolationWindow != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].isolationWindow.cvParam) { if (cv.accession.Equals(_isolationWindowTargetMZ)) { isolationMz = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_isolationWindowLowerOffset)) { lowIsolation = double.Parse(cv.value, CultureInfo.InvariantCulture); } if (cv.accession.Equals(_isolationWindowUpperOffset)) { highIsolation = double.Parse(cv.value, CultureInfo.InvariantCulture); } } } DissociationType dissociationType = DissociationType.Unknown; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].activation.cvParam != null) { // for EThcD scans, the dissociation type will not be listed as EThcD. it will be 2 different dissociation types // in the list, one as ETD and one with HCD. so we need to check for that case and interpret it as EThcD. List <DissociationType> scanDissociationTypes = new List <DissociationType>(); foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].activation.cvParam) { if (DissociationDictionary.TryGetValue(cv.accession, out var scanDissociationType)) { scanDissociationTypes.Add(scanDissociationType); } } if (scanDissociationTypes.Contains(DissociationType.ETD) && scanDissociationTypes.Contains(DissociationType.HCD)) { dissociationType = DissociationType.EThcD; } else if (scanDissociationTypes.Any()) { dissociationType = scanDissociationTypes.First(); } else { dissociationType = DissociationType.Unknown; } } double?monoisotopicMz = null; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].userParam != null) { foreach (var userParam in _mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].scanList.scan[0].userParam) { if (userParam.name.EndsWith("Monoisotopic M/Z:")) { monoisotopicMz = double.Parse(userParam.value, CultureInfo.InvariantCulture); } } } int?precursorScanNumber; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedIndex - 1].precursorList.precursor[0].spectrumRef == null) { precursorScanNumber = null; } else { precursorScanNumber = GetOneBasedPrecursorScanNumber(_mzMLConnection, oneBasedIndex); } return(new MsDataScan( mzmlMzSpectrum, oneBasedIndex, msOrder.Value, isCentroid.Value, polarity, rtInMinutes, new MzRange(low, high), scanFilter, analyzer, tic, injectionTime, null, nativeId, selectedIonMz, selectedIonCharge, selectedIonIntensity, isolationMz, lowIsolation + highIsolation, dissociationType, precursorScanNumber, monoisotopicMz )); }
public static MzSpectrum GenerateComplementarySpectrum(MzSpectrum spectrum, double precursorMass, DissociationType dissociationType) { double protonMassShift = complementaryIonConversionDictionary[dissociationType].ToMass(1); double[] newMzSpectrum = new double[spectrum.Size]; double[] intensity = new double[spectrum.Size]; for (int i = spectrum.Size - 1; i >= 0; i--) { int j = spectrum.Size - i - 1; double mz = spectrum.XArray[i]; double compFragmentMass = (precursorMass + protonMassShift) - mz.ToMass(1); newMzSpectrum[j] = compFragmentMass.ToMz(1); intensity[j] = spectrum.YArray[i]; } return(new MzSpectrum(newMzSpectrum, intensity, false)); }
public void SaveCustomMod_Click(object sender, RoutedEventArgs e) { string modsDirectory = Path.Combine(GlobalVariables.DataDir, @"Mods"); string customModsPath = Path.Combine(modsDirectory, @"CustomModifications.txt"); List <string> customModsText = new List <string>(); if (!File.Exists(customModsPath)) { customModsText.Add("Custom Modifications"); } else { customModsText = File.ReadAllLines(customModsPath).ToList(); } string idText = originalIdTextBox.Text; string motifText = motifTextBox.Text; string chemicalFormulaText = chemicalFormulaTextBox.Text; string modMassText = modMassTextBox.Text; string neutralLossText = neutralLossTextBox.Text; string diagnosticIonText = diagnosticIonTextBox.Text; string modificationTypeText = modificationTypeTextBox.Text; string locationRestriction = locationRestrictions[locationRestrictionComboBox.Text]; DissociationType disType = GlobalVariables.AllSupportedDissociationTypes[dissociationTypeComboBox.Text]; if (ErrorsDetected(idText, motifText, modMassText, chemicalFormulaText, neutralLossText, modificationTypeText, diagnosticIonText)) { return; } // create custom mod Dictionary <DissociationType, List <double> > neutralLosses = null; if (!string.IsNullOrEmpty(neutralLossText)) { neutralLosses = new Dictionary <DissociationType, List <double> > { { disType, neutralLossText.Split(',').Select(p => double.Parse(p, CultureInfo.InvariantCulture)).ToList() } }; } Dictionary <DissociationType, List <double> > diagnosticIons = null; if (!string.IsNullOrEmpty(diagnosticIonText)) { diagnosticIons = new Dictionary <DissociationType, List <double> >() { { disType, diagnosticIonText.Split(',').Select(p => double.Parse(p, CultureInfo.InvariantCulture).ToMass(1)).ToList() } }; } ModificationMotif.TryGetMotif(motifText, out ModificationMotif finalMotif); ChemicalFormula chemicalFormula = null; if (!string.IsNullOrEmpty(chemicalFormulaText)) { chemicalFormula = ChemicalFormula.ParseFormula(chemicalFormulaText); } double?modMass = null; if (!string.IsNullOrEmpty(modMassText)) { modMass = double.Parse(modMassText, CultureInfo.InvariantCulture); } Modification modification = new Modification( _originalId: idText, _modificationType: modificationTypeText, _target: finalMotif, _locationRestriction: locationRestriction, _chemicalFormula: chemicalFormula, _monoisotopicMass: modMass, _neutralLosses: neutralLosses, _diagnosticIons: diagnosticIons); if (GlobalVariables.AllModsKnownDictionary.ContainsKey(modification.IdWithMotif)) { MessageBox.Show("A modification already exists with the name: " + modification.IdWithMotif, "Error", MessageBoxButton.OK, MessageBoxImage.Hand); return; } // write custom mod to mods file // write/read temp file to make sure the mod is readable, then delete it string tempPath = Path.Combine(modsDirectory, @"temp.txt"); try { List <string> temp = new List <string> { modification.ToString(), @"//" }; File.WriteAllLines(tempPath, temp); var parsedMods = UsefulProteomicsDatabases.PtmListLoader.ReadModsFromFile(tempPath, out var errors); if (parsedMods.Count() != 1) { MessageBox.Show("Problem parsing custom mod: One mod was expected, a different number was generated", "Error", MessageBoxButton.OK, MessageBoxImage.Hand); return; } if (errors.Any()) { string concatErrors = string.Join(Environment.NewLine, errors.Select(p => p.Item2)); MessageBox.Show("Problem(s) parsing custom mod: " + Environment.NewLine + concatErrors, "Error", MessageBoxButton.OK, MessageBoxImage.Hand); return; } File.Delete(tempPath); } catch (Exception ex) { MessageBox.Show("Problem parsing custom mod: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Hand); File.Delete(tempPath); return; } // delete old custom mods file, write new one try { customModsText.Add(modification.ToString()); customModsText.Add(@"//"); File.Delete(customModsPath); File.WriteAllLines(customModsPath, customModsText); } catch (Exception ex) { MessageBox.Show("Problem saving custom mod to file: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Hand); return; } GlobalVariables.AddMods(new List <Modification> { modification }, false); DialogResult = true; }
private void SaveButton_Click(object sender, RoutedEventArgs e) { string fieldNotUsed = "1"; if (!GlobalGuiSettings.CheckTaskSettingsValidity(precursorMassToleranceTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text, maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text, fieldNotUsed, fieldNotUsed, DeconvolutionMaxAssumedChargeStateTextBox.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed)) { return; } Protease protease = (Protease)proteaseComboBox.SelectedItem; int MaxMissedCleavages = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MinPeptideLength = int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int MaxPeptideLength = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MinVariantDepth = int.Parse(MinVariantDepthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int MaxHeterozygousVariants = int.Parse(MaxHeterozygousVariantsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int MaxModificationIsoforms = int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture); InitiatorMethionineBehavior InitiatorMethionineBehavior = (InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex; DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()]; CustomFragmentationWindow.Close(); Tolerance ProductMassTolerance; if (productMassToleranceComboBox.SelectedIndex == 0) { ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } Tolerance PrecursorMassTolerance; if (precursorMassToleranceComboBox.SelectedIndex == 0) { PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { PrecursorMassTolerance = new PpmTolerance(double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } var listOfModsVariable = new List <(string, string)>(); foreach (var heh in variableModTypeForTreeViewObservableCollection) { listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable)) { return; } var listOfModsFixed = new List <(string, string)>(); foreach (var heh in fixedModTypeForTreeViewObservableCollection) { listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } bool parseMaxThreadsPerFile = int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) <= Environment.ProcessorCount && int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) > 0; CommonParameters commonParamsToSave = new CommonParameters( useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value, deconvolutionMaxAssumedChargeState: int.Parse(DeconvolutionMaxAssumedChargeStateTextBox.Text, CultureInfo.InvariantCulture), doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value, taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "GPTMDTask", maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile, digestionParams: new DigestionParams( protease: protease.Name, maxMissedCleavages: MaxMissedCleavages, minPeptideLength: MinPeptideLength, maxPeptideLength: MaxPeptideLength, maxModificationIsoforms: MaxModificationIsoforms, initiatorMethionineBehavior: InitiatorMethionineBehavior), dissociationType: dissociationType, scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture), precursorMassTolerance: PrecursorMassTolerance, productMassTolerance: ProductMassTolerance, listOfModsFixed: listOfModsFixed, listOfModsVariable: listOfModsVariable, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down", addCompIons: addCompIonCheckBox.IsChecked.Value, minVariantDepth: MinVariantDepth, maxHeterozygousVariants: MaxHeterozygousVariants); TheTask.GptmdParameters.ListOfModsGptmd = new List <(string, string)>(); foreach (var heh in gptmdModTypeForTreeViewObservableCollection) { TheTask.GptmdParameters.ListOfModsGptmd.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } TheTask.CommonParameters = commonParamsToSave; DialogResult = true; }
public CommonParameters(string taskDescriptor = null, DissociationType dissociationType = DissociationType.HCD, DissociationType childScanDissociationType = DissociationType.Unknown, bool doPrecursorDeconvolution = true, bool useProvidedPrecursorInfo = true, double deconvolutionIntensityRatio = 3, int deconvolutionMaxAssumedChargeState = 12, bool reportAllAmbiguity = true, bool addCompIons = false, int totalPartitions = 1, double scoreCutoff = 5, int?numberOfPeaksToKeepPerWindow = 200, double?minimumAllowedIntensityRatioToBasePeak = 0.01, double?windowWidthThomsons = null, int?numberOfWindows = null, bool normalizePeaksAccrossAllWindows = false, bool trimMs1Peaks = false, bool trimMsMsPeaks = true, bool useDeltaScore = false, Tolerance productMassTolerance = null, Tolerance precursorMassTolerance = null, Tolerance deconvolutionMassTolerance = null, int maxThreadsToUsePerFile = -1, DigestionParams digestionParams = null, IEnumerable <(string, string)> listOfModsVariable = null, IEnumerable <(string, string)> listOfModsFixed = null, double qValueOutputFilter = 1.0,
public static void CreateAndWriteMyMzmlWithCalibratedSpectra(IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile, string outputFile, bool writeIndexed) { var mzML = new Generated.mzMLType() { version = "1", cvList = new Generated.CVListType() }; mzML.cvList.count = "1"; mzML.cvList.cv = new Generated.CVType[1]; mzML.cvList.cv[0] = new Generated.CVType() { URI = @"https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo", fullName = "Proteomics Standards Initiative Mass Spectrometry Ontology", id = "MS" }; mzML.fileDescription = new Generated.FileDescriptionType() { fileContent = new Generated.ParamGroupType() }; mzML.fileDescription.fileContent.cvParam = new Generated.CVParamType[2]; mzML.fileDescription.fileContent.cvParam[0] = new Generated.CVParamType() { accession = "MS:1000579" // MS1 Data }; mzML.fileDescription.fileContent.cvParam[1] = new Generated.CVParamType() { accession = "MS:1000580" // MSn Data }; mzML.softwareList = new Generated.SoftwareListType() { count = "1", software = new Generated.SoftwareType[1] }; // TODO: add the raw file fields mzML.softwareList.software[0] = new Generated.SoftwareType() { id = "mzLib", version = "1", cvParam = new Generated.CVParamType[1] }; mzML.softwareList.software[0].cvParam[0] = new Generated.CVParamType() { accession = "MS:1000799", value = "mzLib" }; // Leaving empty. Can't figure out the configurations. // ToDo: read instrumentConfigurationList from mzML file mzML.instrumentConfigurationList = new Generated.InstrumentConfigurationListType(); mzML.dataProcessingList = new Generated.DataProcessingListType() { count = "1", dataProcessing = new Generated.DataProcessingType[1] }; // Only writing mine! Might have had some other data processing (but not if it is a raw file) // ToDo: read dataProcessingList from mzML file mzML.dataProcessingList.dataProcessing[0] = new Generated.DataProcessingType() { id = "mzLibProcessing" }; mzML.run = new Generated.RunType() { chromatogramList = new Generated.ChromatogramListType() { count = "1", chromatogram = new Generated.ChromatogramType[1] } }; // ToDo: Finish the chromatogram writing! mzML.run.chromatogramList.chromatogram[0] = new Generated.ChromatogramType(); mzML.run.spectrumList = new Generated.SpectrumListType() { count = (myMsDataFile.NumSpectra).ToString(CultureInfo.InvariantCulture), defaultDataProcessingRef = "mzLibProcessing", spectrum = new Generated.SpectrumType[myMsDataFile.NumSpectra] }; // Loop over all spectra for (int i = 1; i <= myMsDataFile.NumSpectra; i++) { mzML.run.spectrumList.spectrum[i - 1] = new Generated.SpectrumType() { defaultArrayLength = myMsDataFile.GetOneBasedScan(i).MassSpectrum.Size, index = i.ToString(CultureInfo.InvariantCulture), id = myMsDataFile.GetOneBasedScan(i).OneBasedScanNumber.ToString(), cvParam = new Generated.CVParamType[8] }; mzML.run.spectrumList.spectrum[i - 1].cvParam[0] = new Generated.CVParamType(); if (myMsDataFile.GetOneBasedScan(i).MsnOrder == 1) { mzML.run.spectrumList.spectrum[i - 1].cvParam[0].accession = "MS:1000579"; } else if (myMsDataFile.GetOneBasedScan(i) is IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > ) { var scanWithPrecursor = myMsDataFile.GetOneBasedScan(i) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; mzML.run.spectrumList.spectrum[i - 1].cvParam[0].accession = "MS:1000580"; // So needs a precursor! mzML.run.spectrumList.spectrum[i - 1].precursorList = new Generated.PrecursorListType() { count = 1.ToString(), precursor = new Generated.PrecursorType[1] }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0] = new Generated.PrecursorType(); string precursorID = scanWithPrecursor.OneBasedPrecursorScanNumber.ToString(); mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].spectrumRef = precursorID; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].selectedIonList = new Generated.SelectedIonListType() { count = 1.ToString(), selectedIon = new Generated.ParamGroupType[1] }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].selectedIonList.selectedIon[0] = new Generated.ParamGroupType() { cvParam = new Generated.CVParamType[3] }; // Selected ion MZ mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].selectedIonList.selectedIon[0].cvParam[0] = new Generated.CVParamType() { name = "selected ion m/z", value = scanWithPrecursor.SelectedIonMZ.ToString(CultureInfo.InvariantCulture), accession = "MS:1000744" }; // Charge State if (scanWithPrecursor.SelectedIonChargeStateGuess.HasValue) { mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].selectedIonList.selectedIon[0].cvParam[1] = new Generated.CVParamType() { name = "charge state", value = scanWithPrecursor.SelectedIonChargeStateGuess.Value.ToString(CultureInfo.InvariantCulture), accession = "MS:1000041" }; } // Selected ion intensity if (scanWithPrecursor.SelectedIonIntensity.HasValue) { mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].selectedIonList.selectedIon[0].cvParam[2] = new Generated.CVParamType() { name = "peak intensity", value = scanWithPrecursor.SelectedIonIntensity.Value.ToString(CultureInfo.InvariantCulture), accession = "MS:1000042" }; } MzRange isolationRange = scanWithPrecursor.IsolationRange; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].isolationWindow = new Generated.ParamGroupType() { cvParam = new Generated.CVParamType[3] }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].isolationWindow.cvParam[0] = new Generated.CVParamType() { accession = "MS:1000827", name = "isolation window target m/z", value = isolationRange.Mean.ToString(CultureInfo.InvariantCulture) }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].isolationWindow.cvParam[1] = new Generated.CVParamType() { accession = "MS:1000828", name = "isolation window lower offset", value = (isolationRange.Width / 2).ToString(CultureInfo.InvariantCulture) }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].isolationWindow.cvParam[2] = new Generated.CVParamType() { accession = "MS:1000829", name = "isolation window upper offset", value = (isolationRange.Width / 2).ToString(CultureInfo.InvariantCulture) }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].activation = new Generated.ParamGroupType() { cvParam = new Generated.CVParamType[1] }; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].activation.cvParam[0] = new Generated.CVParamType(); DissociationType dissociationType = scanWithPrecursor.DissociationType; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].activation.cvParam[0].accession = DissociationTypeAccessions[dissociationType]; mzML.run.spectrumList.spectrum[i - 1].precursorList.precursor[0].activation.cvParam[0].name = DissociationTypeNames[dissociationType]; } mzML.run.spectrumList.spectrum[i - 1].cvParam[1] = new Generated.CVParamType() { name = "ms level", accession = "MS:1000511", value = myMsDataFile.GetOneBasedScan(i).MsnOrder.ToString(CultureInfo.InvariantCulture) }; mzML.run.spectrumList.spectrum[i - 1].cvParam[2] = new Generated.CVParamType() { name = CentroidNames[myMsDataFile.GetOneBasedScan(i).IsCentroid], accession = CentroidAccessions[myMsDataFile.GetOneBasedScan(i).IsCentroid] }; if (PolarityNames.TryGetValue(myMsDataFile.GetOneBasedScan(i).Polarity, out string polarityName) && PolarityAccessions.TryGetValue(myMsDataFile.GetOneBasedScan(i).Polarity, out string polarityAccession)) { mzML.run.spectrumList.spectrum[i - 1].cvParam[3] = new Generated.CVParamType() { name = polarityName, accession = polarityAccession }; } // Spectrum title mzML.run.spectrumList.spectrum[i - 1].cvParam[4] = new Generated.CVParamType() { name = "spectrum title", accession = "MS:1000796", value = myMsDataFile.GetOneBasedScan(i).OneBasedScanNumber.ToString() }; if ((myMsDataFile.GetOneBasedScan(i).MassSpectrum.Size) > 0) { // Lowest observed mz mzML.run.spectrumList.spectrum[i - 1].cvParam[5] = new Generated.CVParamType() { name = "lowest observed m/z", accession = "MS:1000528", value = myMsDataFile.GetOneBasedScan(i).MassSpectrum.FirstX.ToString(CultureInfo.InvariantCulture) }; // Highest observed mz mzML.run.spectrumList.spectrum[i - 1].cvParam[6] = new Generated.CVParamType() { name = "highest observed m/z", accession = "MS:1000527", value = myMsDataFile.GetOneBasedScan(i).MassSpectrum.LastX.ToString(CultureInfo.InvariantCulture) }; } // Total ion current mzML.run.spectrumList.spectrum[i - 1].cvParam[7] = new Generated.CVParamType() { name = "total ion current", accession = "MS:1000285", value = myMsDataFile.GetOneBasedScan(i).TotalIonCurrent.ToString(CultureInfo.InvariantCulture) }; // Retention time mzML.run.spectrumList.spectrum[i - 1].scanList = new Generated.ScanListType() { count = "1", scan = new Generated.ScanType[1] }; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0] = new Generated.ScanType() { cvParam = new Generated.CVParamType[3] }; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].cvParam[0] = new Generated.CVParamType() { name = "scan start time", accession = "MS:1000016", value = myMsDataFile.GetOneBasedScan(i).RetentionTime.ToString(CultureInfo.InvariantCulture), unitCvRef = "UO", unitAccession = "UO:0000031", unitName = "minute" }; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].cvParam[1] = new Generated.CVParamType() { name = "filter string", accession = "MS:1000512", value = myMsDataFile.GetOneBasedScan(i).ScanFilter }; if (myMsDataFile.GetOneBasedScan(i).InjectionTime.HasValue) { mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].cvParam[2] = new Generated.CVParamType() { name = "ion injection time", accession = "MS:1000927", value = myMsDataFile.GetOneBasedScan(i).InjectionTime.Value.ToString(CultureInfo.InvariantCulture) }; } if (myMsDataFile.GetOneBasedScan(i) is IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > ) { var scanWithPrecursor = myMsDataFile.GetOneBasedScan(i) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; if (scanWithPrecursor.SelectedIonMonoisotopicGuessMz.HasValue) { mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].userParam = new Generated.UserParamType[1]; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].userParam[0] = new Generated.UserParamType() { name = "[mzLib]Monoisotopic M/Z:", value = scanWithPrecursor.SelectedIonMonoisotopicGuessMz.Value.ToString(CultureInfo.InvariantCulture) }; } } mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].scanWindowList = new Generated.ScanWindowListType() { count = 1, scanWindow = new Generated.ParamGroupType[1] }; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].scanWindowList.scanWindow[0] = new Generated.ParamGroupType() { cvParam = new Generated.CVParamType[2] }; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].scanWindowList.scanWindow[0].cvParam[0] = new Generated.CVParamType() { name = "scan window lower limit", accession = "MS:1000501", value = myMsDataFile.GetOneBasedScan(i).ScanWindowRange.Minimum.ToString(CultureInfo.InvariantCulture) }; mzML.run.spectrumList.spectrum[i - 1].scanList.scan[0].scanWindowList.scanWindow[0].cvParam[1] = new Generated.CVParamType() { name = "scan window upper limit", accession = "MS:1000500", value = myMsDataFile.GetOneBasedScan(i).ScanWindowRange.Maximum.ToString(CultureInfo.InvariantCulture) }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList = new Generated.BinaryDataArrayListType() { // ONLY WRITING M/Z AND INTENSITY DATA, NOT THE CHARGE! (but can add charge info later) // CHARGE (and other stuff) CAN BE IMPORTANT IN ML APPLICATIONS!!!!! count = 2.ToString(), binaryDataArray = new Generated.BinaryDataArrayType[5] }; // M/Z Data mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0] = new Generated.BinaryDataArrayType() { binary = myMsDataFile.GetOneBasedScan(i).MassSpectrum.Get64BitXarray() }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0].encodedLength = (4 * Math.Ceiling(((double)mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0].binary.Length / 3))).ToString(CultureInfo.InvariantCulture); mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0].cvParam = new Generated.CVParamType[3]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0].cvParam[0] = new Generated.CVParamType() { accession = "MS:1000514", name = "m/z array" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0].cvParam[1] = new Generated.CVParamType() { accession = "MS:1000523", name = "64-bit float" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[0].cvParam[2] = new Generated.CVParamType() { accession = "MS:1000576", name = "no compression" }; // Intensity Data mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1] = new Generated.BinaryDataArrayType() { binary = myMsDataFile.GetOneBasedScan(i).MassSpectrum.Get64BitYarray() }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1].encodedLength = (4 * Math.Ceiling(((double)mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1].binary.Length / 3))).ToString(CultureInfo.InvariantCulture); mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1].cvParam = new Generated.CVParamType[3]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1].cvParam[0] = new Generated.CVParamType() { accession = "MS:1000515", name = "intensity array" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1].cvParam[1] = new Generated.CVParamType() { accession = "MS:1000523", name = "64-bit float" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[1].cvParam[2] = new Generated.CVParamType() { accession = "MS:1000576", name = "no compression" }; if (myMsDataFile.GetOneBasedScan(i).NoiseData != null) { // mass mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2] = new Generated.BinaryDataArrayType() { binary = myMsDataFile.GetOneBasedScan(i).Get64BitNoiseDataMass() }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].encodedLength = (4 * Math.Ceiling(((double)mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].binary.Length / 3))).ToString(CultureInfo.InvariantCulture); mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].cvParam = new Generated.CVParamType[3]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].cvParam[0] = new Generated.CVParamType() { accession = "MS:1000786", name = "non-standard data array" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].cvParam[1] = new Generated.CVParamType() { accession = "MS:1000523", name = "64-bit float" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].cvParam[2] = new Generated.CVParamType() { accession = "MS:1000576", name = "no compression" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].userParam = new Generated.UserParamType[1]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[2].userParam[0] = new Generated.UserParamType() { name = "kelleherCustomType", value = "noise m/z" }; // noise mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3] = new Generated.BinaryDataArrayType() { binary = myMsDataFile.GetOneBasedScan(i).Get64BitNoiseDataNoise() }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].encodedLength = (4 * Math.Ceiling(((double)mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].binary.Length / 3))).ToString(CultureInfo.InvariantCulture); mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].cvParam = new Generated.CVParamType[3]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].cvParam[0] = new Generated.CVParamType() { accession = "MS:1000786", name = "non-standard data array" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].cvParam[1] = new Generated.CVParamType() { accession = "MS:1000523", name = "64-bit float" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].cvParam[2] = new Generated.CVParamType() { accession = "MS:1000576", name = "no compression" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].userParam = new Generated.UserParamType[1]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[3].userParam[0] = new Generated.UserParamType() { name = "kelleherCustomType", value = "noise baseline" }; // baseline mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4] = new Generated.BinaryDataArrayType() { binary = myMsDataFile.GetOneBasedScan(i).Get64BitNoiseDataBaseline() }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].encodedLength = (4 * Math.Ceiling(((double)mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].binary.Length / 3))).ToString(CultureInfo.InvariantCulture); mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].cvParam = new Generated.CVParamType[3]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].cvParam[0] = new Generated.CVParamType() { accession = "MS:1000786", name = "non-standard data array" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].cvParam[1] = new Generated.CVParamType() { accession = "MS:1000523", name = "64-bit float" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].cvParam[2] = new Generated.CVParamType() { accession = "MS:1000576", name = "no compression" }; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].userParam = new Generated.UserParamType[1]; mzML.run.spectrumList.spectrum[i - 1].binaryDataArrayList.binaryDataArray[4].userParam[0] = new Generated.UserParamType() { name = "kelleherCustomType", value = "noise intensity" }; } } if (writeIndexed) { throw new NotImplementedException("Writing indexed mzMLs not yet supported"); } else { using (TextWriter writer = new StreamWriter(outputFile)) { mzmlSerializer.Serialize(writer, mzML); } } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { string fieldNotUsed = "1"; if (!GlobalGuiSettings.CheckTaskSettingsValidity(PrecusorMsTlTextBox.Text, productMassToleranceTextBox.Text, missedCleavagesTextBox.Text, maxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, maxThreadsTextBox.Text, minScoreAllowed.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed, TopNPeaksTextBox.Text, MinRatioTextBox.Text, null, null, numberOfDatabaseSearchesTextBox.Text, TxtBoxMaxModPerPep.Text, fieldNotUsed, fieldNotUsed)) { return; } DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()]; DissociationType childDissociationType = DissociationType.Unknown; if (ChildScanDissociationTypeComboBox.SelectedItem.ToString() != "Null") { childDissociationType = GlobalVariables.AllSupportedDissociationTypes[ChildScanDissociationTypeComboBox.SelectedItem.ToString()]; } CustomFragmentationWindow.Close(); if (RbtOGlycoSearch.IsChecked.Value) { TheTask._glycoSearchParameters.GlycoSearchType = EngineLayer.GlycoSearch.GlycoSearchType.OGlycanSearch; } else if (RbtNGlycoSearch.IsChecked.Value) { TheTask._glycoSearchParameters.GlycoSearchType = EngineLayer.GlycoSearch.GlycoSearchType.NGlycanSearch; } else if (Rbt_N_O_GlycoSearch.IsChecked.Value) { TheTask._glycoSearchParameters.GlycoSearchType = EngineLayer.GlycoSearch.GlycoSearchType.N_O_GlycanSearch; } TheTask._glycoSearchParameters.OGlycanDatabasefile = CmbOGlycanDatabase.SelectedItem.ToString(); TheTask._glycoSearchParameters.NGlycanDatabasefile = CmbNGlycanDatabase.SelectedItem.ToString(); TheTask._glycoSearchParameters.GlycoSearchTopNum = int.Parse(txtTopNum.Text, CultureInfo.InvariantCulture); TheTask._glycoSearchParameters.MaximumOGlycanAllowed = int.Parse(TbMaxOGlycanNum.Text, CultureInfo.InvariantCulture); TheTask._glycoSearchParameters.OxoniumIonFilt = CkbOxoniumIonFilt.IsChecked.Value; if (CheckBoxDecoy.IsChecked.Value) { if (RadioButtonReverseDecoy.IsChecked.Value) { TheTask._glycoSearchParameters.DecoyType = DecoyType.Reverse; } else //if (radioButtonSlideDecoy.IsChecked.Value) { TheTask._glycoSearchParameters.DecoyType = DecoyType.Slide; } } else { TheTask._glycoSearchParameters.DecoyType = DecoyType.None; } Protease protease = (Protease)proteaseComboBox.SelectedItem; int MaxMissedCleavages = string.IsNullOrEmpty(missedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(missedCleavagesTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MinPeptideLength = (int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MaxPeptideLength = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int MaxModificationIsoforms = (int.Parse(maxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture)); int MaxModPerPep = (int.Parse(TxtBoxMaxModPerPep.Text, CultureInfo.InvariantCulture)); InitiatorMethionineBehavior InitiatorMethionineBehavior = ((InitiatorMethionineBehavior)initiatorMethionineBehaviorComboBox.SelectedIndex); DigestionParams digestionParamsToSave = new DigestionParams( protease: protease.Name, maxMissedCleavages: MaxMissedCleavages, minPeptideLength: MinPeptideLength, maxPeptideLength: MaxPeptideLength, maxModificationIsoforms: MaxModificationIsoforms, maxModsForPeptides: MaxModPerPep, initiatorMethionineBehavior: InitiatorMethionineBehavior); Tolerance ProductMassTolerance; if (productMassToleranceComboBox.SelectedIndex == 0) { ProductMassTolerance = new AbsoluteTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { ProductMassTolerance = new PpmTolerance(double.Parse(productMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } Tolerance PrecursorMassTolerance; if (cbbPrecusorMsTl.SelectedIndex == 0) { PrecursorMassTolerance = new AbsoluteTolerance(double.Parse(PrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture)); } else { PrecursorMassTolerance = new PpmTolerance(double.Parse(PrecusorMsTlTextBox.Text, CultureInfo.InvariantCulture)); } var listOfModsVariable = new List <(string, string)>(); foreach (var heh in VariableModTypeForTreeViewObservableCollection) { listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } var listOfModsFixed = new List <(string, string)>(); foreach (var heh in FixedModTypeForTreeViewObservableCollection) { listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } CommonParameters commonParamsToSave = new CommonParameters( precursorMassTolerance: PrecursorMassTolerance, taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "GlycoSearchTask", productMassTolerance: ProductMassTolerance, doPrecursorDeconvolution: deconvolutePrecursors.IsChecked.Value, useProvidedPrecursorInfo: useProvidedPrecursor.IsChecked.Value, digestionParams: digestionParamsToSave, trimMs1Peaks: trimMs1.IsChecked.Value, trimMsMsPeaks: trimMsMs.IsChecked.Value, numberOfPeaksToKeepPerWindow: int.Parse(TopNPeaksTextBox.Text), minimumAllowedIntensityRatioToBasePeak: double.Parse(MinRatioTextBox.Text, CultureInfo.InvariantCulture), dissociationType: dissociationType, ms2childScanDissociationType: childDissociationType, scoreCutoff: double.Parse(minScoreAllowed.Text, CultureInfo.InvariantCulture), totalPartitions: int.Parse(numberOfDatabaseSearchesTextBox.Text, CultureInfo.InvariantCulture), maxThreadsToUsePerFile: int.Parse(maxThreadsTextBox.Text, CultureInfo.InvariantCulture), listOfModsVariable: listOfModsVariable, listOfModsFixed: listOfModsFixed, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down"); TheTask.CommonParameters = commonParamsToSave; DialogResult = true; }
private void SaveButton_Click(object sender, RoutedEventArgs e) { string fieldNotUsed = "1"; if (!GlobalGuiSettings.CheckTaskSettingsValidity(PrecursorMassToleranceTextBox.Text, ProductMassToleranceTextBox.Text, MissedCleavagesTextBox.Text, MaxModificationIsoformsTextBox.Text, MinPeptideLengthTextBox.Text, MaxPeptideLengthTextBox.Text, MaxThreadsTextBox.Text, MinScoreAllowed.Text, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed, fieldNotUsed, null, null, fieldNotUsed, MaxModsPerPeptideTextBox.Text, fieldNotUsed, fieldNotUsed)) { return; } Protease protease = (Protease)ProteaseComboBox.SelectedItem; int maxMissedCleavages = string.IsNullOrEmpty(MissedCleavagesTextBox.Text) ? int.MaxValue : (int.Parse(MissedCleavagesTextBox.Text, CultureInfo.InvariantCulture)); int minPeptideLength = int.Parse(MinPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxPeptideLength = string.IsNullOrEmpty(MaxPeptideLengthTextBox.Text) ? int.MaxValue : (int.Parse(MaxPeptideLengthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture)); int minVariantDepth = int.Parse(MinVariantDepthTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxHeterozygousVariants = int.Parse(MaxHeterozygousVariantsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture); int maxModificationIsoforms = int.Parse(MaxModificationIsoformsTextBox.Text, CultureInfo.InvariantCulture); int maxModsPerPeptide = int.Parse(MaxModsPerPeptideTextBox.Text, CultureInfo.InvariantCulture); DissociationType dissociationType = GlobalVariables.AllSupportedDissociationTypes[DissociationTypeComboBox.SelectedItem.ToString()]; CustomFragmentationWindow.Close(); DigestionParams digestionParamsToSave = new DigestionParams( protease: protease.Name, maxMissedCleavages: maxMissedCleavages, minPeptideLength: minPeptideLength, maxPeptideLength: maxPeptideLength, maxModificationIsoforms: maxModificationIsoforms, maxModsForPeptides: maxModsPerPeptide); var listOfModsVariable = new List <(string, string)>(); foreach (var heh in VariableModTypeForTreeViewObservableCollection) { listOfModsVariable.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } if (!GlobalGuiSettings.VariableModCheck(listOfModsVariable)) { return; } var listOfModsFixed = new List <(string, string)>(); foreach (var heh in FixedModTypeForTreeViewObservableCollection) { listOfModsFixed.AddRange(heh.Children.Where(b => b.Use).Select(b => (b.Parent.DisplayName, b.ModName))); } Tolerance productMassTolerance; if (ProductMassToleranceComboBox.SelectedIndex == 0) { productMassTolerance = new AbsoluteTolerance(double.Parse(ProductMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { productMassTolerance = new PpmTolerance(double.Parse(ProductMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } Tolerance precursorMassTolerance; if (PrecursorMassToleranceComboBox.SelectedIndex == 0) { precursorMassTolerance = new AbsoluteTolerance(double.Parse(PrecursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } else { precursorMassTolerance = new PpmTolerance(double.Parse(PrecursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture)); } bool parseMaxThreadsPerFile = int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) <= Environment.ProcessorCount && int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) > 0; //the below parameters are optimized for top-down but do not exist in the GUI as of Nov. 13, 2019 if (((Protease)ProteaseComboBox.SelectedItem).Name.Contains("top-down")) { CommonParameters commonParamsToSave = new CommonParameters( taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "CalibrateTask", maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile, digestionParams: digestionParamsToSave, dissociationType: dissociationType, scoreCutoff: double.Parse(MinScoreAllowed.Text, CultureInfo.InvariantCulture), listOfModsFixed: listOfModsFixed, listOfModsVariable: listOfModsVariable, productMassTolerance: productMassTolerance, precursorMassTolerance: precursorMassTolerance, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down", minVariantDepth: minVariantDepth, maxHeterozygousVariants: maxHeterozygousVariants, useProvidedPrecursorInfo: false, //Updated deconvolutionMaxAssumedChargeState: 60, //Updated trimMsMsPeaks: false); //Updated TheTask.CommonParameters = commonParamsToSave; } else //bottom-up { CommonParameters commonParamsToSave = new CommonParameters( taskDescriptor: OutputFileNameTextBox.Text != "" ? OutputFileNameTextBox.Text : "CalibrateTask", maxThreadsToUsePerFile: parseMaxThreadsPerFile ? int.Parse(MaxThreadsTextBox.Text, CultureInfo.InvariantCulture) : new CommonParameters().MaxThreadsToUsePerFile, digestionParams: digestionParamsToSave, dissociationType: dissociationType, scoreCutoff: double.Parse(MinScoreAllowed.Text, CultureInfo.InvariantCulture), listOfModsFixed: listOfModsFixed, listOfModsVariable: listOfModsVariable, productMassTolerance: productMassTolerance, precursorMassTolerance: precursorMassTolerance, assumeOrphanPeaksAreZ1Fragments: protease.Name != "top-down", minVariantDepth: minVariantDepth, maxHeterozygousVariants: maxHeterozygousVariants); TheTask.CommonParameters = commonParamsToSave; } TheTask.CalibrationParameters.WriteIndexedMzml = writeIndexMzmlCheckbox.IsChecked.Value; DialogResult = true; }
private static IMzmlScan GetMsDataOneBasedScanFromConnection(Generated.mzMLType _mzMLConnection, int oneBasedSpectrumNumber) { double[] masses = null; double[] intensities = null; foreach (Generated.BinaryDataArrayType binaryData in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].binaryDataArrayList.binaryDataArray) { bool compressed = false; bool mzArray = false; bool intensityArray = false; bool is32bit = true; foreach (Generated.CVParamType cv in binaryData.cvParam) { compressed |= cv.accession.Equals(_zlibCompression); is32bit &= !cv.accession.Equals(_64bit); is32bit |= cv.accession.Equals(_32bit); mzArray |= cv.accession.Equals(_mzArray); intensityArray |= cv.accession.Equals(_intensityArray); } double[] data = ConvertBase64ToDoubles(binaryData.binary, compressed, is32bit); if (mzArray) { masses = data; } if (intensityArray) { intensities = data; } } var ok = new MzmlMzSpectrum(masses, intensities, false); int? msOrder = null; bool? isCentroid = null; Polarity polarity = Polarity.Unknown; double tic = double.NaN; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].cvParam) { if (cv.accession.Equals(_msnOrderAccession)) { msOrder = int.Parse(cv.value); } if (cv.accession.Equals(_centroidSpectrum)) { isCentroid = true; } if (cv.accession.Equals(_profileSpectrum)) { isCentroid = false; } if (cv.accession.Equals(_totalIonCurrent)) { tic = double.Parse(cv.value); } polarityDictionary.TryGetValue(cv.accession, out polarity); } double rtInMinutes = double.NaN; string scanFilter = null; double?injectionTime = null; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].scanList.scan[0].cvParam != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].scanList.scan[0].cvParam) { if (cv.accession.Equals(_retentionTime)) { rtInMinutes = double.Parse(cv.value); if (cv.unitName == "second") { rtInMinutes /= 60; } } if (cv.accession.Equals(_filterString)) { scanFilter = cv.value; } if (cv.accession.Equals(_ionInjectionTime)) { injectionTime = double.Parse(cv.value); } } } double high = double.NaN; double low = double.NaN; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].scanList.scan[0].scanWindowList != null) { foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].scanList.scan[0].scanWindowList.scanWindow[0].cvParam) { if (cv.accession.Equals(_scanWindowLowerLimit)) { low = double.Parse(cv.value); } if (cv.accession.Equals(_scanWindowUpperLimit)) { high = double.Parse(cv.value); } } } if (msOrder.Value == 1) { return(new MzmlScan(oneBasedSpectrumNumber, ok, msOrder.Value, isCentroid.Value, polarity, rtInMinutes, new MzRange(low, high), scanFilter, GetMzAnalyzer(_mzMLConnection, scanFilter), tic, injectionTime)); } double selectedIonMz = double.NaN; int? selectedIonCharge = null; double?selectedIonIntensity = null; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].precursorList.precursor[0].selectedIonList.selectedIon[0].cvParam) { if (cv.accession.Equals(_selectedIonMz)) { selectedIonMz = double.Parse(cv.value); } if (cv.accession.Equals(_precursorCharge)) { selectedIonCharge = int.Parse(cv.value); } if (cv.accession.Equals(_peakIntensity)) { selectedIonIntensity = double.Parse(cv.value); } } double?isolationMz = null; double lowIsolation = double.NaN; double highIsolation = double.NaN; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].precursorList.precursor[0].isolationWindow.cvParam) { if (cv.accession.Equals(_isolationWindowTargetMZ)) { isolationMz = double.Parse(cv.value); } if (cv.accession.Equals(_isolationWindowLowerOffset)) { lowIsolation = double.Parse(cv.value); } if (cv.accession.Equals(_isolationWindowUpperOffset)) { highIsolation = double.Parse(cv.value); } } DissociationType dissociationType = DissociationType.Unknown; foreach (Generated.CVParamType cv in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].precursorList.precursor[0].activation.cvParam) { dissociationDictionary.TryGetValue(cv.accession, out dissociationType); } double?monoisotopicMz = null; if (_mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].scanList.scan[0].userParam != null) { foreach (var userParam in _mzMLConnection.run.spectrumList.spectrum[oneBasedSpectrumNumber - 1].scanList.scan[0].userParam) { if (userParam.name.EndsWith("Monoisotopic M/Z:")) { monoisotopicMz = double.Parse(userParam.value); } } } return(new MzmlScanWithPrecursor(oneBasedSpectrumNumber, ok, msOrder.Value, isCentroid.Value, polarity, rtInMinutes, new MzRange(low, high), scanFilter, GetMzAnalyzer(_mzMLConnection, scanFilter), tic, selectedIonMz, selectedIonCharge, selectedIonIntensity, isolationMz.Value, lowIsolation + highIsolation, dissociationType, GetOneBasedPrecursorScanNumber(_mzMLConnection, oneBasedSpectrumNumber), monoisotopicMz, injectionTime)); }