本文整理汇总了C#中SrmDocument.ChangeAll方法的典型用法代码示例。如果您正苦于以下问题:C# SrmDocument.ChangeAll方法的具体用法?C# SrmDocument.ChangeAll怎么用?C# SrmDocument.ChangeAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SrmDocument
的用法示例。
在下文中一共展示了SrmDocument.ChangeAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MinimizeLibraries
/// <summary>
/// Minimizes all libraries in a document to produce a new document with
/// just the library information necessary for the spectra referenced by
/// the nodes in the document.
/// </summary>
/// <param name="document">Document for which to minimize library information</param>
/// <param name="pathDirectory">Directory into which new minimized libraries are built</param>
/// <param name="nameModifier">A name modifier to append to existing names for
/// full libraries to create new library names</param>
/// <param name="progressMonitor">Broker to communicate status and progress</param>
/// <returns>A new document instance with minimized libraries</returns>
public static SrmDocument MinimizeLibraries(SrmDocument document,
string pathDirectory, string nameModifier, IProgressMonitor progressMonitor)
{
var settings = document.Settings;
var pepLibraries = settings.PeptideSettings.Libraries;
if (!pepLibraries.HasLibraries)
return document;
if (!pepLibraries.IsLoaded)
throw new InvalidOperationException(Resources.BlibDb_MinimizeLibraries_Libraries_must_be_fully_loaded_before_they_can_be_minimzed);
// Separate group nodes by the libraries to which they refer
var setUsedLibrarySpecs = new HashSet<LibrarySpec>();
foreach (var librarySpec in pepLibraries.LibrarySpecs)
{
string libraryName = librarySpec.Name;
if (document.MoleculeTransitionGroups.Contains(nodeGroup =>
nodeGroup.HasLibInfo && Equals(nodeGroup.LibInfo.LibraryName, libraryName)))
{
setUsedLibrarySpecs.Add(librarySpec);
}
}
var listLibraries = new List<Library>();
var listLibrarySpecs = new List<LibrarySpec>();
var dictOldNameToNew = new Dictionary<string, string>();
if (setUsedLibrarySpecs.Count > 0)
{
Directory.CreateDirectory(pathDirectory);
var usedNames = new HashSet<string>();
for (int i = 0; i < pepLibraries.LibrarySpecs.Count; i++)
{
var librarySpec = pepLibraries.LibrarySpecs[i];
if (!setUsedLibrarySpecs.Contains(librarySpec))
continue;
string baseName = Path.GetFileNameWithoutExtension(librarySpec.FilePath);
string fileName = GetUniqueName(baseName, usedNames) + BiblioSpecLiteSpec.EXT;
using (var blibDb = CreateBlibDb(Path.Combine(pathDirectory, fileName)))
{
blibDb.ProgressMonitor = progressMonitor;
var librarySpecMin = librarySpec as BiblioSpecLiteSpec;
if (librarySpecMin == null || !librarySpecMin.IsDocumentLibrary)
{
string nameMin = librarySpec.Name;
// Avoid adding the modifier a second time, if it has
// already been done once.
if (!nameMin.EndsWith(nameModifier + ")")) // Not L10N
nameMin = string.Format("{0} ({1})", librarySpec.Name, nameModifier); // Not L10N
librarySpecMin = new BiblioSpecLiteSpec(nameMin, blibDb.FilePath);
}
listLibraries.Add(blibDb.MinimizeLibrary(librarySpecMin,
pepLibraries.Libraries[i], document));
// Terminate if user canceled
if (progressMonitor != null && progressMonitor.IsCanceled)
return document;
listLibrarySpecs.Add(librarySpecMin);
dictOldNameToNew.Add(librarySpec.Name, librarySpecMin.Name);
}
}
document = (SrmDocument) document.ChangeAll(node =>
{
var nodeGroup = node as TransitionGroupDocNode;
if (nodeGroup == null || !nodeGroup.HasLibInfo)
return node;
string libName = nodeGroup.LibInfo.LibraryName;
string libNameNew = dictOldNameToNew[libName];
if (Equals(libName, libNameNew))
return node;
var libInfo = nodeGroup.LibInfo.ChangeLibraryName(libNameNew);
return nodeGroup.ChangeLibInfo(libInfo);
},
(int) SrmDocument.Level.TransitionGroups);
}
return document.ChangeSettingsNoDiff(settings.ChangePeptideLibraries(
lib => lib.ChangeLibraries(listLibrarySpecs, listLibraries)));
}