示例#1
0
        /// <summary>
        /// Populate the instrument configuration list
        /// </summary>
        /// <param name="mzMl"></param>
        private void ConstructInstrumentConfigurationList(mzMLType mzMl)
        {
            var instrumentData = _rawFile.GetInstrumentData();

            // Referenceable param group for common instrument properties
            mzMl.referenceableParamGroupList = new ReferenceableParamGroupListType
            {
                count = "1",
                referenceableParamGroup = new ReferenceableParamGroupType[1]
            };
            mzMl.referenceableParamGroupList.referenceableParamGroup[0] = new ReferenceableParamGroupType
            {
                id      = "commonInstrumentParams",
                cvParam = new CVParamType[2]
            };

            // Instrument model
            if (!OntologyMapping.InstrumentModels.TryGetValue(instrumentData.Name, out var instrumentModel))
            {
                instrumentModel = new CVParamType
                {
                    accession = "MS:1000483",
                    name      = "Thermo Fisher Scientific instrument model",
                    cvRef     = "MS",
                    value     = ""
                };
            }

            mzMl.referenceableParamGroupList.referenceableParamGroup[0].cvParam[0] = instrumentModel;

            // Instrument serial number
            mzMl.referenceableParamGroupList.referenceableParamGroup[0].cvParam[1] = new CVParamType
            {
                cvRef     = "MS",
                accession = "MS:1000529",
                name      = "instrument serial number",
                value     = instrumentData.SerialNumber
            };

            // Add a default analyzer if none were found
            if (_massAnalyzers.Count == 0)
            {
                _massAnalyzers.Add(MassAnalyzerType.Any, "IC1");
            }

            // Set the run default instrument configuration ref
            mzMl.run.defaultInstrumentConfigurationRef = "IC1";

            var instrumentConfigurationList = new InstrumentConfigurationListType
            {
                count = _massAnalyzers.Count.ToString(),
                instrumentConfiguration = new InstrumentConfigurationType[_massAnalyzers.Count]
            };

            // Make a new instrument configuration for each analyzer
            var massAnalyzerIndex = 0;

            foreach (var massAnalyzer in _massAnalyzers)
            {
                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex] = new InstrumentConfigurationType
                {
                    id = massAnalyzer.Value,
                    referenceableParamGroupRef = new ReferenceableParamGroupRefType[1],
                    componentList = new ComponentListType(),
                    cvParam       = new CVParamType[3]
                };
                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].referenceableParamGroupRef[0] =
                    new ReferenceableParamGroupRefType
                {
                    @ref = "commonInstrumentParams"
                };
                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList =
                    new ComponentListType
                {
                    count    = "3",
                    source   = new SourceComponentType[1],
                    analyzer = new AnalyzerComponentType[1],
                    detector = new DetectorComponentType[1]
                };

                // Instrument source
                if (_ionizationTypes.IsNullOrEmpty())
                {
                    _ionizationTypes.Add(IonizationModeType.Any,
                                         OntologyMapping.IonizationTypes[IonizationModeType.Any]);
                }

                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList.source[0] =
                    new SourceComponentType
                {
                    order   = 1,
                    cvParam = new CVParamType[_ionizationTypes.Count]
                };

                var index = 0;
                // Ionization type
                foreach (var ionizationType in _ionizationTypes)
                {
                    instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList.source[0]
                    .cvParam[index] =
                        ionizationType.Value;
                    index++;
                }

                // Instrument analyzer
                // Mass analyzer type
                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList.analyzer[0] =
                    new AnalyzerComponentType
                {
                    order   = index + 1,
                    cvParam = new CVParamType[1]
                };
                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList.analyzer[0]
                .cvParam[0] =
                    OntologyMapping.MassAnalyzerTypes[massAnalyzer.Key];
                index++;

                // Instrument detector
                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList.detector[0] =
                    new DetectorComponentType
                {
                    order   = index + 1,
                    cvParam = new CVParamType[1]
                };

                // Try to map the instrument to the detector
                var         detectorCvParams = OntologyMapping.InstrumentToDetectors[instrumentModel.accession];
                CVParamType detectorCvParam;
                if (massAnalyzerIndex < detectorCvParams.Count)
                {
                    detectorCvParam = detectorCvParams[massAnalyzerIndex];
                }
                else
                {
                    detectorCvParam = OntologyMapping.InstrumentToDetectors["MS:1000483"][0];
                }

                instrumentConfigurationList.instrumentConfiguration[massAnalyzerIndex].componentList.detector[0]
                .cvParam[0] = detectorCvParam;
                massAnalyzerIndex++;
            }

            mzMl.instrumentConfigurationList = instrumentConfigurationList;
        }
示例#2
0
        /// <summary>
        /// Populate the precursor list element
        /// </summary>
        /// <param name="scanEvent">the scan event</param>
        /// <param name="charge">the charge</param>
        /// <returns>the precursor list</returns>
        private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int?charge)
        {
            // Construct the precursor
            var precursorList = new PrecursorListType
            {
                count     = "1",
                precursor = new PrecursorType[1]
            };

            var precursor = new PrecursorType
            {
                selectedIonList = new SelectedIonListType
                {
                    count       = 1.ToString(),
                    selectedIon = new ParamGroupType[1]
                }
            };

            precursor.spectrumRef = ConstructSpectrumTitle(_precursorScanNumber);

            precursor.selectedIonList.selectedIon[0] =
                new ParamGroupType
            {
                cvParam = new CVParamType[3]
            };

            IReaction reaction       = null;
            var       precursorMass  = 0.0;
            double?   isolationWidth = null;

            try
            {
                reaction       = scanEvent.GetReaction(0);
                precursorMass  = reaction.PrecursorMass;
                isolationWidth = reaction.IsolationWidth;
            }
            catch (ArgumentOutOfRangeException exception)
            {
                //do nothing
            }

            // Selected ion MZ
            var ionCvParams = new List <CVParamType>
            {
                new CVParamType
                {
                    name          = "selected ion m/z",
                    value         = precursorMass.ToString(CultureInfo.InvariantCulture),
                    accession     = "MS:1000744",
                    cvRef         = "MS",
                    unitCvRef     = "MS",
                    unitAccession = "MS:1000040",
                    unitName      = "m/z"
                }
            };

            if (charge != null)
            {
                ionCvParams.Add(new CVParamType
                {
                    name      = "charge state",
                    value     = charge.ToString(),
                    accession = "MS:1000041",
                    cvRef     = "MS"
                });
            }

            precursor.selectedIonList.selectedIon[0].cvParam = ionCvParams.ToArray();

            precursor.isolationWindow =
                new ParamGroupType
            {
                cvParam = new CVParamType[3]
            };
            precursor.isolationWindow.cvParam[0] =
                new CVParamType
            {
                accession     = "MS:1000827",
                name          = "isolation window target m/z",
                value         = precursorMass.ToString(CultureInfo.InvariantCulture),
                cvRef         = "MS",
                unitCvRef     = "MS",
                unitAccession = "MS:1000040",
                unitName      = "m/z"
            };
            if (isolationWidth != null)
            {
                var offset = isolationWidth.Value / 2;
                precursor.isolationWindow.cvParam[1] =
                    new CVParamType
                {
                    accession     = "MS:1000828",
                    name          = "isolation window lower offset",
                    value         = offset.ToString(CultureInfo.InvariantCulture),
                    cvRef         = "MS",
                    unitCvRef     = "MS",
                    unitAccession = "MS:1000040",
                    unitName      = "m/z"
                };
                precursor.isolationWindow.cvParam[2] =
                    new CVParamType
                {
                    accession     = "MS:1000829",
                    name          = "isolation window upper offset",
                    value         = offset.ToString(CultureInfo.InvariantCulture),
                    cvRef         = "MS",
                    unitCvRef     = "MS",
                    unitAccession = "MS:1000040",
                    unitName      = "m/z"
                };
            }

            var activationCvParams = new List <CVParamType>();

            if (reaction != null && reaction.CollisionEnergyValid)
            {
                activationCvParams.Add(
                    new CVParamType
                {
                    accession     = "MS:1000045",
                    name          = "collision energy",
                    cvRef         = "MS",
                    value         = reaction.CollisionEnergy.ToString(CultureInfo.InvariantCulture),
                    unitCvRef     = "UO",
                    unitAccession = "UO:0000266",
                    unitName      = "electronvolt"
                });
            }

            if (reaction != null)
            {
                if (!OntologyMapping.DissociationTypes.TryGetValue(reaction.ActivationType, out var activation))
                {
                    activation = new CVParamType
                    {
                        accession = "MS:1000044",
                        name      = "Activation Method",
                        cvRef     = "MS",
                        value     = ""
                    };
                }

                activationCvParams.Add(activation);
            }

            precursor.activation =
                new ParamGroupType
            {
                cvParam = activationCvParams.ToArray()
            };

            precursorList.precursor[0] = precursor;

            return(precursorList);
        }