public ChromLibSpectrumInfo(LibKey key, int id, double peakArea, IndexedRetentionTimes retentionTimesByFileId, IEnumerable<SpectrumPeaksInfo.MI> transitionAreas)
 {
     Key = key;
     Id = id;
     PeakArea = peakArea;
     RetentionTimesByFileId = retentionTimesByFileId;
     TransitionAreas = ImmutableList.ValueOf(transitionAreas) ?? ImmutableList.Empty<SpectrumPeaksInfo.MI>();
 }
 public ChromLibSpectrumInfo(LibKey key, int id, double peakArea, IndexedRetentionTimes retentionTimesByFileId, IEnumerable <SpectrumPeaksInfo.MI> transitionAreas)
 {
     Key      = key;
     Id       = id;
     PeakArea = peakArea;
     RetentionTimesByFileId = retentionTimesByFileId;
     TransitionAreas        = ImmutableList.ValueOf(transitionAreas) ?? ImmutableList.Empty <SpectrumPeaksInfo.MI>();
 }
        public static ChromLibSpectrumInfo Read(Stream stream)
        {
            LibKey key      = LibKey.Read(stream);
            int    id       = PrimitiveArrays.ReadOneValue <int>(stream);
            double peakArea = PrimitiveArrays.ReadOneValue <double>(stream);
            var    retentionTimesByFileId = IndexedRetentionTimes.Read(stream);
            int    mzCount = PrimitiveArrays.ReadOneValue <int>(stream);
            var    mzs     = PrimitiveArrays.Read <double>(stream, mzCount);
            var    areas   = PrimitiveArrays.Read <float>(stream, mzCount);
            var    mzAreas = ImmutableList.ValueOf(Enumerable.Range(0, mzCount)
                                                   .Select(index => new SpectrumPeaksInfo.MI
            {
                Mz        = mzs[index],
                Intensity = areas[index]
            }));

            return(new ChromLibSpectrumInfo(key, id, peakArea, retentionTimesByFileId, mzAreas));
        }
Beispiel #4
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);
            }
        }