public SrmDocument Import(TextReader reader, IProgressMonitor progressMonitor, long lineCount, bool isMinutes, bool removeMissing = false, bool changePeaks = true) { var status = new ProgressStatus(Resources.PeakBoundaryImporter_Import_Importing_Peak_Boundaries); double timeConversionFactor = isMinutes ? 1.0 : 60.0; int linesRead = 0; int progressPercent = 0; var docNew = (SrmDocument) Document.ChangeIgnoreChangingChildren(true); var docReference = docNew; var sequenceToNode = new Dictionary<Tuple<string, bool>, IList<IdentityPath>>(); var fileNameToFileMatch = new Dictionary<string, ChromSetFileMatch>(); var trackAdjustedResults = new HashSet<ResultsKey>(); var modMatcher = new ModificationMatcher(); // Make the dictionary of modified peptide strings to doc nodes and paths for (int i = 0; i < Document.MoleculeCount; ++i) { IdentityPath peptidePath = Document.GetPathTo((int) SrmDocument.Level.Molecules, i); PeptideDocNode peptideNode = (PeptideDocNode) Document.FindNode(peptidePath); var peptidePair = new Tuple<string, bool>(peptideNode.RawTextId, peptideNode.IsDecoy); IList<IdentityPath> idPathList; // Each (sequence, isDecoy) pair can be associated with more than one peptide, // to handle the case of duplicate peptides in the doucment. if (sequenceToNode.TryGetValue(peptidePair, out idPathList)) { idPathList.Add(peptidePath); sequenceToNode[peptidePair] = idPathList; } else { idPathList = new List<IdentityPath> { peptidePath }; sequenceToNode.Add(peptidePair, idPathList); } } // Add annotations as possible columns var allFieldNames = new List<string[]>(FIELD_NAMES); allFieldNames.AddRange(from def in Document.Settings.DataSettings.AnnotationDefs where def.AnnotationTargets.Contains(AnnotationDef.AnnotationTarget.precursor_result) select new[] { def.Name }); string line = reader.ReadLine(); linesRead++; int[] fieldIndices; int fieldsTotal; // If we aren't changing peaks, allow start and end time to be missing var requiredFields = changePeaks ? REQUIRED_FIELDS : REQUIRED_NO_CHROM; char correctSeparator = ReadFirstLine(line, allFieldNames, requiredFields, out fieldIndices, out fieldsTotal); while ((line = reader.ReadLine()) != null) { linesRead++; if (progressMonitor != null) { if (progressMonitor.IsCanceled) return Document; int progressNew = (int) (linesRead*100/lineCount); if (progressPercent != progressNew) { progressMonitor.UpdateProgress(status = status.ChangePercentComplete(progressNew)); progressPercent = progressNew; } } var dataFields = new DataFields(fieldIndices, line.ParseDsvFields(correctSeparator), allFieldNames); if (dataFields.Length != fieldsTotal) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Line__0__field_count__1__differs_from_the_first_line__which_has__2_, linesRead, dataFields.Length, fieldsTotal)); } string modifiedPeptideString = dataFields.GetField(Field.modified_peptide); modMatcher.CreateMatches(Document.Settings, new List<string> {modifiedPeptideString}, Settings.Default.StaticModList, Settings.Default.HeavyModList); // Convert the modified peptide string into a standardized form that // converts unimod, names, etc, into masses, eg [+57.0] var nodeForModPep = modMatcher.GetModifiedNode(modifiedPeptideString); if (nodeForModPep == null) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Peptide_has_unrecognized_modifications__0__at_line__1_, modifiedPeptideString, linesRead)); } nodeForModPep = nodeForModPep.ChangeSettings(Document.Settings, SrmSettingsDiff.ALL); modifiedPeptideString = nodeForModPep.RawTextId; // Modified sequence, or custom ion name string fileName = dataFields.GetField(Field.filename); bool isDecoy = dataFields.IsDecoy(linesRead); var peptideIdentifier = new Tuple<string, bool>(modifiedPeptideString, isDecoy); int charge; bool chargeSpecified = dataFields.TryGetCharge(linesRead, out charge); string sampleName = dataFields.GetField(Field.sample_name); double? startTime = null; double? endTime = null; if (changePeaks) { startTime = dataFields.GetTime(Field.start_time, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_start_time_, linesRead); if (startTime.HasValue) startTime = startTime / timeConversionFactor; endTime = dataFields.GetTime(Field.end_time, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_end_time_, linesRead); if (endTime.HasValue) endTime = endTime / timeConversionFactor; } // Error if only one of startTime and endTime is null if (startTime == null && endTime != null) throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Missing_start_time_on_line__0_, linesRead)); if (startTime != null && endTime == null) throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Missing_end_time_on_line__0_, linesRead)); // Add filename to second dictionary if not yet encountered ChromSetFileMatch fileMatch; if (!fileNameToFileMatch.TryGetValue(fileName, out fileMatch)) { fileMatch = Document.Settings.MeasuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(fileName)); fileNameToFileMatch.Add(fileName, fileMatch); } if (fileMatch == null) { UnrecognizedFiles.Add(fileName); continue; } var chromSet = fileMatch.Chromatograms; string nameSet = chromSet.Name; ChromFileInfoId[] fileIds; if (sampleName == null) { fileIds = chromSet.MSDataFileInfos.Select(x => x.FileId).ToArray(); } else { var sampleFile = chromSet.MSDataFileInfos.FirstOrDefault(info => Equals(sampleName, info.FilePath.GetSampleName())); if (sampleFile == null) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Sample__0__on_line__1__does_not_match_the_file__2__, sampleName, linesRead, fileName)); } fileIds = new[] {sampleFile.FileId}; } // Look up the IdentityPath of peptide in first dictionary IList<IdentityPath> pepPaths; if (!sequenceToNode.TryGetValue(peptideIdentifier, out pepPaths)) { UnrecognizedPeptides.Add(modifiedPeptideString); continue; } // Define the annotations to be added var annotations = dataFields.GetAnnotations(); AnnotationsAdded = annotations.Keys.ToList(); // Loop over all the transition groups in that peptide to find matching charge, // or use all transition groups if charge not specified bool foundSample = false; foreach (var pepPath in pepPaths) { var nodePep = (PeptideDocNode)docNew.FindNode(pepPath); for(int i = 0; i < nodePep.Children.Count; ++i) { var groupRelPath = nodePep.GetPathTo(i); var groupNode = (TransitionGroupDocNode) nodePep.FindNode(groupRelPath); if (!chargeSpecified || charge == groupNode.TransitionGroup.PrecursorCharge) { var groupFileIndices = new HashSet<int>(groupNode.ChromInfos.Select(x => x.FileId.GlobalIndex)); // Loop over the files in this groupNode to find the correct sample // Change peak boundaries for the transition group foreach (var fileId in fileIds) { if (groupFileIndices.Contains(fileId.GlobalIndex)) { var groupPath = new IdentityPath(pepPath, groupNode.Id); // Attach annotations docNew = docNew.AddPrecursorResultsAnnotations(groupPath, fileId, annotations); // Change peak var filePath = chromSet.GetFileInfo(fileId).FilePath; if (changePeaks) { docNew = docNew.ChangePeak(groupPath, nameSet, filePath, null, startTime, endTime, UserSet.IMPORTED, null, false); } // For removing peaks that are not in the file, if removeMissing = true trackAdjustedResults.Add(new ResultsKey(fileId.GlobalIndex, groupNode.Id)); foundSample = true; } } } } } if (!foundSample) { UnrecognizedChargeStates.Add(new UnrecognizedChargeState(charge, fileName, modifiedPeptideString)); } } // Remove peaks from the document that weren't in the file. if (removeMissing) docNew = RemoveMissing(docNew, trackAdjustedResults, changePeaks); // If nothing has changed, return the old Document before ChangeIgnoreChangingChildren was turned off if (!ReferenceEquals(docNew, docReference)) Document = (SrmDocument) Document.ChangeIgnoreChangingChildren(false).ChangeChildrenChecked(docNew.Children); return Document; }
public SrmDocument Import(TextReader reader, IProgressMonitor progressMonitor, long lineCount, bool isMinutes, bool removeMissing = false, bool changePeaks = true) { IProgressStatus status = new ProgressStatus(Resources.PeakBoundaryImporter_Import_Importing_Peak_Boundaries); double timeConversionFactor = isMinutes ? 1.0 : 60.0; int linesRead = 0; int progressPercent = 0; var docNew = (SrmDocument)Document.ChangeIgnoreChangingChildren(true); var docReference = docNew; var sequenceToNode = MakeSequenceDictionary(Document); var fileNameToFileMatch = new Dictionary <string, ChromSetFileMatch>(); var trackAdjustedResults = new HashSet <ResultsKey>(); var modMatcher = new ModificationMatcher(); var canonicalSequenceDict = new Dictionary <string, string>(); // Add annotations as possible columns var allFieldNames = new List <string[]>(FIELD_NAMES); allFieldNames.AddRange(from def in Document.Settings.DataSettings.AnnotationDefs where def.AnnotationTargets.Contains(AnnotationDef.AnnotationTarget.precursor_result) select new[] { def.Name }); string line = reader.ReadLine(); linesRead++; int[] fieldIndices; int fieldsTotal; // If we aren't changing peaks, allow start and end time to be missing var requiredFields = changePeaks ? REQUIRED_FIELDS : REQUIRED_NO_CHROM; char correctSeparator = ReadFirstLine(line, allFieldNames, requiredFields, out fieldIndices, out fieldsTotal); while ((line = reader.ReadLine()) != null) { linesRead++; if (progressMonitor != null) { if (progressMonitor.IsCanceled) { return(Document); } int progressNew = (int)(linesRead * 100 / lineCount); if (progressPercent != progressNew) { progressMonitor.UpdateProgress(status = status.ChangePercentComplete(progressNew)); progressPercent = progressNew; } } var dataFields = new DataFields(fieldIndices, line.ParseDsvFields(correctSeparator), allFieldNames); if (dataFields.Length != fieldsTotal) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Line__0__field_count__1__differs_from_the_first_line__which_has__2_, linesRead, dataFields.Length, fieldsTotal)); } string modifiedPeptideString = dataFields.GetField(Field.modified_peptide); string fileName = dataFields.GetField(Field.filename); bool isDecoy = dataFields.IsDecoy(linesRead); IList <IdentityPath> pepPaths; if (!sequenceToNode.TryGetValue(Tuple.Create(modifiedPeptideString, isDecoy), out pepPaths)) { string canonicalSequence; if (!canonicalSequenceDict.TryGetValue(modifiedPeptideString, out canonicalSequence)) { if (modifiedPeptideString.Any(c => c < 'A' || c > 'Z')) { modMatcher.CreateMatches(Document.Settings, new List <string> { modifiedPeptideString }, Settings.Default.StaticModList, Settings.Default.HeavyModList); var nodeForModPep = modMatcher.GetModifiedNode(modifiedPeptideString); if (nodeForModPep == null) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Peptide_has_unrecognized_modifications__0__at_line__1_, modifiedPeptideString, linesRead)); } nodeForModPep = nodeForModPep.ChangeSettings(Document.Settings, SrmSettingsDiff.ALL); // Convert the modified peptide string into a standardized form that // converts unimod, names, etc, into masses, eg [+57.0] canonicalSequence = nodeForModPep.ModifiedTarget.Sequence; canonicalSequenceDict.Add(modifiedPeptideString, canonicalSequence); } } if (null != canonicalSequence) { sequenceToNode.TryGetValue(Tuple.Create(canonicalSequence, isDecoy), out pepPaths); } } if (null == pepPaths) { UnrecognizedPeptides.Add(modifiedPeptideString); continue; } Adduct charge; bool chargeSpecified = dataFields.TryGetCharge(linesRead, out charge); string sampleName = dataFields.GetField(Field.sample_name); double?apexTime = dataFields.GetTime(Field.apex_time, timeConversionFactor, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_time_, linesRead); double?startTime = dataFields.GetTime(Field.start_time, timeConversionFactor, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_start_time_, linesRead); double?endTime = dataFields.GetTime(Field.end_time, timeConversionFactor, Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_end_time_, linesRead); // Error if only one of startTime and endTime is null if (startTime == null && endTime != null) { if (changePeaks) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Missing_start_time_on_line__0_, linesRead)); } endTime = null; } if (startTime != null && endTime == null) { if (changePeaks) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Missing_end_time_on_line__0_, linesRead)); } startTime = null; } // Add filename to second dictionary if not yet encountered ChromSetFileMatch fileMatch; if (!fileNameToFileMatch.TryGetValue(fileName, out fileMatch)) { fileMatch = Document.Settings.MeasuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(fileName)); fileNameToFileMatch.Add(fileName, fileMatch); } if (fileMatch == null) { UnrecognizedFiles.Add(fileName); continue; } var chromSet = fileMatch.Chromatograms; string nameSet = chromSet.Name; ChromFileInfoId[] fileIds; if (sampleName == null) { fileIds = chromSet.MSDataFileInfos.Select(x => x.FileId).ToArray(); } else { var sampleFile = chromSet.MSDataFileInfos.FirstOrDefault(info => Equals(sampleName, info.FilePath.GetSampleName())); if (sampleFile == null) { throw new IOException(string.Format(Resources.PeakBoundaryImporter_Import_Sample__0__on_line__1__does_not_match_the_file__2__, sampleName, linesRead, fileName)); } fileIds = new[] { sampleFile.FileId }; } // Define the annotations to be added var annotations = dataFields.GetAnnotations(); if (!changePeaks) { if (apexTime.HasValue) { annotations.Add(ComparePeakBoundaries.APEX_ANNOTATION, dataFields.GetField(Field.apex_time)); } if (startTime.HasValue && endTime.HasValue) { annotations.Add(ComparePeakBoundaries.START_TIME_ANNOTATION, dataFields.GetField(Field.start_time)); annotations.Add(ComparePeakBoundaries.END_TIME_ANNOTATION, dataFields.GetField(Field.end_time)); } } AnnotationsAdded = annotations.Keys.ToList(); // Loop over all the transition groups in that peptide to find matching charge, // or use all transition groups if charge not specified bool foundSample = false; foreach (var pepPath in pepPaths) { var nodePep = (PeptideDocNode)docNew.FindNode(pepPath); foreach (TransitionGroupDocNode groupNode in nodePep.Children) { if (chargeSpecified && charge != groupNode.TransitionGroup.PrecursorAdduct) { continue; } // Loop over the files in this groupNode to find the correct sample // Change peak boundaries for the transition group foreach (var fileId in GetApplicableFiles(fileIds, groupNode)) { var groupPath = new IdentityPath(pepPath, groupNode.Id); // Attach annotations if (annotations.Any()) { docNew = docNew.AddPrecursorResultsAnnotations(groupPath, fileId, annotations); } // Change peak var filePath = chromSet.GetFileInfo(fileId).FilePath; if (changePeaks) { docNew = docNew.ChangePeak(groupPath, nameSet, filePath, null, startTime, endTime, UserSet.IMPORTED, null, false); } // For removing peaks that are not in the file, if removeMissing = true trackAdjustedResults.Add(new ResultsKey(fileId.GlobalIndex, groupNode.Id)); foundSample = true; } } } if (!foundSample) { UnrecognizedChargeStates.Add(new UnrecognizedChargeState(charge, fileName, modifiedPeptideString)); } } // Remove peaks from the document that weren't in the file. if (removeMissing) { docNew = RemoveMissing(docNew, trackAdjustedResults, changePeaks); } // If nothing has changed, return the old Document before ChangeIgnoreChangingChildren was turned off if (!ReferenceEquals(docNew, docReference)) { Document = (SrmDocument)Document.ChangeIgnoreChangingChildren(false).ChangeChildrenChecked(docNew.Children); } return(Document); }
private SrmDocument AddPeptides(SrmDocument document, bool validating, ref IdentityPath selectedPath) { if (tabControl1.SelectedTab != tabPagePeptideList) return document; var matcher = new ModificationMatcher(); var listPeptideSequences = ListPeptideSequences(); if (listPeptideSequences == null) return null; try { matcher.CreateMatches(document.Settings, listPeptideSequences, Settings.Default.StaticModList, Settings.Default.HeavyModList); } catch (FormatException e) { MessageDlg.ShowException(this, e); ShowPeptideError(new PasteError { Column = colPeptideSequence.Index, Message = Resources.PasteDlg_AddPeptides_Unable_to_interpret_peptide_modifications }); return null; } var strNameMatches = matcher.FoundMatches; if (!validating && !string.IsNullOrEmpty(strNameMatches)) { string message = TextUtil.LineSeparate(Resources.PasteDlg_AddPeptides_Would_you_like_to_use_the_Unimod_definitions_for_the_following_modifications, string.Empty, strNameMatches); if (MultiButtonMsgDlg.Show(this, message, Resources.PasteDlg_AddPeptides_OK) == DialogResult.Cancel) return null; } var backgroundProteome = GetBackgroundProteome(document); // Insert last to first so that proteins get inserted on top of each other // in the order they are added. Peptide insertion into peptide lists needs // to be carefully tracked to insert them in the order they are listed in // the grid. int lastGroupGlobalIndex = 0, lastPeptideIndex = -1; for (int i = gridViewPeptides.Rows.Count - 1; i >= 0; i--) { PeptideGroupDocNode peptideGroupDocNode; var row = gridViewPeptides.Rows[i]; var pepModSequence = Convert.ToString(row.Cells[colPeptideSequence.Index].Value); pepModSequence = FastaSequence.NormalizeNTerminalMod(pepModSequence); var proteinName = Convert.ToString(row.Cells[colPeptideProtein.Index].Value); if (string.IsNullOrEmpty(pepModSequence) && string.IsNullOrEmpty(proteinName)) continue; if (string.IsNullOrEmpty(proteinName)) { peptideGroupDocNode = GetSelectedPeptideGroupDocNode(document, selectedPath); if (!IsPeptideListDocNode(peptideGroupDocNode)) { peptideGroupDocNode = null; } } else { peptideGroupDocNode = FindPeptideGroupDocNode(document, proteinName); } if (peptideGroupDocNode == null) { if (string.IsNullOrEmpty(proteinName)) { peptideGroupDocNode = new PeptideGroupDocNode(new PeptideGroup(), document.GetPeptideGroupId(true), null, new PeptideDocNode[0]); } else { ProteinMetadata metadata = null; PeptideGroup peptideGroup = backgroundProteome.IsNone ? new PeptideGroup() : (backgroundProteome.GetFastaSequence(proteinName, out metadata) ?? new PeptideGroup()); if (metadata != null) peptideGroupDocNode = new PeptideGroupDocNode(peptideGroup, metadata, new PeptideDocNode[0]); else peptideGroupDocNode = new PeptideGroupDocNode(peptideGroup, proteinName, peptideGroup.Description, new PeptideDocNode[0]); } // Add to the end, if no insert node var to = selectedPath; if (to == null || to.Depth < (int)SrmDocument.Level.MoleculeGroups) document = (SrmDocument)document.Add(peptideGroupDocNode); else { Identity toId = selectedPath.GetIdentity((int) SrmDocument.Level.MoleculeGroups); document = (SrmDocument) document.Insert(toId, peptideGroupDocNode); } selectedPath = new IdentityPath(peptideGroupDocNode.Id); } var peptides = new List<PeptideDocNode>(); foreach (PeptideDocNode peptideDocNode in peptideGroupDocNode.Children) { peptides.Add(peptideDocNode); } var fastaSequence = peptideGroupDocNode.PeptideGroup as FastaSequence; PeptideDocNode nodePepNew; if (fastaSequence != null) { // Attempt to create node for error checking. nodePepNew = fastaSequence.CreateFullPeptideDocNode(document.Settings, FastaSequence.StripModifications(pepModSequence)); if (nodePepNew == null) { ShowPeptideError(new PasteError { Column = colPeptideSequence.Index, Line = i, Message = Resources.PasteDlg_AddPeptides_This_peptide_sequence_was_not_found_in_the_protein_sequence }); return null; } } // Create node using ModificationMatcher. nodePepNew = matcher.GetModifiedNode(pepModSequence, fastaSequence).ChangeSettings(document.Settings, SrmSettingsDiff.ALL); // Avoid adding an existing peptide a second time. if (!peptides.Contains(nodePep => Equals(nodePep.Key, nodePepNew.Key))) { if (nodePepNew.Peptide.FastaSequence != null) { peptides.Add(nodePepNew); peptides.Sort(FastaSequence.ComparePeptides); } else { int groupGlobalIndex = peptideGroupDocNode.PeptideGroup.GlobalIndex; if (groupGlobalIndex == lastGroupGlobalIndex && lastPeptideIndex != -1) { peptides.Insert(lastPeptideIndex, nodePepNew); } else { lastPeptideIndex = peptides.Count; peptides.Add(nodePepNew); } lastGroupGlobalIndex = groupGlobalIndex; } var newPeptideGroupDocNode = new PeptideGroupDocNode(peptideGroupDocNode.PeptideGroup, peptideGroupDocNode.Annotations, peptideGroupDocNode.Name, peptideGroupDocNode.Description, peptides.ToArray(), false); document = (SrmDocument)document.ReplaceChild(newPeptideGroupDocNode); } } if (!validating && listPeptideSequences.Count > 0) { var pepModsNew = matcher.GetDocModifications(document); document = document.ChangeSettings(document.Settings.ChangePeptideModifications(mods => pepModsNew)); document.Settings.UpdateDefaultModifications(false); } return document; }
public void ImportFasta(TextReader reader, long lineCount, bool peptideList, string description) { SrmTreeNode nodePaste = SequenceTree.SelectedNode as SrmTreeNode; IdentityPath selectPath = null; var to = nodePaste != null ? nodePaste.Path : null; var docCurrent = DocumentUI; ModificationMatcher matcher = null; if(peptideList) { matcher = new ModificationMatcher(); List<string> sequences = new List<string>(); string line; var header = reader.ReadLine(); // Read past header while ((line = reader.ReadLine()) != null) { string sequence = FastaSequence.NormalizeNTerminalMod(line.Trim()); sequences.Add(sequence); } try { matcher.CreateMatches(docCurrent.Settings, sequences, Settings.Default.StaticModList, Settings.Default.HeavyModList); var strNameMatches = matcher.FoundMatches; if (!string.IsNullOrEmpty(strNameMatches)) { var message = TextUtil.LineSeparate(Resources.SkylineWindow_ImportFasta_Would_you_like_to_use_the_Unimod_definitions_for_the_following_modifications, string.Empty, strNameMatches); if (DialogResult.Cancel == MultiButtonMsgDlg.Show( this, string.Format(message), Resources.SkylineWindow_ImportFasta_OK)) { return; } } } catch(FormatException x) { MessageDlg.ShowException(this, x); return; } reader = new StringReader(TextUtil.LineSeparate(header, TextUtil.LineSeparate(sequences.ToArray()))); } SrmDocument docNew = null; int emptyPeptideGroups = 0; using (var longWaitDlg = new LongWaitDlg(this) { Text = description }) { IdentityPath nextAdded; longWaitDlg.PerformWork(this, 1000, longWaitBroker => docNew = docCurrent.ImportFasta(reader, longWaitBroker, lineCount, matcher, to, out selectPath, out nextAdded, out emptyPeptideGroups)); if (docNew == null) return; if (longWaitDlg.IsDocumentChanged(docCurrent)) { MessageDlg.Show(this, Resources.SkylineWindow_ImportFasta_Unexpected_document_change_during_operation); return; } } // If importing the FASTA produced any childless proteins docNew = ImportFastaHelper.HandleEmptyPeptideGroups(this, emptyPeptideGroups, docNew); if (docNew == null || Equals(docCurrent, docNew)) return; selectPath = null; var enumGroupsCurrent = docCurrent.MoleculeGroups.GetEnumerator(); foreach (PeptideGroupDocNode nodePepGroup in docNew.MoleculeGroups) { if (enumGroupsCurrent.MoveNext() && !ReferenceEquals(nodePepGroup, enumGroupsCurrent.Current)) { selectPath = new IdentityPath(nodePepGroup.Id); break; } } ModifyDocument(description, doc => { if (!ReferenceEquals(doc, docCurrent)) throw new InvalidDataException(Resources.SkylineWindow_ImportFasta_Unexpected_document_change_during_operation); if (matcher != null) { var pepModsNew = matcher.GetDocModifications(docNew); docNew = docNew.ChangeSettings(docNew.Settings.ChangePeptideModifications(mods => pepModsNew)); docNew.Settings.UpdateDefaultModifications(false); } return docNew; }); if (selectPath != null) SequenceTree.SelectedPath = selectPath; }
public FastaImporter(SrmDocument document, ModificationMatcher modMatcher) : this(document, true) { _modMatcher = modMatcher; }
public PeptideGroupBuilder(string line, ModificationMatcher modMatcher, SrmSettings settings) : this(line, true, settings) { _modMatcher = modMatcher; }
private static ModificationMatcher CreateModificationMatcher(SrmSettings settings, IEnumerable<string> sequences) { var modMatcher = new ModificationMatcher(); // We want AutoSelect on so we can generate transition groups, but we want the filter to // be lenient because we are only using this to match modifications, not generate the // final transition groups var settingsMatcher = settings.ChangeTransitionFilter(filter => filter.ChangeAutoSelect(true)) .ChangeTransitionFullScan(fullscan => fullscan.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.None, null, null)) .ChangeTransitionFilter(filter => filter.ChangePrecursorCharges(Enumerable.Range(TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE).ToArray())); try { modMatcher.CreateMatches(settingsMatcher, sequences != null ? sequences.Distinct() : new string[0], Properties.Settings.Default.StaticModList, Properties.Settings.Default.HeavyModList); } catch (FormatException) { modMatcher.CreateMatches(settingsMatcher, new string[0], Properties.Settings.Default.StaticModList, Properties.Settings.Default.HeavyModList); } return modMatcher; }