예제 #1
0
            protected override bool DoCellValidating(int rowIndex, int columnIndex, string value)
            {
                string errorText = null;

                if (columnIndex == COLUMN_SEQUENCE && GridView.IsCurrentCellInEditMode)
                {
                    string sequence = value;
                    errorText = ValidateSequence(sequence);
                }
                else if (columnIndex == COLUMN_PRODUCT_ION && GridView.IsCurrentCellInEditMode)
                {
                    string chargeText = value;
                    errorText = ValidateProductIon(chargeText);
                }
                else if (columnIndex == COLUMN_VALUE && GridView.IsCurrentCellInEditMode)
                {
                    string optimizedText = value;
                    errorText = ValidateOptimizedValue(optimizedText);
                }
                if (errorText == null && GridView.IsCurrentCellInEditMode &&
                    (columnIndex == COLUMN_SEQUENCE || columnIndex == COLUMN_PRODUCT_ION))
                {
                    var             curRow = GridView.Rows[rowIndex].DataBoundItem as DbOptimization;
                    OptimizationKey curKey = curRow != null ? new OptimizationKey(curRow.Key) : new OptimizationKey();
                    switch (columnIndex)
                    {
                    case COLUMN_SEQUENCE:
                    {
                        var seqCharge = new SequenceAndCharge(value);
                        curKey.PeptideModSeq   = seqCharge.ModifiedSequence;
                        curKey.PrecursorAdduct = seqCharge.Charge;
                        break;
                    }

                    case COLUMN_PRODUCT_ION:
                    {
                        var fragCharge = new FragmentAndCharge(value);
                        curKey.FragmentIon   = fragCharge.FragmentIon;
                        curKey.ProductAdduct = fragCharge.Adduct;
                        break;
                    }
                    }
                    int iExist = Optimizations.ToArray().IndexOf(item => Equals(item.Key, curKey));
                    if (iExist != -1 && iExist != rowIndex)
                    {
                        errorText = string.Format(
                            Resources.LibraryGridViewDriver_DoCellValidating_There_is_already_an_optimization_with_sequence___0___and_product_ion___2___in_the_list_,
                            curKey.PeptideModSeq, Transition.GetChargeIndicator(curKey.PrecursorAdduct), curKey.FragmentIon, Transition.GetChargeIndicator(curKey.ProductAdduct));
                    }
                }
                if (errorText != null)
                {
                    MessageDlg.Show(MessageParent, errorText);
                    return(false);
                }

                return(true);
            }
            protected override bool DoCellValidating(int rowIndex, int columnIndex, string value)
            {
                string errorText = null;

                if (columnIndex == COLUMN_SEQUENCE && GridView.IsCurrentCellInEditMode)
                {
                    string sequence = value;
                    errorText = ValidateSequence(sequence);
                }
                else if (columnIndex == COLUMN_PRODUCT_ION && GridView.IsCurrentCellInEditMode)
                {
                    string chargeText = value;
                    errorText = ValidateProductIon(chargeText);
                }
                else if (columnIndex == COLUMN_VALUE && GridView.IsCurrentCellInEditMode)
                {
                    string optimizedText = value;
                    errorText = ValidateOptimizedValue(optimizedText);
                }
                if (errorText == null && GridView.IsCurrentCellInEditMode &&
                    (columnIndex == COLUMN_SEQUENCE || columnIndex == COLUMN_PRODUCT_ION))
                {
                    var             curRow = GridView.Rows[rowIndex].DataBoundItem as DbOptimization;
                    OptimizationKey curKey = curRow != null ? new OptimizationKey(curRow.Key) : new OptimizationKey();
                    switch (columnIndex)
                    {
                    case COLUMN_SEQUENCE:
                        curKey.PeptideModSeq = Transition.StripChargeIndicators(value, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE);
                        curKey.Charge        = Transition.GetChargeFromIndicator(value, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE).GetValueOrDefault(1);
                        break;

                    case COLUMN_PRODUCT_ION:
                        curKey.FragmentIon   = Transition.StripChargeIndicators(value, Transition.MIN_PRODUCT_CHARGE, Transition.MAX_PRODUCT_CHARGE);
                        curKey.ProductCharge = Transition.GetChargeFromIndicator(value, Transition.MIN_PRODUCT_CHARGE, Transition.MAX_PRODUCT_CHARGE).GetValueOrDefault(1);
                        break;
                    }
                    int iExist = Optimizations.ToArray().IndexOf(item => Equals(item.Key, curKey));
                    if (iExist != -1 && iExist != rowIndex)
                    {
                        errorText = string.Format(
                            Resources.LibraryGridViewDriver_DoCellValidating_There_is_already_an_optimization_with_sequence___0___and_product_ion___2___in_the_list_,
                            curKey.PeptideModSeq, Transition.GetChargeIndicator(curKey.Charge), curKey.FragmentIon, Transition.GetChargeIndicator(curKey.ProductCharge));
                    }
                }
                if (errorText != null)
                {
                    MessageDlg.Show(MessageParent, errorText);
                    return(false);
                }

                return(true);
            }
            public void AddResults()
            {
                var settings = _document.Settings;

                if (!settings.HasResults)
                {
                    MessageDlg.Show(MessageParent, Resources.LibraryGridViewDriver_AddResults_The_active_document_must_contain_results_in_order_to_add_optimized_values_);
                    return;
                }

                var newOptimizations = new HashSet <DbOptimization>();

                foreach (PeptideGroupDocNode seq in _document.MoleculeGroups.Where(seq => seq.TransitionCount > 0 && !seq.IsDecoy))
                {
                    foreach (PeptideDocNode peptide in seq.Children)
                    {
                        foreach (TransitionGroupDocNode nodeGroup in peptide.Children)
                        {
                            string sequence = _document.Settings.GetSourceTextId(peptide);
                            int    charge   = nodeGroup.TransitionGroup.PrecursorCharge;
                            foreach (TransitionDocNode nodeTran in nodeGroup.Children)
                            {
                                OptimizationKey key   = null;
                                double?         value = null;
                                if (Equals(ViewType, ExportOptimize.CE))
                                {
                                    key   = new OptimizationKey(ViewDbType, sequence, charge, nodeTran.GetFragmentIonName(CultureInfo.InvariantCulture), nodeTran.Transition.Charge);
                                    value = OptimizationStep <CollisionEnergyRegression> .FindOptimizedValueFromResults(
                                        settings, peptide, nodeGroup, nodeTran, OptimizedMethodType.Transition, GetCollisionEnergy);
                                }
                                else if (Equals(ViewType, ExportOptimize.COV))
                                {
                                    key = new OptimizationKey(ViewDbType, sequence, charge, null, 0);
                                    double?cov = OptimizationStep <CompensationVoltageRegressionFine> .FindOptimizedValueFromResults(_document.Settings,
                                                                                                                                     peptide, nodeGroup, null, OptimizedMethodType.Precursor, SrmDocument.GetCompensationVoltageFine);

                                    value = cov.HasValue ? cov.Value : 0;
                                }
                                if (value.HasValue && value > 0)
                                {
                                    newOptimizations.Add(new DbOptimization(key, value.Value));
                                }
                            }
                        }
                    }
                }
                AddToLibrary(newOptimizations);
            }
예제 #4
0
            private void AddToLibrary(IEnumerable <DbOptimization> libraryOptimizationsNew)
            {
                if (libraryOptimizationsNew == null)
                {
                    return;
                }

                var dictLibraryIndices = new Dictionary <OptimizationKey, int>();

                for (int i = 0; i < Optimizations.Count; i++)
                {
                    // Sometimes the last item can be empty with no sequence.
                    var key = Optimizations[i].Key;
                    if (key != null && !dictLibraryIndices.ContainsKey(key))
                    {
                        dictLibraryIndices.Add(key, i);
                    }
                }

                var listOptimizationsNew     = libraryOptimizationsNew.ToList();
                var listChangedOptimizations = new List <OptimizationKey>();

                // Check for existing matching optimizations
                for (int i = listOptimizationsNew.Count - 1; i >= 0; i--)
                {
                    int optimizationIndex;
                    if (!dictLibraryIndices.TryGetValue(listOptimizationsNew[i].Key, out optimizationIndex))
                    {
                        continue;
                    }

                    if (Equals(listOptimizationsNew[i], Optimizations[optimizationIndex]))
                    {
                        listOptimizationsNew.RemoveAt(i);
                        continue;
                    }

                    listChangedOptimizations.Add(listOptimizationsNew[i].Key);
                }

                listChangedOptimizations.Sort();

                // If there were any matches, get user feedback
                AddOptimizationsAction action;

                using (var dlg = new AddOptimizationsDlg(listOptimizationsNew.Count -
                                                         listChangedOptimizations.Count,
                                                         listChangedOptimizations))
                {
                    if (dlg.ShowDialog(MessageParent) != DialogResult.OK)
                    {
                        return;
                    }
                    action = dlg.Action;
                }

                Optimizations.RaiseListChangedEvents = false;
                try
                {
                    // Add the new optimizations to the library list
                    foreach (var optimization in listOptimizationsNew)
                    {
                        OptimizationKey key = optimization.Key;
                        int             optimizationIndex;
                        // Add any optimizations not yet in the library
                        if (!dictLibraryIndices.TryGetValue(key, out optimizationIndex))
                        {
                            optimization.Id = null;
                            Optimizations.Add(optimization);
                            continue;
                        }

                        var optimizationExist = Optimizations[optimizationIndex];
                        // Replace optimizations if the user said to
                        if (action == AddOptimizationsAction.replace)
                        {
                            optimizationExist.Value = optimization.Value;
                        }
                        // Skip optimizations if the user said to, or no change has occurred.
                        else if (action == AddOptimizationsAction.skip || Equals(optimization, optimizationExist))
                        {
                        }
                        // Average existing and new if that is what the user specified.
                        else if (action == AddOptimizationsAction.average)
                        {
                            optimizationExist.Value = (optimization.Value + optimizationExist.Value) / 2;
                        }
                    }
                }
                finally
                {
                    Optimizations.RaiseListChangedEvents = true;
                }
                Optimizations.ResetBindings();
            }