diff --git a/src/Common/CommonStandard/DataObj/RawDataMetadata.cs b/src/Common/CommonStandard/DataObj/RawDataMetadata.cs new file mode 100644 index 000000000..503e11687 --- /dev/null +++ b/src/Common/CommonStandard/DataObj/RawDataMetadata.cs @@ -0,0 +1,284 @@ +using System; +using System.Collections.Generic; + +namespace CompMs.Common.DataObj { + public enum RawDataVendor { + Unknown, + Agilent, + Bruker, + Sciex, + Shimadzu, + ThermoFisher, + Waters, + OpenFormat, + } + + public enum MetadataSource { + Unknown, + VendorHeader, + SpectrumHeader, + SpectrumStatistics, + FileName, + Repository, + User, + Derived, + } + + public enum RawPolarityMode { + Unknown, + Positive, + Negative, + PolaritySwitching, + MixedFunctions, + } + + public enum RawAcquisitionMethod { + Unknown, + FullScan, + DDA, + DIA, + AIF, + SIM, + SRM, + MRM, + PRM, + } + + public enum RawSeparationTechnique { + Unknown, + DirectInfusion, + LiquidChromatography, + GasChromatography, + CapillaryElectrophoresis, + } + + public enum RawSampleType { + Unknown, + Sample, + Blank, + QualityControl, + Standard, + } + + public sealed class MetadataValue { + public MetadataValue() { + Value = default(T); + Source = MetadataSource.Unknown; + Evidence = string.Empty; + } + + public MetadataValue(T value, MetadataSource source, double confidence, string evidence = "") { + Value = value; + Source = source; + Confidence = NormalizeConfidence(confidence); + Evidence = evidence ?? string.Empty; + } + + public T Value { get; set; } + public MetadataSource Source { get; set; } + public double Confidence { get; set; } + public string Evidence { get; set; } + + private static double NormalizeConfidence(double confidence) { + if (confidence < 0d) return 0d; + if (confidence > 1d) return 1d; + return confidence; + } + } + + public sealed class RawSourceMetadata { + public RawSourceMetadata() { + FilePath = string.Empty; + FileName = string.Empty; + NativeFormat = string.Empty; + ReaderName = string.Empty; + ReaderVersion = string.Empty; + VendorSdkVersion = string.Empty; + } + + public string FilePath { get; set; } + public string FileName { get; set; } + public string NativeFormat { get; set; } + public RawDataVendor Vendor { get; set; } + public string ReaderName { get; set; } + public string ReaderVersion { get; set; } + public string VendorSdkVersion { get; set; } + } + + public sealed class RawInstrumentMetadata { + public RawInstrumentMetadata() { + Manufacturer = new MetadataValue(); + Model = new MetadataValue(); + Name = new MetadataValue(); + SerialNumber = new MetadataValue(); + IonAnalyzer = new MetadataValue(); + IonSource = new MetadataValue(); + Detector = new MetadataValue(); + SoftwareVersion = new MetadataValue(); + FirmwareVersion = new MetadataValue(); + } + + public MetadataValue Manufacturer { get; set; } + public MetadataValue Model { get; set; } + public MetadataValue Name { get; set; } + public MetadataValue SerialNumber { get; set; } + public MetadataValue IonAnalyzer { get; set; } + public MetadataValue IonSource { get; set; } + public MetadataValue Detector { get; set; } + public MetadataValue SoftwareVersion { get; set; } + public MetadataValue FirmwareVersion { get; set; } + } + + public sealed class RawRunMetadata { + public RawRunMetadata() { + AcquisitionStartTime = new MetadataValue(); + Operator = new MetadataValue(); + Description = new MetadataValue(); + AcquisitionMethodName = new MetadataValue(); + ProcessingMethodName = new MetadataValue(); + ScanCount = new MetadataValue(); + StartTimeMinutes = new MetadataValue(); + EndTimeMinutes = new MetadataValue(); + LowestMz = new MetadataValue(); + HighestMz = new MetadataValue(); + } + + public MetadataValue AcquisitionStartTime { get; set; } + public MetadataValue Operator { get; set; } + public MetadataValue Description { get; set; } + public MetadataValue AcquisitionMethodName { get; set; } + public MetadataValue ProcessingMethodName { get; set; } + public MetadataValue ScanCount { get; set; } + public MetadataValue StartTimeMinutes { get; set; } + public MetadataValue EndTimeMinutes { get; set; } + public MetadataValue LowestMz { get; set; } + public MetadataValue HighestMz { get; set; } + } + + public sealed class RawAcquisitionMetadata { + public RawAcquisitionMetadata() { + Polarity = new MetadataValue(); + Method = new MetadataValue(); + Separation = new MetadataValue(); + HasIonMobility = new MetadataValue(); + HasImaging = new MetadataValue(); + HasMs1 = new MetadataValue(); + HasMs2 = new MetadataValue(); + SpectrumRepresentation = new MetadataValue(); + CollisionEnergies = new List(); + IsolationWindowTargets = new List(); + MsLevels = new List(); + } + + public MetadataValue Polarity { get; set; } + public MetadataValue Method { get; set; } + public MetadataValue Separation { get; set; } + public MetadataValue HasIonMobility { get; set; } + public MetadataValue HasImaging { get; set; } + public MetadataValue HasMs1 { get; set; } + public MetadataValue HasMs2 { get; set; } + public MetadataValue SpectrumRepresentation { get; set; } + public List CollisionEnergies { get; set; } + public List IsolationWindowTargets { get; set; } + public List MsLevels { get; set; } + } + + public sealed class RawSampleMetadata { + public RawSampleMetadata() { + Id = new MetadataValue(); + Name = new MetadataValue(); + Comment = new MetadataValue(); + Vial = new MetadataValue(); + Plate = new MetadataValue(); + Rack = new MetadataValue(); + Type = new MetadataValue(); + ClassName = new MetadataValue(); + AnalyticalOrder = new MetadataValue(); + Batch = new MetadataValue(); + VendorFields = new Dictionary(StringComparer.OrdinalIgnoreCase); + } + + public MetadataValue Id { get; set; } + public MetadataValue Name { get; set; } + public MetadataValue Comment { get; set; } + public MetadataValue Vial { get; set; } + public MetadataValue Plate { get; set; } + public MetadataValue Rack { get; set; } + public MetadataValue Type { get; set; } + public MetadataValue ClassName { get; set; } + public MetadataValue AnalyticalOrder { get; set; } + public MetadataValue Batch { get; set; } + public Dictionary VendorFields { get; set; } + } + + public sealed class RawExperimentMetadata { + public RawExperimentMetadata() { + Id = string.Empty; + Name = string.Empty; + Polarity = new MetadataValue(); + Method = new MetadataValue(); + VendorFields = new Dictionary(StringComparer.OrdinalIgnoreCase); + } + + public string Id { get; set; } + public string Name { get; set; } + public MetadataValue Polarity { get; set; } + public MetadataValue Method { get; set; } + public Dictionary VendorFields { get; set; } + } + + public sealed class RawMetadataWarning { + public RawMetadataWarning() { + Code = string.Empty; + Message = string.Empty; + } + + public RawMetadataWarning(string code, string message) { + Code = code ?? string.Empty; + Message = message ?? string.Empty; + } + + public string Code { get; set; } + public string Message { get; set; } + } + + public sealed class RawDataMetadata { + public RawDataMetadata() { + SchemaVersion = "msdial.raw-metadata.v1"; + Source = new RawSourceMetadata(); + Instrument = new RawInstrumentMetadata(); + Run = new RawRunMetadata(); + Acquisition = new RawAcquisitionMetadata(); + Samples = new List(); + Experiments = new List(); + VendorFields = new Dictionary(StringComparer.OrdinalIgnoreCase); + Warnings = new List(); + } + + public string SchemaVersion { get; set; } + public RawSourceMetadata Source { get; set; } + public RawInstrumentMetadata Instrument { get; set; } + public RawRunMetadata Run { get; set; } + public RawAcquisitionMetadata Acquisition { get; set; } + public List Samples { get; set; } + public List Experiments { get; set; } + public Dictionary VendorFields { get; set; } + public List Warnings { get; set; } + } + + public sealed class RawMetadataReadOptions { + public RawMetadataReadOptions() { + MaxSpectrumHeaders = 200; + IncludeVendorFields = true; + } + + public int MaxSpectrumHeaders { get; set; } + public bool IncludeVendorFields { get; set; } + } + + public interface IRawMetadataReader { + string ReaderName { get; } + bool CanRead(string path); + RawDataMetadata ReadMetadata(string path, RawMetadataReadOptions options); + } +} diff --git a/src/Common/CommonStandard/DataObj/RawMeasurement.cs b/src/Common/CommonStandard/DataObj/RawMeasurement.cs index 91f990a2d..982c804c0 100644 --- a/src/Common/CommonStandard/DataObj/RawMeasurement.cs +++ b/src/Common/CommonStandard/DataObj/RawMeasurement.cs @@ -70,6 +70,7 @@ public class RawMeasurement { public List CollisionEnergyTargets { get; set; } public MaldiFrameLaserInfo MaldiFrameLaserInfo { get; set; } public List MaldiFrames { get; set; } + public RawDataMetadata Metadata { get; set; } public RawMeasurement() { @@ -83,6 +84,7 @@ public RawMeasurement() MaldiFrameLaserInfo = new MaldiFrameLaserInfo(); MaldiFrames = new List(); + Metadata = new RawDataMetadata(); } } diff --git a/tests/Common/CommonStandardTests/DataObj/RawDataMetadataTests.cs b/tests/Common/CommonStandardTests/DataObj/RawDataMetadataTests.cs new file mode 100644 index 000000000..237e39209 --- /dev/null +++ b/tests/Common/CommonStandardTests/DataObj/RawDataMetadataTests.cs @@ -0,0 +1,29 @@ +using CompMs.Common.DataObj; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace CommonStandardTests.DataObj { + [TestClass] + public sealed class RawDataMetadataTests { + [TestMethod] + public void RawMeasurement_InitializesMetadataContract() { + var measurement = new RawMeasurement(); + + Assert.IsNotNull(measurement.Metadata); + Assert.AreEqual("msdial.raw-metadata.v1", measurement.Metadata.SchemaVersion); + Assert.IsNotNull(measurement.Metadata.Samples); + Assert.IsNotNull(measurement.Metadata.Experiments); + } + + [DataTestMethod] + [DataRow(-1d, 0d)] + [DataRow(0.75d, 0.75d)] + [DataRow(2d, 1d)] + public void MetadataValue_NormalizesConfidence(double input, double expected) { + var value = new MetadataValue("value", MetadataSource.VendorHeader, input, "header"); + + Assert.AreEqual(expected, value.Confidence, 0.0001d); + Assert.AreEqual(MetadataSource.VendorHeader, value.Source); + Assert.AreEqual("header", value.Evidence); + } + } +}