-- Tables are required if database option is used with EpDis/MassPred 
--
-- This SQL script is prepared for IBM DB2 (LUW version)
-- 
--
-- First drop tables if exists
drop table epdis_cache;
drop table protein;
drop table epitope;
drop table epitope_fail;
drop table epitope_numeric;
drop table hydro;
drop table region;
drop table region_fail;
drop table region_numeric;


-- Create new tables

create table epdis_cache 
            (
             key                    varchar(70)    not null, 
             prediction_result      blob(1048576) inline length 164 not null,
             primary key (key)            );

create table protein 
            (
             id                     varchar(20)    not null, 
             sequence               varchar(10000) not null, 
             length                 smallint       not null, 
             fasta_header           varchar(500)   not null, 
             ord_num_in_disprot     varchar(20)    not null,
             primary key (id)
            );
       
create table epitope 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             position               integer                , 
             epitope                varchar(32)            , 
             pos                    integer                , 
             core                   varchar(32)            , 
             aff_log                decimal(5,0)           , 
             aff                    decimal(5,0)           , 
             rank                   decimal(5,0)           , 
             binding                char(2)                , 
             type                   varchar(32)            , 
             allele                 varchar(32)            , 
             length                 integer                
            );
       
create table epitope_fail 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             type                   varchar(32)            , 
             allele                 varchar(32)            , 
             length                 integer
            );
       
create table epitope_numeric 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             position               integer                , 
             epitope                varchar(32)            , 
             pos                    integer                , 
             core                   varchar(32)            , 
             aff_log                decimal(10,3)          , 
             aff                    decimal(10,3)          , 
             rank                   decimal(10,3)          , 
             binding                char(2)                , 
             type                   varchar(32)            , 
             allele                 varchar(32)            , 
             length                 integer
            );
       
create table hydro 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             aa                     char(1)                , 
             position               integer                , 
             hydro_kd               decimal(10,3)          , 
             hydro_hw               decimal(10,3)
            );
       
create table region 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             begin                  integer                , 
             end                    integer                , 
             order                  char(1)                , 
             type                   varchar(32)
            );
       
create table region_fail 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             type                   varchar(32)
            );
       
create table region_numeric 
            (
             protein_id             varchar(64)            , 
             protein_reference      varchar(64)            , 
             protein_file_name      varchar(64)            , 
             position               integer                , 
             aa                     char(1)                , 
             value                  decimal(9,6)           , 
             order                  char(1)                , 
             type                   varchar(32)
            );
            