Exemplo n.º 1
0
        public override bool GetChromatogram(
            int id,
            Target modifiedSequence,
            Color peptideColor,
            out ChromExtra extra,
            out TimeIntensities timeIntensities)
        {
            bool loaded = false;

            extra           = null;
            timeIntensities = null;
            int idRemain = id;

            for (int iTaskList = 0; iTaskList < _chromatogramRequestProviders.Length; iTaskList++)
            {
                ChromatogramRequestProvider requestProvider = _chromatogramRequestProviders[iTaskList];
                if (requestProvider.ChromKeys.Count <= idRemain)
                {
                    idRemain -= requestProvider.ChromKeys.Count;
                    continue;
                }
                ChromTaskList chromTaskList = _chromTaskLists[iTaskList];
                if (null == chromTaskList)
                {
                    chromTaskList = _chromTaskLists[iTaskList] = new ChromTaskList(CheckCancelled, _document, _chorusAccount, requestProvider.ChorusUrl, ChromTaskList.ChunkChromatogramRequest(requestProvider.GetChromatogramRequest(), 1000));
                    chromTaskList.SetMinimumSimultaneousTasks(3);
                }
                ChromKey chromKey = requestProvider.ChromKeys[idRemain];
                loaded = chromTaskList.GetChromatogram(chromKey, out timeIntensities);
                if (loaded)
                {
                    extra = new ChromExtra(id, chromKey.Precursor == 0 ? 0 : -1);
                    if (chromKey.Precursor.IsNegative)
                    {
                        _sourceHasNegativePolarityData = true;
                    }
                    else
                    {
                        _sourceHasPositivePolarityData = true;
                    }
                    if (timeIntensities.NumPoints > 0 && Status is ChromatogramLoadingStatus)
                    {
                        ((ChromatogramLoadingStatus)Status).Transitions.AddTransition(
                            modifiedSequence,
                            peptideColor,
                            extra.StatusId,
                            extra.StatusRank,
                            timeIntensities.Times,
                            timeIntensities.Intensities);
                    }
                }
                break;
            }
            int percentComplete = _chromTaskLists.Sum(taskList => taskList == null ? 0 : taskList.PercentComplete) /
                                  _chromTaskLists.Length;

            percentComplete = Math.Min(percentComplete, 99);
            SetPercentComplete(percentComplete);
            return(loaded);
        }
Exemplo n.º 2
0
        public static IPeakFinder CreatePeakFinder(TimeIntensities interpolatedTimeIntensities)
        {
            var peakFinder = PeakFinders.NewDefaultPeakFinder();

            peakFinder.SetChromatogram(interpolatedTimeIntensities.Times, interpolatedTimeIntensities.Intensities);
            return(peakFinder);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get a chromatogram with properly sorted time values.
        /// </summary>
        public void ReleaseChromatogram(byte[] bytesFromDisk, out TimeIntensities timeIntensities)
        {
            var times       = Times.ToArray(bytesFromDisk);
            var intensities = Intensities.ToArray(bytesFromDisk);
            var massErrors  = MassErrors != null
                ? MassErrors.ToArray(bytesFromDisk)
                : null;

            var scanIds = Scans != null
                ? Scans.ToArray(bytesFromDisk)
                : null;

            // Make sure times and intensities match in length.
            if (times.Length != intensities.Length)
            {
                throw new InvalidDataException(
                          string.Format(Resources.ChromCollected_ChromCollected_Times__0__and_intensities__1__disagree_in_point_count,
                                        times.Length, intensities.Length));
            }
            if (massErrors != null && massErrors.Length != intensities.Length)
            {
                throw new InvalidDataException(
                          string.Format(Resources.ChromCollector_ReleaseChromatogram_Intensities___0___and_mass_errors___1___disagree_in_point_count_,
                                        intensities.Length, massErrors.Length));
            }
            timeIntensities = new TimeIntensities(times, intensities, massErrors, scanIds);
            // Release memory.
            Times       = null;
            Intensities = null;
            MassErrors  = null;
            Scans       = null;
        }
Exemplo n.º 4
0
        public override bool GetChromatogram(int id, Target modifiedSequence, Color color, out ChromExtra extra, out TimeIntensities timeIntensities)
        {
            // No mass errors in SRM
            if (_readChromatograms == 0)
            {
                _readStartTime = DateTime.UtcNow; // Said to be 117x faster than Now and this is for a delta
            }

            float[] times, intensities;
            if (!_globalChromatogramExtractor.GetChromatogram(id, out times, out intensities))
            {
                _dataFile.GetChromatogram(id, out string chromId, out times, out intensities);
            }

            timeIntensities = new TimeIntensities(times, intensities, null, null);

            // Assume that each chromatogram will be read once, though this may
            // not always be completely true.
            _readChromatograms++;

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                double predictedMinutes = ExpectedReadDurationMinutes;
                if (_readMaxMinutes > 0 && predictedMinutes > _readMaxMinutes)
                {
                    // TODO: This warning isn't checked in the command line version of Skyline.  Maybe we should do that.
                    if (Status is ChromatogramLoadingStatus)
                    {
                        Status =
                            ((ChromatogramLoadingStatus)Status).ChangeWarningMessage(Resources.ChromatogramDataProvider_GetChromatogram_This_import_appears_to_be_taking_longer_than_expected__If_importing_from_a_network_drive__consider_canceling_this_import__copying_to_local_disk_and_retrying_);
                    }
                }
            }

            if (_readChromatograms < _chromIds.Count)
            {
                SetPercentComplete(50 + _readChromatograms * 50 / _chromIds.Count);
            }

            int index = _chromIndices[id];

            extra = new ChromExtra(index, -1);  // TODO: is zero the right value?

            // Display in AllChromatogramsGraph
            var loadingStatus = Status as ChromatogramLoadingStatus;

            if (loadingStatus != null)
            {
                loadingStatus.Transitions.AddTransition(
                    modifiedSequence,
                    color,
                    index, -1,
                    times,
                    intensities);
            }
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Release a chromatogram if its collector is complete (indicated by retention time).
        /// </summary>
        /// <returns>-1 if chromatogram is not finished yet.</returns>
        public int ReleaseChromatogram(
            int chromatogramIndex, float retentionTime, ChromCollector collector,
            out TimeIntensities timeIntensities)
        {
            int groupIndex = GetGroupIndex(chromatogramIndex);
            var spillFile  = _spillFiles[groupIndex];

            // Not done reading yet.
            if (retentionTime < spillFile.MaxTime || (collector != null && !collector.IsSetTimes))
            {
                timeIntensities = null;
                return(-1);
            }

            // No chromatogram information collected.
            if (collector == null)
            {
                timeIntensities = TimeIntensities.EMPTY;
                return(0);
            }

            if (ReferenceEquals(_cachedSpillFile, spillFile))
            {
                if (spillFile.Stream != null)
                {
                    if (_bytesFromSpillFile == null || spillFile.Stream.Length != _bytesFromSpillFile.Length)
                    {
                        // Need to reread spill file if more bytes were written since the time it was cached.
                        _cachedSpillFile = null;
                    }
                }
            }

            if (!ReferenceEquals(_cachedSpillFile, spillFile))
            {
                _cachedSpillFile    = spillFile;
                _bytesFromSpillFile = null;
                var fileStream = spillFile.Stream;
                if (fileStream != null)
                {
                    fileStream.Seek(0, SeekOrigin.Begin);
                    _bytesFromSpillFile = new byte[fileStream.Length];
                    int bytesRead = fileStream.Read(_bytesFromSpillFile, 0, _bytesFromSpillFile.Length);
                    Assume.IsTrue(bytesRead == _bytesFromSpillFile.Length);
                    // TODO: Would be nice to have something that releases spill files progressively, as they are
                    //       no longer needed.
                    // spillFile.CloseStream();
                }
            }
            collector.ReleaseChromatogram(_bytesFromSpillFile, out timeIntensities);

            return(collector.StatusId);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the intensities from the other TimeIntensities to the intensities in this.
        /// The returned TimeIntensities whill have a set of times which is the union of the
        /// times in this and <paramref name="other"/>.
        /// </summary>
        public TimeIntensities MergeTimesAndAddIntensities(TimeIntensities other)
        {
            if (Times.Equals(other.Times))
            {
                return(AddIntensities(other));
            }
            var mergedTimes = ImmutableList.ValueOf(Times.Concat(other.Times).Distinct().OrderBy(time => time));

            if (mergedTimes.Equals(Times))
            {
                return(AddIntensities(other));
            }
            return(Interpolate(mergedTimes, false).AddIntensities(other));
        }
Exemplo n.º 7
0
        public static RawTimeIntensities FromChromatogramGroupData(ChromatogramGroupData chromatogramGroupData)
        {
            var timeIntensitiesList = new List <TimeIntensities>();
            var timeLists           = chromatogramGroupData.TimeLists.Select(timeList => ImmutableList.ValueOf(timeList.Times)).ToArray();
            var scanIdLists         = chromatogramGroupData.ScanIdLists
                                      .Select(scanIdList => ImmutableList.ValueOf(scanIdList.ScanIds)).ToArray();

            foreach (var chromatogram in chromatogramGroupData.Chromatograms)
            {
                IEnumerable <float> massErrors = null;
                if (chromatogram.MassErrors100X.Count > 0)
                {
                    massErrors = chromatogram.MassErrors100X.Select(error => error / 100.0f);
                }
                else if (chromatogram.MassErrorsDeprecated.Count > 0)
                {
                    massErrors = chromatogram.MassErrorsDeprecated;
                }
                var timeIntensities = new TimeIntensities(timeLists[chromatogram.TimeListIndex - 1],
                                                          chromatogram.Intensities,
                                                          massErrors,
                                                          chromatogram.ScanIdListIndex == 0 ? null : scanIdLists[chromatogram.ScanIdListIndex - 1]);
                timeIntensitiesList.Add(timeIntensities);
            }
            InterpolationParams interpolationParams;

            if (chromatogramGroupData.InterpolatedNumPoints == 0)
            {
                interpolationParams = null;
            }
            else
            {
                interpolationParams = new InterpolationParams(chromatogramGroupData.InterpolatedStartTime, chromatogramGroupData.InterpolatedEndTime, chromatogramGroupData.InterpolatedNumPoints, chromatogramGroupData.InterpolatedDelta)
                                      .ChangeInferZeroes(chromatogramGroupData.InferZeroes);
            }
            var rawTimeIntensities = new RawTimeIntensities(timeIntensitiesList, interpolationParams);

            if (chromatogramGroupData.TimeIntervals != null)
            {
                var startTimes = chromatogramGroupData.TimeIntervals.StartTimes;
                var endTimes   = chromatogramGroupData.TimeIntervals.EndTimes;

                var timeIntervals = TimeIntervals.FromIntervals(Enumerable.Range(0, startTimes.Count)
                                                                .Select(i => new KeyValuePair <float, float>(startTimes[i], endTimes[i])));
                rawTimeIntensities = rawTimeIntensities.ChangeTimeIntervals(timeIntervals);
            }

            return(rawTimeIntensities);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Adds the intensities from the other TimeIntensities to the intensities in this.
 /// The returned TimeIntensities will have the same set of times as this.
 /// </summary>
 public TimeIntensities AddIntensities(TimeIntensities other)
 {
     if (!Times.Equals(other.Times))
     {
         other = other.Interpolate(Times, false);
     }
     float[] newIntensities = new float[Times.Count];
     for (int i = 0; i < Times.Count; i++)
     {
         // Avoid arithmetic overflow
         double intensitySum = Intensities[i] + other.Intensities[i];
         newIntensities[i] = intensitySum < float.MaxValue ? (float)intensitySum : float.MaxValue;
     }
     return(new TimeIntensities(Times, newIntensities, null, null));
 }
Exemplo n.º 9
0
        public static InterpolatedTimeIntensities ReadFromStream(Stream stream, ChromGroupHeaderInfo chromGroupHeaderInfo, ChromTransition[] chromTransitions)
        {
            Dictionary <ChromSource, int[]> scanIds = new Dictionary <ChromSource, int[]>();
            int numTrans = chromTransitions.Length;

            Assume.IsTrue(numTrans == chromGroupHeaderInfo.NumTransitions);
            int numPoints             = chromGroupHeaderInfo.NumPoints;
            var sharedTimes           = PrimitiveArrays.Read <float>(stream, numPoints);
            var transitionIntensities = new IList <float> [numTrans];

            for (int i = 0; i < numTrans; i++)
            {
                transitionIntensities[i] = PrimitiveArrays.Read <float>(stream, numPoints);
            }
            IList <float>[] transitionMassErrors = new IList <float> [numTrans];
            if (chromGroupHeaderInfo.HasMassErrors)
            {
                for (int i = 0; i < numTrans; i++)
                {
                    transitionMassErrors[i] = ReadMassErrors(stream, numPoints);
                }
            }
            if (chromGroupHeaderInfo.HasFragmentScanIds)
            {
                scanIds.Add(ChromSource.fragment, PrimitiveArrays.Read <int>(stream, numPoints));
            }
            if (chromGroupHeaderInfo.HasSimScanIds)
            {
                scanIds.Add(ChromSource.sim, PrimitiveArrays.Read <int>(stream, numPoints));
            }
            if (chromGroupHeaderInfo.HasMs1ScanIds)
            {
                scanIds.Add(ChromSource.ms1, PrimitiveArrays.Read <int>(stream, numPoints));
            }
            List <TimeIntensities> listOfTimeIntensities = new List <TimeIntensities>();

            for (int i = 0; i < numTrans; i++)
            {
                var   chromSource = chromTransitions[i].Source;
                int[] transitionScanIds;
                scanIds.TryGetValue(chromSource, out transitionScanIds);

                var timeIntensities = new TimeIntensities(sharedTimes, transitionIntensities[i], transitionMassErrors[i], transitionScanIds);
                listOfTimeIntensities.Add(timeIntensities);
            }
            return(new InterpolatedTimeIntensities(listOfTimeIntensities, chromTransitions.Select(chromTransition => chromTransition.Source)));
        }
Exemplo n.º 10
0
        public override bool GetChromatogram(int id, Target modifiedSequence, Color color, out ChromExtra extra, out TimeIntensities timeIntensities)
        {
            float[] times, intensities;
            if (!_globalChromatogramExtractor.GetChromatogram(id, out times, out intensities))
            {
                _dataFile.GetChromatogram(id, out _, out times, out intensities);
            }

            timeIntensities = new TimeIntensities(times, intensities, null, null);

            // Assume that each chromatogram will be read once, though this may
            // not always be completely true.
            _readChromatograms++;

            if (_readChromatograms < _chromIds.Count)
            {
                SetPercentComplete(50 + _readChromatograms * 50 / _chromIds.Count);
            }

            int index = _chromIndices[id];

            extra = new ChromExtra(index, -1);  // TODO: is zero the right value?

            // Display in AllChromatogramsGraph
            var loadingStatus = Status as ChromatogramLoadingStatus;

            if (loadingStatus != null)
            {
                loadingStatus.Transitions.AddTransition(
                    modifiedSequence,
                    color,
                    index, -1,
                    times,
                    intensities);
            }
            return(true);
        }
Exemplo n.º 11
0
 public override bool GetChromatogram(int id, Target modifiedSequence, Color peptideColor, out ChromExtra extra, out TimeIntensities timeIntensities)
 {
     return(_cachedChromatogramDataProvider.GetChromatogram(
                id, modifiedSequence, peptideColor,
                out extra, out timeIntensities));
 }
Exemplo n.º 12
0
        public override bool GetChromatogram(int id, Target modifiedSequence, Color peptideColor, out ChromExtra extra, out TimeIntensities timeIntensities)
        {
            var chromKeyIndices = _chromKeyIndices[id];

            if (_lastChromGroupInfo == null || _lastIndices.GroupIndex != chromKeyIndices.GroupIndex)
            {
                _lastChromGroupInfo = _cache.LoadChromatogramInfo(chromKeyIndices.GroupIndex);
                _lastChromGroupInfo.ReadChromatogram(_cache);
            }
            _lastIndices = chromKeyIndices;
            var tranInfo = _lastChromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex);

            timeIntensities = tranInfo.TimeIntensities;

            // Assume that each chromatogram will be read once, though this may
            // not always be completely true.
            _readChromatograms++;

            // But avoid reaching 100% before reading is actually complete
            SetPercentComplete(Math.Min(99, 100 * _readChromatograms / _chromKeyIndices.Length));

            extra = new ChromExtra(chromKeyIndices.StatusId, chromKeyIndices.StatusRank);

            // Display in AllChromatogramsGraph
            if (chromKeyIndices.Key.Precursor != 0 && Status is ChromatogramLoadingStatus)
            {
                ((ChromatogramLoadingStatus)Status).Transitions.AddTransition(
                    modifiedSequence,
                    peptideColor,
                    chromKeyIndices.StatusId,
                    chromKeyIndices.StatusRank,
                    timeIntensities.Times,
                    timeIntensities.Intensities);
            }
            return(true);
        }
Exemplo n.º 13
0
 public abstract bool GetChromatogram(int id, Target modifiedSequence, Color color, out ChromExtra extra, out TimeIntensities timeIntensities);
Exemplo n.º 14
0
 public SingletonImpl(TimeIntensities timeIntensities) : base(ImmutableList.Singleton(timeIntensities))
 {
 }
Exemplo n.º 15
0
 public static TimeIntensitiesGroup Singleton(TimeIntensities timeIntensities)
 {
     return(new SingletonImpl(timeIntensities));
 }
Exemplo n.º 16
0
 public PeakIntegrator(TimeIntensities interpolatedTimeIntensities)
     : this(interpolatedTimeIntensities, null)
 {
 }
Exemplo n.º 17
0
        public void Interpolate(float[] timesNew, bool inferZeros)
        {
            var chromatogramTimeIntensities = new TimeIntensities(RawTimes, RawIntensities, RawMassErrors, RawScanIds);

            TimeIntensities = chromatogramTimeIntensities.Interpolate(timesNew, inferZeros);
        }
Exemplo n.º 18
0
 public void FixChromatogram(float[] timesNew, float[] intensitiesNew, int[] scanIndexesNew)
 {
     TimeIntensities = RawTimeIntensities = new TimeIntensities(timesNew, intensitiesNew, null, scanIndexesNew);
 }
Exemplo n.º 19
0
 public PeakIntegrator(TimeIntensities interpolatedTimeIntensities, IPeakFinder peakFinder)
 {
     InterpolatedTimeIntensities = interpolatedTimeIntensities;
     PeakFinder = peakFinder;
 }