Esempio n. 1
0
        public void TestImportExportIdpXml ()
        {
            var testModel = new TestModel();

            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testModel.idpDB"))
            using (var session = testModel.session = sessionFactory.OpenSession())
            {
                var distinctAnalyses = testModel.session.Query<Analysis>();
                foreach (var analysis in distinctAnalyses)
                    session.Save(new AnalysisParameter()
                                     {
                                         Analysis = analysis,
                                         Name = "ProteinDatabase",
                                         Value = "testImportExport.fasta"
                                     });

                /*IList<string> idpXmlPaths;
                using (var exporter = new Exporter(session))
                {
                    idpXmlPaths = exporter.WriteIdpXml(true, true);
                    exporter.WriteSpectra();
                    exporter.WriteProteins("testImportExport.fasta", false);
                }*/
                session.Close();

                /*using (var parser = new Parser(".", qonverterSettingsHandler, false, idpXmlPaths.ToArray()))
                {
                    // ReadXml should pick up mzML files in the same directory as the idpXMLs
                    parser.Start();
                }*/

                //var merger = new Merger("testImportExport.idpDB", idpXmlPaths.Select(o => Path.ChangeExtension(o, ".idpDB")));
                //merger.Start();
            }

            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testImportExport.idpDB"))
            using (var session = testModel.session = sessionFactory.OpenSession())
            {
                foreach (var analysis in session.Query<Analysis>())
                    session.Delete(session.UniqueResult<AnalysisParameter>(o => o.Analysis.Id == analysis.Id &&
                                                                                o.Name == "ProteinDatabase"));
                session.Flush();

                testModel.TestOverallCounts();
                testModel.TestSanity();
                testModel.TestProteins();
                testModel.TestPeptides();
                testModel.TestPeptideInstances();
                testModel.TestSpectrumSourceGroups();
                testModel.TestSpectrumSources();
                testModel.TestSpectra();
                testModel.TestAnalyses();
                testModel.TestPeptideSpectrumMatches();
                testModel.TestModifications();
                // TODO: enable QonverterSettings round trip for idpXML?
                //testModel.TestQonverterSettings();
            }
        }
Esempio n. 2
0
        public void TestSchemaUpdater()
        {
            Assert.AreEqual(15, SchemaUpdater.CurrentSchemaRevision);

            var testModel = new TestModel() { TestContext = TestContext };
            TestModel.ClassInitialize(TestContext);
            testModel.TestInitialize();
            testModelFile(testModel, "testModel.idpDB");

            string filename = null;

            // test all revisions without a data filter applied
            // we don't need to test upgrade from 12 to 13; the extra table (PeptideModificationProbability) is ignored and necessary for the current NHibernate bindings
            // we don't need to test upgrade from 11 to 12; the changed table (XICMetrics) is ignored
            // we don't need to test upgrade from 10 to 11; the extra columns (GeneGroups, Genes) are ignored
            // we don't need to test upgrade from 9 to 10; the extra tables (XICMetrics, XICMetricsSettings) are ignored
            // we don't need to test upgrade from 8 to 9; the extra columns (GeneLevelFiltering, DistinctMatchFormat) are ignored
            // we don't need to test upgrade from 7 to 8; the extra columns are ignored
            // we don't need to test upgrade from 5 to 6; it simply forces reapplication of the basic filters
            // we don't need to test upgrade from 4 to 5; it's a simple null value fix

            filename = "testModel-v4.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 4);
            testModelFile(testModel, filename);

            filename = "testModel-v3.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 3);
            testModelFile(testModel, filename);

            filename = "testModel-v2.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 2);
            testModelFile(testModel, filename);

            filename = "testModel-v1.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 1);
            testModelFile(testModel, filename);

            filename = "testModel-v0.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 0);
            testModelFile(testModel, filename);


            // test all revisions with a data filter applied (only check that the update worked this time)

            File.Copy("testModel.idpDB", "testFilter.idpDB", true);
            var dataFilter = new DataFilter { MaximumQValue = 1 };
            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testFilter.idpDB"))
            using (var session = testModel.session = sessionFactory.OpenSession())
            {
                dataFilter.ApplyBasicFilters(session);
            }

            filename = "testFilter-v4.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 4);
            testFilterFile(filename);

            filename = "testFilter-v3.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 3);
            testFilterFile(filename);

            filename = "testFilter-v2.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 2);
            testFilterFile(filename);

            filename = "testFilter-v1.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 1);
            testFilterFile(filename);

            filename = "testFilter-v0.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 0);
            testFilterFile(filename);
        }
Esempio n. 3
0
        void testModelFile(TestModel testModel, string filename)
        {
            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory(filename))
            using (var session = testModel.session = sessionFactory.OpenSession())
            {
                Assert.AreEqual(SchemaUpdater.CurrentSchemaRevision, session.UniqueResult<int>("SELECT SchemaRevision FROM About"));

                testModel.TestOverallCounts();
                testModel.TestSanity();
                testModel.TestProteins();
                testModel.TestPeptides();
                testModel.TestPeptideInstances();
                testModel.TestSpectrumSourceGroups();
                testModel.TestSpectrumSources();
                testModel.TestSpectra();
                testModel.TestAnalyses();
                testModel.TestPeptideSpectrumMatches();
                testModel.TestModifications();
            }
        }
Esempio n. 4
0
        public void TestMergerModel ()
        {

            #region Example proteins

            string[] testProteinSequences = new string[]
            {
                "PEPTIDERPEPTIDEKPEPTIDE",
                "TIDERPEPTIDEKPEP",
                "RPEPKTIDERPEPKTIDE",
                "EDITPEPKEDITPEPR",
                "PEPREDITPEPKEDIT",
                "EPPIERPETPDETKTDPEPIIRDE"
            };

            #endregion

            #region Example PSMs

            List<SpectrumTuple> mergeSourcePsmSummary1 = new List<SpectrumTuple>()
            {
                 //               Group Source Spectrum Analysis     Score  Q   List of Peptide@Charge/ScoreDivider
                 new SpectrumTuple("/A/1", 1, 1, 1, 12, 0, "[C2H2O1]PEPTIDE@2/1 TIDERPEPTIDEK@4/2 EPPIER@1/3"),
                 new SpectrumTuple("/A/1", 1, 2, 1, 23, 0, "PEPTIDER@2/1 PETPDETK@3/3 EDITPEPK@2/5"),
                 new SpectrumTuple("/A/1", 1, 3, 1, 34, 0, "PEPTIDEK@2/1 TIDER@1/4 PETPDETK@2/8"),
                 new SpectrumTuple("/A/1", 2, 1, 1, 43, 0, "PEPTIDE@2/1 E[H-2O-1]DIT[P1O4]PEPR@2/2 EPPIER@1/7"),
                 new SpectrumTuple("/A/1", 2, 2, 1, 32, 0, "PEPTIDER@3/1 EDITPEPK@3/4 EDITPEPR@3/5"),
                 new SpectrumTuple("/A/1", 2, 3, 1, 21, 0, "PEPT[P1O4]IDEK@3/1 TIDEK@1/7 PETPDETK@2/8"),
                 new SpectrumTuple("/A/2", 3, 1, 1, 56, 0, "TIDEK@2/1 TIDE@1/2 P[P1O4]EPTIDE@3/3"),
                 new SpectrumTuple("/A/2", 3, 2, 1, 45, 0, "TIDER@2/1 TIDERPEPTIDEK@4/3 PEPTIDEK@3/4"),
                 new SpectrumTuple("/A/2", 3, 3, 1, 34, 0, "TIDE@1/1 PEPTIDEK@3/6 TIDEK@1/7"),
                 new SpectrumTuple("/B/1", 4, 1, 1, 65, 0, "TIDERPEPTIDEK@4/1 PETPDETK@3/8 EDITPEPR@3/9"),
                 new SpectrumTuple("/B/1", 4, 2, 1, 53, 0, "E[H-2O-1]DITPEPK@2/1 PEPTIDEK@3/2 PEPTIDE@2/3"),
                 new SpectrumTuple("/B/1", 4, 3, 1, 42, 0, "EDIT@2/1 PEPTIDEK@3/3 EDITPEPR@2/4"),
                 new SpectrumTuple("/B/2", 5, 1, 1, 20, 0, "EPPIER@2/1 TIDE@1/7 PEPTIDE@2/9"),
                 new SpectrumTuple("/B/2", 5, 2, 1, 24, 0, "PETPDETK@2/1 PEPTIDEK@3/5 EDITPEPR@2/8"),
                 new SpectrumTuple("/B/2", 5, 3, 1, 24, 0, "PETPDETK@3/1 EDIT@1/4 TIDER@2/6"),
             };

             List<SpectrumTuple> mergeSourcePsmSummary2 = new List<SpectrumTuple>()
             {
                 new SpectrumTuple("/A/1", 1, 1, 2, 120, 0, "TIDERPEPTIDEK@4/1 PEPTIDE@2/2 EPPIER@1/3"),
                 new SpectrumTuple("/A/1", 1, 2, 2, 230, 0, "PEPTIDER@2/1 PETPDETK@3/3 EDITPEPK@2/5"),
                 new SpectrumTuple("/A/1", 1, 3, 2, 340, 0, "PEPTIDEK@2/1 TIDER@1/4 PETPDETK@2/8"),
                 new SpectrumTuple("/A/1", 2, 1, 2, 430, 0, "PEPTIDE@2/1 EDITPEPR@2/2 EPPIER@1/7"),
                 new SpectrumTuple("/A/1", 2, 2, 2, 320, 0, "PEPTIDER@3/1 EDITPEPK@3/4 EDITPEPR@3/5"),
                 new SpectrumTuple("/A/1", 2, 3, 2, 210, 0, "PEPT[P1O4]IDEK@3/1 TIDEK@1/7 PETPDETK@2/8"),
                 new SpectrumTuple("/A/2", 3, 1, 2, 560, 0, "TIDEK@2/1 TIDE@1/2 PEPTIDE@3/3"),
                 new SpectrumTuple("/A/2", 3, 2, 2, 450, 0, "TIDER@2/1 TIDERPEPTIDEK@4/3 PEPTIDEK@3/4"),
                 new SpectrumTuple("/A/2", 3, 3, 2, 340, 0, "TIDE@1/1 PEPTIDEK@3/6 TIDEK@1/7"),
                 new SpectrumTuple("/B/1", 4, 1, 2, 650, 0, "TIDERPEPTIDEK@4/1 PET[P1O4]PDETK@3/8 EDITPEPR@3/9"),
                 new SpectrumTuple("/B/1", 4, 2, 2, 530, 0, "EDITPEPK@2/1 PEPTIDEK@3/2 PEPTIDE@2/3"),
                 new SpectrumTuple("/B/1", 4, 3, 2, 420, 0, "EDIT@2/1 PEPTIDEK@3/3 EDITPEPR@2/4"),
                 new SpectrumTuple("/B/2", 5, 1, 2, 200, 0, "E[H-2O-1]PPIER@2/1 TIDE@1/7 PEPTIDE@2/9"),
                 new SpectrumTuple("/B/2", 5, 2, 2, 240, 0, "PEPTIDEK@2/1 PETPDETK@2/4 EDITPEPR@2/8"),
                 new SpectrumTuple("/B/2", 5, 3, 2, 240, 0, "PETPDETK@3/1 EDIT@1/4 TIDER@2/6"),
             };

             var qonverterSettings1 = new QonverterSettings()
             {
                 QonverterMethod = Qonverter.QonverterMethod.StaticWeighted,
                 DecoyPrefix = "quiRKy",
                 RerankMatches = true,
                 ScoreInfoByName = new Dictionary<string, Qonverter.Settings.ScoreInfo>()
                    {
                        {"score1", new Qonverter.Settings.ScoreInfo()
                                    {
                                        Weight = 1,
                                        Order = Qonverter.Settings.Order.Ascending,
                                        NormalizationMethod = Qonverter.Settings.NormalizationMethod.Linear
                                    }},
                        {"score2", new Qonverter.Settings.ScoreInfo()
                                    {
                                        Weight = 42,
                                        Order = Qonverter.Settings.Order.Descending,
                                        NormalizationMethod = Qonverter.Settings.NormalizationMethod.Quantile
                                    }}
                    }
             };

             var qonverterSettings2 = new QonverterSettings()
             {
                 QonverterMethod = Qonverter.QonverterMethod.SVM,
                 DecoyPrefix = "___---",
                 RerankMatches = false,
                 ScoreInfoByName = new Dictionary<string, Qonverter.Settings.ScoreInfo>()
                    {
                        {"foo", new Qonverter.Settings.ScoreInfo()
                                {
                                    Weight = 7,
                                    Order = Qonverter.Settings.Order.Ascending,
                                    NormalizationMethod = Qonverter.Settings.NormalizationMethod.Off
                                }},
                        {"bar", new Qonverter.Settings.ScoreInfo()
                                {
                                    Weight = 11,
                                    Order = Qonverter.Settings.Order.Descending,
                                    NormalizationMethod = Qonverter.Settings.NormalizationMethod.Off
                                }}
                    }
             };

            #endregion

            File.Delete("testMergeSource1.idpDB");
            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testMergeSource1.idpDB", new SessionFactoryConfig { CreateSchema = true }))
            using (var session = sessionFactory.OpenSession())
            {
                TestModel.CreateTestProteins(session, testProteinSequences);
                TestModel.CreateTestData(session, mergeSourcePsmSummary1);
                TestModel.AddSubsetPeakData(session);

                qonverterSettings1.Analysis = session.UniqueResult<Analysis>(o => o.Software.Name == "Engine 1");
                session.Save(qonverterSettings1);
                session.Flush();
            }

            File.Delete("testMergeSource2.idpDB");
            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testMergeSource2.idpDB", new SessionFactoryConfig { CreateSchema = true }))
            using (var session = sessionFactory.OpenSession())
            {
                TestModel.CreateTestProteins(session, testProteinSequences);
                TestModel.CreateTestData(session, mergeSourcePsmSummary2);
                TestModel.AddSubsetPeakData(session);

                // copy is required because session.Save() takes ownership of the instance
                var qonverterSettings2Copy = new QonverterSettings()
                {
                    Analysis = session.UniqueResult<Analysis>(o => o.Software.Name == "Engine 2"),
                    QonverterMethod = qonverterSettings2.QonverterMethod,
                    DecoyPrefix = qonverterSettings2.DecoyPrefix,
                    RerankMatches = qonverterSettings2.RerankMatches,
                    ScoreInfoByName = qonverterSettings2.ScoreInfoByName
                };
                session.Save(qonverterSettings2Copy);
                session.Flush();
            }

            // create a new merged idpDB from two idpDB files
            File.Delete("testMerger.idpDB");
            Merger.Merge("testMerger.idpDB", new string[] { "testMergeSource1.idpDB", "testMergeSource2.idpDB" });

            var testModel = new TestModel();

            // test that testMerger.idpDB passes the TestModel tests
            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testMerger.idpDB"))
            using (var session = testModel.session = sessionFactory.OpenSession())
            {
                testModel.TestOverallCounts();
                testModel.TestSanity();
                testModel.TestProteins();
                testModel.TestPeptides();
                testModel.TestPeptideInstances();
                testModel.TestSpectrumSourceGroups();
                testModel.TestSpectrumSources(false);
                testModel.TestSpectra(false);
                testModel.TestAnalyses();
                testModel.TestPeptideSpectrumMatches();
                testModel.TestModifications();
                testModel.TestQonverterSettings();
            }

            // create an in-memory representation of testMergeSource2
            var memoryFactory = SessionFactoryFactory.CreateSessionFactory(":memory:", new SessionFactoryConfig { CreateSchema = true });
            var memoryConnection = SessionFactoryFactory.CreateFile(":memory:");
            var memorySession = memoryFactory.OpenSession(memoryConnection);
            {
                TestModel.CreateTestProteins(memorySession, testProteinSequences);
                TestModel.CreateTestData(memorySession, mergeSourcePsmSummary2);
                TestModel.AddSubsetPeakData(memorySession);

                qonverterSettings2.Analysis = memorySession.UniqueResult<Analysis>(o => o.Software.Name == "Engine 2");
                memorySession.Save(qonverterSettings2);
                memorySession.Flush();
            }

            // merge the in-memory connection into the testMergeSource1 file
            /*Merger.Merge("testMergeSource1.idpDB", memoryConnection as System.Data.SQLite.SQLiteConnection);

            // testMergeSource1.idpDB should pass just like testMerger.idpDB
            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testMergeSource1.idpDB"))
            using (var session = testModel.session = sessionFactory.OpenSession())
            {
                testModel.TestOverallCounts();
                testModel.TestSanity();
                testModel.TestProteins();
                testModel.TestPeptides();
                testModel.TestPeptideInstances();
                testModel.TestSpectrumSourceGroups();
                testModel.TestSpectrumSources(false);
                testModel.TestSpectra(false);
                testModel.TestAnalyses();
                testModel.TestPeptideSpectrumMatches();
                testModel.TestModifications();
                testModel.TestQonverterSettings();
            }*/
        }
Esempio n. 5
0
        public void TestImportExportIdpXml()
        {
            var testModel = new TestModel();

            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testModel.idpDB"))
                using (var session = testModel.session = sessionFactory.OpenSession())
                {
                    var distinctAnalyses = testModel.session.Query <Analysis>();
                    foreach (var analysis in distinctAnalyses)
                    {
                        session.Save(new AnalysisParameter()
                        {
                            Analysis = analysis,
                            Name     = "ProteinDatabase",
                            Value    = "testImportExport.fasta"
                        });
                    }

                    /*IList<string> idpXmlPaths;
                     * using (var exporter = new Exporter(session))
                     * {
                     *  idpXmlPaths = exporter.WriteIdpXml(true, true);
                     *  exporter.WriteSpectra();
                     *  exporter.WriteProteins("testImportExport.fasta", false);
                     * }*/
                    session.Close();

                    /*using (var parser = new Parser(".", qonverterSettingsHandler, false, idpXmlPaths.ToArray()))
                     * {
                     *  // ReadXml should pick up mzML files in the same directory as the idpXMLs
                     *  parser.Start();
                     * }*/

                    //var merger = new Merger("testImportExport.idpDB", idpXmlPaths.Select(o => Path.ChangeExtension(o, ".idpDB")));
                    //merger.Start();
                }

            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testImportExport.idpDB"))
                using (var session = testModel.session = sessionFactory.OpenSession())
                {
                    foreach (var analysis in session.Query <Analysis>())
                    {
                        session.Delete(session.UniqueResult <AnalysisParameter>(o => o.Analysis.Id == analysis.Id &&
                                                                                o.Name == "ProteinDatabase"));
                    }
                    session.Flush();

                    testModel.TestOverallCounts();
                    testModel.TestSanity();
                    testModel.TestProteins();
                    testModel.TestPeptides();
                    testModel.TestPeptideInstances();
                    testModel.TestSpectrumSourceGroups();
                    testModel.TestSpectrumSources();
                    testModel.TestSpectra();
                    testModel.TestAnalyses();
                    testModel.TestPeptideSpectrumMatches();
                    testModel.TestModifications();
                    // TODO: enable QonverterSettings round trip for idpXML?
                    //testModel.TestQonverterSettings();
                }
        }
Esempio n. 6
0
 public static void ClassInitialize(TestContext testContext)
 {
     TestModel.ClassInitialize(testContext);
 }
Esempio n. 7
0
        public void TestStaticQonverter()
        {
            #region Example with forward and reverse proteins
            string[] testProteinSequences = new string[]
            {
                "PEPTIDERPEPTIDEK",
                "TIDERPEPTIDEKPEP",
                "DERPEPTIDEKPEPTI",
                "THEQUICKBRWNFXUMPSVERTHELZYDG",
                "KEDITPEPREDITPEP",
                "PEPKEDITPEPREDIT",
                "ITPEPKEDITPEPRED",
                "GDYZLEHTREVSPMUXFNWRBKCIUQEHT"
            };

            const string decoyPrefix   = "r-";
            const int    analysisCount = 2;
            const int    sourceCount   = 2;
            const int    chargeCount   = 2;

            File.Delete("testStaticQonversion.idpDB");
            var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testStaticQonversion.idpDB", new SessionFactoryConfig {
                CreateSchema = true
            });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            session.Clear();

            // add decoy prefix to the second half of the proteins
            for (long i = testProteinSequences.LongLength / 2; i < testProteinSequences.LongLength; ++i)
            {
                var pro = session.Get <Protein>(i + 1);
                pro.Accession = decoyPrefix + pro.Accession;
                session.Update(pro);
            }
            #endregion

            #region Example PSMs
            // For each combination of 2 engines, 2 sources, and 2 charges,
            // we test qonversion on this scenario:
            //
            // Scan Score DecoyState Targets Decoys Ambiguous -> Expected QValue
            // 50   6     T          1       0      0            0
            // 30   5     T          2       0      0            0
            // 40   4     T          3       0      0            0
            // 10   3     D          3       1      0            2/4
            // 20   2     D          3       2      0            4/5
            // 60   1     T          4       2      0            4/6

            double q = PeptideSpectrumMatch.DefaultQValue;

            for (int analysis = 1; analysis <= analysisCount; ++analysis)
            {
                for (int source = 1; source <= sourceCount; ++source)
                {
                    for (int charge = 1; charge <= chargeCount; ++charge)
                    {
                        List <SpectrumTuple> testPsmSummary = new List <SpectrumTuple>()
                        {
                            //               Group Source Spectrum  Analysis    Score Q   List of Peptide@Charge/ScoreDivider
                            new SpectrumTuple("/", source, 5, analysis, 6, q, String.Format("TIDERPEPTIDEK@{0}/1 PEPTIDER@{0}/8", charge)),
                            new SpectrumTuple("/", source, 3, analysis, 5, q, String.Format("TIDERPEPTIDEK@{0}/1 PEPTIDER@{0}/2", charge)),
                            new SpectrumTuple("/", source, 4, analysis, 4, q, String.Format("EDITPEP@{0}/1 THEQUICKBR@{0}/4", charge)),
                            new SpectrumTuple("/", source, 1, analysis, 3, q, String.Format("PEPTIDEKPEP@{0}/1 PEPTIDEK@{0}/2", charge)),
                            new SpectrumTuple("/", source, 2, analysis, 2, q, String.Format("TIDER@{0}/1 PEPTIDER@{0}/2", charge)),
                            new SpectrumTuple("/", source, 6, analysis, 1, q, String.Format("EDITPEPR@{0}/1 TIDERPEPTIDEK@{0}/3", charge))
                        };

                        TestModel.CreateTestData(session, testPsmSummary);
                    }
                }
            }

            List <SpectrumTuple> testPsmSummaryWithoutScores = new List <SpectrumTuple>()
            {
                new SpectrumTuple("/", 1, 1, analysisCount + 1, null, 0.01, "TIDERPEPTIDEK@1/1 PEPTIDER@3/8"),
                new SpectrumTuple("/", 1, 2, analysisCount + 1, null, 0.02, "KEDITPEPR@2/1 PEPTIDEK@2/8"),
                new SpectrumTuple("/", 1, 3, analysisCount + 1, null, 0.03, "THEQUICKBR@3/1 THELZYDG@1/8"),
            };

            TestModel.CreateTestData(session, testPsmSummaryWithoutScores);

            // force all peptide instances to fully specific
            foreach (PeptideInstance pi in session.Query <PeptideInstance>())
            {
                pi.NTerminusIsSpecific = pi.CTerminusIsSpecific = true;
                session.Update(pi);
            }

            session.Flush();
            session.Close(); // close the connection
            sessionFactory.Close();
            #endregion

            var qonverter = new IDPicker.Qonverter()
            {
                SettingsByAnalysis = new Dictionary <int, Qonverter.Settings>()
            };

            for (int i = 1; i <= analysisCount + 1; ++i)
            {
                qonverter.SettingsByAnalysis[i] = new Qonverter.Settings()
                {
                    QonverterMethod             = Qonverter.QonverterMethod.StaticWeighted,
                    ChargeStateHandling         = Qonverter.ChargeStateHandling.Ignore,
                    TerminalSpecificityHandling = Qonverter.TerminalSpecificityHandling.Ignore,
                    MassErrorHandling           = Qonverter.MassErrorHandling.Ignore,
                    MissedCleavagesHandling     = Qonverter.MissedCleavagesHandling.Ignore,
                    DecoyPrefix     = decoyPrefix,
                    ScoreInfoByName = new Dictionary <string, Qonverter.Settings.ScoreInfo>()
                    {
                        { "score1", new Qonverter.Settings.ScoreInfo()
                          {
                              Weight = 1
                          } },
                        { "score2", new Qonverter.Settings.ScoreInfo()
                          {
                              Weight = 0
                          } }
                    }
                }
            }
            ;

            var progressTester = new QonversionProgressTest()
            {
                Qonverter             = qonverter,
                ExpectedTotalAnalyses = analysisCount * sourceCount // engine 3 is ignored
            };

            File.Copy("testStaticQonversion.idpDB", "testStaticQonversion2.idpDB", true);

            // test without progress monitor
            qonverter.Qonvert("testStaticQonversion2.idpDB");

            qonverter.QonversionProgress += new IDPicker.Qonverter.QonversionProgressEventHandler(progressTester.qonverter_QonversionProgress);

            File.Copy("testStaticQonversion.idpDB", "testStaticQonversion3.idpDB", true);

            // test progress monitor with cancelling
            // (must before a full qonversion since the QValue test doesn't expect cancellation)
            progressTester.ExpectedQonvertedAnalyses = 0;
            progressTester.CancelAtCount             = 4;
            qonverter.Qonvert("testStaticQonversion3.idpDB");

            // test progress monitor without cancelling
            progressTester.ExpectedQonvertedAnalyses = 0;
            progressTester.CancelAtCount             = int.MaxValue;
            qonverter.Qonvert("testStaticQonversion.idpDB");

            sessionFactory = SessionFactoryFactory.CreateSessionFactory("testStaticQonversion.idpDB");
            session        = sessionFactory.OpenSession();
            session.Clear();

            #region QValue test
            Dictionary <long, double> expectedQValues = new Dictionary <long, double>()
            {
                // with high scoring decoys, Q values can spike and gradually go down again;
                // we squash these spikes such that Q value is monotonically increasing;
                // then we convert Q values to FDR scores using linear interpolation
                //               targets  decoys  ambiguous  unadjusted-Q-value  adjusted-Q-value  FDR-score
                { 4, 0 },        // 1        0       0              0                   0             0
                { 2, 0.2 },      // 2        0       0              0                   0             0.2
                { 3, 0.4 },      // 2        1       0              0.666               0.4           0.4
                { 0, 0.488 },    // 3        1       0              0.5                 0.4           0.488
                { 1, 0.577 },    // 4        1       0              0.4                 0.4           0.577
                { 5, 0.666 },    // 4        2       0              0.666               0.666         0.666
            };

            for (long engine = 1; engine <= 2; ++engine)
            {
                for (long source = 1; source <= 2; ++source)
                {
                    for (int charge = 1; charge <= 2; ++charge)
                    {
                        foreach (var itr in expectedQValues)
                        {
                            var topRankedMatch = session.CreateQuery("SELECT psm " +
                                                                     "FROM PeptideSpectrumMatch psm " +
                                                                     "WHERE psm.Analysis.id = ? " +
                                                                     "  AND psm.Spectrum.Source.id = ? " +
                                                                     "  AND psm.Spectrum.Index = ? " +
                                                                     "  AND psm.Charge = ? " +
                                                                     "  AND psm.Rank = 1" +
                                                                     "GROUP BY psm.Spectrum.id ")
                                                 .SetParameter(0, engine)
                                                 .SetParameter(1, source)
                                                 .SetParameter(2, itr.Key)
                                                 .SetParameter(3, charge)
                                                 .List <PeptideSpectrumMatch>().First();

                            Assert.AreEqual(session.Get <Analysis>(engine), topRankedMatch.Analysis);
                            Assert.AreEqual(session.Get <SpectrumSource>(source), topRankedMatch.Spectrum.Source);
                            Assert.AreEqual(charge, topRankedMatch.Charge);
                            Assert.AreEqual(itr.Value, topRankedMatch.QValue, 1e-3);
                        }
                    }
                }
            }

            var scorelessMatches = session.CreateQuery("SELECT psm " +
                                                       "FROM PeptideSpectrumMatch psm " +
                                                       "WHERE psm.Analysis.id = 3 " +
                                                       "  AND psm.Rank = 1")
                                   .List <PeptideSpectrumMatch>();
            Assert.AreEqual(3, scorelessMatches.Count);
            Assert.AreEqual(0.01, scorelessMatches[0].QValue, 1e-12);
            Assert.AreEqual(0.02, scorelessMatches[1].QValue, 1e-12);
            Assert.AreEqual(0.03, scorelessMatches[2].QValue, 1e-12);
            #endregion
        }
Esempio n. 8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                TreeNode tn = new TreeNode("  父节点" + i);
                for (int j = 0; j < 3; j++)
                {
                    tn.Nodes.Add("    子节点" + j);
                }
                this.treeViewEx1.Nodes.Add(tn);
            }

            List <KeyValuePair <string, string> > lstCom = new List <KeyValuePair <string, string> >();

            for (int i = 0; i < 5; i++)
            {
                lstCom.Add(new KeyValuePair <string, string>(i.ToString(), "选项" + i));
            }

            this.ucComboBox1.Source        = lstCom;
            this.ucComboBox2.Source        = lstCom;
            this.ucComboBox1.SelectedIndex = 1;
            this.ucComboBox2.SelectedIndex = 1;


            List <ListEntity> lst = new List <ListEntity>();

            for (int i = 0; i < 5; i++)
            {
                lst.Add(new ListEntity()
                {
                    ID          = i.ToString(),
                    Title       = "选项" + i,
                    ShowMoreBtn = true,
                    Source      = i
                });
            }
            this.ucListExt1.SetList(lst);

            List <KeyValuePair <string, string> > lstHL = new List <KeyValuePair <string, string> >();

            for (int i = 0; i < 30; i++)
            {
                lstHL.Add(new KeyValuePair <string, string>(i.ToString(), "选项" + i));
            }

            this.ucHorizontalList1.DataSource = lstHL;

            List <MenuItemEntity> lstMenu = new List <MenuItemEntity>();

            for (int i = 0; i < 2; i++)
            {
                MenuItemEntity item = new MenuItemEntity()
                {
                    Key        = "p" + i.ToString(),
                    Text       = "菜单项" + i,
                    DataSource = "这里编写一些自定义的数据源,用于扩展"
                };
                item.Childrens = new List <MenuItemEntity>();
                for (int j = 0; j < 5; j++)
                {
                    MenuItemEntity item2 = new MenuItemEntity()
                    {
                        Key        = "c" + i.ToString(),
                        Text       = "菜单子项" + i + "-" + j,
                        DataSource = "这里编写一些自定义的数据源,用于扩展"
                    };
                    item.Childrens.Add(item2);
                }
                lstMenu.Add(item);
            }
            for (int i = 2; i < 4; i++)
            {
                MenuItemEntity item = new MenuItemEntity()
                {
                    Key        = "p" + i.ToString(),
                    Text       = "菜单项" + i,
                    DataSource = "这里编写一些自定义的数据源,用于扩展"
                };
                lstMenu.Add(item);
            }
            this.ucMenu1.MenuStyle  = MenuStyle.Top;
            this.ucMenu1.DataSource = lstMenu;


            List <object> lstPage2 = new List <object>();

            for (int i = 0; i < 1000; i++)
            {
                lstPage2.Add(i);
            }
            ucPagerControl21.PageSize   = 10;
            ucPagerControl21.DataSource = lstPage2;

            ucBtnsGroup1.DataSource = new Dictionary <string, string>()
            {
                { "1", "男" }, { "0", "女" }
            };
            ucBtnsGroup2.IsMultiple = true;
            ucBtnsGroup2.DataSource = new Dictionary <string, string>()
            {
                { "1", "河南" }, { "2", "北京" }, { "3", "湖南" }, { "4", "上海" }
            };
            ucBtnsGroup2.SelectItem = new List <string>()
            {
                "2", "3"
            };


            List <DataGridViewColumnEntity> lstCulumns = new List <DataGridViewColumnEntity>();

            lstCulumns.Add(new DataGridViewColumnEntity()
            {
                DataField = "ID", HeadText = "编号", Width = 70, WidthType = SizeType.Absolute
            });
            lstCulumns.Add(new DataGridViewColumnEntity()
            {
                DataField = "Name", HeadText = "姓名", Width = 100, WidthType = SizeType.Absolute
            });
            lstCulumns.Add(new DataGridViewColumnEntity()
            {
                DataField = "Age", HeadText = "年龄", Width = 100, WidthType = SizeType.Absolute
            });
            lstCulumns.Add(new DataGridViewColumnEntity()
            {
                DataField = "Birthday", HeadText = "生日", Width = 120, WidthType = SizeType.Absolute, Format = (a) => { return(((DateTime)a).ToString("yyyy-MM-dd")); }
            });
            lstCulumns.Add(new DataGridViewColumnEntity()
            {
                DataField = "Sex", HeadText = "性别", Width = 100, WidthType = SizeType.Absolute, Format = (a) => { return(((int)a) == 0 ? "女" : "男"); }
            });
            this.ucComboxGrid1.GridColumns = lstCulumns;
            List <object> lstSourceGrid = new List <object>();

            for (int i = 0; i < 100; i++)
            {
                TestModel model = new TestModel()
                {
                    ID       = i.ToString(),
                    Age      = 3 * i,
                    Name     = "姓名——" + i,
                    Birthday = DateTime.Now.AddYears(-10),
                    Sex      = i % 2
                };
                lstSourceGrid.Add(model);
            }
            this.ucComboxGrid1.GridDataSource = lstSourceGrid;
        }
Esempio n. 9
0
        public void TestSchemaUpdater()
        {
            Assert.AreEqual(15, SchemaUpdater.CurrentSchemaRevision);

            var testModel = new TestModel()
            {
                TestContext = TestContext
            };

            TestModel.ClassInitialize(TestContext);
            testModel.TestInitialize();
            testModelFile(testModel, "testModel.idpDB");

            string filename = null;

            // test all revisions without a data filter applied
            // we don't need to test upgrade from 12 to 13; the extra table (PeptideModificationProbability) is ignored and necessary for the current NHibernate bindings
            // we don't need to test upgrade from 11 to 12; the changed table (XICMetrics) is ignored
            // we don't need to test upgrade from 10 to 11; the extra columns (GeneGroups, Genes) are ignored
            // we don't need to test upgrade from 9 to 10; the extra tables (XICMetrics, XICMetricsSettings) are ignored
            // we don't need to test upgrade from 8 to 9; the extra columns (GeneLevelFiltering, DistinctMatchFormat) are ignored
            // we don't need to test upgrade from 7 to 8; the extra columns are ignored
            // we don't need to test upgrade from 5 to 6; it simply forces reapplication of the basic filters
            // we don't need to test upgrade from 4 to 5; it's a simple null value fix

            filename = "testModel-v4.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 4);
            testModelFile(testModel, filename);

            filename = "testModel-v3.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 3);
            testModelFile(testModel, filename);

            filename = "testModel-v2.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 2);
            testModelFile(testModel, filename);

            filename = "testModel-v1.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 1);
            testModelFile(testModel, filename);

            filename = "testModel-v0.idpDB";
            File.Copy("testModel.idpDB", filename, true);
            downgradeToRevision(filename, 0);
            testModelFile(testModel, filename);


            // test all revisions with a data filter applied (only check that the update worked this time)

            File.Copy("testModel.idpDB", "testFilter.idpDB", true);
            var dataFilter = new DataFilter {
                MaximumQValue = 1
            };

            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory("testFilter.idpDB"))
                using (var session = testModel.session = sessionFactory.OpenSession())
                {
                    dataFilter.ApplyBasicFilters(session);
                }

            filename = "testFilter-v4.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 4);
            testFilterFile(filename);

            filename = "testFilter-v3.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 3);
            testFilterFile(filename);

            filename = "testFilter-v2.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 2);
            testFilterFile(filename);

            filename = "testFilter-v1.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 1);
            testFilterFile(filename);

            filename = "testFilter-v0.idpDB";
            File.Copy("testFilter.idpDB", filename, true);
            downgradeToRevision(filename, 0);
            testFilterFile(filename);
        }