Skip to content

Commit

Permalink
add option to extract resolution data for orbitrap scans
Browse files Browse the repository at this point in the history
  • Loading branch information
rrad committed Jan 23, 2025
1 parent 29edae1 commit 756d26a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Monocle.CLI/MakeMonoOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ public class MakeMonoOptions

[Option("Ms2Ms3Precursor", Hidden = true, Required = false, HelpText = "Assign precursors to the ms3 scan from the parent ms2.")]
public bool Ms2Ms3Precursor { get; set; } = false;

[Option("Resolution", Hidden = true, Required = false, HelpText = "Extract resolution from all scans with resolution information.")]
public bool Resolution { get; set; } = false;
}
}
4 changes: 3 additions & 1 deletion Monocle.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ static void Main(string[] args)
ForceCharges = options.ForceCharges,
UseMostIntense = options.UseMostIntense,
Ms2Ms3Precursor = options.Ms2Ms3Precursor,
RawMonoMz = options.RawMonoMz
RawMonoMz = options.RawMonoMz,
Resolution = options.Resolution,
};

var readerOptions = new ScanReaderOptions();
readerOptions.Resolution = monocleOptions.Resolution;

SetupLogger(options.RunQuiet, options.WriteDebug);

Expand Down
15 changes: 15 additions & 0 deletions Monocle/Data/Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ public class Scan : IDisposable
/// If a dependent scan, the activation method used to generate the scan fragments
/// </summary>
public string PrecursorActivationMethod { get; set; } = "";

/// <summary>
/// Whether the Centroids list has baseline data
/// </summary>
public bool HasBaseline { get; set; }

/// <summary>
/// Whether the Centroids list has noise data
/// </summary>
public bool HasNoise { get; set; }

/// <summary>
/// Whether the Centroids list has resolution data
/// </summary>
public bool HasResolution { get; set; }

/// <summary>
/// The observed centroid peaks in the scan
Expand Down
10 changes: 10 additions & 0 deletions Monocle/File/MzDBReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ private void DecodePeaks(Scan scan, int flags, byte[] data) {
}
scan.Centroids.Add(centroid);
}

if ((flags & MzDBWriter.HAS_BASELINE) != 0) {
scan.HasBaseline = true;
}
if ((flags & MzDBWriter.HAS_NOISE) != 0) {
scan.HasNoise = true;
}
if ((flags & MzDBWriter.HAS_RESOLUTION) != 0) {
scan.HasResolution = true;
}
}

private byte[] DecompressData(byte[] data) {
Expand Down
30 changes: 17 additions & 13 deletions Monocle/File/MzDBWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class MzDBWriter : IScanWriter
/// <param name="path">Path to the SQLite db file</param>
public void Open(string path)
{
// Overwrite existing.
if (System.IO.File.Exists(path)) {
System.IO.File.Delete(path);
}

db = new SqliteConnection($"Data Source={path}");
db.Open();

Expand Down Expand Up @@ -225,9 +230,9 @@ public void WriteScan(Scan scan)
peakInsert.Parameters.AddWithValue("$id", ++peakIndex);
peakInsert.Parameters.AddWithValue("$scan", scan.ScanNumber);
peakInsert.Parameters.AddWithValue("$peak_count", scan.Centroids.Count);
peakInsert.Parameters.AddWithValue("$data_type", getPeakFlags(scan));
peakInsert.Parameters.AddWithValue("$data_type", GetPeakFlags(scan));
// skipping compression for now.
peakInsert.Parameters.AddWithValue("$data", encodePeaks(scan));
peakInsert.Parameters.AddWithValue("$data", EncodePeaks(scan));
peakInsert.ExecuteNonQuery();

foreach(Precursor precursor in scan.Precursors) {
Expand All @@ -252,15 +257,15 @@ public void WriteScan(Scan scan)
/// </summary>
/// <param name="scan">The scan with the peak data.</param>
/// <returns>An integer with the flags for the type of data stored.</returns>
private int getPeakFlags(Scan scan) {
private int GetPeakFlags(Scan scan) {
int output = 0;
if (scan.DetectorType == "FTMS" || scan.DetectorType == "ASTMS") {
if (scan.HasBaseline && scan.HasNoise) {
output = HAS_MZ_DOUBLE | HAS_INTENSITY | HAS_BASELINE | HAS_NOISE;
}
else {
output = HAS_MZ_FLOAT | HAS_INTENSITY;
}
if (scan.DetectorType == "ASTMS") {
if (scan.HasResolution) {
output |= HAS_RESOLUTION;
}
return output;
Expand All @@ -271,7 +276,7 @@ private int getPeakFlags(Scan scan) {
/// </summary>
/// <param name="scan">The scan with the peaks to store</param>
/// <returns>A byte array with the peak data.</returns>
private byte[] encodePeaks(Scan scan) {
private byte[] EncodePeaks(Scan scan) {
int peakCount = scan.Centroids.Count;
double[] mz = new double[peakCount];
float[] all = new float[peakCount * 5];
Expand All @@ -294,16 +299,16 @@ private byte[] encodePeaks(Scan scan) {
int resolutionBytes = peakCount * sizeof(uint);

byte[] output = null;
if (scan.DetectorType == "FTMS") {
output = new byte[mzDoubleBytes + intensityBytes + baselineBytes + noiseBytes];
Buffer.BlockCopy(mz, 0, output, 0, mzDoubleBytes);
Buffer.BlockCopy(all, mzFloatBytes, output, mzDoubleBytes, intensityBytes + baselineBytes + noiseBytes);
}
else if (scan.DetectorType == "ASTMS") {
if (scan.HasResolution && scan.HasBaseline && scan.HasNoise) {
// BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count);
output = new byte[mzDoubleBytes + intensityBytes + baselineBytes + noiseBytes + resolutionBytes];
Buffer.BlockCopy(mz, 0, output, 0, mzDoubleBytes);
Buffer.BlockCopy(all, mzFloatBytes, output, mzDoubleBytes, intensityBytes + baselineBytes + noiseBytes);
Buffer.BlockCopy(resolution, 0, output, mzDoubleBytes + intensityBytes + baselineBytes + noiseBytes, resolutionBytes);
} else if (scan.HasBaseline && scan.HasNoise) {
output = new byte[mzDoubleBytes + intensityBytes + baselineBytes + noiseBytes];
Buffer.BlockCopy(mz, 0, output, 0, mzDoubleBytes);
Buffer.BlockCopy(all, mzFloatBytes, output, mzDoubleBytes, intensityBytes + baselineBytes + noiseBytes);
}
else {
output = new byte[mzFloatBytes + intensityBytes];
Expand All @@ -330,6 +335,5 @@ public static byte[] CompressData(byte[] data)
}
}
}

}

13 changes: 13 additions & 0 deletions Monocle/File/RawReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ public void CentroidsFromArrays(
}
scan.Centroids.Add(tempCentroid);
}

if (baselines != null)
{
scan.HasBaseline = true;
}
if (noises != null)
{
scan.HasNoise = true;
}
if ((scan.DetectorType == "ASTMS" || Options.Resolution) && resolutions != null)
{
scan.HasResolution = true;
}
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Monocle/File/ScanReaderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ namespace Monocle.File
{
public class ScanReaderOptions
{
/// Deprecated. Use member in MonocleOptions instead.
public bool RawMonoMz = false;
/// Extract resolution information for every scan that has
/// resolution information. Resolution for ASTMS will always
/// be extracted.
public bool Resolution = false;
}

}
7 changes: 7 additions & 0 deletions Monocle/MonocleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public int MS_Level
/// </summary>
public bool RawMonoMz { get; set; } = false;

/// <summary>
/// If set to true, Resolution data will be extracted from all scans
/// that have resolution data (Orbitrap, Astral).
/// Requires mzdb format for output.
/// </summary>
public bool Resolution { get; set; } = false;

/// <summary>
/// Allow get/set of property based on property name
/// </summary>
Expand Down

0 comments on commit 756d26a

Please sign in to comment.