public static bool TryInitMsDataFile(IWin32Window parent, MsDataFile msDataFile, out string errorMessage) { bool success = false; string message = null; using (var longWaitDialog = new LongWaitDialog(parent, Program.AppName)) { new LongOperationBroker(broker => { broker.UpdateStatusMessage(string.Format("Reading retention times for {0}", msDataFile.Name)); success = MsDataFileUtil.TryInitMsDataFile(msDataFile.Workspace, msDataFile, broker.CancellationToken, out message); }, longWaitDialog).LaunchJob(); } errorMessage = message; return(success); }
public void Redisplay() { if (!IsHandleCreated) { return; } if (_inRedisplay) { return; } try { _inRedisplay = true; tbxMinCharge.Text = MinCharge.ToString(); tbxMaxCharge.Text = MaxCharge.ToString(); tbxPeptideSequence.Text = PeptideSequence; cbxShowPeptideMzs.Enabled = !string.IsNullOrEmpty(PeptideSequence); tbxMassAccuracy.Text = MassAccuracy.ToString(); TurnoverCalculator turnoverCalculator = null; if (!string.IsNullOrEmpty(PeptideSequence)) { turnoverCalculator = new TurnoverCalculator(Workspace, PeptideSequence); } msGraphControlEx1.GraphPane.GraphObjList.Clear(); msGraphControlEx1.GraphPane.CurveList.Clear(); if (_spectrumData == null || comboChromatogram.SelectedIndex >= 0 && null == _chromatogramDatas[comboChromatogram.SelectedIndex]) { using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name))) { if (comboChromatogram.SelectedIndex >= 0 && null == _chromatogramDatas[comboChromatogram.SelectedIndex]) { string chromatogramName; float[] timeArray; float[] intensityArray; msDataFileImpl.GetChromatogram(comboChromatogram.SelectedIndex, out chromatogramName, out timeArray, out intensityArray); _chromatogramDatas[comboChromatogram.SelectedIndex] = new ChromatogramData(chromatogramName, timeArray, intensityArray); } _spectrumData = _spectrumData ?? new SpectrumData(msDataFileImpl, ScanIndex); } } ChromatogramData chromatogram = null; if (comboChromatogram.SelectedIndex >= 0) { chromatogram = _chromatogramDatas[comboChromatogram.SelectedIndex]; } tbxMsLevel.Text = _spectrumData.MsLevel.ToString(); tbxTime.Text = _spectrumData.Time.ToString(); if (chromatogram != null && ScanIndex < chromatogram.TimeArray.Length) { tbxChromatogramRetentionTime.Text = chromatogram.TimeArray[ScanIndex].ToString(); tbxChromatogramIonCurrent.Text = chromatogram.IntensityArray[ScanIndex].ToString(NumberFormat); } else { tbxChromatogramRetentionTime.Text = tbxChromatogramIonCurrent.Text = @"N/A"; } if (cbxShowProfile.Checked && _spectrumData.ProfileMzs != null) { msGraphControlEx1.AddGraphItem(msGraphControlEx1.GraphPane, new SpectrumGraphItem() { Points = new PointPairList(_spectrumData.ProfileMzs, _spectrumData.ProfileIntensities), GraphItemDrawMethod = MSGraphItemDrawMethod.line, Color = Color.Blue, }); } if (_spectrumData.ProfileIntensities != null) { tbxSumOfProfileIntensities.Text = _spectrumData.ProfileIntensities.Sum().ToString(NumberFormat); } else { tbxSumOfProfileIntensities.Text = ""; } tbxCentroidIntensitySum.Text = _spectrumData.CentroidIntensities.Sum().ToString(NumberFormat); var spectrum = new SpectrumGraphItem { Points = new PointPairList(_spectrumData.CentroidMzs, _spectrumData.CentroidIntensities), GraphItemDrawMethod = MSGraphItemDrawMethod.stick, Color = Color.Black }; if (turnoverCalculator != null) { var mzRanges = new Dictionary <MzRange, String>(); double monoisotopicMass = Workspace.GetAminoAcidFormulas().GetMonoisotopicMass(PeptideSequence); double peptideIntensity = 0.0; for (int charge = MinCharge; charge <= MaxCharge; charge++) { foreach (var mzRange in turnoverCalculator.GetMzs(charge)) { double mass = (mzRange.Center - AminoAcidFormulas.ProtonMass) * charge; double massDifference = mass - monoisotopicMass; var label = massDifference.ToString("0.#"); if (label[0] != '-') { label = "+" + label; } label = "M" + label; label += new string('+', charge); mzRanges.Add(mzRange, label); var chromatogramPoint = MsDataFileUtil.GetPoint(mzRange, _spectrumData.CentroidMzs, _spectrumData.CentroidIntensities); peptideIntensity += chromatogramPoint.GetIntensity(mzRange, MassAccuracy); } } spectrum.MassAccuracy = MassAccuracy; spectrum.MzRanges = mzRanges; tbxPeptideIntensity.Text = peptideIntensity.ToString(NumberFormat); } if (cbxShowCentroids.Checked) { msGraphControlEx1.AddGraphItem(msGraphControlEx1.GraphPane, spectrum); } if (turnoverCalculator != null && cbxShowPeptideMzs.Checked) { double massAccuracy = MassAccuracy; for (int charge = MinCharge; charge <= MaxCharge; charge++) { var mzs = turnoverCalculator.GetMzs(charge); var height = int.MaxValue; foreach (var mzRange in mzs) { double min = mzRange.MinWithMassAccuracy(massAccuracy); double max = mzRange.MaxWithMassAccuracy(massAccuracy); msGraphControlEx1.GraphPane.GraphObjList.Add(new BoxObj(min, height, max - min, height, Color.Goldenrod, Color.Goldenrod) { IsClippedToChartRect = true, ZOrder = ZOrder.F_BehindGrid }); } } } msGraphControlEx1.Invalidate(); } finally { _inRedisplay = false; } }
private void AddPeptide(Workspace workspace, PeakFinderPeptide peakFinderPeptide) { var msDataFile = GetMsDataFile(workspace, peakFinderPeptide.DataFile); Peptide peptide; using (var session = workspace.OpenWriteSession()) { var dbMsDataFile = new DbMsDataFile { Name = peakFinderPeptide.DataFile, Label = peakFinderPeptide.DataFile, }; if (msDataFile == null) { session.BeginTransaction(); session.Save(dbMsDataFile); session.Transaction.Commit(); } workspace.DatabasePoller.LoadAndMergeChanges(null); msDataFile = workspace.MsDataFiles.FindByKey(dbMsDataFile.GetId()); var dbPeptide = (DbPeptide) session.CreateCriteria <DbPeptide>().Add(Restrictions.Eq("Sequence", peakFinderPeptide.PeptideSequence)). UniqueResult(); if (dbPeptide == null) { dbPeptide = new DbPeptide { FullSequence = peakFinderPeptide.PeptideSequence, Sequence = peakFinderPeptide.PeptideSequence, }; session.BeginTransaction(); session.Save(dbPeptide); session.Transaction.Commit(); } session.BeginTransaction(); session.Save(new DbPeptideSpectrumMatch { RetentionTime = peakFinderPeptide.FirstDetectedTime * 60, PrecursorCharge = peakFinderPeptide.MinCharge, Peptide = dbPeptide, MsDataFile = session.Load <DbMsDataFile>(msDataFile.Id), }); if (peakFinderPeptide.LastDetectedTime != peakFinderPeptide.FirstDetectedTime) { session.Save(new DbPeptideSpectrumMatch { RetentionTime = peakFinderPeptide.LastDetectedTime * 60, PrecursorCharge = peakFinderPeptide.MaxCharge, Peptide = dbPeptide, MsDataFile = session.Load <DbMsDataFile>(msDataFile.Id), }); } session.Transaction.Commit(); peptide = new Peptide(workspace, dbPeptide); } MsDataFileUtil.InitMsDataFile(workspace, msDataFile); var peptideAnalysis = peptide.EnsurePeptideAnalysis(); if (peptideAnalysis == null) { Assert.Fail(); } PeptideFileAnalysis.EnsurePeptideFileAnalysis(peptideAnalysis, msDataFile); }
public void TestChromatogramGenerator() { String dbPath = Path.Combine(TestContext.TestDir, "test" + Guid.NewGuid() + ".tpg"); using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory(dbPath, SessionFactoryFlags.CreateSchema)) { using (var session = sessionFactory.OpenSession()) { session.BeginTransaction(); DbWorkspace dbWorkspace = new DbWorkspace { TracerDefCount = 1, }; session.Save(dbWorkspace); DbTracerDef dbTracerDef = TracerDef.GetN15Enrichment(); dbTracerDef.Workspace = dbWorkspace; dbTracerDef.Name = "Tracer"; session.Save(dbTracerDef); session.Save(new DbSetting { Workspace = dbWorkspace, Name = SettingEnum.data_directory.ToString(), Value = GetDataDirectory() }); session.Transaction.Commit(); } } Workspace workspace = new Workspace(dbPath); workspace.SetTaskScheduler(TaskScheduler.Default); var dbMsDataFile = new DbMsDataFile { Name = "20090724_HT3_0", }; using (var session = workspace.OpenWriteSession()) { session.BeginTransaction(); session.Save(dbMsDataFile); session.Transaction.Commit(); } workspace.DatabasePoller.LoadAndMergeChanges(null); var msDataFile = workspace.MsDataFiles.FindByKey(dbMsDataFile.GetId()); Assert.IsTrue(MsDataFileUtil.InitMsDataFile(workspace, msDataFile)); DbPeptide dbPeptide; using (var session = workspace.OpenWriteSession()) { session.BeginTransaction(); dbPeptide = new DbPeptide { Protein = "TestProtein", Sequence = "YLAAYLLLVQGGNAAPSAADIK", FullSequence = "K.YLAAYLLLVQGGNAAPSAADIK.A", }; session.Save(dbPeptide); var searchResult = new DbPeptideSpectrumMatch { Peptide = dbPeptide, MsDataFile = session.Load <DbMsDataFile>(msDataFile.Id), PrecursorCharge = 3, RetentionTime = 20.557 * 60, }; session.Save(searchResult); session.Transaction.Commit(); } var peptide = new Peptide(workspace, dbPeptide); var peptideAnalysis = peptide.EnsurePeptideAnalysis(); peptideAnalysis.IncChromatogramRefCount(); var peptideFileAnalysis = PeptideFileAnalysis.EnsurePeptideFileAnalysis(peptideAnalysis, msDataFile); workspace.DatabasePoller.LoadAndMergeChanges(null); peptideAnalysis.IncChromatogramRefCount(); var chromatogramGenerator = new ChromatogramGenerator(workspace); chromatogramGenerator.Start(); while (peptideFileAnalysis.ChromatogramSet == null) { Thread.Sleep(100); } var chromatogramDatas = peptideFileAnalysis.GetChromatograms(); Assert.IsFalse(chromatogramDatas.Chromatograms.Count == 0); chromatogramGenerator.Stop(); while (chromatogramGenerator.IsThreadAlive) { Thread.Sleep(100); } }