Exemplo n.º 1
0
 private void AddChromInfo(ChromInfoList <TransitionGroupChromInfo> chromGroupInfos, ChromInfoList <TransitionChromInfo> chromInfos,
                           Dictionary <int, int> dictPpmBin2ToCount, List <double> vals)
 {
     if (chromInfos.IsEmpty || chromGroupInfos.IsEmpty)
     {
         return;
     }
     foreach (var chromInfo in chromInfos)
     {
         if (_transition == TransitionMassError.best && chromInfo.RankByLevel != 1)
         {
             continue;
         }
         if (_pointsType == PointsTypeMassError.targets_1FDR && chromInfo.GetMatchingQValue(chromGroupInfos) > 0.01)
         {
             continue;
         }
         var massError = chromInfo.MassError;
         if (massError.HasValue)
         {
             vals.Add((float)massError);
             var ppmBin2 = (int)Math.Floor(massError.Value / _binSize);
             if (dictPpmBin2ToCount.ContainsKey(ppmBin2))
             {
                 dictPpmBin2ToCount[ppmBin2]++;
             }
             else
             {
                 dictPpmBin2ToCount.Add(ppmBin2, 1);
             }
         }
     }
 }
Exemplo n.º 2
0
        private Results <TransitionChromInfo> MergeResultsUserInfo(
            SrmSettings settings, Results <TransitionChromInfo> results)
        {
            if (!HasResults)
            {
                return(Results);
            }

            var dictFileIdToChromInfo = results.SelectMany(l => l)
                                        // Merge everything that does not already exist (handled below),
                                        // as merging only user modified causes loss of information in
                                        // updates
                                        //.Where(i => i.IsUserModified)
                                        .ToDictionary(i => i.FileIndex);

            var listResults = new List <ChromInfoList <TransitionChromInfo> >();

            for (int i = 0; i < results.Count; i++)
            {
                List <TransitionChromInfo> listChromInfo = null;
                var chromSet      = settings.MeasuredResults.Chromatograms[i];
                var chromInfoList = Results[i];
                foreach (var fileInfo in chromSet.MSDataFileInfos)
                {
                    TransitionChromInfo chromInfo;
                    if (!dictFileIdToChromInfo.TryGetValue(fileInfo.FileIndex, out chromInfo))
                    {
                        continue;
                    }
                    if (listChromInfo == null)
                    {
                        listChromInfo = new List <TransitionChromInfo>(chromInfoList);
                    }
                    int iExist = listChromInfo.IndexOf(chromInfoExist =>
                                                       ReferenceEquals(chromInfoExist.FileId, chromInfo.FileId) &&
                                                       chromInfoExist.OptimizationStep == chromInfo.OptimizationStep);
                    if (iExist == -1)
                    {
                        listChromInfo.Add(chromInfo);
                    }
                    else if (chromInfo.IsUserModified)
                    {
                        listChromInfo[iExist] = chromInfo;
                    }
                }
                if (listChromInfo != null)
                {
                    chromInfoList = new ChromInfoList <TransitionChromInfo>(listChromInfo);
                }
                listResults.Add(chromInfoList);
            }
            if (ArrayUtil.InnerReferencesEqual <TransitionChromInfo, ChromInfoList <TransitionChromInfo> >(listResults, Results))
            {
                return(Results);
            }
            return(new Results <TransitionChromInfo>(listResults));
        }
Exemplo n.º 3
0
 private void AddChromInfo(ChromInfoList <TransitionGroupChromInfo> chromGroupInfos, ChromInfoList <TransitionChromInfo> chromInfos,
                           double mz, int[,] counts2D)
 {
     if (chromInfos.IsEmpty)
     {
         return;
     }
     foreach (var chromInfo in chromInfos)
     {
         if (_transition == TransitionMassError.best && chromInfo.RankByLevel != 1)
         {
             continue;
         }
         if (_pointsType == PointsTypeMassError.targets_1FDR && chromInfo.GetMatchingQValue(chromGroupInfos) > 0.01)
         {
             continue;
         }
         var massError = chromInfo.MassError;
         if (massError.HasValue)
         {
             var xVal = _xAxis == Histogram2DXAxis.mass_to_charge ? mz : chromInfo.RetentionTime;
             if (ReferenceEquals(counts2D, EMPTY_COUNTS))
             {
                 _maxMass = Math.Max(_maxMass, massError.Value);
                 _minMass = Math.Min(_minMass, massError.Value);
                 _maxX    = Math.Max(_maxX, xVal);
                 _minX    = Math.Min(_minX, xVal);
             }
             else
             {
                 int x = (int)Math.Floor((xVal - _minX) / ((_maxX - _minX) / xAxisBins));
                 int y = (int)Math.Floor((massError.Value - _minMass) / _binSizePpm);
                 counts2D[Math.Min(x, counts2D.GetLength(0) - 1), Math.Min(y, counts2D.GetLength(1) - 1)]++;
             }
         }
     }
 }
Exemplo n.º 4
0
 private IDictionary <MsDataFileUri, TransitionChromInfo> ToDict(SrmDocument doc, ChromInfoList <TransitionChromInfo> chromInfoList)
 {
     return(chromInfoList.ToDictionary(c =>
                                       doc.MeasuredResults.MSDataFileInfos.First(fi => ReferenceEquals(fi.FileId, c.FileId)).FilePath));
 }
Exemplo n.º 5
0
 private double GetHeight(ChromInfoList <TransitionGroupChromInfo> transitionGroupChromInfos)
 {
     return(!transitionGroupChromInfos.IsEmpty ? transitionGroupChromInfos.Max(c => c.Height ?? 0) : 0);
 }
Exemplo n.º 6
0
            public SrmDocument AddAnnotationTestValues(SrmDocument document)
            {
                _counter      = 0;
                _elementCount = 0;
                document      = document.ChangeSettings(document.Settings.ChangeDataSettings(
                                                            document.Settings.DataSettings.ChangeAnnotationDefs(ImmutableList.ValueOf(GetTestAnnotations()))));
                var measuredResults = document.MeasuredResults;

                if (measuredResults != null)
                {
                    var chromatograms = measuredResults.Chromatograms.ToArray();
                    for (int i = 0; i < chromatograms.Length; i++)
                    {
                        _elementCount++;
                        chromatograms[i] = chromatograms[i].ChangeAnnotations(
                            AddAnnotations(chromatograms[i].Annotations, AnnotationDef.AnnotationTarget.replicate));
                    }
                    document = document.ChangeMeasuredResults(measuredResults.ChangeChromatograms(chromatograms));
                }
                var proteins = document.MoleculeGroups.ToArray();

                for (int iProtein = 0; iProtein < proteins.Length; iProtein++)
                {
                    var protein = proteins[iProtein];
                    _elementCount++;
                    protein = (PeptideGroupDocNode)protein.ChangeAnnotations(AddAnnotations(protein.Annotations,
                                                                                            AnnotationDef.AnnotationTarget.protein));
                    var peptides = protein.Molecules.ToArray();
                    for (int iPeptide = 0; iPeptide < peptides.Length; iPeptide++)
                    {
                        var peptide = peptides[iPeptide];
                        _elementCount++;
                        peptide = (PeptideDocNode)peptide.ChangeAnnotations(AddAnnotations(peptide.Annotations,
                                                                                           AnnotationDef.AnnotationTarget.peptide));
                        var precursors = peptide.TransitionGroups.ToArray();
                        for (int iPrecursor = 0; iPrecursor < precursors.Length; iPrecursor++)
                        {
                            var precursor = precursors[iPrecursor];
                            precursor = (TransitionGroupDocNode)precursor.ChangeAnnotations(
                                AddAnnotations(precursor.Annotations,
                                               AnnotationDef.AnnotationTarget.precursor));
                            _elementCount++;
                            var transitions = precursor.Transitions.ToArray();
                            for (int iTransition = 0; iTransition < transitions.Length; iTransition++)
                            {
                                var transition = transitions[iTransition];
                                _elementCount++;
                                transition = (TransitionDocNode)transition.ChangeAnnotations(
                                    AddAnnotations(transition.Annotations,
                                                   AnnotationDef.AnnotationTarget.transition));
                                if (transition.Results != null)
                                {
                                    var results = transition.Results.ToArray();
                                    for (int replicateIndex = 0; replicateIndex < results.Length; replicateIndex++)
                                    {
                                        _elementCount          += results[replicateIndex].Count;
                                        results[replicateIndex] = new ChromInfoList <TransitionChromInfo>(
                                            results[replicateIndex]
                                            .Select(chromInfo => chromInfo.ChangeAnnotations(AddAnnotations(
                                                                                                 chromInfo.Annotations,
                                                                                                 AnnotationDef.AnnotationTarget.transition_result))));
                                    }
                                    transition = transition.ChangeResults(new Results <TransitionChromInfo>(results));
                                }
                                transitions[iTransition] = transition;
                            }
                            if (precursor.Results != null)
                            {
                                var results = precursor.Results.ToArray();
                                for (int replicateIndex = 0; replicateIndex < results.Length; replicateIndex++)
                                {
                                    _elementCount          += results[replicateIndex].Count;
                                    results[replicateIndex] = new ChromInfoList <TransitionGroupChromInfo>(
                                        results[replicateIndex].Select(chromInfo =>
                                                                       chromInfo.ChangeAnnotations(AddAnnotations(chromInfo.Annotations,
                                                                                                                  AnnotationDef.AnnotationTarget.precursor_result))));
                                }
                                precursor = precursor.ChangeResults(new Results <TransitionGroupChromInfo>(results));
                            }
                            precursor = (TransitionGroupDocNode)precursor.ChangeChildren(transitions);
                            precursors[iPrecursor] = precursor;
                        }
                        peptide            = (PeptideDocNode)peptide.ChangeChildren(precursors);
                        peptides[iPeptide] = peptide;
                    }
                    protein            = (PeptideGroupDocNode)protein.ChangeChildren(peptides);
                    proteins[iProtein] = protein;
                }
                return((SrmDocument)document.ChangeChildren(proteins));
            }
Exemplo n.º 7
0
 private double GetHeight(ChromInfoList<TransitionGroupChromInfo> transitionGroupChromInfos)
 {
     return transitionGroupChromInfos != null ? transitionGroupChromInfos.Max(c => c.Height ?? 0) : 0;
 }
Exemplo n.º 8
0
        private int IndexOfChromInfo <TDocNode, TChromInfo>(ChromatogramSet chromatogramSet,
                                                            ResultRef <TDocNode, TChromInfo> resultRef, ChromInfoList <TChromInfo> chromInfoList)
            where TDocNode : DocNode where TChromInfo : ChromInfo
        {
            var chromFileInfo = resultRef.FindChromFileInfo(chromatogramSet);

            for (int i = 0; i < chromInfoList.Count; i++)
            {
                var chromInfo = chromInfoList[i];
                if (!ReferenceEquals(chromInfo.FileId, chromFileInfo.Id))
                {
                    continue;
                }
                if (resultRef.GetOptimizationStep(chromInfo) != resultRef.OptimizationStep)
                {
                    continue;
                }
                return(i);
            }
            return(-1);
        }
Exemplo n.º 9
0
        private ChromInfoList <TChromInfo> SetChromInfoAnnotations <TDocNode, TChromInfo>(ChromatogramSet chromatogramSet,
                                                                                          ResultRef <TDocNode, TChromInfo> resultRef, ChromInfoList <TChromInfo> chromInfoList,
                                                                                          Annotations annotations) where TDocNode : DocNode where TChromInfo : ChromInfo
        {
            int i = IndexOfChromInfo(chromatogramSet, resultRef, chromInfoList);

            if (i < 0)
            {
                throw ElementNotFoundException(resultRef);
            }
            var newChromInfoList = chromInfoList.ToArray();

            newChromInfoList[i] = resultRef.ChangeAnnotations(newChromInfoList[i], annotations);
            return(new ChromInfoList <TChromInfo>(newChromInfoList));
        }