public PeptideGroupDocNode(PeptideGroup id, Annotations annotations, ProteinMetadata proteinMetadata, PeptideDocNode[] children, bool autoManageChildren) : base(id, annotations, children, autoManageChildren) { if (Equals(id.Name, proteinMetadata.Name)) proteinMetadata = proteinMetadata.ChangeName(null); // Make it clear that the name hasn't been altered if (Equals(id.Description, proteinMetadata.Description)) proteinMetadata = proteinMetadata.ChangeDescription(null); // Make it clear that the description hasn't been altered _proteinMetadata = proteinMetadata; }
public SrmDocument ConvertToSmallMolecules(SrmDocument document, ConvertToSmallMoleculesMode mode = ConvertToSmallMoleculesMode.formulas, bool invertCharges = false, bool ignoreDecoys=false) { if (mode == ConvertToSmallMoleculesMode.none) return document; var newdoc = new SrmDocument(document.Settings); var note = new Annotations(TestingConvertedFromProteomic, null, 1); // Mark this as a testing node so we don't sort it newdoc = (SrmDocument)newdoc.ChangeIgnoreChangingChildren(true); // Retain copied results foreach (var peptideGroupDocNode in document.MoleculeGroups) { if (!peptideGroupDocNode.IsProteomic) { newdoc = (SrmDocument)newdoc.Add(peptideGroupDocNode); // Already a small molecule } else { var newPeptideGroup = new PeptideGroup(); var newPeptideGroupDocNode = new PeptideGroupDocNode(newPeptideGroup, peptideGroupDocNode.Annotations.Merge(note), peptideGroupDocNode.Name, peptideGroupDocNode.Description, new PeptideDocNode[0], peptideGroupDocNode.AutoManageChildren); foreach (var mol in peptideGroupDocNode.Molecules) { var peptideSequence = mol.Peptide.Sequence; // Create a PeptideDocNode with the presumably baseline charge and label var precursorCharge = (mol.TransitionGroups.Any() ? mol.TransitionGroups.First().TransitionGroup.PrecursorCharge : 0) * (invertCharges ? -1 : 1); var isotopeLabelType = mol.TransitionGroups.Any() ? mol.TransitionGroups.First().TransitionGroup.LabelType : IsotopeLabelType.light; var moleculeCustomIon = ConvertToSmallMolecule(mode, document, mol, precursorCharge, isotopeLabelType); var precursorCustomIon = moleculeCustomIon; var newPeptide = new Peptide(moleculeCustomIon); var newPeptideDocNode = new PeptideDocNode(newPeptide, newdoc.Settings, null, null, null, null, mol.ExplicitRetentionTime, note, mol.Results, new TransitionGroupDocNode[0], mol.AutoManageChildren); foreach (var transitionGroupDocNode in mol.TransitionGroups) { if (transitionGroupDocNode.IsDecoy) { if (ignoreDecoys) continue; throw new Exception("There is no translation from decoy to small molecules"); // Not L10N } if (transitionGroupDocNode.TransitionGroup.PrecursorCharge != Math.Abs(precursorCharge) || !Equals(isotopeLabelType, transitionGroupDocNode.TransitionGroup.LabelType)) { // Different charges or labels mean different ion formulas precursorCharge = transitionGroupDocNode.TransitionGroup.PrecursorCharge * (invertCharges ? -1 : 1); isotopeLabelType = transitionGroupDocNode.TransitionGroup.LabelType; precursorCustomIon = ConvertToSmallMolecule(mode, document, mol, precursorCharge, isotopeLabelType); } var newTransitionGroup = new TransitionGroup(newPeptide, precursorCustomIon, precursorCharge, isotopeLabelType); // Remove any library info, since for the moment at least small molecules don't support this and it won't roundtrip var resultsNew = RemoveTransitionGroupChromInfoLibraryInfo(transitionGroupDocNode); var newTransitionGroupDocNode = new TransitionGroupDocNode(newTransitionGroup, transitionGroupDocNode.Annotations.Merge(note), document.Settings, null, null, transitionGroupDocNode.ExplicitValues, resultsNew, null, transitionGroupDocNode.AutoManageChildren); var mzShift = invertCharges ? 2.0 * BioMassCalc.MassProton : 0; // We removed hydrogen rather than added Assume.IsTrue((Math.Abs(newTransitionGroupDocNode.PrecursorMz + mzShift - transitionGroupDocNode.PrecursorMz) - Math.Abs(transitionGroupDocNode.TransitionGroup.PrecursorCharge * BioMassCalc.MassElectron)) <= 1E-5); foreach (var transition in transitionGroupDocNode.Transitions) { double mass = 0; var transitionCharge = transition.Transition.Charge * (invertCharges ? -1 : 1); var ionType = IonType.custom; CustomIon transitionCustomIon; double mzShiftTransition = 0; if (transition.Transition.IonType == IonType.precursor) { ionType = IonType.precursor; transitionCustomIon = new DocNodeCustomIon(precursorCustomIon.Formula, string.IsNullOrEmpty(precursorCustomIon.Formula) ? precursorCustomIon.MonoisotopicMass : (double?) null, string.IsNullOrEmpty(precursorCustomIon.Formula) ? precursorCustomIon.AverageMass : (double?) null, SmallMoleculeNameFromPeptide(peptideSequence, transitionCharge)); mzShiftTransition = invertCharges ? 2.0 * BioMassCalc.MassProton : 0; // We removed hydrogen rather than added } else if (transition.Transition.IonType == IonType.custom) { transitionCustomIon = transition.Transition.CustomIon; mass = transitionCustomIon.MonoisotopicMass; } else { // TODO - try to get fragment formula? mass = BioMassCalc.CalculateIonMassFromMz(transition.Mz, transition.Transition.Charge); transitionCustomIon = new DocNodeCustomIon(mass, mass,// We can't really get at mono vs average mass from m/z, but for test purposes this is fine transition.Transition.FragmentIonName); } if (mode == ConvertToSmallMoleculesMode.masses_and_names) { // Discard the formula if we're testing the use of mass-with-names (for matching in ratio calcs) target specification transitionCustomIon = new DocNodeCustomIon(transitionCustomIon.MonoisotopicMass, transitionCustomIon.AverageMass, transition.Transition.FragmentIonName); } else if (mode == ConvertToSmallMoleculesMode.masses_only) { // Discard the formula and name if we're testing the use of mass-only target specification transitionCustomIon = new DocNodeCustomIon(transitionCustomIon.MonoisotopicMass, transitionCustomIon.AverageMass); } var newTransition = new Transition(newTransitionGroup, ionType, null, transition.Transition.MassIndex, transition.Transition.Charge * (invertCharges ? -1 : 1), null, transitionCustomIon); if (ionType == IonType.precursor) { mass = document.Settings.GetFragmentMass(transitionGroupDocNode.TransitionGroup.LabelType, null, newTransition, newTransitionGroupDocNode.IsotopeDist); } var newTransitionDocNode = new TransitionDocNode(newTransition, transition.Annotations.Merge(note), null, mass, transition.IsotopeDistInfo, null, transition.Results); Assume.IsTrue((Math.Abs(newTransitionDocNode.Mz + mzShiftTransition - transition.Mz) - Math.Abs(transitionGroupDocNode.TransitionGroup.PrecursorCharge * BioMassCalc.MassElectron)) <= 1E-5, String.Format("unexpected mz difference {0}-{1}={2}", newTransitionDocNode.Mz , transition.Mz, newTransitionDocNode.Mz - transition.Mz)); // Not L10N newTransitionGroupDocNode = (TransitionGroupDocNode)newTransitionGroupDocNode.Add(newTransitionDocNode); } if (newPeptideDocNode != null) newPeptideDocNode = (PeptideDocNode)newPeptideDocNode.Add(newTransitionGroupDocNode); } newPeptideGroupDocNode = (PeptideGroupDocNode)newPeptideGroupDocNode.Add(newPeptideDocNode); } newdoc = (SrmDocument)newdoc.Add(newPeptideGroupDocNode); } } // No retention time prediction for small molecules (yet?) newdoc = newdoc.ChangeSettings(newdoc.Settings.ChangePeptideSettings(newdoc.Settings.PeptideSettings.ChangePrediction( newdoc.Settings.PeptideSettings.Prediction.ChangeRetentionTime(null)))); return newdoc; }
public EditPepModsDlg(SrmSettings settings, PeptideDocNode nodePeptide) { DocSettings = settings; NodePeptide = nodePeptide; ExplicitMods = nodePeptide.ExplicitMods; InitializeComponent(); Icon = Resources.Skyline; SuspendLayout(); ComboBox comboStaticLast = null; List<ComboBox> listComboHeavyLast = null; List<Label> listLabelHeavyLast = null; Label labelAALast = null; string seq = nodePeptide.Peptide.Sequence; var modsDoc = DocSettings.PeptideSettings.Modifications; _listLabelTypeHeavy.AddRange(from typedMods in modsDoc.GetHeavyModifications() select typedMods.LabelType); for (int i = 0; i < seq.Length; i++) { char aa = seq[i]; int row = i + 1; if (comboStaticLast == null || listComboHeavyLast == null) // ReSharper { labelAALast = labelAA1; comboStaticLast = comboStatic1; foreach (var labelType in _listLabelTypeHeavy) { if (listComboHeavyLast == null) { listComboHeavyLast = new List<ComboBox> { comboHeavy1_1 }; listLabelHeavyLast = new List<Label> { labelHeavy1 }; labelHeavy1.Text = GetIsotopeLabelText(labelType); } else { var comboHeavyLast = listComboHeavyLast[listComboHeavyLast.Count - 1]; panelMain.Controls.Add(comboHeavyLast = new ComboBox { Name = GetHeavyName(row, labelType.SortOrder), Left = comboHeavyLast.Right + HSPACE, Top = comboHeavyLast.Top, Size = comboHeavyLast.Size, TabIndex = comboHeavyLast.TabIndex + 1 }); listComboHeavyLast.Add(comboHeavyLast); var labelHeavyLast = listLabelHeavyLast[listLabelHeavyLast.Count - 1]; panelMain.Controls.Add(labelHeavyLast = new Label { Text = GetIsotopeLabelText(labelType), Name = GetIsotopeLabelName(labelType.SortOrder), Left = comboHeavyLast.Left, Top = labelHeavyLast.Top, TabIndex = labelHeavyLast.TabIndex + 1 }); listLabelHeavyLast.Add(labelHeavyLast); } } } else { int controlsPerRow = 2 + listComboHeavyLast.Count; int top = Top = comboStaticLast.Bottom + VSPACE; panelMain.Controls.Add(labelAALast = new Label { Name = ("labelAA" + row), // Not L10N AutoSize = true, Font = labelAA1.Font, Left = labelAA1.Left, Top = top + (labelAALast.Top - comboStaticLast.Top), Size = labelAA1.Size, TabIndex = labelAALast.TabIndex + controlsPerRow }); panelMain.Controls.Add(comboStaticLast = new ComboBox { Name = GetStaticName(row), Left = comboStaticLast.Left, Top = top, Size = comboStaticLast.Size, TabIndex = comboStaticLast.TabIndex + controlsPerRow }); foreach (var labelType in _listLabelTypeHeavy) { int col = labelType.SortOrder - 1; var comboHeavyLast = listComboHeavyLast[col]; panelMain.Controls.Add(comboHeavyLast = new ComboBox { Name = GetHeavyName(row, labelType.SortOrder), Left = comboHeavyLast.Left, Top = top, Size = comboHeavyLast.Size, TabIndex = comboHeavyLast.TabIndex + controlsPerRow }); listComboHeavyLast[col] = comboHeavyLast; } } // Store static modification combos and selected indexes _listSelectedIndexStatic.Add(-1); _listComboStatic.Add(InitModificationCombo(comboStaticLast, i, IsotopeLabelType.light)); // Store heavy moficiation combos and selected indexes if (listComboHeavyLast != null) // ReSharper { for (int j = 0; j < _listLabelTypeHeavy.Count; j++) { while (_listListComboHeavy.Count <= j) { _listListSelectedIndexHeavy.Add(new List<int>()); _listListComboHeavy.Add(new List<ComboBox>()); } var comboHeavyLast = listComboHeavyLast[j]; var labelType = _listLabelTypeHeavy[j]; _listListSelectedIndexHeavy[j].Add(-1); _listListComboHeavy[j].Add(InitModificationCombo(comboHeavyLast, i, labelType)); } } // Store amino acid labels labelAALast.Text = aa.ToString(CultureInfo.InvariantCulture); _listLabelAA.Add(labelAALast); } for (int i = 0; i < _listLabelAA.Count; i++) { UpdateAminoAcidLabel(i); } if (comboStaticLast != null && comboStaticLast != comboStatic1) { // Increase width by the delta from the left edges of the first and last // heavy combo box columns int widthDiff = _listListComboHeavy[_listListComboHeavy.Count - 1][0].Left - _listListComboHeavy[0][0].Left; Width += widthDiff; // Increase height by the delta from the bottom edges of the first and last // amino acid labels if (comboStatic1 != null) // ReSharper { int heightDiff = comboStaticLast.Bottom - comboStatic1.Bottom; heightDiff += comboStatic1.Bottom - panelMain.Height; Height += heightDiff; } if (listComboHeavyLast != null) // ReSharper btnOk.TabIndex = listComboHeavyLast[listComboHeavyLast.Count - 1].TabIndex + 1; btnCancel.TabIndex = btnOk.TabIndex + 1; } ResumeLayout(true); }
private void ExportGroupNode(PeptideDocNode peptideNode, TransitionGroupDocNode groupNode, ChromatogramSet chromatograms, ICollection<string> filesToExport, ICollection<ChromSource> chromSources, TextWriter writer, CultureInfo cultureInfo) { string peptideModifiedSequence = _settings.GetDisplayName(peptideNode); int precursorCharge = groupNode.TransitionGroup.PrecursorCharge; string labelType = groupNode.TransitionGroup.LabelType.Name; var filesInChrom = chromatograms.MSDataFilePaths.Select(path=>path.GetFileName()).ToList(); // Don't load the chromatogram group if none of its files are being exported if (!filesInChrom.Where(filesToExport.Contains).Any()) return; ChromatogramGroupInfo[] arrayChromInfo; if (!_measuredResults.TryLoadChromatogram(chromatograms, peptideNode, groupNode, _matchTolerance, true, out arrayChromInfo)) { // TODO: Determine if this is a real error or just a missing node for this file // If the former throw an exception, if the latter continue return; } if (arrayChromInfo.Length != chromatograms.FileCount) { throw new InvalidDataException(string.Format(Resources.ChromatogramExporter_ExportGroupNode_One_or_more_missing_chromatograms_at_charge_state__0__of__1_, precursorCharge, peptideModifiedSequence)); } foreach (var chromGroupInfo in arrayChromInfo) { string fileName = chromGroupInfo.FilePath.GetFileName(); // Skip the files that have not been selected for export if (!filesToExport.Contains(fileName)) continue; foreach (var nodeTran in groupNode.Transitions) { // TODO: Check a source attribute on the transition chrom info bool isMs1 = nodeTran.Transition.IsPrecursor() && !nodeTran.HasLoss; if (isMs1 && !chromSources.Contains(ChromSource.ms1)) continue; if (!isMs1 && !chromSources.Contains(ChromSource.fragment)) continue; int productCharge = nodeTran.Transition.Charge; float productMz = (float)nodeTran.Mz; var chromInfo = chromGroupInfo.GetTransitionInfo(productMz, _matchTolerance); // Sometimes a transition in the transition group does not have results for a particular file // If this happens just skip it for that file if (chromInfo == null) continue; IList<float> times = chromInfo.Times; IList<float> intensities = chromInfo.Intensities; if (times.Count != intensities.Count || intensities.Count == 0) { throw new InvalidDataException(string.Format(Resources.ChromatogramExporter_Export_Bad_chromatogram_data_for_charge__0__state_of_peptide__1_, precursorCharge, peptideModifiedSequence)); } float tic = CalculateTic(times, intensities); string[] fieldArray = { fileName, peptideModifiedSequence, System.Convert.ToString(precursorCharge, cultureInfo), System.Convert.ToString(productMz, cultureInfo), nodeTran.GetFragmentIonName(CultureInfo.InvariantCulture), System.Convert.ToString(productCharge, cultureInfo), labelType, System.Convert.ToString(tic, cultureInfo) }; FormatChromLine(writer, fieldArray, times, intensities, cultureInfo); } } }
protected abstract bool IsMatch(string seq, PeptideDocNode nodePep, out TransitionGroupDocNode nodeGroup);
public PeptideDocNode CreateDocNodeFromMatches(PeptideDocNode nodePep, IEnumerable<AAModInfo> infos) { bool hasHeavy; return CreateDocNodeFromMatches(nodePep, infos, true, out hasHeavy); }
// ReSharper restore SuggestBaseTypeForParameter // ReSharper disable SuggestBaseTypeForParameter private static void AssertPrecursorMzAreEqaul(PeptideDocNode nodePep1, int index1, PeptideDocNode nodePep2, int index2) { Assert.AreEqual(((TransitionGroupDocNode)nodePep1.Children[index1]).PrecursorMz, ((TransitionGroupDocNode)nodePep2.Children[index2]).PrecursorMz); }
private static int GetTypeImageIndex(PeptideDocNode nodePep) { if (nodePep.IsDecoy) { return (int) (nodePep.HasLibInfo ? SequenceTree.ImageId.peptide_lib_decoy : SequenceTree.ImageId.peptide_decoy); } if (!nodePep.IsProteomic) { return (int)SequenceTree.ImageId.molecule; } if (string.Equals(nodePep.GlobalStandardType, PeptideDocNode.STANDARD_TYPE_IRT)) { return (int) (nodePep.HasLibInfo ? SequenceTree.ImageId.peptide_irt_lib : SequenceTree.ImageId.peptide_irt); } if (string.Equals(nodePep.GlobalStandardType, PeptideDocNode.STANDARD_TYPE_QC)) { return (int)(nodePep.HasLibInfo ? SequenceTree.ImageId.peptide_qc_lib : SequenceTree.ImageId.peptide_qc); } if (string.Equals(nodePep.GlobalStandardType, PeptideDocNode.STANDARD_TYPE_NORMALIZAITON)) { return (int)(nodePep.HasLibInfo ? SequenceTree.ImageId.peptide_standard_lib : SequenceTree.ImageId.peptide_standard); } return (int)(nodePep.HasLibInfo ? SequenceTree.ImageId.peptide_lib : SequenceTree.ImageId.peptide); }
public static void DrawPeptideText(PeptideDocNode nodePep, SrmSettings settings, IEnumerable<TextSequence> textSequences, Graphics g, Rectangle bounds, ModFontHolder fonts, Color foreColor, Color backColor) { if (textSequences == null) textSequences = CreateTextSequences(nodePep, settings, GetLabel(nodePep, string.Empty), g, fonts); Rectangle rectDraw = new Rectangle(0, bounds.Y, 0, bounds.Height); foreach (var textSequence in textSequences) { rectDraw.X = textSequence.Position + bounds.X + TreeViewMS.PADDING; rectDraw.Width = textSequence.Width; // Use selection highlight color, if the background is highlight. if (backColor != SystemColors.Highlight) foreColor = textSequence.Color; TextRenderer.DrawText(g, textSequence.Text, textSequence.Font, rectDraw, foreColor, backColor, FORMAT_TEXT_SEQUENCE); } }
public static string DisplayText(PeptideDocNode node, DisplaySettings settings) { return GetLabel(node, string.Empty); }
public static TextSequence[] CreateTextSequences(PeptideDocNode nodePep, SrmSettings settings, string label, IDeviceContext g, ModFontHolder fonts) { // Store text and font information for all label types bool heavyMods = false; var listTypeSequences = new List<TextSequence> { CreateTypeTextSequence(nodePep, settings, IsotopeLabelType.light, fonts) }; foreach (var labelType in settings.PeptideSettings.Modifications.GetHeavyModificationTypes()) { // Only color for the label types actually measured in this peptide if (!nodePep.HasChildType(labelType)) continue; var textSequence = CreateTypeTextSequence(nodePep, settings, labelType, fonts); listTypeSequences.Add(textSequence); heavyMods = (heavyMods || textSequence != null); } // Calculate text sequence values for the peptide display string var listTextSequences = new List<TextSequence>(); if (nodePep.Peptide.IsCustomIon) listTextSequences.Add(CreatePlainTextSequence(nodePep.CustomIon.DisplayName, fonts)); // If no modifications, use a single plain text sequence else if (!heavyMods && !listTypeSequences[0].Text.Contains("[")) // Not L10N: For identifying modifications listTextSequences.Add(CreatePlainTextSequence(label, fonts)); else { string pepSequence = nodePep.Peptide.Sequence; int startPep = label.IndexOf(pepSequence, StringComparison.Ordinal); int endPep = startPep + pepSequence.Length; // Add prefix plain-text if necessary if (startPep > 0) { string prefix = label.Substring(0, startPep); listTextSequences.Add(CreatePlainTextSequence(prefix, fonts)); } // Enumerate amino acid characters coallescing their font information // into text sequences. var prevCharFont = new CharFont('.', fonts.Plain, Color.Black); // Not L10N: Amino acid format var indexes = new int[listTypeSequences.Count]; CharFont charFont; var sb = new StringBuilder(); while ((charFont = GetCharFont(indexes, listTypeSequences, fonts)) != null) { if (!charFont.IsSameDisplay(prevCharFont) && sb.Length > 0) { listTextSequences.Add(CreateTextSequence(sb, prevCharFont)); sb.Remove(0, sb.Length); } sb.Append(charFont.Character); prevCharFont = charFont; } // Add the last segment if (sb.Length > 0) listTextSequences.Add(CreateTextSequence(sb, prevCharFont)); // Add suffix plain-text if necessary if (endPep < label.Length) { string suffix = label.Substring(endPep); listTextSequences.Add(CreatePlainTextSequence(suffix, fonts)); } } if (g != null) { // Calculate placement for each text sequence int textRectWidth = 0; foreach (var textSequence in listTextSequences) { Size sizeMax = new Size(int.MaxValue, int.MaxValue); textSequence.Position = textRectWidth; textSequence.Width = TextRenderer.MeasureText(g, textSequence.Text, textSequence.Font, sizeMax, FORMAT_TEXT_SEQUENCE). Width; textRectWidth += textSequence.Width; } } return listTextSequences.ToArray(); }
private static double GetPrecursorMz(PeptideDocNode nodePep, int iChild) { return ((TransitionGroupDocNode)nodePep.Children[iChild]).PrecursorMz; }
// ReSharper restore SuggestBaseTypeForParameter // ReSharper disable SuggestBaseTypeForParameter private bool IsLabelTypeRequired(PeptideDocNode nodePep, TransitionGroupDocNode nodeGroup, IEnumerable<TransitionGroupDocNode> listGroups) { // If not adding a label type, or this precursor is already the label type being added, // then no further work is required if (!AddLabelType || RefineLabelType == null || Equals(RefineLabelType, nodeGroup.TransitionGroup.LabelType)) return false; // If either the peptide or the list of new groups already contains the // label type to be added, then do not add foreach (TransitionGroupDocNode nodeGroupChild in nodePep.Children) { if (nodeGroupChild.TransitionGroup.PrecursorCharge == nodeGroup.TransitionGroup.PrecursorCharge && Equals(RefineLabelType, nodeGroupChild.TransitionGroup.LabelType)) return false; } foreach (TransitionGroupDocNode nodeGroupAdded in listGroups) { if (nodeGroupAdded.TransitionGroup.PrecursorCharge == nodeGroup.TransitionGroup.PrecursorCharge && Equals(RefineLabelType, nodeGroupAdded.TransitionGroup.LabelType)) return false; } return true; }
private static List<TransitionGroupDocNode> GetDecoyGroups(PeptideDocNode nodePep, Peptide decoyPeptide, ExplicitMods mods, IEnumerable<TransitionGroupDocNode> comparableGroups, SrmDocument document, bool shiftMass) { var decoyNodeTranGroupList = new List<TransitionGroupDocNode>(); var chargeToPrecursor = new Tuple<int, TransitionGroupDocNode>[TransitionGroup.MAX_PRECURSOR_CHARGE+1]; foreach (TransitionGroupDocNode nodeGroup in comparableGroups) { var transGroup = nodeGroup.TransitionGroup; int precursorMassShift; TransitionGroupDocNode nodeGroupPrimary = null; var primaryPrecursor = chargeToPrecursor[nodeGroup.TransitionGroup.PrecursorCharge]; if (primaryPrecursor != null) { precursorMassShift = primaryPrecursor.Item1; nodeGroupPrimary = primaryPrecursor.Item2; } else if (shiftMass) { precursorMassShift = GetPrecursorMassShift(); } else { precursorMassShift = TransitionGroup.ALTERED_SEQUENCE_DECOY_MZ_SHIFT; } var decoyGroup = new TransitionGroup(decoyPeptide, transGroup.PrecursorCharge, transGroup.LabelType, false, precursorMassShift); var decoyNodeTranList = nodeGroupPrimary != null ? decoyGroup.GetMatchingTransitions(document.Settings, nodeGroupPrimary, mods) : GetDecoyTransitions(nodeGroup, decoyGroup, shiftMass); var nodeGroupDecoy = new TransitionGroupDocNode(decoyGroup, Annotations.EMPTY, document.Settings, mods, nodeGroup.LibInfo, nodeGroup.ExplicitValues, nodeGroup.Results, decoyNodeTranList, false); decoyNodeTranGroupList.Add(nodeGroupDecoy); if (primaryPrecursor == null) { chargeToPrecursor[transGroup.PrecursorCharge] = new Tuple<int, TransitionGroupDocNode>(precursorMassShift, nodeGroupDecoy); } } return decoyNodeTranGroupList; }
private static SrmDocument GenerateDecoysFunc(SrmDocument document, int numDecoys, bool multiCycle, Func<SequenceMods, SequenceMods> genDecoySequence) { // Loop through the existing tree in random order creating decoys var settings = document.Settings; var enzyme = settings.PeptideSettings.Enzyme; var decoyNodePepList = new List<PeptideDocNode>(); var setDecoyKeys = new HashSet<PeptideModKey>(); while (numDecoys > 0) { int startDecoys = numDecoys; foreach (var nodePep in document.Peptides.ToArray().RandomOrder()) { if (numDecoys == 0) break; // Decoys should not be based on standard peptides if (nodePep.GlobalStandardType != null) continue; // If the non-terminal end of the peptide sequence is all a single character, skip this peptide, // since it can't support decoy generation. var sequence = nodePep.Peptide.Sequence; if (genDecoySequence != null && sequence.Substring(0, sequence.Length - 1).Distinct().Count() == 1) continue; var seqMods = new SequenceMods(nodePep); if (genDecoySequence != null) { seqMods = genDecoySequence(seqMods); } var peptide = nodePep.Peptide; var decoyPeptide = new Peptide(null, seqMods.Sequence, null, null, enzyme.CountCleavagePoints(seqMods.Sequence), true); if (seqMods.Mods != null) seqMods.Mods = seqMods.Mods.ChangePeptide(decoyPeptide); foreach (var comparableGroups in PeakFeatureEnumerator.ComparableGroups(nodePep)) { var decoyNodeTranGroupList = GetDecoyGroups(nodePep, decoyPeptide, seqMods.Mods, comparableGroups, document, Equals(seqMods.Sequence, peptide.Sequence)); if (decoyNodeTranGroupList.Count == 0) continue; var nodePepNew = new PeptideDocNode(decoyPeptide, settings, seqMods.Mods, null, nodePep.ExplicitRetentionTime, decoyNodeTranGroupList.ToArray(), false); if (!Equals(nodePep.ModifiedSequence, nodePepNew.ModifiedSequence)) { var sourceKey = new ModifiedSequenceMods(nodePep.ModifiedSequence, nodePep.ExplicitMods); nodePepNew = nodePepNew.ChangeSourceKey(sourceKey); } // Avoid adding duplicate peptides if (setDecoyKeys.Contains(nodePepNew.Key)) continue; setDecoyKeys.Add(nodePepNew.Key); decoyNodePepList.Add(nodePepNew); numDecoys--; } } // Stop if not multi-cycle or the number of decoys has not changed. if (!multiCycle || startDecoys == numDecoys) break; } var decoyNodePepGroup = new PeptideGroupDocNode(new PeptideGroup(true), Annotations.EMPTY, PeptideGroup.DECOYS, null, decoyNodePepList.ToArray(), false); decoyNodePepGroup = decoyNodePepGroup.ChangeSettings(document.Settings, SrmSettingsDiff.ALL); return (SrmDocument)document.Add(decoyNodePepGroup); }
// ReSharper restore SuggestBaseTypeForParameter // ReSharper disable SuggestBaseTypeForParameter public PeptideTreeNode(SequenceTree tree, PeptideDocNode nodePeptide) : base(tree, nodePeptide) { }
private static IEnumerable<KeyValuePair<IsotopeLabelType, string>> GetTypedModifiedSequences( PeptideDocNode nodePep, SrmSettings settings) { foreach (var labelType in settings.PeptideSettings.Modifications.GetModificationTypes()) { if (nodePep.Peptide.IsCustomIon) continue; // Only return the modified sequence, if the peptide actually as a child // of this type. if (!nodePep.HasChildType(labelType)) continue; var calc = settings.TryGetPrecursorCalc(labelType, nodePep.ExplicitMods); if (calc == null) continue; string modSequence = calc.GetModifiedSequence(nodePep.Peptide.Sequence, true); // Never have to worry about this being a custom ion, we already checked // Only return if the modified sequence contains modifications if (modSequence.Contains('[')) // Not L10N yield return new KeyValuePair<IsotopeLabelType, string>(labelType, modSequence); } }
public static string GetLabel(PeptideDocNode nodePep, string resultsText) { return nodePep + resultsText; }
public PickTransitionGroupTip(PeptideDocNode nodePep, TransitionGroupDocNode nodeGroup, SrmSettings settings) { _nodePep = nodePep; _nodeGroup = nodeGroup; _settings = settings; }
public static Image GetPeakImage(PeptideDocNode nodePep, SequenceTree sequenceTree) { int imageIndex = GetPeakImageIndex(nodePep, sequenceTree); return (imageIndex != -1 ? sequenceTree.StateImageList.Images[imageIndex] : null); }
// ReSharper restore SuggestBaseTypeForParameter // ReSharper disable SuggestBaseTypeForParameter private static void AssertPrecursorMzIsModified(PeptideDocNode nodePep1, int index1, PeptideDocNode nodePep2, int index2, double deltaMass, double tolerance) { Assert.AreEqual(((TransitionGroupDocNode) nodePep1.Children[index1]).PrecursorMz, ((TransitionGroupDocNode) nodePep2.Children[index2]).PrecursorMz + deltaMass, tolerance); }
public static int GetPeakImageIndex(PeptideDocNode nodePep, SequenceTree sequenceTree) { var settings = sequenceTree.Document.Settings; if (!settings.HasResults) return -1; int index = sequenceTree.GetDisplayResultsIndex(nodePep); float? ratio = (nodePep.HasResults ? nodePep.GetPeakCountRatio(index) : null); if (ratio == null) return (int)SequenceTree.StateImageId.peak_blank; if (ratio < 0.5) return (int)SequenceTree.StateImageId.no_peak; if (ratio < 1.0) return (int)SequenceTree.StateImageId.keep; return (int)SequenceTree.StateImageId.peak; }
public PeptideDocNode CreateDocNodeFromMatches(PeptideDocNode nodePep, IEnumerable<AAModInfo> infos, bool stringPaste, out bool hasHeavy) { hasHeavy = false; List<ExplicitMod> listLightMods = new List<ExplicitMod>(); var dictHeavyMods = new Dictionary<IsotopeLabelType, List<ExplicitMod>>(); foreach (var info in infos) { var match = GetMatch(info.ModKey); if (match == null) return null; AAModMatch modMatch = (AAModMatch)match; var lightMod = modMatch.StructuralMod; if (lightMod != null) { // Make sure all mods are explicit for ensure mods. if (stringPaste) lightMod = lightMod.ChangeExplicit(true); listLightMods.Add(new ExplicitMod(info.IndexAA, lightMod)); } var heavyMod = modMatch.HeavyMod; if (heavyMod != null) { var type = UserDefinedTypedMods.ContainsKey(modMatch.HeavyMod) ? UserDefinedTypedMods[modMatch.HeavyMod] : DocDefHeavyLabelType; List<ExplicitMod> listHeavyMods; if (!dictHeavyMods.TryGetValue(type, out listHeavyMods)) { listHeavyMods = new List<ExplicitMod>(); dictHeavyMods.Add(type, listHeavyMods); } listHeavyMods.Add(new ExplicitMod(info.IndexAA, heavyMod)); } } // Build the set of explicit modifications for the peptide. // If ensure mods is set to true, then perform the work here to ensure // that the mods persist corectly with the current settings. var targetImplicitMods = new ExplicitMods(nodePep, Settings.PeptideSettings.Modifications.StaticModifications, DefSetStatic, Settings.PeptideSettings.Modifications.GetHeavyModifications(), DefSetHeavy); // If no light modifications are present, this code assumes the user wants the // default global light modifications. Unless not stringPaste, in which case the target // static mods must also be empty if (listLightMods.Count == 0 && (stringPaste || targetImplicitMods.StaticModifications.Count == 0)) listLightMods = null; else if (stringPaste && ArrayUtil.EqualsDeep(listLightMods.ToArray(), targetImplicitMods.StaticModifications)) listLightMods = null; var listTypedHeavyMods = new List<TypedExplicitModifications>(); foreach (var targetDocMod in targetImplicitMods.GetHeavyModifications()) { List<ExplicitMod> listMods; if (dictHeavyMods.TryGetValue(targetDocMod.LabelType, out listMods) && (!stringPaste || !ArrayUtil.EqualsDeep(listMods, targetDocMod.Modifications))) listTypedHeavyMods.Add(new TypedExplicitModifications(nodePep.Peptide, targetDocMod.LabelType, listMods) .AddModMasses(listLightMods == null ? null : new TypedExplicitModifications(nodePep.Peptide, IsotopeLabelType.light, listLightMods))); } // Put the explicit modifications on the peptide. ExplicitMods mods = (listLightMods != null || listTypedHeavyMods.Count > 0) ? new ExplicitMods(nodePep.Peptide, listLightMods, listTypedHeavyMods, listLightMods != null && listLightMods.Contains(mod => mod.Modification.IsVariable)) : null; hasHeavy = dictHeavyMods.Keys.Count > 0; return nodePep.ChangeExplicitMods(mods).ChangeSettings(Settings, SrmSettingsDiff.PROPS); }
public static Image GetTypeImage(PeptideDocNode nodePep, SequenceTree sequenceTree) { return sequenceTree.ImageList.Images[GetTypeImageIndex(nodePep)]; }
private PeptideDocNode CreateDocNodeFromSettings(string seq, PeptideDocNode nodePep, SrmSettingsDiff diff, out TransitionGroupDocNode nodeGroupMatched) { PeptideDocNode nodePepMod = nodePep.ChangeSettings(Settings, diff ?? SrmSettingsDiff.ALL, false); TransitionGroupDocNode nodeGroupMatchedFound; if (IsMatch(seq, nodePepMod, out nodeGroupMatchedFound)) { nodeGroupMatched = nodeGroupMatchedFound; return nodePepMod; } nodeGroupMatched = null; return null; }
public static bool HasPeptideTip(PeptideDocNode nodePep, SrmSettings settings) { return nodePep.Peptide.Begin.HasValue || nodePep.Rank.HasValue || nodePep.Note != null || // With one child, its tip detail will be appended nodePep.Children.Count == 1 || // With multiple children, modification sequences may be shown GetTypedModifiedSequences(nodePep, settings).Any(); }
private static bool IsNotRagged(PeptideDocNode nodePeptide) { Peptide peptide = nodePeptide.Peptide; FastaSequence fastaSeq = peptide.FastaSequence; if (fastaSeq == null) return true; int begin = peptide.Begin ?? 0; return ((begin < 2 || "KR".IndexOf(fastaSeq.Sequence[begin - 2]) == -1) && "KR".IndexOf(peptide.NextAA) == -1); }
public static Size RenderTip(PeptideDocNode nodePep, TransitionDocNode nodeTranSelected, SrmSettings settings, Graphics g, Size sizeMax, bool draw) { var table = new TableDesc(); using (RenderTools rt = new RenderTools()) { Peptide peptide = nodePep.Peptide; SizeF size; if (peptide.IsCustomIon) { table.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Molecule, nodePep.CustomIon.Name, rt); table.AddDetailRow(Resources.TransitionTreeNode_RenderTip_Formula, nodePep.CustomIon.Formula, rt); table.AddDetailRow(Resources.PeptideTreeNode_RenderTip_Neutral_Mass, nodePep.CustomIon.GetMass(settings.TransitionSettings.Prediction.PrecursorMassType).ToString(LocalizationHelper.CurrentCulture), rt); size = table.CalcDimensions(g); table.Draw(g); return new Size((int)Math.Round(size.Width + 2), (int)Math.Round(size.Height + 2)); } if (nodePep.Children.Count > 1) { foreach (var typedModSequence in GetTypedModifiedSequences(nodePep, settings)) table.AddDetailRow(typedModSequence.Key.Title, typedModSequence.Value, rt); } if (peptide.Begin.HasValue) { // Add a spacing row, if anything was added if (table.Count > 0) table.AddDetailRow(" ", " ", rt); // Not L10N table.AddDetailRow(Resources.PeptideTreeNode_RenderTip_Previous, peptide.PrevAA.ToString(CultureInfo.InvariantCulture), rt); table.AddDetailRow(Resources.PeptideTreeNode_RenderTip_First, peptide.Begin.Value.ToString(LocalizationHelper.CurrentCulture), rt); table.AddDetailRow(Resources.PeptideTreeNode_RenderTip_Last, ((peptide.End ?? 1) - 1).ToString(LocalizationHelper.CurrentCulture), rt); table.AddDetailRow(Resources.PeptideTreeNode_RenderTip_Next, peptide.NextAA.ToString(CultureInfo.InvariantCulture), rt); } if (nodePep.Rank.HasValue) table.AddDetailRow(Resources.PeptideTreeNode_RenderTip_Rank, nodePep.Rank.Value.ToString(LocalizationHelper.CurrentCulture), rt); size = table.CalcDimensions(g); if (draw) table.Draw(g); // Render group tip, if there is only one, and this node is collapsed if (nodePep.Children.Count == 1) { var nodeGroup = (TransitionGroupDocNode)nodePep.Children[0]; if (size.Height > 0) size.Height += TableDesc.TABLE_SPACING; if (draw) g.TranslateTransform(0, size.Height); Size sizeMaxGroup = new Size(sizeMax.Width, sizeMax.Height - (int)size.Height); SizeF sizeGroup = TransitionGroupTreeNode.RenderTip(nodePep, nodeGroup, nodeTranSelected, settings, g, sizeMaxGroup, draw); if (draw) g.TranslateTransform(0, -size.Height); size.Width = Math.Max(size.Width, sizeGroup.Width); size.Height += sizeGroup.Height; } return new Size((int)Math.Round(size.Width + 2), (int)Math.Round(size.Height + 2)); } }
protected override bool IsMatch(string seqMod, PeptideDocNode nodePepMod, out TransitionGroupDocNode nodeGroup) { foreach(TransitionGroupDocNode nodeGroupChild in nodePepMod.Children) { nodeGroup = nodeGroupChild; var calc = Settings.TryGetPrecursorCalc(nodeGroupChild.TransitionGroup.LabelType, nodePepMod.ExplicitMods); if (calc == null) return false; string modSequence = calc.GetModifiedSequence(nodePepMod.Peptide.Sequence, false); // If this sequence matches the sequence of the library peptide, a match has been found. if (Equals(seqMod, modSequence)) return true; } nodeGroup = null; return false; }
/// <summary> /// Creates a text sequence with the fully modified peptide sequence text /// and font information for a given label type. /// </summary> private static TextSequence CreateTypeTextSequence(PeptideDocNode nodePep, SrmSettings settings, IsotopeLabelType labelType, ModFontHolder fonts) { var calc = settings.TryGetPrecursorCalc(labelType, nodePep.ExplicitMods); if (calc == null) return null; return new TextSequence { Text = nodePep.IsProteomic ? calc.GetModifiedSequence(nodePep.Peptide.Sequence, true) : nodePep.CustomIon.DisplayName, Font = fonts.GetModFont(labelType), Color = ModFontHolder.GetModColor(labelType) }; }