示例#1
0
        public MultiProgressStatus Add(ChromatogramLoadingStatus status)
        {
            var  uniqueList = new List <ChromatogramLoadingStatus>();
            bool added      = false;

            foreach (var loadingStatus in ProgressList)
            {
                if (loadingStatus.FilePath.Equals(status.FilePath))
                {
                    uniqueList.Add(status);
                    added = true;
                }
                else
                {
                    uniqueList.Add(loadingStatus);
                }
            }
            if (!added)
            {
                uniqueList.Add(status);
            }
            return(ChangeProp(ImClone(this), s =>
            {
                s.ProgressList = ImmutableList.ValueOf(uniqueList);
            }));
        }
示例#2
0
        private void Retry(ChromatogramLoadingStatus status)
        {
            ChromatogramManager.RemoveFile(status.FilePath);
            if (!_partialProgressList.Contains(status.FilePath))
            {
                _partialProgressList.Add(status.FilePath);
            }
            graphChromatograms.ClearGraph(status.FilePath);
            for (int i = 0; i < flowFileStatus.Controls.Count; i++)
            {
                var control = (FileProgressControl)flowFileStatus.Controls[i];
                if (control.FilePath.Equals(status.FilePath))
                {
                    control.Reset();
                    Selected = i;
                    break;
                }
            }

            // Add this file back into the chromatogram set for each of its replicates.
            ModifyDocument(Resources.AllChromatogramsGraph_Retry_Retry_import_results, monitor =>
            {
                Program.MainWindow.ModifyDocumentNoUndo(doc =>
                {
                    var oldResults = doc.Settings.MeasuredResults ??
                                     new MeasuredResults(new ChromatogramSet[0]);
                    var newResults = oldResults.AddDataFile(status.FilePath, status.ReplicateNames);
                    return(doc.ChangeMeasuredResults(newResults, monitor));
                });
            });
        }
示例#3
0
        private void RemoveFailedFile(ChromatogramLoadingStatus status)
        {
            // Remove this file from document.
            var canceledPath = status.FilePath;

            ModifyDocument(Resources.AllChromatogramsGraph_RemoveFailedFile_Remove_failed_file,
                           monitor => Program.MainWindow.ModifyDocumentNoUndo(
                               doc => FilterFiles(doc, info => !info.FilePath.Equals(canceledPath))));
        }
示例#4
0
        /// <summary>
        /// Display chromatogram data.
        /// </summary>
        /// <param name="status"></param>
        public void UpdateStatus(ChromatogramLoadingStatus status)
        {
            // Update progress bars and progress labels.
            var fileCount = Math.Max(1, status.SegmentCount - 1);

            // Update file label.
            if (status.Segment == status.SegmentCount - 1)
            {
                lblFileName.Visible     = false;
                progressBarFile.Visible = false;
                lblFileCount.Text       = Resources.AllChromatogramsGraph_UpdateStatus_Joining_chromatograms___;
            }
            else
            {
                progressBarFile.Value = status.ZoomedPercentComplete;

                // Clear graph when a new file starts loading.
                if (null != status.FilePath && _currentFilePath != status.FilePath)
                {
                    _currentFilePath = status.FilePath;
//                    LOG.Info("Showing " + _currentFilePath);    // Not L10N
                    lblFileName.Text = status.FilePath.GetFileName() + status.FilePath.GetSampleName();
                    asyncGraph.ClearGraph(status);
                }

                lblFileCount.Text = string.Format(Resources.AllChromatogramsGraph_UpdateStatus__0__of__1__files, status.Segment + 1, fileCount);
            }

            // Show multi-file progress bar if we have more than one file to import.
            if (fileCount != 1)
            {
                if (Visible && !panelMultifileProgress.Visible)
                {
                    panelMultifileProgress.Visible = true;
                    panelFileProgress.Top         -= _adjustLayoutForMultifile;
                    panelGraph.Height -= _adjustLayoutForMultifile;
                    // TODO: uncomment this when single file cancellation works
                    //btnCancelFile.Visible = true;
                }
                progressBarAllFiles.Value = status.PercentComplete;
            }

            // Show warning message if necessary.
            if (status.WarningMessage != null)
            {
                lblWarning.Text    = status.WarningMessage;
                lblWarning.Visible = true;
                asyncGraph.Height  = lblWarning.Top - 7;
            }
            else
            {
                lblWarning.Visible = false;
                asyncGraph.Height  = panelFileProgress.Top - 7;
            }

            lblDuration.Text = _stopwatch.Elapsed.ToString(@"hh\:mm\:ss"); // Not L10N
        }
示例#5
0
        /// <summary>
        /// Add the given files to the queue of files to load.
        /// </summary>
        public void Load(
            IList <DataFileReplicates> loadList,
            SrmDocument document,
            string documentFilePath,
            ChromatogramCache cacheRecalc,
            MultiFileLoadMonitor loadMonitor,
            Action <IList <FileLoadCompletionAccumulator.Completion> > complete)
        {
            lock (this)
            {
                // Find non-duplicate paths to load.
                var uniqueLoadList = new List <DataFileReplicates>();
                foreach (var loadItem in loadList)
                {
                    // Ignore a file that is already being loaded (or is queued for loading).
                    if (_loadingPaths.ContainsKey(loadItem.DataFile))
                    {
                        continue;
                    }
                    int idIndex = document.Id.GlobalIndex;
                    _loadingPaths.Add(loadItem.DataFile, idIndex);
                    uniqueLoadList.Add(loadItem);
                }

                if (uniqueLoadList.Count == 0)
                {
                    return;
                }

                int threadCount = GetOptimalThreadCount(_threadCountPreferred, uniqueLoadList.Count, _simultaneousFileOptions);
                _worker.RunAsync(threadCount, @"Load file");

                var accumulator = new FileLoadCompletionAccumulator(complete, threadCount, uniqueLoadList.Count);

                // Add new paths to queue.
                foreach (var loadItem in uniqueLoadList)
                {
                    var loadingStatus = new ChromatogramLoadingStatus(loadItem.DataFile, loadItem.ReplicateList);

                    ChangeStatus(s => s.Add(loadingStatus));

                    // Queue work item to load the file.
                    _worker.Add(new LoadInfo
                    {
                        Path             = loadItem.DataFile,
                        PartPath         = loadItem.PartPath,
                        Document         = document,
                        DocumentFilePath = documentFilePath,
                        CacheRecalc      = cacheRecalc,
                        Status           = loadingStatus,
                        LoadMonitor      = new SingleFileLoadMonitor(loadMonitor, loadItem.DataFile),
                        Complete         = accumulator.Complete
                    });
                }
            }
        }
示例#6
0
        /// <summary>
        /// Add the given file to the queue of files to load.
        /// </summary>
        public void Load(
            IList <DataFileReplicates> loadList,
            SrmDocument document,
            string documentFilePath,
            ChromatogramCache cacheRecalc,
            MultiFileLoadMonitor loadMonitor,
            Action <ChromatogramCache, IProgressStatus> complete)
        {
            // This may be called on multiple background loader threads simultaneously, but QueueWorker can handle it.
            _worker.RunAsync(_threadCount, "Load file"); // Not L10N

            lock (this)
            {
                // Find non-duplicate paths to load.
                var uniqueLoadList = new List <DataFileReplicates>();
                foreach (var loadItem in loadList)
                {
                    // Ignore a file that is already being loaded (or is queued for loading).
                    if (_loadingPaths.ContainsKey(loadItem.DataFile))
                    {
                        continue;
                    }
                    int idIndex = document.Id.GlobalIndex;
                    _loadingPaths.Add(loadItem.DataFile, idIndex);
                    uniqueLoadList.Add(loadItem);
                }

                if (uniqueLoadList.Count == 0)
                {
                    return;
                }

                // Add new paths to queue.
                foreach (var loadItem in uniqueLoadList)
                {
                    var loadingStatus = new ChromatogramLoadingStatus(loadItem.DataFile, loadItem.ReplicateList);

                    ChangeStatus(s => s.Add(loadingStatus));

                    // Queue work item to load the file.
                    _worker.Add(new LoadInfo
                    {
                        Path             = loadItem.DataFile,
                        PartPath         = loadItem.PartPath,
                        Document         = document,
                        DocumentFilePath = documentFilePath,
                        CacheRecalc      = cacheRecalc,
                        Status           = loadingStatus,
                        LoadMonitor      = new SingleFileLoadMonitor(loadMonitor, loadItem.DataFile),
                        Complete         = complete
                    });
                }
            }
        }
        private void ProcessBinSRM(
            List <ChromatogramLoadingStatus.TransitionData.Peak> bin,
            ref bool peaksAdded,
            ref float maxTime,
            ref float maxIntensity)
        {
            float retentionTime = bin[0].BinIndex * ChromatogramLoadingStatus.TIME_RESOLUTION;

            maxTime    = Math.Max(maxTime, retentionTime);
            peaksAdded = true;

            foreach (var peak in bin)
            {
                // New peptide curve.
                if (_lastCurve == null || !ReferenceEquals(peak.ModifiedSequence, _lastCurve.ModifiedSequence))
                {
                    _lastCurve = new CurveInfo(peak.ModifiedSequence, peak.Color, retentionTime, peak.Intensity);
                    _graphPane.CurveList.Add(_lastCurve.Curve);
                    maxIntensity = Math.Max(maxIntensity, peak.Intensity);
                    continue;
                }

                // Add intensity to existing peptide curve.
                for (int i = _lastCurve.Curve.NPts - 1; i >= 0; i--)
                {
                    int binIndex = ChromatogramLoadingStatus.GetBinIndex((float)_lastCurve.Curve.Points[i].X);
                    if (binIndex > peak.BinIndex)
                    {
                        if (i == 0)
                        {
                            _lastCurve.InsertAt(0, retentionTime, peak.Intensity);
                            _lastCurve.CheckZeroes(0);
                            maxIntensity = Math.Max(maxIntensity, peak.Intensity);
                        }
                    }
                    else if (binIndex == peak.BinIndex)
                    {
                        _lastCurve.Curve.Points[i].Y += peak.Intensity;
                        _lastCurve.CheckZeroes(i);
                        maxIntensity = Math.Max(maxIntensity, (float)_lastCurve.Curve.Points[i].Y);
                        break;
                    }
                    else
                    {
                        _lastCurve.InsertAt(i + 1, retentionTime, peak.Intensity);
                        _lastCurve.CheckZeroes(i + 1);
                        maxIntensity = Math.Max(maxIntensity, peak.Intensity);
                        break;
                    }
                }
            }
        }
        private void ProcessBinSRM(
            List <ChromatogramLoadingStatus.TransitionData.Peak> bin,
            GraphInfo info)
        {
            float retentionTime = bin[0].BinIndex * ChromatogramLoadingStatus.TIME_RESOLUTION;

            info.MaxX  = Math.Max(info.MaxX, retentionTime + ChromatogramLoadingStatus.TIME_RESOLUTION);
            _renderMin = Math.Min(_renderMin, retentionTime - ChromatogramLoadingStatus.TIME_RESOLUTION);
            _renderMax = Math.Max(_renderMax, retentionTime + ChromatogramLoadingStatus.TIME_RESOLUTION);

            foreach (var peak in bin)
            {
                float intensity = peak.Intensity;
                info.MaxY = Math.Max(info.MaxY, intensity);

                // New peptide curve.
                if (info.LastCurve == null || !ReferenceEquals(peak.ModifiedSequence, info.LastCurve.ModifiedSequence))
                {
                    info.LastCurve = new CurveInfo(peak.ModifiedSequence, peak.Color, retentionTime, intensity);
                    info.GraphPane.CurveList.Add(info.LastCurve.Curve);
                    continue;
                }

                // Add intensity to existing peptide curve.
                for (int i = info.LastCurve.Curve.NPts - 1; i >= 0; i--)
                {
                    int binIndex = ChromatogramLoadingStatus.GetBinIndex((float)info.LastCurve.Curve.Points[i].X);
                    if (binIndex > peak.BinIndex)
                    {
                        if (i == 0)
                        {
                            info.LastCurve.InsertAt(0, retentionTime, intensity);
                            info.LastCurve.CheckZeroes(0);
                        }
                    }
                    else if (binIndex == peak.BinIndex)
                    {
                        info.LastCurve.Curve.Points[i].Y += intensity;
                        info.MaxY = Math.Max(info.MaxY, (float)info.LastCurve.Curve.Points[i].Y);
                        info.LastCurve.CheckZeroes(i);
                        break;
                    }
                    else
                    {
                        info.LastCurve.InsertAt(i + 1, retentionTime, intensity);
                        info.LastCurve.CheckZeroes(i + 1);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Update status (main thread).
        /// </summary>
        public void UpdateStatus(ChromatogramLoadingStatus status)
        {
            if (!_backgroundInitialized)
            {
                _backgroundInitialized = true;
                BackgroundInitialize();
            }

            // Create info for new file.
            var key  = status.FilePath.GetFilePath();
            var info = GetInfo(key);

            if (info == null)
            {
                info = _graphs[key] = new GraphInfo
                {
                    GraphPane    = _templatePane.Clone(),
                    ActiveCurves = new List <CurveInfo>()
                };
                info.GraphPane.Title.Text = status.FilePath.GetFileNameWithoutExtension();
            }

            // Create curve information from the transition data.
            List <ChromatogramLoadingStatus.TransitionData.Peak> bin;

            while (status.Transitions.BinnedPeaks.TryDequeue(out bin))
            {
                if (status.Transitions.Progressive)
                {
                    ProcessBinProgressive(bin, info);
                }
                else
                {
                    ProcessBinSRM(bin, info);
                }
            }

            if (status.Transitions.Progressive)
            {
                info.CurrentTime = status.Transitions.CurrentTime;
                info.MaxX        = Math.Max(info.MaxX, status.Transitions.MaxRetentionTime);
            }
            else
            {
                info.CurrentTime = null;
            }
            status.Transitions.MaxIntensity = info.MaxY;
        }
示例#10
0
        public MultiProgressStatus ChangeStatus(ChromatogramLoadingStatus status)
        {
            var progressList = new List <ChromatogramLoadingStatus>(ProgressList.Count);

            foreach (var progressStatus in ProgressList)
            {
                if (!ReferenceEquals(status.Id, progressStatus.Id))
                {
                    progressList.Add(progressStatus);
                }
                // Avoid overwriting a final status with a non-final status
                else if (status.IsFinal || !progressStatus.IsFinal)
                {
                    progressList.Add(status);
                }
                else
                {
                    return(this);    // The list already contains a progress value that is final
                }
            }
            return(ChangeProp(ImClone(this), s => s.ProgressList = ImmutableList.ValueOf(progressList)));
        }
示例#11
0
 public MultiProgressStatus ChangeStatus(ChromatogramLoadingStatus loadingStatus)
 {
     return(ChangeStatus(s => s.ChangeStatus(loadingStatus)));
 }
示例#12
0
 public void SetStatus(ChromatogramLoadingStatus status)
 {
     Status     = status;
     IsCanceled = false;
     try
     {
         if (status.IsError)
         {
             if (Error == null)
             {
                 Error = string.Format(Resources.FileProgressControl_SetStatus_, DateTime.Now.ToShortTimeString(),
                                       ExceptionUtil.GetMessage(status.ErrorException));
                 _errorCount++;
                 if (_errorLog.Count == 3)
                 {
                     _errorLog.RemoveAt(2);
                     _errorExceptions.RemoveAt(2);
                 }
                 _errorLog.Insert(0, Error);
                 _errorExceptions.Insert(0, ExceptionUtil.GetStackTraceText(status.ErrorException, null, false));
                 btnRetry.Text    = Resources.FileProgressControl_SetStatus_Retry;
                 btnRetry.Visible = true;
                 ShowWarningIcon(Resources.FileProgressControl_SetStatus_failed);
             }
         }
         else
         {
             if (!string.IsNullOrEmpty(status.WarningMessage))
             {
                 Warning = status.WarningMessage;
                 ShowWarningIcon(Resources.FileProgressControl_SetStatus_warning);
             }
             if (status.IsCanceled)
             {
                 IsCanceled           = true;
                 progressBar.Visible  = false;
                 labelPercent.Visible = false;
                 labelStatus.Text     = Resources.FileProgressControl_SetStatus_canceled;
                 labelStatus.Visible  = true;
                 btnRetry.Text        = Resources.FileProgressControl_SetStatus_Retry;
                 btnRetry.Visible     = true;
                 _backColor           = _cancelColor;
             }
             else if (status.IsComplete)
             {
                 Finish();
             }
             else if (status.PercentComplete > 0)
             {
                 progressBar.Visible  = true;
                 labelPercent.Visible = true;
                 progressBar.Value    = status.PercentComplete;
                 labelPercent.Text    = (status.PercentComplete / 100.0).ToString("P0"); // Not L10N
                 labelStatus.Visible  = false;
                 btnRetry.Text        = Resources.FileProgressControl_SetStatus_Cancel;
                 btnRetry.Visible     = true;
                 _backColor           = _okColor;
             }
         }
         Invalidate();
     }
     catch
     {
         // ignored
     }
 }
 /// <summary>
 /// Clear the graph and track new status object.
 /// </summary>
 /// <param name="status"></param>
 public void ClearGraph(ChromatogramLoadingStatus status)
 {
     _newStatus = status;
 }
        /// <summary>
        /// Render the graph on the background thread.
        /// </summary>
        /// <param name="bitmap">Destination bitmap.</param>
        /// <param name="fullFrame">True to force full frame rendering.</param>
        protected override Rectangle Render(Bitmap bitmap, bool fullFrame)
        {
            _fullFrame = fullFrame;

            var newStatus = Interlocked.Exchange(ref _newStatus, null);

            if (newStatus != null)
            {
                _status = newStatus;
                ResetGraph();
            }

            if (_status == null)
            {
                return(Rectangle.Empty);
            }

            // We need to process data even if the control isn't visible to reduce
            // the memory load of raw chromatogram data.
            bool   newPeaks    = false;
            double time        = _lastTime;
            bool   progressive = false;

            if (_status.Transitions != null)
            {
                progressive = _status.Transitions.Progressive;
                time        = _status.Transitions.CurrentTime;
                newPeaks    = AddData(_status.Transitions);
            }

            if (!IsVisible)
            {
                return(Rectangle.Empty);
            }

            Rectangle invalidRect;

            if (_fullFrame || _xAxisAnimation != null || _yAxisAnimation != null || (newPeaks && !progressive) || time < _lastTime)
            {
                // full frame invalidation
                invalidRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            }
            else if (newPeaks || time > _lastTime)
            {
                var p1     = _graphPane.GeneralTransform(_lastTime, 0, CoordType.AxisXYScale);
                var p2     = _graphPane.GeneralTransform(time, 0, CoordType.AxisXYScale);
                int x      = (int)p1.X - 1;
                int y      = 0;
                int width  = (int)(p2.X + PROGRESS_LINE_WIDTH) - x;
                int height = (int)p1.Y + 2;
                invalidRect = new Rectangle(x, y, width, height);
            }
            else
            {
                invalidRect = Rectangle.Empty;
            }

            // Animate changing axis scales.
            Animate();

            // For progressive import, update the progress line.
            if (progressive)
            {
                _lastTime = time;
                UpdateProgressLine(time);
                if (_unfinishedBox == null)
                {
                    invalidRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                }
            }

            // Render a new bitmap if something has changed.
            if (invalidRect.Width > 0 && _status.Transitions != null &&
                (_status.Transitions.CurrentTime > 0 || _status.Transitions.MaxRetentionTime > 0))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.SetClip(invalidRect);
                    _graphPane.ReSize(graphics, new RectangleF(0, 0, bitmap.Width, bitmap.Height));
                    _graphPane.Draw(graphics);
                }
            }

            return(invalidRect);
        }