Example #1
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);
        }
Example #2
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);
            }
        }
Example #3
0
 public Config(string outputPath)
 {
     OutputPath      = outputPath;
     Filenames       = new List <string>();
     Filters         = new List <string>();
     Extension       = string.Empty;
     ContactFilename = string.Empty;
     WriteConfig     = new MSDataFile.WriteConfig();
 }
Example #4
0
 public Config(string outputPath)
 {
     OutputPath = outputPath;
     Filenames = new List<string>();
     Filters = new List<string>();
     Extension = string.Empty;
     ContactFilename = string.Empty;
     WriteConfig = new MSDataFile.WriteConfig();
 }
Example #5
0
        void assignTooltips()
        {
            setToolTip(this.SetDefaultsButton, "Saves the current settings and uses them as the defaults next time you use MSConvertGUI without a recognized input file type.");
            setToolTip(this.WriteIndexBox, "Include an index in mzML and mzXML output files.");
            setToolTip(this.GzipBox, "This compresses the entire output file using gzip, and adds \".gz\" to the end of the filename.");
            setToolTip(this.UseZlibBox, "Using zlib to compress peak lists results in much smaller mzML and mzXML output files.");
            setToolTip(this.OptionsGB, "Useful options for controlling output format and file size.");
            setToolTip(this.FileListRadio, "Click this for normal operation.");
            setToolTip(this.TextFileRadio, "Click this if your input file actually contains a list of files to be converted.");
            setToolTip(this.AddFilterButton, "Add the filter specifed above to the list below.","Filters");
            setToolTip(this.RemoveFilterButton, "Select a filter in the list below then click here to remove it.", "Filters");
            setToolTip(this.ZeroSamplesMSLevelLow, "Lowest MS level for scans to be treated with this filter.","Zero Samples");
            setToolTip(this.ZeroSamplesMSLevelHigh, "Highest MS level for scans to be treated with this filter (may be left blank).", "Zero Samples");
            setToolTip(this.ZeroSamplesMSLevelLabel, "Perform this filter only on scans with these MS Levels.", "Zero Samples");
            setToolTip(this.ZeroSamplesRemove, "Reduces output file sizes by removing zero values which are not adjacent to nonzero values.", "Zero Samples");
            setToolTip(this.ZeroSamplesPanel, "These filters help with missing or unwanted zero value samples.", "Zero Samples");
            setToolTip(this.PeakMSLevelLow, "Lowest MS level on which to perform peak picking.","Peak Picking");
            setToolTip(this.PeakMSLevelHigh, "Highest MS level on which to perform peak picking (may be left blank).", "Peak Picking");
            setToolTip(this.PeakMSLevelLabel, "Selects the MS levels for scans on which to perform peak picking.", "Peak Picking");
            setToolTip(this.MSLevelLow, "Lowest MS level for scans to include in the conversion.","MS Level");
            setToolTip(this.MSLevelHigh, "Highest MS level to include in the conversion (may be left blank).", "MS Level");
            setToolTip(this.ScanNumberLow, "Lowest scan number to include in the conversion.","Subset");
            setToolTip(this.ScanNumberLabel, "Use this filter to include only scans with a limited range of scan numbers.", "Subset");
            setToolTip(this.mzWinLabel, "Use this filter to include only scans with a limited range of m/z values.", "Subset");
            setToolTip(this.ScanTimeLabel, "Use this filter to include only scans with a limited range of scan times.", "Subset");
            setToolTip(this.mzWinLow, "Lowest m/z value to include in the conversion.", "Subset");
            setToolTip(this.ScanTimeHigh, "Highest scan time to include in the conversion.", "Subset");
            setToolTip(this.mzWinHigh, "Highest m/z value to include in the conversion.", "Subset");
            setToolTip(this.ScanTimeLow, "Lowest scan time to include in the conversion.", "Subset");
            setToolTip(this.ScanNumberHigh, "Highest scan number to include in the conversion (may be left blank).", "Subset");
            setToolTip(this.SubsetPanel, "Set values for one or more subset filters, then click Add.", "Subset");
            setToolTip(this.FilterBox, "This chooses the type of filter that you want to add next.");
            setToolTip(this.AboutButton, "Provides information on using MSConvert.");
            setToolTip(this.FilterGB, "Use these controls to add to the conversion filter list.  The order of the filter list is significant.  In particular, vendor-supplied peakPicking must be first since it only works on raw, untransformed data.");
            setToolTip(this.StartButton, "Click here to begin the conversion process.");
            setToolTip(this.RemoveFileButton, "Select a file to be removed from the conversion list, then click here.");
            setToolTip(this.FileListBox, "Add files to this conversion list by using the Browse button to select a file, then clicking the Add button.");
            setToolTip(this.FileBox, "Use the Browse button or type a filename here, then click Add to add it to the list of files to be converted.");
            setToolTip(this.AddFileButton, "Adds the current file to the conversion list.");
            setToolTip(this.FilterDGV, "Use the controls above to add conversion filters. The order can be significant.");
            setToolTip(this.MakeTPPCompatibleOutputButton, "Check this to use TPP-compatible output settings, e.g. an MGF TITLE format like <basename>.<scan>.<scan>.<charge>.");
            MSDataFile.WriteConfig mwc = new MSDataFile.WriteConfig(); // for obtaining default numpress tolerance
            setToolTip(this.NumpressLinearBox, String.Format("Check this to use numpress linear prediction lossy compression for binary mz and rt data in mzML output (relative accuracy loss will not exceed {0}).  Note that not all mzML readers recognize this format.", mwc.numpressLinearErrorTolerance));
            setToolTip(this.NumpressSlofBox, String.Format("Check this to use numpress short logged float lossy compression for binary intensities in mzML output (relative accuracy loss will not exceed  {0}).  Note that not all mzML readers recognize this format.", mwc.numpressSlofErrorTolerance));
            setToolTip(this.NumpressPicBox, "Check this to use numpress positive integer lossy compression for binary intensities in mzML output (absolute accuracy loss will not exceed 0.5).  Note that not all mzML readers recognize this format.");
            setToolTip(this.ETDFilterPanel, "Use these filter options to remove unreacted and charge-reduced precursor peaks in ETD spectra.","ETD Peak");
            setToolTip(this.ETDRemovePrecursorBox, "Check this to remove unreacted precursor peaks from ETD spectra.","ETD Peak");
            setToolTip(this.ETDRemoveChargeReducedBox, "Check this to remove charge-reduced precursor peaks from ETD spectra.","ETD Peak");
            setToolTip(this.ETDRemoveNeutralLossBox, "Check this to remove prominent neutral losses of the +1 charge-reduced precursor from ETD spectra.","ETD Peak");
            setToolTip(this.ETDBlanketRemovalBox, "Check this for an alternative way of neutral loss filtering using a charge-scaled 60 Da exclusion window below the charge-reduced precursors.","ETD Peak");

            setToolTip(this.ThresholdFilterPanel, "Use this filter to remove small noise peaks or undesirable big peaks. Several different thresholding methods are available.","Threshold");

            string thresholdOrientation = "Controls whether the threshold filter keeps the most intense or the least intense peaks.";
            setToolTip(this.thresholdOrientationLabel, thresholdOrientation, "Threshold");
            setToolTip(this.thresholdOrientationComboBox, thresholdOrientation, "Threshold");

            string thresholdTypeHelp = "The filter can use different thresholding schemes:\r\n" +
                                       "Count types: keeps the most/least intense peaks.\r\n" +
                                       "Absolute: keeps peaks with intensities greater than the threshold.\r\n" +
                                       "Relative types: keeps a peak if its the fraction of BPI/TIC is greater than the threshold.\r\n" +
                                       "Fraction of TIC: keeps as many peaks as needed until the threshold of TIC is accounted for.";
            setToolTip(this.thresholdTypeLabel, thresholdTypeHelp, "Threshold");
            setToolTip(this.thresholdTypeComboBox, thresholdTypeHelp, "Threshold");

            string thresholdValueHelp = "The meaning of this threshold value depends on the threshold type:\r\n" +
                                        "Count types: keeps the <value> most/least intense peaks.\r\n" +
                                        "Absolute: keeps peaks with intensities greater/less than <value>.\r\n" +
                                        "Relative types: keeps a peak if its the fraction of BPI/TIC is greater/less than <value>.\r\n" +
                                        "Fraction of TIC: keeps as many peaks as needed until the fraction <value> of the TIC is accounted for.";
            setToolTip(this.thresholdValueLabel, thresholdValueHelp, "Threshold");
            setToolTip(this.thresholdValueTextBox, thresholdValueHelp, "Threshold");

            setToolTip(this.ChargeStatePredictorPanel, "Use this filter to add missing (and optionally overwrite existing) charge state information to MSn spectra.\r\n" +
                                                       "For CID spectra, the charge state is single/multiple based on %TIC below the precursor m/z.\r\n" +
                                                       "For ETD spectra, the charge state is predicted using the published ETDz SVM prediction model.","Charge State Predictor");
            setToolTip(this.ChaOverwriteCharge, "Check this to overwrite spectra's existing charge state(s) with the predicted ones.", "Charge State Predictor");

            string chaSingleHelp = "When the %TIC below the precursor m/z is less than this value, the spectrum is predicted as singly charged.";
            setToolTip(this.ChaSingleLabel, chaSingleHelp, "Charge State Predictor");
            setToolTip(this.ChaSingleBox, chaSingleHelp, "Charge State Predictor");

            string maxChargeHelp = "Maximum multiple charge state to be predicted.";
            setToolTip(this.ChaMCMaxLabel, maxChargeHelp, "Charge State Predictor");
            setToolTip(this.ChaMCMaxBox, maxChargeHelp, "Charge State Predictor");

            string minChargeHelp = "Minimum multiple charge state to be predicted.";
            setToolTip(this.ChaMCMinLabel, minChargeHelp, "Charge State Predictor");
            setToolTip(this.ChaMCMinBox, minChargeHelp, "Charge State Predictor");

            string OutputExtensionHelp = "Sets the filename extension for the output file(s)";
            setToolTip(this.OutputExtensionLabel, OutputExtensionHelp);
            setToolTip(this.OutputExtensionBox, OutputExtensionHelp);

            string precisionHelp = "Sets output precision for writing binary m/z and intensity information. High resolution instruments should use 64-bit m/z values, but otherwise it just creates unnecessarily large output files.";
            setToolTip(this.PrecisionLabel, precisionHelp);
            setToolTip(this.Precision64, precisionHelp);
            setToolTip(this.Precision32, precisionHelp);

            string activationTypeHelp = "Include only scans with this precursor activation type.";
            setToolTip(this.ActivationTypeLabel, activationTypeHelp, "Activation");
            setToolTip(this.ActivationTypeBox, activationTypeHelp, "Activation");

            string msLevelHelp = "Use this filter to include only scans with certain MS levels.";
            setToolTip(this.MSLevelLabel, msLevelHelp,"MS Level");
            setToolTip(this.MSLevelPanel, msLevelHelp, "MS Level");

            string preferVendorHelp = "Uncheck this box if you prefer ProteoWizard's peak picking algorithm to that provided by the vendor (normally the vendor code works better). Not all input formats have vendor peakpicking, but it's OK to leave this checked.";
            setToolTip(this.PeakPreferVendorBox, preferVendorHelp,"Peak Picking");
            setToolTip(this.PeakPickingPanel, "Use this filter to perform peak picking (centroiding) on the input data.", "Peak Picking");

            string outputHelp = "Choose the directory for writing the converted file(s).";
            setToolTip(this.OutputLabel, outputHelp);
            setToolTip(this.OutputBox, outputHelp);

            string outputFormatHelp = "Selects the output format for the conversion";
            setToolTip(this.FormatLabel, outputFormatHelp);
            setToolTip(this.OutputFormatBox, outputFormatHelp);

            string addZerosHelp = "Adds flanking zero values next to nonzero values where needed, to help with things like smoothing.";
            setToolTip(this.ZeroSamplesAddMissing, addZerosHelp, "Zero Samples");
            setToolTip(this.ZeroSamplesAddMissingFlankCountBox, addZerosHelp, "Zero Samples");
        }
Example #6
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()
Example #7
0
        void assignTooltips()
        {
            setToolTip(this.SetDefaultsButton, "Saves the current settings and uses them as the defaults next time you use MSConvertGUI without a recognized input file type.");
            setToolTip(this.WriteIndexBox, "Include an index in mzML and mzXML output files.");
            setToolTip(this.GzipBox, "This compresses the entire output file using gzip, and adds \".gz\" to the end of the filename.");
            setToolTip(this.UseZlibBox, "Using zlib to compress peak lists results in much smaller mzML and mzXML output files.");
            setToolTip(this.OptionsGB, "Useful options for controlling output format and file size.");
            setToolTip(this.FileListRadio, "Click this for normal operation.");
            setToolTip(this.TextFileRadio, "Click this if your input file actually contains a list of files to be converted.");
            setToolTip(this.AddFilterButton, "Add the filter specifed above to the list below.", "Filters");
            setToolTip(this.RemoveFilterButton, "Select a filter in the list below then click here to remove it.", "Filters");
            setToolTip(this.ZeroSamplesMSLevelLow, "Lowest MS level for scans to be treated with this filter.", "Zero Samples");
            setToolTip(this.ZeroSamplesMSLevelHigh, "Highest MS level for scans to be treated with this filter (may be left blank).", "Zero Samples");
            setToolTip(this.ZeroSamplesMSLevelLabel, "Perform this filter only on scans with these MS Levels.", "Zero Samples");
            setToolTip(this.ZeroSamplesRemove, "Reduces output file sizes by removing zero values which are not adjacent to nonzero values.", "Zero Samples");
            setToolTip(this.ZeroSamplesPanel, "These filters help with missing or unwanted zero value samples.", "Zero Samples");
            setToolTip(this.PeakMSLevelLow, "Lowest MS level on which to perform peak picking.", "Peak Picking");
            setToolTip(this.PeakMSLevelHigh, "Highest MS level on which to perform peak picking (may be left blank).", "Peak Picking");
            setToolTip(this.PeakMSLevelLabel, "Selects the MS levels for scans on which to perform peak picking.", "Peak Picking");
            setToolTip(this.MSLevelLow, "Lowest MS level for scans to include in the conversion.", "MS Level");
            setToolTip(this.MSLevelHigh, "Highest MS level to include in the conversion (may be left blank).", "MS Level");
            setToolTip(this.ScanNumberLow, "Lowest scan number to include in the conversion.", "Subset");
            setToolTip(this.ScanNumberLabel, "Use this filter to include only scans with a limited range of scan numbers.", "Subset");
            setToolTip(this.mzWinLabel, "Use this filter to include only scans with a limited range of m/z values.", "Subset");
            setToolTip(this.ScanTimeLabel, "Use this filter to include only scans with a limited range of scan times.", "Subset");
            setToolTip(this.mzWinLow, "Lowest m/z value to include in the conversion.", "Subset");
            setToolTip(this.ScanTimeHigh, "Highest scan time to include in the conversion.", "Subset");
            setToolTip(this.mzWinHigh, "Highest m/z value to include in the conversion.", "Subset");
            setToolTip(this.ScanTimeLow, "Lowest scan time to include in the conversion.", "Subset");
            setToolTip(this.ScanNumberHigh, "Highest scan number to include in the conversion (may be left blank).", "Subset");
            setToolTip(this.SubsetPanel, "Set values for one or more subset filters, then click Add.", "Subset");
            setToolTip(this.FilterBox, "This chooses the type of filter that you want to add next.");
            setToolTip(this.AboutButton, "Provides information on using MSConvertGUI.");
            setToolTip(this.FilterGB, "Use these controls to add to the conversion filter list.  The order of the filter list is significant.  In particular, vendor-supplied peakPicking must be first since it only works on raw, untransformed data.");
            setToolTip(this.StartButton, "Click here to begin the conversion process.");
            setToolTip(this.RemoveFileButton, "Select a file to be removed from the conversion list, then click here.");
            setToolTip(this.FileListBox, "Add files to this conversion list by using the Browse button to select a file, then clicking the Add button.");
            setToolTip(this.FileBox, "Use the Browse button or type a filename here, then click Add to add it to the list of files to be converted.");
            setToolTip(this.AddFileButton, "Adds the current file to the conversion list.");
            setToolTip(this.FilterDGV, "Use the controls above to add conversion filters. The order can be significant.");
            setToolTip(this.MakeTPPCompatibleOutputButton, "Check this to use TPP-compatible output settings, e.g. an MGF TITLE format like <basename>.<scan>.<scan>.<charge>.");
            MSDataFile.WriteConfig mwc = new MSDataFile.WriteConfig(); // for obtaining default numpress tolerance
            setToolTip(this.NumpressLinearBox, String.Format("Check this to use numpress linear prediction lossy compression for binary mz and rt data in mzML output (relative accuracy loss will not exceed {0}).  Note that not all mzML readers recognize this format.", mwc.numpressLinearErrorTolerance));
            setToolTip(this.NumpressSlofBox, String.Format("Check this to use numpress short logged float lossy compression for binary intensities in mzML output (relative accuracy loss will not exceed  {0}).  Note that not all mzML readers recognize this format.", mwc.numpressSlofErrorTolerance));
            setToolTip(this.NumpressPicBox, "Check this to use numpress positive integer lossy compression for binary intensities in mzML output (absolute accuracy loss will not exceed 0.5).  Note that not all mzML readers recognize this format.");
            setToolTip(this.ETDFilterPanel, "Use these filter options to remove unreacted and charge-reduced precursor peaks in ETD spectra.", "ETD Peak");
            setToolTip(this.ETDRemovePrecursorBox, "Check this to remove unreacted precursor peaks from ETD spectra.", "ETD Peak");
            setToolTip(this.ETDRemoveChargeReducedBox, "Check this to remove charge-reduced precursor peaks from ETD spectra.", "ETD Peak");
            setToolTip(this.ETDRemoveNeutralLossBox, "Check this to remove prominent neutral losses of the +1 charge-reduced precursor from ETD spectra.", "ETD Peak");
            setToolTip(this.ETDBlanketRemovalBox, "Check this for an alternative way of neutral loss filtering using a charge-scaled 60 Da exclusion window below the charge-reduced precursors.", "ETD Peak");

            setToolTip(this.ThresholdFilterPanel, "Use this filter to remove small noise peaks or undesirable big peaks. Several different thresholding methods are available.", "Threshold");

            string thresholdOrientation = "Controls whether the threshold filter keeps the most intense or the least intense peaks.";

            setToolTip(this.thresholdOrientationLabel, thresholdOrientation, "Threshold");
            setToolTip(this.thresholdOrientationComboBox, thresholdOrientation, "Threshold");

            string thresholdTypeHelp = "The filter can use different thresholding schemes:\r\n" +
                                       "Count types: keeps the most/least intense peaks.\r\n" +
                                       "Absolute: keeps peaks with intensities greater than the threshold.\r\n" +
                                       "Relative types: keeps a peak if its the fraction of BPI/TIC is greater than the threshold.\r\n" +
                                       "Fraction of TIC: keeps as many peaks as needed until the threshold of TIC is accounted for.";

            setToolTip(this.thresholdTypeLabel, thresholdTypeHelp, "Threshold");
            setToolTip(this.thresholdTypeComboBox, thresholdTypeHelp, "Threshold");

            string thresholdValueHelp = "The meaning of this threshold value depends on the threshold type:\r\n" +
                                        "Count types: keeps the <value> most/least intense peaks.\r\n" +
                                        "Absolute: keeps peaks with intensities greater/less than <value>.\r\n" +
                                        "Relative types: keeps a peak if its the fraction of BPI/TIC is greater/less than <value>.\r\n" +
                                        "Fraction of TIC: keeps as many peaks as needed until the fraction <value> of the TIC is accounted for.";

            setToolTip(this.thresholdValueLabel, thresholdValueHelp, "Threshold");
            setToolTip(this.thresholdValueTextBox, thresholdValueHelp, "Threshold");

            setToolTip(this.ChargeStatePredictorPanel, "Use this filter to add missing (and optionally overwrite existing) charge state information to MSn spectra.\r\n" +
                       "For CID spectra, the charge state is single/multiple based on %TIC below the precursor m/z.\r\n" +
                       "For ETD spectra, the charge state is predicted using the published ETDz SVM prediction model.", "Charge State Predictor");
            setToolTip(this.ChaOverwriteCharge, "Check this to overwrite spectra's existing charge state(s) with the predicted ones.", "Charge State Predictor");

            string chaSingleHelp = "When the %TIC below the precursor m/z is less than this value, the spectrum is predicted as singly charged.";

            setToolTip(this.ChaSingleLabel, chaSingleHelp, "Charge State Predictor");
            setToolTip(this.ChaSingleBox, chaSingleHelp, "Charge State Predictor");

            string maxChargeHelp = "Maximum multiple charge state to be predicted.";

            setToolTip(this.ChaMCMaxLabel, maxChargeHelp, "Charge State Predictor");
            setToolTip(this.ChaMCMaxBox, maxChargeHelp, "Charge State Predictor");

            string minChargeHelp = "Minimum multiple charge state to be predicted.";

            setToolTip(this.ChaMCMinLabel, minChargeHelp, "Charge State Predictor");
            setToolTip(this.ChaMCMinBox, minChargeHelp, "Charge State Predictor");

            string OutputExtensionHelp = "Sets the filename extension for the output file(s)";

            setToolTip(this.OutputExtensionLabel, OutputExtensionHelp);
            setToolTip(this.OutputExtensionBox, OutputExtensionHelp);

            string precisionHelp = "Sets output precision for writing binary m/z and intensity information. High resolution instruments should use 64-bit m/z values, but otherwise it just creates unnecessarily large output files.";

            setToolTip(this.PrecisionLabel, precisionHelp);
            setToolTip(this.Precision64, precisionHelp);
            setToolTip(this.Precision32, precisionHelp);

            string activationTypeHelp = "Include only scans with this precursor activation type.";

            setToolTip(this.ActivationTypeLabel, activationTypeHelp, "Activation");
            setToolTip(this.ActivationTypeBox, activationTypeHelp, "Activation");

            string msLevelHelp = "Use this filter to include only scans with certain MS levels.";

            setToolTip(this.MSLevelLabel, msLevelHelp, "MS Level");
            setToolTip(this.MSLevelPanel, msLevelHelp, "MS Level");

            string preferVendorHelp = "Uncheck this box if you prefer ProteoWizard's peak picking algorithm to that provided by the vendor (normally the vendor code works better). Not all input formats have vendor peakpicking, but it's OK to leave this checked.";

            setToolTip(this.PeakPreferVendorBox, preferVendorHelp, "Peak Picking");
            setToolTip(this.PeakPickingPanel, "Use this filter to perform peak picking (centroiding) on the input data.", "Peak Picking");

            string outputHelp = "Choose the directory for writing the converted file(s).";

            setToolTip(this.OutputLabel, outputHelp);
            setToolTip(this.OutputBox, outputHelp);

            string outputFormatHelp = "Selects the output format for the conversion";

            setToolTip(this.FormatLabel, outputFormatHelp);
            setToolTip(this.OutputFormatBox, outputFormatHelp);

            string addZerosHelp = "Adds flanking zero values next to nonzero values where needed, to help with things like smoothing.";

            setToolTip(this.ZeroSamplesAddMissing, addZerosHelp, "Zero Samples");
            setToolTip(this.ZeroSamplesAddMissingFlankCountBox, addZerosHelp, "Zero Samples");
        }
Example #8
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);
            }
        }
        /// <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()
Example #10
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);
            }
        }