Exemplo n.º 1
0
        /// <summary>
        /// Collects statistics on how much space savings minimizing will achieve, and (if outStream
        /// is not null) writes out the minimized cache file.
        /// </summary>
        public void Minimize(Settings settings, ProgressCallback progressCallback, Stream outStream,
                             FileStream outStreamScans = null, FileStream outStreamPeaks = null, FileStream outStreamScores = null)
        {
            var  writer = outStream == null ? null : new Writer(ChromatogramCache, outStream, outStreamScans, outStreamPeaks, outStreamScores);
            var  statisticsCollector = new MinStatisticsCollector(this);
            bool readChromatograms   = settings.NoiseTimeRange.HasValue || writer != null;

            var chromGroupHeaderToIndex =
                ChromGroupHeaderInfos
                .Select((cghi, index) => new KeyValuePair <ChromGroupHeaderInfo5, int>(cghi, index))
                .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            var chromGroups      = new ChromatogramGroupInfo[ChromGroupHeaderInfos.Count];
            var transitionGroups = new List <TransitionGroupDocNode> [ChromGroupHeaderInfos.Count];

            foreach (var nodePep in Document.Molecules)
            {
                foreach (var nodeGroup in nodePep.TransitionGroups)
                {
                    ChromatogramGroupInfo[] groupInfos;
                    ChromatogramCache.TryLoadChromatogramInfo(nodePep, nodeGroup, _tolerance, out groupInfos);
                    foreach (var chromGroupInfo in groupInfos)
                    {
                        int headerIndex = chromGroupHeaderToIndex[chromGroupInfo.Header];
                        if (chromGroups[headerIndex] == null)
                        {
                            chromGroups[headerIndex]      = chromGroupInfo;
                            transitionGroups[headerIndex] = new List <TransitionGroupDocNode>();
                        }
                        transitionGroups[headerIndex].Add(nodeGroup);
                    }
                }
            }

            for (int iHeader = 0; iHeader < ChromGroupHeaderInfos.Count; iHeader++)
            {
                var chromGroupInfo = chromGroups[iHeader];
                IList <TransitionGroupDocNode> transitionGroupDocNodes;
                if (chromGroupInfo == null)
                {
                    chromGroupInfo          = ChromatogramCache.LoadChromatogramInfo(ChromGroupHeaderInfos[iHeader]);
                    transitionGroupDocNodes = new TransitionGroupDocNode[0];
                }
                else
                {
                    transitionGroupDocNodes = transitionGroups[iHeader];
                }
                if (readChromatograms)
                {
                    try
                    {
                        chromGroupInfo.ReadChromatogram(ChromatogramCache);
                    }
                    catch (Exception exception)
                    {
                        Trace.TraceWarning("Unable to read chromatogram {0}", exception); // Not L10N
                    }
                }
                MinimizedChromGroup minimizedChromGroup = MinimizeChromGroup(settings,
                                                                             chromGroupInfo, transitionGroupDocNodes);
                statisticsCollector.ProcessChromGroup(minimizedChromGroup);
                if (progressCallback != null)
                {
                    progressCallback.Invoke(statisticsCollector.GetStatistics());
                }
                if (writer != null)
                {
                    writer.WriteChromGroup(chromGroupInfo, minimizedChromGroup);
                }
                // Null out the ChromGroup in our array so it can be garbage collected.
                chromGroups[iHeader] = null;
            }
            if (progressCallback != null)
            {
                progressCallback.Invoke(statisticsCollector.GetStatistics());
            }
            if (writer != null)
            {
                writer.WriteEndOfFile();
            }
        }