Beispiel #1
0
        public static void Parse(Spectrum spec, WiffFile wifffile, int cycleCount,
            int experimentCount, string ms1file, string ms2file,
            string mgffile, Param para)
        {
            StreamWriter writerms1 = null;
            StreamWriter writerms2 = null;
            StreamWriter writermgf = null;

            // 输出Locus2Scan的哈希表
            StreamWriter writerLocus2Scan = null;
            string locus2scanName = ms1file.Substring(0, ms1file.LastIndexOf('.')) + ".Locus2Scan";
            writerLocus2Scan = new StreamWriter(new FileStream(locus2scanName, FileMode.Create, FileAccess.Write));

            // 输出 .xtract FLAG 文件
            string flagMsFileName = ms1file.Substring(0, ms1file.LastIndexOf('.')) + ".xtract";

            if (para.ms1 == 1){
                writerms1 = new StreamWriter(new FileStream(ms1file, FileMode.Create, FileAccess.Write));
                spec.WriteHeader(writerms1,para);               // 写表头
            }

            if (para.ms2 == 1){
                writerms2 = new StreamWriter(new FileStream(ms2file, FileMode.Create, FileAccess.Write));
                spec.WriteHeader(writerms2, para);              // 写表头
            }

            if (para.mgf == 1){
                writermgf = new StreamWriter(new FileStream(mgffile, FileMode.Create, FileAccess.Write));
            }

            for (int j = 0; j < cycleCount; j++){
                string header = "[wiff] <Output files>: ";
                Console.Write("\r" + header + String.Format("{0:F3}", (double)(j + 1) / (double)cycleCount * 100) + "%");
                for (int i = 0; i < experimentCount; i++){
                    TotalIonChromatogram totalIonChromatogram = spec.array[i];
                    float num = (float)totalIonChromatogram.GetYValue(j);
                    if (i == 0 || num > 0f){
                        bool doCentroid = false;
                        spec.cycle = j + 1;
                        spec.experiment = i + 1;
                        spec.m_msExperiment = spec.wiffExperiments[i];
                        //spec.m_spectrum = spec.m_msExperiment.GetMassSpectrum(j);
                        try{            // AB 数据可能因为质量不好的原因,造成 Get 不到谱图号
                            spec.m_spectrum = spec.m_msExperiment.GetMassSpectrum(j);
                        }catch (System.Exception e){
                            continue;
                        }
                        spec.details = spec.m_msExperiment.Details;
                        spec.m_spectrumInfo = spec.m_msExperiment.GetMassSpectrumInfo(j);
                        spec.pointsAreContinuous = !spec.m_spectrumInfo.CentroidMode;

                        if (spec.GetDataSize(doCentroid) > 0){
                            List<double> centermzs = new List<double>();
                            List<double> centerint = new List<double>();
                            spec.GetData(doCentroid, out centermzs, out centerint);

                            if (para.cent == true){
                                PeakDetection.WindowCentroid(centermzs, centerint, out spec.mz, out spec.intensity, spec);
                            }else{
                                spec.mz = centermzs;
                                spec.intensity = centerint;
                            }

                            spec.retentionTime = (double)totalIonChromatogram.GetXValue(j);
                            spec.precursor_mz = 0.0;
                            spec.charge = 0;
                            if (spec.m_spectrumInfo.IsProductSpectrum){
                                spec.precursor_mz = spec.m_spectrumInfo.ParentMZ;
                                spec.charge = spec.m_spectrumInfo.ParentChargeState;
                            }
                            spec.scan++;
                            //scan从1开始
                            if (spec.GetMSLevel() == 1 && para.ms1 == 1){
                                spec.WriteMS1(writerms1);

                            }else if(spec.GetMSLevel() > 1){
                                if (para.ms2 == 1){
                                    spec.WriteMS2(writerms2);
                                }

                                if (para.mgf == 1){
                                    spec.WriteMGF(wifffile,writermgf);
                                }

                                // 输出 locus2scan 哈希表
                                string wifftitle = "Locus:" + "1.1.1." + spec.cycle + "." + spec.experiment;
                                //Console.WriteLine("WiffTitle:"+wifftitle);
                                //Console.WriteLine("Scan:"+spec.scan);
                                //Console.Read();
                                writerLocus2Scan.WriteLine(wifftitle+" "+spec.scan);
                            }
                        }
                    }
                }
            }

            if (para.ms1 == 1){
                writerms1.Close();
            }

            if (para.ms2 == 1){
                writerms2.Close();
            }

            if (para.mgf == 1){
                writermgf.Close();
            }

            //写出.Xtract文件作为导出flag.
            FileStream flagMsFile = new FileStream(flagMsFileName, FileMode.Create, FileAccess.Write);
            flagMsFile.Close();
            writerLocus2Scan.Close();
            Console.WriteLine();
        }
Beispiel #2
0
        public void WriteMGF(WiffFile wifffile, StreamWriter writer)
        {
            string title = wifffile.name + "." + scan + "." + scan + "." + "2.0.dta";
            writer.WriteLine("BEGIN IONS");
            writer.WriteLine("TITLE=" + title);
            //string wifftitle = "Locus:" + "1.1.1." + this.cycle + "." + this.experiment;
            //Console.WriteLine("pFindTitle:" + title);
            //Console.WriteLine("WIFFTITILE=" + wifftitle);
            //Console.Read();
            //if (this.charge != 0)
            //{
            //    writer.WriteLine("CHARGE=" + this.charge + "+");
            //}
            writer.WriteLine("CHARGE=2+");
            writer.WriteLine("RTINSECONDS=" + this.retentionTime.ToString("F6"));
            writer.WriteLine("PEPMASS=" + this.precursor_mz.ToString("G10"));

            //去噪,统计频率最高的谱峰,不输出
            Dictionary<int, int> dic = new Dictionary<int, int>();
            for (int i = 0; i < mz.Count; i++)
            {
                if (dic.ContainsKey((int)intensity[i]))
                    dic[(int)intensity[i]] += 1;
                else
                    dic.Add((int)intensity[i], 1);
            }

            //int mostInten = 0;
            int[] mostInten = new int[4];
            int countMost = 0;
            var aaaa = dic.OrderByDescending(a => a.Value);         //按照value降序排序;
            foreach (KeyValuePair<int, int> a in aaaa)
            {
                //Console.WriteLine(a.Key + " " + a.Value);
                mostInten[countMost++] = a.Key;
                if (countMost == 2)
                    break;
            }
            //Console.WriteLine(mostInten[0] + " " + mostInten[1] + " " + mostInten[2]);
            //Console.Read();

            //输出,但避开强度频率最高的峰
            for (int i = 0; i < mz.Count; ++i)
            {
                if ((int)intensity[i] != mostInten[0] && (int)intensity[i] != mostInten[1])
                    writer.WriteLine(mz[i].ToString("F5") + "\t" + intensity[i]);
            }
            writer.WriteLine("END IONS\n");
        }