예제 #1
0
        private void writeSingleSpectrum(string sourceFile, string nativeID, string outFileName)
        {
            MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig();
            writeConfig.format    = MSDataFile.Format.Format_MGF;
            writeConfig.precision = MSDataFile.Precision.Precision_32;

            //var predicate = new SpectrumList_FilterPredicate_IndexSet();
            //predicate.indexSet.Add(nativeID);

            var predicate = new SpectrumList_FilterPredicate_NativeIDSet();

            predicate.nativeIDSet.Add(nativeID);


            try
            {
                //Workspace.SetText("\r\nWriting selected spectrum to " + outFileName);
                MainForm.SetText(this, "Start writing selected spectrum to " + outFileName + "\r\n");
                using (MSDataFile msFile = new MSDataFile(sourceFile))
                {
                    msFile.run.spectrumList = new SpectrumList_Filter(msFile.run.spectrumList, new SpectrumList_FilterAcceptSpectrum(predicate.accept));
                    msFile.write(outFileName, writeConfig);
                }
                MainForm.SetText(this, "Finished writing selected spectrum to " + outFileName + "\r\n");
            }
            catch (Exception exc)
            {
                //throw new Exception("Error in writiing new spectra file", exc);
                //Workspace.SetText("\r\nError in writing new spectra file\r\n");
                tbPepNovoResult.AppendText("\r\nError in writing new spectra file\r\n");
                throw new Exception(exc.Message);
            }
        }
예제 #2
0
        public static List<string> IDList(string idpXML, string mzML)
        {
            List<string> list = new List<string>();
            MSDataFile foo = new MSDataFile(mzML);
            SpectrumList sl = foo.run.spectrumList;

            IDPicker.Workspace workspace = new IDPicker.Workspace();
            Package.loadWorkspace(ref workspace, idpXML);

            foreach (IDPicker.SourceGroupList.MapPair groupItr in workspace.groups)
                foreach (IDPicker.SourceInfo source in groupItr.Value.getSources(true))
                    foreach (IDPicker.SpectrumList.MapPair sItr in source.spectra)
                    {
                        IDPicker.ResultInstance ri = sItr.Value.results[1];
                        IDPicker.VariantInfo vi = ri.info.peptides.Min;
                        bool boolCharge = sItr.Value.id.charge.Equals(3);
                        if (boolCharge)
                        {
                            string rawPepSequence = vi.ToString();
                            string interpretation = vi.ToSimpleString();
                            // Look up the index with nativeID
                            object idOrIndex = null;
                            if (sItr.Value.nativeID != null && sItr.Value.nativeID.Length > 0)
                            {
                                idOrIndex = sItr.Value.nativeID;
                                list.Add(idOrIndex.ToString());
                            }
                        }//end if (boolcharge)
                    }//end foreach
            return list;
        }
예제 #3
0
        public IList <string> WriteSpectra(MSDataFile.WriteConfig config)
        {
            var outputPaths = new List <string>();

            foreach (SpectrumSource ss in session.Query <SpectrumSource>())
            {
                if (ss.Metadata == null)
                {
                    continue;
                }

                string outputSuffix;
                switch (config.format)
                {
                case MSDataFile.Format.Format_mzML: outputSuffix = ".mzML"; break;

                case MSDataFile.Format.Format_mzXML: outputSuffix = ".mzXML"; break;

                case MSDataFile.Format.Format_MGF: outputSuffix = ".mgf"; break;

                case MSDataFile.Format.Format_MS2: outputSuffix = ".ms2"; break;

                default:
                    config.format = MSDataFile.Format.Format_mzML;
                    outputSuffix  = ".mzML";
                    break;
                }

                MSDataFile.write(ss.Metadata, ss.Name + outputSuffix, config);

                outputPaths.Add(ss.Name + outputSuffix);
            }
            return(outputPaths);
        }
예제 #4
0
        static void openButton_Click(object sender, EventArgs e)
        {
            string filepath = _fileTextBox.Text;

            if (!File.Exists(filepath))
            {
                MessageBox.Show("That filepath does not exist.", "404 File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                var msd = new MSDataFile(filepath);
                var sl  = msd.run.spectrumList;
                MessageBox.Show(String.Format("The file has {0} spectra.", sl.size()), "Spectra Count");
            }
            catch (Exception ex)
            {
                string message = ex.ToString();
                if (ex.InnerException != null)
                {
                    message += "\n\nAdditional information: " + ex.InnerException.ToString();
                }
                MessageBox.Show(message,
                                "Error opening file",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
예제 #5
0
 protected void calculateSHA1()
 {
     lock (calculateSHA1Mutex)
     {
         jobInfo.log("SHA1 Checking", "SHA1 Checking");
         MSDataFile.calculateSHA1Checksums(msd);
     }
 }
예제 #6
0
파일: PSM.cs 프로젝트: trishorts/Compass
        public void SetRawFile(MSDataFile dataFile)
        {
            MsnDataScan scan = dataFile[ScanNumber] as MsnDataScan;

            IsolationMZ = scan.IsolationRange.Mean;
            Spectrum    = dataFile.GetSpectrum(ScanNumber);
            ScanWidth   = scan.MzRange.Width;
        }
예제 #7
0
        public void MyTestInitialize()
        {
            dataFile = new MSDataFile(Properties.Settings.Default.mzXMLTestFile1);
            spectrumCache = new SpectrumCache();
            ticGenerator = new TicGenerator(dataFile.run, spectrumCache);

            timer = new Stopwatch();
        }
예제 #8
0
        public DataSource( string filepath )
        {
            msDataFile = new MSDataFile(filepath);
            sourceFilepath = filepath;

            /*setInputFileWaitHandle = new EventWaitHandle( false, EventResetMode.ManualReset );
            setInputFileDelegate = new ParameterizedThreadStart( startSetInputFile );
            Thread setInputFileThread = new Thread( setInputFileDelegate );

            setInputFileThread.Start( (object) filepath );*/
        }
예제 #9
0
        public void GenerateFromMSMS()
        {
            dataFile = new MSDataFile(Properties.Settings.Default.mzXMLTestFile2);
            spectrumCache = new SpectrumCache();
            xicGenerator = new XicGenerator(dataFile.run, spectrumCache);

            IXYData xic = xicGenerator.Generate(592.3, 592.3, 0.01, TimeUnit.Seconds);

            Assert.AreEqual(239, xic.XValues.Count);
            Assert.AreEqual(7.6804, Math.Round(xic.GetXYPair(168).XValue, 10));
            Assert.AreEqual(519, xic.GetXYPair(168).YValue);
        }
예제 #10
0
파일: Convertor.cs 프로젝트: B-Rich/Compass
        public void Convert(string omssaCSV, MSDataFile dataFile)
        {
            string filePath = Path.ChangeExtension(omssaCSV, ".pepxml");
            using (PepXmlWriter writer = new PepXmlWriter(filePath))
            {

                writer.WriteSampleProtease(Protease);

                writer.StartSearchSummary("OMSSA", true, true);

                writer.WriteProteinDatabase(FastaDatabaseFile);

                writer.WriteSearchProtease(Protease, MissedClevages);

                foreach (int modNumber in FixedMods)
                {
                    OmssaModification mod;
                    if (OmssaModification.TryGetModification(modNumber, out mod))
                    {
                        writer.WriteModification(mod, mod.Sites, true);
                    }
                }

                foreach (int modNumber in VariableMods)
                {
                    OmssaModification mod;
                    if (OmssaModification.TryGetModification(modNumber, out mod))
                    {
                        writer.WriteModification(mod, mod.Sites, false);
                    }
                }

                writer.SetCurrentStage(PepXmlWriter.Stage.Spectra, true);

                using (OmssaCsvPsmReader reader = new OmssaCsvPsmReader(omssaCSV, UserModFile))
                {
                    reader.AddMSDataFile(dataFile);
                    reader.LoadProteins(FastaDatabaseFile);
                    foreach (PeptideSpectralMatch psm in reader.ReadNextPsm())
                    {
                        writer.StartSpectrum(psm.SpectrumNumber, psm.Spectrum.RetentionTime, psm.Spectrum.PrecursorMz, psm.Spectrum.PrecursorCharge);
                        writer.WritePSM(psm);
                        writer.EndSpectrum();
                    }

                }

            }
        }
예제 #11
0
        private SourceInfo[] getSourceInfo(DirectoryInfo dirInfo, bool getDetails)
        {
            var sourceInfoList = new List <SourceInfo>();

            sourceInfoList.Add(new SourceInfo());
            sourceInfoList[0].type         = getSourceType(dirInfo);
            sourceInfoList[0].name         = dirInfo.Name;
            sourceInfoList[0].path         = new MSDataRunPath(dirInfo.FullName, 0);
            sourceInfoList[0].dateModified = dirInfo.LastWriteTime;
            sourceInfoList[0].hasDetails   = getDetails;

            if (!getDetails)
            {
                return(sourceInfoList.ToArray());
            }

            if (sourceInfoList[0].type == "File Folder")
            {
                return(sourceInfoList.ToArray());
            }
            else if (sourceInfoList[0].type != String.Empty)
            {
                try
                {
                    MSDataFile msInfo = new MSDataFile(dirInfo.FullName);
                    sourceInfoList[0].populateFromMSData(msInfo);
                } catch (ThreadAbortException)
                {
                    return(null);
                } catch
                {
                    sourceInfoList[0].spectra = 0;
                    sourceInfoList[0].type    = "Invalid " + sourceInfoList[0].type;
                }

                sourceInfoList[0].size         = 0;
                sourceInfoList[0].dateModified = DateTime.MinValue;
                foreach (FileInfo fileInfo in dirInfo.GetFiles("*", SearchOption.AllDirectories))
                {
                    sourceInfoList[0].size += (UInt64)fileInfo.Length;
                    if (fileInfo.LastWriteTime > sourceInfoList[0].dateModified)
                    {
                        sourceInfoList[0].dateModified = fileInfo.LastWriteTime;
                    }
                }
                return(sourceInfoList.ToArray());
            }
            return(null);
        }
예제 #12
0
        public void Convert(string omssaCSV, MSDataFile dataFile)
        {
            string filePath = Path.ChangeExtension(omssaCSV, ".pepxml");

            using (PepXmlWriter writer = new PepXmlWriter(filePath))
            {
                writer.WriteSampleProtease(Protease);

                writer.StartSearchSummary("OMSSA", true, true);

                writer.WriteProteinDatabase(FastaDatabaseFile);

                writer.WriteSearchProtease(Protease, MissedClevages);

                foreach (int modNumber in FixedMods)
                {
                    OmssaModification mod;
                    if (OmssaModification.TryGetModification(modNumber, out mod))
                    {
                        writer.WriteModification(mod, mod.Sites, true);
                    }
                }

                foreach (int modNumber in VariableMods)
                {
                    OmssaModification mod;
                    if (OmssaModification.TryGetModification(modNumber, out mod))
                    {
                        writer.WriteModification(mod, mod.Sites, false);
                    }
                }


                writer.SetCurrentStage(PepXmlWriter.Stage.Spectra, true);

                using (OmssaCsvPsmReader reader = new OmssaCsvPsmReader(omssaCSV, UserModFile))
                {
                    reader.AddMSDataFile(dataFile);
                    reader.LoadProteins(FastaDatabaseFile);
                    foreach (PeptideSpectralMatch psm in reader.ReadNextPsm())
                    {
                        writer.StartSpectrum(psm.SpectrumNumber, psm.Spectrum.RetentionTime, psm.Spectrum.PrecursorMz, psm.Spectrum.PrecursorCharge);
                        writer.WritePSM(psm);
                        writer.EndSpectrum();
                    }
                }
            }
        }
예제 #13
0
        public ParseSpectraFile(string mzmlPath, HashSet <int> scanNumSet, string ext)
        {
            int currentScanNum = -1;

            try
            {
                MSDataFile   msd          = new MSDataFile(mzmlPath);
                SpectrumList spectrumList = msd.run.spectrumList;
                for (int i = 0; i < spectrumList.size(); ++i)
                {
                    Spectrum spectrum = spectrumList.spectrum(i, true);
                    if (int.Parse(spectrum.cvParams[0].value) == 2)
                    {
                        Match match = scanNumPattern.Match(spectrum.id);
                        currentScanNum = int.Parse(match.Groups[1].Value);
                        if (scanNumSet.Contains(currentScanNum))
                        {
                            MZIntensityPairList mzIntensityPairs = new MZIntensityPairList();
                            spectrum.getMZIntensityPairs(ref mzIntensityPairs);
                            Dictionary <float, int> originalPeakList = new Dictionary <float, int>(mzIntensityPairs.Count);
                            foreach (MZIntensityPair mzIntensity in mzIntensityPairs)
                            {
                                originalPeakList[(float)mzIntensity.mz] = (int)mzIntensity.intensity;
                            }

                            spectraMap[currentScanNum] = originalPeakList;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ": " + currentScanNum, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }
 private void SetupMSMSData()
 {
     dataFile = new MSDataFile(Properties.Settings.Default.mzXMLTestFile2);
     spectrumCache = new SpectrumCache();
     timePointToRtConverter = new RtToTimePointConverter(dataFile.run, spectrumCache);
 }
 public void MyTestInitialize()
 {
     dataFile = new MSDataFile(Properties.Settings.Default.mzXMLTestFile1);
     spectrumCache = new SpectrumCache();
     timePointToRtConverter = new RtToTimePointConverter(dataFile.run, spectrumCache);
 }
예제 #16
0
        public void UpdatePsmInformation(MSDataFile dataFile, bool is2dFDR = true, bool useMedian = true, double evalueThreshold = 1e-3)
        {
            List <double> errors = new List <double>();

            MaximumPrecursorMassError = 0;
            int           count          = 0;
            int           msms           = 0;
            int           ms             = 0;
            int           localMSMS      = -1;
            List <int>    msmsBetweenMS  = new List <int>();
            List <double> injectionTimes = new List <double>();

            for (int sn = dataFile.FirstSpectrumNumber; sn <= dataFile.LastSpectrumNumber; sn++)
            {
                int order = dataFile.GetMsnOrder(sn);
                if (order == 1)
                {
                    ms++;
                    if (localMSMS >= 0)
                    {
                        msmsBetweenMS.Add(localMSMS);
                    }
                    localMSMS = 0;
                }
                else
                {
                    localMSMS++;
                    msms++;
                    injectionTimes.Add(dataFile.GetInjectionTime(sn));
                }
            }
            MaxMSMSScansBetweenMS     = msmsBetweenMS.Max();
            AverageMSMSSCansBetweenMS = msmsBetweenMS.Average();
            TotalMSMSscans            = msms;
            TotalMSscans             = ms;
            AverageMSMSInjectionTime = injectionTimes.Average();
            MaxMSMSInjectionTime     = injectionTimes.Max();

            foreach (KeyValuePair <int, SortedMaxSizedContainer <PSM> > kvp in _data)
            {
                int scanNumber = kvp.Key;
                SortedMaxSizedContainer <PSM> psms = kvp.Value;

                double   isolationMZ = dataFile.GetPrecusorMz(scanNumber);
                Polarity polarity    = dataFile.GetPolarity(scanNumber);

                foreach (PSM psm in psms)
                {
                    psm.Charge     *= (int)polarity; // For negative mode ions
                    psm.IsolationMz = isolationMZ;
                    double    isolationMass   = Mass.MassFromMz(isolationMZ, psm.Charge);
                    double    theoreticalMass = psm.MonoisotopicMass;
                    int       nominalMassOffset;
                    double    adjustedIsolationMass;
                    Tolerance tolerancePPM = Tolerance.CalculatePrecursorMassError(theoreticalMass,
                                                                                   isolationMass, out nominalMassOffset, out adjustedIsolationMass);
                    psm.AdjustedIsolationMass = adjustedIsolationMass;
                    psm.IsotopeSelected       = nominalMassOffset;
                    if (!HasPPMInfo)
                    {
                        psm.PrecursorMassError = tolerancePPM.Value;
                    }

                    double positive = Math.Abs(psm.PrecursorMassError);
                    if (positive > MaximumPrecursorMassError)
                    {
                        MaximumPrecursorMassError = positive;
                    }

                    if (psm.FdrScoreMetric <= evalueThreshold)
                    {
                        errors.Add(psm.PrecursorMassError);
                    }

                    count++;
                }
            }

            SystematicPrecursorMassError = useMedian ? GetMedianValue(errors) : errors.Average();

            // Adjust all psms to
            foreach (PSM psm in PeptideSpectralMatches)
            {
                psm.CorrectedPrecursorMassError = psm.PrecursorMassError - SystematicPrecursorMassError;
            }
        }
        public void GetMSMSSpectrum()
        {
            dataFile = new MSDataFile(Properties.Settings.Default.mzXMLTestFile2);
            spectrumCache = new SpectrumCache();
            averagedSpectrumExtractor = new AveragedSpectrumExtractor(dataFile.run, spectrumCache);
            Domain.ISpectrum msmsSpectrum = averagedSpectrumExtractor.GetMSMSSpectrum(7.8, 1, 592.3, 0.5);

            Assert.AreEqual(42279, msmsSpectrum.Count);
            Assert.AreEqual(37, Math.Round(msmsSpectrum.GetXYPair(63).YValue, 5));
        }
예제 #18
0
        public static void quantify(Workspace ws, string rootInputDirectory, QuantitationInfo.Method method)
        {
            if (method == QuantitationInfo.Method.None)
                return;

            ws.groups.assembleParentGroups();
            foreach (SourceInfo source in ws.groups["/"].getSources(true))
            {
                source.filepath = Util.FindSourceInSearchPath(source.name, rootInputDirectory);
                using (MSDataFile msd = new MSDataFile(source.filepath))
                using (pwiz.CLI.msdata.SpectrumList sl = msd.run.spectrumList)
                {
                    foreach (SpectrumInfo si in source.spectra.Values)
                    {
                        int index = sl.find(si.nativeID);
                        if (index == sl.size())
                            throw new KeyNotFoundException("spectrum \"" + si.nativeID + "\" not found in " + source.filepath);

                        si.quantitation = new QuantitationInfo()
                        {
                            method = method,
                            ITRAQ_113_intensity = 0,
                            ITRAQ_114_intensity = 0,
                            ITRAQ_115_intensity = 0,
                            ITRAQ_116_intensity = 0,
                            ITRAQ_117_intensity = 0,
                            ITRAQ_118_intensity = 0,
                            ITRAQ_119_intensity = 0,
                            ITRAQ_121_intensity = 0
                        };

                        const double tolerance = 0.5; // TODO: make user configurable?

                        pwiz.CLI.msdata.Spectrum s = sl.spectrum(index, true);
                        BinaryData mzData = s.getMZArray().data;
                        BinaryData intensityData = s.getIntensityArray().data;

                        if (method == QuantitationInfo.Method.ITRAQ4Plex)
                            for (int i = 0; i < mzData.Count; ++i)
                            {
                                if (mzData[i] < 113) continue;
                                else if (inTolerance(mzData[i], 114, tolerance)) si.quantitation.ITRAQ_114_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 115, tolerance)) si.quantitation.ITRAQ_115_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 116, tolerance)) si.quantitation.ITRAQ_116_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 117, tolerance)) si.quantitation.ITRAQ_117_intensity += intensityData[i];
                                else if (mzData[i] > 117) break;
                            }
                        else if(method == QuantitationInfo.Method.ITRAQ8Plex)
                            for (int i = 0; i < mzData.Count; ++i)
                            {
                                if (mzData[i] < 112) continue;
                                else if (inTolerance(mzData[i], 113, tolerance)) si.quantitation.ITRAQ_113_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 114, tolerance)) si.quantitation.ITRAQ_114_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 115, tolerance)) si.quantitation.ITRAQ_115_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 116, tolerance)) si.quantitation.ITRAQ_116_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 117, tolerance)) si.quantitation.ITRAQ_117_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 118, tolerance)) si.quantitation.ITRAQ_118_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 119, tolerance)) si.quantitation.ITRAQ_119_intensity += intensityData[i];
                                else if (inTolerance(mzData[i], 121, tolerance)) si.quantitation.ITRAQ_121_intensity += intensityData[i];
                                else if (mzData[i] > 121) break;
                            }
                    }
                }
            }
        }
예제 #19
0
 public MsnDataScan(int spectrumNumber, int msnOrder, MSDataFile <TSpectrum> parentFile = null)
     : base(spectrumNumber, msnOrder, parentFile)
 {
 }
예제 #20
0
        //get pepSequence,source,scanID, write into a csv file.
        //have tons of information: theretical ion intensity, pep info, chargeLabel...
        public static void idpReader(string idpXMLFile, string mzMLFile, double TicCutoffPercentage, int z, int model)
        {
            //get the path and filename of output csv file:
            string fileName = Path.GetFileNameWithoutExtension(idpXMLFile);
            string filePath = Path.GetDirectoryName(idpXMLFile);
            string csvFile = Path.Combine(filePath, fileName) + "_" + z.ToString() + ".csv";

            IDPicker.Workspace workspace = new IDPicker.Workspace();
            Package.loadWorkspace(ref workspace, idpXMLFile);

            using (StreamWriter file = new StreamWriter(csvFile))
            {
                //TODO idOrIndex + "," + pepSequence + "," + pepBond + "," + AA + "," + bIons + "," + yIons;
                file.WriteLine("nativeID,pepSequence,bond,b1,b2,y1,y2");

                MSDataFile foo = new MSDataFile(mzMLFile);
                SpectrumList sl = foo.run.spectrumList;

                foreach (IDPicker.SourceGroupList.MapPair groupItr in workspace.groups)
                    foreach (IDPicker.SourceInfo source in groupItr.Value.getSources(true))
                        foreach (IDPicker.SpectrumList.MapPair sItr in source.spectra)
                        {

                            IDPicker.ResultInstance ri = sItr.Value.results[1];
                            IDPicker.VariantInfo vi = ri.info.peptides.Min;

                            string ss = vi.ToString() + "," + sItr.Value.id.source.name + "," + sItr.Value.nativeID;
                            bool boolCharge = sItr.Value.id.charge.Equals(z);
                            if (boolCharge)
                            {
                                string rawPepSequence = vi.ToString();
                                string pepSequence = vi.peptide.sequence;
                                int len = pepSequence.Length;

                                // Look up the index with nativeID
                                object idOrIndex = null;
                                if( sItr.Value.nativeID != null && sItr.Value.nativeID.Length > 0 )
                                    idOrIndex = sItr.Value.nativeID;
                                int spectrumIndex = sl.find(idOrIndex as string);
                                // Trust the local index, if the nativeID lookup fails
                                if( spectrumIndex >= sl.size() )
                                    spectrumIndex = sItr.Value.id.index;
                                // Bail of the loca index is larger than the spectrum list size
                                if( spectrumIndex >= sl.size() )
                                    throw new Exception( "Can't find spectrum associated with the index." );

                                //get base peak and TIC and converted to string
                                Spectrum spec1 = sl.spectrum(spectrumIndex, true);
                                MZIntensityPairList peaks = new MZIntensityPairList();
                                spec1.getMZIntensityPairs(ref peaks);
                                Set<Peak> peakList = new Set<Peak>();

                                //get base peak and TIC
                                double basePeakValue = 0;
                                double TICValue = 0;
                                CVParamList list = spec1.cvParams;
                                foreach (CVParam CVP in list)
                                {
                                    if (CVP.name == "base peak intensity")
                                    {
                                        basePeakValue = CVP.value;
                                    }
                                    if (CVP.name == "total ion current")
                                    {
                                        TICValue = CVP.value;
                                    }
                                }
                                string basePeak = basePeakValue.ToString();
                                string TIC = TICValue.ToString();

                                //very important. Surendra put them here
                                //to change those with modifications {} into a format
                                //that fragment method will accept.
                                string interpretation = vi.ToSimpleString();

                                Peptide peptide = new Peptide(interpretation, ModificationParsing.ModificationParsing_Auto, ModificationDelimiter.ModificationDelimiter_Brackets);

                                Fragmentation fragmentation = peptide.fragmentation(true, true);
                                //prepare the qualified peaklist
                                double intenThreshhold = 0;
                                int totalIntenClass = 0;

                                double[] intenArray = new double[peaks.Count];
                                //used during the foreach loop
                                int indexPeaks = 0;

                                //get all the peaks no matter how small they are
                                //then calculate the threshhold TIC
                                //test here
                                foreach (MZIntensityPair mzIntensity in peaks)
                                {
                                    //Peak p = new Peak(mzIntensity.mz, mzIntensity.intensity);
                                    //peakList.Add(p);
                                    intenArray[indexPeaks] = mzIntensity.intensity;
                                    indexPeaks++;
                                }
                                Array.Sort(intenArray);
                                Array.Reverse(intenArray, 0, peaks.Count);

                                //if currTIC>=cutoff, then break
                                double currTIC = 0;
                                double cutOffTIC = TicCutoffPercentage * TICValue;
                                foreach (double inten in intenArray)
                                {
                                    currTIC = currTIC + inten;
                                    if (currTIC < cutOffTIC)
                                    {
                                        intenThreshhold = inten;
                                        totalIntenClass++;
                                    }
                                    else break;
                                }

                                //then based on that, generate a new peaklist that contains only ABC peaks
                                //then calculate the intensity classes
                                foreach (MZIntensityPair mzIntensity in peaks)
                                {
                                    if (mzIntensity.intensity >= intenThreshhold)
                                    {
                                        //note 0 here. This is to tell people that the orbiorbi fragment charge is unknown.
                                        //the peaklist will be updated later.
                                        Peak p = new Peak(mzIntensity.mz, mzIntensity.intensity,0);
                                        peakList.Add(p);
                                    }
                                }
                                Console.WriteLine("nativeID: =============" + idOrIndex);
                                //update peaklist for charge states.
                                peakList = Package.chargeAssignment(peakList);
                                        //int ones = 0;
                                        //int twos = 0;
                                        //foreach (var peak in peakList)
                                        //{
                                        //    //Console.WriteLine(peak.fragmentCharge);
                                        //    if (peak.fragmentCharge == 1) ones++;
                                        //    else if (peak.fragmentCharge == 2) twos++;
                                        //}

                                        //Console.WriteLine("charge 1: " + ones);
                                        //Console.WriteLine("charge 2: " + twos);

                                //rowDic contains row information of each peptide bond
                                Dictionary<int, string> rowDic = new Dictionary<int, string>();
                                //intensityDic contains intensity information of fragment ions for each peptide bond
                                Dictionary<int, List<double>> intensityDic = new Dictionary<int, List<double>>();
                                //commonList contains the common intensities
                                List<double> duplicateList = new List<double>();

                                //call the method
                                List<double> completeIntensityList = new List<double>();
                                for (int k = 1; k < len; k++)
                                {
                                    List<double> intensityList = new List<double>();

                                    string bion = pepSequence.Substring(0, k);
                                    string yion = pepSequence.Substring(k, len - k);

                                    int NR = Package.parseAAResidues(bion, 'R');
                                    int NK = Package.parseAAResidues(bion, 'K');
                                    int NH = Package.parseAAResidues(bion, 'H');
                                    int NL = k;
                                    int CR = Package.parseAAResidues(yion, 'R');
                                    int CK = Package.parseAAResidues(yion, 'K');
                                    int CH = Package.parseAAResidues(yion, 'H');
                                    int CL = len - k;
                                    int pepBond = k;
                                    int NBasicAA = NR + NK + NH;
                                    int CBasicAA = CR + CK + CH;
                                    string AA = NR + "," + NK + "," + NH + "," + NL + "," + CR + "," + CK + "," + CH + "," + CL;

                                    double[] bCharge = new double[z + 1];
                                    double[] yCharge = new double[z + 1];
                                    //double[] bIntensity = new double[z + 1];
                                    //double[] yIntensity = new double[z + 1];
                                    //add variable for "real" charges

                                    if (model == 0) //naive model
                                    {
                                        int[] bFragmentCharge = new int[z + 1];
                                        int[] yFragmentCharge = new int[z + 1];
                                        //return the b ion charge 1 Intensity, if matched
                                        for (int i = 1; i < z; i++)
                                        {
                                            bCharge[i] = fragmentation.b(k, i);
                                            yCharge[i] = fragmentation.y(len - k, i);
                                            //change for ORBI-ORBI purposes.
                                            Peak bmatched = Package.findClose(peakList, bCharge[i], bCharge[i] * 30 * Math.Pow(10, -6));
                                            Peak ymatched = Package.findClose(peakList, yCharge[i], yCharge[i] * 30 * Math.Pow(10, -6));
                                            if (bmatched != null)
                                            {
                                                //bIntensity[i] = bmatched.rankOrIntensity;
                                                int fragmentCharge = bmatched.fragmentCharge;
                                                if (fragmentCharge == i)
                                                    bFragmentCharge[i] = 3;
                                                else bFragmentCharge[i] = 2;
                                                //intensityList.Add(bmatched.rankOrIntensity);
                                                //completeIntensityList.Add(bmatched.rankOrIntensity);
                                            }
                                            else bFragmentCharge[i] = 1;
                                            //else bIntensity[i] = 0;
                                            if (ymatched != null)
                                            {
                                                //yIntensity[i] = ymatched.rankOrIntensity;
                                                //yFragmentCharge[i] = ymatched.fragmentCharge;
                                                int fragmentCharge = ymatched.fragmentCharge;
                                                if (fragmentCharge == i)
                                                    yFragmentCharge[i] = 3;
                                                else yFragmentCharge[i] = 2;
                                                //intensityList.Add(ymatched.rankOrIntensity);
                                                //completeIntensityList.Add(ymatched.rankOrIntensity);
                                            }
                                            else yFragmentCharge[i] = 1;
                                            //else yIntensity[i] = 0;
                                        }
                                        string finalString = idOrIndex + "," + pepSequence + "," + pepBond + "," + bFragmentCharge[1] + "," + bFragmentCharge[2] + "," + yFragmentCharge[1] + "," + yFragmentCharge[2];
                                        file.WriteLine(finalString);
                                    }
                                    else if (model == 1) //my binary logistic regression basophile model
                                    {
                                        int b1=0, b2=0, y1=0, y2 = 0;
                                        double y1_logit = 0.1098112 * NR + 0.2085831 * NK + 0.1512109 * NH + 0.0460839 * NL
                                                        - 0.3872417 * CR - 0.3684911 * CK - 0.1634741 * CH - 0.1693931 * CL + 1.2632997;
                                        double y2_logit =-0.6345364 * NR - 0.3365917 * NK - 0.4577882 * NH - 0.1492703 * NL
                                                        + 0.7738133 * CR + 0.6036758 * CK + 0.5942542 * CH + 0.0701467 * CL + 0.0806280;
                                        double b1_logit = 0.0801432 * NR - 0.1088081 * NK - 0.1338220 * NH - 0.1413059 * NL
                                                        - 0.3157957 * CR - 0.2708274 * CK - 0.3703136 * CH + 0.0157418 * CL + 1.2124699;
                                        double b2_logit = 0.8606449 * NR + 0.2763119 * NK + 0.4969152 * NH + 0.0685712 * NL
                                                        - 1.3346995 * CR - 1.0977316 * CK - 1.0973677 * CH - 0.2028884 * CL + 1.9355980;
                                        if (b1_logit > -0.5)
                                        {
                                            double mz_b1 = fragmentation.b(k, 1);
                                            Peak matched = Package.findClose(peakList, mz_b1, mz_b1 * 30 * Math.Pow(10, -6));
                                            if (matched != null)
                                            {
                                                if (matched.fragmentCharge == 1) b1 = 3;
                                                else b1 = 2;
                                            }
                                            else b1 = 1;
                                        }
                                        else b1 = 0;
                                        if (b2_logit > 0)
                                        {
                                            double mz_b2 = fragmentation.b(k, 2);
                                            Peak matched = Package.findClose(peakList, mz_b2, mz_b2 * 30 * Math.Pow(10, -6));
                                            if (matched != null)
                                            {
                                                if (matched.fragmentCharge == 2) b2 = 3;
                                                else b2 = 2;
                                            }
                                            else b2 = 1;
                                        }
                                        else b2 = 0;
                                        if (y1_logit > -0.5)
                                        {
                                            double mz_y1 = fragmentation.y(len - k, 1);
                                            Peak matched = Package.findClose(peakList, mz_y1, mz_y1 * 30 * Math.Pow(10, -6));
                                            if (matched != null)
                                            {
                                                if (matched.fragmentCharge == 1) y1 = 3;
                                                else y1 = 2;
                                            }
                                            else y1 = 1;
                                        }
                                        else y1 = 0;
                                        if (y2_logit > -0.5)
                                        {
                                            double mz_y2 = fragmentation.y(len - k, 2);
                                            Peak matched = Package.findClose(peakList, mz_y2, mz_y2 * 30 * Math.Pow(10, -6));
                                            if (matched != null)
                                            {
                                                if (matched.fragmentCharge == 2) y2 = 3;
                                                else y2 = 2;
                                            }
                                            else y2 = 1;
                                        }
                                        else y2 = 0;
                                        string finalString = idOrIndex + "," + pepSequence + "," + pepBond + "," + b1 + "," + b2 + "," + y1 + "," + y2;
                                        file.WriteLine(finalString);
                                    }

                                    else if (model == 2) //Surendra's ordinal model
                                    {
                                        int b1 = 0, b2 = 0, y1 = 0, y2 = 0;
                                        double logit = NR * 0.9862 + NH * 0.8772 + NK * 0.7064 + NL * 0.4133
                                                     - CR * 1.1688 - CH * 0.3948 - CK * 0.6710 - CL * 0.4859;
                                        //charge Label = "1", generate b+,y++
                                        if (logit < -2.2502)
                                        {
                                            double mz_b1 = fragmentation.b(k, 1);
                                            Peak b1matched = Package.findClose(peakList, mz_b1, mz_b1 * 30 * Math.Pow(10, -6));
                                            if (b1matched != null)
                                            {
                                                if (b1matched.fragmentCharge == 1) b1 = 3;  //matched, charge agree
                                                else b1 = 2; //matched, charge does not agree
                                            }
                                            else b1 = 1; //unmatched, but predicted.

                                            double mz_y2 = fragmentation.y(len - k, 2);
                                            Peak y2matched = Package.findClose(peakList, mz_y2, mz_y2 * 30 * Math.Pow(10, -6));
                                            if (y2matched != null)
                                            {
                                                if (y2matched.fragmentCharge == 2) y2 = 3;  //matched, charge agree
                                                else y2 = 2; //matched, charge does not agree
                                            }
                                            else y2 = 1; //unmatched, but predicted.
                                        }
                                        //ambiLabel = "2", generate b+, y+, b++, y++
                                        else if (logit < 0.7872)
                                        {
                                            double mz_b1 = fragmentation.b(k, 1);
                                            Peak b1matched = Package.findClose(peakList, mz_b1, mz_b1 * 30 * Math.Pow(10, -6));
                                            if (b1matched != null)
                                            {
                                                if (b1matched.fragmentCharge == 1) b1 = 3;  //matched, charge agree
                                                else b1 = 2; //matched, charge does not agree
                                            }
                                            else b1 = 1; //unmatched, but predicted.

                                            double mz_y1 = fragmentation.y(len - k, 1);
                                            Peak y1matched = Package.findClose(peakList, mz_y1, mz_y1 * 30 * Math.Pow(10, -6));
                                            if (y1matched != null)
                                            {
                                                if (y1matched.fragmentCharge == 1) y1 = 3;  //matched, charge agree
                                                else y1 = 2; //matched, charge does not agree
                                            }
                                            else y1 = 1; //unmatched, but predicted.

                                            double mz_b2 = fragmentation.b(k, 2);
                                            Peak b2matched = Package.findClose(peakList, mz_b2, mz_b2 * 30 * Math.Pow(10, -6));
                                            if (b2matched != null)
                                            {
                                                if (b2matched.fragmentCharge == 2) b2 = 3;  //matched, charge agree
                                                else b2 = 2; //matched, charge does not agree
                                            }
                                            else b2 = 1; //unmatched, but predicted.

                                            double mz_y2 = fragmentation.y(len - k, 2);
                                            Peak y2matched = Package.findClose(peakList, mz_y2, mz_y2 * 30 * Math.Pow(10, -6));
                                            if (y2matched != null)
                                            {
                                                if (y2matched.fragmentCharge == 2) y2 = 3;  //matched, charge agree
                                                else y2 = 2; //matched, charge does not agree
                                            }
                                            else y2 = 1; //unmatched, but predicted.
                                        }
                                        //ambiLabel = "3", generate b++,y+
                                        else
                                        {
                                            double mz_b2 = fragmentation.b(k, 2);
                                            Peak b2matched = Package.findClose(peakList, mz_b2, mz_b2 * 30 * Math.Pow(10, -6));
                                            if (b2matched != null)
                                            {
                                                if (b2matched.fragmentCharge == 2) b2 = 3;  //matched, charge agree
                                                else b2 = 2; //matched, charge does not agree
                                            }
                                            else b2 = 1; //unmatched, but predicted.

                                            double mz_y1 = fragmentation.y(len - k, 1);
                                            Peak y1matched = Package.findClose(peakList, mz_y1, mz_y1 * 30 * Math.Pow(10, -6));
                                            if (y1matched != null)
                                            {
                                                if (y1matched.fragmentCharge == 1) y1 = 3;  //matched, charge agree
                                                else y1 = 2; //matched, charge does not agree
                                            }
                                            else y1 = 1; //unmatched, but predicted.
                                        }
                                        string finalString = idOrIndex + "," + pepSequence + "," + pepBond + "," + b1 + "," + b2 + "," + y1 + "," + y2;
                                        file.WriteLine(finalString);
                                    }

                                    //intensityDic.Add(pepBond, intensityList);

                                    //rowDic.Add(pepBond, finalString);
                                }//end for each peptide bond
                            }//end if z==3
                        }//end foreach peptide
            }//end using
        }
예제 #21
0
 public MSDataScan(int spectrumNumber, int msnOrder = 1, MSDataFile parentFile = null)
 {
     SpectrumNumber = spectrumNumber;
     MsnOrder       = msnOrder;
     ParentFile     = parentFile;
 }
예제 #22
0
        ///<summary>
        ///original code for grabbing the required ions
        ///get pepSequence,source,scanID, write into a csv file. 
        ///have tons of information: theretical ion intensity, pep info, chargeLabel...
        ///</summary>
        public static List<string> idpReader_original(string idpXMLFile, string mzMLFile, double TicCutoffPercentage, int z, List<string> pepList, List<string> output)
        {
            //get the path and filename of output csv file:
            string fileName = Path.GetFileNameWithoutExtension(idpXMLFile);
            string filePath = Path.GetDirectoryName(idpXMLFile);
            IDPicker.Workspace workspace = new IDPicker.Workspace();
            Package.loadWorkspace(ref workspace, idpXMLFile);

            MSDataFile foo = new MSDataFile(mzMLFile);
            SpectrumList sl = foo.run.spectrumList;

            foreach (IDPicker.SourceGroupList.MapPair groupItr in workspace.groups)
                foreach (IDPicker.SourceInfo source in groupItr.Value.getSources(true))
                    foreach (IDPicker.SpectrumList.MapPair sItr in source.spectra)
                    {

                        IDPicker.ResultInstance ri = sItr.Value.results[1];
                        IDPicker.VariantInfo vi = ri.info.peptides.Min;

                        string ss = vi.ToString() + "," + sItr.Value.id.source.name + "," + sItr.Value.nativeID;
                        bool boolCharge = sItr.Value.id.charge.Equals(z);
                        if (boolCharge)
                        {
                            string rawPepSequence = vi.ToString();
                            string pepSequence = vi.peptide.sequence;
                            int len = pepSequence.Length;

                            //make sure that the peptide is what we want
                            if (pepList.Contains(pepSequence))
                            {
                                // Look up the index with nativeID
                                object idOrIndex = null;
                                if (sItr.Value.nativeID != null && sItr.Value.nativeID.Length > 0)
                                    idOrIndex = sItr.Value.nativeID;
                                int spectrumIndex = sl.find(idOrIndex as string);
                                // Trust the local index, if the nativeID lookup fails
                                if (spectrumIndex >= sl.size())
                                    spectrumIndex = sItr.Value.id.index;
                                // Bail of the loca index is larger than the spectrum list size
                                if (spectrumIndex >= sl.size())
                                    throw new Exception("Can't find spectrum associated with the index.");

                                //Console.WriteLine(idOrIndex.ToString());
                                //get base peak and TIC and converted to string
                                Spectrum spec1 = sl.spectrum(spectrumIndex, true);
                                MZIntensityPairList peaks = new MZIntensityPairList();
                                spec1.getMZIntensityPairs(ref peaks);
                                Set<Peak> peakList = new Set<Peak>();

                                //get base peak and TIC
                                double basePeakValue = 0;
                                double TICValue = 0;
                                CVParamList list = spec1.cvParams;
                                foreach (CVParam CVP in list)
                                {
                                    if (CVP.name == "base peak intensity")
                                    {
                                        basePeakValue = CVP.value;
                                    }
                                    if (CVP.name == "total ion current")
                                    {
                                        TICValue = CVP.value;
                                    }
                                }
                                string basePeak = basePeakValue.ToString();
                                string TIC = TICValue.ToString();

                                //very important. Surendra put them here
                                //to change those with modifications {} into a format
                                //that fragment method will accept.
                                string interpretation = vi.ToSimpleString();

                                Peptide peptide = new Peptide(interpretation, ModificationParsing.ModificationParsing_Auto, ModificationDelimiter.ModificationDelimiter_Brackets);

                                Fragmentation fragmentation = peptide.fragmentation(true, true);
                                //prepare the qualified peaklist
                                double intenThreshhold = 0;
                                int totalIntenClass = 0;

                                double[] intenArray = new double[peaks.Count];
                                //used during the foreach loop
                                int indexPeaks = 0;

                                //get all the peaks no matter how small they are
                                //then calculate the threshhold TIC
                                //test here
                                foreach (MZIntensityPair mzIntensity in peaks)
                                {
                                    //Peak p = new Peak(mzIntensity.mz, mzIntensity.intensity);
                                    //peakList.Add(p);
                                    intenArray[indexPeaks] = mzIntensity.intensity;
                                    indexPeaks++;
                                }
                                Array.Sort(intenArray);
                                Array.Reverse(intenArray, 0, peaks.Count);

                                //if currTIC>=cutoff, then break
                                double currTIC = 0;
                                double cutOffTIC = TicCutoffPercentage * TICValue;
                                foreach (double inten in intenArray)
                                {
                                    currTIC = currTIC + inten;
                                    if (currTIC < cutOffTIC)
                                    {
                                        intenThreshhold = inten;
                                        totalIntenClass++;
                                    }
                                    else break;
                                }

                                //then based on that, generate a new peaklist that contains only ABC peaks
                                //then calculate the intensity classes
                                foreach (MZIntensityPair mzIntensity in peaks)
                                {
                                    if (mzIntensity.intensity >= intenThreshhold)
                                    {
                                        Peak p = new Peak(mzIntensity.mz, mzIntensity.intensity);
                                        peakList.Add(p);
                                    }
                                }

                                //rowDic contains row information of each peptide bond
                                Dictionary<int, string> rowDic = new Dictionary<int, string>();
                                //intensityDic contains intensity information of fragment ions for each peptide bond
                                Dictionary<int, List<double>> intensityDic = new Dictionary<int, List<double>>();
                                //commonList contains the common intensities
                                List<double> duplicateList = new List<double>();

                                //call the method
                                List<double> completeIntensityList = new List<double>();
                                for (int k = 1; k < len; k++)
                                {
                                    List<double> intensityList = new List<double>();

                                    string bion = pepSequence.Substring(0, k);
                                    string yion = pepSequence.Substring(k, len - k);

                                    int NR = Package.parseAAResidues(bion, 'R');
                                    int NK = Package.parseAAResidues(bion, 'K');
                                    int NH = Package.parseAAResidues(bion, 'H');
                                    int NL = k;
                                    int CR = Package.parseAAResidues(yion, 'R');
                                    int CK = Package.parseAAResidues(yion, 'K');
                                    int CH = Package.parseAAResidues(yion, 'H');
                                    int CL = len - k;
                                    int R = NR - CR;
                                    int K = NK - CK;
                                    int H = NH - CH;
                                    int L = NL - CL;
                                    int pepBond = k;
                                    int NBasicAA = NR + NK + NH;
                                    int CBasicAA = CR + CK + CH;
                                    string AA = NBasicAA + "," + CBasicAA + "," + NR + "," + NK + "," + NH + "," + NL + "," + CR + "," + CK + "," + CH + "," + CL + "," + R + "," + K + "," + H + "," + L;

                                    double[] bCharge = new double[z + 1];
                                    double[] yCharge = new double[z + 1];
                                    double[] bIntensity = new double[z + 1];
                                    double[] yIntensity = new double[z + 1];
                                    string bIonIntensity = "";
                                    string yIonIntensity = "";
                                    //to judge if the sum of intensities are 0
                                    //so to exclude the case with all "0s"
                                    double sumIntensity = 0;

                                    //return the b ion charge 1 Intensity, if matched
                                    for (int i = 1; i <= z; i++)
                                    {
                                        bCharge[i] = fragmentation.b(k, i);
                                        yCharge[i] = fragmentation.y(len - k, i);
                                        //change for Q-star purposes.
                                        Peak bmatched = Package.findClose(peakList, bCharge[i], 70 * bCharge[i] * Math.Pow(10, -6));
                                        Peak ymatched = Package.findClose(peakList, yCharge[i], 70 * yCharge[i] * Math.Pow(10, -6));
                                        if (bmatched != null)
                                        {
                                            bIntensity[i] = bmatched.rankOrIntensity;
                                            intensityList.Add(bmatched.rankOrIntensity);
                                            completeIntensityList.Add(bmatched.rankOrIntensity);
                                        }
                                        else bIntensity[i] = 0;
                                        if (ymatched != null)
                                        {
                                            yIntensity[i] = ymatched.rankOrIntensity;
                                            intensityList.Add(ymatched.rankOrIntensity);
                                            completeIntensityList.Add(ymatched.rankOrIntensity);
                                        }
                                        else yIntensity[i] = 0;

                                        sumIntensity = sumIntensity + bIntensity[i] + yIntensity[i];

                                        //record b/y ion intensity information into a string
                                        bIonIntensity = bIonIntensity + "," + bIntensity[i];
                                        yIonIntensity = yIonIntensity + "," + yIntensity[i];

                                    }

                                    intensityDic.Add(pepBond, intensityList);
                                    //to determine charge label, need to split by precursor charge
                                    //first need to make a metric to determine if all intensities are "0"

                                    if (z == 3)
                                    {
                                        if (sumIntensity != 0)
                                        {
                                            ////////////////////////////////////////////////
                                            //set the ambiguity label as follows:
                                            //-3: (0/+3) y3 only
                                            //-2: (0/+3, +1/+2) y3, b1y2
                                            //-1: (+1/+2): b1y2
                                            //0: (+1/+2, +2/+1): b1y2, b2y1
                                            //1: (+2/+1): b2y1
                                            //2: (+2/+1, +3/0): b2y1, b3
                                            //3: (+3/0): b3 only
                                            ////////////////////////////////////////////////

                                            double b1 = bIntensity[1];
                                            double b2 = bIntensity[2];
                                            double y1 = yIntensity[1];
                                            double y2 = yIntensity[2];
                                            double b3 = bIntensity[3];
                                            double y3 = yIntensity[3];
                                            double b1y2 = b1 + y2;
                                            double b2y1 = b2 + y1;
                                            string ambiguityLabel = "";
                                            //first part: set the intensity group: y3, b1y2, b2y1, b3
                                            //if one group was found, set the label
                                            //if two were found, but adjacent to each other, then ambiguity label is set
                                            if (y3 != 0 && (b1y2 + b2y1 + b3) == 0) ambiguityLabel = "-3";
                                            else if (y3 != 0 && b1y2 != 0 && (b2y1 + b3) == 0) ambiguityLabel = "-2";
                                            else if (b1y2 != 0 && (y3 + b2y1 + b3) == 0) ambiguityLabel = "-1";
                                            else if (b1y2 != 0 && b2y1 != 0 && (y3 + b3) == 0) ambiguityLabel = "0";
                                            else if (b2y1 != 0 && (y3 + b1y2 + b3) == 0) ambiguityLabel = "1";
                                            else if (b2y1 != 0 && b3 != 0 && (y3 + b1y2) == 0) ambiguityLabel = "2";
                                            else if (b3 != 0 && (y3 + b1y2 + b2y1) == 0) ambiguityLabel = "3";
                                            else ambiguityLabel = "error";

                                            string finalString = idOrIndex + "," + pepSequence + "," + basePeak + "," + TIC + bIonIntensity + yIonIntensity + "," + len + "," + pepBond + "," + AA + "," + ambiguityLabel;
                                            rowDic.Add(pepBond, finalString);
                                        }
                                    }
                                }//end for each peptide bond

                                //now we have: rowDic, intensityDic for each pep bond
                                //and we have: and completeIntensityList for each peptide
                                //the purpose of this is to remove such rows with duplicate matches
                                duplicateList = Package.findCommon(completeIntensityList);
                                foreach (int bond in rowDic.Keys)
                                {
                                    bool unique = true;
                                    foreach (double inten in duplicateList)
                                    {
                                        if (intensityDic[bond].Contains(inten))
                                        {
                                            unique = false;
                                            Console.WriteLine("kick");
                                            break;
                                        }
                                    }
                                    if (unique)
                                    {
                                        output.Add(rowDic[bond]);
                                    }
                                }
                            }//end of if peplist contains pepsequence
                        }//end if z==3
                    }//end foreach peptide
            return output;
        }
예제 #23
0
        void processFile(string filename, Config config, ReaderList readers, Map <string, int> usedOutputFilenames)
        {
            // read in data file
            using (var msdList = new MSDataList())
            {
                string msg = String.Format("Opening file \"{0}\" for read...", filename);
                var    stripCredentialsMatch = Regex.Match(filename, "https?://([^:]+:[^@]+@).*", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                if (stripCredentialsMatch.Success)
                {
                    msg = msg.Replace(stripCredentialsMatch.Groups[1].Value, "");
                }

                LogUpdate?.Invoke(msg, _info);
                StatusUpdate?.Invoke(msg, ProgressBarStyle.Marquee, _info);
                readers.read(filename, msdList, config.ReaderConfig);

                foreach (var msd in msdList)
                {
                    try
                    {
                        var    outputFilename       = config.outputFilename(filename, msd);
                        string deduplicatedFilename = outputFilename;

                        StatusUpdate?.Invoke("Waiting...", ProgressBarStyle.Marquee, _info);

                        // only one thread
                        lock (_calculateSHA1Mutex)
                        {
                            // if output name is same as input name, add a suffix
                            if (filename == outputFilename)
                            {
                                ++usedOutputFilenames[outputFilename];
                            }

                            if (usedOutputFilenames.Contains(deduplicatedFilename))
                            {
                                deduplicatedFilename = deduplicatedFilename.Replace(Path.GetExtension(outputFilename), String.Format(" ({0}).{1}", usedOutputFilenames[outputFilename] + 1, Path.GetExtension(outputFilename)));
                            }
                            ++usedOutputFilenames[outputFilename];

                            LogUpdate?.Invoke("Calculating SHA1 checksum...", _info);
                            StatusUpdate?.Invoke("Calculating SHA1 checksum...", ProgressBarStyle.Marquee, _info);
                            MSDataFile.calculateSHA1Checksums(msd);
                        }

                        var ilr = new IterationListenerRegistry();
                        ilr.addListenerWithTimer(this, 1);

                        LogUpdate?.Invoke("Processing...", _info);
                        StatusUpdate?.Invoke("Processing...", ProgressBarStyle.Marquee, _info);

                        SpectrumListFactory.wrap(msd, config.Filters, ilr);

                        config.WriteConfig.useWorkerThreads = msd.run.spectrumList.benefitsFromWorkerThreads();

                        if ((msd.run.spectrumList == null) || msd.run.spectrumList.empty())
                        {
                            if ((msd.run.chromatogramList != null) && !msd.run.chromatogramList.empty())
                            {
                                msg = "Note: input contains only chromatogram data.";
                                switch (config.WriteConfig.format)
                                {
                                case MSDataFile.Format.Format_MZ5:
                                case MSDataFile.Format.Format_mzML:
                                    break;

                                default:
                                    msg += "  The selected output format can only represent spectra.  Consider using mzML instead.";
                                    break;
                                }
                            }
                            else
                            {
                                msg = "Note: input contains no spectra or chromatogram data.";
                            }
                            LogUpdate?.Invoke(msg, _info);
                            StatusUpdate?.Invoke(msg, ProgressBarStyle.Continuous, _info);
                        }

                        if (StatusUpdate != null && msd.run.spectrumList != null)
                        {
                            StatusUpdate(String.Format("Processing ({0} of {1})",
                                                       DataGridViewProgressCell.MessageSpecialValue.CurrentValue,
                                                       DataGridViewProgressCell.MessageSpecialValue.Maximum),
                                         ProgressBarStyle.Continuous, _info);
                        }

                        // write out the new data file
                        msg = String.Format("Writing \"{0}\"...", deduplicatedFilename);
                        LogUpdate?.Invoke(msg, _info);
                        StatusUpdate?.Invoke(msg, ProgressBarStyle.Continuous, _info);
                        MSDataFile.write(msd, deduplicatedFilename, config.WriteConfig, ilr);
                        ilr.removeListener(this);
                    }
                    finally
                    {
                        msd.Dispose();
                    }
                }
            }
        }
예제 #24
0
파일: MsnDataScan.cs 프로젝트: B-Rich/CSMSL
 public MsnDataScan(int spectrumNumber, int msnOrder, MSDataFile parentFile = null)
     : base(spectrumNumber, msnOrder, parentFile)
 {
 }
예제 #25
0
파일: PSM.cs 프로젝트: kmmbvnr/Compass
 public void SetRawFile(MSDataFile dataFile)
 {
     MsnDataScan scan = dataFile[ScanNumber] as MsnDataScan;
     IsolationMZ = scan.IsolationRange.Mean;
     Spectrum = dataFile.GetReadOnlyMZSpectrum(ScanNumber, true);
     ScanWidth = scan.MzRange.Width;
 }
예제 #26
0
        public static void RawFileToCsv <T>(MSDataFile <T> msDataFile, string outputFilePath) where T : ISpectrum
        {
            // See the BasicCsvWriting example for more details

            Console.WriteLine("Writing file to: " + outputFilePath);

            // The main field delimiter, for CSV it is a comma
            const char delimiter = ',';

            using (StreamWriter writer = new StreamWriter(outputFilePath))
            {
                // Now that the stream is open, we can a line of text to it to serve as the header row.
                // CSV formats are just text files with fields separated by commas.
                writer.WriteLine("Spectrum Number,MS Level,Precursor m/z,# of Peaks in Spectrum,m/z Range");

                // The using statement on the msDataFile will ensure that things are properly disposed of after
                // you are done using the file, or if an exception has occurred.
                using (msDataFile)
                {
                    // MsDataFiles require opening their data connection manually.
                    msDataFile.Open();

                    // Simply loop over every data scan in the file
                    foreach (MSDataScan <T> scan in msDataFile)
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.Append(scan.SpectrumNumber);
                        sb.Append(delimiter);

                        sb.Append(scan.MsnOrder);
                        sb.Append(delimiter);

                        // We need to check if this is an MS1 or MS2 scan. Both scans are of type MSDataScan,
                        // but for MS2 scans, there is additional information (precursor m/z for example). So we need
                        // to cast it to MsnDataScan to access those properties.
                        // Try casting using the 'as' keyword. It will either return the cast object or null, so we need to
                        // check for null before trying to access a property of it.
                        MsnDataScan <T> msnScan = scan as MsnDataScan <T>;
                        if (msnScan != null)
                        {
                            // It is a MS2 scan

                            sb.Append(msnScan.GetPrecursorMz());
                        }
                        else
                        {
                            // It is a MS1 scan, so no precursor information. So lets put Not an Number in this column.
                            // you could skip this if you want to have blank cells.
                            sb.Append(double.NaN);
                        }
                        sb.Append(delimiter);

                        // We can just use the original scan object now
                        sb.Append(scan.MassSpectrum.Count);
                        sb.Append(delimiter);

                        sb.Append(scan.MzRange);

                        writer.WriteLine(sb.ToString());
                    }
                }
            }
        }
예제 #27
0
파일: InputFile.cs 프로젝트: B-Rich/Compass
        public void UpdatePsmInformation(MSDataFile dataFile, bool is2dFDR = true, bool useMedian = true, double evalueThreshold = 1e-3)
        {
            List<double> errors = new List<double>();
            MaximumPrecursorMassError = 0;
            int count = 0;
            int msms = 0;
            int ms = 0;
            int localMSMS = -1;
            List<int> msmsBetweenMS = new List<int>();
            List<double> injectionTimes = new List<double>();
            for(int sn = dataFile.FirstSpectrumNumber; sn < dataFile.LastSpectrumNumber; sn++)
            {
                int order = dataFile.GetMsnOrder(sn);
                if (order == 1)
                {
                    ms++;
                    if(localMSMS >= 0)
                        msmsBetweenMS.Add(localMSMS);
                    localMSMS = 0;
                }
                else
                {
                    localMSMS++;
                    msms++;
                    injectionTimes.Add(dataFile.GetInjectionTime(sn));
                }
            }
            MaxMSMSScansBetweenMS = msmsBetweenMS.Max();
            AverageMSMSSCansBetweenMS = msmsBetweenMS.Average();
            TotalMSMSscans = msms;
            TotalMSscans = ms;
            AverageMSMSInjectionTime = injectionTimes.Average();
            MaxMSMSInjectionTime = injectionTimes.Max();

            foreach (KeyValuePair<int, SortedMaxSizedContainer<PSM>> kvp in _data)
            {
                int scanNumber = kvp.Key;
                SortedMaxSizedContainer<PSM> psms = kvp.Value;

                double isolationMZ = dataFile.GetPrecusorMz(scanNumber);
                foreach (PSM psm in psms)
                {
                    psm.IsolationMz = isolationMZ;
                    double isolationMass = Mass.MassFromMz(isolationMZ, psm.Charge);
                    double theoreticalMass = psm.MonoisotopicMass;
                    int nominalMassOffset;
                    double adjustedIsolationMass;
                    Tolerance tolerancePPM = Tolerance.CalculatePrecursorMassError(theoreticalMass,
                        isolationMass, out nominalMassOffset, out adjustedIsolationMass);
                    psm.AdjustedIsolationMass = adjustedIsolationMass;
                    psm.IsotopeSelected = nominalMassOffset;
                    if(!HasPPMInfo)
                        psm.PrecursorMassError = tolerancePPM.Value;

                    double positive = Math.Abs(psm.PrecursorMassError);
                    if (positive > MaximumPrecursorMassError)
                    {
                        MaximumPrecursorMassError = positive;
                    }

                    if (psm.FdrScoreMetric <= evalueThreshold)
                    {
                        errors.Add(psm.PrecursorMassError);
                    }

                    count++;
                }
            }

            SystematicPrecursorMassError = useMedian ? GetMedianValue(errors) : errors.Average();

            // Adjust all psms to
            foreach (PSM psm in PeptideSpectralMatches)
            {
                psm.CorrectedPrecursorMassError = psm.PrecursorMassError - SystematicPrecursorMassError;
            }
        }
예제 #28
0
        public bool SetInputFile( string filepath )
        {
            MSDataFile tempInterface;

            try
            {
                OnStatusReport( "Loading metadata from source file..." );
                OnProgressReport( 0 );

                tempInterface = new MSDataFile(filepath);
                pwiz.CLI.msdata.ChromatogramList cl = tempInterface.run.chromatogramList;
                pwiz.CLI.msdata.SpectrumList sl = tempInterface.run.spectrumList;

                int ticIndex = cl.findNative("TIC");
                if( ticIndex < cl.size() )
                {
                    pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram(ticIndex, true);
                    chromatograms.Add( new Chromatogram( this, tic ) );
                }

                CVParam spectrumType = tempInterface.fileDescription.fileContent.cvParamChild( CVID.MS_spectrum_type );
                if( spectrumType.cvid == CVID.CVID_Unknown && !sl.empty() )
                    spectrumType = sl.spectrum(0).cvParamChild( CVID.MS_spectrum_type );

                if( spectrumType.cvid == CVID.MS_SRM_spectrum )
                {
                    if( cl.empty() )
                        throw new Exception( "Error loading metadata: SRM file contains no chromatograms" );

                    // load the rest of the chromatograms
                    for( int i = 0; i < cl.size(); ++i )
                    {
                        if( i == ticIndex )
                            continue;
                        pwiz.CLI.msdata.Chromatogram c = cl.chromatogram( i );

                        OnStatusReport( String.Format( "Loading chromatograms from source file ({0} of {1})...",
                                        ( i + 1 ), cl.size() ) );
                        OnProgressReport( ( i + 1 ) * 100 / cl.size() );

                        chromatograms.Add( new Chromatogram( this, c ) );
                    }

                } else if( spectrumType.cvid == CVID.MS_MS1_spectrum ||
                           spectrumType.cvid == CVID.MS_MSn_spectrum )
                {
                    // get all scans by sequential access
                    for( int i = 0; i < sl.size(); ++i )
                    {
                        pwiz.CLI.msdata.Spectrum s = sl.spectrum( i );

                        if( ( ( i + 1 ) % 100 ) == 0 || ( i + 1 ) == sl.size() )
                        {
                            OnStatusReport( String.Format( "Loading spectra from source file ({0} of {1})...",
                                            ( i + 1 ), sl.size() ) );
                            OnProgressReport( ( i + 1 ) * 100 / sl.size() );
                        }

                        spectra.Add( new MassSpectrum( this, s ) );
                    }
                } else
                    throw new Exception( "Error loading metadata: unable to open files with spectrum type \"" + spectrumType.name + "\"" );

                OnStatusReport( "Finished loading source metadata." );
                OnProgressReport( 100 );

            } catch( Exception ex )
            {
                string message = "SeeMS encountered an error reading metadata from \"" + filepath + "\" (" + ex.Message + ")";
                if( ex.InnerException != null )
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                MessageBox.Show( message,
                                "Error reading source metadata",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false );
                OnStatusReport( "Failed to read source metadata." );
                return false;
            }

            return true;
        }
예제 #29
0
        /// <summary>
        /// write out a subset of high quality spectra based on ScanRanker metrics file
        /// using ProteoWizard library
        /// </summary>
        public void Write()
        {
            foreach (FileInfo file in inFileList)
            {
                string fileBaseName = Path.GetFileNameWithoutExtension(file.FullName);
                string metricsFileName = fileBaseName + metricsFileSuffix + ".txt";
                string outFileName = fileBaseName + outFileSuffix + "." + outFormat;

                Workspace.SetText("\r\nStart writing high quality spectra for file: " + file.Name + " ...\r\n\r\n");
                if (File.Exists(outFileName))
                {
                    File.Delete(outFileName);
                }

                if (!File.Exists(metricsFileName))
                {
                    Workspace.SetText("\r\nError: Cannot find quality metrics file: " + metricsFileName + " in output directory!");
                    Workspace.ChangeButtonTo("Close");
                    return;
                }


                //List<int> allIndices = new List<int>();
                //List<int> highQualIndices = new List<int>();
                List<string> allIndices = new List<string>();   
                List<string> highQualIndices = new List<string>();

                // read metrics file, split and get high quality spectra indecies from the second column
                try
                {
                    Workspace.SetText("\r\nExtracting scan index from metrics file: " + metricsFileName);
                    using (TextReader tr = File.OpenText(metricsFileName))
                    {
                        tr.ReadLine();  // read the header line but do nothing, first three lines are header
                        tr.ReadLine();  // read the header line but do nothing
                        tr.ReadLine();  // read the header line but do nothing
                        string line = string.Empty;
                        while ((line = tr.ReadLine()) != null)
                        {
                            string[] items = line.Split('\t');
                            //int index = Convert.ToInt32(items[1]);  //index
                            string index = Convert.ToString(items[1]);  //nativeID
                            if (!allIndices.Exists(element => element == index))   // remove duplicate index
                            {
                                allIndices.Add(index);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    //throw new Exception("Error in reading metrics file for spectra removal\r\n",exc);
                    Workspace.SetText("\r\nError in reading metrics file for spectra removal\r\n");
                    Workspace.ChangeButtonTo("Close");
                    throw new Exception(exc.Message);
                }

                // get indices for high quality spectra
                Workspace.SetText("\r\nGenerating indices of high quality spectra");
                int numOutputSpectra = Convert.ToInt32(allIndices.Count * cutoff);
                highQualIndices = allIndices.GetRange(0, numOutputSpectra);
                //highQualIndices.Sort();

                //var predicate = new SpectrumList_FilterPredicate_IndexSet();
                //foreach (int i in highQualIndices)
                //{
                //    predicate.indexSet.Add(i);                    
                //}

                var predicate = new SpectrumList_FilterPredicate_NativeIDSet();
                foreach (string i in highQualIndices)
                {
                    predicate.nativeIDSet.Add(i);
                }

                //var sorterPredicate = new SpectrumList_SorterPredicate_IndexSet();
                //foreach (int i in highQualIndices)
                //{
                //    sorterPredicate.indexSet.Add(i);
                //}

                //MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig(MSDataFile.Format.Format_mzXML);
                MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig();
                if (outFormat.Equals("mzXML") || outFormat.Equals("mzxml"))
                {
                    writeConfig.format = MSDataFile.Format.Format_mzXML;
                }
                else if (outFormat.Equals("mzML") || outFormat.Equals("mzml"))
                {
                    writeConfig.format = MSDataFile.Format.Format_mzML;
                }
                else if (outFormat.Equals("MGF") || outFormat.Equals("mgf"))
                {
                    writeConfig.format = MSDataFile.Format.Format_MGF;
                }
                else if (outFormat.Equals("MS2") || outFormat.Equals("ms2"))
                {
                    writeConfig.format = MSDataFile.Format.Format_MS2;
                }
                else
                {
                    MessageBox.Show("Plese select output format");
                }

                writeConfig.precision = MSDataFile.Precision.Precision_32;
                
                try
                {
                    Workspace.SetText("\r\nWriting high quality spectra to file: " + outFileName);
                    using (var msFile = new MSDataFile(file.FullName))
                    {
                        var indexSet = new string[highQualIndices.Count];
                        var sl = msFile.run.spectrumList;
                        for (int i=0; i < highQualIndices.Count; ++i)
                        {
                            string id = highQualIndices[i];
                            int index = sl.find(id);
                            if (index == sl.size())
                                throw new Exception("nativeID \"" + id + "\" not found in file");
                            indexSet[i] = index.ToString();
                        }

                        var indexSetString = String.Join(" ", indexSet);
                        var predicate2 = new SpectrumList_FilterPredicate_IndexSet(indexSetString);
                        var filter = new SpectrumList_Filter(msFile.run.spectrumList, predicate2);
                        msFile.run.spectrumList = filter;
                        
                        //msFile.run.spectrumList = new SpectrumList_Sorter(msFile.run.spectrumList, new SpectrumList_Sorter_LessThan( sorterPredicate.lessThan ));
                        //msFile.run.spectrumList = new SpectrumList_Sorter(msFile.run.spectrumList, new SpectrumList_Sorter_LessThan(lessThan));
                        //Workspace.SetText("\r\nFinished msFile.run.spectrumList");
                        msFile.write(outFileName, writeConfig);
                    }
                }
                catch (Exception exc)
                {
                    //throw new Exception("Error in writiing new spectra file", exc);
                    Workspace.SetText("\r\nError in writing new spectra file\r\n");
                    Workspace.ChangeButtonTo("Close");
                    throw new Exception(exc.Message);
                }

                Workspace.SetText("\r\nFinished writing high quality spectra for file: " + file.Name + " \r\n\r\n");
                
            }// end of foreach file

            Workspace.SetText("\r\nFinished writing high quality spectra!");
            Workspace.ChangeButtonTo("Close");
        } // end of write()
예제 #30
0
        static void openButton_Click(object sender, EventArgs e)
        {
            string filepath = _fileTextBox.Text;
            if (!File.Exists(filepath))
            {
                MessageBox.Show("That filepath does not exist.", "404 File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                var msd = new MSDataFile(filepath);
                var sl = msd.run.spectrumList;
                MessageBox.Show(String.Format("The file has {0} spectra.", sl.size()), "Spectra Count");
            }
            catch (Exception ex)
            {
                string message = ex.ToString();
                if (ex.InnerException != null)
                    message += "\n\nAdditional information: " + ex.InnerException.ToString();
                MessageBox.Show(message,
                                "Error opening file",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }

        }
예제 #31
0
 public void AddMSDataFile(MSDataFile<ISpectrum> dataFile)
 {
     _dataFiles.Add(dataFile.Name, dataFile);
 }
예제 #32
0
파일: PsmReader.cs 프로젝트: kmmbvnr/CSMSL
 public void AddMSDataFile(MSDataFile dataFile)
 {
     _dataFiles.Add(dataFile.Name, dataFile);
 }
예제 #33
0
파일: MainLogic.cs 프로젝트: mdcallah/pwiz
        void processFile(string filename, Config config, ReaderList readers)
        {
            // read in data file
            using (var msdList = new MSDataList())
            {
                string msg = String.Format("Opening file \"{0}\" for read...", filename);
                if (LogUpdate != null)
                {
                    LogUpdate(msg, _info);
                }
                if (StatusUpdate != null)
                {
                    StatusUpdate(msg, ProgressBarStyle.Marquee, _info);
                }
                readers.read(filename, msdList);

                foreach (var msd in msdList)
                {
                    var outputFilename = config.outputFilename(filename, msd);

                    if (filename == outputFilename)
                    {
                        throw new ArgumentException("Output filepath is the same as input filepath");
                    }

                    if (StatusUpdate != null)
                    {
                        StatusUpdate("Waiting...", ProgressBarStyle.Marquee, _info);
                    }

                    // only one thread
                    lock (calculateSHA1Mutex)
                    {
                        if (LogUpdate != null)
                        {
                            LogUpdate("Calculating SHA1 checksum...", _info);
                        }
                        if (StatusUpdate != null)
                        {
                            StatusUpdate("Calculating SHA1 checksum...", ProgressBarStyle.Marquee, _info);
                        }
                        MSDataFile.calculateSHA1Checksums(msd);
                    }

                    if (LogUpdate != null)
                    {
                        LogUpdate("Processing...", _info);
                    }
                    if (StatusUpdate != null)
                    {
                        StatusUpdate("Processing...", ProgressBarStyle.Marquee, _info);
                    }

                    SpectrumListFactory.wrap(msd, config.Filters);

                    if ((msd.run.spectrumList == null) || msd.run.spectrumList.empty())
                    {
                        if ((msd.run.chromatogramList != null) && !msd.run.chromatogramList.empty())
                        {
                            msg = "Note: input contains only chromatogram data.";
                            switch (config.WriteConfig.format)
                            {
                            case MSDataFile.Format.Format_MZ5:
                            case MSDataFile.Format.Format_mzML:
                                break;

                            default:
                                msg += "  The selected output format can only represent spectra.  Consider using mzML instead.";
                                break;
                            }
                        }
                        else
                        {
                            msg = "Note: input contains no spectra or chromatogram data.";
                        }
                        if (LogUpdate != null)
                        {
                            LogUpdate(msg, _info);
                        }
                        if (StatusUpdate != null)
                        {
                            StatusUpdate(msg, ProgressBarStyle.Continuous, _info);
                        }
                    }

                    if (StatusUpdate != null && msd.run.spectrumList != null)
                    {
                        StatusUpdate(String.Format("Processing ({0} of {1})",
                                                   DataGridViewProgressCell.MessageSpecialValue.CurrentValue,
                                                   DataGridViewProgressCell.MessageSpecialValue.Maximum),
                                     ProgressBarStyle.Continuous, _info);
                    }

                    // write out the new data file
                    var ilr = new IterationListenerRegistry();
                    ilr.addListener(this, 100);
                    msg = String.Format("Writing \"{0}\"...", outputFilename);
                    if (LogUpdate != null)
                    {
                        LogUpdate(msg, _info);
                    }
                    if (StatusUpdate != null)
                    {
                        StatusUpdate(msg, ProgressBarStyle.Continuous, _info);
                    }
                    MSDataFile.write(msd, outputFilename, config.WriteConfig, ilr);
                    ilr.removeListener(this);
                }
            }
        }
예제 #34
0
        private void TestPWiz(string strFilePath)
        {
            const bool RUN_BENCHMARKS = false;

            try
            {
                var objPWiz2 = new MSDataFile(strFilePath);

                Console.WriteLine("Spectrum count: " + objPWiz2.run.spectrumList.size());
                Console.WriteLine();

                if (objPWiz2.run.spectrumList.size() > 0)
                {
                    var intSpectrumIndex = 0;

                    do
                    {
                        var oSpectrum = objPWiz2.run.spectrumList.spectrum(intSpectrumIndex, getBinaryData: true);

                        pwiz.CLI.data.CVParam param;
                        if (oSpectrum.scanList.scans.Count > 0)
                        {
                            if (clsProteowizardDataParser.TryGetCVParam(oSpectrum.scanList.scans[0].cvParams, pwiz.CLI.cv.CVID.MS_scan_start_time, out param))
                            {
                                var intScanNum          = intSpectrumIndex + 1;
                                var dblStartTimeMinutes = param.timeInSeconds() / 60.0;

                                Console.WriteLine("ScanIndex " + intSpectrumIndex + ", Scan " + intScanNum + ", Elution Time " + dblStartTimeMinutes + " minutes");
                            }
                        }

                        // Use the following to determine info on this spectrum
                        if (clsProteowizardDataParser.TryGetCVParam(oSpectrum.cvParams, pwiz.CLI.cv.CVID.MS_ms_level, out param))
                        {
                            int.TryParse(param.value, out _);
                        }

                        // Use the following to get the MZs and Intensities
                        var oMZs = oSpectrum.getMZArray();
                        oSpectrum.getIntensityArray();

                        if (oMZs.data.Count > 0)
                        {
                            Console.WriteLine("  Data count: " + oMZs.data.Count);

                            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                            if (RUN_BENCHMARKS)
                            {
                                double    dblTIC1           = 0;
                                double    dblTIC2           = 0;
                                var       dtStartTime       = default(DateTime);
                                var       dtEndTime         = default(DateTime);
                                double    dtRunTimeSeconds1 = 0;
                                double    dtRunTimeSeconds2 = 0;
                                const int LOOP_ITERATIONS   = 2000;

                                // Note from Matt Chambers (matt.chambers42 at gmail)
                                // Repeatedly accessing items directly via oMZs.data() can be very slow
                                // With 700 points and 2000 iterations, it takes anywhere from 0.6 to 1.1 seconds to run from dtStartTime to dtEndTime
                                dtStartTime = DateTime.Now;
                                for (var j = 1; j <= LOOP_ITERATIONS; j++)
                                {
                                    for (var intIndex = 0; intIndex <= oMZs.data.Count - 1; intIndex++)
                                    {
                                        dblTIC1 += oMZs.data[intIndex];
                                    }
                                }
                                dtEndTime         = DateTime.Now;
                                dtRunTimeSeconds1 = dtEndTime.Subtract(dtStartTime).TotalSeconds;

                                // The preferred method is to copy the data from .data to a locally-stored mzArray var
                                // With 700 points and 2000 iterations, it takes 0.016 seconds to run from dtStartTime to dtEndTime
                                dtStartTime = DateTime.Now;
                                for (var j = 1; j <= LOOP_ITERATIONS; j++)
                                {
                                    var oMzArray = oMZs.data;
                                    for (var intIndex = 0; intIndex <= oMzArray.Count - 1; intIndex++)
                                    {
                                        dblTIC2 += oMzArray[intIndex];
                                    }
                                }
                                dtEndTime         = DateTime.Now;
                                dtRunTimeSeconds2 = dtEndTime.Subtract(dtStartTime).TotalSeconds;

                                Console.WriteLine("  " + oMZs.data.Count + " points with " + LOOP_ITERATIONS + " iterations gives Runtime1=" + dtRunTimeSeconds1.ToString("0.0##") + " sec. vs. Runtime2=" + dtRunTimeSeconds2.ToString("0.0##") + " sec.");

                                if (Math.Abs(dblTIC1 - dblTIC2) > float.Epsilon)
                                {
                                    Console.WriteLine("  TIC values don't agree; this is unexpected");
                                }
                            }
                        }

                        if (intSpectrumIndex < 25)
                        {
                            intSpectrumIndex += 1;
                        }
                        else
                        {
                            intSpectrumIndex += 50;
                        }
                    } while (intSpectrumIndex < objPWiz2.run.spectrumList.size());
                }

                if (objPWiz2.run.chromatogramList.size() > 0)
                {
                    var intChromIndex = 0;

                    do
                    {
                        var oTimeIntensityPairList = new TimeIntensityPairList();

                        // Note that even for a small .Wiff file (1.5 MB), obtaining the Chromatogram list will take some time (20 to 60 seconds)
                        // The chromatogram at index 0 should be the TIC
                        // The chromatogram at index >=1 will be each SRM

                        var oChromatogram = objPWiz2.run.chromatogramList.chromatogram(intChromIndex, getBinaryData: true);

                        // Determine the chromatogram type

                        if (clsProteowizardDataParser.TryGetCVParam(oChromatogram.cvParams, pwiz.CLI.cv.CVID.MS_TIC_chromatogram, out var param))
                        {
                            // Obtain the data
                            oChromatogram.getTimeIntensityPairs(ref oTimeIntensityPairList);
                        }

                        if (clsProteowizardDataParser.TryGetCVParam(oChromatogram.cvParams, pwiz.CLI.cv.CVID.MS_selected_reaction_monitoring_chromatogram, out param))
                        {
                            // Obtain the SRM scan
                            oChromatogram.getTimeIntensityPairs(ref oTimeIntensityPairList);
                        }

                        intChromIndex += 1;
                    } while (intChromIndex < 50 && intChromIndex < objPWiz2.run.chromatogramList.size());
                }
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error using ProteoWizard reader: " + ex.Message, ex);
            }
        }
예제 #35
0
        private void writeUnidentifiedSpectra(string spectraFilename,
                                              string outFileSuffix,
                                              List <string> unidentifiedSpectra,
                                              float cutoff,
                                              string outFormat)
        {
            int numOutputSpectra = Convert.ToInt32(unidentifiedSpectra.Count * cutoff);
            //List<int> highQualIndices;
            List <string> highQualIndices;

            highQualIndices = unidentifiedSpectra.GetRange(0, numOutputSpectra);

            //var predicate = new SpectrumList_FilterPredicate_IndexSet();
            //foreach (int i in highQualIndices)
            //{
            //    predicate.indexSet.Add(i);
            //}

            var predicate = new SpectrumList_FilterPredicate_NativeIDSet();

            foreach (string i in highQualIndices)
            {
                predicate.nativeIDSet.Add(i);
            }

            //MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig(MSDataFile.Format.Format_mzXML);
            MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig();
            if (outFormat.Equals("mzXML") || outFormat.Equals("mzxml"))
            {
                writeConfig.format = MSDataFile.Format.Format_mzXML;
            }
            else if (outFormat.Equals("mzML") || outFormat.Equals("mzml"))
            {
                writeConfig.format = MSDataFile.Format.Format_mzML;
            }
            else if (outFormat.Equals("MGF") || outFormat.Equals("mgf"))
            {
                writeConfig.format = MSDataFile.Format.Format_MGF;
            }
            else if (outFormat.Equals("MS2") || outFormat.Equals("ms2"))
            {
                writeConfig.format = MSDataFile.Format.Format_MS2;
            }
            else
            {
                MessageBox.Show("Plese select output format");
            }

            writeConfig.precision = MSDataFile.Precision.Precision_32;

            try
            {
                string outFileName = Path.GetFileNameWithoutExtension(spectraFilename) + outFileSuffix + "-Top" + (recoveryCutoff * 100).ToString()
                                     + "PercUnidentSpec." + recoveryOutFormat;
                Workspace.SetText("\r\nWriting unidentified high quality spectra to file: " + outFileName);
                using (MSDataFile msFile = new MSDataFile(spectraFilename))
                {
                    msFile.run.spectrumList = new SpectrumList_Filter(msFile.run.spectrumList, new SpectrumList_FilterAcceptSpectrum(predicate.accept));
                    msFile.write(outFileName, writeConfig);
                }
            }
            catch (Exception exc)
            {
                //throw new Exception("Error in writiing new spectra file", exc);
                Workspace.SetText("\r\nError in writing new spectra file\r\n");
                Workspace.ChangeButtonTo("Close");
                throw new Exception(exc.Message);
            }
        }
예제 #36
0
        public static void RawFileToCsv(MSDataFile msDataFile, string outputFilePath)
        {
            // See the BasicCsvWriting example for more details

            Console.WriteLine("Writing file to: " + outputFilePath);

            // The main field delimiter, for CSV it is a comma
            const char delimiter = ',';

            using (StreamWriter writer = new StreamWriter(outputFilePath))
            {
                // Now that the stream is open, we can a line of text to it to serve as the header row.
                // CSV formats are just text files with fields separated by commas.
                writer.WriteLine("Spectrum Number,MS Level,Precursor m/z,# of Peaks in Spectrum,m/z Range");

                // The using statement on the msDataFile will ensure that things are properly disposed of after
                // you are done using the file, or if an exception has occurred.
                using (msDataFile)
                {
                    // MsDataFiles require opening their data connection manually.
                    msDataFile.Open();

                    // Simply loop over every data scan in the file
                    foreach (MSDataScan scan in msDataFile)
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.Append(scan.SpectrumNumber);
                        sb.Append(delimiter);

                        sb.Append(scan.MsnOrder);
                        sb.Append(delimiter);

                        // We need to check if this is an MS1 or MS2 scan. Both scans are of type MSDataScan,
                        // but for MS2 scans, there is additional information (precursor m/z for example). So we need
                        // to cast it to MsnDataScan to access those properties.
                        // Try casting using the 'as' keyword. It will either return the cast object or null, so we need to
                        // check for null before trying to access a property of it.
                        MsnDataScan msnScan = scan as MsnDataScan;
                        if (msnScan != null)
                        {
                            // It is a MS2 scan

                            sb.Append(msnScan.PrecursorMz);
                        }
                        else
                        {
                            // It is a MS1 scan, so no precursor information. So lets put Not an Number in this column.
                            // you could skip this if you want to have blank cells.
                            sb.Append(double.NaN);
                        }
                        sb.Append(delimiter);

                        // We can just use the original scan object now
                        sb.Append(scan.MassSpectrum.Count);
                        sb.Append(delimiter);

                        sb.Append(scan.MzRange);

                        writer.WriteLine(sb.ToString());
                    }
                }

            }
        }
예제 #37
0
파일: MainLogic.cs 프로젝트: zjjyyang/ftdr
        void processFile(string filename, Config config, ReaderList readers)
        {
            if (LogUpdate != null)
            {
                LogUpdate("Opening file...", _info);
            }
            if (StatusUpdate != null)
            {
                StatusUpdate("Opening file...", ProgressBarStyle.Marquee, _info);
            }

            // read in data file
            using (var msdList = new MSDataList())
            {
                readers.read(filename, msdList);

                foreach (var msd in msdList)
                {
                    var outputFilename = config.outputFilename(filename, msd);

                    if (filename == outputFilename)
                    {
                        throw new ArgumentException("Output filepath is the same as input filepath");
                    }

                    if (LogUpdate != null)
                    {
                        LogUpdate("Calculating SHA1 checksum...", _info);
                    }
                    if (StatusUpdate != null)
                    {
                        StatusUpdate("Calculating SHA1 checksum...", ProgressBarStyle.Marquee, _info);
                    }

                    // only one thread
                    lock (calculateSHA1Mutex)
                        MSDataFile.calculateSHA1Checksums(msd);

                    if (LogUpdate != null)
                    {
                        LogUpdate("Processing...", _info);
                    }
                    if (StatusUpdate != null)
                    {
                        StatusUpdate("Processing...", ProgressBarStyle.Marquee, _info);
                    }

                    SpectrumListFactory.wrap(msd, config.Filters);
                    if (StatusUpdate != null && msd.run.spectrumList != null)
                    {
                        StatusUpdate(String.Format("Processing ({0} of {1})",
                                                   DataGridViewProgressCell.MessageSpecialValue.CurrentValue,
                                                   DataGridViewProgressCell.MessageSpecialValue.Maximum),
                                     ProgressBarStyle.Continuous, _info);
                    }

                    // write out the new data file
                    IterationListenerRegistry ilr = null;
                    ilr = new IterationListenerRegistry();
                    ilr.addListener(this, 100);
                    MSDataFile.write(msd, outputFilename, config.WriteConfig, ilr);
                }
            }
        }
예제 #38
0
 public void MyTestCleanup()
 {
     dataFile.Dispose();
     dataFile = null;
 }
예제 #39
0
        /// <summary>
        /// write out a subset of high quality spectra based on ScanRanker metrics file
        /// using ProteoWizard library
        /// </summary>
        public void Write()
        {
            foreach (FileInfo file in inFileList)
            {
                string fileBaseName    = Path.GetFileNameWithoutExtension(file.FullName);
                string metricsFileName = fileBaseName + metricsFileSuffix + ".txt";
                string outFileName     = fileBaseName + outFileSuffix + "." + outFormat;

                Workspace.SetText("\r\nStart writing high quality spectra for file: " + file.Name + " ...\r\n\r\n");
                if (File.Exists(outFileName))
                {
                    File.Delete(outFileName);
                }

                if (!File.Exists(metricsFileName))
                {
                    Workspace.SetText("\r\nError: Cannot find quality metrics file: " + metricsFileName + " in output directory!");
                    Workspace.ChangeButtonTo("Close");
                    return;
                }


                //List<int> allIndices = new List<int>();
                //List<int> highQualIndices = new List<int>();
                List <string> allIndices      = new List <string>();
                List <string> highQualIndices = new List <string>();

                // read metrics file, split and get high quality spectra indecies from the second column
                try
                {
                    Workspace.SetText("\r\nExtracting scan index from metrics file: " + metricsFileName);
                    using (TextReader tr = File.OpenText(metricsFileName))
                    {
                        tr.ReadLine();  // read the header line but do nothing, first three lines are header
                        tr.ReadLine();  // read the header line but do nothing
                        tr.ReadLine();  // read the header line but do nothing
                        string line = string.Empty;
                        while ((line = tr.ReadLine()) != null)
                        {
                            string[] items = line.Split('\t');
                            //int index = Convert.ToInt32(items[1]);  //index
                            string index = Convert.ToString(items[1]);           //nativeID
                            if (!allIndices.Exists(element => element == index)) // remove duplicate index
                            {
                                allIndices.Add(index);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    //throw new Exception("Error in reading metrics file for spectra removal\r\n",exc);
                    Workspace.SetText("\r\nError in reading metrics file for spectra removal\r\n");
                    Workspace.ChangeButtonTo("Close");
                    throw new Exception(exc.Message);
                }

                // get indices for high quality spectra
                Workspace.SetText("\r\nGenerating indices of high quality spectra");
                int numOutputSpectra = Convert.ToInt32(allIndices.Count * cutoff);
                highQualIndices = allIndices.GetRange(0, numOutputSpectra);
                //highQualIndices.Sort();

                //var predicate = new SpectrumList_FilterPredicate_IndexSet();
                //foreach (int i in highQualIndices)
                //{
                //    predicate.indexSet.Add(i);
                //}

                var predicate = new SpectrumList_FilterPredicate_NativeIDSet();
                foreach (string i in highQualIndices)
                {
                    predicate.nativeIDSet.Add(i);
                }

                //var sorterPredicate = new SpectrumList_SorterPredicate_IndexSet();
                //foreach (int i in highQualIndices)
                //{
                //    sorterPredicate.indexSet.Add(i);
                //}

                //MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig(MSDataFile.Format.Format_mzXML);
                MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig();
                if (outFormat.Equals("mzXML") || outFormat.Equals("mzxml"))
                {
                    writeConfig.format = MSDataFile.Format.Format_mzXML;
                }
                else if (outFormat.Equals("mzML") || outFormat.Equals("mzml"))
                {
                    writeConfig.format = MSDataFile.Format.Format_mzML;
                }
                else if (outFormat.Equals("MGF") || outFormat.Equals("mgf"))
                {
                    writeConfig.format = MSDataFile.Format.Format_MGF;
                }
                else if (outFormat.Equals("MS2") || outFormat.Equals("ms2"))
                {
                    writeConfig.format = MSDataFile.Format.Format_MS2;
                }
                else
                {
                    MessageBox.Show("Plese select output format");
                }

                writeConfig.precision = MSDataFile.Precision.Precision_32;

                try
                {
                    Workspace.SetText("\r\nWriting high quality spectra to file: " + outFileName);
                    using (var msFile = new MSDataFile(file.FullName))
                    {
                        var indexSet = new string[highQualIndices.Count];
                        var sl       = msFile.run.spectrumList;
                        for (int i = 0; i < highQualIndices.Count; ++i)
                        {
                            string id    = highQualIndices[i];
                            int    index = sl.find(id);
                            if (index == sl.size())
                            {
                                throw new Exception("nativeID \"" + id + "\" not found in file");
                            }
                            indexSet[i] = index.ToString();
                        }

                        var indexSetString = String.Join(" ", indexSet);
                        var predicate2     = new SpectrumList_FilterPredicate_IndexSet(indexSetString);
                        var filter         = new SpectrumList_Filter(msFile.run.spectrumList, predicate2);
                        msFile.run.spectrumList = filter;

                        //msFile.run.spectrumList = new SpectrumList_Sorter(msFile.run.spectrumList, new SpectrumList_Sorter_LessThan( sorterPredicate.lessThan ));
                        //msFile.run.spectrumList = new SpectrumList_Sorter(msFile.run.spectrumList, new SpectrumList_Sorter_LessThan(lessThan));
                        //Workspace.SetText("\r\nFinished msFile.run.spectrumList");
                        msFile.write(outFileName, writeConfig);
                    }
                }
                catch (Exception exc)
                {
                    //throw new Exception("Error in writiing new spectra file", exc);
                    Workspace.SetText("\r\nError in writing new spectra file\r\n");
                    Workspace.ChangeButtonTo("Close");
                    throw new Exception(exc.Message);
                }

                Workspace.SetText("\r\nFinished writing high quality spectra for file: " + file.Name + " \r\n\r\n");
            }// end of foreach file

            Workspace.SetText("\r\nFinished writing high quality spectra!");
            Workspace.ChangeButtonTo("Close");
        } // end of write()
예제 #40
0
        private SourceInfo[] getSourceInfo( DirectoryInfo dirInfo, bool getDetails )
        {
            var sourceInfoList = new List<SourceInfo>();
            sourceInfoList.Add( new SourceInfo() );
            sourceInfoList[0].type = getSourceType( dirInfo );
            sourceInfoList[0].name = dirInfo.Name;
            sourceInfoList[0].dateModified = dirInfo.LastWriteTime;
            sourceInfoList[0].hasDetails = getDetails;

            if( !getDetails )
                return sourceInfoList.ToArray();

            if( sourceInfoList[0].type == "File Folder" )
            {
                return sourceInfoList.ToArray();
            } else if( sourceInfoList[0].type != String.Empty )
            {
                try
                {
                    MSDataFile msInfo = new MSDataFile( dirInfo.FullName );
                    sourceInfoList[0].populateFromMSData( msInfo );

                } catch( ThreadAbortException )
                {
                    return null;
                } catch
                {
                    sourceInfoList[0].spectra = 0;
                    sourceInfoList[0].type = "Invalid " + sourceInfoList[0].type;
                }

                sourceInfoList[0].size = 0;
                sourceInfoList[0].dateModified = DateTime.MinValue;
                foreach( FileInfo fileInfo in dirInfo.GetFiles( "*", SearchOption.AllDirectories ) )
                {
                    sourceInfoList[0].size += (UInt64) fileInfo.Length;
                    if( fileInfo.LastWriteTime > sourceInfoList[0].dateModified )
                        sourceInfoList[0].dateModified = fileInfo.LastWriteTime;
                }
                return sourceInfoList.ToArray();
            }
            return null;
        }
예제 #41
0
        private void listView_ItemSelectionChanged( object sender, ListViewItemSelectionChangedEventArgs e )
        {
            if( listView.SelectedItems.Count > 1 )
            {
                List<string> dataSourceList = new List<string>();
                foreach( ListViewItem item in listView.SelectedItems )
                {
                    if( item.SubItems[1].Text != "File Folder" )
                        dataSourceList.Add( String.Format( "\"{0}\"", item.SubItems[0].Text ) );
                }
                sourcePathTextBox.Text = String.Join( " ", dataSourceList.ToArray() );

                ticGraphControl.GraphPane.GraphObjList.Clear();
                ticGraphControl.GraphPane.CurveList.Clear();
                ticGraphControl.Visible = false;

            } else if( listView.SelectedItems.Count > 0 )
            {
                sourcePathTextBox.Text = listView.SelectedItems[0].SubItems[0].Text;

                ticGraphControl.GraphPane.GraphObjList.Clear();
                ticGraphControl.GraphPane.CurveList.Clear();

                string sourcePath = Path.Combine( CurrentDirectory, sourcePathTextBox.Text );
                string sourceType = getSourceType( sourcePath );
                if( !String.IsNullOrEmpty( sourceType ) &&
                    sourceType != "File Folder" )
                {
                    using (MSDataFile msData = new MSDataFile( sourcePath ))
                    using (ChromatogramList cl = msData.run.chromatogramList)
                    {
                        if( cl != null && !cl.empty() && cl.find( "TIC" ) != cl.size() )
                        {
                            ticGraphControl.Visible = true;
                            pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram( cl.find( "TIC" ), true );
                            Map<double, double> sortedFullPointList = new Map<double, double>();
                            IList<double> timeList = tic.binaryDataArrays[0].data;
                            IList<double> intensityList = tic.binaryDataArrays[1].data;
                            int arrayLength = timeList.Count;
                            for( int i = 0; i < arrayLength; ++i )
                                sortedFullPointList[timeList[i]] = intensityList[i];
                            ZedGraph.PointPairList points = new ZedGraph.PointPairList(
                                new List<double>( sortedFullPointList.Keys ).ToArray(),
                                new List<double>( sortedFullPointList.Values ).ToArray() );
                            ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve( "TIC", points, Color.Black, ZedGraph.SymbolType.None );
                            item.Line.IsAntiAlias = true;
                            ticGraphControl.AxisChange();
                            ticGraphControl.Refresh();
                        } else
                            ticGraphControl.Visible = false;
                    }
                } else
                    ticGraphControl.Visible = false;
            } else
                sourcePathTextBox.Text = "";
        }
예제 #42
0
        private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (listView.SelectedItems.Count > 1)
            {
                List <string> dataSourceList = new List <string>();
                foreach (ListViewItem item in listView.SelectedItems)
                {
                    if (item.SubItems[1].Text != "File Folder")
                    {
                        dataSourceList.Add(String.Format("\"{0}\"", item.SubItems[0].Text));
                    }
                }
                sourcePathTextBox.Text = String.Join(" ", dataSourceList.ToArray());

                ticGraphControl.GraphPane.GraphObjList.Clear();
                ticGraphControl.GraphPane.CurveList.Clear();
                ticGraphControl.Visible = false;
            }
            else if (listView.SelectedItems.Count > 0)
            {
                sourcePathTextBox.Text = listView.SelectedItems[0].SubItems[0].Text;

                ticGraphControl.GraphPane.GraphObjList.Clear();
                ticGraphControl.GraphPane.CurveList.Clear();

                string sourcePath = Path.Combine(CurrentDirectory, sourcePathTextBox.Text);
                string sourceType = getSourceType(sourcePath);
                if (!String.IsNullOrEmpty(sourceType) &&
                    sourceType != "File Folder")
                {
                    using (MSDataFile msData = new MSDataFile(sourcePath))
                        using (ChromatogramList cl = msData.run.chromatogramList)
                        {
                            if (cl != null && !cl.empty() && cl.find("TIC") != cl.size())
                            {
                                ticGraphControl.Visible = true;
                                pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram(cl.find("TIC"), true);
                                Map <double, double>         sortedFullPointList = new Map <double, double>();
                                IList <double> timeList      = tic.binaryDataArrays[0].data;
                                IList <double> intensityList = tic.binaryDataArrays[1].data;
                                int            arrayLength   = timeList.Count;
                                for (int i = 0; i < arrayLength; ++i)
                                {
                                    sortedFullPointList[timeList[i]] = intensityList[i];
                                }
                                ZedGraph.PointPairList points = new ZedGraph.PointPairList(
                                    new List <double>(sortedFullPointList.Keys).ToArray(),
                                    new List <double>(sortedFullPointList.Values).ToArray());
                                ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve("TIC", points, Color.Black, ZedGraph.SymbolType.None);
                                item.Line.IsAntiAlias = true;
                                ticGraphControl.AxisChange();
                                ticGraphControl.Refresh();
                            }
                            else
                            {
                                ticGraphControl.Visible = false;
                            }
                        }
                }
                else
                {
                    ticGraphControl.Visible = false;
                }
            }
            else
            {
                sourcePathTextBox.Text = "";
            }
        }
예제 #43
0
        private void writeSingleSpectrum(string sourceFile, string nativeID, string outFileName)
        {
            MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig();
            writeConfig.format = MSDataFile.Format.Format_MGF;
            writeConfig.precision = MSDataFile.Precision.Precision_32;

            //var predicate = new SpectrumList_FilterPredicate_IndexSet();
            //predicate.indexSet.Add(nativeID);

            var predicate = new SpectrumList_FilterPredicate_NativeIDSet();
            predicate.nativeIDSet.Add(nativeID);
            

            try
            {
                //Workspace.SetText("\r\nWriting selected spectrum to " + outFileName);
                MainForm.SetText(this, "Start writing selected spectrum to " + outFileName + "\r\n");
                using (MSDataFile msFile = new MSDataFile(sourceFile))
                {
                    msFile.run.spectrumList = new SpectrumList_Filter(msFile.run.spectrumList, new SpectrumList_FilterAcceptSpectrum(predicate.accept));
                    msFile.write(outFileName, writeConfig);
                }
                MainForm.SetText(this, "Finished writing selected spectrum to " + outFileName + "\r\n");
            }
            catch (Exception exc)
            {
                //throw new Exception("Error in writiing new spectra file", exc);
                //Workspace.SetText("\r\nError in writing new spectra file\r\n");
                tbPepNovoResult.AppendText("\r\nError in writing new spectra file\r\n");
                throw new Exception(exc.Message);
            }
        }