Beispiel #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);
 }
Beispiel #2
0
        public double GetTotalArea(int replicateIndex, IsotopeLabelType isotopeLabelType)
        {
            // ReSharper disable InconsistentlySynchronizedField
            if (replicateIndex >= _allTotalAreas.Length)
            {
                return(0);
            }
            // ReSharper restore InconsistentlySynchronizedField

            ImmutableSortedList <IsotopeLabelType, double> areasByLabelType;

            lock (_allTotalAreas)
            {
                areasByLabelType = _allTotalAreas[replicateIndex];
                // ReSharper disable once ConvertIfStatementToNullCoalescingExpression
                if (null == areasByLabelType)
                {
                    areasByLabelType = _allTotalAreas[replicateIndex] =
                        ImmutableSortedList.FromValues(CalculateTotalAreas(replicateIndex));
                }
            }
            double area;

            areasByLabelType.TryGetValue(isotopeLabelType, out area);
            return(area);
        }
Beispiel #3
0
        public static T Parse(String formula)
        {
            var    result          = new Dictionary <string, int>();
            string currentElement  = null;
            int    currentQuantity = 0;

            foreach (char ch in formula)
            {
                if (Char.IsDigit(ch))
                {
                    currentQuantity = currentQuantity * 10 + (ch - '0');
                }
                else if (Char.IsUpper(ch))
                {
                    if (currentElement != null)
                    {
                        if (currentQuantity == 0)
                        {
                            currentQuantity = 1;
                        }
                        int previous;
                        if (result.TryGetValue(currentElement, out previous))
                        {
                            result[currentElement] = previous + currentQuantity;
                        }
                        else
                        {
                            result.Add(currentElement, previous + currentQuantity);
                        }
                    }
                    currentQuantity = 0;
                    currentElement  = string.Empty + ch;
                }
                // Allow apostrophe for heavy isotopes (e.g. C' for 13C)
                else if (!Char.IsWhiteSpace(ch))
                {
                    currentElement = currentElement + ch;
                }
            }
            if (currentElement != null)
            {
                if (currentQuantity == 0)
                {
                    currentQuantity = 1;
                }

                int previous;
                if (result.TryGetValue(currentElement, out previous))
                {
                    result[currentElement] = previous + currentQuantity;
                }
                else
                {
                    result.Add(currentElement, previous + currentQuantity);
                }
            }
            return(new T {
                Dictionary = ImmutableSortedList.FromValues(result)
            });
        }
Beispiel #4
0
        public virtual WorkspaceData Merge(WorkspaceData newWorkspaceData)
        {
            var myList    = Data;
            var theirList = GetData(newWorkspaceData);
            var baseList  = GetData(Workspace.SavedData);

            if (null == myList || Equals(baseList, myList))
            {
                return(newWorkspaceData);
            }
            if (null == theirList || null == baseList || Equals(theirList, baseList))
            {
                return(SetData(newWorkspaceData, myList));
            }
            var myChanges = new HashSet <KeyValuePair <TKey, TValue> >(Data);

            myChanges.SymmetricExceptWith(SavedData);

            var myChangedKeys = new HashSet <TKey>(myChanges.Select(pair => pair.Key)).Distinct();
            var newValues     =
                new List <KeyValuePair <TKey, TValue> >(Data.Where(pair => myChangedKeys.Contains(pair.Key)));

            newValues.AddRange(theirList.Where(pair => !myChangedKeys.Contains(pair.Key)));

            var mergedData = ImmutableSortedList.FromValues(newValues, Data.KeyComparer);

            return(SetData(newWorkspaceData, mergedData));
        }
Beispiel #5
0
 protected override ImmutableSortedList <long, Peptide> CreateEntityList()
 {
     return
         (ImmutableSortedList.FromValues(Workspace.Data.Peptides
                                         .Select(entry => new KeyValuePair <long, Peptide>(
                                                     entry.Key, new Peptide(Workspace, entry.Key, entry.Value)))));
 }
Beispiel #6
0
        public void SetData(WorkspaceData workspaceData)
        {
            var dataFileIds =
                _alignments.Keys.Select(key => key.FromId)
                .Concat(_alignments.Keys.Select(key => key.ToId))
                .Distinct()
                .ToArray();
            var changedDataFileIds = new HashSet <long>();

            foreach (var dataFileId in dataFileIds)
            {
                if (!Equals(GetRetentionTimes(dataFileId), GetRetentionTimes(workspaceData, dataFileId)))
                {
                    changedDataFileIds.Add(dataFileId);
                }
            }
            if (changedDataFileIds.Count > 0)
            {
                _alignments = ImmutableSortedList.FromValues(
                    _alignments.Where(pair
                                      => !changedDataFileIds.Contains(pair.Key.FromId) &&
                                      !changedDataFileIds.Contains(pair.Key.ToId)));
            }
            WorkspaceData = workspaceData;
        }
Beispiel #7
0
 public void AddAlignment(AlignmentKey alignmentKey, RetentionTimeAlignment alignmentValue)
 {
     _alignments = ImmutableSortedList.FromValues(
         _alignments.Concat(new[]
     {
         new KeyValuePair <AlignmentKey, RetentionTimeAlignment>(alignmentKey, alignmentValue)
     }));
 }
Beispiel #8
0
        public void SetSetting <T>(SettingEnum settingEnum, T value)
        {
            var strName   = settingEnum.ToString();
            var strValue  = Equals(value, default(T)) ? null : value.ToString();
            var newValues = Data.Where(pair => !Equals(pair.Key, strName)).ToList();

            newValues.Add(new KeyValuePair <string, string>(strName, strValue));
            Data = ImmutableSortedList.FromValues(newValues);
        }
Beispiel #9
0
        public static TracerPercentFormula Parse(string formula)
        {
            var           result          = new Dictionary <string, double>();
            string        currentElement  = null;
            StringBuilder currentQuantity = new StringBuilder();

            for (int ich = 0; ich < formula.Length; ich++)
            {
                char ch = formula[ich];
                if (ch == '%')
                {
                    continue;
                }

                if (char.IsDigit(ch) || ch == '.')
                {
                    currentQuantity.Append(ch);
                }
                else if (Char.IsUpper(ch))
                {
                    if (currentElement != null)
                    {
                        double quantity = currentQuantity.Length == 0 ? 100 : double.Parse(currentQuantity.ToString());
                        if (result.ContainsKey(currentElement))
                        {
                            result[currentElement] = result[currentElement] + quantity;
                        }
                        else
                        {
                            result[currentElement] = quantity;
                        }
                    }
                    currentQuantity = new StringBuilder();
                    currentElement  = "" + ch;
                }
                else if (Char.IsLower(ch))
                {
                    currentElement = currentElement + ch;
                }
            }
            if (currentElement != null)
            {
                double quantity = currentQuantity.Length == 0 ? 100 : double.Parse(currentQuantity.ToString());
                if (result.ContainsKey(currentElement))
                {
                    result[currentElement] = result[currentElement] + quantity;
                }
                else
                {
                    result[currentElement] = quantity;
                }
            }
            return(new TracerPercentFormula {
                Dictionary = ImmutableSortedList.FromValues(result)
            });
        }
Beispiel #10
0
 public ChromatogramSetData(DbChromatogramSet chromatogramSet, IEnumerable <DbChromatogram> chromatograms)
 {
     Times         = ImmutableList.ValueOf(chromatogramSet.Times);
     ScanIndexes   = ImmutableList.ValueOf(chromatogramSet.ScanIndexes);
     Chromatograms =
         ImmutableSortedList.FromValues(
             chromatograms.Select(
                 chromatogram =>
                 new KeyValuePair <MzKey, Chromatogram>(chromatogram.MzKey, new Chromatogram(chromatogram))));
 }
Beispiel #11
0
 public ChromatogramSetData(AnalysisChromatograms analysisChromatograms)
 {
     Times         = ImmutableList.ValueOf(analysisChromatograms.Times);
     ScanIndexes   = ImmutableList.ValueOf(analysisChromatograms.ScanIndexes);
     Chromatograms = ImmutableSortedList.FromValues(analysisChromatograms.Chromatograms.Select(
                                                        chromatogram =>
                                                        new KeyValuePair <MzKey, Chromatogram>(
                                                            chromatogram.MzKey,
                                                            new Chromatogram(chromatogram))));
 }
Beispiel #12
0
        public PeptideAnalysisData UnloadChromatograms()
        {
            var fileAnalyses = FileAnalyses.Select(entry => new KeyValuePair <long, PeptideFileAnalysisData>(
                                                       entry.Key, entry.Value.UnloadChromatograms()));

            return(new PeptideAnalysisData(this)
            {
                ChromatogramsWereLoaded = false,
                FileAnalyses = ImmutableSortedList.FromValues(fileAnalyses),
            });
        }
        protected override ImmutableSortedList <long, PeptideAnalysis> CreateEntityList()
        {
            var data = Workspace.Data.PeptideAnalyses;

            if (data == null)
            {
                return(ImmutableSortedList <long, PeptideAnalysis> .EMPTY);
            }
            return
                (ImmutableSortedList.FromValues(data.Select(entry => new KeyValuePair <long, PeptideAnalysis>(
                                                                entry.Key, new PeptideAnalysis(Workspace, entry.Key, entry.Value)))));
        }
Beispiel #14
0
        protected override ImmutableSortedList <long, MsDataFile> CreateEntityList()
        {
            var data = Workspace.Data.MsDataFiles;

            if (data == null)
            {
                return(ImmutableSortedList <long, MsDataFile> .EMPTY);
            }
            return
                (ImmutableSortedList.FromValues(data.Select(entry => new KeyValuePair <long, MsDataFile>(
                                                                entry.Key, new MsDataFile(Workspace, entry.Key, entry.Value)))));
        }
Beispiel #15
0
        public virtual WorkspaceData Merge(WorkspaceData newData)
        {
            var baseList  = GetData(Workspace.SavedData);
            var myList    = GetData(Workspace.Data);
            var theirList = GetData(newData);

            if (myList == null)
            {
                return(newData);
            }
            if (baseList == null || theirList == null)
            {
                return(SetData(newData, myList));
            }

            if (Equals(baseList, theirList) || Equals(myList, theirList))
            {
                return(SetData(newData, myList));
            }
            var mergedList = new Dictionary <TKey, TData>(myList.AsDictionary());

            foreach (var entry in theirList)
            {
                TData myData;
                if (!mergedList.TryGetValue(entry.Key, out myData))
                {
                    mergedList.Add(entry.Key, entry.Value);
                    continue;
                }
                TData baseData;
                if (baseList.TryGetValue(entry.Key, out baseData))
                {
                    if (!CheckDirty(baseData, myData))
                    {
                        mergedList[entry.Key] = entry.Value;
                    }
                    else
                    {
                        if (CheckDirty(myData, entry.Value))
                        {
                            Console.Out.WriteLine("Unable to merge {0}", entry.Key);
                        }
                    }
                }
            }
            foreach (var deletedKey in baseList.Keys.Except(theirList.Keys))
            {
                mergedList.Remove(deletedKey);
            }
            return(SetData(newData, ImmutableSortedList.FromValues(mergedList, theirList.KeyComparer)));
        }
Beispiel #16
0
        public PsmTimes(IEnumerable <DbPeptideSpectrumMatch> psms)
        {
            var values = new List <KeyValuePair <PsmKey, IList <double> > >();

            foreach (var grouping in psms.ToLookup(psm => new PsmKey(psm), psm => psm.RetentionTime))
            {
                var times = grouping.Distinct().ToArray();
                if (times.Length == 0)
                {
                    continue;
                }
                Array.Sort(times);
                values.Add(new KeyValuePair <PsmKey, IList <double> >(grouping.Key, times));
            }
            _sortedList = ImmutableSortedList.FromValues(values);
        }
Beispiel #17
0
        private ImmutableSortedList <ResultKey, Replicate> CreateReplicateList()
        {
            var srmDocument = Document;

            if (!srmDocument.Settings.HasResults)
            {
                return(ImmutableSortedList <ResultKey, Replicate> .EMPTY);
            }
            return(ImmutableSortedList <ResultKey, Replicate> .FromValues(
                       Enumerable.Range(0, srmDocument.Settings.MeasuredResults.Chromatograms.Count)
                       .Select(replicateIndex =>
            {
                var replicate = new Replicate(this, replicateIndex);
                return new KeyValuePair <ResultKey, Replicate>(new ResultKey(replicate, 0), replicate);
            }), Comparer <ResultKey> .Default));
        }
Beispiel #18
0
        private void BtnOkOnClick(object sender, EventArgs e)
        {
            var modifications = new Dictionary <String, double>();

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                var row       = dataGridView1.Rows[i];
                var deltaMass = Convert.ToDouble(row.Cells[colMassDelta.Index].Value);
                if (deltaMass == 0)
                {
                    continue;
                }
                modifications[Convert.ToString(row.Cells[colSymbol.Index].Value)] = deltaMass;
            }
            Workspace.Data = Workspace.Data.SetModifications(ImmutableSortedList.FromValues(modifications));
            Close();
        }
Beispiel #19
0
        public void TestBinarySearch()
        {
            int seed = (int)DateTime.Now.Ticks;

            Console.Out.WriteLine("ImmutableSortedList.TestBinarySearch seed: {0}", seed);
            int    iteration = 0;
            Random random    = new Random(seed);

            for (int maxValue = 10; maxValue < 1000; maxValue *= 10)
            {
                int size = random.Next(maxValue * 2);
                var list = new List <int>(size);
                while (list.Count < size)
                {
                    list.Add(random.Next(maxValue));
                }
                var immutableSortedList = ImmutableSortedList.FromValues(list.Select(i => new KeyValuePair <int, int>(i, i)));
                list.Sort();
                CollectionAssert.AreEqual(list, immutableSortedList.Keys.ToArray());
                for (int key = -1; key < maxValue + 1; key++)
                {
                    var msg = "Iteration #" + iteration + ": Searching for " + key + " in [" + string.Join(",", list.ToArray()) + "]";
                    iteration++;
                    int key1       = key;
                    int firstIndex = CollectionUtil.BinarySearch(list, i => i.CompareTo(key1), true);
                    int lastIndex  = CollectionUtil.BinarySearch(list, i => i.CompareTo(key1), false);
                    Assert.IsTrue(firstIndex <= lastIndex);
                    var range = immutableSortedList.BinarySearch(key);
                    if (range.Length <= 0)
                    {
                        Assert.AreEqual(0, range.Length, msg);
                        Assert.AreEqual(~firstIndex, range.Start, msg);
                        Assert.AreEqual(~lastIndex, range.End, msg);
                    }
                    else
                    {
                        Assert.AreEqual(firstIndex, range.Start, msg);
                        Assert.AreEqual(lastIndex + 1, range.End, msg);
                    }
                    Assert.IsTrue(range.Start == list.Count || list[range.Start] >= key);
                    Assert.IsTrue(range.End == list.Count || list[range.End] > key);
                    Assert.IsTrue(range.Start == 0 || list[range.Start - 1] < key);
                }
            }
        }
Beispiel #20
0
        public static PeptideFormatter MakePeptideFormatter(SrmSettings srmSettings, Peptide peptide,
                                                            ExplicitMods explicitMods, ICollection <IsotopeLabelType> heavyLabelTypes,
                                                            ModFontHolder modFontHolder)
        {
            var lightModifiedSequence =
                ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence, explicitMods, IsotopeLabelType.light);
            var heavyModifiedSequences = new List <KeyValuePair <IsotopeLabelType, ModifiedSequence> >();

            foreach (var labelType in srmSettings.PeptideSettings.Modifications.GetHeavyModificationTypes())
            {
                if (!heavyLabelTypes.Contains(labelType))
                {
                    continue;
                }

                heavyModifiedSequences.Add(new KeyValuePair <IsotopeLabelType, ModifiedSequence>(labelType,
                                                                                                 ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence, explicitMods, labelType)));
            }

            var peptideFormatter = new PeptideFormatter(srmSettings, lightModifiedSequence, heavyModifiedSequences, modFontHolder);

            if (explicitMods != null && explicitMods.HasCrosslinks)
            {
                var linkedPeptides = new List <KeyValuePair <ModificationSite, PeptideFormatter> >();
                foreach (var entry in explicitMods.Crosslinks)
                {
                    if (entry.Value.Peptide == null)
                    {
                        continue;
                    }

                    var childFormatter = MakePeptideFormatter(srmSettings, entry.Value.Peptide,
                                                              entry.Value.ExplicitMods, heavyLabelTypes, modFontHolder)
                                         .ChangeCrosslinkedIndexAa(entry.Value.IndexAa);
                    linkedPeptides.Add(new KeyValuePair <ModificationSite, PeptideFormatter>(entry.Key, childFormatter));
                }

                peptideFormatter = peptideFormatter
                                   .ChangeLinkedPeptides(ImmutableSortedList.FromValues(linkedPeptides));
            }

            return(peptideFormatter);
        }
Beispiel #21
0
        public virtual void Update(WorkspaceChangeArgs workspaceChange)
        {
            if (null == _entityList)
            {
                return;
            }
            var  newData = GetData(Workspace.Data) ?? ImmutableSortedList <TKey, TData> .EMPTY;
            var  newKeys = new HashSet <TKey>(newData.Keys);
            bool changed = !Equals(newData.Keys, _entityList.Keys);

            if (changed)
            {
                var entities = new Dictionary <TKey, TEntity>(_entityList.AsDictionary());
                foreach (var key in newKeys)
                {
                    TEntity entity;
                    if (!entities.TryGetValue(key, out entity))
                    {
                        TData itemData;
                        newData.TryGetValue(key, out itemData);
                        entities.Add(key, CreateEntityForKey(key, itemData));
                    }
                }
                _entityList = ImmutableSortedList.FromValues(entities, _entityList.KeyComparer);
            }
            foreach (var entity in _entityList.Values)
            {
                TData itemData;
                var   key = GetKey(entity);
                newData.TryGetValue(key, out itemData);
                entity.Update(workspaceChange, itemData);
            }
            if (changed)
            {
                var listChanged = ListChanged;
                if (listChanged != null)
                {
                    listChanged(this, new ListChangedEventArgs(ListChangedType.Reset, -1));
                }
            }
        }
Beispiel #22
0
        public void MergeFrom(RetentionTimeAlignments retentionTimeAlignments)
        {
            var newAlignments = new List <KeyValuePair <AlignmentKey, RetentionTimeAlignment> >();

            foreach (var pair in retentionTimeAlignments._alignments)
            {
                if (_alignments.ContainsKey(pair.Key))
                {
                    continue;
                }
                if (Equals(GetRetentionTimes(pair.Key.FromId), retentionTimeAlignments.GetRetentionTimes(pair.Key.FromId)) &&
                    Equals(GetRetentionTimes(pair.Key.ToId), retentionTimeAlignments.GetRetentionTimes(pair.Key.ToId)))
                {
                    newAlignments.Add(pair);
                }
            }
            if (newAlignments.Count == 0)
            {
                return;
            }
            _alignments = ImmutableSortedList.FromValues(_alignments.Concat(newAlignments));
        }
Beispiel #23
0
        public ComplexFragmentIon AddChild(ModificationSite modificationSite, ComplexFragmentIon child)
        {
            if (IsOrphan && !IsEmptyOrphan)
            {
                throw new InvalidOperationException(string.Format(@"Cannot add {0} to {1}.", child, this));
            }

            if (child.Transition.MassIndex != 0)
            {
                throw new InvalidOperationException(string.Format(@"{0} cannot be a child fragment ion transition.", child.Transition));
            }

            var newLosses = TransitionLosses;

            if (child.TransitionLosses != null)
            {
                if (newLosses == null)
                {
                    newLosses = child.TransitionLosses;
                }
                else
                {
                    newLosses = new TransitionLosses(newLosses.Losses.Concat(child.TransitionLosses.Losses).ToList(), newLosses.MassType);
                }

                child = child.ChangeLosses(null);
            }

            return(ChangeProp(ImClone(this), im =>
            {
                im.Children =
                    ImmutableSortedList.FromValues(Children.Append(
                                                       new KeyValuePair <ModificationSite, ComplexFragmentIon>(
                                                           modificationSite, child)));
                im.TransitionLosses = newLosses;
            }));
        }
Beispiel #24
0
        public MoleculeAccessionNumbers(string keysTSV, string inChiKey = null)
        {
            var keys = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); // Treat "cas" and "CAS" as identical lookups

            if (!string.IsNullOrEmpty(keysTSV) || !string.IsNullOrEmpty(inChiKey))
            {
                if (!string.IsNullOrEmpty(keysTSV))
                {
                    // Pick apart a string like "CAS:58-08-2\tinchi:1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3\tmykey:a:b:c:d"
                    foreach (var kvp in keysTSV.Split(TextUtil.SEPARATOR_TSV))
                    {
                        var pair = kvp.Split(':');
                        if (pair.Length > 1)
                        {
                            var key   = pair[0].Trim();
                            var value = string.Join(":", pair.Skip(1)).Trim(); // In case value contains semicolons // Not L10N
                            if (!string.IsNullOrEmpty(value))
                            {
                                keys.Add(key, value);
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(inChiKey))
                {
                    if (keys.ContainsKey(TagInChiKey))
                    {
                        Assume.AreEqual(inChiKey, keys[TagInChiKey]);
                    }
                    else
                    {
                        keys.Add(TagInChiKey, inChiKey);
                    }
                }
            }
            AccessionNumbers = ImmutableSortedList <string, string> .FromValues(keys, ACCESSION_TYPE_SORTER);
        }
Beispiel #25
0
        public static Dictionary <long, PeptideAnalysisData> Query(ISession session, IdPredicate peptideAnalysisIds, IdPredicate chromatogramsToSnapshot)
        {
            if (peptideAnalysisIds.AlwaysFalse)
            {
                return(new Dictionary <long, PeptideAnalysisData>());
            }
            string selectAnalyses  = "FROM " + typeof(DbPeptideAnalysis) + " T WHERE " + peptideAnalysisIds.GetSql("T.Id");
            var    query           = session.CreateQuery(selectAnalyses);
            var    peptideAnalyses = new List <DbPeptideAnalysis>();

            query.List(peptideAnalyses);
            var peptideAnalysisSnapshots = peptideAnalyses.ToDictionary(a => a.Id.GetValueOrDefault(), a => new PeptideAnalysisData(a));

            foreach (var entry in QueryFileAnalyses(session, peptideAnalysisIds))
            {
                PeptideAnalysisData snapshot;
                if (!peptideAnalysisSnapshots.TryGetValue(entry.Key, out snapshot))
                {
                    Trace.TraceWarning("DbPeptideAnalysis with Id {0} not found", entry.Key);
                    continue;
                }
                peptideAnalysisSnapshots[entry.Key] =
                    snapshot.SetFileAnalyses(ImmutableSortedList.FromValues(entry.Value));
            }

            if (!chromatogramsToSnapshot.AlwaysFalse)
            {
                var chromatogramSetsByFileAnalysisId = QueryChromatogramSets(session, chromatogramsToSnapshot);
                var peptideIds          = peptideAnalysisSnapshots.Values.Select(snapshot => snapshot.PeptideId).ToArray();
                var psmTimesByPeptideId = LoadPsmTimesByPeptideAndFile(session, peptideIds);
                foreach (var entry in peptideAnalysisSnapshots.ToArray())
                {
                    if (!chromatogramsToSnapshot.Matches(entry.Key))
                    {
                        continue;
                    }
                    var peptideAnalysisData = entry.Value;
                    IDictionary <long, PsmTimes> psmTimesByDataFileId;
                    psmTimesByPeptideId.TryGetValue(entry.Value.PeptideId, out psmTimesByDataFileId);
                    var fileAnalysisEntries = entry.Value.FileAnalyses.ToArray();
                    for (int i = 0; i < fileAnalysisEntries.Length; i++)
                    {
                        var pair         = fileAnalysisEntries[i];
                        var fileAnalysis = pair.Value;
                        ChromatogramSetData chromatogramSetData;
                        if (chromatogramSetsByFileAnalysisId.TryGetValue(pair.Key, out chromatogramSetData))
                        {
                            fileAnalysis = fileAnalysis.SetChromatogramSet(chromatogramSetData);
                        }
                        if (null != psmTimesByDataFileId)
                        {
                            PsmTimes psmTimes;
                            if (psmTimesByDataFileId.TryGetValue(pair.Value.MsDataFileId, out psmTimes))
                            {
                                fileAnalysis = fileAnalysis.SetPsmTimes(psmTimes);
                            }
                        }
                        fileAnalysisEntries[i] = new KeyValuePair <long, PeptideFileAnalysisData>(pair.Key, fileAnalysis);
                    }
                    peptideAnalysisData = peptideAnalysisData
                                          .SetFileAnalyses(ImmutableSortedList.FromValues(fileAnalysisEntries), true);
                    peptideAnalysisSnapshots[entry.Key] = peptideAnalysisData;
                }
            }
            return(peptideAnalysisSnapshots);
        }
Beispiel #26
0
        public MoleculeAccessionNumbers(IDictionary <string, string> keys)
        {
            var nonEmptyKeys = keys == null ? new KeyValuePair <string, string>[] {} : keys.Where(kvp => !string.IsNullOrEmpty(kvp.Value)).ToArray();

            AccessionNumbers = ImmutableSortedList <string, string> .FromValues(nonEmptyKeys, ACCESSION_TYPE_SORTER);
        }
Beispiel #27
0
        private void UpdatePeptides(Dictionary <string, ProteinData> allProteins)
        {
            var peptideIndex = CreatePeptideIndex(allProteins.Keys);

            if (peptideIndex == null)
            {
                return;
            }
            for (int retryCount = 0; ; retryCount++)
            {
                var originalPeptides = Workspace.Data.Peptides;
                var peptides         = originalPeptides.ToArray();
                for (int i = 0; i < peptides.Length; i++)
                {
                    string message = string.Format("Peptide {0}/{1}", i, peptides.Length);
                    if (retryCount > 0)
                    {
                        message += string.Format(" (Retry #{0})", retryCount);
                    }
                    if (!UpdateProgress(message, 100 * i / peptides.Length))
                    {
                        return;
                    }
                    var peptide          = peptides[i].Value;
                    var proteinSequences = FindPeptides(peptide.Sequence, peptideIndex);
                    if (proteinSequences.Count == 0)
                    {
                        continue;
                    }
                    var names   = new SortedDictionary <String, String>();
                    var prevAAs = new List <string>();
                    var nextAAs = new List <string>();
                    foreach (var proteinSequence in proteinSequences)
                    {
                        var proteinData = allProteins[proteinSequence];
                        names[proteinData.GetName()] = proteinData.GetDescription();
                        for (int ichPeptide = proteinSequence.IndexOf(peptide.Sequence, StringComparison.Ordinal);
                             ichPeptide >= 0;
                             ichPeptide = proteinSequence.IndexOf(peptide.Sequence, ichPeptide + 1, StringComparison.Ordinal))
                        {
                            if (ichPeptide == 0)
                            {
                                prevAAs.Add("-");
                            }
                            else
                            {
                                prevAAs.Add(proteinSequence.Substring(ichPeptide - 1, 1));
                            }
                            int ichPeptideEnd = ichPeptide + peptide.Sequence.Length;
                            if (ichPeptideEnd == proteinSequence.Length)
                            {
                                nextAAs.Add("-");
                            }
                            else
                            {
                                nextAAs.Add(proteinSequence.Substring(ichPeptideEnd, 1));
                            }
                        }
                    }
                    string fullSequence;
                    if (prevAAs.Distinct().Count() == 1)
                    {
                        fullSequence = prevAAs[0] + ".";
                    }
                    else
                    {
                        fullSequence = "?.";
                    }
                    fullSequence += peptide.Sequence;
                    if (nextAAs.Distinct().Count() == 1)
                    {
                        fullSequence += "." + nextAAs[0];
                    }
                    else
                    {
                        fullSequence += ".?";
                    }
                    peptide = peptide.SetFullSequence(fullSequence)
                              .SetProteinName(string.Join("\r\n", names.Keys.ToArray()))
                              .SetProteinDescription(string.Join("\r\n---\r\n", names.Values.ToArray()));
                    peptides[i] = new KeyValuePair <long, PeptideData>(peptides[i].Key, peptide);
                }
                bool success = Workspace.RunOnEventQueue(() =>
                {
                    if (!Equals(originalPeptides, Workspace.Data.Peptides))
                    {
                        return(false);
                    }
                    Workspace.Data = Workspace.Data.SetPeptides(ImmutableSortedList.FromValues(peptides));
                    return(true);
                });
                if (success)
                {
                    return;
                }
            }
        }
Beispiel #28
0
 // Handle formulae which may contain subtractions, as is deprotonation description ie C12H8O2-H (=C12H7O2) or even C12H8O2-H2O (=C12H6O)
 public static T ParseExpression(String formula)
 {
     return(new T {
         Dictionary = ImmutableSortedList.FromValues(ParseExpressionToDictionary(formula))
     });
 }
 protected override ImmutableSortedList <long, PeptideFileAnalysis> CreateEntityList()
 {
     return(ImmutableSortedList.FromValues(
                PeptideAnalysis.Data.FileAnalyses.Select(
                    pair => new KeyValuePair <long, PeptideFileAnalysis>(pair.Key, new PeptideFileAnalysis(PeptideAnalysis, pair.Key, pair.Value)))));
 }
Beispiel #30
0
 public static T FromDict(IDictionary <string, int> dict)
 {
     return(new T {
         Dictionary = ImmutableSortedList.FromValues(dict)
     });
 }