Пример #1
0
        private static void ExportMultiQuantTextMethod(MethodTransitions transitions)
        {
            string filePath = Path.ChangeExtension(transitions.FinalMethod, ".MultiQuant.txt");
            string export   = "Group Name\tName\tStart Mass - 1\tEnd Mass - 1\tExpected RT\tPeriod\tExperiment\tExtraction Type" + Environment.NewLine;

            foreach (var transition in transitions.Transitions)
            {
                var extarctionStart = IsPrecursorTypeTransition(transition)
                                          ? transition.PrecursorMz - transition.PrecursorWindow / 2
                                          : transition.ProductMz - transition.ProductWindow / 2;
                var extractionEnd = IsPrecursorTypeTransition(transition)
                                        ? transition.PrecursorMz + transition.PrecursorWindow / 2
                                        : transition.ProductMz + transition.ProductWindow / 2;

                var nameParts = transition.Label.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                var groupName = nameParts.Length >= 2
                                    ? string.Format("{0}.{1}", nameParts[0], nameParts[1])
                                    : transition.Label;

                export += string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}",
                                        groupName,
                                        transition.Label,
                                        extarctionStart,
                                        extractionEnd,
                                        transition.Dwell,
                                        1,
                                        transition.ExperimentIndex + 1,
                                        "Scan");
                export += Environment.NewLine;
            }
            using (var file = new StreamWriter(filePath))
            {
                file.Write(export);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        private void WriteToIDATemplate(MassSpecMethod method, MethodTransitions transitions)
        {
            object idaServer;

            ((IMassSpecMethod2)method).GetDataDependSvr(out idaServer);
            ClearIncludeList(idaServer);

            double minTOFMass = 0;
            double maxTOFMass = 0;

            ((IDDEMethodObj)idaServer).getUsersSurvTOFMasses(ref minTOFMass, ref maxTOFMass);

            var addedEntries = new List <string>();
            var assignedCandidateMassToRT       = new Dictionary <double, double>();
            var entryKeyToAssignedCandidateMass = new Dictionary <string, double>();

            foreach (var transition in transitions.Transitions)
            {
                double retentionTime = 0;

                // If the ScheduledMethod flag was set assume that the Dwell time column in the
                // transition list file has retention time.
                if (ScheduledMethod)
                {
                    retentionTime = transition.Dwell;
                }

                string entryKey = transition.PrecursorMz + retentionTime.ToString(CultureInfo.InvariantCulture);
                if (addedEntries.Contains(entryKey) ||
                    transition.PrecursorMz <= minTOFMass ||
                    transition.PrecursorMz >= maxTOFMass)
                {
                    continue;
                }

                var precursorMz = Math.Round(transition.PrecursorMz, 3);
                while (assignedCandidateMassToRT.ContainsKey(precursorMz))
                {
                    // Analyst does not allow duplicate masses in inclusion list
                    precursorMz += 0.001;
                }
                ((IDDEMethodObj)idaServer).AddIonEntry(1, precursorMz, retentionTime);
                addedEntries.Add(entryKey);
                assignedCandidateMassToRT.Add(precursorMz, retentionTime);
                entryKeyToAssignedCandidateMass.Add(entryKey, precursorMz);
            }

            if (ScheduledMethod) // calculate experiment index which is used for exporting a quantitaion method
            {
                ((IDDEMethodObj)idaServer).putExceedCountSwitch(2000000);
                ((IDDEMethodObj)idaServer).putIntensityThreshold(0);

                int windowInSec = RTWindowInSeconds.HasValue ? RTWindowInSeconds.Value : 60;
                ((IDDEMethodObj3)idaServer).putIncludeForSecs(windowInSec);
                int maxConcurrentCount = MaxConcurrentCount(assignedCandidateMassToRT, windowInSec);
                ((IDDEMethodObj)idaServer).putSpectraSwitch(maxConcurrentCount);
                var period = (Period)method.GetPeriod(0);
                while (period.ExperimCount > 2)
                {
                    period.DeleteExperiment(period.ExperimCount - 1);
                }
                var templateExperiment = (Experiment)period.GetExperiment(1);
                for (int newExperimentIdx = 1; newExperimentIdx < maxConcurrentCount; newExperimentIdx++)
                {
                    int pIdx;
                    var experiment = (IClone)period.CreateExperiment(out pIdx);
                    experiment.CopyDataFrom(templateExperiment);
                }

                // sort by mass then by RT
                var massRtList = assignedCandidateMassToRT.OrderBy(c => c.Value).ThenBy(c => c.Key).ToList();

                foreach (var transition in transitions.Transitions)
                {
                    double assignedCandidateMass;
                    var    entryKey = transition.PrecursorMz + transition.Dwell.ToString(CultureInfo.InvariantCulture);
                    if (!entryKeyToAssignedCandidateMass.TryGetValue(entryKey, out assignedCandidateMass))
                    {
                        continue;
                    }

                    var scheduledIndex = massRtList.FindIndex(m => Math.Abs(m.Key - assignedCandidateMass) < 0.001);
                    transition.ExperimentIndex = IsPrecursorTypeTransition(transition)
                                                     ? 0
                                                     : (scheduledIndex % maxConcurrentCount) + 1;
                }
            }
        }
Пример #4
0
        private void WriteToTargetedMSMSTemplate(MassSpecMethod method, MethodTransitions transitions)
        {
            var period = (Period)method.GetPeriod(0);


            Experiment tofExperiment = null;
            Experiment prodIonExperiment;

            switch (period.ExperimCount)
            {
            case 2:
                tofExperiment     = (Experiment)period.GetExperiment(0);
                prodIonExperiment = (Experiment)period.GetExperiment(1);

                // delete the product ion experiment. We will be adding one for each precursor ion in the transition list.
                period.DeleteExperiment(1);

                break;

            case 1:
                prodIonExperiment = (Experiment)period.GetExperiment(0);

                // delete the product ion experiment. We will be adding one for each precursor ion in the transition list.
                period.DeleteExperiment(0);

                break;

            default:
                throw new IOException(string.Format("Expected 1 or 2 experiments in the template. Found {0} experiments.", period.ExperimCount));
            }


            int j;

            if (Ms1Scan)
            {
                // If the template does not already have a TOF MS scan add one now.
                if (tofExperiment == null)
                {
                    var experiment = (Experiment)period.CreateExperiment(out j);
                    experiment.InitExperiment();
                    experiment.ScanType = TOF_MS_SCAN;
                }
            }


            if (prodIonExperiment == null)
            {
                throw new IOException("Product Ion scan was not found in the method.");
            }

            // Get the TOF mass range from the template
            var tofPropertiesTemplate = (ITOFProperties)prodIonExperiment;


            short s;

            //Get initial source parameters from the template
            var           sourceParamsTblInput = (ParamDataColl)prodIonExperiment.SourceParamsTbl;
            ParameterData param      = (ParameterData)sourceParamsTblInput.FindParameter("GS1", out s);
            float         sourceGas1 = param == null ? 0 : param.startVal;

            param = (ParameterData)sourceParamsTblInput.FindParameter("GS2", out s);
            float sourceGas2 = param == null ? 0 : param.startVal;

            param = (ParameterData)sourceParamsTblInput.FindParameter("CUR", out s);
            float curtainGas = param == null ? 0 : param.startVal;

            param = (ParameterData)sourceParamsTblInput.FindParameter("TEM", out s);
            float temperature = param == null ? 0 : param.startVal;

            param = (ParameterData)sourceParamsTblInput.FindParameter("IHT", out s);
            float nanoTemperature = param == null ? 0 : param.startVal;


            string ionSprayVoltageParamName = "ISVF"; // ISVF on 5600, IS on QSTAR
            float  ionSprayVoltage;

            var paramData = ((ParameterData)sourceParamsTblInput.FindParameter(ionSprayVoltageParamName, out s));

            if (s != -1)
            {
                ionSprayVoltage = paramData.startVal;
            }
            else
            {
                ionSprayVoltageParamName = "IS";
                ionSprayVoltage          = ((ParameterData)sourceParamsTblInput.FindParameter(ionSprayVoltageParamName, out s)).startVal;
            }

            // We will use parameters from the first mass range in the template product ion experiment.
            var massRangeTemplate = (IMassRange)prodIonExperiment.GetMassRange(0);
            var paramTblTemplate  = (ParamDataColl)massRangeTemplate.MassDepParamTbl;


            double minPrecursorMass = double.MaxValue;
            double maxPrecursorMass = 0;

            var precursorsToExperimentIndex = new Dictionary <double, int>();

            foreach (var transition in transitions.Transitions)
            {
                if (precursorsToExperimentIndex.ContainsKey(transition.PrecursorMz))
                {
                    transition.ExperimentIndex = IsPrecursorTypeTransition(transition)
                                                     ? 0
                                                     : precursorsToExperimentIndex[transition.PrecursorMz];
                    continue;
                }

                var experiment = (Experiment)period.CreateExperiment(out j);
                precursorsToExperimentIndex.Add(transition.PrecursorMz, j);
                transition.ExperimentIndex = IsPrecursorTypeTransition(transition) ? 0 : j;
                experiment.InitExperiment();

                // Setting ScanType to 6 for QSTAR causes method export to fail. Setting it to 9 works for both AB 5600 and QSTAR
                experiment.ScanType = PROD_ION_SCAN;

                experiment.FixedMass = transition.PrecursorMz;

                minPrecursorMass = Math.Min(minPrecursorMass, transition.PrecursorMz);
                maxPrecursorMass = Math.Max(maxPrecursorMass, transition.PrecursorMz);

                var tofProperties = (ITOFProperties)experiment;


                tofProperties.AccumTime  = tofPropertiesTemplate.AccumTime;
                tofProperties.TOFMassMin = tofPropertiesTemplate.TOFMassMin;
                tofProperties.TOFMassMax = tofPropertiesTemplate.TOFMassMax;


                // The following should trigger the "Suggest" button functionality
                // of updating the Q2 transmission window.
                tofProperties.UseQ1TranDefault = 1;
                //tofProperties.UseTOFExtrDefault = 1; // Works without this one.


                // High Sensitivity vs. High Resolution
                var tofProperties2         = experiment as ITOFProperties2;
                var templateTofProperties2 = prodIonExperiment as ITOFProperties2;
                if (tofProperties2 != null && templateTofProperties2 != null)
                {
                    tofProperties2.HighSensitivity = templateTofProperties2.HighSensitivity;
                }

                var sourceParamsTblOutput = (ParamDataColl)experiment.SourceParamsTbl;
                if (sourceParamsTblInput.FindParameter("GS1", out s) != null && s != -1)
                {
                    sourceParamsTblOutput.AddSetParameter("GS1", sourceGas1, sourceGas1, 0, out s);
                }
                if (sourceParamsTblInput.FindParameter("GS2", out s) != null && s != -1)
                {
                    sourceParamsTblOutput.AddSetParameter("GS2", sourceGas2, sourceGas2, 0, out s);
                }
                if (sourceParamsTblInput.FindParameter("CUR", out s) != null && s != -1)
                {
                    sourceParamsTblOutput.AddSetParameter("CUR", curtainGas, curtainGas, 0, out s);
                }
                if (sourceParamsTblInput.FindParameter("TEM", out s) != null && s != -1)
                {
                    sourceParamsTblOutput.AddSetParameter("TEM", temperature, temperature, 0, out s);
                }
                if (sourceParamsTblInput.FindParameter("IHT", out s) != null && s != -1)
                {
                    sourceParamsTblOutput.AddSetParameter("IHT", nanoTemperature, nanoTemperature, 0, out s);
                }
                if (sourceParamsTblInput.FindParameter(ionSprayVoltageParamName, out s) != null && s != -1)
                {
                    sourceParamsTblOutput.AddSetParameter(ionSprayVoltageParamName, ionSprayVoltage, ionSprayVoltage, 0, out s);
                }

                // Copy the compound dependent parameters from the template
                for (int i = 0; i < experiment.MassRangesCount; i++)
                {
                    var massRange     = (IMassRange)experiment.GetMassRange(i);
                    var massDepParams = (ParamDataColl)massRange.MassDepParamTbl;

                    // Declustering potential
                    float dp = ((ParameterData)paramTblTemplate.FindParameter("DP", out s)).startVal;
                    if (s != -1)
                    {
                        if (transition.DP > 0)
                        {
                            dp = Convert.ToSingle(transition.DP);
                        }
                        massDepParams.AddSetParameter("DP", dp, dp, 0, out s);
                    }


                    // Collision engergy
                    float ce = ((ParameterData)paramTblTemplate.FindParameter("CE", out s)).startVal;
                    if (s != -1)
                    {
                        if (transition.CE > 0)
                        {
                            ce = Convert.ToSingle(transition.CE);
                        }
                        massDepParams.AddSetParameter("CE", ce, ce, 0, out s);
                    }

                    // Ion release delay
                    float ird = ((ParameterData)paramTblTemplate.FindParameter("IRD", out s)).startVal;
                    if (s != -1)
                    {
                        massDepParams.AddSetParameter("IRD", ird, ird, 0, out s);
                    }

                    // Ion release width
                    float irw = ((ParameterData)paramTblTemplate.FindParameter("IRW", out s)).startVal;
                    if (s != -1)
                    {
                        massDepParams.AddSetParameter("IRW", irw, irw, 0, out s);
                    }

                    // Collision energy spread; Only on the Analyst TF 1.5.1 and TF1.5.2
                    paramData = ((ParameterData)paramTblTemplate.FindParameter("CES", out s));
                    if (s != -1)
                    {
                        massDepParams.AddSetParameter("CES", paramData.startVal, paramData.startVal, 0, out s);
                    }

                    // Focusing potential; Only on Analyst QS 2.0
                    paramData = ((ParameterData)paramTblTemplate.FindParameter("FP", out s));
                    if (s != -1)
                    {
                        massDepParams.AddSetParameter("FP", paramData.startVal, paramData.startVal, 0, out s);
                    }

                    // Declustering potential 2; Only on Analyst QS 2.0
                    paramData = ((ParameterData)paramTblTemplate.FindParameter("DP2", out s));
                    if (s != -1)
                    {
                        massDepParams.AddSetParameter("DP2", paramData.startVal, paramData.startVal, 0, out s);
                    }

                    // Collision gas; Only on Analyst QS 2.0
                    paramData = ((ParameterData)paramTblTemplate.FindParameter("CAD", out s));
                    if (s != -1)
                    {
                        massDepParams.AddSetParameter("CAD", paramData.startVal, paramData.startVal, 0, out s);
                    }
                }
            }

            // Expand the mass range for the TOF MS scan if the precursor mass of any of the MS/MS experiments
            // was out of the range
            if (Ms1Scan)
            {
                var ms1TofProperties = (ITOFProperties)(period.GetExperiment(0));
                ms1TofProperties.TOFMassMin = Math.Min(ms1TofProperties.TOFMassMin, minPrecursorMass);
                ms1TofProperties.TOFMassMax = Math.Max(ms1TofProperties.TOFMassMax, maxPrecursorMass);
            }
        }
Пример #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);
        }