本文整理汇总了C#中Library.TryLoadSpectrum方法的典型用法代码示例。如果您正苦于以下问题:C# Library.TryLoadSpectrum方法的具体用法?C# Library.TryLoadSpectrum怎么用?C# Library.TryLoadSpectrum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library
的用法示例。
在下文中一共展示了Library.TryLoadSpectrum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckLibrary
private static void CheckLibrary(Library lib, int minPeaks)
{
Assert.IsNotNull(lib);
Assert.IsTrue(lib.IsLoaded);
foreach (var key in KEYS_LIB_YEAST_NIST)
{
SpectrumHeaderInfo info;
Assert.IsTrue(lib.TryGetLibInfo(key, out info));
SpectrumPeaksInfo peaksInfo;
Assert.IsTrue(lib.TryLoadSpectrum(key, out peaksInfo));
Assert.IsTrue(peaksInfo.Peaks.Length >= minPeaks);
}
}
示例2: Write
/// <summary>
/// Test only method for creating a <see cref="BiblioSpecLibrary"/> file
/// from another loaded <see cref="Library"/>. Should this move into test project?
/// </summary>
/// <param name="streamManager">Provides access to the file system</param>
/// <param name="path">Path to write to</param>
/// <param name="library">The loaded library to use as a data source</param>
public static void Write(IStreamManager streamManager, string path, Library library)
{
using (FileSaver fs = new FileSaver(path, streamManager))
using (Stream outStream = streamManager.CreateStream(fs.SafeName, FileMode.Create, true))
{
outStream.Write(BitConverter.GetBytes(library.SpectrumCount), 0, sizeof(int)); // num_spectra
outStream.Write(BitConverter.GetBytes(0), 0, sizeof(int)); // filtered
outStream.Write(BitConverter.GetBytes(1), 0, sizeof(int)); // version1
outStream.Write(BitConverter.GetBytes(1), 0, sizeof(int)); // version2
outStream.Write(BitConverter.GetBytes(0), 0, sizeof(int)); // next_id
SequenceMassCalc calc = new SequenceMassCalc(MassType.Monoisotopic);
byte[] seqBuffer = new byte[1024];
int scanNum = 1;
foreach (var key in library.Keys)
{
SpectrumPeaksInfo peaksInfo;
if (!library.TryLoadSpectrum(key, out peaksInfo))
continue;
string sequence = key.Sequence;
// Only works for unmodified sequence
Debug.Assert(!key.IsModified);
double precursorMH = calc.GetPrecursorMass(sequence);
int charge = key.Charge;
float precursorMz = (float) SequenceMassCalc.GetMZ(precursorMH, charge);
outStream.Write(BitConverter.GetBytes(scanNum), 0, sizeof(int)); // scan_num
outStream.Write(BitConverter.GetBytes(2), 0, sizeof(int)); // scan_type
outStream.Write(BitConverter.GetBytes(precursorMz), 0, sizeof(float)); // pre_mz
outStream.Write(BitConverter.GetBytes(charge), 0, sizeof(int)); // scan_type
outStream.Write(BitConverter.GetBytes(0f), 0, sizeof(int)); // r_time
outStream.Write(BitConverter.GetBytes(peaksInfo.Peaks.Length), 0, sizeof(int)); // num_peaks
outStream.Write(BitConverter.GetBytes(0), 0, sizeof(int)); // 32-bit peak_ptr
outStream.Write(BitConverter.GetBytes(sequence.Length), 0, sizeof(int)); // seq_len
outStream.Write(BitConverter.GetBytes(0), 0, sizeof(int)); // annot
outStream.Write(BitConverter.GetBytes(scanNum), 0, sizeof(int)); // copies (bogus value for ranking)
outStream.Write(BitConverter.GetBytes(0), 0, sizeof(int)); // lib_id
scanNum++;
// Sequence
int len = sequence.Length;
seqBuffer[len] = 0;
Encoding.UTF8.GetBytes(sequence, 0, len, seqBuffer, 0);
outStream.Write(seqBuffer, 0, len + 1);
// Modifications
const string zeros = "000000000000000000000000000000000000000000000000000"; // Not L10N
Encoding.UTF8.GetBytes(zeros.Substring(0, len), 0, len, seqBuffer, 0);
outStream.Write(seqBuffer, 0, len + 1);
// Peaks
foreach (var mi in peaksInfo.Peaks)
{
outStream.Write(BitConverter.GetBytes((float)mi.Mz), 0, sizeof(float));
outStream.Write(BitConverter.GetBytes(mi.Intensity), 0, sizeof(float));
}
}
streamManager.Finish(outStream);
fs.Commit();
}
}