예제 #1
0
 public PeptideData(DbPeptide dbPeptide)
 {
     FullSequence       = dbPeptide.FullSequence;
     Sequence           = dbPeptide.Sequence;
     ProteinName        = dbPeptide.Protein;
     ProteinDescription = dbPeptide.ProteinDescription;
 }
예제 #2
0
 public PeptideData(DbPeptide dbPeptide)
 {
     FullSequence = dbPeptide.FullSequence;
     Sequence = dbPeptide.Sequence;
     ProteinName = dbPeptide.Protein;
     ProteinDescription = dbPeptide.ProteinDescription;
 }
예제 #3
0
파일: Peptide.cs 프로젝트: zrolfs/pwiz
        public static DbPeptideAnalysis CreateDbPeptideAnalysis(ISession session, DbPeptide dbPeptide)
        {
            int minCharge, maxCharge;
            var query = session.CreateQuery("SELECT MIN(s.PrecursorCharge), MAX(s.PrecursorCharge)"
                                            + "\nFROM " + typeof(DbPeptideSpectrumMatch) +
                                            " s WHERE s.Peptide = :peptide")
                        .SetParameter("peptide", dbPeptide);
            var minMaxCharge = (object[])query.UniqueResult();

            if (minMaxCharge == null)
            {
                return(null);
            }
            minCharge = Convert.ToInt32(minMaxCharge[0]);
            maxCharge = Convert.ToInt32(minMaxCharge[1]);
            return(new DbPeptideAnalysis
            {
                Peptide = dbPeptide,
                MinCharge = minCharge,
                MaxCharge = maxCharge,
            });
        }
예제 #4
0
 public SearchResultKey(DbMsDataFile msDataFile, DbPeptide peptide, double retentionTime)
     : this(msDataFile.Id.GetValueOrDefault(), peptide.Id.GetValueOrDefault(), retentionTime)
 {
 }
예제 #5
0
        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);
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 public SearchResultKey(DbMsDataFile msDataFile, DbPeptide peptide, double retentionTime)
     : this(msDataFile.Id.GetValueOrDefault(), peptide.Id.GetValueOrDefault(), retentionTime)
 {
 }
예제 #8
0
파일: Peptide.cs 프로젝트: zrolfs/pwiz
 public Peptide(Workspace workspace, DbPeptide dbPeptide) : this(workspace, dbPeptide.GetId(), new PeptideData(dbPeptide))
 {
 }
        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);
            }
        }
예제 #10
0
        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);
        }