Example #1
0
        internal static MassSpecMethod ExtractMsMethod(IAcqMethod dataAcqMethod)
        {
            if (dataAcqMethod == null)
            {
                return(null);
            }

            const int         kMsMethodDeviceType = 0; // device type for MassSpecMethod
            int               devType;                 // device type
            EnumDeviceMethods enumMethod = (EnumDeviceMethods)dataAcqMethod;

            enumMethod.Reset();
            do
            {
                object devMethod; // one of the sub-methods
                int    devModel;  // device model
                int    devInst;   // device instrument type
                enumMethod.Next(out devMethod, out devType, out devModel, out devInst);
                if (devType == kMsMethodDeviceType)
                {
                    return((MassSpecMethod)devMethod);
                }
                if (devType == -1)
                {
                    //Call Err.Raise(1, "ExtractMSMethod", "No MS method found")
                    return(null);
                }
            }while (devType == kMsMethodDeviceType);

            return(null);
        }
Example #2
0
        internal static IAcqMethod GetAcqMethod(string methodFilePath, out MassSpecMethod templateMsMethod)
        {
            ApplicationClass analyst = new ApplicationClass();

            // Make sure that Analyst is fully started
            IAcqMethodDirConfig acqMethodDir = (IAcqMethodDirConfig)analyst.Acquire();

            if (acqMethodDir == null)
            {
                throw new IOException("Failed to initialize.  Analyst may need to be started.");
            }

            object acqMethodObj;

            acqMethodDir.LoadNonUIMethod(methodFilePath, out acqMethodObj);
            IAcqMethod templateAcqMethod = (IAcqMethod)acqMethodObj;

            templateMsMethod = ExtractMsMethod(templateAcqMethod);
            return(templateAcqMethod);
        }
Example #3
0
        public override void build()
        {
            MassSpecMethod templateMsMethod;

            IAcqMethod templateAcqMethod = GetAcqMethod(TemplateMethod, out templateMsMethod);


            ValidateMethod(templateMsMethod);


            foreach (var methodTranList in MethodTrans)
            {
                Console.Error.WriteLine(string.Format("MESSAGE: Exporting method {0}", Path.GetFileName(methodTranList.FinalMethod)));

                if (string.IsNullOrEmpty(methodTranList.TransitionList))
                {
                    throw new IOException(string.Format("Failure creating method file {0}.  The transition list is empty.", methodTranList.FinalMethod));
                }

                try
                {
                    WriteToTemplate(templateAcqMethod, methodTranList);
                }
                catch (Exception x)
                {
                    throw new IOException(string.Format("Failure creating method file {0}.  {1}", methodTranList.FinalMethod, x.Message));
                }

                if (!File.Exists(methodTranList.OutputMethod))
                {
                    throw new IOException(string.Format("Failure creating method file {0}.", methodTranList.FinalMethod));
                }

                // Skyline uses a segmented progress status, which expects 100% for each
                // segment, with one segment per file.
                Console.Error.WriteLine("100%");
            }
        }
Example #4
0
        public void WriteToTemplate(String templateMethodFile, MethodTransitions transitions)
        {
            MassSpecMethod templateMsMethod;

            IAcqMethod templateAcqMethod = GetAcqMethod(TemplateMethod, out templateMsMethod);

            var method = ExtractMsMethod(templateAcqMethod);

            if (InclusionList || ScheduledMethod)
            {
                WriteToIDATemplate(method, transitions);
            }
            else
            {
                WriteToTargetedMSMSTemplate(method, transitions);
            }

            templateAcqMethod.SaveAcqMethodToFile(transitions.OutputMethod, 1);

            if (ExportMultiQuant)
            {
                ExportMultiQuantTextMethod(transitions);
            }
        }
Example #5
0
        private void WriteToTemplate(IAcqMethod acqMethod, MethodTransitions transitions)
        {
            var method = ExtractMsMethod(acqMethod);
            // Get the last period in the given template method.
            // We will add transitions to the last period only.
            var period       = (Period)method.GetPeriod(method.PeriodCount - 1);
            var msExperiment = (Experiment)period.GetExperiment(0);

            double?triggerThreshold = transitions.Transitions[0].Threshold;
            bool   analystSupportsEnhancedScheduledMrm = AnalystSupportsEnhancedScheduledMrm(msExperiment);

            if (triggerThreshold.HasValue && analystSupportsEnhancedScheduledMrm)
            {
                IExperiment8 experimentEnhanced = (IExperiment8)msExperiment;
                experimentEnhanced.IsEnhancedsMRM = 1;
            }

            if (!triggerThreshold.HasValue && msExperiment.MassRangesCount > 0 && analystSupportsEnhancedScheduledMrm && ((IMassRange4)msExperiment.GetMassRange(0)).TriggerThreshold > 0)
            {
                triggerThreshold = ((IMassRange4)msExperiment.GetMassRange(0)).TriggerThreshold;
            }


            var   templateMassRangeParams = (ParamDataColl)((IMassRange)msExperiment.GetMassRange(0)).MassDepParamTbl;
            short templateCxpParameterIdx;
            var   templateCxp = (ParameterData)templateMassRangeParams.FindParameter("CXP", out templateCxpParameterIdx);
            short templateSvParameterIdx;
            var   templateSv = (ParameterData)templateMassRangeParams.FindParameter("SV", out templateSvParameterIdx);

            msExperiment.DeleteAllMasses();

            float?medianArea = null;
            float?minArea    = null;
            int   count      = transitions.Transitions.Count();

            if (count >= 2)
            {
                var orderedTransitions = transitions.Transitions.OrderBy(t => t.AveragePeakArea);
                medianArea = orderedTransitions.ElementAt((int)(count * Properties.Settings.Default.FractionOfTranstionsToUseDwellWeighting)).AveragePeakArea
                             + orderedTransitions.ElementAt((int)((count - 1) * Properties.Settings.Default.FractionOfTranstionsToUseDwellWeighting)).AveragePeakArea;
                medianArea /= 2;
                minArea     = transitions.Transitions.Min(t => t.AveragePeakArea);
            }

            foreach (var transition in transitions.Transitions)
            {
                int i;
                var msMassRange  = (MassRange)msExperiment.CreateMassRange(out i);
                var msMassRange3 = (IMassRange3)msMassRange;

                msMassRange.SetMassRange(transition.PrecursorMz, 0, transition.ProductMz);
                msMassRange.DwellTime   = transition.Dwell;
                msMassRange3.CompoundID = transition.Label;
                var   massRangeParams = (ParamDataColl)msMassRange.MassDepParamTbl;
                short s;
                massRangeParams.Description = transition.Label;
                massRangeParams.AddSetParameter("DP", (float)transition.DP, (float)transition.DP, 0, out s);
                massRangeParams.AddSetParameter("CE", (float)transition.CE, (float)transition.CE, 0, out s);

                if (templateCxpParameterIdx > 0 && templateCxp != null)
                {
                    massRangeParams.AddSetParameter("CXP", templateCxp.startVal, templateCxp.stopVal, templateCxp.stepVal, out s);
                }

                if (templateSvParameterIdx > 0 && templateSv != null)
                {
                    massRangeParams.AddSetParameter("SV", templateSv.startVal, templateSv.stopVal, templateSv.stepVal, out s);
                }

                if (transition.CoV.HasValue)
                {
                    massRangeParams.AddSetParameter("COV", (float)transition.CoV, (float)transition.CoV, 0, out s);
                }

                if (analystSupportsEnhancedScheduledMrm)
                {
                    var msMassRange4 = (IMassRange4)msMassRange;
                    var groupId      = transition.Group;
                    msMassRange4.GroupID          = groupId;
                    msMassRange4.IsPrimary        = transition.Primary.HasValue && transition.Primary.Value == 2 ? 0 : 1;
                    msMassRange4.TriggerThreshold = triggerThreshold.HasValue ? triggerThreshold.Value : Properties.Settings.Default.MinTriggerThreshold;

                    double?detectionWindow = transitions.Transitions.Where(t => t.Group == groupId).Max(t => t.VariableRtWindow);
                    msMassRange4.DetectionWindow = detectionWindow.HasValue ? detectionWindow.Value * 60 : msMassRange4.DetectionWindow;

                    if (medianArea.HasValue && minArea.HasValue && minArea != medianArea && transition.AveragePeakArea.HasValue && transition.AveragePeakArea < medianArea)
                    {
                        double averageArea = transition.AveragePeakArea >= 1 ? (double)transition.AveragePeakArea : 1.0;
                        double scaledArea  = (Math.Log(averageArea - minArea.Value + 1) / Math.Log((double)medianArea))
                                             * (Properties.Settings.Default.MaxDwellWeightingForTargets - Properties.Settings.Default.MinDwellWeightingForTargets);
                        msMassRange4.DwellWeighting = Properties.Settings.Default.MaxDwellWeightingForTargets - scaledArea;
                    }
                    else
                    {
                        msMassRange4.DwellWeighting = 1.0;
                    }
                }
            }

            acqMethod.SaveAcqMethodToFile(transitions.OutputMethod, 1);
        }
Example #6
0
        internal static MassSpecMethod ExtractMsMethod(IAcqMethod dataAcqMethod)
        {
            if (dataAcqMethod == null)
                return null;

            const int kMsMethodDeviceType = 0; // device type for MassSpecMethod
            int devType; // device type
            EnumDeviceMethods enumMethod = (EnumDeviceMethods)dataAcqMethod;
            enumMethod.Reset();
            do
            {
                object devMethod; // one of the sub-methods
                int devModel; // device model
                int devInst; // device instrument type
                enumMethod.Next(out devMethod, out devType, out devModel, out devInst);
                if (devType == kMsMethodDeviceType)
                    return (MassSpecMethod)devMethod;
                if (devType == -1)
                {
                    //Call Err.Raise(1, "ExtractMSMethod", "No MS method found")
                    return null;
                }
            }
            while (devType == kMsMethodDeviceType);

            return null;
        }
Example #7
0
        private void WriteToTemplate(IAcqMethod acqMethod, MethodTransitions transitions)
        {
            var method = ExtractMsMethod(acqMethod);
            // Get the last period in the given template method.
            // We will add transitions to the last period only.
            var period = (Period)method.GetPeriod(method.PeriodCount - 1);
            var msExperiment = (Experiment)period.GetExperiment(0);

            double? triggerThreshold = transitions.Transitions[0].Threshold;
            bool analystSupportsEnhancedScheduledMrm = AnalystSupportsEnhancedScheduledMrm(msExperiment);
            if (triggerThreshold.HasValue && analystSupportsEnhancedScheduledMrm)
            {
                IExperiment8 experimentEnhanced = (IExperiment8)msExperiment;
                experimentEnhanced.IsEnhancedsMRM = 1;
            }

            if (!triggerThreshold.HasValue && msExperiment.MassRangesCount > 0 && analystSupportsEnhancedScheduledMrm && ((IMassRange4)msExperiment.GetMassRange(0)).TriggerThreshold > 0)
            {
                triggerThreshold = ((IMassRange4)msExperiment.GetMassRange(0)).TriggerThreshold;
            }

            var templateMassRangeParams = (ParamDataColl)((IMassRange)msExperiment.GetMassRange(0)).MassDepParamTbl;
            short templateCxpParameterIdx;
            var templateCxp = (ParameterData)templateMassRangeParams.FindParameter("CXP", out templateCxpParameterIdx);
            short templateSvParameterIdx;
            var templateSv = (ParameterData)templateMassRangeParams.FindParameter("SV", out templateSvParameterIdx);

            msExperiment.DeleteAllMasses();

            float? medianArea = null;
            float? minArea = null;
            int count = transitions.Transitions.Count();
            if (count >= 2)
            {
                var orderedTransitions = transitions.Transitions.OrderBy(t => t.AveragePeakArea);
                medianArea = orderedTransitions.ElementAt((int)(count * Properties.Settings.Default.FractionOfTranstionsToUseDwellWeighting)).AveragePeakArea
                    + orderedTransitions.ElementAt((int)((count - 1) * Properties.Settings.Default.FractionOfTranstionsToUseDwellWeighting)).AveragePeakArea;
                medianArea /= 2;
                minArea = transitions.Transitions.Min(t => t.AveragePeakArea);
            }

            foreach (var transition in transitions.Transitions)
            {
                int i;
                var msMassRange = (MassRange) msExperiment.CreateMassRange(out i);
                var msMassRange3 = (IMassRange3) msMassRange;

                msMassRange.SetMassRange(transition.PrecursorMz, 0, transition.ProductMz);
                msMassRange.DwellTime = transition.Dwell;
                msMassRange3.CompoundID = transition.Label;
                var massRangeParams = (ParamDataColl) msMassRange.MassDepParamTbl;
                short s;
                massRangeParams.Description = transition.Label;
                massRangeParams.AddSetParameter("DP", (float) transition.DP, (float) transition.DP, 0, out s);
                massRangeParams.AddSetParameter("CE", (float) transition.CE, (float) transition.CE, 0, out s);

                if (templateCxpParameterIdx > 0 && templateCxp != null)
                    massRangeParams.AddSetParameter("CXP", templateCxp.startVal, templateCxp.stopVal, templateCxp.stepVal, out s);

                if (templateSvParameterIdx > 0 && templateSv != null)
                    massRangeParams.AddSetParameter("SV", templateSv.startVal, templateSv.stopVal, templateSv.stepVal, out s);

                if(transition.CoV.HasValue)
                    massRangeParams.AddSetParameter("COV", (float)transition.CoV, (float)transition.CoV, 0, out s);

                if (analystSupportsEnhancedScheduledMrm)
                {
                    var msMassRange4 = (IMassRange4)msMassRange;
                    var groupId = transition.Group;
                    msMassRange4.GroupID = groupId;
                    msMassRange4.IsPrimary = transition.Primary.HasValue && transition.Primary.Value == 2 ? 0 : 1;
                    msMassRange4.TriggerThreshold = triggerThreshold.HasValue ? triggerThreshold.Value : Properties.Settings.Default.MinTriggerThreshold;

                    double? detectionWindow = transitions.Transitions.Where(t => t.Group == groupId).Max(t => t.VariableRtWindow);
                    msMassRange4.DetectionWindow = detectionWindow.HasValue ? detectionWindow.Value * 60 : msMassRange4.DetectionWindow;

                    if (medianArea.HasValue && minArea.HasValue && minArea != medianArea && transition.AveragePeakArea.HasValue && transition.AveragePeakArea < medianArea)
                    {
                        double averageArea = transition.AveragePeakArea >= 1 ? (double)transition.AveragePeakArea : 1.0;
                        double scaledArea = (Math.Log(averageArea - minArea.Value + 1) / Math.Log((double)medianArea))
                            * (Properties.Settings.Default.MaxDwellWeightingForTargets - Properties.Settings.Default.MinDwellWeightingForTargets);
                        msMassRange4.DwellWeighting = Properties.Settings.Default.MaxDwellWeightingForTargets - scaledArea;
                    }
                    else
                    {
                        msMassRange4.DwellWeighting = 1.0;
                    }
                }
            }

            acqMethod.SaveAcqMethodToFile(transitions.OutputMethod, 1);
        }