示例#1
0
文件: Program.cs 项目: rfellers/pwiz
        public void Build()
        {
            foreach (var methodTranList in MethodTrans)
            {
                Console.Error.WriteLine("MESSAGE: Exporting method {0}", Path.GetFileName(methodTranList.FinalMethod));
                if (string.IsNullOrEmpty(methodTranList.TransitionList))
                {
                    throw new IOException(string.Format("Failure creating method file {0}. The mass list is empty.", methodTranList.FinalMethod));
                }

                string outMeth = EnsureExtension(methodTranList.OutputMethod, ".meth");  // Thermo needs the extension to be .meth
                if (!Equals(outMeth, methodTranList.OutputMethod) && File.Exists(methodTranList.OutputMethod))
                {
                    File.Move(methodTranList.OutputMethod, outMeth);
                }

                try
                {
                    using (IMethodXMLContext mxc = MethodXMLFactory.CreateContext(InstrumentType, InstrumentVersion))
                        using (IMethodXML mx = mxc.Create())
                        {
                            mx.Open(TemplateMethod);
                            mx.EnableValidation(true);

                            ListItem[] listItems = ParseList(methodTranList.TransitionList).ToArray();
                            if (!listItems.Any())
                            {
                                throw new IOException("Empty mass list found.");
                            }

                            if (InstrumentType.Equals(InstrumentFusion))
                            {
                                mx.ApplyMethodModificationsFromXML(GetFusionModificationXml(listItems, outMeth));
                            }
                            else
                            {
                                mx.ImportMassListFromXML(GetTsqMassListXml(listItems, outMeth));
                            }
                            mx.SaveAs(outMeth);
                        }

                    if (!File.Exists(outMeth))
                    {
                        throw new IOException(string.Format("Failure creating method file {0}.", methodTranList.FinalMethod));
                    }
                }
                finally
                {
                    if (!Equals(outMeth, methodTranList.OutputMethod))
                    {
                        File.Move(outMeth, methodTranList.OutputMethod);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Helper function to get the MethodXMLContext
        /// </summary>
        /// <param name="model">The instrument model</param>
        /// <param name="version">The instrument version</param>
        /// <returns></returns>
        public static IMethodXMLContext CreateContext(string model = "", string version = "")
        {
            if (string.IsNullOrEmpty(model))
            {
                model = MethodXMLFactory.GetInstalledServerModel();
            }

            if (string.IsNullOrEmpty(version))
            {
                version = MethodXMLFactory.GetLatestInstalledVersion(model);
            }

            if (!MethodXMLFactory.GetInstalledInstrumentModels().Contains(model))
            {
                throw new ArgumentException("Cannot create method context for non-installed instrument model: " + model);
            }

            return(MethodXMLFactory.CreateContext(model, version));
        }