示例#1
0
        private phosphoRS.PTMResultClass RunOnSource(string sourceFilepath, int currentSource, int totalSources, PhosphoRSConfig config, IDictionary<long, PhosphoPeptideAttestationRow> phosphoRows)
        {
            var msd = new pwiz.CLI.msdata.MSDataFile(sourceFilepath);
            var spectrumList = msd.run.spectrumList;

            int rowNumber = 0;
            int totalRows = phosphoRows.Count();
            items.Clear();

            var spectrumTypes = new Set<CVID>();

            foreach (var row in phosphoRows)
            {
                if (rowNumber == 0 || (rowNumber % 100) == 0)
                {
                    if (cancelAttestation.IsCancellationRequested)
                    {
                        this.progressBar.ProgressBar.Visible = false;
                        _bgWorkerCancelled = true;
                        setProgress(-1, "Cancelled.");
                        return null;
                    }
                    else
                    {
                        if (rowNumber == 0)
                            setStatus(String.Format("Reading peaks and creating PhosphoRS objects for source {0} of {1} ({2}): {3} spectra\r\n", currentSource, totalSources, Path.GetFileName(sourceFilepath), totalRows));
                        setProgress((rowNumber + 1) / totalRows * 100, String.Format("Reading peaks and creating PhosphoRS objects for source {0} of {1} ({2}): {3}/{4} spectra", currentSource, totalSources, Path.GetFileName(sourceFilepath), rowNumber + 1, totalRows));
                    }
                }

                var pwizSpectrum = spectrumList.spectrum(spectrumList.find(row.Value.SpectrumNativeID), true); //may create indexoutofrange error if no spectrum nativeID                   

                var OriginalMZs = pwizSpectrum.getMZArray().data; //getMZArray().data returns IList<double>
                var OriginalIntensities = pwizSpectrum.getIntensityArray().data;
                row.Value.Peaks = new phosphoRS.Peak[OriginalMZs.Count];
                for (int i = 0; i < OriginalMZs.Count; ++i)
                    row.Value.Peaks[i] = new phosphoRS.Peak(OriginalMZs[i], OriginalIntensities[i]);

                if (config.spectrumType == phosphoRS.SpectrumType.None)
                {
                    row.Value.SpectrumType = phosphoRS.SpectrumType.None;
                    foreach (var precursor in pwizSpectrum.precursors)
                        foreach (var method in precursor.activation.cvParamChildren(CVID.MS_dissociation_method))
                        {
                            // if dissociation method is set to "Auto" but could not be determined from the file, alert the user
                            if (!spectrumTypeByDissociationMethod.Contains(method.cvid))
                                throw new InvalidDataException("cannot handle unmapped dissociation method \"" + CV.cvTermInfo(method.cvid).shortName() + "\" for spectrum \"" + row.Value.SourceName + "/" + row.Value.SpectrumNativeID + "\"; please override the method manually");
                            else if (row.Value.SpectrumType != phosphoRS.SpectrumType.ECD_ETD) // don't override ETD (e.g. if there is also supplemental CID)
                            {
                                row.Value.SpectrumType = spectrumTypeByDissociationMethod[method.cvid];
                                spectrumTypes.Add(method.cvid);
                            }
                        }

                    if (row.Value.SpectrumType == phosphoRS.SpectrumType.None)
                        throw new InvalidDataException("cannot find a dissociation method for spectrum \"" + row.Value.SourceName + "/" + row.Value.SpectrumNativeID + "\"; please set the method manually");
                }
                else
                    row.Value.SpectrumType = config.spectrumType;

                var psm = getPhosphoRS_PSM(config, row.Value);

                // DEBUG
                //tbStatus.AppendText(PeptideToString(phosphoPeptide) + "," + AAS.ToOneLetterCodeString() + "," + ptmRepresentation.ToString() + "\n");
                // Init the mod map of original variant for this PSM.
                var id2ModMap = new List<System.Tuple<int, List<int>>> { new System.Tuple<int, List<int>>((int) row.Value.PSMId, row.Value.OriginalPhosphoSites.Keys.ToList<int>()) };

                items.Add(new System.Tuple<phosphoRS.PeptideSpectrumMatch, List<System.Tuple<int, List<int>>>>(psm, id2ModMap));

                ++rowNumber;
            }

            // report automatically found fragmentation method
            if (config.spectrumType == phosphoRS.SpectrumType.None)
                setStatus(String.Format("Found {0} fragmentation types: {1}\r\n", spectrumTypes.Count, String.Join(", ", spectrumTypes.Keys.Select(o => CV.cvTermInfo(o).shortName()))));

            setProgress(currentSource / totalSources * 100, String.Format("Running PhosphoRS on source {0} of {1} ({2})...", currentSource, totalSources, Path.GetFileName(sourceFilepath)));

            // Initialize the localization.
            currentNr = 0;
            var phosphoRS_Context = new phosphoRS.ThreadManagement(this, cancelAttestation, config.maxIsoformCount, config.maxPTMCount, config.scoreNLToo, config.fragmentMassTolerance, config.scoredAA, items.Count);

            // Start the site localization (takes advantage of multi-threading)
            try
            {
                phosphoRS_Context.StartPTMLocalisation();

                // Safety if the attestation module doesn't throw the exception.
                if (cancelAttestation.IsCancellationRequested)
                {
                    this.progressBar.ProgressBar.Visible = false;
                    _bgWorkerCancelled = true;
                    setProgress(-1, "Cancelled.");
                    return null;
                }

                return phosphoRS_Context.PTMResult;
            }
            catch (OperationCanceledException)
            {
                this.progressBar.ProgressBar.Visible = false;
                _bgWorkerCancelled = true;
                setProgress(-1, "Cancelled.");
                return null;
            }
            finally
            {
                msd.Dispose();
            }
        }
示例#2
0
        private phosphoRS.PTMResultClass RunOnSource(string sourceFilepath, int currentSource, int totalSources, PhosphoRSConfig config, IDictionary <long, PhosphoPeptideAttestationRow> phosphoRows)
        {
            var msd          = new pwiz.CLI.msdata.MSDataFile(sourceFilepath);
            var spectrumList = msd.run.spectrumList;

            int rowNumber = 0;
            int totalRows = phosphoRows.Count();

            items.Clear();

            var spectrumTypes = new Set <CVID>();

            foreach (var row in phosphoRows)
            {
                if (rowNumber == 0 || (rowNumber % 100) == 0)
                {
                    if (cancelAttestation.IsCancellationRequested)
                    {
                        this.progressBar.ProgressBar.Visible = false;
                        _bgWorkerCancelled = true;
                        setProgress(-1, "Cancelled.");
                        return(null);
                    }
                    else
                    {
                        if (rowNumber == 0)
                        {
                            setStatus(String.Format("Reading peaks and creating PhosphoRS objects for source {0} of {1} ({2}): {3} spectra\r\n", currentSource, totalSources, Path.GetFileName(sourceFilepath), totalRows));
                        }
                        setProgress((rowNumber + 1) / totalRows * 100, String.Format("Reading peaks and creating PhosphoRS objects for source {0} of {1} ({2}): {3}/{4} spectra", currentSource, totalSources, Path.GetFileName(sourceFilepath), rowNumber + 1, totalRows));
                    }
                }

                var pwizSpectrum = spectrumList.spectrum(spectrumList.find(row.Value.SpectrumNativeID), true); //may create indexoutofrange error if no spectrum nativeID

                var OriginalMZs         = pwizSpectrum.getMZArray().data;                                      //getMZArray().data returns IList<double>
                var OriginalIntensities = pwizSpectrum.getIntensityArray().data;
                row.Value.Peaks = new phosphoRS.Peak[OriginalMZs.Count];
                for (int i = 0; i < OriginalMZs.Count; ++i)
                {
                    row.Value.Peaks[i] = new phosphoRS.Peak(OriginalMZs[i], OriginalIntensities[i]);
                }

                if (config.spectrumType == phosphoRS.SpectrumType.None)
                {
                    row.Value.SpectrumType = phosphoRS.SpectrumType.None;
                    foreach (var precursor in pwizSpectrum.precursors)
                    {
                        foreach (var method in precursor.activation.cvParamChildren(CVID.MS_dissociation_method))
                        {
                            // if dissociation method is set to "Auto" but could not be determined from the file, alert the user
                            if (!spectrumTypeByDissociationMethod.Contains(method.cvid))
                            {
                                throw new InvalidDataException("cannot handle unmapped dissociation method \"" + CV.cvTermInfo(method.cvid).shortName() + "\" for spectrum \"" + row.Value.SourceName + "/" + row.Value.SpectrumNativeID + "\"; please override the method manually");
                            }
                            else if (row.Value.SpectrumType != phosphoRS.SpectrumType.ECD_ETD) // don't override ETD (e.g. if there is also supplemental CID)
                            {
                                row.Value.SpectrumType = spectrumTypeByDissociationMethod[method.cvid];
                                spectrumTypes.Add(method.cvid);
                            }
                        }
                    }

                    if (row.Value.SpectrumType == phosphoRS.SpectrumType.None)
                    {
                        throw new InvalidDataException("cannot find a dissociation method for spectrum \"" + row.Value.SourceName + "/" + row.Value.SpectrumNativeID + "\"; please set the method manually");
                    }
                }
                else
                {
                    row.Value.SpectrumType = config.spectrumType;
                }

                var psm = getPhosphoRS_PSM(config, row.Value);

                // DEBUG
                //tbStatus.AppendText(PeptideToString(phosphoPeptide) + "," + AAS.ToOneLetterCodeString() + "," + ptmRepresentation.ToString() + "\n");
                // Init the mod map of original variant for this PSM.
                var id2ModMap = new List <System.Tuple <int, List <int> > > {
                    new System.Tuple <int, List <int> >((int)row.Value.PSMId, row.Value.OriginalPhosphoSites.Keys.ToList <int>())
                };

                items.Add(new System.Tuple <phosphoRS.PeptideSpectrumMatch, List <System.Tuple <int, List <int> > > >(psm, id2ModMap));

                ++rowNumber;
            }

            // report automatically found fragmentation method
            if (config.spectrumType == phosphoRS.SpectrumType.None)
            {
                setStatus(String.Format("Found {0} fragmentation types: {1}\r\n", spectrumTypes.Count, String.Join(", ", spectrumTypes.Keys.Select(o => CV.cvTermInfo(o).shortName()))));
            }

            setProgress(currentSource / totalSources * 100, String.Format("Running PhosphoRS on source {0} of {1} ({2})...", currentSource, totalSources, Path.GetFileName(sourceFilepath)));

            // Initialize the localization.
            currentNr = 0;
            var phosphoRS_Context = new phosphoRS.ThreadManagement(this, cancelAttestation, config.maxIsoformCount, config.maxPTMCount, config.scoreNLToo, config.fragmentMassTolerance, config.scoredAA, items.Count);

            // Start the site localization (takes advantage of multi-threading)
            try
            {
                phosphoRS_Context.StartPTMLocalisation();

                // Safety if the attestation module doesn't throw the exception.
                if (cancelAttestation.IsCancellationRequested)
                {
                    this.progressBar.ProgressBar.Visible = false;
                    _bgWorkerCancelled = true;
                    setProgress(-1, "Cancelled.");
                    return(null);
                }

                return(phosphoRS_Context.PTMResult);
            }
            catch (OperationCanceledException)
            {
                this.progressBar.ProgressBar.Visible = false;
                _bgWorkerCancelled = true;
                setProgress(-1, "Cancelled.");
                return(null);
            }
            finally
            {
                msd.Dispose();
            }
        }