static NHibernateHelper()
 {
     if (m_ISessionFactory == null)
     {
         m_ISessionFactory = GetFactory();
     }
 }
Пример #2
0
 public static void Init()
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path        = string.Empty;
         string wanted_path = System.IO.Directory.GetCurrentDirectory();
         if (string.IsNullOrEmpty(configfilepath))
         {
             path = wanted_path + "\\hibernate.cfg.xml";
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         throw ex;
         //Console.Write(ex.StackTrace);
         //logger.Error(ex.Message);
     }
 }
        public void Constructor2Test()
        {
            Mock <Configuration.IConfigurationResolver> connectionStringDiscovererMock = new Mock <Configuration.IConfigurationResolver>();

            connectionStringDiscovererMock.Setup(it => it.GetConfiguration()).Returns("Data Source=:memory:;Version=3;New=True;");

            FluentNHibernateSessionFactoryBuilderForSQLite nh1 = (new FluentNHibernateSessionFactoryBuilderForSQLite()
            {
                InMemory = true,
                ConnectionStringDiscoverer = connectionStringDiscovererMock.Object,
                TypeNames = new List <string>()
                {
                    this.GetType().AssemblyQualifiedName
                },
                EnabledDiagnostics = true,
                NHibernateRawConfigurationValues = new Dictionary <string, string>()
                {
                    { "a", "b" }
                },
                MergeEventListeners = new NHibernate.Event.IMergeEventListener[] { new Mock <NHibernate.Event.IMergeEventListener>().Object }
            });


            using (NHibernate.ISessionFactory session = nh1.BuildSessionFactory())
            {
                session.Close();
            }
        }
Пример #4
0
        public static void Init()
        {
            string path = System.IO.Path.GetFullPath("~/hibernate.cfg.xml");

            SessionFactory.Init();
            NHibernate.ISessionFactory session = SessionFactory.sFactory;
        }
Пример #5
0
        static void Main()
        {
            DbConnectionStringBuilder dcsBuilder = new DbConnectionStringBuilder();

            dcsBuilder.Add("User ID", "wjzgis");
            dcsBuilder.Add("Password", "wjzgis");
            dcsBuilder.Add("Service Name", "sunz");
            dcsBuilder.Add("Host", "172.16.1.9");
            dcsBuilder.Add("Integrated Security", false);
            string licPath = Application.StartupPath + "\\DDTek.lic";
            //dcsBuilder.Add("License Path", licPath);
            //若路径中存在空格,则会在路径名称前加上"\""
            string conStr = dcsBuilder.ConnectionString;

            conStr = conStr.Replace("\"", "");

            Configuration config = new Configuration();

            config.AddDirectory(new System.IO.DirectoryInfo(System.IO.Path.Combine(Application.StartupPath, "DataMapping")));

            config.Properties["connection.connection_string"] = conStr;


            NHibernate.ISessionFactory sFactory = config.BuildSessionFactory();
            NHibernate.ISession        session  = sFactory.OpenSession();


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Пример #6
0
 static NHibernateHelper()
 {
     if (m_ISessionFactory == null)
     {
         m_ISessionFactory = GetFactory();
     }
 }
Пример #7
0
        /// <summary>
        /// 创建Nhibernate实例
        /// 允许指定多个程序集进行
        /// </summary>
        /// <param name="hibernateConnection"></param>
        /// <param name="assemblys"></param>
        /// <returns></returns>
        public static NhibernateHelper GetNhibernateHelper(string hibernateConnection, List <string> assemblys)
        {
            if (string.IsNullOrWhiteSpace(hibernateConnection))
            {
                throw new Exception("NhibernateHelper创建错误:数据库连接为null");
            }

            if (assemblys == null || assemblys.Count == 0)
            {
                throw new Exception("NhibernateHelper创建错误:没有指定程序集");
            }

            Configuration config = new Configuration();

            foreach (string strAssembly in assemblys)
            {
                config.AddAssembly(strAssembly);
            }
            //config.SetProperty("ConnectionString", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\项目\龙岩\Out\Bin\SysWorkspace.mdb;Persist Security Info=False");
            config.Properties["connection.connection_string"] = hibernateConnection;
            NHibernate.ISessionFactory sFactory = config.BuildSessionFactory();
            NHibernate.ISession        session  = sFactory.OpenSession();

            return(new NhibernateHelper(session));
        }
Пример #8
0
 public static void Init(IHostingEnvironment env)
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path = string.Empty;
         if (string.IsNullOrEmpty(configfilepath))
         {
             //  var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment;
             path = System.IO.Path.Combine(env.ContentRootPath, "hibernate.cfg.xml");
             //path = @"D:\Suresh\BickBucket\src\Api.Socioboard\hibernate.cfg.xml";
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         throw ex;
         //Console.Write(ex.StackTrace);
         //logger.Error(ex.Message);
     }
 }
Пример #9
0
        private static void Init()
        {
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
            config.AddAssembly(typeof(Product).Assembly);

            _factory = config.BuildSessionFactory();
        }
Пример #10
0
        public static NHibernate.ISessionFactory BuildSessionFactory()
        {
            FluentNHibernate.Cfg.Db.MsSqlConfiguration databaseConfiguration = FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2012
                                                                               .MaxFetchDepth(5)
                                                                               .IsolationLevel(System.Data.IsolationLevel.ReadCommitted)
                                                                               .ConnectionString("Data Source=127.0.0.1,1433,db_port;User ID=devweekuser;Password=devweekpwd;Database=DemoDB;Application Name=OragonSamplesTest")
                                                                               .ShowSql().FormatSql()
                                                                               .DefaultSchema("dbo");

            FluentNHibernate.Cfg.FluentConfiguration configuration = FluentNHibernate.Cfg.Fluently
                                                                     .Configure()
                                                                     .Database(databaseConfiguration)
                                                                     .Cache(it =>
                                                                            it.UseQueryCache()
                                                                            .ProviderClass <NHibernate.Cache.HashtableCacheProvider>()
                                                                            )
                                                                     .Diagnostics(it =>
                                                                                  it.Enable(true)
                                                                                  .OutputToConsole()
                                                                                  )
                                                                     .Mappings(it =>
            {
                it.FluentMappings.AddFromAssemblyOf <Data.Mappings.ClassroomMapper>();
            })
                                                                     .ExposeConfiguration(config =>
            {
                NHibernate.Tool.hbm2ddl.SchemaUpdate update = new NHibernate.Tool.hbm2ddl.SchemaUpdate(config);

                update.Execute(true, true);
            });
            ;

            NHibernate.ISessionFactory sessionFactory = configuration.BuildSessionFactory();
            return(sessionFactory);
        }
Пример #11
0
 public static void Init()
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path        = string.Empty;
         string wanted_path = System.IO.Directory.GetCurrentDirectory();
         if (string.IsNullOrEmpty(configfilepath))
         {
             //                  var appEnv = CallContextServiceLocator.Locator.ServiceProvider
             //.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment;
             //  path = System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "hibernate.cfg.xml");
             //path = System.Reflection.Assembly.GetExecutingAssembly().Location;
             // path = @"D:\bitbucket\Updated\src\SocioboardDataServices\hibernate.cfg.xml";
             path = wanted_path + "\\hibernate.cfg.xml";
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         throw ex;
         //Console.Write(ex.StackTrace);
         //logger.Error(ex.Message);
     }
 }
Пример #12
0
        /// <summary>
        /// initializes the session for database
        /// </summary>
        private static void Init()
        {
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();

            config.AddFile("db.cfg.xml");//adds all the embedded resources .hbm.xml
            config.AddFile("models.xml");
            sFactory = config.BuildSessionFactory();
        }
Пример #13
0
 private static void ReadData(NHibernate.ISessionFactory factory)
 {
     using (var session = factory.OpenSession())
         using (var transaction = session.BeginTransaction()) {
             var customer = session.Get <Customer>(1);
             Console.WriteLine("Name:" + customer.FirstName + " " + customer.LastName);
         }
 }
Пример #14
0
        /// <summary>

        /// initializes the session for database

        /// </summary>

        private static void Init()
        {
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.PostgreSQL82Dialect");
            //NHibernate.Driver.NpgsqlDriver
            //config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.NpgsqlDriver");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, SessionFactory.connectionString);
            config.AddXmlFile(".\\AppFiles\\Database\\models.xml");

            sFactory = config.BuildSessionFactory();
        }
Пример #15
0
        /// <summary>
        /// initializes the session for database
        /// </summary>
        private static void Init()
        {
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.PostgreSQL82Dialect");
            //NHibernate.Driver.NpgsqlDriver
            //config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.NpgsqlDriver");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, SessionFactory.connectionString);
            config.AddXmlFile(".\\AppFiles\\Database\\models.xml");

            sFactory = config.BuildSessionFactory();
        }
Пример #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string _db_filename = @"c:\tempsq\web-builder.sq3";

            services.AddSingleton <FluentConfiguration>((provider) => {
                var cfg2 = Fluently.Configure();
                cfg2.Database(SQLiteConfiguration.Standard.UsingFile(_db_filename));
                cfg2.Mappings(m =>
                {
                    m.FluentMappings.Conventions.Setup(c => c.Add(AutoImport.Never()));
                    m.FluentMappings.Conventions.AddAssembly(Assembly.GetExecutingAssembly());
                    m.HbmMappings.AddFromAssembly(Assembly.GetExecutingAssembly());

                    var assembly = Assembly.Load("web");
                    m.FluentMappings.Conventions.AddAssembly(assembly);
                    m.FluentMappings.AddFromAssembly(assembly);
                    m.HbmMappings.AddFromAssembly(assembly);
                });
                cfg2.ExposeConfiguration(cfg =>
                {
                    cfg.SetProperty("current_session_context_class", "thread_static");
                    _cfg = cfg;
                });


                return(cfg2);
            });

            services.AddSingleton <NHibernate.ISessionFactory>((provider) => {
                var cfg  = provider.GetService <FluentConfiguration>();
                var fact = cfg.BuildSessionFactory();


                return(fact);
            });

            services.AddScoped <NHibernate.ISession>((provider) =>
            {
                var cfg = provider.GetService <FluentConfiguration>();
                NHibernate.ISessionFactory factory = provider.GetService <NHibernate.ISessionFactory>();
                return(factory.OpenSession());
            });

            services.AddScoped <NHibernate.Cfg.Configuration>((provider) =>
            {
                return(_cfg);
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #17
0
 /// <summary>
 /// Static constructor creates a new session factory used by all instances
 /// of this class.
 /// 构造函数(静态):创建新的Session
 /// </summary>
 static Repository()
 {
     try
     {
         //加载数据库相关配置信息
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration().Configure(@"HibernateMapping.cfg.xml");
         //创建SessionFactory
         _sessionfactory = config.BuildSessionFactory();
         //创建存储本地数据的内存槽
         _localDataStoreSlot = System.Threading.Thread.AllocateDataSlot();
     }
     catch (Exception ex)
     {
         string s = ex.Message;
     }
 }
        static SessionFactoryHelper()
        {
            var nhConfigs = new Configuration();
            nhConfigs.SetProperty(Environment.Dialect, "NHibernate.Dialect.SQLiteDialect");
            nhConfigs.SetProperty(Environment.ConnectionDriver, "NHibernate.Driver.SQLite20Driver");
            nhConfigs.SetProperty(Environment.ConnectionString, "Data Source=NHibernateExample.db;Version=3;");
            nhConfigs.SetProperty(Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
            nhConfigs.SetProperty(Environment.CommandTimeout, "600");

            SessionFactory = Fluently.Configure(nhConfigs)
                .Mappings(m => m.FluentMappings
                    .Add<CatMap>()
                    .Add<OwnerMap>()
                    .Add<ToyMap>()
                    .Conventions.Add<YesNoBoolPropertyConvention>())
                .BuildSessionFactory();
        }
Пример #19
0
        private static void InsertData(NHibernate.ISessionFactory factory)
        {
            using (var session = factory.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    Customer customer1 = new Customer();
                    //customer1.Id = 1;
                    customer1.FirstName = "Dipesh";
                    customer1.LastName  = "Kokitkar";
                    transaction.Begin();
                    session.Save(customer1);

                    //session.Save(new Customer {FirstName="Dipesh",LastName="Kokitkar"});
                    //session.Save(new Customer {FirstName = "Dipali", LastName = "Kokitkar" });
                    transaction.Commit();
                    Console.WriteLine("TAble Created");
                }
        }
        private string CreateQueryCountString(ISearchExpression searchExpression, NHibernate.ISessionFactory sessionFactory, Dictionary <string, object> paramNames)
        {
            if (searchExpression is QueryExpression)
            {
                string s = (searchExpression as QueryExpression).Query;

                int idx;
                //// remove joins
                //string[] joins = new string[] { "inner join", "left outer join", "right outer join", "full outer join", "left join", "right join", "full join" };
                //
                //foreach(string join in joins)
                //{
                //    idx = s.IndexOf(join);
                //    if (idx != -1)
                //    {
                //        s = s.Substring(0, idx).Trim();
                //    }
                //}

                idx = s.IndexOf("from");
                if (idx != -1)
                {
                    s = s.Substring(idx);
                }
                return("select count(*) " + s);
            }

            NHibernate.Metadata.IClassMetadata metaData = sessionFactory.GetClassMetadata(typeof(T));

            StringBuilder sb = new StringBuilder();

            sb.Append("select count(*) ");
            sb.Append("from ");
            sb.Append(metaData.EntityName);
            sb.Append(" ");
            if (searchExpression != null)
            {
                sb.Append("where ");

                sb.Append(GetQueryWhere(searchExpression, sessionFactory, paramNames));
            }
            return(sb.ToString());
        }
Пример #21
0
        public void ConnectDB(NHibernate.ISessionFactory session_factory)
        {
            this.session_factory = session_factory;

            using (var db_session = session_factory.OpenSession())
            {
                using (var tx = db_session.BeginTransaction())
                {
                    var crit = db_session.CreateCriteria <DbObjectMappings.CorpusInfo>();
                    //.Add(NHibernate.Criterion.Expression.Eq("Status", 1));
                    var corpora = crit.List <DbObjectMappings.CorpusInfo>();

                    foreach (var corpus_info in corpora)
                    {
                        corpus_infos.Add(corpus_info);
                    }
                }
            }
        }
Пример #22
0
        public static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            Log("Starting Up...");

            azureStorageAccountName = ConfigurationManager.AppSettings["azure-storage-account-name"];
            azureStorageAccountKey  = ConfigurationManager.AppSettings["azure-storage-account-key"];
            azureStorageBaseURL     = "https://" + azureStorageAccountName + ".blob.core.windows.net/" + ConfigurationManager.AppSettings["azure-storage-blob-container"] + "/";

            var connectionString = ConfigurationManager.AppSettings["db_fodt"];
            var cfg = DatabaseBootstrapper.Bootstrap(connectionString);

            sessionFactory = cfg.BuildSessionFactory();

            Log("Opening Connection to Old FODT DB");
            oldDatabaseConnection = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.AppSettings["db_old_fodt"]);
            oldDatabaseConnection.Open();

            if (doDatabaseImport)
            {
                TruncateDatabase();
                ImportPhotos();
                ImportAwardsList();
                ImportPersons();
                ImportPersonPhotos();
                ImportShows();
                ImportShowPhotos();
                ImportAwards();
                ImportCast();
                ImportCrew();
                ImportEC();
                FixInsertedDateTimeColumns();
            }
            if (doFixLargePhotoFlag)
            {
                FixLargePhotoFlag();
            }
            if (doBlobUpload)
            {
                ImportPhotoBlobs();
            }
        }
Пример #23
0
        public int AddOrUpdate(int id, string endereco, object emails, string name, object phones, string empresa)
        {
            try
            {
                using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory())
                {
                    using (NHibernate.ISession session = sessionFactory.OpenSession())
                    {
                        using (NHibernate.ITransaction transaction = session.BeginTransaction())
                        {
                            ContatoEntitis contatoToBeSave = new ContatoEntitis
                            {
                                Id       = id,
                                Endereco = endereco,
                                Email    = JsonConvert.SerializeObject(emails),
                                Nome     = name,
                                Telefone = JsonConvert.SerializeObject(phones),
                                Empresa  = empresa
                            };

                            if (contatoToBeSave.Id > 0)
                            {
                                session.Update(contatoToBeSave);
                            }

                            else
                            {
                                session.Save(contatoToBeSave);
                            }

                            transaction.Commit();

                            return(contatoToBeSave.Id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #24
0
        private static NHibernate.ISessionFactory GetFactory()
        {
            NHibernate.ISessionFactory aISessionFactory = null;

            NHibernate.Cfg.Configuration aConfiguration = new NHibernate.Cfg.Configuration();

            if (aConfiguration == null)
            {
                throw new InvalidOperationException("La configurazione di NHibernate non è disponibile.");
            }

            aConfiguration.Configure();
            aISessionFactory = aConfiguration.BuildSessionFactory();

            if (aISessionFactory == null)
            {
                throw new InvalidOperationException("Impossibile creare l'oggetto NHibernate.ISessionFactory.");
            }

            return(aISessionFactory);
        }
Пример #25
0
        public List <ContatoEntitis> List()
        {
            try
            {
                List <ContatoEntitis> retorno = new List <ContatoEntitis>();
                using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory())
                {
                    using (NHibernate.ISession session = sessionFactory.OpenSession())
                    {
                        retorno = session.Query <ContatoEntitis>().ToList();
                        session.Flush();
                    }
                }

                return(retorno);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #26
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            sessionFactory = Fluently.Configure()
                .Database(
                    MsSqlConfiguration.MsSql2008
                    .ConnectionString(c => c.Server(@".\MSSQL2008R2")
                                            .Database("objectflow")
                                            .Username("objectflow")
                                            .Password("password"))
                    .DefaultSchema("dbo")
                )
                .Mappings(x => x.FluentMappings.AddFromAssemblyOf<MvcApplication>())
                //.ExposeConfiguration(cfg => cfg.SetProperty("current_session_context_class", "managed_web"))
                .BuildSessionFactory();
            //BeginRequest += MvcApplication_BeginRequest;
            //EndRequest += MvcApplication_EndRequest;
            BootstrapContainer();
        }
Пример #27
0
        public ContatoEntitis Get(int id)
        {
            try
            {
                ContatoEntitis retorno = new ContatoEntitis();

                using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory())
                {
                    using (NHibernate.ISession session = sessionFactory.OpenSession())
                    {
                        retorno = session.Get <ContatoEntitis>(id);
                        session.Flush();
                    }
                }

                return(retorno);
            }
            catch (Exception exs)
            {
                throw;
            }
        }
Пример #28
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            sessionFactory = Fluently.Configure()
                             .Database(
                MsSqlConfiguration.MsSql2008
                .ConnectionString(c => c.Server(@".\MSSQL2008R2")
                                  .Database("objectflow")
                                  .Username("objectflow")
                                  .Password("password"))
                .DefaultSchema("dbo")
                )
                             .Mappings(x => x.FluentMappings.AddFromAssemblyOf <MvcApplication>())
                             //.ExposeConfiguration(cfg => cfg.SetProperty("current_session_context_class", "managed_web"))
                             .BuildSessionFactory();
            //BeginRequest += MvcApplication_BeginRequest;
            //EndRequest += MvcApplication_EndRequest;
            BootstrapContainer();
        }
Пример #29
0
        /// <summary>
        /// Private constructor that initialises the unique instance of this class
        /// </summary>
        private DataManager()
        {
            try
            {
                // Initialise NHibernate Configuration  
                this.config = new NHibernate.Cfg.Configuration().Configure();

                // Add assembly
                this.config.AddAssembly( typeof(Person).Assembly );
                //this.config.AddAssembly( "Contact.hbm.xml" );
                //this.config.AddAssembly( "Person.hbm.xml" );
                //this.config.AddAssembly( "Project.hbm.xml" );
                //this.config.AddAssembly( "DataModel" );

                // Initialise NHibernate factory
                sessionFactory = this.config.BuildSessionFactory();
            }
            catch( Exception ex )
            {
                throw ex;
            }
        }
Пример #30
0
 		/// <summary> Configures NHibernate to access the data source and map entities to tables. </summary>
 		public Persister()
 		{
 			System.Console.Out.WriteLine("Configuration of NHibernate...\n");
 			const string connectionString = @"Data Source=(local)\sqlexpress;Initial Catalog=nhibernate;Integrated Security=SSPI";
 
 			// Enable the logging of NHibernate operations
 			log4net.Config.XmlConfigurator.Configure();
 
 			// Create the object that will hold the configuration settings
 			// and fill it with the information to access to the database
 			NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
 			configuration.Properties[NHibernate.Cfg.Environment.ConnectionProvider] = "NHibernate.Connection.DriverConnectionProvider";
 
 			System.Console.Out.WriteLine("Use SQL Server database: ConnectionString = <"
 				 + connectionString + ">\n");
 
 			// These are the three lines of code to change in order to use another database
 			configuration.Properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.Dialect.MsSql2000Dialect";
 			configuration.Properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver";
 			configuration.Properties[NHibernate.Cfg.Environment.ConnectionString] = connectionString;
 
 
 			// Use NHibernate.Mapping.Attributes to create mapping information about our entities
             System.Console.Out.WriteLine("Generating the mapping information for NHibernate...\n");
             NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)
             using (System.IO.MemoryStream stream = NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly()))
             {
                 configuration.AddInputStream(stream); // Send the mapping information to NHibernate configuration
             }
 
 			// Create the table in the database for the entity Message
 			System.Console.Out.WriteLine("Creating the table in the database for the entity Message...");
 			new NHibernate.Tool.hbm2ddl.SchemaExport(configuration).Create(true, true);
 
 
 			// Build the SessionFactory
 			System.Console.Out.WriteLine("\n\nBuilding the session factory, end of the configuration\n\n");
 			_sessionFactory = configuration.BuildSessionFactory();
 		}
Пример #31
0
 public static void Init()
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path = string.Empty;
         if (string.IsNullOrEmpty(configfilepath))
         {
             path = HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml");
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly("SocioBoardInvitationMailSender");//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error : " + ex.StackTrace);
     }
 }
Пример #32
0
        /// <summary>
        /// Uses reflection to create a new SoftLimitMRUCache with a specified size and sets session factory query plan cache to it.
        /// This is done like this as NHibernate does not currently provide any way to specify the query plan cache size through configuration.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private static bool TrySetQueryPlanCacheSize(NHibernate.ISessionFactory factory, int size)
        {
            var factoryImpl = factory as NHibernate.Impl.SessionFactoryImpl;

            if (factoryImpl != null)
            {
                var queryPlanCacheFieldInfo = typeof(NHibernate.Impl.SessionFactoryImpl).GetField("queryPlanCache", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                if (queryPlanCacheFieldInfo != null)
                {
                    var queryPlanCache = (NHibernate.Engine.Query.QueryPlanCache)queryPlanCacheFieldInfo.GetValue(factoryImpl);

                    var planCacheFieldInfo = typeof(NHibernate.Engine.Query.QueryPlanCache).GetField("planCache", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                    if (planCacheFieldInfo != null)
                    {
                        var softLimitMRUCache = new NHibernate.Util.SoftLimitMRUCache(size);

                        planCacheFieldInfo.SetValue(queryPlanCache, softLimitMRUCache);
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #33
0
        public bool Delete(ContatoEntitis contatoToBeDelete)
        {
            try
            {
                using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory())
                {
                    using (NHibernate.ISession session = sessionFactory.OpenSession())
                    {
                        using (NHibernate.ITransaction transaction = session.BeginTransaction())
                        {
                            session.Delete(contatoToBeDelete);
                            transaction.Commit();
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #34
0
 public static void Init()
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path = string.Empty;
         if (string.IsNullOrEmpty(configfilepath))
         {
             path = HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml");
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly("SocioBoard");//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error : " + ex.StackTrace);
     }
 }
Пример #35
0
 public static void Init()
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path = string.Empty;
         if (string.IsNullOrEmpty(configfilepath))
         {
             path = HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml");
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
 }
 public static void Init()
 {
     try
     {
         NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
         string path = string.Empty;
         if (string.IsNullOrEmpty(configfilepath))
         {
             path = HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml");
         }
         else
         {
             path = configfilepath;
         }
         config.Configure(path);
         config.AddAssembly(Assembly.GetExecutingAssembly());//adds all the embedded resources .hbm.xml
         sFactory = config.BuildSessionFactory();
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
 }
Пример #37
0
        public static NHibernate.ISession OpenSession()
        {
            if (factory == null)
            {
                try
                {
                    var config = new Configuration();
                    //config.Configure(@"D:\workspace\shoperp\DataConvert\bin\Debug\hibernate1.cfg.xml");
                    string file = EnvironmentDirHelper.PROGRAM_DIR + "\\" + @"hibernate.cfg.xml";
                    Console.WriteLine("正在使用数据库连接配置文件:" + file);
                    config.Configure(file);
                    config.AddAssembly(typeof(NHibernateHelper).Assembly);
                    config.BuildMappings();
                    factory = config.BuildSessionFactory();
                }
                catch (Exception ex)
                {
                    Logger.Log("初始货NHibernate失败", ex);
                    throw new Exception("初始化数据库连接失败", ex);
                }
            }

            return(factory.OpenSession());
        }
Пример #38
0
 public static void PopulateDatabase(object sender, NHibernate.ISessionFactory sessionFactory)
 {
     using (var session = sessionFactory.OpenSession())
         using (var tx = session.BeginTransaction())
         {
             if (session.Query <Culture>().Any())
             {
                 return;
             }
             var enCulture = new Culture {
                 DisplayName = "English", Name = "en-US", FlagFilename = "flag_En.png"
             };
             var roCulture = new Culture {
                 DisplayName = "Romana", Name = "ro-RO", FlagFilename = "flag_Ro.png"
             };
             var deCulture = new Culture {
                 DisplayName = "Deustch", Name = "de-DE", FlagFilename = "flag_De.png"
             };
             session.Save(enCulture);
             session.Save(roCulture);
             session.Save(deCulture);
             var USACountry = new Country {
                 Culture = enCulture, Name = "USA"
             };
             var RomaniaCountry = new Country {
                 Culture = roCulture, Name = "Romania"
             };
             var GermanyCountry = new Country {
                 Culture = deCulture, Name = "Germany"
             };
             session.Save(USACountry);
             session.Save(RomaniaCountry);
             session.Save(GermanyCountry);
             tx.Commit();
         }
 }
Пример #39
0
 public CategoryRepository(NHibernate.ISessionFactory northwind)
 {
     _northwind = northwind;
 }
Пример #40
0
        /// <summary>
        /// Initializes the session factory and ensure that the
        /// configuration file exists.
        /// </summary>
        private void InitSessionFactory()
        {
            //expect the hibernate.cfg.xml file to be in the application folder
            NHibernate.Cfg.Configuration temp = new NHibernate.Cfg.Configuration();

            cfg = temp.Configure();
            cfg.AddAssembly("gooeycms.data");

            //build the session factory based upon the configuration
            sessionFactory = cfg.BuildSessionFactory();
        }
Пример #41
0
        public void TestClusters ()
        {
            // each protein in the test scenarios is created from simple repeating motifs
            var testProteinSequences = new string[]
            {
                createSimpleProteinSequence("A", 20), // PRO1

                createSimpleProteinSequence("B", 20),

                createSimpleProteinSequence("C", 20),

                createSimpleProteinSequence("D", 20),

                createSimpleProteinSequence("E", 20), // PRO5
                createSimpleProteinSequence("E", 21),

                createSimpleProteinSequence("F", 20),
                createSimpleProteinSequence("F", 21),

                createSimpleProteinSequence("G", 20),
                createSimpleProteinSequence("G", 21), // PRO10
                
                createSimpleProteinSequence("H", 20),
                createSimpleProteinSequence("H", 21),
                
                createSimpleProteinSequence("AAAABBBBCCCC", 24),
                createSimpleProteinSequence("AAAABBBB", 24),
                createSimpleProteinSequence("BBBBCCCC", 24), // PRO15

                createSimpleProteinSequence("BBBBBDDDDD", 20),
                createSimpleProteinSequence("BBBBDDDD", 24),
                createSimpleProteinSequence("ZBBBBDDD", 24),
                createSimpleProteinSequence("YBBBDDD", 20),
                createSimpleProteinSequence("WBBDD", 21), // PRO20

                createSimpleProteinSequence("DDDDDFFFFF", 20),
                createSimpleProteinSequence("FFFFFHHHHH", 20),

                createSimpleProteinSequence("HHHHHKKKKK", 20),
                createSimpleProteinSequence("HHHHHKKKKK", 30),
                createSimpleProteinSequence("KKKKKMMMMM", 20), // PRO25

                createSimpleProteinSequence("LLLLLNNNNN", 20),
                createSimpleProteinSequence("NNNNNQQQQQ", 20),
                createSimpleProteinSequence("NNNNNQQQQQ", 30),

                createSimpleProteinSequence("MMMMMPPPPP", 20),
                createSimpleProteinSequence("PPPPPRRRRR", 20), // PRO30
                createSimpleProteinSequence("PPPPPRRRR", 24),
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            const int analysisCount = 2;
            const int sourceCount = 1;
            const int chargeCount = 2;

            for (int analysis = 1; analysis <= analysisCount; ++analysis)
            for (int source = 1; source <= sourceCount; ++source)
            for (int charge = 1; charge <= chargeCount; ++charge)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                    // Columns:     Group  Source Spectrum Analysis Score Q List of Peptide@Charge/ScoreDivider
                    
                    // 1 protein to 1 peptide to 1 spectrum = 1 additional peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAAAAAAAA@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein to 1 peptide to 2 spectra = 1 additional peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBBBBBB@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBBBBBB@{0}/1 CCCCCCCCCC@{0}/8", charge)),

                    // 1 protein to 2 peptides to 1 spectrum (each)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCCCCCCC@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCCCCCC@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein to 2 peptides to 2 spectra (each)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDDD@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDDD@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDD@{0}/1  AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDD@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins to 1 peptide to 1 spectrum (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("EEEEEEEEEE@{0}/1 AAAAAAAAAA@{0}/8", charge)),

                    // 2 proteins to 1 peptide to 2 spectra (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFFFFFF@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFFFFFF@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins to 2 peptides to 1 spectrum (each) (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGGGGGGG@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGGGGGG@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins to 2 peptides to 2 spectra (each) (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHHH@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHHH@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHH@{0}/1  AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHH@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein to 2 peptides
                    // 1 protein to 1 of the above peptides (subsumed protein)
                    // 1 protein to the other above peptide (subsumed protein)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAABBBB@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBCCCC@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein to 5 peptides
                    // 1 protein to 4 of the above peptides
                    // 1 protein to 3 of the above peptides and 1 extra peptides
                    // 1 protein to 2 of the above peptides and 2 extra peptides
                    // 1 protein to 1 of the above peptides and 3 extra peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBDDDDD@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBDDDD@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBDDD@{0}/1    AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBDD@{0}/1      BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBDD@{0}/1       AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("ZBBBBDDD@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("YBBBDD@{0}/1     AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("YBBBDDD@{0}/1    BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WBB@{0}/1        AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WBBD@{0}/1       BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WBBDD@{0}/1      AAAAAAAAAA@{0}/8", charge)),

                    // 1 protein to 3 peptides, 1 of which is evidenced by an ambiguous spectrum
                    // 1 protein to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDFFFFF@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDFFFF@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DFFFFF@{0}/1 FFFFFH@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFHHHHH@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    
                    // 2 proteins to 3 peptides, 1 of which is evidenced by an ambiguous spectrum
                    // 1 protein to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHKKKKK@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHKKKK@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HKKKKK@{0}/1 KKKKKM@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("KKKKKMMMMM@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    
                    // 1 protein to 3 peptides, 1 of which is evidenced by an ambiguous spectrum
                    // 2 proteins to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LLLLLNNNNN@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LLLLLNNNN@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LNNNNN@{0}/1 NNNNNQ@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("NNNNNQQQQQ@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    
                    // 1 protein to 3 peptides, 2 of which are evidenced by ambiguous spectra
                    // 1 protein to 1 peptide evidenced by an ambiguous spectrum above and 1 extra peptide
                    // 1 protein to 1 peptide evidenced by the other ambiguous spectrum above and 1 extra peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MMMMMPPPPP@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MPPPPP@{0}/1 PRRRRR@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("PPPPPRRRRR@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MPPPP@{0}/1 PRRRRP@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("PPPPRRRRP@{0}/1  AAAAAAAAAA@{0}/8", charge)),

                };

                TestModel.CreateTestData(session, testPsmSummary);
            }

            var dataFilter = new DataFilter()
            {
                MaximumQValue = 1,
                MinimumDistinctPeptides = 0,
                MinimumSpectra = 0,
                MinimumAdditionalPeptides = 0
            };
            dataFilter.ApplyBasicFilters(session);

            // clear session so objects are loaded from database
            session.Clear();

            // 1 protein to 1 peptide to 1 spectrum
            Assert.AreEqual(1, session.UniqueResult<Protein>(o => o.Accession == "PRO1").Cluster);

            // 1 protein to 1 peptide to 2 spectra
            Assert.AreEqual(6, session.UniqueResult<Protein>(o => o.Accession == "PRO2").Cluster);

            // 1 protein to 2 peptides to 1 spectrum (each)
            Assert.AreEqual(10, session.UniqueResult<Protein>(o => o.Accession == "PRO3").Cluster);

            // 1 protein to 2 peptides to 2 spectra (each)
            Assert.AreEqual(12, session.UniqueResult<Protein>(o => o.Accession == "PRO4").Cluster);

            // 2 proteins to 1 peptide to 1 spectrum (ambiguous protein group)
            Assert.AreEqual(13, session.UniqueResult<Protein>(o => o.Accession == "PRO5").Cluster);
            Assert.AreEqual(13, session.UniqueResult<Protein>(o => o.Accession == "PRO6").Cluster);

            // 2 proteins to 1 peptide to 2 spectra (ambiguous protein group)
            Assert.AreEqual(14, session.UniqueResult<Protein>(o => o.Accession == "PRO7").Cluster);
            Assert.AreEqual(14, session.UniqueResult<Protein>(o => o.Accession == "PRO8").Cluster);

            // 2 proteins to 2 peptides to 1 spectrum (each) (ambiguous protein group)
            Assert.AreEqual(2, session.UniqueResult<Protein>(o => o.Accession == "PRO9").Cluster);
            Assert.AreEqual(2, session.UniqueResult<Protein>(o => o.Accession == "PRO10").Cluster);

            // 2 proteins to 2 peptides to 2 spectra (each) (ambiguous protein group)
            Assert.AreEqual(3, session.UniqueResult<Protein>(o => o.Accession == "PRO11").Cluster);
            Assert.AreEqual(3, session.UniqueResult<Protein>(o => o.Accession == "PRO12").Cluster);

            // 1 protein to 2 peptides to 1 spectrum (each)
            // 1 protein to 1 of the above peptides (subsumed protein)
            // 1 protein to the other above peptide (subsumed protein)
            Assert.AreEqual(4, session.UniqueResult<Protein>(o => o.Accession == "PRO13").Cluster);
            Assert.AreEqual(4, session.UniqueResult<Protein>(o => o.Accession == "PRO14").Cluster);
            Assert.AreEqual(4, session.UniqueResult<Protein>(o => o.Accession == "PRO15").Cluster);

            // 1 protein to 5 peptides
            // 1 protein to 4 of the above peptides
            // 1 protein to 3 of the above peptides and 1 extra peptides
            // 1 protein to 2 of the above peptides and 2 extra peptides
            // 1 protein to 1 of the above peptides and 3 extra peptides
            Assert.AreEqual(5, session.UniqueResult<Protein>(o => o.Accession == "PRO16").Cluster);
            Assert.AreEqual(5, session.UniqueResult<Protein>(o => o.Accession == "PRO17").Cluster);
            Assert.AreEqual(5, session.UniqueResult<Protein>(o => o.Accession == "PRO18").Cluster);
            Assert.AreEqual(5, session.UniqueResult<Protein>(o => o.Accession == "PRO19").Cluster);
            Assert.AreEqual(5, session.UniqueResult<Protein>(o => o.Accession == "PRO20").Cluster);

            // 1 protein to 3 peptides, 1 of which is evidenced by an ambiguous spectrum
            // 1 protein to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide
            Assert.AreEqual(7, session.UniqueResult<Protein>(o => o.Accession == "PRO21").Cluster);
            Assert.AreEqual(7, session.UniqueResult<Protein>(o => o.Accession == "PRO22").Cluster);

            // 2 proteins to 3 peptides, 1 of which is evidenced by an ambiguous spectrum
            // 1 protein to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide
            Assert.AreEqual(8, session.UniqueResult<Protein>(o => o.Accession == "PRO23").Cluster);
            Assert.AreEqual(8, session.UniqueResult<Protein>(o => o.Accession == "PRO24").Cluster);
            Assert.AreEqual(8, session.UniqueResult<Protein>(o => o.Accession == "PRO25").Cluster);

            // 1 protein to 3 peptides, 1 of which is evidenced by an ambiguous spectrum
            // 2 proteins to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide
            Assert.AreEqual(9, session.UniqueResult<Protein>(o => o.Accession == "PRO26").Cluster);
            Assert.AreEqual(9, session.UniqueResult<Protein>(o => o.Accession == "PRO27").Cluster);
            Assert.AreEqual(9, session.UniqueResult<Protein>(o => o.Accession == "PRO28").Cluster);

            // 1 protein to 3 peptides, 2 of which are evidenced by ambiguous spectra
            // 1 protein to 1 peptide evidenced by an ambiguous spectrum above and 1 extra peptide
            // 1 protein to 1 peptide evidenced by the other ambiguous spectrum above and 1 extra peptide
            Assert.AreEqual(11, session.UniqueResult<Protein>(o => o.Accession == "PRO29").Cluster);
            Assert.AreEqual(11, session.UniqueResult<Protein>(o => o.Accession == "PRO30").Cluster);
            Assert.AreEqual(11, session.UniqueResult<Protein>(o => o.Accession == "PRO31").Cluster);

            session.Close();
        }
Пример #42
0
 public ProductRepository(NHibernate.ISessionFactory northwind)
 {
     _northwind = northwind;
 }
Пример #43
0
        public void TestAdditionalPeptides ()
        {
            // each protein in the test scenarios is created from simple repeating motifs
            var testProteinSequences = new string[]
            {
                createSimpleProteinSequence("A", 20), // PRO1

                createSimpleProteinSequence("B", 20),

                createSimpleProteinSequence("C", 20),

                createSimpleProteinSequence("D", 20),

                createSimpleProteinSequence("E", 20), // PRO5
                createSimpleProteinSequence("E", 21),

                createSimpleProteinSequence("F", 20),
                createSimpleProteinSequence("F", 21),

                createSimpleProteinSequence("G", 20),
                createSimpleProteinSequence("G", 21), // PRO10
                
                createSimpleProteinSequence("H", 20),
                createSimpleProteinSequence("H", 21),
                
                createSimpleProteinSequence("AAAABBBBCCCC", 24),
                createSimpleProteinSequence("AAAABBBB", 24),
                createSimpleProteinSequence("BBBBCCCC", 24), // PRO15
                
                createSimpleProteinSequence("DDDDEEEEFFFF", 24),
                createSimpleProteinSequence("DDDDEEEE", 24),
                createSimpleProteinSequence("DDDDEEEE", 16),

                createSimpleProteinSequence("GGGGHHHHIIII", 24),
                createSimpleProteinSequence("GGGGHHHHIIII", 36), // PRO20
                createSimpleProteinSequence("GGGGHHHH", 24),
                createSimpleProteinSequence("HHHHIIII", 24),
                
                createSimpleProteinSequence("KKKKLLLLMMMM", 24),
                createSimpleProteinSequence("KKKKLLLLMMMM", 36),
                createSimpleProteinSequence("LLLLMMMM", 24), // PRO25
                createSimpleProteinSequence("LLLLMMMM", 16),
                
                createSimpleProteinSequence("NNNNPPPPQQQQ", 24),
                createSimpleProteinSequence("PPPPQQQQRRRR", 24),
                
                createSimpleProteinSequence("SSSSTTTTUUUU", 24),
                createSimpleProteinSequence("TTTTUUUUVVVV", 24), // PRO30
                createSimpleProteinSequence("TTTTUUUUVVVV", 36),
                
                createSimpleProteinSequence("WWWWYYYYZZZZ", 24),
                createSimpleProteinSequence("WWWWYYYYZZZZ", 36),
                createSimpleProteinSequence("YYYYZZZZFFFF", 24),
                
                createSimpleProteinSequence("AAAACCCCEEEE", 24), // PRO35
                createSimpleProteinSequence("AAAACCCCEEEE", 36),
                createSimpleProteinSequence("CCCCEEEEGGGG", 24),
                createSimpleProteinSequence("CCCCEEEEGGGG", 36),

                createSimpleProteinSequence("BBBBBDDDDD", 20),
                createSimpleProteinSequence("BBBBDDDD", 24), // PRO40
                createSimpleProteinSequence("ZBBBBDDD", 24),
                createSimpleProteinSequence("YBBBDDD", 20),
                createSimpleProteinSequence("WBBDD", 21),

                createSimpleProteinSequence("DDDDDFFFFF", 20),
                createSimpleProteinSequence("FFFFFHHHHH", 20), // PRO45

                createSimpleProteinSequence("HHHHHKKKKK", 20),
                createSimpleProteinSequence("HHHHHKKKKK", 30),
                createSimpleProteinSequence("KKKKKMMMMM", 20),

                createSimpleProteinSequence("LLLLLNNNNN", 20),
                createSimpleProteinSequence("NNNNNQQQQQ", 20), // PRO50
                createSimpleProteinSequence("NNNNNQQQQQ", 30),

                createSimpleProteinSequence("MMMMMPPPPP", 20),
                createSimpleProteinSequence("PPPPPRRRRR", 20),
                createSimpleProteinSequence("PPPPPRRRR", 24),

                createSimpleProteinSequence("QQQQSSSSUUUU", 24), // PRO55
                createSimpleProteinSequence("SSSSUUUUYYYY", 24),

                createSimpleProteinSequence("RRRRTTTTWWWWZZZZ", 32),
                createSimpleProteinSequence("TTTTWWWWZZZZBBBB", 32),
                createSimpleProteinSequence("RRRRTTTTZZZZBBBBTTTTWWWW", 24),

                createSimpleProteinSequence("AAAADDDDGGGGKKKK", 32), // PRO60
                createSimpleProteinSequence("DDDDGGGGKKKKNNNN", 32),
                createSimpleProteinSequence("AAAADDDDKKKKNNNN", 32),

                createSimpleProteinSequence("BBBBEEEEHHHH", 24),
                createSimpleProteinSequence("EEEEHHHHLLLL", 24),
                createSimpleProteinSequence("HHHHLLLLPPPP", 24), // PRO65

                createSimpleProteinSequence("CCCCFFFFIIII", 24),
                createSimpleProteinSequence("FFFFIIIIMMMM", 24),
                createSimpleProteinSequence("IIIIMMMMQQQQ", 24),

                createSimpleProteinSequence("NNNNRRRRUUUU", 24),
                createSimpleProteinSequence("RRRRUUUUZZZZ", 24), // PRO70
                createSimpleProteinSequence("UUUUZZZZCCCC", 24),
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            const int analysisCount = 2;
            const int sourceCount = 1;
            const int chargeCount = 2;

            for (int analysis = 1; analysis <= analysisCount; ++analysis)
            for (int source = 1; source <= sourceCount; ++source)
            for (int charge = 1; charge <= chargeCount; ++charge)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                    // Columns:     Group  Source Spectrum Analysis Score Q List of Peptide@Charge/ScoreDivider
                    
                    // 1 protein (PRO1) to 1 peptide to 1 spectrum = 1 additional peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAAAAAAAA@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO2) to 1 peptide to 2 spectra = 1 additional peptide
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBBBBBB@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBBBBBB@{0}/1 CCCCCCCCCC@{0}/8", charge)),

                    // 1 protein (PRO3) to 2 peptides to 1 spectrum (each) = 2 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCCCCCCC@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCCCCCC@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO4) to 2 peptides to 2 spectra (each) = 2 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDDD@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDDD@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDD@{0}/1  AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDD@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO5,6) to 1 peptide to 1 spectrum = 1 additional peptide (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("EEEEEEEEEE@{0}/1 AAAAAAAAAA@{0}/8", charge)),

                    // 2 proteins (PRO7,8) to 1 peptide to 2 spectra = 1 additional peptide (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFFFFFF@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFFFFFF@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO9,10) to 2 peptides to 1 spectrum (each) = 2 additional peptides (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGGGGGGG@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGGGGGG@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO11,12) to 2 peptides to 2 spectra (each) = 2 additional peptides (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHHH@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHHH@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHH@{0}/1  AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHHHHH@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO13) to 2 peptides = 2 additional peptide
                    // 1 protein (PRO14) to 1 of the above peptides = 0 additional peptides (subsumed protein)
                    // 1 protein (PRO15) to the other above peptide = 0 additional peptides (subsumed protein)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAABBBB@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBCCCC@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO16) to 2 peptides = 2 additional peptide
                    // 2 proteins (PRO17,18) to 1 of the above peptides = 0 additional peptides (subsumed ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDEEEE@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("EEEEFFFF@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO19,20) to 2 peptides = 2 additional peptide (ambiguous protein group)
                    // 1 protein (PRO21) to 1 of the above peptides = 0 additional peptides (subsumed protein)
                    // 1 protein (PRO22) to the other above peptide = 0 additional peptides (subsumed protein)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGHHHH@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHIIII@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO23,24) to 2 peptides = 2 additional peptides (ambiguous protein group)
                    // 2 proteins (PRO25,26) to 1 of the above peptides = 0 additional peptides (subsumed ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("KKKKLLLL@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LLLLMMMM@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO27) to 3 peptides = 3 additional peptides
                    // 1 protein (PRO28) to 1 of the above peptides and 1 extra peptide = 1 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("NNNNPPPP@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("NNNNPPP@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("PPPPQQQQ@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("QQQQRRRR@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO29) to 3 peptides = 3 additional peptides
                    // 2 proteins (PRO30,31) to 1 of the above peptides and 1 extra peptide = 1 additional peptides (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("SSSSTTTT@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("SSSSTTT@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("TTTTUUUU@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("UUUUVVVV@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO32,33) to 3 peptides = 3 additional peptides (ambiguous protein group)
                    // 1 protein (PRO34) to 1 of the above peptides and 1 extra peptide = 1 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WWWWYYYY@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WWWWYYY@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("YYYYZZZZ@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("ZZZZFFFF@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 2 proteins (PRO35,36) to 3 peptides = 3 additional peptides (ambiguous protein group)
                    // 2 proteins (PRO37,38) to 1 of the above peptides and 1 extra peptide = 1 additional peptides (ambiguous protein group)
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAACCCC@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAACCC@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCEEEE@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("EEEEGGGG@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                    // 1 protein (PRO39) to 5 peptides = 5 additional peptides
                    // 1 protein (PRO40) to 4 of the above peptides = 0 additional peptides
                    // 1 protein (PRO41) to 3 of the above peptides and 1 extra peptides = 1 additional peptides
                    // 1 protein (PRO42) to 2 of the above peptides and 2 extra peptides = 2 additional peptides
                    // 1 protein (PRO43) to 1 of the above peptides and 3 extra peptides = 3 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBDDDDD@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBDDDD@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBDDD@{0}/1    AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBDD@{0}/1      BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBDD@{0}/1       AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("ZBBBBDDD@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("YBBBDD@{0}/1     AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("YBBBDDD@{0}/1    BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WBB@{0}/1        AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WBBD@{0}/1       BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WBBDD@{0}/1      AAAAAAAAAA@{0}/8", charge)),

                    // 1 protein (PRO44) to 3 peptides, 1 of which is evidenced by an ambiguous spectrum = 3 additional peptides
                    // 1 protein (PRO45) to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide = 1 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDFFFFF@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDFFFF@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DFFFFF@{0}/1 FFFFFH@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFHHHHH@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    
                    // 2 proteins (PRO46,47) to 3 peptides, 1 of which is evidenced by an ambiguous spectrum = 3 additional peptides
                    // 1 protein (PRO48) to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide = 1 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHKKKKK@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHKKKK@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HKKKKK@{0}/1 KKKKKM@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("KKKKKMMMMM@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    
                    // 1 protein (PRO49) to 3 peptides, 1 of which is evidenced by an ambiguous spectrum = 3 additional peptides
                    // 2 proteins (PRO50,51) to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide = 1 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LLLLLNNNNN@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LLLLLNNNN@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LNNNNN@{0}/1 NNNNNQ@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("NNNNNQQQQQ@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    
                    // 1 protein (PRO52) to 3 peptides, 2 of which are evidenced by ambiguous spectra = 3 additional peptides
                    // 1 protein (PRO53) to 1 peptide evidenced by an ambiguous spectrum above and 1 extra peptide = 1 additional peptides
                    // 1 protein (PRO54) to 1 peptide evidenced by the other ambiguous spectrum above and 1 extra peptide = 1 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MMMMMPPPPP@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MPPPPP@{0}/1 PRRRRR@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("PPPPPRRRRR@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MPPPP@{0}/1 PRRRRP@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("PPPPRRRRP@{0}/1  AAAAAAAAAA@{0}/8", charge)),

                    // PRO55 -> QQQQSSSS, SSSSUUUU = 2 additional peptides
                    // PRO56 -> UUUUYYYY, SSSSUUUU = 2 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("QQQQSSSS@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("SSSSUUUU@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("UUUUYYYY@{0}/1   AAAAAAAAAA@{0}/8", charge)),

                    // PRO57 -> RRRRTTTT, WWWWZZZZ, TTTTWWWW = 3 additional peptides
                    // PRO58 -> ZZZZBBBB, WWWWZZZZ, TTTTWWWW = 3 additional peptides
                    // PRO59 -> RRRRTTTT, ZZZZBBBB, TTTTWWWW = 3 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("RRRRTTTT@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("WWWWZZZZ@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("TTTTWWWW@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("ZZZZBBBB@{0}/1   BBBBBBBBBB@{0}/8", charge)),

                    // PRO60 -> AAAADDDD, DDDDGGGG, GGGGKKKK = 3 additional peptides
                    // PRO61 -> DDDDGGGG, GGGGKKKK, KKKKNNNN = 3 additional peptides
                    // PRO62 -> AAAADDDD, KKKKNNNN = 0 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAADDDD@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDGGGG@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGKKKK@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("KKKKNNNN@{0}/1   BBBBBBBBBB@{0}/8", charge)),

                    // PRO63 -> BBBBEEEE, EEEEHHHH = 2 additional peptides
                    // PRO64 -> EEEEHHHH, HHHHLLLL = 0 additional peptides
                    // PRO65 -> HHHHLLLL, LLLLPPPP = 2 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBEEEE@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("EEEEHHHH@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHLLLL@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("LLLLPPPP@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    
                    // PRO66 -> CCCCFFFF, CFFFFI, FFFFIIII = 3 additional peptides
                    // PRO67 -> FFFFIIII, FIIIIM, IIIIMMMM = 1 additional peptides
                    // PRO68 -> IIIIMMMM, IMMMMQ, MMMMQQQQ = 3 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCFFFF@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CFFFFI@{0}/1     BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFIIII@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FIIIIM@{0}/1     BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("IIIIMMMM@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("IMMMMQ@{0}/1     BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("MMMMQQQQ@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    
                    // PRO69 -> NNNNRRRR, RRRRUUUU, RRRRUUU = 3 additional peptides
                    // PRO70 -> RRRRUUUU, RRRRUUU, UUUUZZZZ = 0 additional peptides
                    // PRO71 -> UUUUZZZZ, UZZZZC, ZZZZCCCC = 3 additional peptides
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("NNNNRRRR@{0}/1   AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("RRRRUUUU@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("RRRRUUU@{0}/1    AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("UUUUZZZZ@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("UZZZZC@{0}/1     AAAAAAAAAA@{0}/8", charge)),
                    new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("ZZZZCCCC@{0}/1   BBBBBBBBBB@{0}/8", charge)),
                };

                TestModel.CreateTestData(session, testPsmSummary);
            }

            var dataFilter = new DataFilter()
            {
                MaximumQValue = 1,
                MinimumDistinctPeptides = 0,
                MinimumSpectra = 0,
                MinimumAdditionalPeptides = 1
            };
            dataFilter.ApplyBasicFilters(session);

            // clear session so objects are loaded from database
            session.Clear();

            var additionalPeptidesByProteinId = new Map<long, int>();
            foreach (object[] row in session.CreateSQLQuery("SELECT ProteinId, AdditionalMatches FROM AdditionalMatches").List<object[]>())
                additionalPeptidesByProteinId[Convert.ToInt64(row[0])] = Convert.ToInt32(row[1]);

            // 1 protein to 1 peptide to 1 spectrum = 1 additional peptide
            Assert.AreEqual(1, additionalPeptidesByProteinId[1]);

            // 1 protein to 1 peptide to 2 spectra = 1 additional peptide
            Assert.AreEqual(1, additionalPeptidesByProteinId[2]);

            // 1 protein to 2 peptides to 1 spectrum (each) = 2 additional peptides
            Assert.AreEqual(2, additionalPeptidesByProteinId[3]);

            // 1 protein to 2 peptides to 2 spectra (each) = 2 additional peptides
            Assert.AreEqual(2, additionalPeptidesByProteinId[4]);

            // 2 proteins to 1 peptide to 1 spectrum = 1 additional peptide (ambiguous protein group)
            Assert.AreEqual(1, additionalPeptidesByProteinId[5]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[6]);

            // 2 proteins to 1 peptide to 2 spectra = 1 additional peptide (ambiguous protein group)
            Assert.AreEqual(1, additionalPeptidesByProteinId[7]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[8]);

            // 2 proteins to 2 peptides to 1 spectrum (each) = 2 additional peptides (ambiguous protein group)
            Assert.AreEqual(2, additionalPeptidesByProteinId[9]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[10]);

            // 2 proteins to 2 peptides to 2 spectra (each) = 2 additional peptides (ambiguous protein group)
            Assert.AreEqual(2, additionalPeptidesByProteinId[11]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[12]);

            // 1 protein to 2 peptides to 1 spectrum (each) = 2 additional peptide
            // 1 protein to 1 of the above peptides = 0 additional peptides (subsumed protein)
            // 1 protein to the other above peptide = 0 additional peptides (subsumed protein)
            Assert.AreEqual(2, additionalPeptidesByProteinId[13]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[14]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[15]);

            // 1 protein to 2 peptides to 1 spectrum (each) = 2 additional peptide
            // 2 proteins to 1 of the above peptides = 0 additional peptides (subsumed ambiguous protein group)
            Assert.AreEqual(2, additionalPeptidesByProteinId[16]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[17]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[18]);

            // 2 proteins to 2 peptides to 1 spectrum (each) = 2 additional peptide (ambiguous protein group)
            // 1 protein to 1 of the above peptides = 0 additional peptides (subsumed protein)
            // 1 protein to the other above peptide = 0 additional peptides (subsumed protein)
            Assert.AreEqual(2, additionalPeptidesByProteinId[19]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[20]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[21]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[22]);

            // 2 proteins to 2 peptides to 1 spectrum (each) = 2 additional peptides (ambiguous protein group)
            // 2 proteins to 1 of the above peptides = 0 additional peptides (subsumed ambiguous protein group)
            Assert.AreEqual(2, additionalPeptidesByProteinId[23]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[24]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[25]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[26]);

            // 1 protein to 3 peptides to 1 spectrum (each) = 3 additional peptides
            // 1 protein to 1 of the above peptides and 1 extra peptide to 1 spectrum = 1 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[27]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[28]);

            // 1 protein to 3 peptides to 1 spectrum (each) = 3 additional peptides
            // 2 proteins to 1 of the above peptides and 1 extra peptide to 1 spectrum = 1 additional peptides (ambiguous protein group)
            Assert.AreEqual(3, additionalPeptidesByProteinId[29]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[30]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[31]);

            // 2 proteins to 3 peptides to 1 spectrum (each) = 3 additional peptides (ambiguous protein group)
            // 1 protein to 1 of the above peptides and 1 extra peptide to 1 spectrum = 1 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[32]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[33]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[34]);

            // 2 proteins to 3 peptides to 1 spectrum (each) = 3 additional peptides (ambiguous protein group)
            // 2 proteins to 1 of the above peptides and 1 extra peptide to 1 spectrum = 1 additional peptides (ambiguous protein group)
            Assert.AreEqual(3, additionalPeptidesByProteinId[35]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[36]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[37]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[38]);

            // 1 protein (PRO39) to 5 peptides = 5 additional peptides
            // 1 protein (PRO40) to 4 of the above peptides = 0 additional peptides
            // 1 protein (PRO41) to 3 of the above peptides and 1 extra peptides = 1 additional peptides
            // 1 protein (PRO42) to 2 of the above peptides and 2 extra peptides = 2 additional peptides
            // 1 protein (PRO43) to 1 of the above peptides and 3 extra peptides = 3 additional peptides
            Assert.AreEqual(5, additionalPeptidesByProteinId[39]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[40]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[41]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[42]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[43]);

            // 1 protein (PRO44) to 3 peptides, 1 of which is evidenced by an ambiguous spectrum = 3 additional peptides
            // 1 protein (PRO45) to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide = 1 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[44]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[45]);
                    
            // 2 proteins (PRO46,47) to 3 peptides, 1 of which is evidenced by an ambiguous spectrum = 3 additional peptides
            // 1 protein (PRO48) to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide = 1 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[46]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[47]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[48]);
            
            // 1 protein (PRO49) to 3 peptides, 1 of which is evidenced by an ambiguous spectrum = 3 additional peptides
            // 2 proteins (PRO50,51) to 1 peptide evidenced by the ambiguous spectrum above and 1 extra peptide = 1 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[49]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[50]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[51]);

            // 1 protein (PRO52) to 3 peptides, 2 of which are evidenced by ambiguous spectra = 3 additional peptides
            // 1 protein (PRO53) to 1 peptide evidenced by an ambiguous spectrum above and 1 extra peptide = 1 additional peptides
            // 1 protein (PRO54) to 1 peptide evidenced by the other ambiguous spectrum above and 1 extra peptide = 1 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[52]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[53]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[54]);
            
            // PRO55 -> QQQQSSSS, SSSSUUUU = 2 additional peptides
            // PRO56 -> UUUUYYYY, SSSSUUUU = 2 additional peptides
            Assert.AreEqual(2, additionalPeptidesByProteinId[55]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[56]);

            // PRO57 -> RRRRTTTT, WWWWZZZZ, TTTTWWWW = 3 additional peptides
            // PRO58 -> QQQQKKKK, WWWWZZZZ, TTTTWWWW = 3 additional peptides
            // PRO59 -> RRRRTTTT, TTTTZZZZ, TTTTWWWW = 3 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[57]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[58]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[59]);

            // PRO60 -> AAAADDDD, DDDDGGGG, GGGGKKKK = 3 additional peptides
            // PRO61 -> DDDDGGGG, GGGGKKKK, KKKKNNNN = 3 additional peptides
            // PRO62 -> AAAADDDD, KKKKNNNN = 0 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[60]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[61]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[62]);

            // PRO63 -> BBBBEEEE, EEEEHHHH = 2 additional peptides
            // PRO64 -> EEEEHHHH, HHHHLLLL = 0 additional peptides
            // PRO65 -> HHHHLLLL, LLLLPPPP = 2 additional peptides
            Assert.AreEqual(2, additionalPeptidesByProteinId[63]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[64]);
            Assert.AreEqual(2, additionalPeptidesByProteinId[65]);

            // PRO66 -> CCCCFFFF, CFFFFI, FFFFIIII = 3 additional peptides
            // PRO67 -> FFFFIIII, FIIIIM, IIIIMMMM = 1 additional peptides
            // PRO68 -> IIIIMMMM, IMMMMQ, MMMMQQQQ = 3 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[66]);
            Assert.AreEqual(1, additionalPeptidesByProteinId[67]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[68]);

            // PRO69 -> NNNNRRRR, RRRRUUUU, RRRRUUU = 3 additional peptides
            // PRO70 -> RRRRUUUU, RRRRUUU, UUUUZZZZ = 0 additional peptides
            // PRO71 -> UUUUZZZZ, UZZZZC, ZZZZCCCC = 3 additional peptides
            Assert.AreEqual(3, additionalPeptidesByProteinId[69]);
            Assert.AreEqual(0, additionalPeptidesByProteinId[70]);
            Assert.AreEqual(3, additionalPeptidesByProteinId[71]);

            // test that the MinimumAdditionalPeptidesPerProtein filter is applied correctly;
            // proteins filtered out by it should cascade to PeptideInstances, Peptides, and PSMs

            dataFilter.MinimumAdditionalPeptides = 1;
            dataFilter.ApplyBasicFilters(session);

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO55"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO56"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO57"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO58"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO59"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO60"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO61"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO62"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO62"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "AAAADDDD"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "KKKKNNNN"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO63"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO64"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO65"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO64"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "EEEEHHHH"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHLLLL"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO66"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO67"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO68"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO69"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO70"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO71"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO70"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "RRRRUUUU"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "RRRRUUU"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "UUUUZZZZ"));

            dataFilter.MinimumAdditionalPeptides = 2;
            dataFilter.ApplyBasicFilters(session);

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO55"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO56"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO57"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO58"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO59"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO60"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO61"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO62"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO62"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO63"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO64"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO65"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO64"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO66"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO67"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO68"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO67"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "FIIIIM"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "FIIIIM"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO69"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO70"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO71"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO70"));

            dataFilter.MinimumAdditionalPeptides = 3;
            dataFilter.ApplyBasicFilters(session);

            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO55"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO56"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO55"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO56"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "QQQQSSSS"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "SSSSUUUU"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "UUUUYYYY"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "QQQQSSSS"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "SSSSUUUU"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "UUUUYYYY"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO57"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO58"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO59"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO60"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO61"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO62"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO62"));

            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO63"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO64"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO65"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO63"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO64"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO65"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "BBBBEEEE"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "EEEEHHHH"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHLLLL"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "LLLLPPPP"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "BBBBEEEE"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "EEEEHHHH"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "HHHHLLLL"));
            Assert.IsNull(session.UniqueResult<PeptideSpectrumMatch>(o => o.Peptide.Sequence == "LLLLPPPP"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO66"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO67"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO68"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO67"));

            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO69"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Accession == "PRO70"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO71"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession == "PRO70"));

            dataFilter.MinimumAdditionalPeptides = 4;
            dataFilter.ApplyBasicFilters(session);

            Assert.AreEqual(1, session.Query<Protein>().Count());
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO39"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession != "PRO39"));

            var remainingPeptides = new string[] { "BBBBBDDDDD", "BBBBDDDD", "BBBBDDD", "BBBDD", "BBDD" };
            Assert.AreEqual(5, session.Query<Peptide>().Count());
            Assert.AreEqual(5, session.Query<Peptide>().Count(o => remainingPeptides.Contains(o.Sequence)));
            Assert.AreEqual(0, session.Query<Peptide>().Count(o => !remainingPeptides.Contains(o.Sequence)));
            Assert.AreNotEqual(0, session.Query<PeptideSpectrumMatch>().Count(o => remainingPeptides.Contains(o.Peptide.Sequence)));
            Assert.AreEqual(0, session.Query<PeptideSpectrumMatch>().Count(o => !remainingPeptides.Contains(o.Peptide.Sequence)));

            dataFilter.MinimumAdditionalPeptides = 5;
            dataFilter.ApplyBasicFilters(session);

            Assert.AreEqual(1, session.Query<Protein>().Count());
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Accession == "PRO39"));
            Assert.IsNull(session.UniqueResult<PeptideInstance>(o => o.Protein.Accession != "PRO39"));

            dataFilter.MinimumAdditionalPeptides = 6;
            dataFilter.ApplyBasicFilters(session);

            Assert.AreEqual(0, session.Query<Protein>().Count());
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count());
            Assert.AreEqual(0, session.Query<Peptide>().Count());
            Assert.AreEqual(0, session.Query<PeptideSpectrumMatch>().Count());

            session.Close();
        }
Пример #44
0
 private SecondCache(NHibernate.ISessionFactory factory)
 {
     this._factory = factory;
 }
Пример #45
0
        public void TestFilteredQueries ()
        {
            // each protein in the test scenarios is created from simple repeating motifs
            var testProteinSequences = new string[]
            {
                createSimpleProteinSequence("A", 20), // PRO1

                createSimpleProteinSequence("B", 20),

                createSimpleProteinSequence("C", 20),

                createSimpleProteinSequence("D", 20),

                createSimpleProteinSequence("E", 20), // PRO5
                createSimpleProteinSequence("E", 21),

                createSimpleProteinSequence("F", 20),
                createSimpleProteinSequence("F", 21),

                createSimpleProteinSequence("G", 20),
                createSimpleProteinSequence("G", 21), // PRO10

                createSimpleProteinSequence("H", 20),
                createSimpleProteinSequence("H", 21),

                createSimpleProteinSequence("AAAABBBBCCCC", 24),
                createSimpleProteinSequence("AAAABBBB", 24),
                createSimpleProteinSequence("BBBBCCCC", 24), // PRO15

                createSimpleProteinSequence("BBBBBDDDDD", 20),
                createSimpleProteinSequence("BBBBDDDD", 24),
                createSimpleProteinSequence("ZBBBBDDD", 24),
                createSimpleProteinSequence("YBBBDDD", 20),
                createSimpleProteinSequence("WBBDD", 21), // PRO20

                createSimpleProteinSequence("DDDDDFFFFF", 20),
                createSimpleProteinSequence("FFFFFHHHHH", 20),

                createSimpleProteinSequence("HHHHHKKKKK", 20),
                createSimpleProteinSequence("HHHHHKKKKK", 30),
                createSimpleProteinSequence("KKKKKMMMMM", 20), // PRO25

                createSimpleProteinSequence("LLLLLNNNNN", 20),
                createSimpleProteinSequence("NNNNNQQQQQ", 20),
                createSimpleProteinSequence("NNNNNQQQQQ", 30),

                createSimpleProteinSequence("MMMMMPPPPP", 20),
                createSimpleProteinSequence("PPPPPRRRRR", 20), // PRO30
                createSimpleProteinSequence("PPPPPRRRR", 24),

                createSimpleProteinSequence("QQQQSSSSUUUU", 24),
                createSimpleProteinSequence("SSSSUUUUYYYY", 24),

                createSimpleProteinSequence("RRRRTTTTWWWWZZZZ", 32),
                createSimpleProteinSequence("TTTTWWWWZZZZBBBB", 32), // PRO35
                createSimpleProteinSequence("RRRRTTTTZZZZBBBBTTTTWWWW", 24),

                createSimpleProteinSequence("AAAADDDDGGGGKKKK", 32),
                createSimpleProteinSequence("DDDDGGGGKKKKNNNN", 32),
                createSimpleProteinSequence("AAAADDDDKKKKNNNN", 32),

                createSimpleProteinSequence("BBBBEEEEHHHH", 24), // PRO40
                createSimpleProteinSequence("EEEEHHHHLLLL", 24),
                createSimpleProteinSequence("HHHHLLLLPPPP", 24),

                createSimpleProteinSequence("CCCCFFFFIIII", 24),
                createSimpleProteinSequence("FFFFIIIIMMMM", 24),
                createSimpleProteinSequence("IIIIMMMMQQQQ", 24), // PRO45

                createSimpleProteinSequence("NNNNRRRRUUUU", 24),
                createSimpleProteinSequence("RRRRUUUUZZZZ", 24),
                createSimpleProteinSequence("UUUUZZZZCCCC", 24),
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            var log = new StringWriter();
            Console.SetOut(log);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true, WriteSqlToConsoleOut = true});
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            const int analysisCount = 2;
            const int sourceCount = 1;
            const int chargeCount = 2;
            int totalPSMs = 0;

            for (int analysis = 1; analysis <= analysisCount; ++analysis)
            for (int source = 1; source <= sourceCount; ++source)
            for (int charge = 1; charge <= chargeCount; ++charge)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                     // Columns:     Group  Source Spectrum Analysis Score Q List of Peptide@Charge/ScoreDivider

                     // 1 protein (PRO1) to 1 peptide to 1 spectrum = 1 additional peptide
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("AAAAAAAAAA@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                     // 1 protein (PRO2) to 1 peptide to 2 spectra = 1 additional peptide
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBBBBBB@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("BBBBBBBBBB@{0}/1 CCCCCCCCCC@{0}/8", charge)),

                     // 1 protein (PRO3) to 2 peptides to 1 spectrum (each) = 2 additional peptides
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCCCCCCC@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("CCCCCCCCC@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                     // 1 protein (PRO4) to 2 peptides to 2 spectra (each) = 2 additional peptides
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDDD@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDDD@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDD@{0}/1  AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("DDDDDDDDD@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                     // 2 proteins (PRO5,6) to 1 peptide to 1 spectrum = 1 additional peptide (ambiguous protein group)
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("EEEEEEEEEE@{0}/1 AAAAAAAAAA@{0}/8", charge)),

                     // 2 proteins (PRO7,8) to 1 peptide to 2 spectra = 1 additional peptide (ambiguous protein group)
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFF[C1H2]FFFFFF@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("FFFFFFFFFF@{0}/1 BBBBBBBBBB@{0}/8", charge)),

                     // 2 proteins (PRO9,10) to 2 peptides to 1 spectrum (each) = 2 additional peptides (ambiguous protein group)
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGGGGGGG@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("GGGGGGGGG@{0}/1  BBBBBBBBBB@{0}/8", charge)),

                     // 2 proteins (PRO11,12) to 2 peptides to 2 spectra (each) = 2 additional peptides (ambiguous protein group)
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHH[O1]HHHHH@{0}/1 AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("HHHHHH[O1]HHHH@{0}/1 BBBBBBBBBB@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("[O1]HHHHHHHHH@{0}/1  AAAAAAAAAA@{0}/8", charge)),
                     new SpectrumTuple("/", source, ++scan, analysis, 1, 1, String.Format("[O1]HHHHHHHHH@{0}/1  BBBBBBBBBB@{0}/8", charge)),
                };

                totalPSMs += scan;
                TestModel.CreateTestData(session, testPsmSummary);
            }

            var dataFilter = new DataFilter()
                                 {
                                     MaximumQValue = 1,
                                     MinimumDistinctPeptides = 1,
                                     MinimumSpectra = 1,
                                     MinimumAdditionalPeptides = 1
                                 };
            dataFilter.ApplyBasicFilters(session);

            // clear session so objects are loaded from database
            session.Clear();

            // test with default DistinctMatchFormat (charge state and modifications distinct)
            {
                var peptideRows = IDPicker.Forms.PeptideTableForm.DistinctPeptideRow.GetRows(session, dataFilter);
                int row = 0;
                Assert.AreEqual(12, peptideRows.Count);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "AAAAAAAAAA"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "BBBBBBBBBB"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "CCCCCCCCCC"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "CCCCCCCCC"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "DDDDDDDDDD"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "DDDDDDDDD"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "EEEEEEEEEE"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "FFFFFFFFFF"), peptideRows[row].Peptide);
                Assert.AreEqual(4, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "GGGGGGGGGG"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "GGGGGGGGG"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHHHHHHH"), peptideRows[row].Peptide);
                Assert.AreEqual(4, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHHHHHH"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);
            }

            // test with charge state and analysis indistinct and modifications distinct
            {
                dataFilter.DistinctMatchFormat.IsChargeDistinct = false;
                dataFilter.DistinctMatchFormat.IsAnalysisDistinct = false;
                dataFilter.ApplyBasicFilters(session);

                var peptideRows = IDPicker.Forms.PeptideTableForm.DistinctPeptideRow.GetRows(session, dataFilter);
                int row = 0;

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "AAAAAAAAAA"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "BBBBBBBBBB"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "CCCCCCCCCC"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "CCCCCCCCC"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "DDDDDDDDDD"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "DDDDDDDDD"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "EEEEEEEEEE"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "FFFFFFFFFF"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "GGGGGGGGGG"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "GGGGGGGGG"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHHHHHHH"), peptideRows[row].Peptide);
                Assert.AreEqual(2, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHHHHHH"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);
            }

            // test with charge state, analysis, and modifications indistinct
            {
                dataFilter.DistinctMatchFormat.IsChargeDistinct = false;
                dataFilter.DistinctMatchFormat.IsAnalysisDistinct = false;
                dataFilter.DistinctMatchFormat.AreModificationsDistinct = false;
                dataFilter.ApplyBasicFilters(session);

                var peptideRows = IDPicker.Forms.PeptideTableForm.DistinctPeptideRow.GetRows(session, dataFilter);
                int row = 0;

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "AAAAAAAAAA"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "BBBBBBBBBB"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "CCCCCCCCCC"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "CCCCCCCCC"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "DDDDDDDDDD"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "DDDDDDDDD"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "EEEEEEEEEE"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "FFFFFFFFFF"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "GGGGGGGGGG"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "GGGGGGGGG"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(1, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHHHHHHH"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);

                Assert.AreEqual(session.UniqueResult<Peptide>(o => o.Sequence == "HHHHHHHHH"), peptideRows[row].Peptide);
                Assert.AreEqual(1, peptideRows[row].DistinctMatches);
                Assert.AreEqual(2, peptideRows[row++].Spectra);
            }

            session.Close();
        }
 public UserRepository(NHibernate.ISessionFactory northwindWithSecurity, AuthorizationRepositoryFactory authorizationRepositoryFactory)
 {
     _authorizationRepositoryFactory = authorizationRepositoryFactory;
     _northwindWithSecurity = northwindWithSecurity;
 }
Пример #47
0
        public void TestBasicFilters ()
        {
            string[] testProteinSequences = new string[]
            {
                "PEPTIDERPEPTIDEKPEPTIDE",
                "DERPEPTIDEKPEPTIDE",
                "TIDERPEPTIDEKPEP",

                "ELVISKLIVESRTHANKYAVERYMUCH",
                "ELVISISRCKNRLLKING",

                "THEQUICKBRWNFXJUMPSVERTHELAZYDG",
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            int numSources = 2;
            int numAnalyses = 2;

            for (int source = 1; source <= numSources; ++source)
            for (int analysis = 1; analysis <= numAnalyses; ++analysis)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                    //               Group                            Score  Q   List of Peptide@Charge/ScoreDivider

                    // not enough passing peptides for DERPEPTIDEKPEPTIDE or TIDERPEPTIDEKPEP
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "PEPTIDEK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "PEPTIDEK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "PEPTIDEK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "PEPTIDEK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "DERPEPTIDEK@1/1 PEPTIDER@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "DERPEPTIDEK@1/1 PEPTIDER@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "DERPEPTIDEK@1/1 PEPTIDER@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "DERPEPTIDEK@1/1 PEPTIDER@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "TIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "TIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "TIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "TIDER@1/1"),

                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDEK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "DERPEPTIDEK@1/1 PEPTIDER@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "TIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),

                    // not enough distinct peptides for ELVISKLIVESRTHANKYAVERYMUCH
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),

                    // not enough spectra for ELVISISRCKNRLLKING
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"),

                    // not enough spectra for distinct peptide THEQUICK
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "THEQUICK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "THEQUICK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "THEQU[H3C2N1O1]ICK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "THEQU[H3C2N1O1]ICK@1/1"),

                    // not enough spectra for distinct matches THEQUICK@2 and THEQUICK@3
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "THEQUICK@2/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "THEQUICK@3/1"),
                };

                TestModel.CreateTestData(session, testPsmSummary);
            }

            // Spectral counts must be multiplied by numSources.

            // Distinct Matches:
            // PEPTIDEK(+1): 1 spectrum
            // DERPEPTIDEK(+1): 1 spectrum
            // TIDER(+1): 1 spectrum
            // PEPTIDER(+1): 5 spectra
            // PEPTIDERPEPTIDEK(+1): 5 spectra
            // ELVISKLIVESR(+1): 6 spectra
            // ELVISISR(+1): 5 spectra
            // CKNRLLKING(+1): 5 spectra
            // THEQUICK(+1): 2 spectra
            // THEQUICK(+2): 1 spectrum
            // THEQUICK(+3): 1 spectrum
            // THEQU[H3C2N1O1]ICK(+1): 2 spectra

            // Proteins:
            // PEPTIDERPEPTIDEKPEPTIDE: 5 distinct peptides over 13 (passing) spectra
            // DERPEPTIDEKPEPTIDE: 2 distinct peptides, 2 spectra
            // TIDERPEPTIDEKPEP: 3 distinct peptides, 3 spectra
            // ELVISKLIVESRTHANKYAVERYMUCH: 1 distinct peptide, 6 spectra
            // ELVISISRCKNRLLKING: 2 distinct peptides, 10 spectra
            // THEQUICKBRWNFXJUMPSVERTHELAZYDG: 1 distinct peptide, 6 spectra

            var dataFilter = new DataFilter()
            {
                MaximumQValue = 1,
                MinimumDistinctPeptides = 1,
                MinimumSpectra = 1,
                MinimumAdditionalPeptides = 0
            };
            dataFilter.ApplyBasicFilters(session);
            
            // clear session so objects are loaded from database
            session.Clear();

            for (int sourceId = 1; sourceId <= numSources; ++sourceId)
            for (int analysisId = 1; analysisId <= numAnalyses; ++analysisId)
            {
                string source = "Source " + sourceId.ToString();
                string analysis = "Engine " + analysisId.ToString();
                var sourceAnalysisPSMs = session.Query<PeptideSpectrumMatch>().Where(o => o.Analysis.Software.Name == analysis && o.Spectrum.Source.Name == source);

                // test that PSMs with QValue > MaximumQValue are filtered out
                Assert.AreEqual(0, sourceAnalysisPSMs.Count(o => o.QValue > 1));
            }

            // test that non-rank-1 PSMs are filtered out
            Assert.AreEqual(0, session.Query<PeptideSpectrumMatch>().Where(o => o.Rank > 1).Count());

            // test that nothing else is filtered out
            Assert.AreEqual(6, session.Query<Protein>().Count());
            Assert.AreEqual(9, session.Query<Peptide>().Count());
            Assert.AreEqual(35 * (numSources + numAnalyses), session.Query<PeptideSpectrumMatch>().Count());

            dataFilter.MinimumDistinctPeptides = 3;
            dataFilter.MinimumSpectra = 1;
            dataFilter.ApplyBasicFilters(session);
            session.Clear();

            // test that proteins without at least MinimumPeptidesPerProtein peptides are filtered out
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKPEPTIDE"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));

            // test that protein filters cascade to peptide instances
            Assert.AreEqual(5, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.AreEqual(3, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "DERPEPTIDEKPEPTIDE"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "ELVISISRCKNRLLKING"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));

            // test that protein filters cascade to peptides
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDEK"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "DERPEPTIDEK"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "TIDER"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDER"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDERPEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISKLIVESR"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISISR"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "CKNRLLKING"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "THEQUICK"));

            // test that protein filters cascade to PSMs 
            Assert.AreEqual(13 * (numSources + numAnalyses), session.Query<PeptideSpectrumMatch>().Count());

            dataFilter.MinimumDistinctPeptides = 1;
            dataFilter.MinimumSpectra = 4 * numSources;
            dataFilter.ApplyBasicFilters(session);
            session.Clear();

            // test that proteins without at least MinimumSpectraPerProtein spectra are filtered out
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKPEPTIDE"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));

            dataFilter.MinimumDistinctPeptides = 1;
            dataFilter.MinimumSpectra = 1;
            dataFilter.MinimumSpectraPerDistinctMatch = 2 * numSources;
            dataFilter.ApplyBasicFilters(session);
            session.Clear();

            // test that distinct matches without at least MinimumSpectraPerDistinctMatch spectra are filtered out
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDER"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDERPEPTIDEK"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISKLIVESR"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISISR"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "CKNRLLKING"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "THEQUICK"));
            Assert.AreEqual(4 * (numSources + numAnalyses), session.Query<PeptideSpectrumMatch>().Count(o => o.Peptide.Sequence == "THEQUICK" && o.Charge == 1));
            Assert.AreEqual(0, session.Query<PeptideSpectrumMatch>().Count(o => o.Charge == 2));
            Assert.AreEqual(0, session.Query<PeptideSpectrumMatch>().Count(o => o.Charge == 3));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "DERPEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "TIDER"));

            // test that peptide filters cascade to proteins
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKPEPTIDE"));

            dataFilter.MinimumSpectraPerDistinctMatch = 1;
            dataFilter.MinimumSpectraPerDistinctPeptide = 6 * numSources;
            dataFilter.ApplyBasicFilters(session);
            session.Clear();

            // test that distinct peptides without at least MinimumSpectraPerDistinctPeptide spectra are filtered out
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISKLIVESR"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "THEQUICK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDER"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDERPEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISISR"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "CKNRLLKING"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "DERPEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "TIDER"));

            // test that peptide filters cascade to proteins
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKPEPTIDE"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING"));

            // test that peptide filters cascade to peptide instances
            Assert.AreEqual(1, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.AreEqual(1, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "DERPEPTIDEKPEPTIDE"));
            Assert.AreEqual(0, session.Query<PeptideInstance>().Count(o => o.Protein.Sequence == "ELVISISRCKNRLLKING"));

            dataFilter.MinimumSpectraPerDistinctMatch = 1;
            dataFilter.MinimumSpectraPerDistinctPeptide = 1;
            dataFilter.MaximumProteinGroupsPerPeptide = 1;
            dataFilter.ApplyBasicFilters(session);
            session.Clear();

            // test that distinct peptides linking to more than MaximumProteinGroupsPerPeptide protein groups are filtered out
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISKLIVESR"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "THEQUICK"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "ELVISISR"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "CKNRLLKING"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDER"));
            Assert.IsNotNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDERPEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "PEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "DERPEPTIDEK"));
            Assert.IsNull(session.UniqueResult<Peptide>(o => o.Sequence == "TIDER"));

            // test that MaximumProteinGroupsPerPeptide filter cascades to proteins
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING"));
            Assert.IsNotNull(session.UniqueResult<Protein>(o => o.Sequence == "THEQUICKBRWNFXJUMPSVERTHELAZYDG"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "TIDERPEPTIDEKPEP"));
            Assert.IsNull(session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKPEPTIDE"));

            session.Close();
        }
 public CustomerDemographicRepository(NHibernate.ISessionFactory northwind)
 {
     _northwind = northwind;
 }
 public EntityTypeRepository(NHibernate.ISessionFactory northwindWithSecurity)
 {
     _northwindWithSecurity = northwindWithSecurity;
 }
Пример #50
0
        /// <summary>
        /// This method use a lock to syncronize the factory creation.
        /// </summary>
        private void CheckFactory()
        {
            if (mFactory != null) return;
            lock (mSyncObj)
            {
                if (mFactory != null) return;
                var configuration = CreateNHibernateConfiguration(ConfigurationFlags.Default);

                mFactory = configuration.BuildSessionFactory();
            }
        }
 public PermissionRepository(NHibernate.ISessionFactory northwindWithSecurity, PermissionsBuilderServiceFactory permissionBuilderServiceFactory, PermissionsServiceFactory permissionsServiceFactory)
 {
     _northwindWithSecurity = northwindWithSecurity;
     _permissionBuilderServiceFactory = permissionBuilderServiceFactory;
     _permissionsServiceFactory = permissionsServiceFactory;
 }
Пример #52
0
        public void TestCoverage ()
        {
            string[] testProteinSequences = new string[]
            {
                "PEPTIDERPEPTIDEKELVISPEPTIDE",
                "DERPEPTIDEKELVISPEPTIDE",
                "TIDERELVISPEPTIDEKPEP",

                "ELVISKLIVESRTHANKYAVERYMUCH",
                "ELVISISRCKNRLLKING",
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            int numSources = 2;
            int numAnalyses = 2;

            for (int source = 1; source <= numSources; ++source)
            for (int analysis = 1; analysis <= numAnalyses; ++analysis)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                    //               Group                        Score  Q   List of Peptide@Charge/ScoreDivider

                    // PEPTIDERPEPTIDEKELVISPEPTIDE
                    // ------- -------      ------- (PEPTIDE)
                    // --------                     (PEPTIDER)
                    //    -----                     (TIDER)
                    //         --------             (PEPTIDEK)
                    //      -----------             (DERPEPTIDEK)
                    // ----------------             (PEPTIDERPEPTIDEK)
                    // 3334455444444443000001111111 (23/28 covered)

                    // DERPEPTIDEKELVISPEPTIDE
                    //    -------      ------- (PEPTIDE)
                    //    --------             (PEPTIDEK)
                    // -----------             (DERPEPTIDEK)
                    // 11133333332000001111111 (18/23 covered)

                    // TIDERELVISPEPTIDEKPEP
                    //           -------     (PEPTIDE)
                    //           --------    (PEPTIDEK)
                    // -----                 (TIDER)
                    // 111110000022222221000 (13/21 covered)

                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "PEPTIDE@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "PEPTIDEK@1/1 TIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "DERPEPTIDEK@1/1 PEPTIDEKPEP@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "TIDER@1/1"),


                    // ELVISKLIVESRTHANKYAVERYMUCH
                    // ------------                (ELVISLIVESR)
                    // ------------                (E[N-1H-3]LVISLIVESR)
                    // 222222222222000000000000000 (12/27 covered)

                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "E[N-1H-3]LVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "ELVISKLIVESR@1/1"),


                    // ELVISISRCKNRLLKING
                    // --------           (ELVISISR)
                    // ------------       (ELVISISRCKNR)
                    //         ---------- (CKNRLLKING)
                    // 222222222222111111 (18/18 covered)

                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "ELVISISRCKNR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, 42, 0, "CKNRLLKING@1/1"),
                };

                TestModel.CreateTestData(session, testPsmSummary);
            }

            var dataFilter = new DataFilter()
            {
                MaximumQValue = 1,
                MinimumDistinctPeptides = 1,
                MinimumSpectra = 1,
                MinimumAdditionalPeptides = 0
            };
            dataFilter.ApplyBasicFilters(session);

            // clear session so objects are loaded from database
            session.Clear();

            Protein pro;
            const double epsilon = 1e-9;

            // PEPTIDERPEPTIDEKELVISPEPTIDE
            // 3334455444444443000001111111 (23/28 covered)
            pro = session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKELVISPEPTIDE");
            Assert.AreEqual(100 * 23.0 / 28, pro.Coverage, epsilon);
            CollectionAssert.AreEqual(createProteinCoverageMask("3334455444444443000001111111"), pro.CoverageMask.ToArray());

            // DERPEPTIDEKELVISPEPTIDE
            // 11133333332000001111111 (18/23 covered)
            pro = session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKELVISPEPTIDE");
            Assert.AreEqual(100 * 18.0 / 23, pro.Coverage, epsilon);
            CollectionAssert.AreEqual(createProteinCoverageMask("11133333332000001111111"), pro.CoverageMask.ToArray());

            // TIDERELVISPEPTIDEKPEP
            // 111110000011111111000 (13/21 covered)
            pro = session.UniqueResult<Protein>(o => o.Sequence == "TIDERELVISPEPTIDEKPEP");
            Assert.AreEqual(100 * 13.0 / 21, pro.Coverage, epsilon);
            CollectionAssert.AreEqual(createProteinCoverageMask("111110000022222221000"), pro.CoverageMask.ToArray());

            // ELVISKLIVESRTHANKYAVERYMUCH
            // 222222222222000000000000000 (12/27 covered)
            pro = session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH");
            Assert.AreEqual(100 * 12.0 / 27, pro.Coverage, epsilon);
            // TODO: make modifications add depth to sequence coverage?
            //CollectionAssert.AreEqual(createProteinCoverageMask("222222222222000000000000000"), pro.CoverageMask.ToArray());

            // ELVISISRCKNRLLKING
            // 222222222222111111 (18/18 covered)
            pro = session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING");
            Assert.AreEqual(100 * 18 / 18, pro.Coverage, epsilon);
            CollectionAssert.AreEqual(createProteinCoverageMask("222222222222111111"), pro.CoverageMask.ToArray());
        }
 public SystemController(NHibernate.ISessionFactory sessionFactory)
 {
     // TODO: Complete member initialization
     this.sessionFactory = sessionFactory;
 }
Пример #54
0
 public OrderRepository(NHibernate.ISessionFactory northwind)
 {
     _northwind = northwind;
 }
Пример #55
0
        public void TestProteinGroups ()
        {
            string[] testProteinSequences = new string[]
            {
                "PEPTIDERPEPTIDEKPEPTIDE",
                "DERPEPTIDEKPEPTIDE",
                "TIDERPEPTIDEKPEP",

                "ELVISKLIVESRTHANKYAVERYMUCH",
                "ELVISISRCKNRLLKING",
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            int numSources = 2;
            int numAnalyses = 2;

            for (int source = 1; source <= numSources; ++source)
            for (int analysis = 1; analysis <= numAnalyses; ++analysis)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                    //               Group                            Score  Q   List of Peptide@Charge/ScoreDivider

                    // PEPTIDERPEPTIDEKPEPTIDE in protein group: DERPEPTIDEK,PEPTIDEK,PEPTIDERPEPTIDEK,TIDEK
                    // DERPEPTIDEKPEPTIDE in protein group: DERPEPTIDEK,PEPTIDEK,TIDEK
                    // TIDERPEPTIDEKPEP in protein group: DERPEPTIDEK,PEPTIDEK,TIDEK
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "PEPTIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDEK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "PEPTIDERPEPTIDEK@1/1 PEPTIDEK@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "DERPEPTIDEK@1/1 PEPTIDER@1/2"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "TIDER@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 1, "TIDEK@1/1"),

                    // ELVISKLIVESRTHANKYAVERYMUCH in protein group: ELVIS,ELVISK,ELVISKLIVESR
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVIS@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISK@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 2, "LIVESR@1/1"),

                    // ELVISISRCKNRLLKING in protein group: CKNRLLKING,ELVIS,ELVISISR
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"),
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"),
                };

                TestModel.CreateTestData(session, testPsmSummary);
            }

            var dataFilter = new DataFilter()
            {
                MaximumQValue = 1,
                MinimumDistinctPeptides = 2,
                MinimumSpectra = 3 * numSources,
                MinimumAdditionalPeptides = 0
            };
            dataFilter.ApplyBasicFilters(session);

            // clear session so objects are loaded from database
            session.Clear();

            Assert.AreEqual(1, session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE").ProteinGroup);
            Assert.AreEqual(2, session.UniqueResult<Protein>(o => o.Sequence == "DERPEPTIDEKPEPTIDE").ProteinGroup);
            Assert.AreEqual(2, session.UniqueResult<Protein>(o => o.Sequence == "TIDERPEPTIDEKPEP").ProteinGroup);
            Assert.AreEqual(4, session.UniqueResult<Protein>(o => o.Sequence == "ELVISKLIVESRTHANKYAVERYMUCH").ProteinGroup);
            Assert.AreEqual(3, session.UniqueResult<Protein>(o => o.Sequence == "ELVISISRCKNRLLKING").ProteinGroup);

            Assert.AreEqual(2, session.Query<Protein>().Where(o => o.ProteinGroup == 2).Count());

            session.Close();
        }
Пример #56
0
 public EmployeeRepository(NHibernate.ISessionFactory northwind)
 {
     _northwind = northwind;
 }
Пример #57
0
        public void TestAminoAcidOffsets ()
        {
            string[] testProteinSequences = new string[]
            {
                "PEPTIDERPEPTIDEKPEPTIDE",
                "DERPEPTIDEKPEPTIDE",
                "TIDERPEPTIDEKPEP",

                "ELVISKLIVESRTHANKYAVERYMUCH",
                "ELVISISRCKNRLLKING",
            };

            string idpDbName = System.Reflection.MethodInfo.GetCurrentMethod().Name + ".idpDB";
            File.Delete(idpDbName);
            sessionFactory = SessionFactoryFactory.CreateSessionFactory(idpDbName, new SessionFactoryConfig { CreateSchema = true });
            var session = sessionFactory.OpenSession();

            TestModel.CreateTestProteins(session, testProteinSequences);

            int numSources = 2;
            int numAnalyses = 2;

            for (int source = 1; source <= numSources; ++source)
            for (int analysis = 1; analysis <= numAnalyses; ++analysis)
            {
                int scan = 0;

                List<SpectrumTuple> testPsmSummary = new List<SpectrumTuple>()
                {
                    //               Group                            Score  Q   List of Peptide@Charge/ScoreDivider
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDER@1/1"), // [0,7]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDEK@1/1"), // [8,15] [5,12]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@2/1"), // [0,15]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "PEPTIDERPEPTIDEK@3/1"), // [0,15]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "DERPEPTIDEK@1/1"), // [0,10] [5,14]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "TIDER@1/1"), // [0,4] [3,7]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "TIDEK@2/1"), // [6,10] [8,12] [10,14]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "TIDEK@3/1"), // [6,10] [8,12] [10,14]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVIS@1/1"), // [0,4]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISK@1/1"), // [0,5]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISKLIVESR@1/1"), // [0,11]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "LIVESR@1/1"), // [5,11]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "ELVISISR@1/1"), // [0,7]
                    new SpectrumTuple("/", source, ++scan, analysis, scan*2, 0, "CKNRLLKING@1/1"), // [8,18]
                };

                TestModel.CreateTestData(session, testPsmSummary);
            }

            var dataFilter = new DataFilter() { MinimumAdditionalPeptides = 0 };
            dataFilter.ApplyBasicFilters(session);

            // clear session so objects are loaded from database
            session.Clear();

            // get all peptides at the protein N-terminus
            dataFilter.AminoAcidOffset = new List<int> { 0 };
            Assert.AreEqual(8, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            // get all peptides of PEPTIDERPEPTIDEKPEPTIDE at the N-terminus
            dataFilter.Protein = new List<Protein> { session.UniqueResult<Protein>(o => o.Sequence == "PEPTIDERPEPTIDEKPEPTIDE") };
            Assert.AreEqual(2, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            // get all peptides of PEPTIDERPEPTIDEKPEPTIDE that cover offset 8 (PEPTIDERPEPTIDEK, DERPEPTIDEK, PEPTIDEK)
            dataFilter.AminoAcidOffset = new List<int> { 8 };
            Assert.AreEqual(3, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            // get all peptides of PEPTIDERPEPTIDEKPEPTIDE that cover offset 3 or 8 (PEPTIDER, PEPTIDERPEPTIDEK, DERPEPTIDEK, TIDER, PEPTIDEK)
            dataFilter.AminoAcidOffset = new List<int> { 3, 8 };
            Assert.AreEqual(5, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            // get all peptides of PEPTIDERPEPTIDEKPEPTIDE at the C-terminus
            dataFilter.AminoAcidOffset = new List<int> { Int32.MaxValue };
            Assert.AreEqual(0, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            // get all peptides at the protein C-terminus
            dataFilter.Protein = null;
            Assert.AreEqual(1, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            // get all peptides at either protein terminus
            dataFilter.AminoAcidOffset = new List<int> { 0, Int32.MaxValue };
            Assert.AreEqual(9, Convert.ToInt32(session.CreateQuery("SELECT COUNT(DISTINCT pi.Peptide) " + dataFilter.GetFilteredQueryString(DataFilter.FromProtein)).UniqueResult()));

            session.Close();
        }
Пример #58
0
 static Context()
 {
     log4net.Config.XmlConfigurator.Configure();
     SessionFactory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();
 }