コード例 #1
0
ファイル: PeptidesForm.cs プロジェクト: zrolfs/pwiz
 private void ShowPeptideAnalysis(Peptide peptide)
 {
     using (var session = Workspace.OpenSession())
     {
         var dbPeptide         = session.Load <DbPeptide>(peptide.Id);
         var dbPeptideAnalysis = (DbPeptideAnalysis)session
                                 .CreateCriteria(typeof(DbPeptideAnalysis))
                                 .Add(Restrictions.Eq("Peptide", dbPeptide))
                                 .UniqueResult();
         if (dbPeptideAnalysis == null)
         {
             var psmTimesByDataFileId = dbPeptide.PsmTimesByDataFileId(session);
             if (psmTimesByDataFileId.Count == 0)
             {
                 MessageBox.Show(
                     "This peptide cannot be analyzed because it has no search results.",
                     Program.AppName);
                 return;
             }
             if (MessageBox.Show("This peptide has not yet been analyzed.  Do you want to analyze it now?", Program.AppName, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
             {
                 return;
             }
             session.BeginTransaction();
             session.Save(dbPeptideAnalysis = Peptide.CreateDbPeptideAnalysis(session, dbPeptide));
             foreach (var grouping in psmTimesByDataFileId)
             {
                 MsDataFile msDataFile;
                 if (!Workspace.MsDataFiles.TryGetValue(grouping.Key, out msDataFile))
                 {
                     continue;
                 }
                 session.Save(PeptideFileAnalysis.CreatePeptideFileAnalysis(
                                  session, msDataFile, dbPeptideAnalysis, psmTimesByDataFileId));
                 dbPeptideAnalysis.FileAnalysisCount++;
             }
             session.Update(dbPeptideAnalysis);
             session.Transaction.Commit();
         }
         var peptideAnalysis = TopographForm.Instance.LoadPeptideAnalysis(dbPeptideAnalysis.GetId());
         if (peptideAnalysis == null)
         {
             return;
         }
         PeptideAnalysisFrame.ShowPeptideAnalysis(peptideAnalysis);
     }
 }
コード例 #2
0
ファイル: CreateFileAnalysesForm.cs プロジェクト: zrolfs/pwiz
 public void Run(LongOperationBroker longOperationBroker)
 {
     using (var session = PeptideAnalysis.Workspace.OpenSession())
     {
         var peptideAnalysis      = session.Get <DbPeptideAnalysis>(PeptideAnalysis.Id);
         var peptide              = peptideAnalysis.Peptide;
         var psmTimesByDataFileId = peptide.PsmTimesByDataFileId(session);
         session.BeginTransaction();
         foreach (var msDataFile in MsDataFiles)
         {
             var dbPeptideFileAnalysis = PeptideFileAnalysis.CreatePeptideFileAnalysis(
                 session, msDataFile, peptideAnalysis, psmTimesByDataFileId);
             session.Save(dbPeptideFileAnalysis);
             peptideAnalysis.FileAnalysisCount++;
         }
         session.Update(peptideAnalysis);
         session.Save(new DbChangeLog(PeptideAnalysis));
         session.Transaction.Commit();
     }
     PeptideAnalysis.Workspace.DatabasePoller.MergeChangesNow();
 }
コード例 #3
0
        private void DoCreateAnalyses(char[] excludeAas, int minTracerCount)
        {
            var  peptides          = new List <DbPeptide>();
            bool includeMissingMs2 = cbxIncludeMissingMS2.Checked;

            _statusMessage = "Listing peptides";
            using (var session = Workspace.OpenWriteSession())
            {
                session.CreateCriteria(typeof(DbPeptide)).List(peptides);
                for (int i = 0; i < peptides.Count(); i++)
                {
                    _statusMessage = "Peptide " + (i + 1) + "/" + peptides.Count;
                    _progress      = 100 * i / peptides.Count;
                    if (_cancelled)
                    {
                        break;
                    }
                    var peptide = peptides[i];
                    if (peptide.Sequence.IndexOfAny(excludeAas) >= 0)
                    {
                        continue;
                    }
                    if (Workspace.GetMaxTracerCount(peptide.Sequence) < minTracerCount)
                    {
                        continue;
                    }
                    var dbPeptideAnalysis = (DbPeptideAnalysis)session.CreateCriteria(typeof(DbPeptideAnalysis))
                                            .Add(Restrictions.Eq("Peptide", peptide)).UniqueResult();
                    if (dbPeptideAnalysis == null)
                    {
                        dbPeptideAnalysis = Peptide.CreateDbPeptideAnalysis(session, peptide);
                    }
                    var idList = new List <long>();
                    if (dbPeptideAnalysis.Id.HasValue)
                    {
                        var dataFileIdQuery = session.CreateQuery("SELECT A.MsDataFile.Id FROM " + typeof(DbPeptideFileAnalysis) +
                                                                  " A WHERE A.PeptideAnalysis.Id = :peptideAnalysisId")
                                              .SetParameter("peptideAnalysisId", dbPeptideAnalysis.Id);
                        dataFileIdQuery.List(idList);
                    }
                    var existingDataFileIds  = new HashSet <long>(idList);
                    var psmTimesByDataFileId = peptide.PsmTimesByDataFileId(session);
                    if (psmTimesByDataFileId.Count == 0)
                    {
                        continue;
                    }
                    session.BeginTransaction();
                    bool newAnalysis;
                    if (dbPeptideAnalysis.Id.HasValue)
                    {
                        newAnalysis = false;
                    }
                    else
                    {
                        session.Save(dbPeptideAnalysis);
                        newAnalysis = true;
                    }
                    var sqlStatementBuilder = new SqlStatementBuilder(session.GetSessionImplementation().Factory.Dialect);
                    var insertStatements    = new List <string>();
                    IList <MsDataFile> dataFiles;
                    if (includeMissingMs2)
                    {
                        dataFiles = Workspace.MsDataFiles
                                    .Where(msDataFile => !existingDataFileIds.Contains(msDataFile.Id))
                                    .ToArray();
                    }
                    else
                    {
                        dataFiles = new List <MsDataFile>();
                        foreach (var grouping in psmTimesByDataFileId)
                        {
                            MsDataFile dataFile;
                            if (existingDataFileIds.Contains(grouping.Key) || !Workspace.MsDataFiles.TryGetValue(grouping.Key, out dataFile))
                            {
                                continue;
                            }
                            dataFiles.Add(dataFile);
                        }
                    }
                    foreach (var msDataFile in dataFiles)
                    {
                        var dbPeptideFileAnalysis = PeptideFileAnalysis.CreatePeptideFileAnalysis(session, msDataFile, dbPeptideAnalysis, psmTimesByDataFileId);
                        insertStatements.Add(sqlStatementBuilder.GetInsertStatement("DbPeptideFileAnalysis",
                                                                                    new Dictionary <string, object>
                        {
                            { "ChromatogramEndTime", dbPeptideFileAnalysis.ChromatogramEndTime },
                            { "ChromatogramStartTime", dbPeptideFileAnalysis.ChromatogramStartTime },
                            { "MsDataFile", msDataFile.Id },
                            { "PeptideAnalysis", dbPeptideAnalysis.Id },
                            { "AutoFindPeak", 1 },
                            { "Version", 1 },
                            { "PeakCount", 0 },
                            { "PsmCount", dbPeptideFileAnalysis.PsmCount },
                            { "ValidationStatus", 0 },
                        }
                                                                                    ));
                        dbPeptideAnalysis.FileAnalysisCount++;
                        existingDataFileIds.Add(msDataFile.Id);
                    }
                    sqlStatementBuilder.ExecuteStatements(session, insertStatements);
                    session.Update(dbPeptideAnalysis);
                    if (!newAnalysis)
                    {
                        session.Save(new DbChangeLog(Workspace, dbPeptideAnalysis));
                    }
                    else
                    {
                        var dbWorkspace = Workspace.LoadDbWorkspace(session);
                        session.Update(dbWorkspace);
                    }
                    session.Transaction.Commit();
                }
            }
        }