public void AddAlignment(AlignmentKey alignmentKey, RetentionTimeAlignment alignmentValue)
 {
     _alignments = ImmutableSortedList.FromValues(
             _alignments.Concat(new[]
                 {
                     new KeyValuePair<AlignmentKey, RetentionTimeAlignment>(alignmentKey, alignmentValue)
                 }));
 }
 public ReplicateSummaries(SrmDocument document)
 {
     Document = document;
     int replicateCount = 0;
     if (Document.Settings.HasResults)
     {
         replicateCount = Document.Settings.MeasuredResults.Chromatograms.Count;
     }
     _allTotalAreas = new ImmutableSortedList<IsotopeLabelType, double>[replicateCount];
 }
 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 #4
0
 public PeptideFormatter ChangeLinkedPeptides(
     ImmutableSortedList <ModificationSite, PeptideFormatter> linkedPeptides)
 {
     return(ChangeProp(ImClone(this), im => im.LinkedPeptides = linkedPeptides));
 }
Beispiel #5
0
        public WorkspaceData LoadChanges(WorkspaceData savedData, IDictionary <long, bool> requestedPeptideAnalyses)
        {
            var workspaceData = savedData;

            lock (_eventWaitHandle)
            {
                if (!_isRunning)
                {
                    return(null);
                }
            }
            var peptides        = ToMutableDictionary(workspaceData.Peptides);
            var msDataFiles     = ToMutableDictionary(workspaceData.MsDataFiles);
            var peptideAnalyses = ToMutableDictionary(workspaceData.PeptideAnalyses);

            using (var session = _workspace.OpenSession())
            {
                var  changedPeptideIds         = new HashSet <long>();
                var  changedDataFileIds        = new HashSet <long>();
                var  changedPeptideAnalysisIds = new HashSet <long>();
                bool workspaceChanged          = false;
                if (workspaceData.LastChangeLogId.HasValue)
                {
                    long lastChangeLogId = workspaceData.LastChangeLogId.Value;
                    var  changeLogs      = session.CreateCriteria <DbChangeLog>()
                                           .Add(Restrictions.Gt("Id", workspaceData.LastChangeLogId))
                                           .List <DbChangeLog>();
                    foreach (var dbChangeLog in changeLogs)
                    {
                        if (dbChangeLog.PeptideId.HasValue)
                        {
                            changedPeptideIds.Add(dbChangeLog.PeptideId.Value);
                            peptides.Remove(dbChangeLog.PeptideId.Value);
                        }
                        if (dbChangeLog.MsDataFileId.HasValue)
                        {
                            changedDataFileIds.Add(dbChangeLog.MsDataFileId.Value);
                            msDataFiles.Remove(dbChangeLog.MsDataFileId.Value);
                        }
                        if (dbChangeLog.PeptideAnalysisId.HasValue)
                        {
                            changedPeptideAnalysisIds.Add(dbChangeLog.PeptideAnalysisId.Value);
                            peptideAnalyses.Remove(dbChangeLog.PeptideAnalysisId.Value);
                        }
                        if (dbChangeLog.WorkspaceId.HasValue)
                        {
                            workspaceChanged = true;
                        }
                        lastChangeLogId = Math.Max(lastChangeLogId, dbChangeLog.GetId());
                    }
                    workspaceData = workspaceData.SetLastChangeLogId(lastChangeLogId);
                }
                else
                {
                    workspaceChanged = true;
                    long lastChangeLogId = (long?)session.CreateQuery("SELECT Max(T.Id) FROM " + typeof(DbChangeLog) + " T")
                                           .UniqueResult() ?? 0;
                    var dbWorkspace = session.CreateCriteria <DbWorkspace>().UniqueResult <DbWorkspace>();
                    workspaceData = workspaceData
                                    .SetLastChangeLogId(lastChangeLogId)
                                    .SetDbWorkspaceId(dbWorkspace.Id);
                }

                if (workspaceChanged)
                {
                    var settings =
                        session.CreateCriteria <DbSetting>()
                        .List <DbSetting>()
                        .ToDictionary(dbSetting => dbSetting.Name, dbSetting => dbSetting.Value);
                    var tracerDefs =
                        session.CreateCriteria <DbTracerDef>()
                        .List <DbTracerDef>()
                        .ToDictionary(dbTracerDef => dbTracerDef.Name,
                                      dbTracerDef => new TracerDefData(dbTracerDef));
                    var modifications =
                        session.CreateCriteria <DbModification>()
                        .List <DbModification>()
                        .ToDictionary(dbModification => dbModification.Symbol,
                                      dbModification => dbModification.DeltaMass);
                    workspaceData = workspaceData
                                    .SetSettings(ImmutableSortedList.FromValues(settings))
                                    .SetTracerDefs(ImmutableSortedList.FromValues(tracerDefs))
                                    .SetModifications(ImmutableSortedList.FromValues(modifications));
                }

                foreach (var dbPeptide in EntitiesWithIdGreaterThanOrOneOf <DbPeptide>(session, GetLastId(savedData.Peptides), changedPeptideIds))
                {
                    peptides.Add(dbPeptide.GetId(), new PeptideData(dbPeptide));
                }
                workspaceData = workspaceData.SetPeptides(ImmutableSortedList.FromValues(peptides));

                // Load the MSDataFiles
                var dataFileIdPredicate = new IdPredicate(GetLastId(savedData.MsDataFiles), changedDataFileIds);
                var psmsByDataFileId    = session.CreateQuery("FROM " + typeof(DbPeptideSpectrumMatch) + " M WHERE " +
                                                              dataFileIdPredicate.GetSql("M.MsDataFile.Id")).List <DbPeptideSpectrumMatch>().ToLookup(psm => psm.MsDataFile.Id);
                foreach (var dbMsDataFile in EntitiesWithIdGreaterThanOrOneOf <DbMsDataFile>(session, GetLastId(savedData.MsDataFiles), changedDataFileIds))
                {
                    var msDataFileData = new MsDataFileData(dbMsDataFile);
                    var psmTimes       = psmsByDataFileId[dbMsDataFile.GetId()].ToLookup(psm => psm.ModifiedSequence, psm => psm.RetentionTime);
                    msDataFileData = msDataFileData.SetRetentionTimesByModifiedSequence(
                        psmTimes.Select(grouping => new KeyValuePair <string, double>(grouping.Key, grouping.Min())));
                    msDataFiles.Add(dbMsDataFile.GetId(), msDataFileData);
                }

                workspaceData = workspaceData.SetMsDataFiles(ImmutableSortedList.FromValues(msDataFiles));
                var idsToSnapshot           = new HashSet <long>(changedPeptideAnalysisIds);
                var chromatogramsToSnapshot = new HashSet <long>();
                if (null != requestedPeptideAnalyses)
                {
                    foreach (var pair in requestedPeptideAnalyses)
                    {
                        PeptideAnalysisData existing;
                        if (peptideAnalyses.TryGetValue(pair.Key, out existing))
                        {
                            if (pair.Value)
                            {
                                if (existing.ChromatogramsWereLoaded)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                peptideAnalyses[pair.Key] = existing.UnloadChromatograms();
                                continue;
                            }
                        }
                        idsToSnapshot.Add(pair.Key);
                        if (pair.Value)
                        {
                            chromatogramsToSnapshot.Add(pair.Key);
                        }
                    }
                }
                var loadedPeptideAnalyses = PeptideAnalysisSnapshot.Query(session,
                                                                          new IdPredicate(GetLastId(workspaceData.PeptideAnalyses) + 1, idsToSnapshot),
                                                                          new IdPredicate(null, chromatogramsToSnapshot));
                foreach (var entry in loadedPeptideAnalyses)
                {
                    peptideAnalyses[entry.Key] = entry.Value;
                }
                workspaceData = workspaceData.SetPeptideAnalyses(ImmutableSortedList.FromValues(peptideAnalyses));
            }

            return(workspaceData);
        }
 public PeptideAnalysisData SetFileAnalyses(ImmutableSortedList<long, PeptideFileAnalysisData> value)
 {
     return new PeptideAnalysisData(this) {FileAnalyses = value};
 }
Beispiel #7
0
 protected abstract WorkspaceData SetData(WorkspaceData workspaceData, ImmutableSortedList <TKey, TData> data);
Beispiel #8
0
 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 #9
0
 public WorkspaceData SetModifications(ImmutableSortedList<string, double> value)
 {
     return new WorkspaceData(this){Modifications = value};
 }
Beispiel #10
0
 public static T FromDict(IDictionary <string, int> dict)
 {
     return(new T {
         Dictionary = ImmutableSortedList.FromValues(dict)
     });
 }
Beispiel #11
0
 public static T FromDict(ImmutableSortedList <string, int> dict)
 {
     return(new T {
         Dictionary = dict
     });
 }
Beispiel #12
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))
     });
 }
Beispiel #13
0
        protected IDictionary <ResultKey, TResult> MakeChromInfoResultsMap <TChromInfo, TResult>(
            Results <TChromInfo> results, Func <ResultFile, TResult> newResultFunc) where TChromInfo : ChromInfo
        {
            if (results == null)
            {
                return(ImmutableSortedList <ResultKey, TResult> .EMPTY.AsDictionary());
            }
            var replicates  = DataSchema.ReplicateList;
            var resultFiles = DataSchema.ResultFileList;

            if (replicates.Count == results.Count && results.All(r => r.Count == 1 && r[0] != null))
            {
                // If every replicate has exactly one result, then we can reuse the keys in "DataSchema.ReplicateList".
                var newValues = new List <TResult>(replicates.Count);
                for (int replicateIndex = 0; replicateIndex < replicates.Count; replicateIndex++)
                {
                    var        chromInfo  = results[replicateIndex][0];
                    var        optStep    = ResultFile.GetOptStep(chromInfo);
                    ResultFile resultFile = null;
                    if (optStep == 0)
                    {
                        resultFiles.TryGetValue(new ResultFileKey(replicateIndex, chromInfo.FileId, optStep), out resultFile);
                    }
                    if (resultFile == null)
                    {
                        resultFile = new ResultFile(replicates.Values[replicateIndex], chromInfo.FileId, optStep);
                    }
                    newValues.Add(newResultFunc(resultFile));
                }
                return(replicates.ReplaceValues(newValues).AsDictionary());
            }
            var newEntries = new List <KeyValuePair <ResultKey, TResult> >();

            for (int replicateIndex = 0; replicateIndex < results.Count; replicateIndex++)
            {
                var replicate = new Replicate(DataSchema, replicateIndex);
                var files     = results[replicateIndex];
                for (int fileIndex = 0; fileIndex < files.Count; fileIndex++)
                {
                    var chromInfo = files[fileIndex];
                    if (null == chromInfo)
                    {
                        continue;
                    }
                    var        key        = fileIndex == 0 ? replicates.Keys[replicateIndex] : new ResultKey(replicate, fileIndex);
                    int        optStep    = ResultFile.GetOptStep(chromInfo);
                    ResultFile resultFile = null;
                    if (optStep == 0)
                    {
                        resultFiles.TryGetValue(new ResultFileKey(replicateIndex, chromInfo.FileId, optStep), out resultFile);
                    }
                    if (resultFile == null)
                    {
                        resultFile = new ResultFile(replicates.Values[replicateIndex], chromInfo.FileId, optStep);
                    }
                    newEntries.Add(new KeyValuePair <ResultKey, TResult>(key, newResultFunc(resultFile)));
                }
            }
            return(ImmutableSortedList <ResultKey, TResult> .FromValues(newEntries, Comparer <ResultKey> .Default)
                   .AsDictionary());
        }
 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 #15
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 #16
0
 public WorkspaceData SetMsDataFiles(ImmutableSortedList<long, MsDataFileData> value)
 {
     return new WorkspaceData(this){MsDataFiles = value};
 }
Beispiel #17
0
 protected override WorkspaceData SetData(WorkspaceData workspaceData, ImmutableSortedList <long, PeptideAnalysisData> data)
 {
     return(workspaceData.SetPeptideAnalyses(data));
 }
Beispiel #18
0
 public WorkspaceData SetPeptides(ImmutableSortedList<long, PeptideData> value)
 {
     return new WorkspaceData(this){Peptides = value};
 }
Beispiel #19
0
 protected override WorkspaceData SetData(WorkspaceData workspaceData, ImmutableSortedList <long, MsDataFileData> data)
 {
     return(workspaceData.SetMsDataFiles(data));
 }
Beispiel #20
0
 public WorkspaceData SetSettings(ImmutableSortedList<string, string> value)
 {
     return new WorkspaceData(this){Settings = value};
 }
Beispiel #21
0
 public void CompareValues(WorkspaceChangeArgs workspaceChange, ImmutableSortedList <TKey, TValue> newValues)
 {
     Diff(workspaceChange, newValues, Data);
 }
Beispiel #22
0
 public WorkspaceData SetTracerDefs(ImmutableSortedList<string, TracerDefData> value)
 {
     return new WorkspaceData(this){TracerDefs = value};
 }
 public PeptideAnalysisData SetFileAnalyses(ImmutableSortedList<long, PeptideFileAnalysisData> fileAnalyses, bool chromatogramsWereLoaded)
 {
     return new PeptideAnalysisData(this)
                {
                    ChromatogramsWereLoaded = chromatogramsWereLoaded,
                    FileAnalyses = fileAnalyses,
                };
 }
 public RetentionTimeAlignments(WorkspaceData workspaceData)
 {
     WorkspaceData = workspaceData;
     _alignments = ImmutableSortedList<AlignmentKey, RetentionTimeAlignment>.EMPTY;
 }