Ejemplo n.º 1
0
        public PeakBoundsMatch(TransitionGroupChromInfo chromInfoTrue,
                               TransitionGroupChromInfo chromInfoPicked,
                               MatchKey key,
                               ChromatogramSet chromSet,
                               MsDataFileUri filePath,
                               TransitionGroupDocNode nodeGroup,
                               PeptideDocNode nodePep,
                               bool hasNoQValues,
                               bool hasNoScores,
                               bool apexPresent)
        {
            _chromatogramSet = chromSet;

            ChromInfoTrue   = chromInfoTrue;
            ChromInfoPicked = chromInfoPicked;
            Key             = key;
            FilePath        = filePath;
            NodeGroup       = nodeGroup;
            NodePep         = nodePep;
            // Read apex
            if (apexPresent)
            {
                PickedApex          = ParsePickedTimeAnnotation(ComparePeakBoundaries.APEX_ANNOTATION);
                PickedStartBoundary = ParsePickedTimeAnnotation(ComparePeakBoundaries.START_TIME_ANNOTATION);
                PickedEndBoundary   = ParsePickedTimeAnnotation(ComparePeakBoundaries.END_TIME_ANNOTATION);
            }
            else
            {
                PickedApex          = ChromInfoPicked.RetentionTime;
                PickedStartBoundary = ChromInfoPicked.StartRetentionTime;
                PickedEndBoundary   = ChromInfoPicked.EndRetentionTime;
            }
            QValue = GetScoreValue(ChromInfoPicked, MProphetResultsHandler.AnnotationName, ci => ci.QValue);
            if (QValue == null && !IsMissingPickedPeak && !hasNoQValues)
            {
                throw new IOException(string.Format(
                                          Resources.PeakBoundsMatch_QValue_Unable_to_read_q_value_annotation_for_peptide__0__of_file__1_,
                                          ModifiedSequence, FileName));
            }
            Score = GetScoreValue(ChromInfoPicked, MProphetResultsHandler.MAnnotationName, ci => ci.ZScore);
            if (Score == null && !IsMissingPickedPeak && !hasNoScores)
            {
                throw new IOException(string.Format(
                                          Resources.PeakBoundsMatch_PeakBoundsMatch_Unable_to_read_a_score_annotation_for_peptide__0__of_file__1_,
                                          ModifiedSequence, FileName));
            }
        }
 protected bool Equals(MatchKey other)
 {
     return(FileId == other.FileId && TransitionGroupId == other.TransitionGroupId);
 }
        public PeakBoundsMatch(TransitionGroupChromInfo chromInfoTrue,
                               TransitionGroupChromInfo chromInfoPicked,
                               MatchKey key,
                               MsDataFileUri filePath,
                               TransitionGroupDocNode nodeGroup,
                               bool hasNoQValues,
                               bool hasNoScores,
                               bool apexPresent)
        {
            ChromInfoTrue   = chromInfoTrue;
            ChromInfoPicked = chromInfoPicked;
            Key             = key;
            FilePath        = filePath;
            NodeGroup       = nodeGroup;
            // Read apex
            if (apexPresent)
            {
                string apexString = ChromInfoPicked.Annotations.GetAnnotation(ComparePeakBoundaries.APEX_ANNOTATION);
                double apexDouble;
                if (!double.TryParse(apexString, out apexDouble))
                {
                    if (apexString == null || apexString.Equals(TextUtil.EXCEL_NA))
                    {
                        PickedApex = null;
                    }
                    else
                    {
                        throw new IOException(string.Format(Resources.PeakBoundsMatch_PeakBoundsMatch_Unable_to_read_apex_retention_time_value_for_peptide__0__of_file__1__, Sequence, FileName));
                    }
                }
                else
                {
                    PickedApex = apexDouble;
                }
            }
            else
            {
                PickedApex = ChromInfoPicked.RetentionTime;
            }
            string qValueString = ChromInfoPicked.Annotations.GetAnnotation(MProphetResultsHandler.AnnotationName);
            double qValueDouble;

            // qValue MUST be present unless the peak is null or ALL q Values are absent
            if (!double.TryParse(qValueString, out qValueDouble))
            {
                if (!IsMissingPickedPeak && !hasNoQValues)
                {
                    throw new IOException(string.Format(Resources.PeakBoundsMatch_QValue_Unable_to_read_q_value_annotation_for_peptide__0__of_file__1_, Sequence, FileName));
                }
                QValue = null;
            }
            else
            {
                QValue = qValueDouble;
            }
            // Same for score
            string scoreString = ChromInfoPicked.Annotations.GetAnnotation(MProphetResultsHandler.MAnnotationName);
            double scoreDouble;

            if (!double.TryParse(scoreString, out scoreDouble))
            {
                if (!IsMissingPickedPeak && !hasNoScores)
                {
                    throw new IOException(string.Format(Resources.PeakBoundsMatch_QValue_Unable_to_read_q_value_annotation_for_peptide__0__of_file__1_, Sequence, FileName));
                }
                Score = null;
            }
            else
            {
                Score = scoreDouble;
            }
        }
        public void GenerateComparison(SrmDocument docOriginal, IProgressMonitor progressMonitor)
        {
            DocOriginal = docOriginal;
            _docCompare = docOriginal;
            if (IsModel)
            {
                var handler = new MProphetResultsHandler(DocOriginal, PeakScoringModel)
                {
                    AddAnnotation  = true,
                    AddMAnnotation = true
                };
                handler.ScoreFeatures(progressMonitor);
                _docCompare = handler.ChangePeaks(progressMonitor);
            }
            else
            {
                // Add in the necessary annotation definitions so that ImportPeakBoundaries can read them
                _docCompare = AddAnnotationIfMissing(_docCompare, MProphetResultsHandler.AnnotationName);
                _docCompare = AddAnnotationIfMissing(_docCompare, MProphetResultsHandler.MAnnotationName);
                _docCompare = AddAnnotationIfMissing(_docCompare, APEX_ANNOTATION);
                // But strip the values of these annotations if there were any
                var annotationNamesToStrip = new List <string>
                {
                    MProphetResultsHandler.AnnotationName,
                    MProphetResultsHandler.MAnnotationName,
                    APEX_ANNOTATION
                };
                var annotationNamesToKeep = _docCompare.Settings.DataSettings.AnnotationDefs
                                            .Where(def => !annotationNamesToStrip.Contains(def.Name))
                                            .Select(def => def.Name).ToList();
                _docCompare = (SrmDocument)_docCompare.StripAnnotationValues(annotationNamesToKeep);
                Importer    = new PeakBoundaryImporter(_docCompare);
                long lineCount = Helpers.CountLinesInFile(FilePath);
                // Peek at the file to see if it has a column called "Apex"
                using (var reader = new StreamReader(FilePath))
                {
                    var line       = reader.ReadLine();
                    var fieldNames = PeakBoundaryImporter.FIELD_NAMES.ToList();
                    fieldNames.Add(new [] { APEX_ANNOTATION });
                    int   fieldsTotal;
                    int[] fieldIndices;
                    var   separator = PeakBoundaryImporter.DetermineCorrectSeparator(line, fieldNames,
                                                                                     PeakBoundaryImporter.REQUIRED_NO_CHROM, out fieldIndices, out fieldsTotal);
                    ApexPresent = separator != null && fieldIndices.Last() != -1;
                }
                _docCompare = Importer.Import(FilePath, progressMonitor, lineCount, true, !ApexPresent);
            }
            var matches          = new List <PeakBoundsMatch>();
            var truePeptides     = DocOriginal.Molecules.ToList();
            var pickedPeptides   = _docCompare.Molecules.ToList();
            int nTruePeptides    = truePeptides.Count;
            var chromatogramSets = DocOriginal.Settings.MeasuredResults.Chromatograms;

            for (int i = 0; i < chromatogramSets.Count; i++)
            {
                var set = chromatogramSets[i];
                for (int j = 0; j < nTruePeptides; j++)
                {
                    var truePeptide   = truePeptides[j];
                    var pickedPeptide = pickedPeptides[j];
                    // We don't care about peak picking performance for decoys
                    if (truePeptide.IsDecoy)
                    {
                        continue;
                    }
                    // We don't care about peak picking performance for standard peptides
                    if (truePeptide.GlobalStandardType != null)
                    {
                        continue;
                    }
                    var trueGroups   = truePeptide.TransitionGroups.ToList();
                    var pickedGroups = pickedPeptide.TransitionGroups.ToList();
                    for (int k = 0; k < trueGroups.Count; k++)
                    {
                        var trueGroup     = trueGroups[k];
                        var pickedGroup   = pickedGroups[k];
                        var trueResults   = trueGroup.Results[i];
                        var pickedResults = pickedGroup.Results[i];
                        if (trueResults == null)
                        {
                            continue;
                        }
                        int nChromInfos = trueResults.Count;
                        for (int m = 0; m < nChromInfos; m++)
                        {
                            var trueInfo   = trueResults[m];
                            var pickedInfo = pickedResults[m];
                            var fileInfo   = set.GetFileInfo(trueInfo.FileId);
                            var filePath   = fileInfo.FilePath;
                            var key        = new MatchKey(trueGroup.Id.GlobalIndex, trueInfo.FileId.GlobalIndex);
                            matches.Add(new PeakBoundsMatch(trueInfo, pickedInfo, key, filePath, trueGroup,
                                                            HasNoQValues, HasNoScores, ApexPresent));
                        }
                    }
                }
            }
            Matches = matches;
            // Detect if the apex time is in seconds, and if so adjust it to minutes
            if (ApexPresent)
            {
                double maxTime = matches.Where(match => match.PickedApex.HasValue)
                                 .Select(match => match.PickedApex.Value).Max();
                if (maxTime > PeakBoundaryImporter.GetMaxRt(DocOriginal))
                {
                    foreach (var match in matches.Where(match => match.PickedApex.HasValue))
                    {
                        match.PickedApex = match.PickedApex / 60;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void GenerateComparison(SrmDocument docOriginal, IProgressMonitor progressMonitor)
        {
            DocOriginal = docOriginal;
            _docCompare = docOriginal;
            if (IsModel)
            {
                var handler = new MProphetResultsHandler(DocOriginal, PeakScoringModel);
                handler.ScoreFeatures(progressMonitor, true);
                _docCompare = handler.ChangePeaks(progressMonitor);
            }
            else
            {
                // Add in the necessary annotation definitions so that ImportPeakBoundaries can read them
                var annotationNamesToStrip = new List <string>
                {
                    MProphetResultsHandler.AnnotationName,
                    MProphetResultsHandler.MAnnotationName,
                    APEX_ANNOTATION,
                    START_TIME_ANNOTATION,
                    END_TIME_ANNOTATION
                };
                foreach (var annotationName in annotationNamesToStrip)
                {
                    _docCompare = AddAnnotationIfMissing(_docCompare, annotationName);
                }
                // But strip the values of these annotations if there were any
                var annotationNamesToKeep = _docCompare.Settings.DataSettings.AnnotationDefs
                                            .Where(def => !annotationNamesToStrip.Contains(def.Name))
                                            .Select(def => def.Name).ToList();
                _docCompare = (SrmDocument)_docCompare.StripAnnotationValues(annotationNamesToKeep);
                Importer    = new PeakBoundaryImporter(_docCompare);
                long lineCount = Helpers.CountLinesInFile(FilePath);
                // Peek at the file to see if it has a column called "Apex"
                using (var reader = new StreamReader(FilePath))
                {
                    var   line       = reader.ReadLine();
                    var   fieldNames = PeakBoundaryImporter.FIELD_NAMES.ToList();
                    int   fieldsTotal;
                    int[] fieldIndices;
                    var   separator = PeakBoundaryImporter.DetermineCorrectSeparator(line, fieldNames,
                                                                                     PeakBoundaryImporter.REQUIRED_NO_CHROM, out fieldIndices, out fieldsTotal);
                    ApexPresent = separator != null && fieldIndices[(int)PeakBoundaryImporter.Field.apex_time] != -1;
                }
                _docCompare = Importer.Import(FilePath, progressMonitor, lineCount, true, !ApexPresent);
                if (progressMonitor.IsCanceled)
                {
                    return;
                }
            }
            var matches          = new List <PeakBoundsMatch>();
            var truePeptides     = DocOriginal.Molecules.ToList();
            var pickedPeptides   = _docCompare.Molecules.ToList();
            int nTruePeptides    = truePeptides.Count;
            var chromatogramSets = DocOriginal.Settings.MeasuredResults.Chromatograms;

            for (int i = 0; i < chromatogramSets.Count; i++)
            {
                var chromSet = chromatogramSets[i];
                var set      = chromatogramSets[i];
                for (int j = 0; j < nTruePeptides; j++)
                {
                    var truePeptide   = truePeptides[j];
                    var pickedPeptide = pickedPeptides[j];
                    // We don't care about peak picking performance for decoys
                    if (truePeptide.IsDecoy)
                    {
                        continue;
                    }
                    // We don't care about peak picking performance for standard peptides
                    if (truePeptide.GlobalStandardType != null)
                    {
                        continue;
                    }
                    var trueGroups   = truePeptide.TransitionGroups.ToList();
                    var pickedGroups = pickedPeptide.TransitionGroups.ToList();
                    for (int k = 0; k < trueGroups.Count; k++)
                    {
                        var trueGroup     = trueGroups[k];
                        var pickedGroup   = pickedGroups[k];
                        var trueResults   = trueGroup.Results[i];
                        var pickedResults = pickedGroup.Results[i];
                        if (trueResults.IsEmpty)
                        {
                            continue;
                        }
                        int nChromInfos = trueResults.Count;
                        for (int m = 0; m < nChromInfos; m++)
                        {
                            var trueInfo   = trueResults[m];
                            var pickedInfo = pickedResults[m];
                            // For TRIC testing at the moment
//                            double? qvaluePicked = PeakBoundsMatch.GetScoreValue(pickedInfo,
//                                MProphetResultsHandler.AnnotationName, ci => pickedInfo.QValue);
//                            if (qvaluePicked.HasValue && qvaluePicked.Value > 0.01)
//                                continue;
                            var fileInfo = set.GetFileInfo(trueInfo.FileId);
                            var filePath = fileInfo.FilePath;
                            var key      = new MatchKey(trueGroup.Id.GlobalIndex, trueInfo.FileId.GlobalIndex);
                            matches.Add(new PeakBoundsMatch(trueInfo, pickedInfo, key, chromSet, filePath,
                                                            trueGroup, truePeptide, HasNoQValues, HasNoScores, ApexPresent));
                        }
                    }
                }
            }
            Matches = matches;
            // Detect if the apex time is in seconds, and if so adjust it to minutes
            if (ApexPresent)
            {
                // ReSharper disable PossibleMultipleEnumeration
                var    matchesWithApex = matches.Where(match => match.PickedApex.HasValue).ToArray();
                double maxTime         = 0;
                if (matchesWithApex.Length > 0)
                {
                    maxTime = matchesWithApex.Select(match => match.PickedApex.Value).Max();
                }
                if (maxTime > PeakBoundaryImporter.GetMaxRt(DocOriginal))
                {
                    foreach (var match in matchesWithApex)
                    {
                        // If the end is greater than the Apex, then it must also be in seconds (otherwise minutes)
                        if (match.PickedEndBoundary.HasValue && match.PickedEndBoundary > match.PickedApex)
                        {
                            match.PickedEndBoundary = match.PickedEndBoundary / 60;
                        }
                        match.PickedApex = match.PickedApex / 60;
                        // If the start is now greater than the apex, then it must also be in seconds (otherwise minutes)
                        if (match.PickedStartBoundary.HasValue && match.PickedStartBoundary > match.PickedApex)
                        {
                            match.PickedStartBoundary = match.PickedStartBoundary / 60;
                        }
                    }
                }
                // ReSharper restore PossibleMultipleEnumeration
            }
        }
Ejemplo n.º 6
0
 public PeakBoundsMatch(TransitionGroupChromInfo chromInfoTrue, 
     TransitionGroupChromInfo chromInfoPicked,
     MatchKey key,
     MsDataFileUri filePath,
     TransitionGroupDocNode nodeGroup,
     bool hasNoQValues,
     bool hasNoScores,
     bool apexPresent)
 {
     ChromInfoTrue = chromInfoTrue;
     ChromInfoPicked = chromInfoPicked;
     Key = key;
     FilePath = filePath;
     NodeGroup = nodeGroup;
     // Read apex
     if (apexPresent)
     {
         string apexString = ChromInfoPicked.Annotations.GetAnnotation(ComparePeakBoundaries.APEX_ANNOTATION);
         double apexDouble;
         if (!double.TryParse(apexString, out apexDouble))
         {
             if (apexString == null || apexString.Equals(TextUtil.EXCEL_NA))
             {
                 PickedApex = null;
             }
             else
             {
                 throw new IOException(string.Format(Resources.PeakBoundsMatch_PeakBoundsMatch_Unable_to_read_apex_retention_time_value_for_peptide__0__of_file__1__, Sequence, FileName));
             }
         }
         else
         {
             PickedApex = apexDouble;
         }
     }
     else
     {
         PickedApex = ChromInfoPicked.RetentionTime;
     }
     string qValueString = ChromInfoPicked.Annotations.GetAnnotation(MProphetResultsHandler.AnnotationName);
     double qValueDouble;
     // qValue MUST be present unless the peak is null or ALL q Values are absent
     if (!double.TryParse(qValueString, out qValueDouble))
     {
         if (!IsMissingPickedPeak && !hasNoQValues)
         {
             throw new IOException(string.Format(Resources.PeakBoundsMatch_QValue_Unable_to_read_q_value_annotation_for_peptide__0__of_file__1_, Sequence, FileName));
         }
         QValue = null;
     }
     else
     {
         QValue = qValueDouble;
     }
     // Same for score
     string scoreString = ChromInfoPicked.Annotations.GetAnnotation(MProphetResultsHandler.MAnnotationName);
     double scoreDouble;
     if (!double.TryParse(scoreString, out scoreDouble))
     {
         if (!IsMissingPickedPeak && !hasNoScores)
         {
             throw new IOException(string.Format(Resources.PeakBoundsMatch_QValue_Unable_to_read_q_value_annotation_for_peptide__0__of_file__1_, Sequence, FileName));
         }
         Score = null;
     }
     else
     {
         Score = scoreDouble;
     }
 }
Ejemplo n.º 7
0
 protected bool Equals(MatchKey other)
 {
     return FileId == other.FileId && TransitionGroupId == other.TransitionGroupId;
 }
Ejemplo n.º 8
0
 public void GenerateComparison(SrmDocument docOriginal, IProgressMonitor progressMonitor)
 {
     DocOriginal = docOriginal;
     _docCompare = docOriginal;
     if (IsModel)
     {
         var handler = new MProphetResultsHandler(DocOriginal, PeakScoringModel)
         {
             AddAnnotation = true,
             AddMAnnotation = true
         };
         handler.ScoreFeatures(progressMonitor);
         _docCompare = handler.ChangePeaks(progressMonitor);
     }
     else
     {
         // Add in the necessary annotation definitions so that ImportPeakBoundaries can read them
         _docCompare = AddAnnotationIfMissing(_docCompare, MProphetResultsHandler.AnnotationName);
         _docCompare = AddAnnotationIfMissing(_docCompare, MProphetResultsHandler.MAnnotationName);
         _docCompare = AddAnnotationIfMissing(_docCompare, APEX_ANNOTATION);
         // But strip the values of these annotations if there were any
         var annotationNamesToStrip = new List<string>
         {
             MProphetResultsHandler.AnnotationName,
             MProphetResultsHandler.MAnnotationName,
             APEX_ANNOTATION
         };
         var annotationNamesToKeep = _docCompare.Settings.DataSettings.AnnotationDefs
             .Where(def => !annotationNamesToStrip.Contains(def.Name))
             .Select(def => def.Name).ToList();
         _docCompare = (SrmDocument)_docCompare.StripAnnotationValues(annotationNamesToKeep);
         Importer = new PeakBoundaryImporter(_docCompare);
         long lineCount = Helpers.CountLinesInFile(FilePath);
         // Peek at the file to see if it has a column called "Apex"
         using (var reader = new StreamReader(FilePath))
         {
             var line = reader.ReadLine();
             var fieldNames = PeakBoundaryImporter.FIELD_NAMES.ToList();
             fieldNames.Add(new [] {APEX_ANNOTATION});
             int fieldsTotal;
             int[] fieldIndices;
             var separator = PeakBoundaryImporter.DetermineCorrectSeparator(line, fieldNames,
                 PeakBoundaryImporter.REQUIRED_NO_CHROM, out fieldIndices, out fieldsTotal);
             ApexPresent = separator != null && fieldIndices.Last() != -1;
         }
         _docCompare = Importer.Import(FilePath, progressMonitor, lineCount, true, !ApexPresent);
     }
     var matches = new List<PeakBoundsMatch>();
     var truePeptides = DocOriginal.Molecules.ToList();
     var pickedPeptides = _docCompare.Molecules.ToList();
     int nTruePeptides = truePeptides.Count;
     var chromatogramSets = DocOriginal.Settings.MeasuredResults.Chromatograms;
     for (int i = 0; i < chromatogramSets.Count; i++)
     {
         var set = chromatogramSets[i];
         for (int j = 0; j < nTruePeptides; j++)
         {
             var truePeptide = truePeptides[j];
             var pickedPeptide = pickedPeptides[j];
             // We don't care about peak picking performance for decoys
             if (truePeptide.IsDecoy)
                 continue;
             // We don't care about peak picking performance for standard peptides
             if (truePeptide.GlobalStandardType != null)
                 continue;
             var trueGroups = truePeptide.TransitionGroups.ToList();
             var pickedGroups = pickedPeptide.TransitionGroups.ToList();
             for (int k = 0; k < trueGroups.Count; k++)
             {
                 var trueGroup = trueGroups[k];
                 var pickedGroup = pickedGroups[k];
                 var trueResults = trueGroup.Results[i];
                 var pickedResults = pickedGroup.Results[i];
                 if (trueResults == null)
                     continue;
                 int nChromInfos = trueResults.Count;
                 for (int m = 0; m < nChromInfos; m++)
                 {
                     var trueInfo = trueResults[m];
                     var pickedInfo = pickedResults[m];
                     var fileInfo = set.GetFileInfo(trueInfo.FileId);
                     var filePath = fileInfo.FilePath;
                     var key = new MatchKey(trueGroup.Id.GlobalIndex, trueInfo.FileId.GlobalIndex);
                     matches.Add(new PeakBoundsMatch(trueInfo, pickedInfo, key, filePath, trueGroup,
                         HasNoQValues, HasNoScores, ApexPresent));
                 }
             }
         }
     }
     Matches = matches;
     // Detect if the apex time is in seconds, and if so adjust it to minutes
     if (ApexPresent)
     {
         double maxTime = matches.Where(match => match.PickedApex.HasValue)
                                 .Select(match => match.PickedApex.Value).Max();
         if (maxTime > PeakBoundaryImporter.GetMaxRt(DocOriginal))
         {
             foreach (var match in matches.Where(match => match.PickedApex.HasValue))
             {
                 match.PickedApex = match.PickedApex / 60;
             }
         }
     }
 }