Example #1
0
 public ElibSpectrumInfo(String peptideModSeq, int charge, int bestFileId, IEnumerable <KeyValuePair <int, FileData> > fileDatas)
 {
     PeptideModSeq = peptideModSeq;
     Key           = new LibKey(SequenceMassCalc.NormalizeModifiedSequence(peptideModSeq), charge);
     BestFileId    = bestFileId;
     FileDatas     = ImmutableSortedList.FromValues(fileDatas);
 }
Example #2
0
        private void LoadPeptides(IEnumerable <DbIonMobilityPeptide> peptides)
        {
            var dictLibrary = new Dictionary <String, DbIonMobilityPeptide>();

            foreach (var pep in peptides)
            {
                var dict = dictLibrary;
                try
                {
                    // Unnormalized modified sequences will not match anything.  The user interface
                    // attempts to enforce only normalized modified sequences, but this extra protection
                    // handles IonMobilitydb files edited outside Skyline.  TODO - copied from iRT code - is this an issue here?
                    var peptide = SequenceMassCalc.NormalizeModifiedSequence(pep.PeptideModSeq);
                    DbIonMobilityPeptide ignored;
                    if (!dict.TryGetValue(peptide, out ignored))
                    {
                        dict.Add(peptide, pep);
                    }
                }
                catch (ArgumentException)
                {
                }
            }

            DictLibrary = dictLibrary;
        }
Example #3
0
 public virtual Target GetNormalizedModifiedSequence()
 {
     if (_normalizedModifiedSequence == null)
     {
         var seq = SequenceMassCalc.NormalizeModifiedSequence(_peptideModSeq.Sequence);
         _normalizedModifiedSequence = _peptideModSeq.ChangeSequence(seq);
     }
     return(_normalizedModifiedSequence);
 }
Example #4
0
        public static bool ValidateRow(object[] columns, IWin32Window parent, int lineNumber, bool postiveTime)
        {
            if (columns.Length != 2)
            {
                MessageDlg.Show(parent, string.Format(Resources.PeptideGridViewDriver_ValidateRow_The_pasted_text_must_have_two_columns_));
                return(false);
            }

            string seq     = columns[COLUMN_SEQUENCE] as string;
            string time    = columns[COLUMN_TIME] as string;
            string message = null;

            if (string.IsNullOrWhiteSpace(seq))
            {
                message = string.Format(Resources.PeptideGridViewDriver_ValidateRow_Missing_peptide_sequence_on_line__0_, lineNumber);
            }
            else if (!FastaSequence.IsExSequence(seq))
            {
                message = string.Format(Resources.PeptideGridViewDriver_ValidateRow_The_text__0__is_not_a_valid_peptide_sequence_on_line__1_, seq, lineNumber);
            }
            else
            {
                try
                {
                    columns[COLUMN_SEQUENCE] = SequenceMassCalc.NormalizeModifiedSequence(seq);
                }
                catch (Exception x)
                {
                    message = x.Message;
                }

                if (message == null)
                {
                    double dTime;
                    if (string.IsNullOrWhiteSpace(time))
                    {
                        message = string.Format(Resources.PeptideGridViewDriver_ValidateRow_Missing_value_on_line__0_, lineNumber);
                    }
                    else if (!double.TryParse(time, out dTime))
                    {
                        message = string.Format(Resources.PeptideGridViewDriver_ValidateRow_Invalid_decimal_number_format__0__on_line__1_, time, lineNumber);
                    }
                    else if (postiveTime && dTime <= 0)
                    {
                        message = string.Format(Resources.PeptideGridViewDriver_ValidateRow_The_time__0__must_be_greater_than_zero_on_line__1_, time, lineNumber);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }

            MessageDlg.Show(parent, message);
            return(false);
        }
                public SequenceAndCharge(string sequenceAndCharge)
                {
                    const int min = TransitionGroup.MIN_PRECURSOR_CHARGE;
                    const int max = TransitionGroup.MAX_PRECURSOR_CHARGE;

                    string seq = Transition.StripChargeIndicators(sequenceAndCharge, min, max);

                    ModifiedSequence = SequenceMassCalc.NormalizeModifiedSequence(new Target(seq));
                    Charge           = Transition.GetChargeFromIndicator(sequenceAndCharge, min, max, Adduct.SINGLY_PROTONATED);
                }
Example #6
0
        public void TestSequenceMassCalcNormalizeModifiedSequence()
        {
            const string normalizedModifiedSequence = "ASDF[+6.0]GHIJ";

            Assert.AreEqual(normalizedModifiedSequence, SequenceMassCalc.NormalizeModifiedSequence("ASDF[6]GHIJ"));
            Assert.AreEqual(normalizedModifiedSequence, SequenceMassCalc.NormalizeModifiedSequence("ASDF[+6]GHIJ"));
            Assert.AreSame(normalizedModifiedSequence, SequenceMassCalc.NormalizeModifiedSequence(normalizedModifiedSequence));

            Assert.AreEqual("ASDF[-6.0]GHIJ", SequenceMassCalc.NormalizeModifiedSequence("ASDF[-6]GHIJ"));

            AssertEx.ThrowsException <ArgumentException>(() => SequenceMassCalc.NormalizeModifiedSequence("ASC[Carbomidomethyl C]FGHIJ"));
            AssertEx.ThrowsException <ArgumentException>(() => SequenceMassCalc.NormalizeModifiedSequence("ASC[6"));
        }
        public static string ValidateMeasuredDriftTimeCellValues(string[] values)
        {
            int    tempInt;
            double tempDouble;

            if (values.Count() < 3)
            {
                return(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_pasted_text_must_have_three_columns_);
            }

            // Parse sequence
            var sequence = values[EditDriftTimePredictorDlg.COLUMN_SEQUENCE];

            if (string.IsNullOrEmpty(sequence))
            {
                return(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_A_modified_peptide_sequence_is_required_for_each_entry_);
            }

            if (!FastaSequence.IsExSequence(sequence))
            {
                return(string.Format(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_sequence__0__is_not_a_valid_modified_peptide_sequence_, sequence));
            }

            try
            {
                values[EditDriftTimePredictorDlg.COLUMN_SEQUENCE] = SequenceMassCalc.NormalizeModifiedSequence(sequence);
            }
            catch (Exception x)
            {
                return(x.Message);
            }

            // Parse charge
            if ((!int.TryParse(values[EditDriftTimePredictorDlg.COLUMN_CHARGE].Trim(), out tempInt)) || ValidateCharge(tempInt) != null)
            {
                return(string.Format(Resources.EditDriftTimePredictorDlg_ValidateCharge_The_entry__0__is_not_a_valid_charge__Precursor_charges_must_be_integer_values_between_1_and__1__,
                                     values[EditDriftTimePredictorDlg.COLUMN_CHARGE].Trim(), TransitionGroup.MAX_PRECURSOR_CHARGE));
            }

            // Parse drift time
            if (!double.TryParse(values[EditDriftTimePredictorDlg.COLUMN_DRIFT_TIME_MSEC].Trim(), out tempDouble))
            {
                return(string.Format(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_value__0__is_not_a_valid_drift_time_, values[EditDriftTimePredictorDlg.COLUMN_DRIFT_TIME_MSEC].Trim()));
            }

            return(null);
        }
Example #8
0
            public IrtPeptidePicker(IEnumerable <MeasuredPeptide> peptides)
            {
                var listMeasured = new List <MeasuredPeptide>();
                var listIrt      = new List <double>();

                var irts = IrtStandard.CIRT.Peptides.ToDictionary(p =>
                                                                  p.GetNormalizedModifiedSequence(), p => p.Irt);

                foreach (var peptide in peptides)
                {
                    var    normalizedModSeq = SequenceMassCalc.NormalizeModifiedSequence(peptide.Target);
                    double irtValue;
                    if (irts.TryGetValue(normalizedModSeq, out irtValue))
                    {
                        listMeasured.Add(peptide);
                        listIrt.Add(irtValue);
                    }
                }

                _bins = listMeasured.Any()
                    ? Bin(listMeasured, listIrt, listMeasured.Count / BIN_FACTOR)
                    : new List <Tuple <MeasuredPeptide, double> > [0];
            }
Example #9
0
        private void LoadPeptides(IEnumerable <DbIrtPeptide> peptides)
        {
            var dictStandards = new Dictionary <string, double>();
            var dictLibrary   = new Dictionary <string, double>();

            foreach (var pep in peptides)
            {
                var dict = pep.Standard ? dictStandards : dictLibrary;
                try
                {
                    // Unnormalized modified sequences will not match anything.  The user interface
                    // attempts to enforce only normalized modified sequences, but this extra protection
                    // handles irtdb files created before normalization was implemented, or edited outside
                    // Skyline.
                    dict.Add(SequenceMassCalc.NormalizeModifiedSequence(pep.PeptideModSeq), pep.Irt);
                }
                catch (ArgumentException)
                {
                }
            }

            DictStandards = dictStandards;
            DictLibrary   = dictLibrary;
        }
        public static string ValidateRow(object[] columns, int lineNumber)
        {
            if (columns.Length < 2)
            {
                return(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_The_pasted_text_must_have_at_least_two_columns_);
            }
            string seq = columns[EditIonMobilityLibraryDlg.COLUMN_SEQUENCE] as string;
            string collisionalcrosssection   = columns[EditIonMobilityLibraryDlg.COLUMN_COLLISIONAL_CROSS_SECTION] as string;
            string highenergydrifttimeoffset = (columns.Length > 2) ? columns[EditIonMobilityLibraryDlg.COLUMN_HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC] as string : string.Empty;
            string message = null;

            if (string.IsNullOrWhiteSpace(seq))
            {
                message = string.Format(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_Missing_peptide_sequence_on_line__0__, lineNumber);
            }
            else if (!FastaSequence.IsExSequence(seq))
            {
                message = string.Format(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_The_text__0__is_not_a_valid_peptide_sequence_on_line__1__, seq, lineNumber);
            }
            else
            {
                try
                {
                    columns[EditIonMobilityLibraryDlg.COLUMN_SEQUENCE] = SequenceMassCalc.NormalizeModifiedSequence(seq);
                }
                catch (Exception x)
                {
                    message = x.Message;
                }

                if (message == null)
                {
                    double dCollisionalCrossSection;
                    if (string.IsNullOrWhiteSpace(collisionalcrosssection))
                    {
                        message = string.Format(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_Missing_collisional_cross_section_value_on_line__0__, lineNumber);
                    }
                    else if (!double.TryParse(collisionalcrosssection, out dCollisionalCrossSection))
                    {
                        message = string.Format(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_Invalid_number_format__0__for_collisional_cross_section_on_line__1__,
                                                collisionalcrosssection,
                                                lineNumber);
                    }
                    else if (dCollisionalCrossSection <= 0)
                    {
                        message =
                            string.Format(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_The_collisional_cross_section__0__must_be_greater_than_zero_on_line__1__,
                                          dCollisionalCrossSection,
                                          lineNumber);
                    }
                }
                if (message == null)
                {
                    double dHighEnergyDriftTimeOffsetMsec;
                    if (!string.IsNullOrWhiteSpace(highenergydrifttimeoffset) && !double.TryParse(highenergydrifttimeoffset, out dHighEnergyDriftTimeOffsetMsec))
                    {
                        message = string.Format(Resources.CollisionalCrossSectionGridViewDriverBase_ValidateRow_Invalid_number_format__0__for_high_energy_drift_time_offset_on_line__1__,
                                                highenergydrifttimeoffset,
                                                lineNumber);
                    }
                }
            }
            return(message);
        }
Example #11
0
        private static void ValidateDecoys(SrmDocument document, SrmDocument decoysDoc, bool modifiesSequences)
        {
            AssertEx.IsDocumentState(decoysDoc, 1, document.PeptideGroupCount + 1, document.PeptideCount * 2,
                                     document.PeptideTransitionGroupCount * 2, document.PeptideTransitionCount * 2);

            // Check for the existence of the Decoys peptide group and that everything under it is marked as a decoy.
            var nodePeptideGroupDecoy = decoysDoc.PeptideGroups.Single(nodePeptideGroup => nodePeptideGroup.IsDecoy);
            var dictModsToPep         = document.Peptides.ToDictionary(nodePep => nodePep.ModifiedSequence);

            foreach (var nodePep in nodePeptideGroupDecoy.Peptides)
            {
                Assert.AreEqual(true, nodePep.IsDecoy);
                PeptideDocNode nodePepSource = null;
                if (!modifiesSequences)
                {
                    Assert.IsNull(nodePep.SourceKey);
                }
                else
                {
                    Assert.IsNotNull(nodePep.SourceKey, string.Format("Source key for {0}{1} is null", nodePep.ModifiedSequence,
                                                                      nodePep.IsDecoy ? " - decoy" : string.Empty));
                    Assert.IsTrue(FastaSequence.IsExSequence(nodePep.SourceKey.Sequence));
                    Assert.AreEqual(nodePep.SourceKey.ModifiedSequence,
                                    SequenceMassCalc.NormalizeModifiedSequence(nodePep.SourceKey.ModifiedSequence));
                    if (nodePep.HasExplicitMods)
                    {
                        Assert.IsNotNull(nodePep.SourceKey.ExplicitMods);
                    }
                    Assert.IsTrue(dictModsToPep.TryGetValue(nodePep.SourceTextId, out nodePepSource));
                    var sourceKey = new ModifiedSequenceMods(nodePepSource.Peptide.Sequence, nodePepSource.ExplicitMods);
                    Assert.AreEqual(sourceKey.ExplicitMods, nodePep.SourceExplicitMods);
                }
                for (int i = 0; i < nodePep.TransitionGroupCount; i++)
                {
                    var nodeGroup = nodePep.TransitionGroups.ElementAt(i);
                    Assert.AreEqual(true, nodeGroup.IsDecoy);
                    TransitionGroupDocNode nodeGroupSource = null;
                    double shift = SequenceMassCalc.GetPeptideInterval(nodeGroup.TransitionGroup.DecoyMassShift);
                    if (nodePepSource != null && nodeGroup.TransitionGroup.DecoyMassShift.HasValue)
                    {
                        nodeGroupSource = nodePepSource.TransitionGroups.ElementAt(i);
                        Assert.AreEqual(nodeGroupSource.PrecursorMz + shift, nodeGroup.PrecursorMz, SequenceMassCalc.MassTolerance);
                    }
                    for (int j = 0; j < nodeGroup.TransitionCount; j++)
                    {
                        var nodeTran = nodeGroup.Transitions.ElementAt(j);
                        Assert.IsTrue(nodeTran.IsDecoy);
                        if (nodeTran.Transition.IsPrecursor())
                        {
                            Assert.AreEqual(nodeGroup.TransitionGroup.DecoyMassShift, nodeTran.Transition.DecoyMassShift);
                            if (nodeGroupSource != null)
                            {
                                Assert.AreEqual(nodeGroupSource.Transitions.ElementAt(j).Mz + shift, nodeTran.Mz, SequenceMassCalc.MassTolerance);
                            }
                        }
                    }
                }
            }

            // Check that the resulting document persists correctly by passing the SrmDocument to AssertEx.IsSerializable().
            AssertEx.Serializable(decoysDoc);
        }
Example #12
0
        private bool LoadLibraryFromDatabase(ILoadMonitor loader)
        {
            try
            {
                var status = new ProgressStatus(string.Format(Resources.ChromatogramLibrary_LoadLibraryFromDatabase_Reading_precursors_from__0_, Name));
                loader.UpdateProgress(status);
                //                _pooledSessionFactory = new PooledSessionFactory(loader.StreamManager.ConnectionPool,
//                                                                 typeof (ChromLibEntity), FilePath);
                using (var session = _pooledSessionFactory.Connection.OpenSession())
                {
                    var libInfo =
                        session.CreateSQLQuery("SELECT PanoramaServer, LibraryRevision, SchemaVersion FROM LibInfo") // Not L10N
                        .UniqueResult <object[]>();
                    PanoramaServer  = Convert.ToString(libInfo[0]);
                    LibraryRevision = Convert.ToInt32(libInfo[1]);
                    SchemaVersion   = Convert.ToString(libInfo[2]);

                    try
                    {
                        var irtQuery = session.CreateQuery("SELECT PeptideModSeq, Irt, TimeSource FROM IrtLibrary"); // Not L10N
                        _libraryIrts = irtQuery.List <object[]>().Select(
                            irt => new ChromatogramLibraryIrt(new Target((string)irt[0]), (TimeSource)irt[2], Convert.ToDouble(irt[1]))
                            ).ToArray();
                    }
                    catch (GenericADOException)
                    {
                        // IrtLibrary table probably doesn't exist
                    }

                    var rtQuery      = session.CreateQuery("SELECT Precursor.Id, SampleFile.Id, RetentionTime FROM PrecursorRetentionTime"); // Not L10N
                    var rtDictionary = new Dictionary <int, List <KeyValuePair <int, double> > >();                                          // PrecursorId -> [SampleFileId -> RetentionTime]
                    foreach (object[] row in rtQuery.List <object[]>())
                    {
                        var precursorId  = (int)row[0];
                        var sampleFileId = (int)row[1];
                        var rt           = Convert.ToDouble(row[2]);
                        if (!rtDictionary.ContainsKey(precursorId))
                        {
                            rtDictionary.Add(precursorId, new List <KeyValuePair <int, double> >());
                        }
                        rtDictionary[precursorId].Add(new KeyValuePair <int, double>(sampleFileId, rt));
                    }

                    var precursorQuery =
                        session.CreateQuery("SELECT P.Id, P.ModifiedSequence, P.Charge, P.TotalArea FROM " + typeof(Precursor) + // Not L10N
                                            " P");                                                                               // Not L10N
                    var allTransitionAreas = ReadAllTransitionAreas(session);
                    var spectrumInfos      = new List <ChromLibSpectrumInfo>();
                    foreach (object[] row in precursorQuery.List <object[]>())
                    {
                        var id = (int)row[0];
                        if (row[1] == null || row[2] == null)
                        {
                            continue; // Throw an error?
                        }
                        var    modifiedSequence = new Target((string)row[1]);
                        var    charge           = (int)row[2]; // TODO(bspratt) generalize chromatogram libs to small mol
                        double totalArea        = Convert.ToDouble(row[3]);
                        List <KeyValuePair <int, double> > retentionTimes;
                        var indexedRetentionTimes = new IndexedRetentionTimes();
                        if (rtDictionary.TryGetValue(id, out retentionTimes))
                        {
                            indexedRetentionTimes = new IndexedRetentionTimes(retentionTimes);
                        }
                        Target modSeqNormal;
                        try
                        {
                            modSeqNormal = SequenceMassCalc.NormalizeModifiedSequence(modifiedSequence);
                        }
                        catch (ArgumentException)
                        {
                            continue;
                        }

                        var libKey = new LibKey(modSeqNormal.Sequence, charge);
                        IList <SpectrumPeaksInfo.MI> transitionAreas;
                        allTransitionAreas.TryGetValue(id, out transitionAreas);
                        spectrumInfos.Add(new ChromLibSpectrumInfo(libKey, id, totalArea, indexedRetentionTimes, transitionAreas));
                    }
                    SetLibraryEntries(spectrumInfos);

                    var sampleFileQuery =
                        session.CreateQuery("SELECT Id, FilePath, SampleName, AcquiredTime, ModifiedTime, InstrumentIonizationType, " + // Not L10N
                                            "InstrumentAnalyzer, InstrumentDetector FROM SampleFile");                                  // Not L10N
                    var sampleFiles = new List <ChromatogramLibrarySourceInfo>();
                    foreach (object[] row in sampleFileQuery.List <object[]>())
                    {
                        var id = (int)row[0];
                        if (row[1] == null || row[2] == null)
                        {
                            continue; // Throw an error?
                        }
                        var filePath                 = row[1].ToString();
                        var sampleName               = row[2].ToString();
                        var acquiredTime             = row[3] != null ? row[3].ToString() : string.Empty;
                        var modifiedTime             = row[4] != null ? row[4].ToString() : string.Empty;
                        var instrumentIonizationType = row[5] != null ? row[5].ToString() : string.Empty;
                        var instrumentAnalyzer       = row[6] != null ? row[6].ToString() : string.Empty;
                        var instrumentDetector       = row[7] != null ? row[7].ToString() : string.Empty;
                        sampleFiles.Add(new ChromatogramLibrarySourceInfo(id, filePath, sampleName, acquiredTime, modifiedTime, instrumentIonizationType,
                                                                          instrumentAnalyzer, instrumentDetector));
                    }
                    _librarySourceFiles = sampleFiles.ToArray();

                    loader.UpdateProgress(status.Complete());
                    return(true);
                }
            }
            catch (Exception e)
            {
                Trace.TraceWarning(Resources.ChromatogramLibrary_LoadLibraryFromDatabase_Error_loading_chromatogram_library__0_, e);
                return(false);
            }
        }
Example #13
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            if (!helper.ValidateNameTextBox(textName, out var name))
            {
                return;
            }
            else if (_existing.Contains(r => !ReferenceEquals(_standard, r) && Equals(name, r.Name)))
            {
                helper.ShowTextBoxError(textName, Resources.CalibrateIrtDlg_OkDialog_The_iRT_standard__0__already_exists_, name);
                return;
            }

            if (!IsRecalibration)
            {
                var irts = IrtStandard.CIRT.Peptides.ToDictionary(p => p.GetNormalizedModifiedSequence(), p => p.Irt);
                var calibrationPeptides = new List <Tuple <DbIrtPeptide, double> >();
                foreach (var pep in StandardPeptideList)
                {
                    double irt;
                    if (!irts.TryGetValue(SequenceMassCalc.NormalizeModifiedSequence(pep.Target), out irt))
                    {
                        break;
                    }
                    calibrationPeptides.Add(new Tuple <DbIrtPeptide, double>(
                                                new DbIrtPeptide(pep.Target, irt, true, TimeSource.peak), pep.RetentionTime));
                }

                if (calibrationPeptides.Count == StandardPeptideList.Count)
                {
                    var statStandard = new Statistics(calibrationPeptides.Select(p => p.Item1.Irt));
                    var statMeasured = new Statistics(calibrationPeptides.Select(p => p.Item2));
                    if (statStandard.R(statMeasured) >= RCalcIrt.MIN_IRT_TO_TIME_CORRELATION)
                    {
                        var result = MultiButtonMsgDlg.Show(this,
                                                            Resources.CalibrateIrtDlg_OkDialog_All_of_these_peptides_are_known_CiRT_peptides__Would_you_like_to_use_the_predefined_iRT_values_,
                                                            MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, true);
                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }

                        if (result == DialogResult.Yes)
                        {
                            IrtStandard  = new IrtStandard(name, null, calibrationPeptides.Select(x => x.Item1));
                            DialogResult = DialogResult.OK;
                            return;
                        }
                    }
                }
            }

            if (!TryGetLine(true, out var linearEquation))
            {
                return;
            }

            if (!IsRecalibration)
            {
                IrtStandard = new IrtStandard(name, null,
                                              StandardPeptideList.Select(pep =>
                                                                         new DbIrtPeptide(pep.Target, linearEquation.GetY(pep.RetentionTime), true, TimeSource.peak)));
            }
            else
            {
                foreach (var pep in _updatePeptides)
                {
                    pep.Irt = linearEquation.GetY(pep.Irt);
                }
                IrtStandard = new IrtStandard(name, null,
                                              _standard.Peptides.Select(pep =>
                                                                        new DbIrtPeptide(pep.Target, linearEquation.GetY(pep.Irt), true, TimeSource.peak)));
            }
            DialogResult = DialogResult.OK;
        }
Example #14
0
        public void OkDialog()
        {
            var irts = IrtStandard.CIRT.Peptides.ToDictionary(p => p.GetNormalizedModifiedSequence(), p => p.Irt);
            var calibrationPeptides = new List <Tuple <DbIrtPeptide, double> >();

            foreach (var pep in StandardPeptideList)
            {
                double irt;
                if (!irts.TryGetValue(SequenceMassCalc.NormalizeModifiedSequence(pep.Target), out irt))
                {
                    break;
                }
                calibrationPeptides.Add(new Tuple <DbIrtPeptide, double>(new DbIrtPeptide(pep.Target, irt, true, TimeSource.peak), pep.RetentionTime));
            }
            if (calibrationPeptides.Count == StandardPeptideList.Count)
            {
                var statStandard = new Statistics(calibrationPeptides.Select(p => p.Item1.Irt));
                var statMeasured = new Statistics(calibrationPeptides.Select(p => p.Item2));
                if (statStandard.R(statMeasured) >= RCalcIrt.MIN_IRT_TO_TIME_CORRELATION)
                {
                    var result = MultiButtonMsgDlg.Show(this,
                                                        Resources.CalibrateIrtDlg_OkDialog_All_of_these_peptides_are_known_CiRT_peptides__Would_you_like_to_use_the_predefined_iRT_values_,
                                                        MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, true);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (result == DialogResult.Yes)
                    {
                        CalibrationPeptides = calibrationPeptides.Select(x => x.Item1).ToList();
                        DialogResult        = DialogResult.OK;
                        return;
                    }
                }
            }

            double minIrt;
            double maxIrt;

            var helper = new MessageBoxHelper(this);

            if (!helper.ValidateDecimalTextBox(textMinIrt, null, null, out minIrt))
            {
                return;
            }
            if (!helper.ValidateDecimalTextBox(textMaxIrt, minIrt, null, out maxIrt))
            {
                return;
            }

            int iFixed1 = -1, iFixed2 = -1;

            for (int i = 0; i < StandardPeptideList.Count; i++)
            {
                if (!StandardPeptideList[i].FixedPoint)
                {
                    continue;
                }
                if (iFixed1 == -1)
                {
                    iFixed1 = i;
                }
                else
                {
                    iFixed2 = i;
                }
            }

            if (iFixed1 == -1 || iFixed2 == -1)
            {
                MessageDlg.Show(this, Resources.CalibrateIrtDlg_OkDialog_The_standard_must_have_two_fixed_points);
                return;
            }

            double fixedPt1 = StandardPeptideList[iFixed1].RetentionTime;
            double fixedPt2 = StandardPeptideList[iFixed2].RetentionTime;

            double minRt = Math.Min(fixedPt1, fixedPt2);
            double maxRt = Math.Max(fixedPt1, fixedPt2);

            var statRt         = new Statistics(minRt, maxRt);
            var statIrt        = new Statistics(minIrt, maxIrt);
            var linearEquation = new RegressionLine(statIrt.Slope(statRt), statIrt.Intercept(statRt));

            CalibrationPeptides = new List <DbIrtPeptide>();
            foreach (var peptide in StandardPeptideList)
            {
                double iRT = linearEquation.GetY(peptide.RetentionTime);
                CalibrationPeptides.Add(new DbIrtPeptide(peptide.Target, iRT, true, TimeSource.peak));
            }

            DialogResult = DialogResult.OK;
        }
Example #15
0
        public static string ValidateMeasuredDriftTimeCellValues(string[] values)
        {
            Adduct tempAdduct;
            double tempDouble;

            if (values.Length < 3)
            {
                return(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_pasted_text_must_have_three_columns_);
            }

            // Parse sequence
            var sequence = values[EditDriftTimePredictorDlg.COLUMN_SEQUENCE];

            if (string.IsNullOrEmpty(sequence))
            {
                return(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_A_modified_peptide_sequence_is_required_for_each_entry_);
            }

            if (!FastaSequence.IsExSequence(sequence))
            {
                return(string.Format(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_sequence__0__is_not_a_valid_modified_peptide_sequence_, sequence));
            }

            try
            {
                values[EditDriftTimePredictorDlg.COLUMN_SEQUENCE] = SequenceMassCalc.NormalizeModifiedSequence(sequence);
            }
            catch (Exception x)
            {
                return(x.Message);
            }

            // Parse charge
            if ((!Adduct.TryParse(values[EditDriftTimePredictorDlg.COLUMN_CHARGE].Trim(), out tempAdduct)) || ValidateCharge(tempAdduct) != null)
            {
                return(string.Format(Resources.EditDriftTimePredictorDlg_ValidateCharge_The_entry__0__is_not_a_valid_charge__Precursor_charges_must_be_integer_values_between_1_and__1__,
                                     values[EditDriftTimePredictorDlg.COLUMN_CHARGE].Trim(), TransitionGroup.MAX_PRECURSOR_CHARGE));
            }

            // Parse drift time
            if (!double.TryParse(values[EditDriftTimePredictorDlg.COLUMN_ION_MOBILITY].Trim(), out tempDouble))
            {
                return(string.Format(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_value__0__is_not_a_valid_drift_time_, values[EditDriftTimePredictorDlg.COLUMN_ION_MOBILITY].Trim()));
            }

            if (values.Length > EditDriftTimePredictorDlg.COLUMN_CCS)
            {
                // Parse CCS, if any
                if (!string.IsNullOrEmpty(values[EditDriftTimePredictorDlg.COLUMN_CCS]) &&
                    !double.TryParse(values[EditDriftTimePredictorDlg.COLUMN_CCS].Trim(), out tempDouble))
                {
                    return(string.Format(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_value__0__is_not_a_valid_collisional_cross_section_, values[EditDriftTimePredictorDlg.COLUMN_CCS].Trim()));
                }
            }
            if (values.Length > EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET)
            {
                // Parse high energy offset, if any
                if (!string.IsNullOrEmpty(values[EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET]) &&
                    !double.TryParse(values[EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET].Trim(), out tempDouble))
                {
                    return(string.Format(Resources.MeasuredDriftTimeTable_ValidateMeasuredDriftTimeCellValues_The_value__0__is_not_a_valid_high_energy_offset_, values[EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET].Trim()));
                }
            }
            return(null);
        }
Example #16
0
        public void OkDialog()
        {
            var reader           = new StringReader(PeptidesText);
            var invalidLines     = new List <string>();
            var notFoundLines    = new List <string>();
            var acceptedPeptides = new List <LibraryKey>();
            var peptideSequences = GetPeptideSequences();

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                int foundAt;
                var charge = Transition.GetChargeFromIndicator(line,
                                                               TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE, out foundAt);
                if (!charge.IsEmpty)
                {
                    line = line.Substring(0, foundAt);
                }
                Target target;
                try
                {
                    // CONSIDER(bspratt) small molecule equivalent?
                    if (!FastaSequence.IsExSequence(line))
                    {
                        invalidLines.Add(line);
                        continue;
                    }
                    line   = SequenceMassCalc.NormalizeModifiedSequence(line);
                    target = new Target(line);
                }
                catch (Exception)
                {
                    invalidLines.Add(line);
                    continue;
                }

                if (!peptideSequences.ContainsKey(target))
                {
                    notFoundLines.Add(line);
                }
                else
                {
                    acceptedPeptides.Add(new LibKey(target, charge).LibraryKey);
                }
            }

            if (invalidLines.Count > 0)
            {
                if (invalidLines.Count == 1)
                {
                    MessageDlg.Show(this, string.Format(Resources.RefineListDlg_OkDialog_The_sequence__0__is_not_a_valid_peptide, invalidLines[0]));
                }
                else
                {
                    MessageDlg.Show(this, TextUtil.LineSeparate(Resources.RefineListDlg_OkDialog_The_following_sequences_are_not_valid_peptides, string.Empty, TextUtil.LineSeparate(invalidLines)));
                }
                return;
            }
            if (acceptedPeptides.Count == 0)
            {
                MessageDlg.Show(this, Resources.RefineListDlg_OkDialog_None_of_the_specified_peptides_are_in_the_document);
                return;
            }
            if (notFoundLines.Count > 0)
            {
                string message;
                if (notFoundLines.Count == 1)
                {
                    message = string.Format(Resources.RefineListDlg_OkDialog_The_peptide__0__is_not_in_the_document_Do_you_want_to_continue, notFoundLines[0]);
                }
                else if (notFoundLines.Count < 15)
                {
                    message = TextUtil.LineSeparate(Resources.RefineListDlg_OkDialog_The_following_peptides_are_not_in_the_document, string.Empty,
                                                    TextUtil.LineSeparate(notFoundLines), string.Empty,
                                                    Resources.RefineListDlg_OkDialog_Do_you_want_to_continue);
                }
                else
                {
                    message = string.Format(Resources.RefineListDlg_OkDialog_Of_the_specified__0__peptides__1__are_not_in_the_document_Do_you_want_to_continue,
                                            notFoundLines.Count + acceptedPeptides.Count, notFoundLines.Count);
                }
                if (MultiButtonMsgDlg.Show(this, message, MultiButtonMsgDlg.BUTTON_OK) != DialogResult.OK)
                {
                    return;
                }
            }

            AcceptedPeptides = acceptedPeptides.ToArray();
            DialogResult     = DialogResult.OK;
        }
Example #17
0
 public static bool Match(DbIrtPeptide x, DbIrtPeptide y, double?irtTolerance)
 {
     return(Equals(SequenceMassCalc.NormalizeModifiedSequence(x.PeptideModSeq), SequenceMassCalc.NormalizeModifiedSequence(y.PeptideModSeq)) &&
            (!irtTolerance.HasValue || Math.Abs(x.Irt - y.Irt) < irtTolerance.Value));
 }