Пример #1
0
        void Copy_Inter.FileCopy(pTop.classes.File sf, pTop.classes.File df)
        {
            df.File_format_index = sf.File_format_index;
            df.File_format       = string.Copy(sf.File_format);
            df.Instrument_index  = sf.Instrument_index;
            df.Instrument        = string.Copy(sf.Instrument);
            df.Data_file_list.Clear();
            for (int i = 0; i < sf.Data_file_list.Count; i++)
            {
                df.Data_file_list.Add(sf.Data_file_list[i]);
            }

            Factory.Create_Copy_Instance().pParseAdvancedCopy(sf.Pparse_advanced, df.Pparse_advanced);
        }
Пример #2
0
        //read from pParse.para
        void pParse_Inter.pParse_read(string task_path, ref _Task _task)
        {
            string strLine = "";

            try
            {
                pTop.classes.File _file = _task.T_File;
                FileStream        fst   = new FileStream(task_path + "\\param\\pParseTD.cfg", FileMode.Open);
                StreamReader      sr    = new StreamReader(fst, Encoding.Default);
                strLine = sr.ReadLine();
                string subtitle = "";
                ObservableCollection <_FileInfo> dfl = new ObservableCollection <_FileInfo>();
                #region
                while (strLine != null)
                {
                    strLine = strLine.Trim();
                    if (strLine.Length > 0 && strLine.StartsWith("#"))
                    {
                    }
                    else if (strLine.Length > 0 && strLine[0] == '[' && strLine[strLine.Length - 1] == ']')
                    {
                        subtitle = strLine;
                    }
                    else if (strLine.Length > 0 && strLine.LastIndexOf("=") > -1)
                    {
                        if (subtitle.Equals("[Basic Options]"))
                        {
                            if (strLine.Length > 7 && strLine.Substring(0, 7).Equals("datanum"))
                            {
                                //if new a task, then dtnum=0
                                int dtnum = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                for (int i = 0; i < dtnum; i++)
                                {
                                    strLine = sr.ReadLine();
                                    strLine = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                    if (System.IO.File.Exists(@strLine))
                                    {
                                        _FileInfo _fi = new _FileInfo(strLine);
                                        dfl.Add(_fi);
                                    }
                                    else
                                    {
                                        System.Windows.MessageBox.Show("\"" + strLine + "\" does not exist.");
                                    }
                                }
                            }
                            else if (strLine.Length > 12 && strLine.Substring(0, 12).Equals("input_format"))
                            {
                                _file.File_format = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                if (_file.File_format.Equals("raw"))                  //raw
                                {
                                    _file.File_format_index = (int)FormatOptions.RAW; //format改变会引起Data_file_list的清空
                                }
                                else if (_file.File_format.Equals("mgf"))
                                {
                                    _file.File_format_index = (int)FormatOptions.MGF;
                                }
                                _file.Data_file_list.Clear();
                                for (int i = 0; i < dfl.Count; i++)
                                {
                                    _file.Data_file_list.Add(dfl[i]);
                                }
                            }
                        }
                        #region
                        else if (subtitle.Equals("[Advanced Options]"))
                        {
                            if (strLine.Length > ("max_charge").Length && strLine.Substring(0, ("max_charge").Length).Equals("max_charge"))
                            {
                                _file.Pparse_advanced.Max_charge = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1).Trim());
                            }
                            else if (strLine.Length > ("max_mass").Length && strLine.Substring(0, ("max_mass").Length).Equals("max_mass"))
                            {
                                _file.Pparse_advanced.Max_mass = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1).Trim());
                            }
                            else if (strLine.Length > ("SN_threshold").Length && strLine.Substring(0, ("SN_threshold").Length).Equals("SN_threshold"))
                            {
                                _file.Pparse_advanced.Sn_ratio = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1).Trim());
                            }
                            else if (strLine.Length > ("mz_error_tolerance").Length && strLine.Substring(0, ("mz_error_tolerance").Length).Equals("mz_error_tolerance"))
                            {
                                _file.Pparse_advanced.Mz_tolerance = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1).Trim());
                            }
                            else if (strLine.Length > 8 && strLine.Substring(0, 8).Equals("co-elute"))
                            {
                                if (strLine.Substring(strLine.LastIndexOf("=") + 1).Equals("1"))
                                {
                                    _file.Pparse_advanced.Mix_spectra = true;
                                }
                                else
                                {
                                    _file.Pparse_advanced.Mix_spectra = false;
                                }
                            }

                            else if (strLine.Length > 15 && strLine.Substring(0, 15).Equals("isolation_width"))
                            {
                                _file.Pparse_advanced.Isolation_width = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1).Trim());
                            }
                            else if (strLine.Length > ("model_type").Length && strLine.Substring(0, ("model_type").Length).Equals("model_type"))
                            {
                                _file.Pparse_advanced.Model = strLine.Substring(strLine.LastIndexOf("=") + 1).Trim().ToLower().Equals("svm") ? (int)ModelOptions.SVM : (int)ModelOptions.MARS;
                            }
                            else if (strLine.Length > 14 && strLine.Substring(0, 14).Equals("mars_threshold"))
                            {
                                _file.Pparse_advanced.Threshold = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1).Trim());
                            }
                        }
                        #endregion

                        else if (subtitle.Equals("[About pXtract]"))
                        {
                            if (strLine.Length > 3 && strLine.Substring(0, 3).Equals("m/z"))
                            {
                                _file.Pparse_advanced.Mz_decimal       = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                _file.Pparse_advanced.Mz_decimal_index = _file.Pparse_advanced.Mz_decimal - 1;
                            }
                            else if (strLine.Length > 9 && (strLine.Substring(0, 9).Equals("intensity") || strLine.Substring(0, 9).Equals("Intensity")))
                            {
                                _file.Pparse_advanced.Intensity_decimal       = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                _file.Pparse_advanced.Intensity_decimal_index = _file.Pparse_advanced.Intensity_decimal - 1;
                            }
                        }
                    }
                    strLine = sr.ReadLine();
                }
                sr.Close();
                fst.Close();
                #endregion
            }
            catch (Exception exe)
            {
                throw new Exception("[pParseTD_read] line: " + strLine + "\n" + exe.Message);
            }
        }
Пример #3
0
        //read from pTop.pfd
        void pTop_Inter.pTop_read(string task_path, bool pParse, ref _Task _task)
        {
            string strLine = "";

            try
            {
                pTop.classes.File _file         = _task.T_File;
                Identification    _search       = _task.T_Identify;
                Quantitation      _quantitation = _task.T_Quantify;

                FileStream   fst = new FileStream(task_path + "\\param\\pTop.cfg", FileMode.Open);
                StreamReader sr  = new StreamReader(fst, Encoding.Default);
                strLine = sr.ReadLine();
                string subtitle = "";
                #region
                while (strLine != null)
                {
                    strLine = strLine.Trim();
                    if (strLine.Length > 0 && strLine[0] == '[' && strLine[strLine.Length - 1] == ']')
                    {
                        subtitle = strLine;
                    }
                    else if (strLine.Length > 0 && strLine.IndexOf("=") > -1)
                    {
                        if (subtitle.Equals("[spectrum]"))
                        {
                            // msmspath and input_format were read from pParseTD.cfg
                            if (strLine.Length > ("Activation").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Activation"))
                            {
                                _file.Instrument = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                _file.setInstrument_index();
                            }
                            else if (strLine.Length > ("Precursor_Tolerance").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Precursor_Tolerance"))
                            {
                                _search.Ptl.Tl_value = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("Fragment_Tolerance").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Fragment_Tolerance"))
                            {
                                _search.Ftl.Tl_value = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                        }
                        else if (subtitle.Equals("[param]"))
                        {
                            if (strLine.Length > ("workflow").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("workflow"))
                            {
                                _search.SearchModeIndex = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("output_top_k").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("output_top_k"))
                            {
                                _search.OutputTopK = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("max_truncated_mass").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("max_truncated_mass"))
                            {
                                _search.MaxTruncatedMass = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("second_search").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("second_search"))
                            {
                                if (strLine.Substring(strLine.LastIndexOf("=") + 1).Equals("1"))
                                {
                                    _search.SecondSearch = true;
                                }
                                else
                                {
                                    _search.SecondSearch = false;
                                }
                            }
                        }

                        else if (subtitle.Equals("[fixmodify]"))
                        {
                            if (strLine.Length > ("fixedModify_num").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("fixedModify_num"))
                            {
                                int fix_num = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                _search.Fix_mods.Clear();
                                for (int i = 0; i < fix_num; i++)
                                {
                                    strLine = sr.ReadLine();
                                    string fixmod = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                    _search.Fix_mods.Add(fixmod);
                                }
                            }
                        }

                        else if (subtitle.Equals("[modify]"))
                        {
                            if (strLine.Length > ("Max_mod_num").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Max_mod_num"))
                            {
                                _search.Max_mod = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("unexpected_mod").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("unexpected_mod"))
                            {
                                _search.UnexpectedModNum = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("Max_mod_mass").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Max_mod_mass"))
                            {
                                _search.MaxModMass = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("Modify_num").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Modify_num"))
                            {
                                int var_num = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                _search.Var_mods.Clear();
                                for (int i = 0; i < var_num; i++)
                                {
                                    strLine = sr.ReadLine();
                                    string varmod = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                    _search.Var_mods.Add(varmod);
                                }
                            }
                        }
                        else if (subtitle.Equals("[filter]"))
                        {
                            if (strLine.Length > ("threshold").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("threshold"))
                            {
                                _search.Filter.Fdr_value = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1)) * 100;
                            }
                            else if (strLine.Length > ("separate_filtering").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("separate_filtering"))
                            {
                                if (strLine.Substring(strLine.LastIndexOf("=") + 1).Equals("1"))
                                {
                                    _search.Filter.SeparateFiltering = true;
                                }
                                else
                                {
                                    _search.Filter.SeparateFiltering = false;
                                }
                            }
                        }

                        #region [file]
                        if (subtitle.Equals("[file]"))
                        {
                            if (strLine.Length > ("Database").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Database"))
                            {
                                string db_path = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                if (db_path.Trim().Length > 0)
                                {
                                    DB db = new DB();
                                    db.Db_path = db_path;
                                    if (ConfigHelper.ReDBmap.Contains(db.Db_path))
                                    {
                                        db.Db_name       = ConfigHelper.ReDBmap[db.Db_path].ToString();
                                        _search.Db       = db;
                                        _search.Db_index = _search.setDatabaseIndex();
                                    }
                                    else     //the database is damaged
                                    {
                                        _search.Db_index = -1;
                                        _search.Db       = db;
                                    }
                                }
                                else   //when new a task
                                {
                                    _search.Db_index = -1;
                                    _search.Db       = new DB();
                                }
                                #region Todo
                                //当不存在指定数据库时
                                #endregion
                            }
                            else if (strLine.Length > ("pParseTD_cfg").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("pParseTD_cfg"))
                            {
                            }
                            else if (strLine.Length > ("pQuant_cfg").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("pQuant_cfg"))
                            {
                            }
                            else if (strLine.Length > ("outputpath").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("outputpath"))
                            {
                                string tpath = strLine.Substring(strLine.LastIndexOf("=") + 1);

                                if (tpath.Trim().Length > 0)
                                {
                                    if (task_path.EndsWith("\\"))
                                    {
                                        task_path = task_path.Substring(0, task_path.Length - 1);
                                    }
                                    _task.Path      = task_path + "\\";
                                    _task.Task_name = task_path.Substring(task_path.LastIndexOf("\\") + 1);
                                }
                            }
                        }
                        #endregion

                        else if (subtitle.Equals("[quantify]"))
                        {
                            if (strLine.Length > 5 && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("quant"))
                            {
                                string   qt      = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                string[] lb      = qt.Split('|');
                                int      lbcount = lb.GetUpperBound(0);
                                int      lbnum   = int.Parse(lb[0]);
                                #region 如果是MGF文件怎么办
                                #endregion
                                //labeling
                                if (lbnum == 1 && (lb[1].Equals("none") || lb[1].Equals("None")))
                                {
                                    _quantitation.Quantitation_type = (int)Quant_Type.Label_None;
                                }
                                else
                                {
                                    _quantitation.Quantitation_type           = (int)Quant_Type.Labeling; //if 15N, it will be changed in pQuant_Read
                                    _quantitation.Labeling.Multiplicity       = lbnum;
                                    _quantitation.Labeling.Multiplicity_index = lbnum - 1;
                                    if (lbnum == 1)
                                    {
                                        /*
                                         * string[] lbs = lb[1].Split(',');
                                         * foreach (string c in lbs)
                                         * {
                                         *  if (c.Trim() != ""&&c.ToLower()!="none")
                                         *  {
                                         *      _quantitation.Labeling.Medium_label.Add(c.Trim());
                                         *  }
                                         * }*/
                                        _quantitation.Labeling.Medium_label.Add(lb[1]);
                                    }
                                    else if (lbnum == 2)
                                    {
                                        _quantitation.Labeling.Light_label.Add(lb[1]);

                                        _quantitation.Labeling.Heavy_label.Add(lb[2]);
                                    }
                                    else if (lbnum == 3)
                                    {
                                        _quantitation.Labeling.Light_label.Add(lb[1]);

                                        _quantitation.Labeling.Medium_label.Add(lb[2]);

                                        _quantitation.Labeling.Heavy_label.Add(lb[3]);
                                    }
                                }
                            }
                        }
                    }
                    strLine = sr.ReadLine();
                }
                #endregion
                sr.Close();
                fst.Close();
            }
            catch (Exception exe)
            {
                throw new Exception("[pTop_read] line: " + strLine + "\n" + exe.Message);
            }
        }
Пример #4
0
        //generate pTop.cfg
        void pTop_Inter.pTop_write(_Task _task)
        {
            try
            {
                pTop.classes.File _file         = _task.T_File;
                Identification    _search       = _task.T_Identify;
                Quantitation      _quantitation = _task.T_Quantify;

                StreamReader sr      = new StreamReader(@"pTop.ini", Encoding.Default);
                string       strLine = sr.ReadLine();
                string       thread  = "";
                while (strLine != null)
                {
                    if (strLine.Length > 6 && strLine.Substring(0, 6).Equals("thread"))
                    {
                        thread = strLine.Substring(strLine.LastIndexOf("=") + 1);
                    }
                    if (thread != "")
                    {
                        break;
                    }
                    strLine = sr.ReadLine();
                }

                string       filepath = _task.Path + "param\\pTop.cfg";
                FileStream   pFfst    = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                StreamWriter pFsw     = new StreamWriter(pFfst, Encoding.Default);
                pFsw.WriteLine("# This is a standard pTop configuration file");
                pFsw.WriteLine("# For help: mail to [email protected]");
                pFsw.WriteLine("# Time: " + DateTime.Now.ToString());
                pFsw.WriteLine();
                pFsw.WriteLine("[Version]");
                pFsw.WriteLine("pTop_Version=EVA.2.0");
                pFsw.WriteLine();

                pFsw.WriteLine("[spectrum]");
                pFsw.WriteLine("msmsnum=" + _file.Data_file_list.Count.ToString());
                for (int i = 0; i < _file.Data_file_list.Count; i++)
                {
                    string mgfpath = _file.Data_file_list[i].FilePath;
                    pFsw.WriteLine("msmspath" + (i + 1).ToString() + "=" + mgfpath);
                }
                pFsw.WriteLine("input_format=" + _file.File_format);
                pFsw.WriteLine("Activation=" + _file.Instrument);
                //母离子误差指定为 Da
                pFsw.WriteLine("Precursor_Tolerance=" + _search.Ptl.Tl_value.ToString());
                //pFsw.WriteLine("mstolppm=" + _search.Ptl.Isppm.ToString());
                //碎片离子误差指定为 ppm
                pFsw.WriteLine("Fragment_Tolerance=" + _search.Ftl.Tl_value.ToString());
                //pFsw.WriteLine("msmstolppm=" + _search.Ftl.Isppm.ToString());
                pFsw.WriteLine();

                pFsw.WriteLine("[param]");
                pFsw.WriteLine("thread_num=" + thread);
                pFsw.WriteLine("workflow=" + _search.SearchModeIndex.ToString());
                pFsw.WriteLine("# 0 tag flow, 1 ion flow");
                pFsw.WriteLine("output_top_k=" + _search.OutputTopK.ToString());
                pFsw.WriteLine("max_truncated_mass=" + _search.MaxTruncatedMass.ToString());
                pFsw.WriteLine("second_search=" + (_search.SecondSearch ? "1" : "0"));
                pFsw.WriteLine();

                pFsw.WriteLine("[fixmodify]");
                pFsw.WriteLine("fixedModify_num=" + _search.Fix_mods.Count.ToString());
                for (int i = 0; i < _search.Fix_mods.Count; i++)
                {
                    if (_search.Fix_mods[i].Trim().Length > 0)
                    {
                        pFsw.WriteLine("fix_mod" + (i + 1).ToString() + "=" + _search.Fix_mods[i]);
                    }
                }
                pFsw.WriteLine();
                // 可变修饰参数
                pFsw.WriteLine("[modify]");
                pFsw.WriteLine("Max_mod_num=" + _search.Max_mod.ToString());
                pFsw.WriteLine("unexpected_mod=" + _search.UnexpectedModNum.ToString());
                pFsw.WriteLine("Max_mod_mass=" + _search.MaxModMass.ToString());
                pFsw.WriteLine("Modify_num=" + _search.Var_mods.Count.ToString());
                for (int i = 0; i < _search.Var_mods.Count; i++)
                {
                    if (_search.Var_mods[i].Trim().Length > 0)
                    {
                        pFsw.WriteLine("var_mod" + (i + 1).ToString() + "=" + _search.Var_mods[i]);
                    }
                }
                pFsw.WriteLine();

                pFsw.WriteLine("[filter]");
                pFsw.WriteLine("threshold=" + (_search.Filter.Fdr_value / 100).ToString());
                pFsw.WriteLine("separate_filtering=" + (_search.Filter.SeparateFiltering ? "1" : "0"));
                pFsw.WriteLine();

                pFsw.WriteLine("[file]");
                pFsw.WriteLine("Database=" + _search.Db.Db_path);
                pFsw.WriteLine("pParseTD_cfg=" + _task.Path + "param\\pParseTD.cfg");
                if (_quantitation.Quantitation_type != (int)Quant_Type.Label_None)
                {
                    pFsw.WriteLine("pQuant_cfg=" + _task.Path + "param\\pQuant.cfg");
                }
                else
                {
                    pFsw.WriteLine("pQuant_cfg=");
                }
                pFsw.WriteLine("outputpath=" + _task.Path);
                pFsw.WriteLine();

                #region Quant
                pFsw.WriteLine("[quantify]");
                if (_quantitation.Quantitation_type == (int)Quant_Type.Label_None)
                {
                    pFsw.WriteLine("quant=1|none");
                }
                else // quantify based on MS: Quant_Type.Labeling_15N || Quant_Type.Labeling_Dimethyl || Quant_Type.Labeling_SILAC || others
                {
                    string labels = "quant=" + _quantitation.Labeling.Multiplicity.ToString();    //Multiplicity
                    if (_quantitation.Labeling.Multiplicity == 1)  // 1种标记
                    {
                        if (_quantitation.Labeling.Medium_label.Count == 0)
                        {
                            labels += "|none";
                        }
                        else
                        {
                            labels += "|" + _quantitation.Labeling.Medium_label[0];
                        }
                    }
                    else if (_quantitation.Labeling.Multiplicity == 2)     // 2种标记
                    {
                        if (_quantitation.Labeling.Light_label.Count == 0) //light label
                        {
                            labels += "|none";
                        }
                        else
                        {
                            labels += "|" + _quantitation.Labeling.Light_label[0];
                        }
                        if (_quantitation.Labeling.Heavy_label.Count == 0)   //heavy label
                        {
                            labels += "|none";
                        }
                        else
                        {
                            labels += "|" + _quantitation.Labeling.Heavy_label[0];
                        }
                    }
                    else if (_quantitation.Labeling.Multiplicity == 3)     // 3种标记
                    {
                        if (_quantitation.Labeling.Light_label.Count == 0) //light label
                        {
                            labels += "|none";
                        }
                        else
                        {
                            labels += "|" + _quantitation.Labeling.Light_label[0];
                        }
                        if (_quantitation.Labeling.Medium_label.Count == 0)   //medium label
                        {
                            labels += "|none";
                        }
                        else
                        {
                            labels += "|" + _quantitation.Labeling.Medium_label[0];
                        }
                        if (_quantitation.Labeling.Heavy_label.Count == 0)   //heavy label
                        {
                            labels += "|none";
                        }
                        else
                        {
                            labels += "|" + _quantitation.Labeling.Heavy_label[0];
                        }
                    }
                    pFsw.WriteLine(labels);
                }
                pFsw.WriteLine();
                #endregion

                pFsw.WriteLine("[system]");
                pFsw.WriteLine("log=LOG_INFO");
                pFsw.Close();
                pFfst.Close();
            }
            catch (Exception exe)
            {
                throw new Exception(exe.Message);
            }
        }
Пример #5
0
        //read from pTop.pfd
        void pTop_Inter.pTop_read(string task_path, bool pParse, ref _Task _task)
        {
            //try
            {
                pTop.classes.File _file   = _task.T_File;
                Identification    _search = _task.T_Identify;

                FileStream   fst      = new FileStream(task_path + "\\param\\pTop.cfg", FileMode.Open);
                StreamReader sr       = new StreamReader(fst, Encoding.Default);
                string       strLine  = sr.ReadLine();
                string       subtitle = "";
                #region
                while (strLine != null)
                {
                    strLine = strLine.Trim();
                    if (strLine.Length > 0 && strLine[0] == '[' && strLine[strLine.Length - 1] == ']')
                    {
                        subtitle = strLine;
                    }
                    else
                    {
                        #region [database]
                        if (subtitle.Equals("[database]"))
                        {
                            if (strLine.Length > 9 && strLine.Substring(0, ("Database").Length).Equals("Database"))
                            {
                                string db_path = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                if (db_path.Trim().Length > 0)
                                {
                                    DB db = new DB();
                                    db.Db_path = db_path;
                                    if (ConfigHelper.ReDBmap.Contains(db.Db_path))
                                    {
                                        db.Db_name       = ConfigHelper.ReDBmap[db.Db_path].ToString();
                                        _search.Db       = db;
                                        _search.Db_index = _search.setDatabaseIndex();
                                    }
                                    else     //the database is damaged
                                    {
                                        _search.Db_index = -1;
                                        _search.Db       = db;
                                    }
                                }
                                else   //when new a task
                                {
                                    _search.Db_index = -1;
                                    _search.Db       = new DB();
                                }
                                #region Todo
                                //当不存在指定数据库时
                                #endregion
                            }
                        }
                        #endregion
                        #region [spectrum]
                        if (subtitle.Equals("[spectrum]"))
                        {
                            if (strLine.Length > ("Activation").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Activation"))
                            {
                                _file.Instrument = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                _file.setInstrument_index();
                            }
                            else if (strLine.Length > ("Precursor_Tolerance").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Precursor_Tolerance"))
                            {
                                _search.Ptl.Tl_value = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("Fragment_Tolerance").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Fragment_Tolerance"))
                            {
                                _search.Ftl.Tl_value = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                        }
                        #endregion

                        else if (subtitle.Equals("[fixmodify]"))
                        {
                            if (strLine.Length > ("fixedModify_num").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("fixedModify_num"))
                            {
                                int fix_num = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                _search.Fix_mods.Clear();
                                for (int i = 0; i < fix_num; i++)
                                {
                                    strLine = sr.ReadLine();
                                    string fixmod = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                    _search.Fix_mods.Add(fixmod);
                                }
                            }
                        }

                        else if (subtitle.Equals("[modify]"))
                        {
                            if (strLine.Length > ("Max_mod").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Max_mod"))
                            {
                                _search.Max_mod = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                            }
                            else if (strLine.Length > ("Modify_num").Length && strLine.Substring(0, strLine.LastIndexOf("=")).Equals("Modify_num"))
                            {
                                int var_num = int.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1));
                                _search.Var_mods.Clear();
                                for (int i = 0; i < var_num; i++)
                                {
                                    strLine = sr.ReadLine();
                                    string varmod = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                    _search.Var_mods.Add(varmod);
                                }
                            }
                        }


                        else if (subtitle.Equals("[filter]"))
                        {
                            if (strLine.Length > ("threshold").Length && strLine.Substring(0, ("threshold").Length).Equals("threshold"))
                            {
                                _search.Filter.Fdr_value = double.Parse(strLine.Substring(strLine.LastIndexOf("=") + 1)) * 100;
                            }
                        }

                        else if (subtitle.Equals("[output]"))
                        {
                            if (strLine.Length > 10 && strLine.Substring(0, 10).Equals("outputpath"))
                            {
                                string tpath = strLine.Substring(strLine.LastIndexOf("=") + 1);
                                if (tpath.Trim().Length > 0)
                                {
                                    _task.Path      = task_path + "\\";
                                    _task.Task_name = sr.ReadLine().Trim().Substring(strLine.LastIndexOf("=") + 1);
                                }
                            }
                        }
                    }
                    strLine = sr.ReadLine();
                }
                #endregion
                sr.Close();
                fst.Close();
            }
            //catch(Exception exe)
            //{
            //    throw new Exception(exe.Message);
            //}
        }
Пример #6
0
        //generate pTop.pfd
        void pTop_Inter.pTop_write(_Task _task)
        {
            try
            {
                pTop.classes.File _file   = _task.T_File;
                Identification    _search = _task.T_Identify;

                string       filepath = _task.Path + "param\\pTop.cfg";
                FileStream   pFfst    = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                StreamWriter pFsw     = new StreamWriter(pFfst, Encoding.Default);
                pFsw.WriteLine("# This is a standard pTop configuration file");
                pFsw.WriteLine("# For help: mail to [email protected]");
                pFsw.WriteLine("# Time: " + DateTime.Now.ToString());
                pFsw.WriteLine();
                pFsw.WriteLine("[Version]");
                pFsw.WriteLine("pTop_Version=EVA.1.2");
                pFsw.WriteLine();
                pFsw.WriteLine("[database]");
                pFsw.WriteLine("Database=" + _search.Db.Db_path);
                pFsw.WriteLine("pParseTD_cfg=" + _task.Path + "param\\pParseTD.cfg");
                pFsw.WriteLine();

                pFsw.WriteLine("[spectrum]");
                pFsw.WriteLine("msmsnum=" + _file.Data_file_list.Count.ToString());
                for (int i = 0; i < _file.Data_file_list.Count; i++)
                {
                    string mgfpath = _file.Data_file_list[i].FilePath;
                    pFsw.WriteLine("msmspath" + (i + 1).ToString() + "=" + mgfpath);
                }
                pFsw.WriteLine("input_format=" + _file.File_format);
                pFsw.WriteLine("Activation=" + _file.Instrument);
                //母离子误差指定为 Da
                pFsw.WriteLine("Precursor_Tolerance=" + _search.Ptl.Tl_value.ToString());
                //pFsw.WriteLine("mstolppm=" + _search.Ptl.Isppm.ToString());
                //碎片离子误差指定为 ppm
                pFsw.WriteLine("Fragment_Tolerance=" + _search.Ftl.Tl_value.ToString());
                //pFsw.WriteLine("msmstolppm=" + _search.Ftl.Isppm.ToString());
                pFsw.WriteLine();

                pFsw.WriteLine("[fixmodify]");
                pFsw.WriteLine("fixedModify_num=" + _search.Fix_mods.Count.ToString());
                for (int i = 0; i < _search.Fix_mods.Count; i++)
                {
                    if (_search.Fix_mods[i].Trim().Length > 0)
                    {
                        pFsw.WriteLine("fix_mod" + (i + 1).ToString() + "=" + _search.Fix_mods[i]);
                    }
                }
                pFsw.WriteLine();
                // 可变修饰参数
                pFsw.WriteLine("[modify]");
                pFsw.WriteLine("Max_mod=" + _search.Max_mod.ToString());
                pFsw.WriteLine("Modify_num=" + _search.Var_mods.Count.ToString());
                for (int i = 0; i < _search.Var_mods.Count; i++)
                {
                    if (_search.Var_mods[i].Trim().Length > 0)
                    {
                        pFsw.WriteLine("var_mod" + (i + 1).ToString() + "=" + _search.Var_mods[i]);
                    }
                }
                pFsw.WriteLine();


                pFsw.WriteLine();
                pFsw.WriteLine("[filter]");
                pFsw.WriteLine("threshold=" + (_search.Filter.Fdr_value / 100).ToString());
                pFsw.WriteLine();

                //pFsw.WriteLine("[output]");
                //pFsw.WriteLine("outputpath=" + _task.Path + "result\\");
                //pFsw.WriteLine("outputname=" + _task.Task_name);
                pFsw.WriteLine();

                pFsw.WriteLine("[system]");
                pFsw.WriteLine("log=LOG_INFO");
                pFsw.Close();
                pFfst.Close();
            }
            catch (Exception exe)
            {
                throw new Exception(exe.Message);
            }
        }
Пример #7
0
        //generate pQuant.qnt
        void pQuant_Inter.pQuant_write(_Task _task)
        {
            try
            {
                Quantitation      _quant   = _task.T_Quantify;
                pTop.classes.File _file    = _task.T_File;
                string            filepath = _task.Path + "param\\pQuant.cfg";
                FileStream        qfst     = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                StreamWriter      qsw      = new StreamWriter(qfst, Encoding.Default);
                qsw.WriteLine("# This is a standard pQuant configure file.");
                qsw.WriteLine("# Dear user,After '=' and before ';' is the content you can modify.");
                qsw.WriteLine("# Please keep serious when configuring. For some of the options,you can use the default value.");
                qsw.WriteLine("# For help: mail to [email protected]");
                qsw.WriteLine("# Time: " + DateTime.Now.ToString());
                qsw.WriteLine();
                qsw.WriteLine("[INI]");
                qsw.WriteLine("PATH_INI_ELEMENT=" + ConfigHelper.startup_path + "\\element.ini;");
                qsw.WriteLine("PATH_INI_MODIFICATION=" + ConfigHelper.startup_path + "\\modification.ini;");
                qsw.WriteLine("PATH_INI_RESIDUE=" + ConfigHelper.startup_path + "\\aa.ini;");
                qsw.WriteLine();

                qsw.WriteLine("[Performance]");
                qsw.WriteLine("PATH_BIN=" + ConfigHelper.startup_path + ";");
                qsw.WriteLine("NUMBER_MAX_PSM_PER_BLOCK=" + _quant.Quant_advanced.Number_max_psm_per_block + ";");
                qsw.WriteLine("TYPE_START=" + _quant.Quant_advanced.Type_start + ";");
                qsw.WriteLine();

                qsw.WriteLine("[MS1]");
                string ms1path = "";
                for (int i = 0; i < _file.Data_file_list.Count; i++)
                {
                    string tmp = _file.Data_file_list[i].FilePath;
                    ms1path += tmp.Substring(0, tmp.LastIndexOf(".")) + ".pf1|";
                }
                qsw.WriteLine("PATH_MS1=" + ms1path + ";");
                qsw.WriteLine("EXTENSION_TEXT_MS1=" + _quant.Quant_advanced.Extension_text_ms1 + ";");
                qsw.WriteLine();

                qsw.WriteLine("[Identification]");
                #region TODO是否有多个spectra
                #endregion
                string resultfile = ConfigHelper.getFileBySuffix(_task.Path, "spectra");
                qsw.WriteLine("PATH_IDENTIFICATION_FILE=" + resultfile + "|;");
                qsw.WriteLine("TYPE_IDENTIFICATION_FILE=2;");  //0是老pBuild;1是prolucid;2是pFind3.0

                //2014.10.29 chihao:pQuant过滤阈值修改,保持与过滤时一致
                qsw.WriteLine("THRESHOLD_FDR=" + (_task.T_Identify.Filter.Fdr_value / 100.0).ToString() + ";");
                qsw.WriteLine();

                qsw.WriteLine("[Quantitation]");
                //迟浩:定量初始值设置为0,表示标记定量。在搜非标记数据时,也是跑标记流程(画三维图)
                string type_label = "0";
                if (_quant.Quantitation_type == (int)Quant_Type.Label_free)
                {
                    type_label = "1";
                }
                qsw.WriteLine("TYPE_LABEL=" + type_label + ";");
                string labelInfo = "";
                #region 代码冗余
                //迟浩:这一段代码写得不好,建议一起过一遍功能然后优化实现
                if (_quant.Quantitation_type == (int)Quant_Type.Label_None)
                {
                    labelInfo = "1|none";
                }
                else if (_quant.Quantitation_type == (int)Quant_Type.Labeling)  //multiplicity=2
                {
                    int label_num = _quant.Labeling.Multiplicity;
                    labelInfo = label_num.ToString();
                    if (label_num == 1)
                    {
                        labelInfo += "|";
                        if (_quant.Labeling.Medium_label.Count == 0)
                        {
                            labelInfo += "none";
                        }
                        else
                        {
                            labelInfo += _quant.Labeling.Medium_label[0];
                        }
                    }
                    else if (label_num == 2)
                    {
                        if (_quant.Labeling.Light_label.Count == 0 && _quant.Labeling.Heavy_label.Count == 0)
                        {
                            labelInfo = "1|none";
                        }
                        else
                        {
                            labelInfo += "|";
                            if (_quant.Labeling.Light_label.Count == 0)
                            {
                                labelInfo += "none";
                            }
                            else
                            {
                                labelInfo += _quant.Labeling.Light_label[0];
                            }
                            labelInfo += "|";
                            if (_quant.Labeling.Heavy_label.Count == 0)
                            {
                                labelInfo += "none";
                            }
                            else
                            {
                                labelInfo += _quant.Labeling.Heavy_label[0];
                            }
                        }
                    }
                    else if (label_num == 3)
                    {
                        labelInfo += "|";
                        if (_quant.Labeling.Light_label.Count == 0)
                        {
                            labelInfo += "none";
                        }
                        else
                        {
                            labelInfo += _quant.Labeling.Light_label[0];
                        }
                        labelInfo += "|";
                        if (_quant.Labeling.Medium_label.Count == 0)
                        {
                            labelInfo += "none";
                        }
                        else
                        {
                            labelInfo += _quant.Labeling.Medium_label[0];
                        }
                        labelInfo += "|";
                        if (_quant.Labeling.Heavy_label.Count == 0)
                        {
                            labelInfo += "none";
                        }
                        else
                        {
                            labelInfo += _quant.Labeling.Heavy_label[0];
                        }
                    }
                }
                qsw.WriteLine("LL_INFO_LABEL=" + labelInfo + ";");
                #endregion
                string lfec = "none";
                if (_quant.Quant_advanced.Ll_element_enrichment_calibration == (int)LL_ELEMENT_ENRICHMENT_CALIBRATION.N15)
                {
                    lfec = "15N";
                }
                else if (_quant.Quant_advanced.Ll_element_enrichment_calibration == (int)LL_ELEMENT_ENRICHMENT_CALIBRATION.C13)
                {
                    lfec = "13C";
                }
                qsw.WriteLine("LL_ELEMENT_ENRICHMENT_CALIBRATION=" + lfec + ";");
                #region Todo LabelFree
                //Label Free
                #endregion
                qsw.WriteLine("LF_INFO_SAMPLE=; //Label Free暂不考虑");
                qsw.WriteLine();

                qsw.WriteLine("[Evidence]");
                qsw.WriteLine("NUMBER_SCANS_HALF_CMTG=" + _quant.Quant_advanced.Number_scans_half_cmtg + ";");
                qsw.WriteLine("PPM_FOR_CALIBRATION=" + _quant.Quant_advanced.Ppm_for_calibration + ";");
                qsw.WriteLine("PPM_HALF_WIN_ACCURACY_PEAK=" + _quant.Quant_advanced.Ppm_half_win_accuracy_peak + ";");
                qsw.WriteLine("NUMBER_HOLE_IN_CMTG=" + (_quant.Quant_advanced.Number_hole_in_cmtg + 1).ToString() + ";");
                qsw.WriteLine("TYPE_SAME_START_END_BETWEEN_EVIDENCE=" + _quant.Quant_advanced.Type_same_start_end_between_evidence + ";");
                qsw.WriteLine();

                qsw.WriteLine("[Inference]");
                qsw.WriteLine("TYPE_PEPTIDE_RATIO=" + _quant.Quant_inference.Type_peptide_ratio.ToString() + ";");
                qsw.WriteLine("TYPE_PROTEIN_RATIO_CALCULATION=" + _quant.Quant_inference.Type_protein_ratio_calculation + ";");
                qsw.WriteLine("TYPE_UNIQUE_PEPTIDE_ONLY=" + _quant.Quant_inference.Type_unique_peptide_only + ";");
                qsw.WriteLine("THRESHOLD_SCORE_INTERFERENCE=" + _quant.Quant_inference.Threshold_score_interference + ";");
                qsw.WriteLine("THRESHOLD_SCORE_INTENSITY=" + _quant.Quant_inference.Threshold_score_intensity + ";");
                qsw.WriteLine("TYPE_GET_GROUP=" + _quant.Quant_inference.Type_get_group + ";");
                qsw.WriteLine("PATH_FASTA=" + _task.T_Identify.Db.Db_path + ";");
                qsw.WriteLine();

                qsw.WriteLine("[Export]");
                qsw.WriteLine("DIR_EXPORT=" + _task.Path + ";"); //+ "result\\;"
                qsw.WriteLine("FLAG_CREATE_NEW_FOLDER=0;");      //0表示直接使用dir_export的导出目录
                qsw.Close();
                qfst.Close();
            }
            catch (Exception exe)
            {
                throw new Exception(exe.Message);
            }
        }