Example #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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FragmentationSequenceViewModel"/> class.
        /// </summary>
        public FragmentationSequenceViewModel()
        {
            FragmentationSequence = new FragmentationSequence(
                new Sequence(new List <AminoAcid>()),
                1,
                null,
                ActivationMethod.HCD);

            var baseIonTypes = BaseIonType.AllBaseIonTypes.Select(
                bit =>
                new BaseIonTypeViewModel
            {
                BaseIonType = bit,
                IsSelected  = bit == BaseIonType.B || bit == BaseIonType.Y
            });

            BaseIonTypes = new ReactiveList <BaseIonTypeViewModel>(baseIonTypes)
            {
                ChangeTrackingEnabled = true
            };

            NeutralLosses = new ReactiveList <NeutralLossViewModel>
            {
                new NeutralLossViewModel {
                    NeutralLoss = NeutralLoss.NoLoss, IsSelected = true
                },
                new NeutralLossViewModel {
                    NeutralLoss = NeutralLoss.H2O
                },
                new NeutralLossViewModel {
                    NeutralLoss = NeutralLoss.NH3
                }
            };

            NeutralLosses.ChangeTrackingEnabled = true;

            HeavyModifications   = new SearchModification[0];
            LabeledIonViewModels = new LabeledIonViewModel[0];
            SelectedIonTypes     = new IonType[0];

            AddPrecursorIons = true;

            // HideAllIonsCommand deselects all ion types and neutral losses.
            HideAllIonsCommand = ReactiveCommand.Create(() =>
            {
                AddPrecursorIons = false;
                foreach (var baseIonType in BaseIonTypes)
                {
                    baseIonType.IsSelected = false;
                }

                foreach (var neutralLoss in NeutralLosses)
                {
                    neutralLoss.IsSelected = neutralLoss.NeutralLoss == NeutralLoss.NoLoss && neutralLoss.IsSelected;
                }
            });

            // When Base Ion Types are selected/deselected, update ion types.
            BaseIonTypes.ItemChanged.Where(x => x.PropertyName == "IsSelected")
            .Select(_ => GetIonTypes())
            .Subscribe(ionTypes => SelectedIonTypes = ionTypes);

            // When Neutral Losses are selected/deselected, update ion types
            NeutralLosses.ItemChanged.Where(x => x.PropertyName == "IsSelected")
            .Select(_ => GetIonTypes())
            .Subscribe(ionTypes => SelectedIonTypes = ionTypes);

            // When FragmentationSequence is set, select IonTypes for ActivationMethod.
            this.WhenAnyValue(x => x.FragmentationSequence)
            .Where(fragSeq => fragSeq != null)
            .Subscribe(fragSeq => SetActivationMethod(fragSeq.ActivationMethod));

            // When fragmentation sequence changes, update labeled ions
            this.WhenAnyValue(x => x.FragmentationSequence, x => x.SelectedIonTypes, x => x.HeavyModifications, x => x.AddPrecursorIons)
            .SelectMany(async _ => await GetLabeledIonViewModels())
            .Subscribe(livms => LabeledIonViewModels = livms);

            SelectAllIonsCommand = ReactiveCommand.Create(() =>
            {
                foreach (var ion in BaseIonTypes)
                {
                    ion.IsSelected = true;
                }

                AddPrecursorIons = true;
            });

            IcParameters.Instance.WhenAnyValue(x => x.CidHcdIonTypes, x => x.EtdIonTypes)
            .Throttle(TimeSpan.FromMilliseconds(50), RxApp.TaskpoolScheduler)
            .Where(_ => FragmentationSequence != null)
            .Subscribe(_ => SetActivationMethod(FragmentationSequence.ActivationMethod));
        }
Example #3
0
 /// <summary>
 /// Compare the label of this LabeledIon to another LabeledIon for equality.
 /// </summary>
 /// <param name="other">The LabeledIon to compare to.</param>
 /// <returns>A value indicating whether this LabeledIon is equal to the other LabeledIon.</returns>
 public bool Equals(LabeledIonViewModel other)
 {
     return(this.Label.Equals(other.Label));
 }
Example #4
0
 /// <summary>
 /// Compare the label of this LabeledIon to another LabeledIon.
 /// </summary>
 /// <param name="other">The LabeledIon to compare to.</param>
 /// <returns>
 /// A value indicating whether this LabeledIon is
 /// equal to, greater than, or less than the other LabeledIon.
 /// </returns>
 public int CompareTo(LabeledIonViewModel other)
 {
     return(string.Compare(this.Label, other.Label, StringComparison.Ordinal));
 }