public static void TestVeryCloseExperimentalsModern() { IDictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> >(); ModificationMotif.TryGetMotif("M", out ModificationMotif motif); var prot = new Protein("MMMM", null, null, null, mods); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 1); var thePep = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First(); var frags = new List <Product>(); thePep.Fragment(DissociationType.HCD, FragmentationTerminus.Both, frags); var massArray = frags.Select(p => p.NeutralMass).ToArray(); Array.Sort(massArray); double[] intensities = new double[] { 1, 1, 1, 1 }; double[] mz = new double[] { 1, 2, massArray[4].ToMz(1), massArray[4].ToMz(1) + 1e-9 }; MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 600, 1, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters(productMassTolerance: new PpmTolerance(5), scoreCutoff: 1, digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: int.MaxValue, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)); var indexEngine = new IndexingEngine(new List <Protein> { prot }, new List <Modification>(), new List <Modification>(), null, null, null, 1, DecoyType.Reverse, CommonParameters, null, 30000, false, new List <FileInfo>(), TargetContaminantAmbiguity.RemoveContaminant, new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); var cse = new ModernSearchEngine(globalPsms, arrayOfSortedMS2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, new OpenSearchMode(), 0, new List <string>()); cse.Run(); Assert.Less(globalPsms[0].Score, 2); Assert.Greater(globalPsms[0].Score, 1); }
public static void AddCompIonsCommonParams() { CommonParameters cp = new CommonParameters(null, DissociationType.HCD, DissociationType.Unknown, true, true, 3, 12, true, true, 1, 5, 200, 0.01, null, null, false, false, true, false, null, null, null, -1, null, null, null, 1, true, 4, 1); var myMsDataFile = new TestDataFile(); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var localizeableModifications = new List <Modification>(); Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int ii = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)ii); ii++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)ii); ii++; } var proteinList = new List <Protein> { new Protein("MNNNKQQQ", null) }; SearchParameters SearchParameters = new SearchParameters { MassDiffAcceptorType = MassDiffAcceptorType.Exact, SearchTarget = true, }; List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("Test", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, new List <SilacLabel>(), 1, DecoyType.Reverse, cp, SearchParameters.MaxFragmentSize, false, new List <FileInfo>(), new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(cp.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); // without complementary ions PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; var mse = new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, cp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List <string>()).Run(); }
private static void WriteIndexEngineParams(IndexingEngine indexEngine, string fileName) { using (StreamWriter output = new StreamWriter(fileName)) { output.Write(indexEngine); } }
private void GenerateIndexes(IndexingEngine indexEngine, List <DbForTask> dbFilenameList, ref List <CompactPeptide> peptideIndex, ref List <int>[] fragmentIndex, string taskId) { string pathToFolderWithIndices = GetExistingFolderWithIndices(indexEngine, dbFilenameList); if (pathToFolderWithIndices == null) { var output_folderForIndices = GenerateOutputFolderForIndices(dbFilenameList); Status("Writing params...", new List <string> { taskId }); var paramsFile = Path.Combine(output_folderForIndices, "indexEngine.params"); WriteIndexEngineParams(indexEngine, paramsFile); FinishedWritingFile(paramsFile, new List <string> { taskId }); Status("Running Index Engine...", new List <string> { taskId }); var indexResults = (IndexingResults)indexEngine.Run(); peptideIndex = indexResults.PeptideIndex; fragmentIndex = indexResults.FragmentIndex; Status("Writing peptide index...", new List <string> { taskId }); var peptideIndexFile = Path.Combine(output_folderForIndices, "peptideIndex.ind"); WritePeptideIndex(peptideIndex, peptideIndexFile); FinishedWritingFile(peptideIndexFile, new List <string> { taskId }); Status("Writing fragment index...", new List <string> { taskId }); var fragmentIndexFile = Path.Combine(output_folderForIndices, "fragmentIndex.ind"); WriteFragmentIndexNetSerializer(fragmentIndex, fragmentIndexFile); FinishedWritingFile(fragmentIndexFile, new List <string> { taskId }); } else { Status("Reading peptide index...", new List <string> { taskId }); var messageTypes = GetSubclassesAndItself(typeof(List <CompactPeptide>)); var ser = new NetSerializer.Serializer(messageTypes); using (var file = File.OpenRead(Path.Combine(pathToFolderWithIndices, "peptideIndex.ind"))) peptideIndex = (List <CompactPeptide>)ser.Deserialize(file); Status("Reading fragment index...", new List <string> { taskId }); messageTypes = GetSubclassesAndItself(typeof(List <int>[])); ser = new NetSerializer.Serializer(messageTypes); using (var file = File.OpenRead(Path.Combine(pathToFolderWithIndices, "fragmentIndex.ind"))) fragmentIndex = (List <int>[])ser.Deserialize(file); } }
public static void TestModernSearchEngineTopDown() { CommonParameters CommonParameters = new CommonParameters( digestionParams: new DigestionParams(protease: "top-down"), scoreCutoff: 1, assumeOrphanPeaksAreZ1Fragments: false); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("MPKVYSYQEVAEHNGPENFWIIIDDKVYDVSQFKDEHPGGDEIIMDLGGQDATESFVDIGHSDEALRLLKGLYIGDVDKTSERVSVEKVSTSENQSKGSGTLVVILAILMLGVAYYLLNE", "P40312") }; var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TopDownTestData\slicedTDYeast.mzML")); var searchMode = new SinglePpmAroundZeroSearchMode(5); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.Reverse, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, searchMode, 0, new List <string>()).Run(); var psm = allPsmsArray.Where(p => p != null).FirstOrDefault(); Assert.That(psm.MatchedFragmentIons.Count > 50); }
public STT.Task CommitAsync(CancellationToken cancellationToken) { var state = GetCurrentIndexingActivityStatus(); SnTrace.Index.Write("LM: WriteActivityStatusToIndex: {0}", state); return(IndexingEngine.WriteActivityStatusToIndexAsync(state, cancellationToken)); }
internal static void Commit() { var state = GetCurrentIndexingActivityStatus(); SnTrace.Index.Write("LM: WriteActivityStatusToIndex: {0}", state); IndexingEngine.WriteActivityStatusToIndex(state); }
public static void TestIndexEngine() { var proteinList = new List <Protein> { new Protein("MNNNKQQQ", null) }; var variableModifications = new List <ModificationWithMass>(); var fixedModifications = new List <ModificationWithMass>(); var localizeableModifications = new List <ModificationWithMass>(); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int i = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } CommonParameters CommonParameters = new CommonParameters { DigestionParams = new DigestionParams { Protease = new Protease("Custom Protease", new List <string> { "K" }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null), MinPeptideLength = null, }, ConserveMemory = false, ScoreCutoff = 1, }; var engine = new IndexingEngine(proteinList, variableModifications, fixedModifications, new List <ProductType> { ProductType.BnoB1ions, ProductType.Y }, 1, DecoyType.Reverse, new List <IDigestionParams> { CommonParameters.DigestionParams }, CommonParameters, 30000, new List <string>()); var results = (IndexingResults)engine.Run(); Assert.AreEqual(5, results.PeptideIndex.Count); var digestedList = proteinList[0].Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).ToList(); Assert.AreEqual(5, digestedList.Count); foreach (var fdfd in digestedList) { Assert.Contains(fdfd.CompactPeptide(TerminusType.None), results.PeptideIndex); } }
private static bool SameSettings(string pathToOldParamsFile, IndexingEngine indexEngine) { using (StreamReader reader = new StreamReader(pathToOldParamsFile)) if (reader.ReadToEnd().Equals(indexEngine.ToString())) { return(true); } return(false); }
// AddTreeActivity internal static bool AddTree(string treeRoot, int activityId, bool executingUnprocessedActivities) { var delTerms = executingUnprocessedActivities ? new [] { new SnTerm(IndexFieldName.InTree, treeRoot) } : null; var excludedNodeTypes = GetNotIndexedNodeTypes(); var docs = SearchManager.LoadIndexDocumentsByPath(treeRoot, excludedNodeTypes).Select(CreateIndexDocument); IndexingEngine.WriteIndex(delTerms, null, docs); return(true); }
// RemoveTreeActivity, RebuildActivity internal static bool DeleteDocuments(IEnumerable <SnTerm> deleteTerms, VersioningInfo versioning) { IndexingEngine.WriteIndex(deleteTerms, null, null); // don't need to check if indexing interfered here. If it did, change is detected in overlapped adddocument/updatedocument, and refresh (re-delete) is called there. // deletedocuments will never detect change in index, since it sets timestamp in indexhistory to maxvalue. return(true); }
// AddTreeActivity internal static async STT.Task <bool> AddTreeAsync(string treeRoot, int activityId, bool executingUnprocessedActivities, CancellationToken cancellationToken) { var delTerms = executingUnprocessedActivities ? new [] { new SnTerm(IndexFieldName.InTree, treeRoot) } : null; var excludedNodeTypes = GetNotIndexedNodeTypes(); var docs = SearchManager.LoadIndexDocumentsByPath(treeRoot, excludedNodeTypes).Select(CreateIndexDocument); await IndexingEngine.WriteIndexAsync(delTerms, null, docs, cancellationToken).ConfigureAwait(false); return(true); }
// RemoveTreeActivity, RebuildActivity internal async STT.Task <bool> DeleteDocumentsAsync(IEnumerable <SnTerm> deleteTerms, VersioningInfo versioning, CancellationToken cancellationToken) { await IndexingEngine.WriteIndexAsync(deleteTerms, null, null, cancellationToken).ConfigureAwait(false); // Not necessary to check if indexing interfered here. If it did, change is detected in overlapped AddDocument/UpdateDocument // operations and refresh (re-delete) is called there. // Delete documents will never detect changes in index, since it sets timestamp in index history to maxvalue. return(true); }
private void WriteIndexEngineParams(IndexingEngine indexEngine, string fileName, string taskId) { using (StreamWriter output = new StreamWriter(fileName)) { output.Write(indexEngine); } FinishedWritingFile(fileName, new List <string> { taskId }); }
public static void TestIndexEngine() { var proteinList = new List <Protein> { new Protein("MNNNKQQQ", null) }; var variableModifications = new List <ModificationWithMass>(); var fixedModifications = new List <ModificationWithMass>(); var localizeableModifications = new List <ModificationWithMass>(); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int i = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } Protease p = new Protease("Custom Protease2", new List <Tuple <string, TerminusType> > { new Tuple <string, TerminusType>("K", TerminusType.C) }, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null); ProteaseDictionary.Dictionary.Add(p.Name, p); CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(protease: p.Name, minPeptideLength: 1)); var engine = new IndexingEngine(proteinList, variableModifications, fixedModifications, new List <ProductType> { ProductType.B, ProductType.Y }, 1, DecoyType.Reverse, new List <DigestionParams> { CommonParameters.DigestionParams }, CommonParameters, 30000, new List <string>()); var results = (IndexingResults)engine.Run(); Assert.AreEqual(5, results.PeptideIndex.Count); var digestedList = proteinList[0].Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).ToList(); Assert.AreEqual(5, digestedList.Count); foreach (var fdfd in digestedList) { Assert.Contains(fdfd.CompactPeptide(TerminusType.None), results.PeptideIndex); } }
public static void TestIndexEngineWithWeirdSeq() { var proteinList = new List <Protein> { new Protein("MQXQ", null) }; var variableModifications = new List <ModificationWithMass>(); var fixedModifications = new List <ModificationWithMass>(); var localizeableModifications = new List <ModificationWithMass>(); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int i = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } CommonParameters CommonParameters = new CommonParameters { DigestionParams = new DigestionParams { Protease = new Protease("Custom Protease", new List <string> { "K" }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null), MinPeptideLength = null, InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain }, ConserveMemory = false, ScoreCutoff = 1, }; var engine = new IndexingEngine(proteinList, variableModifications, fixedModifications, new List <ProductType> { ProductType.BnoB1ions, ProductType.Y }, 1, DecoyType.Reverse, new List <IDigestionParams> { CommonParameters.DigestionParams }, CommonParameters, 30000, new List <string>()); var results = (IndexingResults)engine.Run(); Assert.AreEqual(1, results.PeptideIndex.Count); Assert.IsNaN(results.PeptideIndex[0].MonoisotopicMassIncludingFixedMods); Assert.AreEqual(30000000 + 1, results.FragmentIndex.Length); }
public static void TestIndexEngineWithWeirdSeq() { var proteinList = new List <Protein> { new Protein("MQXQ", null) }; var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var localizeableModifications = new List <Modification>(); Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int i = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("Custom Protease", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters = new CommonParameters( digestionParams: new DigestionParams( protease: protease.Name, minPeptideLength: 1, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain), scoreCutoff: 1); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); var engine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, null, null, 1, DecoyType.Reverse, CommonParameters, fsp, 30000, false, new List <FileInfo>(), TargetContaminantAmbiguity.RemoveContaminant, new List <string>()); var results = (IndexingResults)engine.Run(); Assert.AreEqual(1, results.PeptideIndex.Count); Assert.IsNaN(results.PeptideIndex[0].MonoisotopicMass); Assert.AreEqual(30000000 + 1, results.FragmentIndex.Length); }
public static void TestVeryCloseExperimentalsModern() { IDictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> >(); ModificationMotif.TryGetMotif("M", out ModificationMotif motif); var prot = new Protein("MMMM", null, null, null, mods); DigestionParams digestionParams = new DigestionParams { MinPeptideLength = 1, }; var thePep = prot.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First(); var massArray = thePep.CompactPeptide(TerminusType.None).ProductMassesMightHaveDuplicatesAndNaNs(new List <ProductType> { ProductType.B, ProductType.Y }); Array.Sort(massArray); double[] intensities = new double[] { 1, 1, 1, 1 }; double[] mz = new double[] { 1, 2, massArray[4].ToMz(1), massArray[4].ToMz(1) + 1e-9 }; MzmlMzSpectrum massSpectrum = new MzmlMzSpectrum(mz, intensities, false); IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > scan = new MzmlScanWithPrecursor(1, massSpectrum, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, 0, null, null, 0, null, DissociationType.Unknown, 1, null, null, "scan=1"); PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 600, 1, null) }; CommonParameters CommonParameters = new CommonParameters { ProductMassTolerance = new PpmTolerance(5), DigestionParams = new DigestionParams { MaxMissedCleavages = 0, MinPeptideLength = null, MaxModificationIsoforms = int.MaxValue, InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain, }, ConserveMemory = false, ScoreCutoff = 1 }; var indexEngine = new IndexingEngine(new List <Protein> { prot }, new List <ModificationWithMass>(), new List <ModificationWithMass>(), new List <ProductType> { ProductType.B, ProductType.Y }, 1, DecoyType.Reverse, new List <IDigestionParams> { CommonParameters.DigestionParams }, CommonParameters, 30000, new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); var cse = new ModernSearchEngine(globalPsms, arrayOfSortedMS2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, new List <ProductType> { ProductType.B, ProductType.Y }, 0, CommonParameters, false, new OpenSearchMode(), 0, new List <string>()); cse.Run(); Assert.Less(globalPsms[0].Score, 2); Assert.Greater(globalPsms[0].Score, 1); }
public static void TestIndexEngineWithWeirdSeq() { var proteinList = new List <Protein> { new Protein("MQXQ", null) }; var variableModifications = new List <ModificationWithMass>(); var fixedModifications = new List <ModificationWithMass>(); var localizeableModifications = new List <ModificationWithMass>(); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int i = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } Protease protease = new Protease("Custom Protease", new List <Tuple <string, TerminusType> > { new Tuple <string, TerminusType>("K", TerminusType.C) }, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters = new CommonParameters( digestionParams: new DigestionParams( protease: protease.Name, minPeptideLength: 1, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain), scoreCutoff: 1); var engine = new IndexingEngine(proteinList, variableModifications, fixedModifications, new List <ProductType> { ProductType.B, ProductType.Y }, 1, DecoyType.Reverse, new List <DigestionParams> { CommonParameters.DigestionParams }, CommonParameters, 30000, new List <string>()); var results = (IndexingResults)engine.Run(); Assert.AreEqual(1, results.PeptideIndex.Count); Assert.IsNaN(results.PeptideIndex[0].MonoisotopicMassIncludingFixedMods); Assert.AreEqual(30000000 + 1, results.FragmentIndex.Length); }
/* AddDocumentActivity, RebuildActivity */ internal static bool AddDocument(IndexDocument document, VersioningInfo versioning) { var delTerms = versioning.Delete.Select(i => new SnTerm(IndexFieldName.VersionId, i)).ToArray(); var updates = GetUpdates(versioning); if (document != null) { SetDocumentFlags(document, versioning); } IndexingEngine.WriteIndex(delTerms, updates, new[] { document }); return(true); }
/* AddDocumentActivity, RebuildActivity */ internal async STT.Task <bool> AddDocumentAsync(IndexDocument document, VersioningInfo versioning, CancellationToken cancellationToken) { var delTerms = versioning.Delete.Select(i => new SnTerm(IndexFieldName.VersionId, i)).ToArray(); var updates = GetUpdates(versioning); if (document != null) { SetDocumentFlags(document, versioning); } await IndexingEngine.WriteIndexAsync(delTerms, updates, new[] { document }, cancellationToken).ConfigureAwait(false); return(true); }
public string GetFooterText(string myCurrentIndexFilePath, IndexingEngine myEngine, bool html) { string appName = string.Format("{0} v{1}", Application.ProductName, Application.ProductVersion); string appUrl = "http://code.google.com/p/zscreen"; string strDateTime; if (mOptions.IndexedTimeInUTC) { strDateTime = DateTime.UtcNow.ToString("yyyy-MM-dd 'at' HH:mm:ss 'UTC'"); } else { strDateTime = DateTime.Now.ToString("yyyy-MM-dd 'at ' HH:mm:ss 'local time'"); } if (html) { appName = Xhtml.MakeAnchor(appUrl, appName); } string footer = string.Format("Generated on {0} using {1}", strDateTime, appName); if (html) { if (mConfig.ShowValidXhtmlIcons) { footer += GetText("valid_xhtml.txt"); } } else { footer += "\r\nLatest version of can be downloaded from " + appUrl; } switch (myEngine) { case IndexingEngine.TreeLib: return("ECHO " + footer + " >> " + (char)34 + myCurrentIndexFilePath + (char)34); default: return(footer); } }
/// <summary> /// Shuts down the indexing feature: stops CommitManager, indexing activity organizator and IndexingEngine. /// </summary> public static void ShutDown() { CommitManager?.ShutDown(); if (IndexingEngine == null) { return; } if (IndexingEngine.IndexIsCentralized) { CentralizedIndexingActivityQueue.ShutDown(); } else { DistributedIndexingActivityQueue.ShutDown(); } IndexingEngine.ShutDown(); SnLog.WriteInformation("Indexing engine has stopped. Max task id and exceptions: " + DistributedIndexingActivityQueue.GetCurrentCompletionState()); }
/// <summary> /// Initializes the indexing feature: starts the IndexingEngine, CommitManager and indexing activity organizator. /// If "consoleOut" is not null, writes progress and debug messages into it. /// </summary> /// <param name="consoleOut">A <see cref="TextWriter"/> instance or null.</param> public static void Start(TextWriter consoleOut) { IndexingEngine.Start(consoleOut); CommitManager = IndexingEngine.IndexIsCentralized ? (ICommitManager) new NoDelayCommitManager() : new NearRealTimeCommitManager(); SnTrace.Index.Write("LM: {0} created.", CommitManager.GetType().Name); CommitManager.Start(); if (IndexingEngine.IndexIsCentralized) { CentralizedIndexingActivityQueue.Startup(consoleOut); } else { DistributedIndexingActivityQueue.Startup(consoleOut); } }
/// <summary> /// Initializes the indexing feature: starts the IndexingEngine, CommitManager and indexing activity organizer. /// If "consoleOut" is not null, writes progress and debug messages into it. /// </summary> /// <param name="consoleOut">A <see cref="TextWriter"/> instance or null.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is None.</param> /// <returns>A Task that represents the asynchronous operation.</returns> public static async STT.Task StartAsync(TextWriter consoleOut, CancellationToken cancellationToken) { await IndexingEngine.StartAsync(consoleOut, cancellationToken).ConfigureAwait(false); CommitManager = IndexingEngine.IndexIsCentralized ? (ICommitManager) new NoDelayCommitManager() : new NearRealTimeCommitManager(); SnTrace.Index.Write("LM: {0} created.", CommitManager.GetType().Name); CommitManager.Start(); if (IndexingEngine.IndexIsCentralized) { CentralizedIndexingActivityQueue.Startup(consoleOut); } else { DistributedIndexingActivityQueue.Startup(consoleOut); } }
private string GetExistingFolderWithIndices(IndexingEngine indexEngine, List <DbForTask> dbFilenameList) { // In every database location... foreach (var ok in dbFilenameList) { var baseDir = Path.GetDirectoryName(ok.FilePath); var directory = new DirectoryInfo(baseDir); DirectoryInfo[] directories = directory.GetDirectories(); // Look at every subdirectory... foreach (DirectoryInfo possibleFolder in directories) { if (File.Exists(Path.Combine(possibleFolder.FullName, "indexEngine.params")) && File.Exists(Path.Combine(possibleFolder.FullName, "peptideIndex.ind")) && File.Exists(Path.Combine(possibleFolder.FullName, "fragmentIndex.ind")) && SameSettings(Path.Combine(possibleFolder.FullName, "indexEngine.params"), indexEngine)) { return(possibleFolder.FullName); } } } return(null); }
public void ShutDown() { CommitManager?.ShutDown(); if (IndexingEngine == null) { return; } //TODO: [async] rewrite this using async APIs. if (IndexingEngine.IndexIsCentralized) { CentralizedIndexingActivityQueue.ShutDown(); } else { DistributedIndexingActivityQueue.ShutDown(); } //TODO: [async] rewrite this using async APIs. IndexingEngine.ShutDownAsync(CancellationToken.None).GetAwaiter().GetResult(); SnLog.WriteInformation("Indexing engine has stopped. Max task id and exceptions: " + DistributedIndexingActivityQueue.GetCurrentCompletionState()); }
public static void TestDeltaValues() { CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, useDeltaScore: true, digestionParams: new DigestionParams(minPeptideLength: 5)); SearchParameters SearchParameters = new SearchParameters { MassDiffAcceptorType = MassDiffAcceptorType.Exact, }; List <Modification> variableModifications = GlobalVariables.AllModsKnown.OfType <Modification>().Where(b => CommonParameters.ListOfModsVariable.Contains((b.ModificationType, b.IdWithMotif))).ToList(); List <Modification> fixedModifications = GlobalVariables.AllModsKnown.OfType <Modification>().Where(b => CommonParameters.ListOfModsFixed.Contains((b.ModificationType, b.IdWithMotif))).ToList(); // Generate data for files Protein TargetProtein1 = new Protein("TIDEANTHE", "accession1"); Protein TargetProtein2 = new Protein("TIDELVE", "accession2"); Protein TargetProtein3 = new Protein("TIDENIE", "accession3"); Protein TargetProteinLost = new Protein("PEPTIDEANTHE", "accession4"); Protein DecoyProteinFound = new Protein("PETPLEDQGTHE", "accessiond", isDecoy: true); MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { TargetProtein1.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], TargetProtein2.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], TargetProtein3.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], DecoyProteinFound.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0] }); var proteinList = new List <Protein> { TargetProtein1, TargetProtein2, TargetProtein3, TargetProteinLost, DecoyProteinFound }; var searchModes = new SinglePpmAroundZeroSearchMode(5); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); //check better when using delta PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, proteinList, searchModes, CommonParameters, new List <string>()).Run(); var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.None, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); PeptideSpectralMatch[] allPsmsArrayModern = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArrayModern, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, massDiffAcceptor, 0, new List <string>()).Run(); FdrAnalysisResults fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run()); FdrAnalysisResults fdrResultsModernDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run()); Assert.IsTrue(fdrResultsClassicDelta.PsmsWithin1PercentFdr == 3); Assert.IsTrue(fdrResultsModernDelta.PsmsWithin1PercentFdr == 3); CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5)); //check worse when using score FdrAnalysisResults fdrResultsClassic = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run()); FdrAnalysisResults fdrResultsModern = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run()); Assert.IsTrue(fdrResultsClassic.PsmsWithin1PercentFdr == 0); Assert.IsTrue(fdrResultsModern.PsmsWithin1PercentFdr == 0); //check that when delta is bad, we used the score // Generate data for files Protein DecoyProtein1 = new Protein("TLEDAGGTHE", "accession1d", isDecoy: true); Protein DecoyProtein2 = new Protein("TLEDLVE", "accession2d", isDecoy: true); Protein DecoyProtein3 = new Protein("TLEDNIE", "accession3d", isDecoy: true); Protein DecoyProteinShiny = new Protein("GGGGGG", "accessionShinyd", isDecoy: true); myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { TargetProtein1.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], TargetProtein2.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], TargetProtein3.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], DecoyProteinShiny.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0], }); proteinList = new List <Protein> { TargetProtein1, DecoyProtein1, TargetProtein2, DecoyProtein2, TargetProtein3, DecoyProtein3, DecoyProteinShiny, }; listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); //check no change when using delta allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, proteinList, searchModes, CommonParameters, new List <string>()).Run(); CommonParameters = new CommonParameters(useDeltaScore: true, digestionParams: new DigestionParams(minPeptideLength: 5)); indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.None, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>()); indexResults = (IndexingResults)indexEngine.Run(); massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); allPsmsArrayModern = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArrayModern, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, massDiffAcceptor, 0, new List <string>()).Run(); fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run()); fdrResultsModernDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run()); Assert.IsTrue(fdrResultsClassicDelta.PsmsWithin1PercentFdr == 3); Assert.IsTrue(fdrResultsModernDelta.PsmsWithin1PercentFdr == 3); CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5)); //check no change when using score fdrResultsClassic = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run()); fdrResultsModern = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run()); Assert.IsTrue(fdrResultsClassic.PsmsWithin1PercentFdr == 3); Assert.IsTrue(fdrResultsModern.PsmsWithin1PercentFdr == 3); }
public static void TestCompIons_ModernSearch() { var myMsDataFile = new TestDataFile(); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var localizeableModifications = new List <Modification>(); Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int ii = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)ii); ii++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)ii); ii++; } var proteinList = new List <Protein> { new Protein("MNNNKQQQ", null) }; SearchParameters SearchParameters = new SearchParameters { MassDiffAcceptorType = MassDiffAcceptorType.Exact, SearchTarget = true, }; List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("singleN4", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams(protease: protease.Name, minPeptideLength: 1), scoreCutoff: 1); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); CommonParameters withCompIons = new CommonParameters(digestionParams: new DigestionParams(protease: protease.Name, minPeptideLength: 1), scoreCutoff: 1, addCompIons: true); var fspComp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fspComp.Add(("", CommonParameters)); var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, null, null, 1, DecoyType.Reverse, CommonParameters, fsp, SearchParameters.MaxFragmentSize, false, new List <FileInfo>(), TargetContaminantAmbiguity.RemoveContaminant, new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); // without complementary ions PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List <string>()).Run(); // with complementary ions PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List <string>()).Run(); // Single search mode Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length); // Single ms2 scan Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length); Assert.That(allPsmsArray[0] != null); Assert.That(allPsmsArray2[0] != null); Assert.IsTrue(allPsmsArray2[0].Score > 1); Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber); Assert.IsTrue(allPsmsArray2[0].Score <= allPsmsArray[0].Score * 2 && allPsmsArray2[0].Score > allPsmsArray[0].Score + 3); }
public static void TestIndexEngine() { var proteinList = new List <Protein> { new Protein("MNNNKQQQ", null) }; var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var localizeableModifications = new List <Modification>(); Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, ushort>(); foreach (var mod in fixedModifications) { modsDictionary.Add(mod, 0); } int i = 1; foreach (var mod in variableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } foreach (var mod in localizeableModifications) { modsDictionary.Add(mod, (ushort)i); i++; } List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease p = new Protease("Custom Protease2", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(p.Name, p); CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(protease: p.Name, minPeptideLength: 1)); var engine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.None, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>()); var results = (IndexingResults)engine.Run(); Assert.AreEqual(5, results.PeptideIndex.Count); var digestedList = proteinList[0].Digest(CommonParameters.DigestionParams, new List <Modification>(), variableModifications).ToList(); Assert.AreEqual(5, digestedList.Count); foreach (PeptideWithSetModifications peptide in digestedList) { Assert.Contains(peptide, results.PeptideIndex); var fragments = peptide.Fragment(CommonParameters.DissociationType, FragmentationTerminus.Both).ToList(); int positionInPeptideIndex = results.PeptideIndex.IndexOf(peptide); foreach (Product fragment in fragments) { // mass of the fragment double fragmentMass = fragment.NeutralMass; int integerMassRepresentation = (int)Math.Round(fragmentMass * 1000); // look up the peptides that have fragments with this mass // the result of the lookup is a list of peptide IDs that have this fragment mass List <int> fragmentBin = results.FragmentIndex[integerMassRepresentation]; // this list should contain this peptide! Assert.Contains(positionInPeptideIndex, fragmentBin); } } }
public string GetFooterText(string myCurrentIndexFilePath, IndexingEngine myEngine, bool html) { string appName = string.Format("{0} v{1}", Application.ProductName, Application.ProductVersion); string appUrl = "http://code.google.com/p/sharexmod"; string strDateTime; if (mOptions.IndexedTimeInUTC) { strDateTime = DateTime.UtcNow.ToString("yyyy-MM-dd 'at' HH:mm:ss 'UTC'"); } else { strDateTime = DateTime.Now.ToString("yyyy-MM-dd 'at ' HH:mm:ss 'local time'"); } if (html) { appName = Xhtml.MakeAnchor(appUrl, appName); } StringBuilder footer = new StringBuilder(); if (html) { footer.Append(string.Format("Generated on {0} using {1}", strDateTime, appName)); if (mConfig.ShowValidXhtmlIcons) { footer.Append(GetText("valid_xhtml.txt")); } } else { footer.AppendLine(GetTreeWalkerEchoLine(myCurrentIndexFilePath, string.Format("Generated on {0} using {1}", strDateTime, appName))); footer.AppendLine(GetTreeWalkerEchoLine(myCurrentIndexFilePath, "Latest version of can be downloaded from " + appUrl)); } return footer.ToString(); }
public string GetFooterText(string myCurrentIndexFilePath, IndexingEngine myEngine, bool html) { string appName = string.Format("{0} v{1}", Application.ProductName, Application.ProductVersion); string appUrl = "http://code.google.com/p/zscreen"; string strDateTime; if (mOptions.IndexedTimeInUTC) { strDateTime = DateTime.UtcNow.ToString("yyyy-MM-dd 'at' HH:mm:ss 'UTC'"); } else { strDateTime = DateTime.Now.ToString("yyyy-MM-dd 'at ' HH:mm:ss 'local time'"); } if (html) { appName = Xhtml.MakeAnchor(appUrl, appName); } string footer = string.Format("Generated on {0} using {1}", strDateTime, appName); if (html) { if (mConfig.ShowValidXhtmlIcons) { footer += GetText("valid_xhtml.txt"); } } else { footer += "\r\nLatest version of can be downloaded from " + appUrl; } switch (myEngine) { case IndexingEngine.TreeLib: return "ECHO " + footer + " >> " + (char)34 + myCurrentIndexFilePath + (char)34; default: return footer; } }