Esempio n. 1
0
        /// <summary>
        /// Calculate fragment ion labels.
        /// </summary>
        /// <param name="labelModifications">The heavy/light labels.</param>
        /// <returns>A list of fragment labeled ions.</returns>
        private ReactiveList <LabeledIonViewModel> GenerateFragmentLabels(ReactiveList <SearchModification> labelModifications = null)
        {
            var fragmentLabelList = new ReactiveList <LabeledIonViewModel> {
                ChangeTrackingEnabled = true
            };

            if (this.SelectedPrSm.Sequence.Count < 1)
            {
                return(fragmentLabelList);
            }

            var sequence = this.SelectedPrSm.Sequence;

            if (labelModifications != null)
            {
                sequence = IonUtils.GetHeavySequence(sequence, labelModifications.ToArray());
            }

            var precursorIon = IonUtils.GetPrecursorIon(sequence, this.SelectedPrSm.Charge);

            lock (this.cacheLock)
            {
                var prefixCompositions = this.prefixCompositionCache.Get(sequence);
                var suffixCompositions = this.suffixCompositionCache.Get(sequence);
                foreach (var ionType in this.IonTypes)
                {
                    var ionFragments = new List <LabeledIonViewModel>();
                    for (int i = 0; i < prefixCompositions.Length; i++)
                    {
                        var composition = ionType.IsPrefixIon
                            ? prefixCompositions[i]
                            : suffixCompositions[i];
                        LabeledIonViewModel label =
                            this.fragmentCache.Get(new Tuple <Composition, IonType>(composition, ionType));
                        label.Index = ionType.IsPrefixIon ? i + 1 : (sequence.Count - (i + 1));
                        if (label.PrecursorIon == null)
                        {
                            label.PrecursorIon = precursorIon;
                        }

                        ionFragments.Add(label);
                    }

                    if (!ionType.IsPrefixIon)
                    {
                        ionFragments.Reverse();
                    }

                    fragmentLabelList.AddRange(ionFragments);
                }
            }

            return(fragmentLabelList);
        }
Esempio n. 2
0
        /// <summary>
        /// Calculate fragment ion labels.
        /// </summary>
        /// <param name="ionTypes">List of IonTypes.</param>
        /// <param name="labelModifications">The heavy/light labels.</param>
        /// <returns>A list of fragment labeled ions.</returns>
        public List <LabeledIonViewModel> GetFragmentLabels(IList <IonType> ionTypes, SearchModification[] labelModifications = null)
        {
            var fragmentLabelList = new List <LabeledIonViewModel> {
                Capacity = this.Sequence.Count * ionTypes.Count * this.Charge
            };

            if (this.Sequence.Count < 1 || this.LcMsRun == null)
            {
                return(fragmentLabelList);
            }

            var sequence = labelModifications == null ? this.Sequence : IonUtils.GetHeavySequence(this.Sequence, labelModifications);

            var precursorIon = IonUtils.GetPrecursorIon(sequence, this.Charge);

            lock (this.cacheLock)
            {
                foreach (var ionType in ionTypes)
                {
                    var ionFragments = new List <LabeledIonViewModel>();
                    for (int i = 1; i < this.Sequence.Count; i++)
                    {
                        var startIndex = ionType.IsPrefixIon ? 0 : i;
                        var length     = ionType.IsPrefixIon ? i : sequence.Count - i;
                        var fragment   = new Sequence(this.Sequence.GetRange(startIndex, length));
                        var ions       = ionType.GetPossibleIons(fragment);

                        foreach (var ion in ions)
                        {
                            var labeledIonViewModel = this.fragmentCache.Get(new Tuple <Composition, IonType>(ion.Composition, ionType));
                            labeledIonViewModel.Index        = length;
                            labeledIonViewModel.PrecursorIon = precursorIon;

                            ionFragments.Add(labeledIonViewModel);
                        }

                        if (!ionType.IsPrefixIon)
                        {
                            ionFragments.Reverse();
                        }
                    }

                    fragmentLabelList.AddRange(ionFragments);
                }
            }

            return(fragmentLabelList);
        }
        /// <summary>
        /// Calculate fragment ion labels.
        /// </summary>
        /// <param name="ionTypes">List of IonTypes.</param>
        /// <param name="labelModifications">The heavy/light labels.</param>
        /// <returns>A list of fragment labeled ions.</returns>
        public List <LabeledIonViewModel> GetFragmentLabels(IList <IonType> ionTypes, SearchModification[] labelModifications = null)
        {
            var fragmentLabelList = new List <LabeledIonViewModel> {
                Capacity = Sequence.Count * ionTypes.Count * Charge
            };

            if (Sequence.Count < 1 || LcMsRun == null)
            {
                return(fragmentLabelList);
            }

            var sequence = labelModifications == null ? Sequence : IonUtils.GetHeavySequence(Sequence, labelModifications);

            var precursorIon = IonUtils.GetPrecursorIon(sequence, Charge);

            var tasks = new List <Task <object> >();

            // Define a delegate that prints and returns the system tick count
            Func <object, List <LabeledIonViewModel> > action = (object type) =>
            {
                IonType iType        = (IonType)type;
                var     ionFragments = new List <LabeledIonViewModel>();
                for (var i = 1; i < Sequence.Count; i++)
                {
                    var startIndex = iType.IsPrefixIon ? 0 : i;
                    var length     = iType.IsPrefixIon ? i : sequence.Count - i;
                    var fragment   = new Sequence(Sequence.GetRange(startIndex, length));
                    var ions       = iType.GetPossibleIons(fragment);
                    foreach (var ion in ions)
                    {
                        lock (cacheLock)
                        {
                            var labeledIonViewModel = fragmentCache.Get(new Tuple <Composition, IonType>(ion.Composition, iType));
                            labeledIonViewModel.Index        = length;
                            labeledIonViewModel.PrecursorIon = precursorIon;

                            ionFragments.Add(labeledIonViewModel);
                        }
                    }

                    if (!iType.IsPrefixIon)
                    {
                        ionFragments.Reverse();
                    }
                }
                return(ionFragments);
            };

            foreach (var ionType in ionTypes)
            {
                tasks.Add(Task <object> .Factory.StartNew(action, ionType));
            }

            Task.WaitAll(tasks.ToArray());

            foreach (Task <object> task in tasks)
            {
                List <LabeledIonViewModel> list = (List <LabeledIonViewModel>)task.Result;
                fragmentLabelList.AddRange(list);
            }

            return(fragmentLabelList);
        }