示例#1
0
        private void LoadPwizReader()
        {
            if (_loaded)
            {
                return;
            }

            var readers = ReaderList.FullReaderList;

            readers.read(_filePath, _dataFile);
            if ((new string[] { ".mzml", ".mzml.gz", ".mzxml", ".mzxml.gz", ".mgf", ".mgf.gz", ".txt", "uimf", "uimf.gz" })
                .Any(ext => _filePath.ToLower().EndsWith(ext)))
            {
                // Files that do not have vendor centroiding available
                Console.WriteLine("Using cwt Centroiding");
                _filters.Add(_cwtCentroiding);
            }
            else
            {
                Console.WriteLine("Using vendor Centroiding");
                _filters.Add(_vendorCentroiding);
            }
            SpectrumListFactory.wrap(_dataFile, _filters);

            _numSpectra = _dataFile.run.spectrumList.size();
            _loaded     = true;
        }
示例#2
0
        protected void readVendorFile()
        {
            jobInfo.log("Prepare to Parse Vendor File", "Prepare");
            msd = new MSDataFile(jobInfo.inputFilePath);
            jobInfo.log("Adapting Vendor File API", "Adapting");

            List <string> filter = new List <string>();

            SpectrumListFactory.wrap(msd, filter); //这一步操作可以帮助加快Wiff文件的初始化速度

            spectrumList = msd.run.spectrumList;
            if (spectrumList == null || spectrumList.empty())
            {
                jobInfo.logError("No Spectrums Found");
            }
            else
            {
                jobInfo.log("Adapting Finished");
            }

            if (jobInfo.format.Equals("WIFF"))
            {
                FileInfo file1 = new FileInfo(jobInfo.inputFilePath);
                if (file1.Exists)
                {
                    fileSize += file1.Length;
                }

                FileInfo file2 = new FileInfo(jobInfo.inputFilePath + ".mtd");
                if (file2.Exists)
                {
                    fileSize += file2.Length;
                }

                FileInfo file3 = new FileInfo(jobInfo.inputFilePath + ".scan");
                if (file3.Exists)
                {
                    fileSize += file3.Length;
                }
            }

            if (jobInfo.format.Equals("RAW"))
            {
                FileInfo file1 = new FileInfo(jobInfo.inputFilePath);
                if (file1.Exists)
                {
                    fileSize += file1.Length;
                }
            }
        }
示例#3
0
        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);
                }
            }
        }
示例#4
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();
                    }
                }
            }
        }
示例#5
0
        private List <double> getPeakStatistics()
        {
            IList <object[]> queryRows;

            lock (session)
            {
                var randomIds = session.CreateQuery("SELECT psm.Id " + viewFilter.GetFilteredQueryString(DataFilter.FromPeptideSpectrumMatch))
                                .List <long>()
                                .Shuffle()
                                .Take(1000)
                                .OrderBy(o => o);
                string randomIdSet = String.Join(",", randomIds.Select(o => o.ToString()).ToArray());
                queryRows = session.CreateQuery("SELECT psm.Spectrum.Source.Name, psm.Spectrum, psm, DISTINCT_GROUP_CONCAT(pm.Offset || ':' || mod.MonoMassDelta), psm.Peptide.Sequence " +
                                                "FROM PeptideSpectrumMatch psm " +
                                                "LEFT JOIN psm.Modifications pm " +
                                                "LEFT JOIN pm.Modification mod " +
                                                "WHERE psm.Id IN (" + randomIdSet + ") " +
                                                "GROUP BY psm.Spectrum.id ")
                            .List <object[]>();
            }
            var spectrumRows = queryRows.Select(o => new SpectrumRow(o)).OrderBy(o => o.SourceName);

            precursorScatterPlot.Clear();
            chargeReducedScatterPlot.Clear();

            int spectraCount = 0;

            string spectrumListFilters = String.Empty;

            Invoke(new MethodInvoker(() =>
            {
                spectrumListFilters = spectrumFiltersTextBox.Text;
                zedGraphControl.MasterPane.AxisChange();
                zedGraphControl.Refresh();
            }));

            var points = new PointPairList();

            string currentSourceName = null;
            string currentSourcePath = null;

            msdata.MSData msd = null;

            lock (owner)
                foreach (var row in spectrumRows)
                {
                    if (row.SourceName != currentSourceName)
                    {
                        currentSourceName = row.SourceName;
                        currentSourcePath = IDPickerForm.LocateSpectrumSource(currentSourceName, session.Connection.GetDataSource());
                        msd = new pwiz.CLI.msdata.MSDataFile(currentSourcePath);

                        //var param = session.Query<AnalysisParameter>().Where(o => o.Name == "SpectrumListFilters").Min(o => o.Value);
                        //string spectrumListFilters = String.IsNullOrEmpty(param) ? String.Empty : param;
                        SpectrumListFactory.wrap(msd, spectrumListFilters.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                    }

                    string label = String.Format("{0}/{1}\n{2}", row.SourceName, msdata.id.abbreviate(row.Spectrum.NativeID), row.ModifiedSequence);

                    var spectrumList = msd.run.spectrumList;

                    ++spectraCount;

                    var pwizPeptide = new proteome.Peptide(row.ModifiedSequence, proteome.ModificationParsing.ModificationParsing_Auto,
                                                           proteome.ModificationDelimiter.ModificationDelimiter_Brackets);
                    var fragmentation = pwizPeptide.fragmentation(true, true);

                    var    pwizSpectrum = spectrumList.spectrum(spectrumList.find(row.Spectrum.NativeID), true);
                    var    pointMap     = new seems.PointMap(new ZedGraph.PointPairList(pwizSpectrum.getMZArray().data, pwizSpectrum.getIntensityArray().data));
                    double tic          = pointMap.Values.Sum();

                    double precursorMz = row.Spectrum.PrecursorMZ;
                    double chargeReducedPrecursorMz = precursorMz * row.PeptideSpectrumMatch.Charge;

                    bool plotMatchedPeaks   = true;
                    bool removeMatchedPeaks = false;

                    double tolerance = 0.03;
                    seems.PointMap.Enumerator itr;
                    IonSeries[] ionSeries = Enum.GetValues(typeof(IonSeries)).Cast <IonSeries>().Where(o => o != IonSeries.Count).ToArray();

                    for (int z = 1; z <= 1; ++z)
                    {
                        for (int length = 1, end = pwizPeptide.sequence.Length; length <= end; ++length)
                        {
                            string NTermFragment = row.ModifiedSequence.Substring(0, length);
                            string CTermFragment = row.ModifiedSequence.Substring(row.ModifiedSequence.Length - length);

                            foreach (IonSeries series in ionSeries)
                            {
                                if ((series == IonSeries.c || series == IonSeries.cMinus1 || series == IonSeries.x) &&
                                    length == pwizPeptide.sequence.Length)
                                {
                                    continue;
                                }

                                itr = pointMap.FindNear(fragmentMass(fragmentation, series, length, z), tolerance);
                                if (itr != null && itr.IsValid)
                                {
                                    if (plotMatchedPeaks)
                                    {
                                        precursorScatterPlot.AddPoint(new PointPair(itr.Current.Key - precursorMz, itr.Current.Value / tic, (int)series, String.Format("{0} {1}\n{2} {3} {4} {5}", label, precursorMz, NTermFragment, itr.Current.Key, IonSeriesLabels[(int)series], length)));
                                        chargeReducedScatterPlot.AddPoint(new PointPair(itr.Current.Key - chargeReducedPrecursorMz, itr.Current.Value / tic, (int)series, String.Format("{0} {1}\n{2} {3} {4} {5}", label, chargeReducedPrecursorMz, NTermFragment, itr.Current.Key, IonSeriesLabels[(int)series], length)));
                                    }

                                    if (removeMatchedPeaks)
                                    {
                                        pointMap.Remove(itr);
                                    }
                                }
                            }
                        }
                    }

                    foreach (var pair in pointMap)
                    {
                        precursorScatterPlot.AddPoint(new PointPair(pair.Key - precursorMz, pair.Value / tic, 0, label));
                        chargeReducedScatterPlot.AddPoint(new PointPair(pair.Key - chargeReducedPrecursorMz, pair.Value / tic, 0, label));
                    }

                    if ((spectraCount % 100) == 0)
                    {
                        Invoke(new MethodInvoker(() =>
                        {
                            zedGraphControl.MasterPane.AxisChange();
                            zedGraphControl.Refresh();
                        }));
                    }
                }

            Invoke(new MethodInvoker(() =>
            {
                if (!lockZoomCheckBox.Checked)
                {
                    zedGraphControl.ZoomOutAll(zedGraphControl.GraphPane);
                }
                zedGraphControl.MasterPane.AxisChange();
                zedGraphControl.Refresh();
            }));
            return(new List <double>()); //percentTicBySpectrumByFragmentType[1];
        }
示例#6
0
        private void getFragmentationStatistics()
        {
            IList <object[]> queryRows;

            lock (session)
            {
                var randomIds = session.CreateQuery("SELECT psm.Id " + viewFilter.GetFilteredQueryString(DataFilter.FromPeptideSpectrumMatch))
                                .List <long>()
                                .Shuffle()
                                .Take(1000)
                                .OrderBy(o => o);
                string randomIdSet = String.Join(",", randomIds.Select(o => o.ToString()).ToArray());
                queryRows = session.CreateQuery("SELECT psm.Spectrum.Source.Name, psm.Spectrum, psm, DISTINCT_GROUP_CONCAT(pm.Offset || ':' || mod.MonoMassDelta), psm.Peptide.Sequence " +
                                                "FROM PeptideSpectrumMatch psm " +
                                                "LEFT JOIN psm.Modifications pm " +
                                                "LEFT JOIN pm.Modification mod " +
                                                "WHERE psm.Id IN (" + randomIdSet + ") " +
                                                "GROUP BY psm.Spectrum.id ")
                            .List <object[]>();
            }
            var spectrumRows = queryRows.Select(o => new SpectrumRow(o)).OrderBy(o => o.SourceName);

            var percentTicBySpectrumByFragmentType       = new List <PointPairList>();
            var percentPeakCountBySpectrumByFragmentType = new List <PointPairList>();
            var meanMzErrorBySpectrumByFragmentType      = new List <PointPairList>();
            var percentTicListByFragmentType             = new List <List <double> >();
            var percentPeakCountListByFragmentType       = new List <List <double> >();
            var meanMzErrorListByFragmentType            = new List <List <double> >();

            foreach (var graphControl in graphControls)
            {
                graphControl.MasterPane.PaneList.ForEach(o => o.CurveList.ForEach(c => c.Clear()));
            }

            for (int i = 0; i < (int)IonSeries.Count; ++i)
            {
                percentTicBySpectrumByFragmentType.Add(percentTicGraphControl.MasterPane.PaneList[i + 1].CurveList[3].Points as PointPairList);
                percentPeakCountBySpectrumByFragmentType.Add(percentPeakCountGraphControl.MasterPane.PaneList[i + 1].CurveList[3].Points as PointPairList);
                meanMzErrorBySpectrumByFragmentType.Add(meanMzErrorGraphControl.MasterPane.PaneList[i + 1].CurveList[3].Points as PointPairList);
                percentTicListByFragmentType.Add(new List <double>());
                percentPeakCountListByFragmentType.Add(new List <double>());
                meanMzErrorListByFragmentType.Add(new List <double>());
            }

            int spectraCount = 0;

            maxPercentTic       = 10;
            maxPercentPeakCount = 10;
            maxMeanMzError      = 0.1;
            var tolerance = fragmentTolerance;

            string spectrumListFilters = String.Empty;

            Invoke(new MethodInvoker(() =>
            {
                tolerance.value = Convert.ToDouble(fragmentToleranceTextBox.Text);
                tolerance.units = (MZTolerance.Units)fragmentToleranceUnitsComboBox.SelectedIndex;
                meanMzErrorGraphControl.GraphPane.YAxis.Title.Text = "Mean m/z error (" + tolerance.units.ToString() + ")";

                spectrumListFilters = spectrumFiltersTextBox.Text;
                setAutomaticScales();
            }));

            var points = new PointPairList();

            string currentSourceName = null;
            string currentSourcePath = null;

            msdata.MSData msd = null;

            lock (owner)
                foreach (var row in spectrumRows)
                {
                    if (row.SourceName != currentSourceName)
                    {
                        currentSourceName = row.SourceName;
                        currentSourcePath = IDPickerForm.LocateSpectrumSource(currentSourceName, session.Connection.GetDataSource());
                        if (String.IsNullOrEmpty(currentSourcePath))
                        {
                            throw new FileNotFoundException("source file not found");
                        }
                        msd = new pwiz.CLI.msdata.MSDataFile(currentSourcePath);

                        //var param = session.Query<AnalysisParameter>().Where(o => o.Name == "SpectrumListFilters").Min(o => o.Value);
                        //string spectrumListFilters = String.IsNullOrEmpty(param) ? String.Empty : param;
                        SpectrumListFactory.wrap(msd, spectrumListFilters.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                    }

                    string spectrumId = String.Format("{0}/{1}", row.SourceName, msdata.id.abbreviate(row.Spectrum.NativeID));

                    var spectrumList = msd.run.spectrumList;

                    ++spectraCount;

                    var pwizPeptide = new proteome.Peptide(row.ModifiedSequence, proteome.ModificationParsing.ModificationParsing_Auto,
                                                           proteome.ModificationDelimiter.ModificationDelimiter_Brackets);
                    var fragmentation = pwizPeptide.fragmentation(true, true);

                    var    pwizSpectrum = spectrumList.spectrum(spectrumList.find(row.Spectrum.NativeID), true);
                    var    pointMap     = new seems.PointMap(new ZedGraph.PointPairList(pwizSpectrum.getMZArray().data, pwizSpectrum.getIntensityArray().data));
                    double tic          = pointMap.Values.Sum();

                    var percentTicByFragmentType       = new List <double>(Enumerable.Repeat(0.0, (int)IonSeries.Count));
                    var percentPeakCountByFragmentType = new List <double>(Enumerable.Repeat(0.0, (int)IonSeries.Count));
                    var matchCountByFragmentType       = new List <int>(Enumerable.Repeat(0, (int)IonSeries.Count));
                    var meanMzErrorByFragmentType      = new List <double>(Enumerable.Repeat(Double.NaN, (int)IonSeries.Count));

                    seems.PointMap.Enumerator itr;
                    double      expected;
                    IonSeries[] ionSeries = Enum.GetValues(typeof(IonSeries)).Cast <IonSeries>().Where(o => o != IonSeries.Count).ToArray();

                    for (int z = 1; z <= 1; ++z)
                    {
                        for (int length = 1, end = pwizPeptide.sequence.Length; length <= end; ++length)
                        {
                            foreach (IonSeries series in ionSeries)
                            {
                                if ((series == IonSeries.c || series == IonSeries.x) &&
                                    length == pwizPeptide.sequence.Length)
                                {
                                    continue;
                                }

                                expected = fragmentMass(fragmentation, series, length, z);
                                itr      = pointMap.FindNear(expected, expected - (expected - tolerance));
                                if (itr != null && itr.IsValid)
                                {
                                    percentTicByFragmentType[(int)series] += itr.Current.Value;
                                    ++percentPeakCountByFragmentType[(int)series];
                                    ++matchCountByFragmentType[(int)series];
                                    if (Double.IsNaN(meanMzErrorByFragmentType[(int)series]))
                                    {
                                        meanMzErrorByFragmentType[(int)series] = 0;
                                    }
                                    meanMzErrorByFragmentType[(int)series] += mzError(itr.Current.Key, expected);
                                }
                            }
                        }
                    }

                    var rng = new Random();

                    for (int i = 0; i < percentTicBySpectrumByFragmentType.Count; ++i)
                    {
                        // convert sum to mean
                        if (percentPeakCountByFragmentType[i] > 0)
                        {
                            meanMzErrorByFragmentType[i] /= matchCountByFragmentType[i];
                        }

                        // convert to percentages
                        percentTicByFragmentType[i]       /= tic / 100;
                        percentPeakCountByFragmentType[i] /= pointMap.Count / 100.0;

                        maxPercentTic       = Math.Max(maxPercentTic, percentTicByFragmentType[i]);
                        maxPercentPeakCount = Math.Max(maxPercentPeakCount, percentPeakCountByFragmentType[i]);

                        double jitter = (rng.NextDouble() - 0.5);
                        percentTicBySpectrumByFragmentType[i].Add(jitter, percentTicByFragmentType[i], String.Format("{0}: {1:G4}% ({2} matches)", spectrumId, percentTicByFragmentType[i], matchCountByFragmentType[i]));
                        percentPeakCountBySpectrumByFragmentType[i].Add(jitter, percentPeakCountByFragmentType[i], String.Format("{0}: {1:G4}% ({2} matches)", spectrumId, percentPeakCountByFragmentType[i], matchCountByFragmentType[i]));

                        percentTicListByFragmentType[i].Add(percentTicByFragmentType[i]);
                        percentPeakCountListByFragmentType[i].Add(percentPeakCountByFragmentType[i]);

                        if (!Double.IsNaN(meanMzErrorByFragmentType[i]))
                        {
                            maxMeanMzError = Math.Max(maxMeanMzError, Math.Abs(meanMzErrorByFragmentType[i]));
                            meanMzErrorBySpectrumByFragmentType[i].Add(jitter, meanMzErrorByFragmentType[i], String.Format("{0}: {1:G4}%", spectrumId, meanMzErrorByFragmentType[i]));
                            meanMzErrorListByFragmentType[i].Add(meanMzErrorByFragmentType[i]);
                        }
                    }

                    if ((spectraCount % 100) == 0)
                    {
                        setAutomaticScales();
                    }
                }// for each spectrum row

            Invoke(new MethodInvoker(() =>
            {
                for (int i = 0; i < percentTicBySpectrumByFragmentType.Count; ++i)
                {
                    if (percentTicListByFragmentType[i].Count < 5)
                    {
                        continue;
                    }
                    percentTicListByFragmentType[i].Sort();
                    percentPeakCountListByFragmentType[i].Sort();
                    addSixNumberSummary(percentTicGraphControl.MasterPane.PaneList[i + 1], percentTicListByFragmentType[i]);
                    addSixNumberSummary(percentPeakCountGraphControl.MasterPane.PaneList[i + 1], percentPeakCountListByFragmentType[i]);

                    if (meanMzErrorListByFragmentType[i].Count < 5)
                    {
                        continue;
                    }
                    meanMzErrorListByFragmentType[i].Sort();
                    addSixNumberSummary(meanMzErrorGraphControl.MasterPane.PaneList[i + 1], meanMzErrorListByFragmentType[i]);
                }
            }));
        }
示例#7
0
        private void LoadPwizReader()
        {
            if (_loaded)
            {
                return;
            }

            var readers = ReaderList.FullReaderList;

            readers.read(FilePath, _dataFile);
            if ((new string[] { ".mzml", ".mzml.gz", ".mzxml", ".mzxml.gz", ".mgf", ".mgf.gz", ".txt", "uimf", "uimf.gz" })
                .Any(ext => FilePath.ToLower().EndsWith(ext)))
            {
                // Files that do not have vendor centroiding available
                Console.WriteLine("Using cwt Centroiding");
                _filters.Add(_cwtCentroiding);
            }
            else
            {
                Console.WriteLine("Using vendor Centroiding");
                _filters.Add(_vendorCentroiding);
            }
            SpectrumListFactory.wrap(_dataFile, _filters);

            _numSpectra = _dataFile.run.spectrumList.size();
            foreach (var srcFile in _dataFile.fileDescription.sourceFiles)
            {
                var cv = srcFile.cvParam(CVID.MS_SHA_1);
                if (!cv.empty())
                {
                    _srcFileChecksum = cv.value;
                    break;
                }
            }

            if (string.IsNullOrWhiteSpace(_srcFileChecksum))
            {
                var fileForChecksum = string.Empty;
                if (File.Exists(FilePath))
                {
                    // is file
                    fileForChecksum = FilePath;
                }
                else
                {
                    var dir   = new DirectoryInfo(FilePath);
                    var files = dir.GetFiles("*", SearchOption.AllDirectories);
                    if (files.Length == 0)
                    {
                        throw new IOException("Cannot open directory with no files: " + FilePath);
                    }
                    fileForChecksum = files[0].FullName;
                }
                using (var fs = new FileStream(fileForChecksum, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var sha1 = new SHA1Managed())
                    {
                        var hash = sha1.ComputeHash(fs);
                        _srcFileChecksum = BitConverter.ToString(hash).ToLower().Replace("-", "");
                    }
            }

            foreach (var software in _dataFile.softwareList)
            {
                _fileFormatVersion = software.version;
            }

            _loaded = true;
        }
示例#8
0
        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);
                }
            }
        }