diff --git a/pepdb/.gitattributes b/pepdb/.gitattributes new file mode 100644 index 00000000..5aeb7c04 --- /dev/null +++ b/pepdb/.gitattributes @@ -0,0 +1,47 @@ +# Convert text files to OS line-endings on checkout, and LF on check-in +* text=auto !eol + +# Text files to convert +*.css text diff=css +*.htm text diff=html +*.html text diff=html +*.java text diff=java +*.js text +*.json text +*.jsp text +*.jspf text +*.jspx text +*.properties text +*.py text diff=python +*.sql text +*.tld text +*.ts text +*.txt text +*.xml text +*.yml text + +# Keep unix endings +*.bash text eol=lf +*.sh text eol=lf + +# Keep Windows endings +*.bat text eol=crlf +*.cmd text eol=crlf + +# Known binary files -- Don't change (binary is a macro for -text -diff) +*.bin binary +*.class binary +*.dll binary +*.ear binary +*.exe binary +*.gif binary +*.gz binary +*.ico binary +*.jar binary +*.jpg binary +*.jpeg binary +*.png binary +*.so binary +*.tar binary +*.war binary +*.zip binary diff --git a/pepdb/build.gradle b/pepdb/build.gradle new file mode 100644 index 00000000..405ae240 --- /dev/null +++ b/pepdb/build.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.labkey.build.module' +} diff --git a/pepdb/module.properties b/pepdb/module.properties new file mode 100644 index 00000000..3d06d5fb --- /dev/null +++ b/pepdb/module.properties @@ -0,0 +1,2 @@ +ModuleClass: org.scharp.atlas.pepdb.PepDBModule +ManageVersion: false diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.00-0.02.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.00-0.02.sql new file mode 100644 index 00000000..a29b8150 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.00-0.02.sql @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2003-2005 Fred Hutchinson Cancer Research Center + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +BEGIN; + +CREATE SCHEMA pepdb; + +CREATE TABLE pepdb.clade ( + clade_id serial NOT NULL, + clade_desc text, + + CONSTRAINT PK_clade PRIMARY KEY (clade_id) +); + +CREATE TABLE pepdb.pathogen ( + pathogen_id serial NOT NULL, + pathogen_desc text, + + CONSTRAINT PK_pathogen PRIMARY KEY (pathogen_id) +); + +CREATE TABLE pepdb.group_type ( + group_type_id serial NOT NULL, + group_type_desc text, + + CONSTRAINT PK_group_type PRIMARY KEY (group_type_id) +); + +CREATE TABLE pepdb.pep_align_ref ( + pep_align_ref_id serial NOT NULL, + pep_align_ref_desc text, + + CONSTRAINT PK_pep_align_ref PRIMARY KEY (pep_align_ref_id) +); + +CREATE TABLE pepdb.peptide_group ( + _ts TIMESTAMP DEFAULT now(), + CreatedBy USERID, + Created TIMESTAMP, + ModifiedBy USERID, + Modified TIMESTAMP, + + peptide_group_id serial NOT NULL, + peptide_group_name text NOT NULL UNIQUE, + pathogen_id integer, + seq_ref text, + clade_id integer, + pep_align_ref_id integer, + group_type_id integer, + + CONSTRAINT PK_peptide_group PRIMARY KEY (peptide_group_id), + CONSTRAINT FK_peptide_group1 FOREIGN KEY(pathogen_id) REFERENCES pepdb.pathogen(pathogen_id), + CONSTRAINT FK_peptide_group2 FOREIGN KEY(clade_id) REFERENCES pepdb.clade(clade_id), + CONSTRAINT FK_peptide_group3 FOREIGN KEY(group_type_id) REFERENCES pepdb.group_type(group_type_id), + CONSTRAINT FK_peptide_group4 FOREIGN KEY(pep_align_ref_id) REFERENCES pepdb.pep_align_ref(pep_align_ref_id) +); + +CREATE TABLE pepdb.protein_category ( + protein_cat_id serial NOT NULL, + protein_cat_desc text, + + CONSTRAINT PK_protein_category PRIMARY KEY (protein_cat_id) +); + +CREATE TABLE pepdb.optimal_epitope_list( + optimal_epitope_list_id serial NOT NULL, + optimal_epitope_list_desc text, + + CONSTRAINT PK_optimal_epitope_list PRIMARY KEY (optimal_epitope_list_id) +); + + +CREATE TABLE pepdb.peptides ( + _ts TIMESTAMP DEFAULT now(), + CreatedBy USERID, + Created TIMESTAMP, + ModifiedBy USERID, + Modified TIMESTAMP, + + peptide_id serial NOT NULL, + peptide_sequence text NOT NULL UNIQUE, + protein_cat_id integer, + amino_acid_start_pos integer, + amino_acid_end_pos integer, + sequence_length integer, + child boolean, + parent boolean DEFAULT false NOT NULL, + src_file_name text, + storage_location text, + optimal_epitope_list_id integer, + hla_restriction text, + + CONSTRAINT PK_peptides PRIMARY KEY (peptide_id), + CONSTRAINT FK_peptides1 FOREIGN KEY(protein_cat_id) REFERENCES pepdb.protein_category(protein_cat_id), + CONSTRAINT FK_peptides2 FOREIGN KEY(optimal_epitope_list_id) REFERENCES pepdb.optimal_epitope_list(optimal_epitope_list_id) +); + + +CREATE TABLE pepdb.peptide_group_assignment ( + _ts TIMESTAMP DEFAULT now(), + CreatedBy USERID, + Created TIMESTAMP, + ModifiedBy USERID, + Modified TIMESTAMP, + + peptide_group_assignment_id serial NOT NULL UNIQUE, + peptide_id integer NOT NULL, + peptide_group_id integer NOT NULL, + peptide_id_in_group integer, + frequency_number float, + frequency_number_date date, + in_current_file boolean DEFAULT false, + + CONSTRAINT PK_peptide_group_assignment PRIMARY KEY (peptide_id,peptide_group_id), + CONSTRAINT FK_peptide_group_assignment1 FOREIGN KEY(peptide_id) REFERENCES pepdb.peptides(peptide_id), + CONSTRAINT FK_peptide_group_assignment2 FOREIGN KEY(peptide_group_id) REFERENCES pepdb.peptide_group(peptide_group_id) +); + +CREATE TABLE pepdb.parent ( + _ts TIMESTAMP DEFAULT now(), + CreatedBy USERID, + Created TIMESTAMP, + ModifiedBy USERID, + Modified TIMESTAMP, + + peptide_id integer NOT NULL, + linked_parent integer NOT NULL, + + CONSTRAINT PK_parent PRIMARY KEY (peptide_id,linked_parent), + CONSTRAINT FK_parent1 FOREIGN KEY(peptide_id) REFERENCES pepdb.peptides(peptide_id), + CONSTRAINT FK_parent2 FOREIGN KEY(linked_parent) REFERENCES pepdb.peptides(peptide_id) +); + +CREATE TABLE pepdb.pool_type ( + pool_type_id serial NOT NULL, + pool_type_desc text, + + CONSTRAINT PK_pool_type PRIMARY KEY (pool_type_id) +); + +CREATE TABLE pepdb.peptide_pool ( + _ts TIMESTAMP DEFAULT now(), + CreatedBy USERID, + Created TIMESTAMP, + ModifiedBy USERID, + Modified TIMESTAMP, + + peptide_pool_id serial NOT NULL, + peptide_pool_name text, + pool_type_id integer, + comment text, + + CONSTRAINT PK_peptide_pool PRIMARY KEY (peptide_pool_id), + CONSTRAINT FK_peptide_pool1 FOREIGN KEY(pool_type_id) REFERENCES pepdb.pool_type(pool_type_id) +); + + +CREATE TABLE pepdb.peptide_pool_assignment ( + _ts TIMESTAMP DEFAULT now(), + CreatedBy USERID, + Created TIMESTAMP, + ModifiedBy USERID, + Modified TIMESTAMP, + + peptide_pool_assignment_id serial NOT NULL UNIQUE, + peptide_pool_id integer NOT NULL, + peptide_id integer NOT NULL, + + CONSTRAINT PK_peptide_pool_assignment PRIMARY KEY (peptide_pool_id,peptide_id), + CONSTRAINT FK_peptide_pool_assignment1 FOREIGN KEY(peptide_pool_id) REFERENCES pepdb.peptide_pool(peptide_pool_id), + CONSTRAINT FK_peptide_pool_assignment2 FOREIGN KEY(peptide_id) REFERENCES pepdb.peptides(peptide_id) +); + +CREATE VIEW pepdb.parent_child_details AS +select par.peptide_id AS child_id,pchild.peptide_sequence AS child_sequence, +pchild.protein_cat_id AS child_protein,pchild.sequence_length AS child_seq_length, +pchild.amino_acid_start_pos AS child_AAStart,pchild.amino_acid_end_pos AS child_AAEnd, +pchild.optimal_epitope_list_id AS child_optimal_epitope_list_id,pchild.hla_restriction AS child_hla_restriction, +par.linked_parent AS parent_id,pparent.peptide_sequence AS parent_sequence, +pparent.protein_cat_id AS parent_protein,pparent.sequence_length AS parent_seq_length, +pparent.amino_acid_start_pos AS parent_AAStart,pparent.amino_acid_end_pos AS parent_AAEnd +from pepdb.parent par LEFT JOIN pepdb.peptides pchild ON (par.peptide_id = pchild.peptide_id) +LEFT JOIN pepdb.peptides pparent ON(par.linked_parent = pparent.peptide_id); + +CREATE VIEW pepdb.group_peptides AS +SELECT src.peptide_id, src.peptide_group_id, src.peptide_id_in_group, + pgroup.peptide_group_name,pgroup.pathogen_id, + p.peptide_sequence,p.protein_cat_id, + p.sequence_length,p.amino_acid_start_pos,p.amino_acid_end_pos, + p.child, p.parent,p.optimal_epitope_list_id,p.hla_restriction, + src.frequency_number,src.frequency_number_date,src.in_current_file +FROM ((pepdb.peptide_group_assignment src LEFT JOIN pepdb.peptide_group pgroup ON ((src.peptide_group_id + = pgroup.peptide_group_id))) LEFT JOIN pepdb.peptides p ON ((src.peptide_id = + p.peptide_id))); + +CREATE VIEW pepdb.pool_peptides AS +SELECT src.peptide_id, p.peptide_sequence, src.peptide_pool_id, pp.pool_type_id, pp.peptide_pool_name, pt.pool_type_desc +FROM +pepdb.peptides p, +pepdb.peptide_pool_assignment src +LEFT JOIN pepdb.peptide_pool pp +LEFT JOIN pepdb.pool_type pt ON(pp.pool_type_id = pt.pool_type_id) ON (src.peptide_pool_id = pp.peptide_pool_id) +WHERE (src.peptide_id = p.peptide_id); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.peptides', 'peptide_id'), 500000, true); +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.peptide_pool', 'peptide_pool_id'), 500000, true); + +COMMIT; + + + + + + + diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.00-2.21.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.00-2.21.sql new file mode 100644 index 00000000..3d37bdc4 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.00-2.21.sql @@ -0,0 +1,226 @@ +CREATE SCHEMA pepdb; + +CREATE TABLE pepdb.clade ( + clade_id SERIAL NOT NULL, + clade_desc text +); + +CREATE TABLE pepdb.peptide_group ( + _ts timestamp without time zone DEFAULT now(), + createdby public.userid, + created timestamp without time zone, + modifiedby public.userid, + modified timestamp without time zone, + peptide_group_id SERIAL NOT NULL, + peptide_group_name text NOT NULL, + pathogen_id integer, + seq_ref text, + clade_id integer, + pep_align_ref_id integer, + group_type_id integer +); + +CREATE TABLE pepdb.peptide_group_assignment ( + _ts timestamp without time zone DEFAULT now(), + createdby public.userid, + created timestamp without time zone, + modifiedby public.userid, + modified timestamp without time zone, + peptide_group_assignment_id SERIAL NOT NULL, + peptide_id integer NOT NULL, + peptide_group_id integer NOT NULL, + peptide_id_in_group character varying, + frequency_number double precision, + frequency_number_date date, + in_current_file boolean DEFAULT false +); + +CREATE TABLE pepdb.peptides ( + _ts timestamp without time zone DEFAULT now(), + createdby public.userid, + created timestamp without time zone, + modifiedby public.userid, + modified timestamp without time zone, + peptide_id SERIAL NOT NULL, + peptide_sequence text NOT NULL, + protein_cat_id integer, + amino_acid_start_pos integer, + amino_acid_end_pos integer, + sequence_length integer, + child boolean, + parent boolean DEFAULT false NOT NULL, + src_file_name text, + storage_location text, + optimal_epitope_list_id integer, + hla_restriction text, + peptide_flag boolean DEFAULT false, + peptide_notes text +); + +CREATE TABLE pepdb.group_type ( + group_type_id SERIAL NOT NULL, + group_type_desc text +); + +CREATE TABLE pepdb.optimal_epitope_list ( + optimal_epitope_list_id SERIAL NOT NULL, + optimal_epitope_list_desc text +); + +CREATE TABLE pepdb.parent ( + _ts timestamp without time zone DEFAULT now(), + createdby public.userid, + created timestamp without time zone, + modifiedby public.userid, + modified timestamp without time zone, + peptide_id integer NOT NULL, + linked_parent integer NOT NULL +); + +CREATE TABLE pepdb.pathogen ( + pathogen_id SERIAL NOT NULL, + pathogen_desc text +); + +CREATE TABLE pepdb.pep_align_ref ( + pep_align_ref_id SERIAL NOT NULL, + pep_align_ref_desc text +); + +CREATE TABLE pepdb.peptide_pool ( + _ts timestamp without time zone DEFAULT now(), + createdby public.userid, + created timestamp without time zone, + modifiedby public.userid, + modified timestamp without time zone, + peptide_pool_id SERIAL NOT NULL, + peptide_pool_name text, + pool_type_id integer, + comment text, + archived boolean DEFAULT false, + parent_pool_id integer, + matrix_peptide_pool_id text +); + +CREATE TABLE pepdb.peptide_pool_assignment ( + _ts timestamp without time zone DEFAULT now(), + createdby public.userid, + created timestamp without time zone, + modifiedby public.userid, + modified timestamp without time zone, + peptide_pool_assignment_id SERIAL NOT NULL, + peptide_pool_id integer NOT NULL, + peptide_id integer NOT NULL, + peptide_group_assignment_id integer +); + +CREATE TABLE pepdb.pool_type ( + pool_type_id SERIAL NOT NULL, + pool_type_desc text +); + +CREATE TABLE pepdb.protein_category ( + protein_cat_id SERIAL NOT NULL, + protein_cat_desc text +); + +CREATE TABLE pepdb.temp_peppoolgroupassign ( + peptide_pool_assignment_id integer, + peptide_group_assignment_id integer +); + +ALTER TABLE ONLY pepdb.peptide_group_assignment + ADD CONSTRAINT peptide_group_assignment_peptide_group_assignment_id_key UNIQUE (peptide_group_assignment_id); + +ALTER TABLE ONLY pepdb.peptide_group + ADD CONSTRAINT peptide_group_peptide_group_name_key UNIQUE (peptide_group_name); + +ALTER TABLE ONLY pepdb.peptide_pool_assignment + ADD CONSTRAINT peptide_pool_assignment_peptide_pool_assignment_id_key UNIQUE (peptide_pool_assignment_id); + +ALTER TABLE ONLY pepdb.peptides + ADD CONSTRAINT peptides_peptide_sequence_key UNIQUE (peptide_sequence); + +ALTER TABLE ONLY pepdb.clade + ADD CONSTRAINT pk_clade PRIMARY KEY (clade_id); + +ALTER TABLE ONLY pepdb.group_type + ADD CONSTRAINT pk_group_type PRIMARY KEY (group_type_id); + +ALTER TABLE ONLY pepdb.optimal_epitope_list + ADD CONSTRAINT pk_optimal_epitope_list PRIMARY KEY (optimal_epitope_list_id); + +ALTER TABLE ONLY pepdb.parent + ADD CONSTRAINT pk_parent PRIMARY KEY (peptide_id, linked_parent); + +ALTER TABLE ONLY pepdb.pathogen + ADD CONSTRAINT pk_pathogen PRIMARY KEY (pathogen_id); + +ALTER TABLE ONLY pepdb.pep_align_ref + ADD CONSTRAINT pk_pep_align_ref PRIMARY KEY (pep_align_ref_id); + +ALTER TABLE ONLY pepdb.peptide_group + ADD CONSTRAINT pk_peptide_group PRIMARY KEY (peptide_group_id); + +ALTER TABLE ONLY pepdb.peptide_group_assignment + ADD CONSTRAINT pk_peptide_group_assignment PRIMARY KEY (peptide_id, peptide_group_id); + +ALTER TABLE ONLY pepdb.peptide_pool + ADD CONSTRAINT pk_peptide_pool PRIMARY KEY (peptide_pool_id); + +ALTER TABLE ONLY pepdb.peptide_pool_assignment + ADD CONSTRAINT pk_peptide_pool_assignment PRIMARY KEY (peptide_pool_id, peptide_id); + +ALTER TABLE ONLY pepdb.peptides + ADD CONSTRAINT pk_peptides PRIMARY KEY (peptide_id); + +ALTER TABLE ONLY pepdb.pool_type + ADD CONSTRAINT pk_pool_type PRIMARY KEY (pool_type_id); + +ALTER TABLE ONLY pepdb.protein_category + ADD CONSTRAINT pk_protein_category PRIMARY KEY (protein_cat_id); + +ALTER TABLE ONLY pepdb.parent + ADD CONSTRAINT fk_parent1 FOREIGN KEY (peptide_id) REFERENCES pepdb.peptides(peptide_id); + +ALTER TABLE ONLY pepdb.parent + ADD CONSTRAINT fk_parent2 FOREIGN KEY (linked_parent) REFERENCES pepdb.peptides(peptide_id); + +ALTER TABLE ONLY pepdb.peptide_group + ADD CONSTRAINT fk_peptide_group1 FOREIGN KEY (pathogen_id) REFERENCES pepdb.pathogen(pathogen_id); + +ALTER TABLE ONLY pepdb.peptide_group + ADD CONSTRAINT fk_peptide_group2 FOREIGN KEY (clade_id) REFERENCES pepdb.clade(clade_id); + +ALTER TABLE ONLY pepdb.peptide_group + ADD CONSTRAINT fk_peptide_group3 FOREIGN KEY (group_type_id) REFERENCES pepdb.group_type(group_type_id); + +ALTER TABLE ONLY pepdb.peptide_group + ADD CONSTRAINT fk_peptide_group4 FOREIGN KEY (pep_align_ref_id) REFERENCES pepdb.pep_align_ref(pep_align_ref_id); + +ALTER TABLE ONLY pepdb.peptide_group_assignment + ADD CONSTRAINT fk_peptide_group_assignment1 FOREIGN KEY (peptide_id) REFERENCES pepdb.peptides(peptide_id); + +ALTER TABLE ONLY pepdb.peptide_group_assignment + ADD CONSTRAINT fk_peptide_group_assignment2 FOREIGN KEY (peptide_group_id) REFERENCES pepdb.peptide_group(peptide_group_id); + +ALTER TABLE ONLY pepdb.peptide_pool + ADD CONSTRAINT fk_peptide_pool1 FOREIGN KEY (pool_type_id) REFERENCES pepdb.pool_type(pool_type_id); + +ALTER TABLE ONLY pepdb.peptide_pool + ADD CONSTRAINT fk_peptide_pool2 FOREIGN KEY (parent_pool_id) REFERENCES pepdb.peptide_pool(peptide_pool_id); + +ALTER TABLE ONLY pepdb.peptide_pool_assignment + ADD CONSTRAINT fk_peptide_pool_assignment1 FOREIGN KEY (peptide_pool_id) REFERENCES pepdb.peptide_pool(peptide_pool_id); + +ALTER TABLE ONLY pepdb.peptide_pool_assignment + ADD CONSTRAINT fk_peptide_pool_assignment2 FOREIGN KEY (peptide_id) REFERENCES pepdb.peptides(peptide_id); + +ALTER TABLE ONLY pepdb.peptide_pool_assignment + ADD CONSTRAINT fk_peptide_pool_assignment3 FOREIGN KEY (peptide_group_assignment_id) REFERENCES pepdb.peptide_group_assignment(peptide_group_assignment_id); + +ALTER TABLE ONLY pepdb.peptides + ADD CONSTRAINT fk_peptides1 FOREIGN KEY (protein_cat_id) REFERENCES pepdb.protein_category(protein_cat_id); + +ALTER TABLE ONLY pepdb.peptides + ADD CONSTRAINT fk_peptides2 FOREIGN KEY (optimal_epitope_list_id) REFERENCES pepdb.optimal_epitope_list(optimal_epitope_list_id); diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.02-0.05.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.02-0.05.sql new file mode 100644 index 00000000..8fe103fd --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.02-0.05.sql @@ -0,0 +1,90 @@ + +INSERT INTO pepdb.clade VALUES (1, 'A'); +INSERT INTO pepdb.clade VALUES (2, 'B'); +INSERT INTO pepdb.clade VALUES (3, 'C'); +INSERT INTO pepdb.clade VALUES (4, 'D'); +INSERT INTO pepdb.clade VALUES (5, 'E'); +INSERT INTO pepdb.clade VALUES (6, 'G'); +INSERT INTO pepdb.clade VALUES (7, 'M'); +INSERT INTO pepdb.clade VALUES (8, 'Other'); +INSERT INTO pepdb.clade VALUES (9, 'Unknown'); +INSERT INTO pepdb.clade VALUES (10, 'A1'); +INSERT INTO pepdb.clade VALUES (11, 'C/A1/D'); +INSERT INTO pepdb.clade VALUES (12, 'D/A1'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.clade', 'clade_id'), 12, true); + +INSERT INTO pepdb.pathogen VALUES (1, 'HIV-1'); +INSERT INTO pepdb.pathogen VALUES (2, 'HIV-2'); +INSERT INTO pepdb.pathogen VALUES (3, 'TB'); +INSERT INTO pepdb.pathogen VALUES (4, 'Malaria'); +INSERT INTO pepdb.pathogen VALUES (5, 'Flu'); +INSERT INTO pepdb.pathogen VALUES (6, 'FEC'); +INSERT INTO pepdb.pathogen VALUES (7, 'EBV'); +INSERT INTO pepdb.pathogen VALUES (8, 'Other'); +INSERT INTO pepdb.pathogen VALUES (9, 'CMV'); +INSERT INTO pepdb.pathogen VALUES (10, 'AD5'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.pathogen', 'pathogen_id'), 10, true); + +INSERT INTO pepdb.group_type VALUES (1, 'Consensus'); +INSERT INTO pepdb.group_type VALUES (2, 'Autologous'); +INSERT INTO pepdb.group_type VALUES (3, 'Mosaic'); +INSERT INTO pepdb.group_type VALUES (4, 'Toggle'); +INSERT INTO pepdb.group_type VALUES (5, 'LABL CTL Epitope'); +INSERT INTO pepdb.group_type VALUES (6, 'Other'); +INSERT INTO pepdb.group_type VALUES (7, 'Vaccine-matched'); +INSERT INTO pepdb.group_type VALUES (8, 'PTE'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.group_type', 'group_type_id'), 8, true); + +INSERT INTO pepdb.pep_align_ref VALUES (1,'HXB2'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.pep_align_ref', 'pep_align_ref_id'), 1, true); + +INSERT INTO pepdb.protein_category VALUES (1, 'GAG'); +INSERT INTO pepdb.protein_category VALUES (2, 'POL'); +INSERT INTO pepdb.protein_category VALUES (3, 'VIF'); +INSERT INTO pepdb.protein_category VALUES (4, 'VPR'); +INSERT INTO pepdb.protein_category VALUES (5, 'TAT'); +INSERT INTO pepdb.protein_category VALUES (6, 'REV'); +INSERT INTO pepdb.protein_category VALUES (7, 'VPU'); +INSERT INTO pepdb.protein_category VALUES (8, 'ENV'); +INSERT INTO pepdb.protein_category VALUES (9, 'NEF'); +INSERT INTO pepdb.protein_category VALUES (10, 'gp160'); +INSERT INTO pepdb.protein_category VALUES (11, 'Integrase'); +INSERT INTO pepdb.protein_category VALUES (12, 'p17'); +INSERT INTO pepdb.protein_category VALUES (13, 'Antigen 85A'); +INSERT INTO pepdb.protein_category VALUES (14, 'BZLF 1'); +INSERT INTO pepdb.protein_category VALUES (15, 'CFP10'); +INSERT INTO pepdb.protein_category VALUES (16, 'EBNA3A'); +INSERT INTO pepdb.protein_category VALUES (17, 'ESAT-6'); +INSERT INTO pepdb.protein_category VALUES (18, 'IE1'); +INSERT INTO pepdb.protein_category VALUES (19, 'p24'); +INSERT INTO pepdb.protein_category VALUES (20, 'p2p7p1p6'); +INSERT INTO pepdb.protein_category VALUES (21, 'pp65'); +INSERT INTO pepdb.protein_category VALUES (22, 'Protease'); +INSERT INTO pepdb.protein_category VALUES (23, 'RT-Integrase'); +INSERT INTO pepdb.protein_category VALUES (24, 'Other'); +INSERT INTO pepdb.protein_category VALUES (25, 'Gag_Pol_TF'); +INSERT INTO pepdb.protein_category VALUES (26, 'RT'); +INSERT INTO pepdb.protein_category VALUES (27, 'Protease-RT'); +INSERT INTO pepdb.protein_category VALUES (28, 'p17-p24'); +INSERT INTO pepdb.protein_category VALUES (29, 'p24-p2p7p1p6'); +INSERT INTO pepdb.protein_category VALUES (30, 'Gag_Pol_TF-Protease'); + + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.protein_category', 'protein_cat_id'), 30, true); + +INSERT INTO pepdb.pool_type VALUES (1, 'Pool'); +INSERT INTO pepdb.pool_type VALUES (2, 'Sub-Pool'); +INSERT INTO pepdb.pool_type VALUES (3, 'Matrix'); +INSERT INTO pepdb.pool_type VALUES (4, 'Other'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.pool_type', 'pool_type_id'), 4, true); + +INSERT INTO pepdb.optimal_epitope_list VALUES (1, 'A'); +INSERT INTO pepdb.optimal_epitope_list VALUES (2, 'B'); +INSERT INTO pepdb.optimal_epitope_list VALUES (3, 'None'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.optimal_epitope_list', 'optimal_epitope_list_id'), 3, true); diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.05-0.08.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.05-0.08.sql new file mode 100644 index 00000000..e356af5c --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.05-0.08.sql @@ -0,0 +1,23 @@ +DROP VIEW pepdb.group_peptides; +ALTER TABLE pepdb.peptide_group_assignment ALTER COLUMN peptide_id_in_group TYPE float; +CREATE VIEW pepdb.group_peptides AS +SELECT src.peptide_group_assignment_id,src.peptide_id, src.peptide_group_id, src.peptide_id_in_group, + pgroup.peptide_group_name,pgroup.pathogen_id, + p.peptide_sequence,p.protein_cat_id, + p.sequence_length,p.amino_acid_start_pos,p.amino_acid_end_pos, + p.child, p.parent,p.optimal_epitope_list_id,p.hla_restriction, + src.frequency_number,src.frequency_number_date,src.in_current_file +FROM ((pepdb.peptide_group_assignment src LEFT JOIN pepdb.peptide_group pgroup ON ((src.peptide_group_id + = pgroup.peptide_group_id))) LEFT JOIN pepdb.peptides p ON ((src.peptide_id = + p.peptide_id))); + +DROP VIEW pepdb.pool_peptides; +CREATE VIEW pepdb.pool_peptides AS +SELECT src.peptide_pool_assignment_id,src.peptide_id,src.peptide_pool_id, +p.peptide_sequence,p.protein_cat_id, +p.sequence_length,p.amino_acid_start_pos,p.amino_acid_end_pos, +p.child, p.parent, + pp.pool_type_id,pp.peptide_pool_name,pt.pool_type_desc +FROM pepdb.peptide_pool_assignment src LEFT JOIN pepdb.peptide_pool pp LEFT JOIN pepdb.pool_type pt ON(pp.pool_type_id = pt.pool_type_id) ON (src.peptide_pool_id = pp.peptide_pool_id), pepdb.peptides p +WHERE (src.peptide_id = p.peptide_id); + diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.08-1.00.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.08-1.00.sql new file mode 100644 index 00000000..cd52d9c6 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-0.08-1.00.sql @@ -0,0 +1,27 @@ +DROP VIEW pepdb.pool_peptides; +CREATE VIEW pepdb.pool_peptides AS +SELECT src.peptide_pool_assignment_id,src.peptide_id,src.peptide_pool_id, +p.peptide_sequence,p.protein_cat_id,pg.peptide_group_id,pg.peptide_id_in_group, +p.sequence_length,p.amino_acid_start_pos,p.amino_acid_end_pos, +p.child, p.parent, + pp.pool_type_id,pp.peptide_pool_name,pt.pool_type_desc +FROM pepdb.peptide_pool_assignment src LEFT JOIN pepdb.peptide_pool pp +LEFT JOIN pepdb.pool_type pt ON(pp.pool_type_id = pt.pool_type_id) +ON (src.peptide_pool_id = pp.peptide_pool_id), pepdb.peptides p, pepdb.peptide_group_assignment pg +WHERE (src.peptide_id = p.peptide_id) and (pg.peptide_id = p.peptide_id); + +DROP VIEW pepdb.parent_child_details; +CREATE VIEW pepdb.parent_child_details AS +select par.peptide_id AS child_id,pchild.peptide_sequence AS child_sequence, +pchild.protein_cat_id AS child_protein,pgchild.peptide_group_id AS child_group, +pgchild.peptide_id_in_group AS child_lab_id,pchild.sequence_length AS child_seq_length, +pchild.amino_acid_start_pos AS child_AAStart,pchild.amino_acid_end_pos AS child_AAEnd, +pchild.optimal_epitope_list_id AS child_optimal_epitope_list_id,pchild.hla_restriction AS child_hla_restriction, +par.linked_parent AS parent_id,pparent.peptide_sequence AS parent_sequence, +pparent.protein_cat_id AS parent_protein,pgparent.peptide_group_id AS parent_group, +pgparent.peptide_id_in_group AS parent_lab_id,pparent.sequence_length AS parent_seq_length, +pparent.amino_acid_start_pos AS parent_AAStart,pparent.amino_acid_end_pos AS parent_AAEnd +from pepdb.parent par LEFT JOIN pepdb.peptides pchild ON (par.peptide_id = pchild.peptide_id) +LEFT JOIN pepdb.peptides pparent ON(par.linked_parent = pparent.peptide_id) +LEFT JOIN pepdb.peptide_group_assignment pgchild ON(par.peptide_id = pgchild.peptide_id) +LEFT JOIN pepdb.peptide_group_assignment pgparent ON(par.linked_parent = pgparent.peptide_id); \ No newline at end of file diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.00-1.50.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.00-1.50.sql new file mode 100644 index 00000000..1cc40829 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.00-1.50.sql @@ -0,0 +1,5 @@ +ALTER TABLE pepdb.peptide_pool ADD COLUMN archived boolean default false; +ALTER TABLE pepdb.peptide_pool_assignment ADD COLUMN peptide_group_assignment_id integer; +ALTER TABLE pepdb.peptide_pool_assignment ADD CONSTRAINT FK_peptide_pool_assignment3 FOREIGN KEY(peptide_group_assignment_id) REFERENCES pepdb.peptide_group_assignment(peptide_group_assignment_id); +ALTER TABLE pepdb.peptides ADD COLUMN peptide_flag boolean default false; +ALTER TABLE pepdb.peptides ADD COLUMN peptide_notes text; diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.50-1.75.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.50-1.75.sql new file mode 100644 index 00000000..62b4ef2c --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.50-1.75.sql @@ -0,0 +1,29 @@ +DROP VIEW pepdb.group_peptides; +CREATE VIEW pepdb.group_peptides AS +SELECT src.peptide_group_assignment_id,src.peptide_id, src.peptide_group_id, src.peptide_id_in_group, + pgroup.peptide_group_name,pgroup.pathogen_id, + p.peptide_sequence,p.protein_cat_id, + p.sequence_length,p.amino_acid_start_pos,p.amino_acid_end_pos, + p.child, p.parent,p.optimal_epitope_list_id,p.hla_restriction,p.peptide_flag,p.peptide_notes, + src.frequency_number,src.frequency_number_date,src.in_current_file +FROM ((pepdb.peptide_group_assignment src LEFT JOIN pepdb.peptide_group pgroup ON ((src.peptide_group_id + = pgroup.peptide_group_id))) LEFT JOIN pepdb.peptides p ON ((src.peptide_id = + p.peptide_id))); + +DROP VIEW pepdb.parent_child_details; +CREATE VIEW pepdb.parent_child_details AS +select par.peptide_id AS child_id,pchild.peptide_sequence AS child_sequence, +pchild.protein_cat_id AS child_protein,pgchild.peptide_group_id AS child_group, +pgchild.peptide_id_in_group AS child_lab_id,pchild.sequence_length AS child_seq_length, +pchild.amino_acid_start_pos AS child_AAStart,pchild.amino_acid_end_pos AS child_AAEnd, +pchild.optimal_epitope_list_id AS child_optimal_epitope_list_id,pchild.hla_restriction AS child_hla_restriction, +pchild.peptide_flag AS child_peptide_flag,pchild.peptide_notes AS child_peptide_notes, +par.linked_parent AS parent_id,pparent.peptide_sequence AS parent_sequence, +pparent.protein_cat_id AS parent_protein,pgparent.peptide_group_id AS parent_group, +pgparent.peptide_id_in_group AS parent_lab_id,pparent.sequence_length AS parent_seq_length, +pparent.amino_acid_start_pos AS parent_AAStart,pparent.amino_acid_end_pos AS parent_AAEnd, +pparent.peptide_flag AS parent_peptide_flag,pparent.peptide_notes AS parent_peptide_notes +from pepdb.parent par LEFT JOIN pepdb.peptides pchild ON (par.peptide_id = pchild.peptide_id) +LEFT JOIN pepdb.peptides pparent ON(par.linked_parent = pparent.peptide_id) +LEFT JOIN pepdb.peptide_group_assignment pgchild ON(par.peptide_id = pgchild.peptide_id) +LEFT JOIN pepdb.peptide_group_assignment pgparent ON(par.linked_parent = pgparent.peptide_id); \ No newline at end of file diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.75-2.00.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.75-2.00.sql new file mode 100644 index 00000000..227659ae --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-1.75-2.00.sql @@ -0,0 +1,12 @@ +DROP VIEW pepdb.pool_peptides; +CREATE VIEW pepdb.pool_peptides AS +SELECT src.peptide_pool_assignment_id,src.peptide_id,src.peptide_pool_id, +p.peptide_sequence,p.protein_cat_id,pg.peptide_group_id,pg.peptide_id_in_group, +p.sequence_length,p.amino_acid_start_pos,p.amino_acid_end_pos, +p.child, p.parent,p.peptide_flag,p.peptide_notes, + pp.pool_type_id,pp.peptide_pool_name,pt.pool_type_desc,pp.archived +FROM pepdb.peptide_pool_assignment src +LEFT JOIN pepdb.peptide_pool pp LEFT JOIN pepdb.pool_type pt ON(pp.pool_type_id = pt.pool_type_id) ON (src.peptide_pool_id = pp.peptide_pool_id) +LEFT JOIN pepdb.peptide_group_assignment pg ON(src.peptide_group_assignment_id = pg.peptide_group_assignment_id), +pepdb.peptides p +WHERE (src.peptide_id = p.peptide_id); \ No newline at end of file diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.00-2.10.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.00-2.10.sql new file mode 100644 index 00000000..5d92cbca --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.00-2.10.sql @@ -0,0 +1,4 @@ + +ALTER TABLE pepdb.peptide_pool ADD COLUMN parent_pool_id integer; +ALTER TABLE pepdb.peptide_pool ADD CONSTRAINT FK_peptide_pool2 FOREIGN KEY(parent_pool_id) REFERENCES pepdb.peptide_pool(peptide_pool_id); +ALTER TABLE pepdb.peptide_pool ADD COLUMN matrix_peptide_pool_id text; diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.10-2.20.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.10-2.20.sql new file mode 100644 index 00000000..08b42fc7 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.10-2.20.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE VIEW pepdb.pool_details AS +SELECT peptide_pool._ts,peptide_pool.createdby,peptide_pool.created,peptide_pool.modifiedby,peptide_pool.modified, +peptide_pool.peptide_pool_id,peptide_pool.peptide_pool_name, +peptide_pool.pool_type_id,pt.pool_type_desc, +peptide_pool.comment,peptide_pool.archived, +peptide_pool.parent_pool_id,peptide_pool.matrix_peptide_pool_id,p.peptide_pool_name AS parent_pool_name +from pepdb.peptide_pool LEFT JOIN pepdb.peptide_pool p ON(peptide_pool.parent_pool_id = p.peptide_pool_id) +LEFT JOIN pepdb.pool_type pt ON (peptide_pool.pool_type_id = pt.pool_type_id); \ No newline at end of file diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.20-2.21.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.20-2.21.sql new file mode 100644 index 00000000..2237cdea --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.20-2.21.sql @@ -0,0 +1,33 @@ +BEGIN; + +DROP VIEW IF EXISTS pepdb.parent_child_details; +DROP VIEW IF EXISTS pepdb.pool_peptides; +DROP VIEW IF EXISTS pepdb.group_peptides; + +-- RT #103413. Modify peptide_id_in_group's column type to varchar because the underlying data source +-- (an uploaded text file) changed format. +ALTER TABLE pepdb.peptide_group_assignment ALTER COLUMN peptide_id_in_group SET DATA TYPE varchar; + +CREATE OR REPLACE VIEW pepdb.parent_child_details AS + SELECT par.peptide_id AS child_id, pchild.peptide_sequence AS child_sequence, pchild.protein_cat_id AS child_protein, pgchild.peptide_group_id AS child_group, pgchild.peptide_id_in_group AS child_lab_id, pchild.sequence_length AS child_seq_length, pchild.amino_acid_start_pos AS child_aastart, pchild.amino_acid_end_pos AS child_aaend, pchild.optimal_epitope_list_id AS child_optimal_epitope_list_id, pchild.hla_restriction AS child_hla_restriction, pchild.peptide_flag AS child_peptide_flag, pchild.peptide_notes AS child_peptide_notes, par.linked_parent AS parent_id, pparent.peptide_sequence AS parent_sequence, pparent.protein_cat_id AS parent_protein, pgparent.peptide_group_id AS parent_group, pgparent.peptide_id_in_group AS parent_lab_id, pparent.sequence_length AS parent_seq_length, pparent.amino_acid_start_pos AS parent_aastart, pparent.amino_acid_end_pos AS parent_aaend, pparent.peptide_flag AS parent_peptide_flag, pparent.peptide_notes AS parent_peptide_notes + FROM pepdb.parent par + LEFT JOIN pepdb.peptides pchild ON par.peptide_id = pchild.peptide_id + LEFT JOIN pepdb.peptides pparent ON par.linked_parent = pparent.peptide_id + LEFT JOIN pepdb.peptide_group_assignment pgchild ON par.peptide_id = pgchild.peptide_id + LEFT JOIN pepdb.peptide_group_assignment pgparent ON par.linked_parent = pgparent.peptide_id; + +CREATE OR REPLACE VIEW pepdb.pool_peptides AS + SELECT src.peptide_pool_assignment_id, src.peptide_id, src.peptide_pool_id, p.peptide_sequence, p.protein_cat_id, pg.peptide_group_id, pg.peptide_id_in_group, p.sequence_length, p.amino_acid_start_pos, p.amino_acid_end_pos, p.child, p.parent, p.peptide_flag, p.peptide_notes, pp.pool_type_id, pp.peptide_pool_name, pt.pool_type_desc, pp.archived + FROM pepdb.peptide_pool_assignment src + LEFT JOIN (pepdb.peptide_pool pp + LEFT JOIN pepdb.pool_type pt ON pp.pool_type_id = pt.pool_type_id) ON src.peptide_pool_id = pp.peptide_pool_id + LEFT JOIN pepdb.peptide_group_assignment pg ON src.peptide_group_assignment_id = pg.peptide_group_assignment_id, pepdb.peptides p + WHERE src.peptide_id = p.peptide_id; + +CREATE OR REPLACE VIEW pepdb.group_peptides AS + SELECT src.peptide_group_assignment_id, src.peptide_id, src.peptide_group_id, src.peptide_id_in_group, pgroup.peptide_group_name, pgroup.pathogen_id, p.peptide_sequence, p.protein_cat_id, p.sequence_length, p.amino_acid_start_pos, p.amino_acid_end_pos, p.child, p.parent, p.optimal_epitope_list_id, p.hla_restriction, p.peptide_flag, p.peptide_notes, src.frequency_number, src.frequency_number_date, src.in_current_file + FROM pepdb.peptide_group_assignment src + LEFT JOIN pepdb.peptide_group pgroup ON src.peptide_group_id = pgroup.peptide_group_id + LEFT JOIN pepdb.peptides p ON src.peptide_id = p.peptide_id; + +COMMIT; diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.21-2.22.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.21-2.22.sql new file mode 100644 index 00000000..011f6039 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-2.21-2.22.sql @@ -0,0 +1,92 @@ + +INSERT INTO pepdb.clade VALUES (1, 'A'); +INSERT INTO pepdb.clade VALUES (2, 'B'); +INSERT INTO pepdb.clade VALUES (3, 'C'); +INSERT INTO pepdb.clade VALUES (4, 'D'); +INSERT INTO pepdb.clade VALUES (5, 'E'); +INSERT INTO pepdb.clade VALUES (6, 'G'); +INSERT INTO pepdb.clade VALUES (7, 'M'); +INSERT INTO pepdb.clade VALUES (8, 'Other'); +INSERT INTO pepdb.clade VALUES (9, 'Unknown'); +INSERT INTO pepdb.clade VALUES (10, 'A1'); +INSERT INTO pepdb.clade VALUES (11, 'C/A1/D'); +INSERT INTO pepdb.clade VALUES (12, 'D/A1'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.clade', 'clade_id'), 12, true); + +INSERT INTO pepdb.pathogen VALUES (1, 'HIV-1'); +INSERT INTO pepdb.pathogen VALUES (2, 'HIV-2'); +INSERT INTO pepdb.pathogen VALUES (3, 'TB'); +INSERT INTO pepdb.pathogen VALUES (4, 'Malaria'); +INSERT INTO pepdb.pathogen VALUES (5, 'Flu'); +INSERT INTO pepdb.pathogen VALUES (6, 'FEC'); +INSERT INTO pepdb.pathogen VALUES (7, 'EBV'); +INSERT INTO pepdb.pathogen VALUES (8, 'Other'); +INSERT INTO pepdb.pathogen VALUES (9, 'CMV'); +INSERT INTO pepdb.pathogen VALUES (10, 'AD5'); +INSERT INTO pepdb.pathogen VALUES (11, 'Pneumococcal'); +INSERT INTO pepdb.pathogen VALUES (12, 'EBOV'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.pathogen', 'pathogen_id'), 12, true); + +INSERT INTO pepdb.group_type VALUES (1, 'Consensus'); +INSERT INTO pepdb.group_type VALUES (2, 'Autologous'); +INSERT INTO pepdb.group_type VALUES (3, 'Mosaic'); +INSERT INTO pepdb.group_type VALUES (4, 'Toggle'); +INSERT INTO pepdb.group_type VALUES (5, 'LABL CTL Epitope'); +INSERT INTO pepdb.group_type VALUES (6, 'Other'); +INSERT INTO pepdb.group_type VALUES (7, 'Vaccine-matched'); +INSERT INTO pepdb.group_type VALUES (8, 'PTE'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.group_type', 'group_type_id'), 8, true); + +INSERT INTO pepdb.pep_align_ref VALUES (1,'HXB2'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.pep_align_ref', 'pep_align_ref_id'), 1, true); + +INSERT INTO pepdb.protein_category VALUES (1, 'GAG'); +INSERT INTO pepdb.protein_category VALUES (2, 'POL'); +INSERT INTO pepdb.protein_category VALUES (3, 'VIF'); +INSERT INTO pepdb.protein_category VALUES (4, 'VPR'); +INSERT INTO pepdb.protein_category VALUES (5, 'TAT'); +INSERT INTO pepdb.protein_category VALUES (6, 'REV'); +INSERT INTO pepdb.protein_category VALUES (7, 'VPU'); +INSERT INTO pepdb.protein_category VALUES (8, 'ENV'); +INSERT INTO pepdb.protein_category VALUES (9, 'NEF'); +INSERT INTO pepdb.protein_category VALUES (10, 'gp160'); +INSERT INTO pepdb.protein_category VALUES (11, 'Integrase'); +INSERT INTO pepdb.protein_category VALUES (12, 'p17'); +INSERT INTO pepdb.protein_category VALUES (13, 'Antigen 85A'); +INSERT INTO pepdb.protein_category VALUES (14, 'BZLF 1'); +INSERT INTO pepdb.protein_category VALUES (15, 'CFP10'); +INSERT INTO pepdb.protein_category VALUES (16, 'EBNA3A'); +INSERT INTO pepdb.protein_category VALUES (17, 'ESAT-6'); +INSERT INTO pepdb.protein_category VALUES (18, 'IE1'); +INSERT INTO pepdb.protein_category VALUES (19, 'p24'); +INSERT INTO pepdb.protein_category VALUES (20, 'p2p7p1p6'); +INSERT INTO pepdb.protein_category VALUES (21, 'pp65'); +INSERT INTO pepdb.protein_category VALUES (22, 'Protease'); +INSERT INTO pepdb.protein_category VALUES (23, 'RT-Integrase'); +INSERT INTO pepdb.protein_category VALUES (24, 'Other'); +INSERT INTO pepdb.protein_category VALUES (25, 'Gag_Pol_TF'); +INSERT INTO pepdb.protein_category VALUES (26, 'RT'); +INSERT INTO pepdb.protein_category VALUES (27, 'Protease-RT'); +INSERT INTO pepdb.protein_category VALUES (28, 'p17-p24'); +INSERT INTO pepdb.protein_category VALUES (29, 'p24-p2p7p1p6'); +INSERT INTO pepdb.protein_category VALUES (30, 'Gag_Pol_TF-Protease'); + + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.protein_category', 'protein_cat_id'), 30, true); + +INSERT INTO pepdb.pool_type VALUES (1, 'Pool'); +INSERT INTO pepdb.pool_type VALUES (2, 'Sub-Pool'); +INSERT INTO pepdb.pool_type VALUES (3, 'Matrix'); +INSERT INTO pepdb.pool_type VALUES (4, 'Other'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.pool_type', 'pool_type_id'), 4, true); + +INSERT INTO pepdb.optimal_epitope_list VALUES (1, 'A'); +INSERT INTO pepdb.optimal_epitope_list VALUES (2, 'B'); +INSERT INTO pepdb.optimal_epitope_list VALUES (3, 'None'); + +SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('pepdb.optimal_epitope_list', 'optimal_epitope_list_id'), 3, true); diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-create.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-create.sql new file mode 100644 index 00000000..a1bcfa3c --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-create.sql @@ -0,0 +1,70 @@ +CREATE VIEW pepdb.group_peptides AS + SELECT src.peptide_group_assignment_id, src.peptide_id, src.peptide_group_id, src.peptide_id_in_group, pgroup.peptide_group_name, pgroup.pathogen_id, p.peptide_sequence, p.protein_cat_id, p.sequence_length, p.amino_acid_start_pos, p.amino_acid_end_pos, p.child, p.parent, p.optimal_epitope_list_id, p.hla_restriction, p.peptide_flag, p.peptide_notes, src.frequency_number, src.frequency_number_date, src.in_current_file FROM ((pepdb.peptide_group_assignment src LEFT JOIN pepdb.peptide_group pgroup ON ((src.peptide_group_id = pgroup.peptide_group_id))) LEFT JOIN pepdb.peptides p ON ((src.peptide_id = p.peptide_id))); + +CREATE VIEW pepdb.parent_child_details AS + SELECT par.peptide_id AS child_id, pchild.peptide_sequence AS child_sequence, pchild.protein_cat_id AS child_protein, pgchild.peptide_group_id AS child_group, pgchild.peptide_id_in_group AS child_lab_id, pchild.sequence_length AS child_seq_length, pchild.amino_acid_start_pos AS child_aastart, pchild.amino_acid_end_pos AS child_aaend, pchild.optimal_epitope_list_id AS child_optimal_epitope_list_id, pchild.hla_restriction AS child_hla_restriction, pchild.peptide_flag AS child_peptide_flag, pchild.peptide_notes AS child_peptide_notes, par.linked_parent AS parent_id, pparent.peptide_sequence AS parent_sequence, pparent.protein_cat_id AS parent_protein, pgparent.peptide_group_id AS parent_group, pgparent.peptide_id_in_group AS parent_lab_id, pparent.sequence_length AS parent_seq_length, pparent.amino_acid_start_pos AS parent_aastart, pparent.amino_acid_end_pos AS parent_aaend, pparent.peptide_flag AS parent_peptide_flag, pparent.peptide_notes AS parent_peptide_notes FROM ((((pepdb.parent par LEFT JOIN pepdb.peptides pchild ON ((par.peptide_id = pchild.peptide_id))) LEFT JOIN pepdb.peptides pparent ON ((par.linked_parent = pparent.peptide_id))) LEFT JOIN pepdb.peptide_group_assignment pgchild ON ((par.peptide_id = pgchild.peptide_id))) LEFT JOIN pepdb.peptide_group_assignment pgparent ON ((par.linked_parent = pgparent.peptide_id))); + +CREATE VIEW pepdb.pool_details AS + SELECT peptide_pool._ts, peptide_pool.createdby, peptide_pool.created, peptide_pool.modifiedby, peptide_pool.modified, peptide_pool.peptide_pool_id, peptide_pool.peptide_pool_name, peptide_pool.pool_type_id, pt.pool_type_desc, peptide_pool.comment, peptide_pool.archived, peptide_pool.parent_pool_id, peptide_pool.matrix_peptide_pool_id, p.peptide_pool_name AS parent_pool_name FROM ((pepdb.peptide_pool LEFT JOIN pepdb.peptide_pool p ON ((peptide_pool.parent_pool_id = p.peptide_pool_id))) LEFT JOIN pepdb.pool_type pt ON ((peptide_pool.pool_type_id = pt.pool_type_id))); + +CREATE VIEW pepdb.pool_peptides AS + SELECT src.peptide_pool_assignment_id, src.peptide_id, src.peptide_pool_id, p.peptide_sequence, p.protein_cat_id, pg.peptide_group_id, pg.peptide_id_in_group, p.sequence_length, p.amino_acid_start_pos, p.amino_acid_end_pos, p.child, p.parent, p.peptide_flag, p.peptide_notes, pp.pool_type_id, pp.peptide_pool_name, pt.pool_type_desc, pp.archived FROM ((pepdb.peptide_pool_assignment src LEFT JOIN (pepdb.peptide_pool pp LEFT JOIN pepdb.pool_type pt ON ((pp.pool_type_id = pt.pool_type_id))) ON ((src.peptide_pool_id = pp.peptide_pool_id))) LEFT JOIN pepdb.peptide_group_assignment pg ON ((src.peptide_group_assignment_id = pg.peptide_group_assignment_id))), pepdb.peptides p WHERE (src.peptide_id = p.peptide_id); + +CREATE VIEW pepdb.peptideGroupRollup AS + SELECT + pg.created, + pg.createdBy, + pg.modified, + pg.modifiedBy, + pg.peptide_group_id, + pg.peptide_group_name AS name, + seq_ref, + p.pathogen_desc AS Pathogen, + c.clade_desc AS Clade, + gt.group_type_desc AS GroupType, + ar.pep_align_ref_desc AS AlignRef + FROM pepdb.peptide_group pg + LEFT JOIN pepdb.pathogen p ON pg.pathogen_id = p.pathogen_id + LEFT JOIN pepdb.clade c ON pg.clade_id = c.clade_id + LEFT JOIN pepdb.group_type gt ON pg.group_type_id = gt.group_type_id + LEFT JOIN pepdb.pep_align_ref ar ON pg.pep_align_ref_id = ar.pep_align_ref_id; + +CREATE VIEW pepdb.peptidePoolRollup AS + SELECT + pp.created, + pp.createdBy, + pp.modified, + pp.modifiedBy, + pp.peptide_pool_id, + pp.peptide_pool_name AS Name, + comment, + pt.pool_type_desc AS PoolType, + archived, + parent_pool_id, + matrix_peptide_pool_id + FROM pepdb.peptide_pool pp + JOIN pepdb.pool_type pt ON pp.pool_type_id = pt.pool_type_id; + +CREATE VIEW pepdb.peptideRollup AS + SELECT + p.created, + p.createdBy, + p.modified, + p.modifiedBy, + p.peptide_id, + peptide_sequence, + protein_cat_desc AS ProteinCategory, + amino_acid_start_pos, + amino_acid_end_pos, + sequence_length, + child, + parent, + src_file_name, + storage_location, + optimal_epitope_list_desc AS OptimalEpitopeList, + hla_restriction, + peptide_flag, + peptide_notes + FROM pepdb.peptides p + LEFT JOIN pepdb.protein_category pc ON p.protein_cat_id = pc.protein_cat_id + LEFT JOIN pepdb.optimal_epitope_list el ON p.optimal_epitope_list_id = el.optimal_epitope_list_id; diff --git a/pepdb/resources/schemas/dbscripts/postgresql/pepdb-drop.sql b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-drop.sql new file mode 100644 index 00000000..bac42b4c --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/postgresql/pepdb-drop.sql @@ -0,0 +1,11 @@ +DROP VIEW IF EXISTS pepdb.group_peptides; + +DROP VIEW IF EXISTS pepdb.parent_child_details; + +DROP VIEW IF EXISTS pepdb.pool_details; + +DROP VIEW IF EXISTS pepdb.pool_peptides; + +DROP VIEW IF EXISTS pepdb.peptideGroupRollup; +DROP VIEW IF EXISTS pepdb.peptidePoolRollup; +DROP VIEW IF EXISTS pepdb.peptideRollup; \ No newline at end of file diff --git a/pepdb/resources/schemas/dbscripts/sqlserver/pepdb-0.00-0.01.sql b/pepdb/resources/schemas/dbscripts/sqlserver/pepdb-0.00-0.01.sql new file mode 100644 index 00000000..d6f510d8 --- /dev/null +++ b/pepdb/resources/schemas/dbscripts/sqlserver/pepdb-0.00-0.01.sql @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2013 Fred Hutchinson Cancer Research Center + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- Tables and views used for Peptide module +CREATE SCHEMA pepdb; +GO \ No newline at end of file diff --git a/pepdb/resources/schemas/pepdb.xml b/pepdb/resources/schemas/pepdb.xml new file mode 100644 index 00000000..21511163 --- /dev/null +++ b/pepdb/resources/schemas/pepdb.xml @@ -0,0 +1,644 @@ + + + + + + + +
+ + + + + +
+ + + + + Peptide Id + + + Peptide Group Id + + + Peptide Number + + + Peptide Group Name + + + Pathogen + + pathogen_id + pathogen + pepdb + + + + Peptide Sequence + + + Protein Category + + protein_cat_id + protein_category + pepdb + + + + Sequence Length + + + AA Start + + + AA End + + + Is Child + + + Is Parent + + + Optimal Epitope List + + optimal_epitope_list_id + optimal_epitope_list + pepdb + + + + HLA Restriction + + + Peptide Flag + + + Peptide Flag Reason + + + Frequency Number + + + Frequency Update Date + + + +
+ + + + + Created By + + UserId + Users + core + + + + dd-MMM-yy + + + Modified By + + UserId + Users + core + + + + dd-MMM-yy + + + + 1 + true + + + Pool Type + + pool_type_id + pool_type + pepdb + + true + + + 1 + + + + + +
+ + + + + Created By + + UserId + Users + core + + + + dd-MMM-yy + + + Modified By + + UserId + Users + core + + + + dd-MMM-yy + + + + 1 + true + + + Pool Type + + pool_type_id + pool_type + pepdb + + true + + + + 1 + + + + + + +
+ + + + + +
+ + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + Child ID + + + Child Sequence + + + Child Protein Category + + protein_cat_id + protein_category + pepdb + + + + Child Peptide Group + + peptide_group_id + peptide_group + pepdb + + + + Child Peptide Number + + + Child Sequence Length + + + Child AAStart + + + Child AAEnd + + + Child Optimal Epitope List + + optimal_epitope_list_id + optimal_epitope_list + pepdb + + + + Child HLA Restriction + + + Child Peptide Flag + + + Child Flag Reason + + + Parent ID + + + Parent Sequence + + + Parent Protein Category + + protein_cat_id + protein_category + pepdb + + + + Parent Peptide Group + + peptide_group_id + peptide_group + pepdb + + + + Parent Peptide Number + + + Parent Sequence Length + + + Parent AAStart + + + Parent AAEnd + + + Parent Peptide Flagged + + + Parent Flag Reason + 2 + + +
+ + + + + Created By + + UserId + Users + core + + + + dd-MMM-yy + + + Modified By + + UserId + Users + core + + + + dd-MMM-yy + + + + 1 + true + + + Protein Category + true + + protein_cat_id + protein_category + pepdb + + + + AAStart + true + + + AAEnd + true + + + true + + + Is Child + true + + + Is Parent + true + + + Source File Name + 1 + true + + + 1 + + + Optimal Epitope List + + optimal_epitope_list_id + optimal_epitope_list + pepdb + + + + 1 + + + Peptide Is Flagged + + + Peptide Flag Reason + 2 + + +
+ + + + + Peptide ID + + + Peptide Pool ID + + + Peptide Sequence + + + Protein Category + + protein_cat_id + protein_category + pepdb + + + + Peptide Group + + peptide_group_id + peptide_group + pepdb + + + + Peptide Number + + + Sequence Length + + + AAStart + + + AAEnd + + + Is Child + + + Is Parent + + + Peptide Flag + + + Flag Reason + 2 + + + Pool Type + + pool_type_id + pool_type + pepdb + + + + Peptide Pool Name + + + Pool Type + + + Archived + + +
+ + + + + +
+ + + + + Created By + true + + UserId + Users + core + + + + true + dd-MMM-yy + + + true + Modified By + + UserId + Users + core + + + + true + dd-MMM-yy + + + + 1 + Peptide Group Name + + + Pathogen + + pathogen_id + pathogen + pepdb + + + + 1 + + + Clade + + clade_id + clade + pepdb + + + + Pep Align Ref + + pep_align_ref_id + pep_align_ref + pepdb + + + + Group Type + + group_type_id + group_type + pepdb + + + + peptide_group_id +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ diff --git a/pepdb/src/org/scharp/atlas/pepdb/PepDBBaseController.java b/pepdb/src/org/scharp/atlas/pepdb/PepDBBaseController.java new file mode 100644 index 00000000..57d01f85 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PepDBBaseController.java @@ -0,0 +1,697 @@ +package org.scharp.atlas.pepdb; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.labkey.api.action.SpringActionController; +import org.labkey.api.attachments.AttachmentFile; +import org.labkey.api.data.BeanViewForm; +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.DataColumn; +import org.labkey.api.data.RenderContext; +import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; +import org.labkey.api.data.TableInfo; +import org.labkey.api.util.DateUtil; +import org.labkey.api.util.HtmlString; +import org.labkey.api.util.HtmlStringBuilder; +import org.labkey.api.util.Link; +import org.labkey.api.view.ActionURL; +import org.scharp.atlas.pepdb.model.PeptideGroup; +import org.scharp.atlas.pepdb.model.PeptidePool; +import org.scharp.atlas.pepdb.model.Peptides; +import org.scharp.atlas.pepdb.model.ProteinCategory; +import org.springframework.validation.Errors; + +import java.io.IOException; +import java.io.Writer; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jul 6, 2009 + * Time: 12:43:07 PM + * To change this template use File | Settings | File Templates. + */ +public class PepDBBaseController extends SpringActionController +{ + private final static Logger _log = LogManager.getLogger(PepDBBaseController.class); + + private static final String VIEW_DISPLAY_PEPTIDE = "displayPeptide.view"; + protected static final String QRY_STRING_PEPTIDE_ID = "peptideId"; + + public static class PeptideQueryForm + { + private String queryKey; + private String queryValue; + private String message; + private TableInfo tInfo; + private SimpleFilter filter; + private List cInfo; + private Sort sort; + private String AAStart; + private String AAEnd; + private String labId; + + public String getMessage() + { + return message; + } + + public void setMessage(String message) + { + this.message = message; + } + + public List getCInfo() + { + return cInfo; + } + + public void setCInfo(List cInfo) + { + this.cInfo = cInfo; + } + + public String getQueryValue() + { + return queryValue; + } + + public void setQueryValue(String queryValue) + { + this.queryValue = queryValue; + } + + public TableInfo getTInfo() + { + return tInfo; + } + + public void setTInfo(TableInfo tInfo) + { + this.tInfo = tInfo; + } + + public SimpleFilter getFilter() + { + return filter; + } + + public void setFilter(SimpleFilter filter) + { + this.filter = filter; + } + + public Sort getSort() + { + return sort; + } + + public void setSort(Sort sort) + { + this.sort = sort; + } + + public String getQueryKey() + { + return queryKey; + } + + public void setQueryKey(String queryKey) + { + this.queryKey = queryKey; + } + + public String getAAStart() + { + return AAStart; + } + + public void setAAStart(String AAStart) + { + this.AAStart = AAStart; + } + + public String getAAEnd() + { + return AAEnd; + } + + public void setAAEnd(String AAEnd) + { + this.AAEnd = AAEnd; + } + + public String getLabId() + { + return labId; + } + + public void setLabId(String labId) + { + this.labId = labId; + } + + public boolean validate(Errors errors) throws SQLException + { + if(getQueryKey() == null || StringUtils.trimToNull(getQueryKey()) == null) + errors.reject(null, "The Search Criteria must be entered."); + String qValue = getQueryValue(); + if (getQueryKey() != null && getQueryKey().equals(PepDBSchema.COLUMN_PARENT_SEQUENCE)) + { + if (StringUtils.trimToNull(qValue) == null) + errors.reject(null, "The Parent Sequence must be entered."); + } + if (getQueryKey() != null && getQueryKey().equals(PepDBSchema.COLUMN_CHILD_SEQUENCE)) + { + if (StringUtils.trimToNull(qValue) == null) + errors.reject(null, "The Child Sequence must be entered."); + } + if (getQueryKey() != null && getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID)) + { + if (StringUtils.trimToNull(qValue) == null) + errors.reject(null, "Peptide Group must be selected to get peptides in a group."); + /* + if(StringUtils.trimToNull(getLabId()) == null) + errors.reject(null, "Peptide Number must be entered."); + */ + } + if (getQueryKey() != null && getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_POOL_ID)) + { + if (StringUtils.trimToNull(qValue) == null) + errors.reject(null, "Peptide Pool Name must be selected to get peptides in a pool."); + } + if (getQueryKey() != null && getQueryKey().equals(PepDBSchema.COLUMN_PROTEIN_CAT_ID)) + { + if (StringUtils.trimToNull(qValue) == null) + errors.reject(null, "Protein Category must be selected to get peptides in a protein category."); + else + { + ProteinCategory pc = PepDBManager.getProCatByID(Integer.parseInt(getQueryValue())); + if(pc.getProtein_cat_desc().trim().contains("-")) + { + if(StringUtils.trimToNull(getAAStart()) != null || StringUtils.trimToNull(getAAEnd()) != null) + errors.reject(null,"When you select a hyphanated Protein Category : "+pc.getProtein_cat_desc()+" AAStart & AAEnd values are not allowed."); + } + else + { + if(StringUtils.trimToNull(getAAStart()) != null && validateInteger(getAAStart().trim()) == null) + errors.reject(null, "AAStart must be an Integer."); + if(StringUtils.trimToNull(getAAEnd()) != null && validateInteger(getAAEnd().trim()) == null) + errors.reject(null, "AAEnd must be an Integer."); + if(StringUtils.trimToNull(getAAStart()) != null && validateInteger(getAAStart().trim()) != null + && StringUtils.trimToNull(getAAEnd()) != null && validateInteger(getAAEnd().trim()) != null + && validateInteger(getAAStart().trim()) > validateInteger(getAAEnd().trim())) + errors.reject(null, "AAStart must be less than or equal to AAEnd."); + } + } + } + if (getQueryKey() != null && getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_ID)) + { + if (StringUtils.trimToNull(qValue) == null) + errors.reject(null, "The Peptide Id range must be entered."); + if (qValue != null && qValue.length() > 0) + { + if (!(qValue.matches("\\d+-\\d+"))) + { + errors.reject(null, "To get the peptides in the range you should specify the Range of numbers.\n" + + "The format for specify the range of peptide is - Example would be 30-100"); + } + else + { + String[] range = qValue.split("-"); + if (Integer.parseInt(range[0]) > Integer.parseInt(range[1])) + { + errors.reject(null, "The minimum value which is before '-' should be less than the max value which is after '-'.\n"); + + } + } + } + } + if(errors != null && errors.getErrorCount() >0) + return false; + return true; + } + + } + + public static class DisplayPeptideForm + { + private String peptide_id; + private boolean modify = false; + private String manufactureStatus; + + public String getPeptide_id() + { + return peptide_id; + } + + public void setPeptide_id(String peptide_id) + { + this.peptide_id = peptide_id; + } + + public void setModify(boolean modify) + { + this.modify = modify; + } + + public boolean getModify() + { + return this.modify; + } + + public String getManufactureStatus() + { + return manufactureStatus; + } + + public void setManufactureStatus(String manufactureStatus) + { + this.manufactureStatus = manufactureStatus; + } + + public String toString() + { + return "DisplayPeptideForm [peptideId:" + this.peptide_id + + ", modify:" + this.modify + + ", manufactureStatus:" + this.manufactureStatus + "]"; + } + } + + public static class PeptideAndGroupForm extends DisplayPeptideForm + { + + private String peptide_group_id; + + public String getPeptide_group_id() + { + return peptide_group_id; + } + + public void setPeptide_group_id(String peptide_group_id) + { + this.peptide_group_id = peptide_group_id; + } + + public String toString() + { + return "PeptideAndGroupForm [peptideGroup:" + this.peptide_group_id + "] - " + super.toString(); + } + + } + + public static class PeptideAndPoolForm extends DisplayPeptideForm + { + private String peptide_pool_id; + + public String getPeptide_pool_id() + { + return peptide_pool_id; + } + + public void setPeptide_pool_id(String peptide_pool_id) + { + this.peptide_pool_id = peptide_pool_id; + } + + public String toString() + { + return "PeptideAndPoolForm [peptidePool:" + this.peptide_pool_id + "] - " + super.toString(); + } + } + + public static class PeptideForm extends BeanViewForm { + public PeptideForm() + { + super(Peptides.class, PepDBSchema.getInstance().getTableInfoPeptides()); + + } + public PeptideForm(String peptideID) + { + this(); + set("peptide_id", String.valueOf(peptideID)); + } + } + + public static class PeptidePoolForm extends BeanViewForm { + public PeptidePoolForm() + { + super(PeptidePool.class, PepDBSchema.getInstance().getTableInfoPeptidePools()); + + } + public PeptidePoolForm(String peptidePoolID) + { + this(); + set("peptide_pool_id", String.valueOf(peptidePoolID)); + } + + } + + public static class PeptideGroupForm extends BeanViewForm { + public PeptideGroupForm() + { + super(PeptideGroup.class, PepDBSchema.getInstance().getTableInfoPeptideGroups()); + + } + public PeptideGroupForm(String peptideGroupID) + { + this(); + set("peptide_group_id", String.valueOf(peptideGroupID)); + } + + public void validate(Errors errors) + { + PeptideGroup bean = getBean(); + if(bean.getPathogen_id() == null || StringUtils.trimToNull(bean.getPathogen_id().toString())==null) + errors.reject(null,"Pathogen is Required"); + if(bean.getClade_id() == null || StringUtils.trimToNull(bean.getClade_id().toString())==null) + errors.reject(null,"Clade is Required"); + if(bean.getGroup_type_id() == null || StringUtils.trimToNull(bean.getGroup_type_id().toString())==null) + errors.reject(null,"Group Type is Required"); + if (StringUtils.trimToNull(bean.getPeptide_group_name()) == null) + errors.reject(null, "Peptide Group Name is required."); + } + + public void validateName(Errors errors) throws SQLException + { + PeptideGroup bean = getBean(); + PeptideGroup pg = PepDBManager.getPeptideGroupByName(bean); + if(pg != null) + errors.reject(null, "Peptide Group with the name : "+bean.getPeptide_group_name()+" with a different ID already exists in the database."); + } + } + + public static class FileForm + { + private String message; + private String actionType; + + public String getMessage() + { + return message; + } + + public void setMessage(String message) + { + this.message = message; + } + + public String getActionType() + { + return actionType; + } + + public void setActionType(String actionType) + { + this.actionType = actionType; + } + + public boolean validate(Errors errors, AttachmentFile file) throws Exception + { + if (file == null || file.getSize() == 0) + errors.reject(null, "File is required.File should be tab delimited text file and the number of field vary depending on file type."); + else + { + if (!(file.getFilename().endsWith(".txt"))) + { + errors.reject(null, "File name must end with in .txt.\nFile should be tab delimited text file and the number of field vary depending on file type."); + } + } + if (getActionType() == null || getActionType().length() == 0) + errors.reject(null, "File Type is required"); + if(errors.getErrorCount() > 0) + return false; + return true; + } + } + + public class DCpeptideId extends DataColumn + { + public DCpeptideId(ColumnInfo col) + { + super(col); + } + + @Override + public void renderGridCellContents(RenderContext ctx, Writer out) throws IOException + { + ColumnInfo c = getColumnInfo(); + Map rowMap = ctx.getRow(); + if (!PepDBSchema.COLUMN_PEPTIDE_ID.equals(c.getName()) && !PepDBSchema.COLUMN_PARENT_ID.equals(c.getName()) && !PepDBSchema.COLUMN_CHILD_ID.equals(c.getName())) + super.renderGridCellContents(ctx, out); + else + { + Integer peptideId = (Integer) rowMap.get(c.getName()); + try + { + new Link.LinkBuilder("P" + peptideId).clearClasses() + .target("_self") + .href(new ActionURL(PepDBController.DisplayPeptideAction.class, getContainer()) + .addParameter(PepDBSchema.COLUMN_PEPTIDE_ID, peptideId)) + .build() + .appendTo(out); + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + } + + @Override + @NotNull + public HtmlString getFormattedHtml(RenderContext ctx) { + HtmlStringBuilder hsb = HtmlStringBuilder.of("P"); + hsb.append(super.getFormattedHtml(ctx)); + return hsb.getHtmlString(); + } + + @Override + public Object getDisplayValue(RenderContext ctx) + { + ColumnInfo c = getColumnInfo(); + Map rowMap = ctx.getRow(); + if (!PepDBSchema.COLUMN_PEPTIDE_ID.equals(c.getName()) && !PepDBSchema.COLUMN_PARENT_ID.equals(c.getName()) && !PepDBSchema.COLUMN_CHILD_ID.equals(c.getName())) + return super.getValue(ctx); + else + { + Integer peptideId = (Integer) rowMap.get(c.getName()); + try + { + return ("P"+peptideId); + } + catch (Exception e) + { + e.printStackTrace(); + return "EXPORT/OUTPUT ERROR"; + } + } + } + + @Override + public Class getValueClass() + { + return Integer.class; + } + + @Override + public Class getDisplayValueClass() + { + return String.class; + } + } + + public class DCpeptidePoolId extends DataColumn + { + public DCpeptidePoolId(ColumnInfo col) + { + super(col); + } + + @Override + public void renderGridCellContents(RenderContext ctx, Writer out) throws IOException + { + ColumnInfo c = getColumnInfo(); + Map rowMap = ctx.getRow(); + if (!PepDBSchema.COLUMN_PEPTIDE_POOL_ID.equals(c.getName())) + super.renderGridCellContents(ctx, out); + else + { + Integer peptidePoolId = (Integer) rowMap.get(c.getName()); + try + { + new Link.LinkBuilder("PP" + peptidePoolId).clearClasses() + .target("_self") + .href(new ActionURL(PepDBController.DisplayPeptidePoolInformationAction.class, getContainer()) + .addParameter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID, peptidePoolId)) + .build() + .appendTo(out); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + + @Override + @NotNull + public HtmlString getFormattedHtml(RenderContext ctx) { + HtmlStringBuilder hsb = HtmlStringBuilder.of("PP"); + hsb.append(super.getFormattedHtml(ctx)); + return hsb.getHtmlString(); + } + + @Override + public Object getDisplayValue(RenderContext ctx) + { + ColumnInfo c = getColumnInfo(); + Map rowMap = ctx.getRow(); + if (!PepDBSchema.COLUMN_PEPTIDE_POOL_ID.equals(c.getName())) + return super.getValue(ctx); + else + { + Integer peptidePoolId = (Integer) rowMap.get(c.getName()); + try + { + return ("PP" + peptidePoolId); + } + catch (Exception e) + { + e.printStackTrace(); + return "EXPORT/OUTPUT ERROR"; + } + } + } + + @Override + public Class getValueClass() + { + return Integer.class; + } + + @Override + public Class getDisplayValueClass() + { + return String.class; + } + } + + public class DCparentPoolId extends DataColumn + { + public DCparentPoolId(ColumnInfo col) + { + super(col); + } + + @Override + public void renderGridCellContents(RenderContext ctx, Writer out) throws IOException + { + ColumnInfo c = getColumnInfo(); + Map rowMap = ctx.getRow(); + if (!PepDBSchema.COLUMN_PARENT_POOL_ID.equals(c.getName())) + super.renderGridCellContents(ctx, out); + else + { + Integer parentPoolId = (Integer) rowMap.get(c.getName()); + try + { + if(parentPoolId != null) + { + new Link.LinkBuilder("PP" + parentPoolId).clearClasses() + .target("_self") + .href(new ActionURL(PepDBController.DisplayPeptidePoolInformationAction.class, getContainer()) + .addParameter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID, parentPoolId)) + .build() + .appendTo(out); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + + @Override + public Object getDisplayValue(RenderContext ctx) + { + ColumnInfo c = getColumnInfo(); + Map rowMap = ctx.getRow(); + if (!PepDBSchema.COLUMN_PARENT_POOL_ID.equals(c.getName())) + return super.getValue(ctx); + else + { + Integer parentPoolId = (Integer) rowMap.get(c.getName()); + try + { + if (parentPoolId != null) + return ("PP" + parentPoolId); + else + return null; + } + catch (Exception e) + { + e.printStackTrace(); + return "EXPORT/OUTPUT ERROR"; + } + } + } + + @Override + public Class getValueClass() + { + return Integer.class; + } + + @Override + public Class getDisplayValueClass() + { + return String.class; + } + } + + public static Integer validateInteger(String value) + { + try + { + return Integer.valueOf(value); + } + catch(NumberFormatException e){return null;} + } + + public static String toLZ(String s) + { + if (s.length() > 6) return s.substring(0, 6); + else if (s.length() < 6) // pad on left with zeros + return "000000000000000000000000000".substring(0, 6 - s.length()) + s; + else return s; + } + + public static java.util.Date isValidDate(String sDateIn) { + + try { + java.util.Date dDate = new java.util.Date(DateUtil.parseDateTime(sDateIn)); + return dDate; + } catch (ConversionException x) { + return null; + } + } + + public static Float validateFloat(String value) + { + try + { + return Float.valueOf(value); + } + catch(NumberFormatException e){return null;} + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/PepDBContainerListener.java b/pepdb/src/org/scharp/atlas/pepdb/PepDBContainerListener.java new file mode 100644 index 00000000..88027139 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PepDBContainerListener.java @@ -0,0 +1,53 @@ +package org.scharp.atlas.pepdb; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.labkey.api.data.Container; +import org.labkey.api.data.ContainerManager.ContainerListener; +import org.labkey.api.security.User; + +import java.beans.PropertyChangeEvent; +import java.util.Collection; +import java.util.Collections; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Mar 16, 2009 + * Time: 10:18:45 AM + * To change this template use File | Settings | File Templates. + */ +public class PepDBContainerListener implements ContainerListener +{ + + private static final Logger _log = LogManager.getLogger(PepDBContainerListener.class); + + @Override + public void containerCreated(Container c, User user) + { + } + + @Override + public void containerDeleted(Container c, User user) + { + } + + @Override + public void containerMoved(Container c, Container oldParent, User user) + { + } + + @NotNull + @Override + public Collection canMove(Container c, Container newParent, User user) + { + return Collections.emptyList(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + } + +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/PepDBController.java b/pepdb/src/org/scharp/atlas/pepdb/PepDBController.java new file mode 100644 index 00000000..c0998ff6 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PepDBController.java @@ -0,0 +1,1400 @@ +package org.scharp.atlas.pepdb; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.labkey.api.action.ExportAction; +import org.labkey.api.action.FormViewAction; +import org.labkey.api.action.SimpleViewAction; +import org.labkey.api.attachments.AttachmentFile; +import org.labkey.api.data.ActionButton; +import org.labkey.api.data.Aggregate; +import org.labkey.api.data.ButtonBar; +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.CompareType; +import org.labkey.api.data.Container; +import org.labkey.api.data.DataRegion; +import org.labkey.api.data.DisplayColumn; +import org.labkey.api.data.ExcelWriter; +import org.labkey.api.data.RenderContext; +import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; +import org.labkey.api.data.TSVGridWriter; +import org.labkey.api.data.Table; +import org.labkey.api.data.TableInfo; +import org.labkey.api.query.FieldKey; +import org.labkey.api.query.QuerySettings; +import org.labkey.api.security.RequiresPermission; +import org.labkey.api.security.permissions.ReadPermission; +import org.labkey.api.security.permissions.UpdatePermission; +import org.labkey.api.view.ActionURL; +import org.labkey.api.view.DetailsView; +import org.labkey.api.view.GridView; +import org.labkey.api.view.HttpView; +import org.labkey.api.view.InsertView; +import org.labkey.api.view.JspView; +import org.labkey.api.view.NavTree; +import org.labkey.api.view.UpdateView; +import org.labkey.api.view.VBox; +import org.labkey.api.view.ViewContext; +import org.scharp.atlas.pepdb.model.PeptideGroup; +import org.scharp.atlas.pepdb.model.PeptidePool; +import org.scharp.atlas.pepdb.model.Peptides; +import org.scharp.atlas.pepdb.model.ProteinCategory; +import org.springframework.beans.PropertyValues; +import org.springframework.validation.BindException; +import org.springframework.validation.Errors; +import org.springframework.web.servlet.ModelAndView; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * User: sravani + * Date: Jul 6, 2009 + * Time: 12:19:21 PM + */ +public class PepDBController extends PepDBBaseController +{ + private static final Logger _log = LogManager.getLogger(PepDBController.class); + private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(PepDBController.class); + + private static final String PAGE_INDEX = "/org/scharp/atlas/pepdb/view/index.jsp"; + private static final String PAGE_PEPTIDE_GROUP_SELECT = "/org/scharp/atlas/pepdb/view/peptideGroupSelect.jsp"; + private static final String PAGE_IMPORT_PEPTIDES = "/org/scharp/atlas/pepdb/view/importPeptides.jsp"; + + // Maximum number of rows to display on a web page at once. Specifying Table.ALL_ROWS was causing a JavaScript timeout. + private static final int MAX_ROWS = 1000; + + public PepDBController() + { + setActionResolver(_actionResolver); + } + + public ActionURL peptideURL(String action) + { + Container c = getViewContext().getContainer(); + return new ActionURL("PepDB", action, c); + } + + protected HttpServletRequest getRequest() + { + return getViewContext().getRequest(); + } + + protected HttpServletResponse getResponse() + { + return getViewContext().getResponse(); + } + + @RequiresPermission(ReadPermission.class) + public class BeginAction extends SimpleViewAction + { + @Override + public ModelAndView getView(DisplayPeptideForm form, BindException errors) throws Exception + { + JspView v = new JspView(PAGE_INDEX, form, errors); + return v; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Begin", peptideURL("begin")); + } + } + + @RequiresPermission(ReadPermission.class) + public class SearchForPeptidesAction extends FormViewAction + { + @Override + public ModelAndView getView(PeptideQueryForm form, boolean reshow, BindException errors) throws Exception + { + ViewContext ctx = getViewContext(); + HttpSession session = ctx.getRequest().getSession(true); + PeptideQueryForm form1 = (PeptideQueryForm) session.getAttribute("QUERY_FORM"); + if (form1 != null && form.getQueryKey() == null) + form = form1; + JspView v = new JspView(PAGE_PEPTIDE_GROUP_SELECT, form, errors); + return v; + } + + @Override + public boolean handlePost(PeptideQueryForm form, BindException errors) throws Exception + { + String actionType = getRequest().getParameter("action_type"); + if (actionType != null && actionType.equals("Get Peptides")) + return true; + else + return false; + } + + @Override + public void validateCommand(PeptideQueryForm form, Errors errors) + { + return; + } + + @Override + public ActionURL getSuccessURL(PeptideQueryForm form) + { + ActionURL urlTest = new ActionURL(GetPeptidesAction.class, getContainer()); + urlTest.addParameter("queryKey", form.getQueryKey()); + urlTest.addParameter("queryValue", form.getQueryValue()); + if (form.getQueryKey() != null && form.getQueryKey().equals(PepDBSchema.COLUMN_PROTEIN_CAT_ID)) + { + if (form.getAAStart() != null) + urlTest.addParameter("AAStart", form.getAAStart()); + if (form.getAAEnd() != null) + urlTest.addParameter("AAEnd", form.getAAEnd()); + } + if (form.getQueryKey() != null && form.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID)) + { + if (form.getLabId() != null) + urlTest.addParameter("labId", form.getLabId()); + } + return urlTest; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Search For Peptides By Criteria", peptideURL("searchForPeptides")); + } + } + + @RequiresPermission(ReadPermission.class) + public class GetPeptidesAction extends SimpleViewAction + { + @Override + public ModelAndView getView(PeptideQueryForm form, BindException errors) throws Exception + { + if (!form.validate(errors)) + { + return new JspView<>(PAGE_PEPTIDE_GROUP_SELECT, form, errors); + } + PropertyValues pv = this.getPropertyValues(); + ViewContext ctx = getViewContext(); + HttpSession session = ctx.getRequest().getSession(true); + session.setAttribute("QUERY_FORM", form); + GridView gridView = new GridView(new DataRegion(), (BindException) null); + if (form.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID)) + { + gridView = getGridViewByGroup(form, pv); + } + if (form.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_POOL_ID)) + { + gridView = getGridViewByPool(form, pv); + } + if (form.getQueryKey().equals(PepDBSchema.COLUMN_PROTEIN_CAT_ID)) + { + gridView = getGridViewByProtein(form, pv); + } + if (form.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_SEQUENCE)) + { + gridView = getGridViewBySequence(form, pv); + } + if (form.getQueryKey().equals(PepDBSchema.COLUMN_PARENT_SEQUENCE)) + { + gridView = getGridViewByParent(form, pv); + } + if (form.getQueryKey().equals(PepDBSchema.COLUMN_CHILD_SEQUENCE)) + { + gridView = getGridViewByChild(form, pv); + } + if (gridView == null) + { + HttpView.redirect(new ActionURL(SearchForPeptidesAction.class, getContainer())); + } + return gridView; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Get Peptides By Criteria", peptideURL("getPeptides")); + } + } + + @RequiresPermission(ReadPermission.class) + public class DisplayPeptideAction extends SimpleViewAction + { + @Override + public ModelAndView getView(DisplayPeptideForm form, BindException errors) throws Exception + { + String pepId = form.getPeptide_id(); + if (pepId == null || pepId.length() == 0 + || (!pepId.trim().toUpperCase().startsWith("P") && validateInteger(pepId.trim()) == null) + || (pepId.trim().toUpperCase().startsWith("P") && validateInteger(pepId.trim().substring(1)) == null)) + { + errors.reject(null, "Peptide Id is required and It has to be an Integer with or without prefix 'P'."); + JspView v = new JspView(PAGE_INDEX, form, errors); + return v; + } + if (pepId.trim().toUpperCase().startsWith("P") && validateInteger(pepId.trim().substring(1)) != null) + pepId = pepId.trim().substring(1); + Peptides p = PepDBManager.getPeptideById(Integer.parseInt(pepId)); + if (p == null) + { + errors.reject(null, "Peptide Id not found in the database."); + JspView v = new JspView(PAGE_INDEX, form, errors); + return v; + } + _log.debug("DisplayPeptideForm: " + form.toString()); + VBox box = new VBox(); + PeptideQueryForm queryform = new PeptideQueryForm(); + queryform.setQueryValue(pepId); + DetailsView dataView = getPeptideDetailsView(queryform, p); + if (!p.isChild()) + { + dataView.getDataRegion().getDisplayColumn("optimal_epitope_list_id").setVisible(false); + dataView.getDataRegion().getDisplayColumn("hla_restriction").setVisible(false); + } + box.addView(dataView); + JspView detailsView = new JspView("/org/scharp/atlas/pepdb/view/peptideDetails.jsp", queryform, errors); + box.addView(detailsView); + PropertyValues pv = this.getPropertyValues(); + if (p.isParent()) + { + PeptideQueryForm parentform = new PeptideQueryForm(); + parentform.setQueryValue((pepId)); + GridView gvChildren = getGridViewByParentId(parentform, pv); + box.addView(gvChildren); + } + if (p.isChild()) + { + PeptideQueryForm childform = new PeptideQueryForm(); + childform.setQueryValue((pepId)); + GridView gvParents = getGridViewByChildId(childform, pv); + box.addView(gvParents); + } + return box; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Display Peptide Details", peptideURL("displayPeptide")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class EditPeptideAction extends FormViewAction + { + @Override + public ModelAndView getView(PeptideForm form, boolean reshow, BindException errors) + { + Peptides p = PepDBManager.getPeptideById(form.getBean().getPeptide_id()); + UpdateView uView = new UpdateView(form, errors); + ButtonBar bb = new ButtonBar(); + //bb.add(new ActionButton("editPeptide.post","Save Changes")); + //ActionURL editPeptideUrl = new ActionURL(EditPeptideAction.class, getContainer()); + + bb.add(new ActionButton(new ActionURL(EditPeptideAction.class, getContainer()), "Save Changes")); + + ActionURL backURL = new ActionURL(DisplayPeptideAction.class, getContainer()); + backURL.addParameter(PepDBSchema.COLUMN_PEPTIDE_ID, form.getBean().getPeptide_id()); + ActionButton cancelButton = new ActionButton(backURL, "Cancel"); + cancelButton.setActionType(ActionButton.Action.LINK); + bb.add(cancelButton); + uView.getDataRegion().setButtonBar(bb); + if (!p.isChild()) + { + uView.getDataRegion().getDisplayColumn("optimal_epitope_list_id").setVisible(false); + uView.getDataRegion().getDisplayColumn("hla_restriction").setVisible(false); + } + uView.setTitle("Update Peptide data for : P" + form.getBean().getPeptide_id()); + return uView; + } + + @Override + public boolean handlePost(PeptideForm form, BindException errors) throws Exception + { + Peptides oldBean = PepDBManager.getPeptideById(form.getBean().getPeptide_id()); + form.setOldValues(oldBean); + Peptides bean = form.getBean(); + PepDBManager.updatePeptide(getUser(), bean); + return true; + } + + @Override + public void validateCommand(PeptideForm form, Errors errors) + { + Peptides bean = form.getBean(); + if (bean.isPeptide_flag() && (bean.getPeptide_notes() == null || bean.getPeptide_notes().length() == 0)) + errors.reject(null, "If a peptide is flagged then you must enter Peptide Flag Reason."); + if (!bean.isPeptide_flag() && bean.getPeptide_notes() != null && bean.getPeptide_notes().trim().length() != 0) + errors.reject(null, "If a peptide is not flagged then Peptide Flag Reason must be blank."); + } + + @Override + public ActionURL getSuccessURL(PeptideForm form) + { + ActionURL url = new ActionURL(DisplayPeptideAction.class, getContainer()); + url.addParameter(PepDBSchema.COLUMN_PEPTIDE_ID, form.getBean().getPeptide_id()); + return url; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Edit Peptide", peptideURL("editPeptide")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class EditPeptidePoolAction extends FormViewAction + { + @Override + public ModelAndView getView(PeptidePoolForm form, boolean reshow, BindException errors) + { + PeptidePool p = PepDBManager.getPeptidePoolByID(form.getBean().getPeptide_pool_id()); + UpdateView uView = new UpdateView(form, errors); + ButtonBar bb = new ButtonBar(); + bb.add(new ActionButton(new ActionURL(EditPeptidePoolAction.class, getContainer()), "Save Changes")); + //bb.add(new ActionButton("editPeptidePool.post","Save Changes")); + ActionURL backURL = new ActionURL(DisplayPeptidePoolInformationAction.class, getContainer()); + backURL.addParameter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID, form.getBean().getPeptide_pool_id()); + ActionButton cancelButton = new ActionButton(backURL, "Cancel"); + cancelButton.setActionType(ActionButton.Action.LINK); + bb.add(cancelButton); + uView.getDataRegion().setButtonBar(bb); + uView.setTitle("Update Peptide Pool data for : PP" + form.getBean().getPeptide_pool_id()); + return uView; + } + + @Override + public boolean handlePost(PeptidePoolForm form, BindException errors) throws Exception + { + PeptidePool bean = form.getBean(); + PeptidePool dbBean = PepDBManager.getPeptidePoolByID(bean.getPeptide_pool_id()); + bean.setCreated(dbBean.getCreated()); + bean.setCreatedBy(dbBean.getCreatedBy()); + PepDBManager.updatePeptidePool(getUser(), bean); + return true; + } + + @Override + public void validateCommand(PeptidePoolForm form, Errors errors) + { + + } + + @Override + public ActionURL getSuccessURL(PeptidePoolForm form) + { + ActionURL url = new ActionURL(DisplayPeptidePoolInformationAction.class, getContainer()); + url.addParameter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID, form.getBean().getPeptide_pool_id()); + return url; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Edit Peptide Pool", peptideURL("editPeptidePool")); + } + } + + @RequiresPermission(ReadPermission.class) + public class ShowAllPeptideGroupsAction extends SimpleViewAction + { + @Override + public ModelAndView getView(PeptideQueryForm form, BindException errors) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance().getTableInfoPeptideGroups(); + PropertyValues pv = this.getPropertyValues(); + form.setTInfo(tableInfo); + List columns = tableInfo.getColumns("peptide_group_name,pathogen_id,seq_ref,clade_id,pep_align_ref_id,group_type_id,createdby,created,modifiedby,modified"); + form.setCInfo(columns); + form.setSort(new Sort(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID)); + form.setMessage("AllPeptideGroups"); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + ActionURL insertUrl = new ActionURL(InsertPeptideGroupAction.class, getContainer()); + ActionButton insert = new ActionButton(insertUrl, "Insert New Group"); + insert.setActionType(ActionButton.Action.LINK); + rgn.getButtonBar(DataRegion.MODE_GRID).add(insert); + DisplayColumn col = rgn.getDisplayColumn(PepDBSchema.COLUMN_PEPTIDE_GROUP_NAME); + ActionURL displayAction = new ActionURL(DisplayPeptideGroupInformationAction.class, getContainer()); + displayAction.addParameter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID,"${" + PepDBSchema.COLUMN_PEPTIDE_GROUP_ID + "}"); + col.setURL(displayAction); + GridView gridView = new GridView(rgn, errors); + gridView.setTitle("All the Peptide Groups in the System are : "); + return gridView; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Display All Peptide Groups", peptideURL("showAllPeptideGroups")); + } + } + + @RequiresPermission(ReadPermission.class) + public class DisplayPeptideGroupInformationAction extends SimpleViewAction + { + @Override + public ModelAndView getView(PeptideAndGroupForm form, BindException errors) throws Exception + { + _log.debug("PeptideAndGroupForm: " + form.toString()); + PeptideGroup pg = PepDBManager.getPeptideGroupByID(Integer.parseInt(form.getPeptide_group_id())); + DataRegion rgn1 = new DataRegion(); + TableInfo tableInfo1 = PepDBSchema.getInstance().getTableInfoPeptideGroups(); + rgn1.setColumns(tableInfo1.getColumns("peptide_group_id,peptide_group_name,pathogen_id,seq_ref,clade_id,pep_align_ref_id,group_type_id,createdby,created,modifiedby,modified")); + ButtonBar buttonBar1 = getButtonBar(); + ActionURL backUrl = new ActionURL(ShowAllPeptideGroupsAction.class, getContainer()); + ActionButton goBack = new ActionButton("List All Groups", backUrl); + buttonBar1.add(goBack); + if (getContainer().hasPermission(getUser(), UpdatePermission.class)) + { + ActionURL updateGroupUrl = new ActionURL(UpdatePeptideGroupAction.class, getContainer()); + updateGroupUrl.addParameter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID, form.getPeptide_group_id()); + ActionButton updateGroupButton = new ActionButton("Update Group Data", updateGroupUrl); + buttonBar1.add(updateGroupButton); + } + rgn1.setButtonBar(buttonBar1, DataRegion.MODE_DETAILS); + DetailsView dataView = new DetailsView(rgn1, form.getPeptide_group_id()); + dataView.setTitle("Group Information from peptide_group table for group : " + pg.getPeptide_group_name()); + VBox vBox = new VBox(); + vBox.addView(dataView); + PropertyValues pv = this.getPropertyValues(); + PeptideQueryForm form2 = new PeptideQueryForm(); + form2.setQueryValue(form.getPeptide_group_id()); + GridView gv = getGridViewByGroup(form2, pv); + vBox.addView(gv); + return vBox; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Display Peptide Group Details", peptideURL("displayPeptideGroupInformation")); + } + } + + @RequiresPermission(ReadPermission.class) + public class ShowAllPeptidePoolsAction extends SimpleViewAction + { + @Override + public ModelAndView getView(PeptideQueryForm form, BindException errors) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance().getTableInfoViewPoolDetails(); + PropertyValues pv = this.getPropertyValues(); + form.setTInfo(tableInfo); + List columns = tableInfo.getColumns("peptide_pool_id,peptide_pool_name,pool_type_desc,parent_pool_id,parent_pool_name,matrix_peptide_pool_id,comment,archived,createdby,created,modifiedby,modified"); + form.setCInfo(columns); + form.setSort(new Sort(PepDBSchema.COLUMN_PEPTIDE_POOL_ID)); + form.setMessage("AllPeptidePools"); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + ActionURL importUrl = new ActionURL(ImportPeptidePoolsAction.class, getContainer()); + ActionButton importB = new ActionButton(importUrl, "Import New Pools"); + importB.setActionType(ActionButton.Action.LINK); + rgn.getButtonBar(DataRegion.MODE_GRID).add(importB); + GridView gridView = new GridView(rgn, errors); + gridView.setTitle("All the Peptide Pools in the System are : "); + return gridView; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Display All Peptide Pools", peptideURL("showAllPeptidePools")); + } + } + + @RequiresPermission(ReadPermission.class) + public class DisplayPeptidePoolInformationAction extends SimpleViewAction + { + @Override + public ModelAndView getView(PeptideAndPoolForm form, BindException errors) throws Exception + { + _log.debug("PeptideAndPoolForm: " + form.toString()); + PeptideQueryForm queryform = new PeptideQueryForm(); + TableInfo tableInfo = PepDBSchema.getInstance().getTableInfoPeptidePools(); + PropertyValues pv = this.getPropertyValues(); + queryform.setTInfo(tableInfo); + queryform.setCInfo(tableInfo.getColumns("peptide_pool_id,peptide_pool_name,pool_type_id,parent_pool_id,matrix_peptide_pool_id,comment,archived,createdby,created,modifiedby,modified")); + DataRegion rgn = getDataRegion(getContainer(), queryform, Table.ALL_ROWS); + rgn.setShowBorders(true); + rgn.setShadeAlternatingRows(true); + ButtonBar buttonBar = getButtonBar(); + ActionURL editUrl = new ActionURL(EditPeptidePoolAction.class, getContainer()); + editUrl.addParameter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID, form.getPeptide_pool_id()); + ActionButton editButton = new ActionButton("Edit Peptide Pool", editUrl); + buttonBar.add(editButton); + rgn.setButtonBar(buttonBar, DataRegion.MODE_DETAILS); + DetailsView dataView = new DetailsView(rgn, form.getPeptide_pool_id()); + dataView.setTitle("Pool Information from peptide_pool table for pool : PP" + form.getPeptide_pool_id()); + queryform.setQueryValue(form.getPeptide_pool_id()); + GridView gv = getGridViewByPool(queryform, pv); + + // Because this page has potentially two data grids, we must give each grid a different + // action url (in order to distinguish the two tables). + gv.getDataRegion().setButtonBar(getGridButtonbarPeptidesInPool(pv)); + VBox box = new VBox(); + box.addView(dataView); + box.addView(gv); + if (PepDBManager.getChildrenPools(form.getPeptide_pool_id()) != null) + { + GridView childPools = getGridViewByParentPool(queryform, pv); + childPools.getDataRegion().setButtonBar(getGridButtonbarPoolsInPool(pv)); + box.addView(childPools); + } + return box; + + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Display Peptide Pool Details", peptideURL("displayPeptidePoolInformation")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class UpdatePeptideGroupAction extends FormViewAction + { + @Override + public ModelAndView getView(PeptideGroupForm form, boolean reshow, BindException errors) throws Exception + { + PeptideGroup pg = PepDBManager.getPeptideGroupByID(form.getBean().getPeptide_group_id()); + UpdateView uView = new UpdateView(form, errors); + ButtonBar bb = new ButtonBar(); + //bb.add(new ActionButton("updatePeptideGroup.post","Save Changes")); + bb.add(new ActionButton(new ActionURL(UpdatePeptideGroupAction.class, getContainer()), "Save Changes")); + ActionURL backURL = new ActionURL(DisplayPeptideGroupInformationAction.class, getContainer()); + backURL.addParameter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID, form.getBean().getPeptide_group_id()); + ActionButton cancelButton = new ActionButton(backURL, "Cancel"); + cancelButton.setActionType(ActionButton.Action.LINK); + bb.add(cancelButton); + uView.getDataRegion().setButtonBar(bb); + if (pg.getPeptide_group_name().equalsIgnoreCase("Optimal Epitopes")) + uView.getDataRegion().getDisplayColumn("peptide_group_name").setVisible(false); + uView.setTitle("Update Peptide Group data for : " + pg.getPeptide_group_name()); + return uView; + } + + @Override + public boolean handlePost(PeptideGroupForm form, BindException errors) throws Exception + { + PeptideGroup bean = form.getBean(); + PeptideGroup dbBean = PepDBManager.getPeptideGroupByID(bean.getPeptide_group_id()); + bean.setCreated(dbBean.getCreated()); + bean.setCreatedBy(dbBean.getCreatedBy()); + PepDBManager.updatePeptideGroup(getUser(), bean); + return true; + } + + @Override + public void validateCommand(PeptideGroupForm form, Errors errors) + { + try + { + form.validate(errors); + form.validateName(errors); + } + catch (SQLException e) + { + errors.reject(null, "There's something wrong with database when trying to get all the existing groups."); + } + } + + @Override + public ActionURL getSuccessURL(PeptideGroupForm form) + { + ActionURL url = new ActionURL(DisplayPeptideGroupInformationAction.class, getContainer()); + url.addParameter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID, form.getBean().getPeptide_group_id()); + return url; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Update Peptide Group", peptideURL("updatePeptideGroup")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class InsertPeptideGroupAction extends FormViewAction + { + @Override + public ModelAndView getView(PeptideGroupForm form, boolean reshow, BindException errors) throws Exception + { + ButtonBar bb = new ButtonBar(); + //bb.add(new ActionButton("insertPeptideGroup.post","Add New Peptide Group")); + bb.add(new ActionButton(new ActionURL(InsertPeptideGroupAction.class, getContainer()), "Add New Peptide Group")); + ActionURL backURL = new ActionURL(BeginAction.class, getContainer()); + ActionButton goBack = new ActionButton(backURL, "Cancel"); + goBack.setActionType(ActionButton.Action.LINK); + bb.add(goBack); + PeptideQueryForm qForm = new PeptideQueryForm(); + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPeptideGroups(); + qForm.setTInfo(tInfo); + qForm.setCInfo(tInfo.getColumns()); + DataRegion rgn = getDataRegion(getContainer(), qForm, Table.ALL_ROWS); + rgn.setButtonBar(bb); + InsertView iView = new InsertView(rgn, form, errors); + return iView; + } + + @Override + public boolean handlePost(PeptideGroupForm form, BindException errors) throws Exception + { + PeptideGroup group = form.getBean(); + group = PepDBManager.insertGroup(getContainer(), getUser(), group); + group.setContainerId(getContainer().getId()); + form.setBean(group); + return true; + } + + @Override + public void validateCommand(PeptideGroupForm form, Errors errors) + { + try + { + form.validate(errors); + form.validateName(errors); + } + catch (SQLException e) + { + errors.reject(null, "There's something wrong with database when trying to get all the existing groups."); + } + } + + @Override + public ActionURL getSuccessURL(PeptideGroupForm form) + { + ActionURL url = new ActionURL(DisplayPeptideGroupInformationAction.class, getContainer()); + url.addParameter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID, form.getBean().getPeptide_group_id().toString()); + return url; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Insert Peptide Group", peptideURL("insertPeptideGroup")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class ImportPeptidesAction extends FormViewAction + { + private List resultPeptides = new LinkedList(); + + @Override + public ModelAndView getView(FileForm form, boolean reshow, BindException errors) throws Exception + { + JspView v = new JspView(PAGE_IMPORT_PEPTIDES, form, errors); + return v; + } + + @Override + public boolean handlePost(FileForm form, BindException errors) throws Exception + { + try + { + List importFiles = getAttachmentFileList(); + AttachmentFile importFile = null; + for (AttachmentFile a : importFiles) + { + if (a != null && a.getSize() != 0) + importFile = a; + } + if (!form.validate(errors, importFile)) + return false; + if (isPost() && form.getActionType().equalsIgnoreCase(("PEPTIDES"))) + { + PeptideImporter importer = new PeptideImporter(); + if (!importer.process(getViewContext().getUser(), importFile, errors, resultPeptides)) + return false; + return true; + } + } + catch (Exception e) + { + e.printStackTrace(); + _log.error(e.getMessage(), e); + errors.reject(null, "There was a problem uploading File: " + e.getMessage()); + return false; + } + return true; + } + + @Override + public void validateCommand(FileForm form, Errors errors) + { + + } + + @Override + public ActionURL getSuccessURL(FileForm form) + { + ActionURL url = new ActionURL(DisplayResultAction.class, getContainer()); + url.addParameter("message", "The file has been successfully imported."); + return url; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Import Peptides", peptideURL("importPeptides")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class DisplayResultAction extends SimpleViewAction + { + @Override + public ModelAndView getView(FileForm form, BindException errors) throws Exception + { + PeptideQueryForm form1 = new PeptideQueryForm(); + PropertyValues pv = this.getPropertyValues(); + GridView v = getGridViewByLastImport(form1, pv); + return v; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Display Results Page", peptideURL("displayResult")); + } + } + + @RequiresPermission(UpdatePermission.class) + public class ImportPeptidePoolsAction extends FormViewAction + { + ActionURL url = null; + + @Override + public ModelAndView getView(FileForm form, boolean reshow, BindException errors) throws Exception + { + JspView v = new JspView("/org/scharp/atlas/pepdb/view/importPools.jsp", form, errors); + return v; + } + + @Override + public boolean handlePost(FileForm form, BindException errors) throws Exception + { + try + { + List importFiles = getAttachmentFileList(); + AttachmentFile importFile = null; + for (AttachmentFile a : importFiles) + { + if (a != null && a.getSize() != 0) + importFile = a; + } + if (!form.validate(errors, importFile)) + return false; + + PoolImporter importer = new PoolImporter(); + if (!importer.process(getViewContext().getUser(), form, importFile, errors)) + return false; + url = new ActionURL(BeginAction.class, getContainer()); + return true; + } + catch (Exception e) + { + e.printStackTrace(); + _log.error(e.getMessage(), e); + errors.reject(null, "There was a problem uploading File: " + e.getMessage()); + return false; + } + } + + @Override + public void validateCommand(FileForm form, Errors errors) + { + + } + + @Override + public ActionURL getSuccessURL(FileForm form) + { + ActionURL url = new ActionURL(ImportPeptidePoolsAction.class, getContainer()); + url.addParameter("message", "The file has been successfully imported."); + return url; + } + + @Override + public void addNavTrail(NavTree root) + { + root.addChild("Import Peptide Pools", peptideURL("importPeptidePools")); + } + } + + + @RequiresPermission(ReadPermission.class) + public abstract class PeptideExcelExportAction extends ExportAction + { + public void printExcel(Object bean, HttpServletResponse response, BindException errors, PeptideQueryForm form) throws Exception + { + try + { + RenderContext context = new RenderContext(getViewContext()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + context.setBaseFilter(form.getFilter()); + context.setBaseSort(form.getSort()); + ExcelWriter ew = new ExcelWriter(()->rgn.getResults(context), rgn.getDisplayColumns()); + ew.setAutoSize(true); + ew.setFilenamePrefix(form.getMessage()); + ew.setSheetName(form.getMessage()); + ew.setFooter(form.getMessage()); + ew.renderWorkbook(getResponse()); + } + catch (SQLException e) + { + _log.error("export: " + e); + } + catch (IOException e) + { + _log.error("export: " + e); + } + catch (Exception e) + { + _log.error("export: " + e); + } + } + } + + @RequiresPermission(ReadPermission.class) + public class PeptidesInPoolExcelExportAction extends PeptideExcelExportAction + { + @Override + public void export(Object bean, HttpServletResponse response, BindException errors) throws Exception + { + PeptideQueryForm form = new PeptideQueryForm(); + PropertyValues pv = this.getPropertyValues(); + form.setQueryValue((String)pv.getPropertyValue("peptide_pool_id").getValue()); + getGridViewByPool(form, pv); + printExcel(bean, response, errors, form); + } + } + + @RequiresPermission(ReadPermission.class) + public class PoolsInPoolExcelExportAction extends PeptideExcelExportAction + { + @Override + public void export(Object bean, HttpServletResponse response, BindException errors) throws Exception + { + PeptideQueryForm form = new PeptideQueryForm(); + PropertyValues pv = this.getPropertyValues(); + form.setQueryValue((String)pv.getPropertyValue("peptide_pool_id").getValue()); + getGridViewByParentPool(form, pv); + printExcel(bean, response, errors, form); + } + } + + @RequiresPermission(ReadPermission.class) + public class PeptideDefaultExcelExportAction extends PeptideExcelExportAction + { + @Override + public void export(Object bean, HttpServletResponse response, BindException errors) throws Exception + { + ViewContext ctx = getViewContext(); + HttpSession session = ctx.getRequest().getSession(); + PeptideQueryForm form = (PeptideQueryForm) session.getAttribute("PEPTIDE_QUERY_FORM"); + _log.error("Form " + form.getMessage() + " had filter : " + form.getFilter()); + printExcel(bean, response, errors, form); + } + } + + + + @RequiresPermission(ReadPermission.class) + public abstract class PeptideTextExportAction extends ExportAction + { + public void printText(Object bean, HttpServletResponse response, BindException errors, PeptideQueryForm form) throws Exception + { + try + { + RenderContext context = new RenderContext(getViewContext()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + context.setBaseFilter(form.getFilter()); + context.setBaseSort(form.getSort()); + + try (TSVGridWriter tsv = new TSVGridWriter(()->rgn.getResults(context), rgn.getDisplayColumns())) + { + tsv.setFilenamePrefix(form.getMessage()); + tsv.write(getResponse()); + } + } + catch (Exception e) + { + _log.error("export: " + e); + } + } + } + + @RequiresPermission(ReadPermission.class) + public class PeptidesInPoolTextExportAction extends PeptideTextExportAction + { + @Override + public void export(Object bean, HttpServletResponse response, BindException errors) throws Exception + { + PeptideQueryForm form = new PeptideQueryForm(); + PropertyValues pv = this.getPropertyValues(); + form.setQueryValue((String)pv.getPropertyValue("peptide_pool_id").getValue()); + getGridViewByPool(form, pv); + printText(bean, response, errors, form); + } + } + + @RequiresPermission(ReadPermission.class) + public class PoolsInPoolTextExportAction extends PeptideTextExportAction + { + @Override + public void export(Object bean, HttpServletResponse response, BindException errors) throws Exception + { + PeptideQueryForm form = new PeptideQueryForm(); + PropertyValues pv = this.getPropertyValues(); + form.setQueryValue((String)pv.getPropertyValue("peptide_pool_id").getValue()); + getGridViewByParentPool(form, pv); + printText(bean, response, errors, form); + } + } + + @RequiresPermission(ReadPermission.class) + public class PeptideDefaultTextExportAction extends PeptideTextExportAction + { + @Override + public void export(Object bean, HttpServletResponse response, BindException errors) throws Exception + { + ViewContext ctx = getViewContext(); + HttpSession session = ctx.getRequest().getSession(); + PeptideQueryForm form = (PeptideQueryForm) session.getAttribute("PEPTIDE_QUERY_FORM"); + printText(bean, response, errors, form); + } + } + + + + protected GridView getGridViewByLastImport(PeptideQueryForm form, PropertyValues pv) throws Exception + { + //PeptideGroup pg = PepDBManager.getPeptideGroupByID(Integer.parseInt(form.getQueryValue())); + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewGroupPeptides(); + form.setTInfo(tableInfo); + //_log.debug("Creating a Filter for peptideGroup." + PepDBSchema.COLUMN_PEPTIDE_GROUP_ID + ": " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_IN_CURRENT_FILE, true); + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_GROUP_ASSIGNMENT_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,peptide_group_name,peptide_id_in_group,pathogen_id," + + "sequence_length,amino_acid_start_pos,amino_acid_end_pos,child,parent,optimal_epitope_list_id,hla_restriction,frequency_number,frequency_number_date")); + + form.setSort(sort); + form.setMessage("Peptides_IN_Last_File"); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + return gridView; + } + + protected GridView getGridViewByGroup(PeptideQueryForm form, PropertyValues pv) throws Exception + { + PeptideGroup pg = PepDBManager.getPeptideGroupByID(Integer.parseInt(form.getQueryValue())); + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewGroupPeptides(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for peptideGroup." + PepDBSchema.COLUMN_PEPTIDE_GROUP_ID + ": " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID, Integer.parseInt(form.getQueryValue())); + if (form.getLabId() != null) + sFilter.addCondition(PepDBSchema.COLUMN_PEPTIDE_ID_IN_GROUP, form.getLabId()); + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_ID_IN_GROUP); + form.setFilter(sFilter); + if (pg.getPeptide_group_name().equalsIgnoreCase("Optimal Epitopes")) + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,peptide_group_name,peptide_id_in_group,pathogen_id," + + "sequence_length,amino_acid_start_pos,amino_acid_end_pos,child,parent,peptide_flag,peptide_notes,optimal_epitope_list_id,hla_restriction,frequency_number,frequency_number_date")); + else + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,peptide_group_name,peptide_id_in_group,pathogen_id," + + "sequence_length,amino_acid_start_pos,amino_acid_end_pos,child,parent,peptide_flag,peptide_notes,frequency_number,frequency_number_date")); + form.setSort(sort); + form.setMessage("Peptides_IN_Group_" + pg.getPeptide_group_name()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "There are (" + + PepDBManager.getCount(Integer.parseInt(form.getQueryValue())) + + ") peptides in the '" + pg.getPeptide_group_name() + "' peptide group."); + return gridView; + } + + protected GridView getGridViewByPool(PeptideQueryForm form, PropertyValues pv) throws Exception + { + PeptidePool pp = PepDBManager.getPeptidePoolByID(Integer.parseInt(form.getQueryValue())); + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewPoolPeptides(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for peptidePool." + PepDBSchema.COLUMN_PEPTIDE_POOL_ID + ": " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID, Integer.parseInt(form.getQueryValue())); + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,peptide_pool_id,peptide_pool_name,pool_type_id," + + "peptide_group_id,peptide_id_in_group,sequence_length,amino_acid_start_pos,amino_acid_end_pos,child,parent,peptide_flag,peptide_notes")); + form.setSort(sort); + form.setMessage("Peptides_IN_Pool_PP" + pp.getPeptide_pool_name()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + ButtonBar bb = getGridButtonbar(pv); + rgn.setButtonBar(bb, DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "The Peptides in the pool " + pp.getPeptide_pool_name() + "(PP" + form.getQueryValue() + ") are : "); + return gridView; + } + + protected GridView getGridViewByParentPool(PeptideQueryForm form, PropertyValues pv) throws Exception + { + PeptidePool pp = PepDBManager.getPeptidePoolByID(Integer.parseInt(form.getQueryValue())); + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewPoolDetails(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for parent peptidePool." + PepDBSchema.COLUMN_PARENT_POOL_ID + ": " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PARENT_POOL_ID, Integer.parseInt(form.getQueryValue())); + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_POOL_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("peptide_pool_id,peptide_pool_name,pool_type_desc,parent_pool_id,parent_pool_name,matrix_peptide_pool_id,comment,archived,createdby,created,modifiedby,modified")); + form.setSort(sort); + form.setMessage("Peptides_WITH_Parent_Pool_PP" + form.getQueryValue()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "The Sub-Pools of Parent Pool " + pp.getPeptide_pool_name() + "(PP" + form.getQueryValue() + ") are : "); + return gridView; + } + + protected GridView getGridViewBySequence(PeptideQueryForm form, PropertyValues pv) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewGroupPeptides(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for peptideSequence." + PepDBSchema.COLUMN_PEPTIDE_SEQUENCE + ": " + form); + SimpleFilter sFilter = new SimpleFilter(); + + boolean sequenceIsEmpty = true; + String sequence = form.getQueryValue(); + if((sequence != null) && (!sequence.trim().isEmpty())){ + sequenceIsEmpty = false; + } + if(!sequenceIsEmpty) + { + sequence = sequence.trim().toUpperCase(); + sFilter.addWhereClause(PepDBSchema.COLUMN_PEPTIDE_SEQUENCE + " LIKE ?", new Object[]{"%" + sequence + "%"}, + FieldKey.fromString(PepDBSchema.COLUMN_PEPTIDE_SEQUENCE)); + form.setFilter(sFilter); + } + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_ID); + + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,peptide_group_name,peptide_id_in_group,pathogen_id," + + "sequence_length,amino_acid_start_pos,amino_acid_end_pos,child,parent,peptide_flag,peptide_notes,optimal_epitope_list_id,hla_restriction")); + form.setSort(sort); + if(!sequenceIsEmpty) + { + form.setMessage("Peptides_WITH_Sequence_" + sequence); + } + else + { + form.setMessage("All_Peptides_In_DB"); + } + DataRegion rgn = getDataRegion(getContainer(), form, MAX_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setSort(sort); + if(!sequenceIsEmpty) { + gridView.setFilter(sFilter); + gridView.setTitle( + "The Peptides Containing the Sequence string '" + sequence + "' are : "); + } + else + { + gridView.setTitle("All the Peptides in Peptide DB : "); + } + return gridView; + } + + protected GridView getGridViewByProtein(PeptideQueryForm form, PropertyValues pv) throws Exception + { + ProteinCategory pc = PepDBManager.getProCatByID(Integer.parseInt(form.getQueryValue())); + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewGroupPeptides(); + form.setTInfo(tableInfo); + String title = "Peptides in Protein Category " + pc.getProtein_cat_desc(); + _log.debug("Creating a Filter for proteinCategory." + PepDBSchema.COLUMN_PROTEIN_CAT_ID + ": " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PROTEIN_CAT_ID, Integer.parseInt(form.getQueryValue())); + if (form.getAAEnd() == null && form.getAAStart() != null) + { + sFilter.addCondition(PepDBSchema.COLUMN_AMINO_ACID_START_POS, Integer.parseInt(form.getAAStart()), CompareType.GTE); + title = "Peptides in Protein Category " + pc.getProtein_cat_desc() + " and after AAStart " + form.getAAStart(); + } + if (form.getAAEnd() != null && form.getAAStart() == null) + { + sFilter.addCondition(PepDBSchema.COLUMN_AMINO_ACID_END_POS, Integer.parseInt(form.getAAEnd()), CompareType.LTE); + title = "Peptides in Protein Category " + pc.getProtein_cat_desc() + " and before AAEnd " + form.getAAEnd(); + } + if (form.getAAStart() != null && form.getAAEnd() != null) + { + sFilter.addBetween(tableInfo.getColumn(PepDBSchema.COLUMN_AMINO_ACID_START_POS).getFieldKey(), Integer.parseInt(form.getAAStart()), Integer.parseInt(form.getAAEnd())); + sFilter.addBetween(tableInfo.getColumn(PepDBSchema.COLUMN_AMINO_ACID_END_POS).getFieldKey(), Integer.parseInt(form.getAAStart()), Integer.parseInt(form.getAAEnd())); + title = "Peptides in Protein Category " + pc.getProtein_cat_desc() + " and between AAStart " + form.getAAStart() + " and AAEnd " + form.getAAEnd(); + } + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,peptide_group_name,peptide_id_in_group,pathogen_id," + + "sequence_length,amino_acid_start_pos,amino_acid_end_pos,child,parent,peptide_flag,peptide_notes,optimal_epitope_list_id,hla_restriction")); + form.setSort(sort); + form.setMessage("Peptides_IN_Protein_" + form.getQueryValue()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle(title); + return gridView; + } + + protected GridView getGridViewByParentId(PeptideQueryForm form, PropertyValues pv) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewParentChildDetails(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for parentID. : " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PARENT_ID, Integer.parseInt(form.getQueryValue())); + Sort sort = new Sort(PepDBSchema.COLUMN_CHILD_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("child_id,child_sequence,child_protein,child_group,child_lab_id,child_seq_length," + + "child_aastart,child_aaend,child_peptide_flag,child_peptide_notes,child_optimal_epitope_list_id,child_hla_restriction")); + form.setSort(sort); + form.setMessage("CHILD_Peptides_WITH_Parent_P" + form.getQueryValue()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "The Child Peptides of Parent peptide ID P" + form.getQueryValue() + " are : "); + return gridView; + } + + protected GridView getGridViewByParent(PeptideQueryForm form, PropertyValues pv) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewParentChildDetails(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for parentSequence. : " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PARENT_SEQUENCE, form.getQueryValue().trim().toUpperCase()); + Sort sort = new Sort(PepDBSchema.COLUMN_CHILD_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("parent_id,child_id,child_sequence,child_protein,child_group,child_lab_id,child_seq_length," + + "child_aastart,child_aaend,child_peptide_flag,child_peptide_notes,child_optimal_epitope_list_id,child_hla_restriction")); + form.setSort(sort); + form.setMessage("CHILD_Peptides_WITH_Parent_Sequence_" + form.getQueryValue()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "The Child Peptides of Parent Sequence " + form.getQueryValue() + " are : "); + return gridView; + } + + protected GridView getGridViewByChildId(PeptideQueryForm form, PropertyValues pv) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewParentChildDetails(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for childID. : " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_CHILD_ID, Integer.parseInt(form.getQueryValue())); + Sort sort = new Sort(PepDBSchema.COLUMN_PARENT_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("parent_id,parent_sequence,parent_protein,parent_group,parent_lab_id," + + "parent_seq_length,parent_aastart,parent_aaend,parent_peptide_flag,parent_peptide_notes")); + form.setSort(sort); + form.setMessage("PARENT_Peptides_WITH_Child_P" + form.getQueryValue()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "The Parent Peptides of Child peptide ID P" + form.getQueryValue() + " are : "); + return gridView; + } + + protected GridView getGridViewByChild(PeptideQueryForm form, PropertyValues pv) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance() + .getTableInfoViewParentChildDetails(); + form.setTInfo(tableInfo); + _log.debug("Creating a Filter for childID. : " + form); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_CHILD_SEQUENCE, form.getQueryValue().trim().toUpperCase()); + Sort sort = new Sort(PepDBSchema.COLUMN_PARENT_ID); + form.setFilter(sFilter); + form.setCInfo(tableInfo.getColumns("child_id,parent_id,parent_sequence,parent_protein,parent_group,parent_lab_id," + + "parent_seq_length,parent_aastart,parent_aaend,parent_peptide_flag,parent_peptide_notes")); + form.setSort(sort); + form.setMessage("PARENT_Peptides_WITH_Child_Sequence_" + form.getQueryValue()); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setButtonBar(getGridButtonbar(pv), DataRegion.MODE_GRID); + GridView gridView = new GridView(rgn, (BindException) null); + gridView.setFilter(sFilter); + gridView.setSort(sort); + gridView.setTitle( + "The Parent Peptides of Child Sequence " + form.getQueryValue() + " are : "); + return gridView; + } + + protected DetailsView getPeptideDetailsView(PeptideQueryForm form, Peptides p) throws Exception + { + TableInfo tableInfo = PepDBSchema.getInstance().getTableInfoPeptides(); + form.setTInfo(tableInfo); + form.setCInfo(tableInfo.getColumns("peptide_id,peptide_sequence,protein_cat_id,sequence_length,amino_acid_start_pos," + + "amino_acid_end_pos,child,parent,optimal_epitope_list_id,hla_restriction,storage_location,src_file_name,peptide_flag,peptide_notes,createdby,created,modifiedby,modified")); + DataRegion rgn = getDataRegion(getContainer(), form, Table.ALL_ROWS); + rgn.setShowBorders(true); + rgn.setShadeAlternatingRows(true); + ButtonBar buttonBar = new ButtonBar(); + ActionURL homeUrl = new ActionURL(BeginAction.class, getContainer()); + ActionButton homeButton = new ActionButton("Peptide Home", homeUrl); + buttonBar.add(homeButton); + ActionURL editUrl = new ActionURL(EditPeptideAction.class, getContainer()); + editUrl.addParameter(PepDBSchema.COLUMN_PEPTIDE_ID, p.getPeptide_id()); + ActionButton editButton = new ActionButton("Edit Peptide", editUrl); + buttonBar.add(editButton); + rgn.setButtonBar(buttonBar, DataRegion.MODE_DETAILS); + DetailsView dataView = new DetailsView(rgn, p.getPeptide_id()); + dataView.setTitle("Peptide Detail Information from peptides table for peptide : P" + p.getPeptide_id()); + return dataView; + } + + private DataRegion getDataRegion(Container c, PeptideQueryForm form, int maxRows) throws Exception + { + DataRegion rgn = new DataRegion(); + List columnList = new ArrayList(); + List displayColumnList = new ArrayList(); + + for (ColumnInfo col : form.getCInfo()) + { + if (col != null) + { + columnList.add(col.getName()); + DisplayColumn dc; + + if (PepDBSchema.COLUMN_PEPTIDE_ID.equals(col.getName()) || PepDBSchema.COLUMN_PARENT_ID.equals(col.getName()) || PepDBSchema.COLUMN_CHILD_ID.equals(col.getName())) + { + dc = new DCpeptideId(col); + } + else if (PepDBSchema.COLUMN_PEPTIDE_POOL_ID.equals(col.getName())) + { + dc = new DCpeptidePoolId(col); + } + else if (PepDBSchema.COLUMN_PARENT_POOL_ID.equals(col.getName())) + { + dc = new DCparentPoolId(col); + } + else { + dc = col.getRenderer(); + } + displayColumnList.add(dc); + } + } + rgn.setColumns(form.getCInfo()); + rgn.setDisplayColumns(displayColumnList); + rgn.setShowBorders(true); + rgn.setShadeAlternatingRows(true); + rgn.setMaxRows(maxRows); + ViewContext ctx = getViewContext(); + HttpSession session = ctx.getRequest().getSession(true); + session.setAttribute("PEPTIDE_QUERY_FORM", form); + + + if (columnList.contains(PepDBSchema.COLUMN_PEPTIDE_ID)) + { + ColumnInfo ci = rgn.getTable().getColumn("peptide_id"); + QuerySettings qs = new QuerySettings(getViewContext(), rgn.getName()); + qs.addAggregates(new Aggregate(ci, Aggregate.BaseType.COUNT)); + qs.setMaxRows(Table.ALL_ROWS); + rgn.setSettings(qs); + // We want MOST of the query settings into our dataregion settings, but we still want to paginate the rows. + rgn.setMaxRows(maxRows); + + } + return rgn; + } + + private ButtonBar getButtonBar() + { + ButtonBar buttonBar = new ButtonBar(); + ActionURL homeUrl = new ActionURL(BeginAction.class, getContainer()); + ActionButton homeButton = new ActionButton("Peptide Home", homeUrl); + buttonBar.add(homeButton); + ActionURL searchURL = new ActionURL(SearchForPeptidesAction.class, getContainer()); + ActionButton searchButton = new ActionButton(searchURL, "Peptide Search Page"); + buttonBar.add(searchButton); + return buttonBar; + } + + /* + * Returns a ButtonBar whose excel and text buttons will + * render whatever grid view is set in the user's Session. + */ + private ButtonBar getGridButtonbar(PropertyValues pv) + { + return getGridButtonbarForClasses(pv, PeptideDefaultExcelExportAction.class,PeptideDefaultTextExportAction.class); + } + + /* + * Returns a ButtonBar whose excel and text buttons explicitly point to an + * action that will generate the Peptide Pools in Pool report. Use when + * multiple grids exist on the same view. + */ + private ButtonBar getGridButtonbarPoolsInPool(PropertyValues pv) + { + return getGridButtonbarForClasses(pv,PoolsInPoolExcelExportAction.class,PoolsInPoolTextExportAction.class); + } + + /* + * Returns a ButtonBar whose excel and text buttons explicitly point to an + * action that will generate the Peptides in Pool report. Use when + * multiple grids exist on the same view. + */ + private ButtonBar getGridButtonbarPeptidesInPool(PropertyValues pv) + { + return getGridButtonbarForClasses(pv,PeptidesInPoolExcelExportAction.class,PeptidesInPoolTextExportAction.class); + } + + private ButtonBar getGridButtonbarForClasses(PropertyValues pv, Class excelActionClass, Class textActionClass) + { + ButtonBar gridButtonBar = getButtonBar(); + //ActionURL exportUrl = new ActionURL(PeptideDefaultExcelExportAction.class, getContainer()); + ActionURL exportUrl = new ActionURL(excelActionClass, getContainer()); + exportUrl.setPropertyValues(pv); + ActionButton export = new ActionButton(exportUrl, "Export to Excel"); + export.setActionType(ActionButton.Action.LINK); + gridButtonBar.add(export); + + ActionURL exportTextURL = new ActionURL(textActionClass, getContainer()); + exportTextURL.setPropertyValues(pv); + ActionButton exportToText = new ActionButton(exportTextURL, "Export All To Text"); + exportToText.setActionType(ActionButton.Action.LINK); + gridButtonBar.add(exportToText); + + return gridButtonBar; + //rgn.setButtonBar(gridButtonBar, DataRegion.MODE_GRID); + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/PepDBManager.java b/pepdb/src/org/scharp/atlas/pepdb/PepDBManager.java new file mode 100644 index 00000000..251e17aa --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PepDBManager.java @@ -0,0 +1,387 @@ +package org.scharp.atlas.pepdb; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.labkey.api.data.Container; +import org.labkey.api.data.SQLFragment; +import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; +import org.labkey.api.data.SqlExecutor; +import org.labkey.api.data.SqlSelector; +import org.labkey.api.data.Table; +import org.labkey.api.data.TableInfo; +import org.labkey.api.data.TableSelector; +import org.labkey.api.query.FieldKey; +import org.labkey.api.security.User; +import org.scharp.atlas.pepdb.model.OptimalEpitopeList; +import org.scharp.atlas.pepdb.model.Parent; +import org.scharp.atlas.pepdb.model.PeptideGroup; +import org.scharp.atlas.pepdb.model.PeptidePool; +import org.scharp.atlas.pepdb.model.PeptidePoolAssignment; +import org.scharp.atlas.pepdb.model.Peptides; +import org.scharp.atlas.pepdb.model.PoolType; +import org.scharp.atlas.pepdb.model.ProteinCategory; +import org.scharp.atlas.pepdb.model.Source; + +import java.sql.SQLException; +import java.util.HashMap; + +/** + * Handles Data Operations. + * + * @version $Id: PeptideManager.java 34530 2009-08-10 20:06:30Z sravani $ + */ +public class PepDBManager +{ + + private static Logger log = LogManager.getLogger(PepDBManager.class); + private static PepDBSchema schema = PepDBSchema.getInstance(); + /** + * Static class + */ + private PepDBManager() + { + } + + public static PeptideGroup[] getPeptideGroups() + { + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID); + return new TableSelector(schema.getTableInfoPeptideGroups(), null, sort).getArray(PeptideGroup.class); + } + + public static PeptidePool[] getPeptidePools() + { + Sort sort = new Sort(PepDBSchema.COLUMN_PEPTIDE_POOL_ID); + return new TableSelector(schema.getTableInfoPeptidePools(), null, sort).getArray(PeptidePool.class); + } + + public static PoolType[] getPoolTypes() + { + Sort sort = new Sort(PepDBSchema.COLUMN_POOL_TYPE_ID); + return new TableSelector(schema.getTableInfoPoolType(), null, sort).getArray(PoolType.class); + } + + public static ProteinCategory[] getProteinCategory() + { + return new TableSelector(schema.getTableInfoProteinCat(), null, new Sort(PepDBSchema.COLUMN_PROTEIN_CAT_ID)).getArray(ProteinCategory.class); + } + + public static OptimalEpitopeList[] getOptimalEpitopeList() + { + return new TableSelector(schema.getTableInfoOptimalEpitopeList(), null, new Sort(PepDBSchema.COLUMN_OPTIMAL_EPITOPE_LIST_ID)).getArray(OptimalEpitopeList.class); + } + + public static Peptides[] getPeptides() + { + TableInfo tInfo = schema.getTableInfoPeptides(); + return new TableSelector(tInfo, null, new Sort("peptide_id")).getArray(Peptides.class); + } + + /** + * @param peptideGroup + * @return the number of peptides in a given group + */ + public static Integer getCount(Integer peptideGroup) + { + SimpleFilter containerFilter = new SimpleFilter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID, peptideGroup); + + return (int)new TableSelector(PepDBSchema.getInstance().getTableInfoViewGroupPeptides(), new SimpleFilter("peptide_group_id", peptideGroup), null).getRowCount(); + } + + public static Peptides insertPeptide(User user, Peptides p) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPeptides(); + Peptides dbPeptide = peptideExists(p, tInfo); + if(dbPeptide == null) + dbPeptide = Table.insert(user,tInfo,p); + return dbPeptide; + } + + public static Peptides updatePeptide(User user, Peptides p) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPeptides(); + return Table.update(user, tInfo, p, p.getPeptide_id()); + } + + public static PeptidePool updatePeptidePool(User user, PeptidePool p) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPeptidePools(); + return Table.update(user,tInfo,p,p.getPeptide_pool_id()); + } + + public static Parent insertParent(User user,Parent parent) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoParent(); + return Table.insert(user,tInfo,parent); + } + + public static Parent parentExists(Parent p) + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoParent(); + Parent dbParent = null; + SimpleFilter sFilter = new SimpleFilter(FieldKey.fromParts("peptide_id"), p.getPeptide_id()); + sFilter.addCondition(FieldKey.fromParts("linked_parent"), p.getLinked_parent()); + Parent[] dbParents = new TableSelector(tInfo, tInfo.getColumns("peptide_id,linked_parent"), sFilter, null).getArray(Parent.class); + if (dbParents.length > 0) + dbParent = dbParents[0]; + return dbParent; + } + + public static Peptides peptideExists(Peptides p, TableInfo tInfo) + { + Peptides dbPeptide = null; + SimpleFilter sFilter = new SimpleFilter(FieldKey.fromParts("peptide_sequence"), p.getPeptide_sequence()); + Peptides[] dbPeptides = new TableSelector(tInfo, sFilter, null).getArray(Peptides.class); + if(dbPeptides.length > 0) + dbPeptide = dbPeptides[0]; + return dbPeptide; + } + + public static Source insertSource(User user, Source src) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoSource(); + SimpleFilter sFilter = new SimpleFilter(FieldKey.fromParts("peptide_group_id"), src.getPeptide_group_id()); + sFilter.addCondition(FieldKey.fromParts("peptide_id"), src.getPeptide_id()); + Source dbSrc ; + Source[] dbSrcs = new TableSelector(tInfo, sFilter, null).getArray(Source.class); + if(dbSrcs.length > 0) + dbSrc = dbSrcs[0]; + else + dbSrc = Table.insert(user,tInfo,src); + dbSrc.setIn_current_file(true); + java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis()); + String sql = "UPDATE pepdb.peptide_group_assignment SET in_current_file = true,modified = ?,modifiedby = ? WHERE peptide_group_assignment_id=?"; + Object[] params = { date,user.getUserId(),dbSrc.getPeptide_group_assignment_id() }; + new SqlExecutor(schema.getSchema()).execute(sql, params); + return dbSrc; + } + + public static PeptidePool insertPeptidePool(User u,PeptidePool pPool) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPeptidePools(); + return Table.insert(u,tInfo,pPool); + } + + public static PeptidePoolAssignment insertPeptidesInPool(User user,PeptidePoolAssignment src) throws Exception + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPoolAssignment(); + SimpleFilter sFilter = new SimpleFilter(FieldKey.fromParts("peptide_pool_id"), src.getPeptide_pool_id()); + sFilter.addCondition(FieldKey.fromParts("peptide_id"), src.getPeptide_id()); + PeptidePoolAssignment dbSrc ; + PeptidePoolAssignment[] dbSrcs = new TableSelector(tInfo, sFilter, null).getArray(PeptidePoolAssignment.class); + if(dbSrcs.length > 0) + return null; + else + dbSrc = Table.insert(user,tInfo,src); + return dbSrc; + } + + public static Source[] getSourcesForPeptide(String peptideId) + { + Source[] sources = null; + try + { + SimpleFilter sfilter = new SimpleFilter(FieldKey.fromParts("peptide_id"), Integer.parseInt(peptideId)); + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoViewGroupPeptides(); + sources = new TableSelector(tInfo, tInfo.getColumns("peptide_group_id,peptide_id_in_group,peptide_group_name,frequency_number,frequency_number_date"), sfilter, null).getArray(Source.class); + if (sources.length < 1) + return null; + } + catch (NumberFormatException e) + { + log.error(e.getMessage(), e); + } + return sources; + } + + public static PeptidePool[] getPoolsForPeptide(String peptideId) + { + SimpleFilter sfilter = new SimpleFilter(FieldKey.fromParts("peptide_id"), Integer.parseInt(peptideId)); + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoViewPoolPeptides(); + PeptidePool[] pools = new TableSelector(tInfo, sfilter, null).getArray(PeptidePool.class); + if (pools.length < 1) + return null; + return pools; + } + + public static PeptideGroup insertGroup(Container c, User user, PeptideGroup pg) throws SQLException + { + PeptideGroup resultGroup = Table.insert(user, PepDBSchema.getInstance().getTableInfoPeptideGroups(), pg); + return resultGroup; + } + + public static PeptideGroup updatePeptideGroup(User user,PeptideGroup pg) throws SQLException + { + return Table.update(user, PepDBSchema.getInstance().getTableInfoPeptideGroups(),pg,pg.getPeptide_group_id()); + } + + public static HashMap getPeptideSequenceMap() + { + HashMap peptideSequenceMap = new HashMap<>(); + Peptides[] peptides = getPeptides(); + for(Peptides peptide : peptides) + peptideSequenceMap.put(peptide.getPeptide_sequence().trim().toUpperCase(), peptide); + return peptideSequenceMap; + } + + public static HashMap getPeptideGroupMap() + { + HashMap groupsMap = new HashMap<>(); + PeptideGroup[] peptideGroups = getPeptideGroups(); + for(PeptideGroup pGroup:peptideGroups) + groupsMap.put(pGroup.getPeptide_group_name().trim().toUpperCase(), pGroup); + return groupsMap; + } + + public static HashMap getPeptidePoolMap() + { + HashMap poolsMap = new HashMap<>(); + PeptidePool[] peptidePools = getPeptidePools(); + for(PeptidePool pPool:peptidePools) + poolsMap.put(pPool.getPeptide_pool_name().trim().toUpperCase(), pPool); + return poolsMap; + } + + public static HashMap getPoolTypeMap() + { + HashMap poolTypeMap = new HashMap<>(); + PoolType[] poolTypes = getPoolTypes(); + for(PoolType pType : poolTypes) + poolTypeMap.put(pType.getPool_type_desc().trim().toUpperCase(), pType); + return poolTypeMap; + } + + public static HashMap getProteinCatMap() + { + HashMap proCatMap = new HashMap<>(); + ProteinCategory[] proCats = getProteinCategory(); + for(ProteinCategory proCat : proCats) + proCatMap.put(proCat.getProtein_cat_desc().trim().toUpperCase(), proCat); + return proCatMap; + } + + public static HashMap getProteinCatIDMap() + { + HashMap proCatMap = new HashMap<>(); + ProteinCategory[] proCats = getProteinCategory(); + for(ProteinCategory proCat : proCats) + proCatMap.put(proCat.getProtein_cat_id(), proCat); + return proCatMap; + } + + public static HashMap getOptimalEpitopeListMap() + { + HashMap optListMap = new HashMap<>(); + OptimalEpitopeList[] optLists = getOptimalEpitopeList(); + for(OptimalEpitopeList optList : optLists) + optListMap.put(optList.getOptimal_epitope_list_desc().trim().toUpperCase(), optList); + return optListMap; + } + + public static Peptides getPeptideById(Integer peptideId) + { + TableInfo tInfo = schema.getTableInfoPeptides(); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PEPTIDE_ID, peptideId); + return new TableSelector(tInfo, sFilter, null).getObject(Peptides.class); + } + + public static Peptides[] getParentPeptides(Peptides p) throws SQLException + { + TableInfo tInfo = schema.getTableInfoPeptides(); + String sql = "select * from pepdb.peptides where peptides.protein_cat_id = ? and ? between peptides.amino_acid_start_pos-2 and peptides.amino_acid_end_pos\n" + + "and ? between peptides.amino_acid_start_pos and peptides.amino_acid_end_pos+2 and child = false"; + Peptides[] peptides = new SqlSelector(schema.getSchema(), sql, new Object[]{p.getProtein_cat_id(),p.getAmino_acid_start_pos(),p.getAmino_acid_end_pos()}).getArray(Peptides.class); + return peptides; + } + + public static Peptides[] getHyphanatedParents(Peptides p) throws SQLException + { + String sql = "select * from "+schema.getTableInfoPeptides()+" where peptides.protein_cat_id = ? " + + " and peptides.peptide_sequence LIKE '%"+p.getPeptide_sequence()+"%' " + + " and child = false"; + Peptides[] peptides = new SqlSelector(schema.getSchema(), sql, new Object[]{p.getProtein_cat_id()}).getArray(Peptides.class); + return peptides; + } + + public static PeptideGroup getPeptideGroupByID(Integer groupId) + { + TableInfo tInfo = schema.getTableInfoPeptideGroups(); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID,groupId); + return new TableSelector(tInfo, sFilter, null).getObject(PeptideGroup.class); + } + + public static ProteinCategory getProCatByID(Integer procatId) + { + TableInfo tInfo = schema.getTableInfoProteinCat(); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PROTEIN_CAT_ID,procatId); + return new TableSelector(tInfo, sFilter, null).getObject(ProteinCategory.class); + } + + public static PeptideGroup getPeptideGroupByName(PeptideGroup pg) + { + PeptideGroup [] groups = null; + TableInfo tInfo = schema.getTableInfoPeptideGroups(); + SQLFragment sql = new SQLFragment("SELECT * FROM "+tInfo+" WHERE UPPER(peptide_group_name) = ? "); + sql.add(pg.getPeptide_group_name().trim().toUpperCase()); + if(pg.getPeptide_group_id() != null) + { + sql.append("AND peptide_group_id != ?"); + sql.add(pg.getPeptide_group_id()); + } + groups = new SqlSelector(schema.getSchema(), sql).getArray(PeptideGroup.class); + + if (groups.length > 0) + return groups[0]; + else + return null; + } + + public static PeptidePool getPeptidePoolByID(Integer poolId) + { + TableInfo tInfo = schema.getTableInfoPeptidePools(); + SimpleFilter sFilter = new SimpleFilter(PepDBSchema.COLUMN_PEPTIDE_POOL_ID,poolId); + return new TableSelector(tInfo, sFilter, null).getObject(PeptidePool.class); + } + + public static int updateInCurrentFile(User user) + { + java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis()); + String sql = "UPDATE pepdb.peptide_group_assignment SET in_current_file = false,modified = ?,modifiedby = ?"; + Object[] params = { date,user.getUserId() }; + return new SqlExecutor(PepDBSchema.getInstance().getSchema()).execute(sql,params); + } + + public static Source getSource(Integer peptideId, Integer groupId) + { + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoSource(); + SimpleFilter sFilter = new SimpleFilter(FieldKey.fromParts("peptide_group_id"), groupId); + sFilter.addCondition(FieldKey.fromParts("peptide_id"), peptideId); + Source dbSrc ; + Source[] dbSrcs = new TableSelector(tInfo, sFilter, null).getArray(Source.class); + if(dbSrcs.length > 0) + dbSrc = dbSrcs[0]; + else + dbSrc = null; + return dbSrc; + } + + public static PeptidePool[] getChildrenPools(String peptidePoolId) + { + SimpleFilter sfilter = new SimpleFilter(FieldKey.fromParts("parent_pool_id"), Integer.parseInt(peptidePoolId)); + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoViewPoolDetails(); + PeptidePool[] pools = new TableSelector(tInfo, sfilter, null).getArray(PeptidePool.class); + if (pools.length < 1) + return null; + return pools; + } + + public static Integer[] getPeptidesInPool(Integer peptidePoolId) + { + SimpleFilter sfilter = new SimpleFilter(FieldKey.fromParts("peptide_pool_id"), peptidePoolId); + TableInfo tInfo = PepDBSchema.getInstance().getTableInfoPoolAssignment(); + Integer[] peptideIds = new TableSelector(tInfo.getColumn("peptide_id"), sfilter, null).getArray(Integer.class); + if (peptideIds.length < 1) + return null; + return peptideIds; + } +} \ No newline at end of file diff --git a/pepdb/src/org/scharp/atlas/pepdb/PepDBModule.java b/pepdb/src/org/scharp/atlas/pepdb/PepDBModule.java new file mode 100644 index 00000000..6296370d --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PepDBModule.java @@ -0,0 +1,100 @@ +package org.scharp.atlas.pepdb; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.labkey.api.data.Container; +import org.labkey.api.data.ContainerManager; +import org.labkey.api.data.DbSchema; +import org.labkey.api.module.DefaultModule; +import org.labkey.api.module.ModuleContext; +import org.labkey.api.util.PageFlowUtil; +import org.labkey.api.view.BaseWebPartFactory; +import org.labkey.api.view.Portal; +import org.labkey.api.view.ViewContext; +import org.labkey.api.view.WebPartFactory; +import org.labkey.api.view.WebPartView; +import org.scharp.atlas.pepdb.query.PepDBQuerySchema; +import org.scharp.atlas.pepdb.view.PepDBWebPart; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +public class PepDBModule extends DefaultModule +{ + private static final Logger _log = LogManager.getLogger(DefaultModule.class); + public static final String NAME = "PepDB"; + + @Override + public String getName() + { + return NAME; + } + + @Override + public @Nullable Double getSchemaVersion() + { + return 2.26; + } + + @Override + protected void init() + { + addController("pepdb", PepDBController.class); + PepDBQuerySchema.register(this); + } + + @Override + @NotNull + protected Collection createWebPartFactories() + { + return Arrays.asList(new BaseWebPartFactory("PepDB Summary", WebPartFactory.LOCATION_BODY, WebPartFactory.LOCATION_RIGHT) + { + { + addLegacyNames("Narrow PepDB Summary"); + } + + @Override + public WebPartView getWebPartView(@NotNull ViewContext portalCtx, @NotNull Portal.WebPart webPart) + { + return new PepDBWebPart(); + } + }); + } + + @Override + public boolean hasScripts() + { + return true; + } + + @Override + @NotNull + public Collection getSummary(Container c) + { + return Collections.emptyList(); + } + + @Override + public void doStartup(ModuleContext moduleContext) + { + // add a container listener so we'll know when our container is deleted: + ContainerManager.addContainerListener(new PepDBContainerListener()); + } + @Override + @NotNull + public Set getSchemaNames() + { + return PageFlowUtil.set(PepDBSchema.getInstance().getSchemaName()); + } + + @Override + @NotNull + public Set getSchemasToTest() + { + return PageFlowUtil.set(PepDBSchema.getInstance().getSchema()); + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/PepDBSchema.java b/pepdb/src/org/scharp/atlas/pepdb/PepDBSchema.java new file mode 100644 index 00000000..c7ef2d9e --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PepDBSchema.java @@ -0,0 +1,162 @@ +package org.scharp.atlas.pepdb; + +import org.labkey.api.data.DbSchema; +import org.labkey.api.data.TableInfo; +import org.labkey.api.data.dialect.SqlDialect; + +/** + * Singleton for storing DB information + * + * @version $Id$ + */ +public class PepDBSchema +{ + + private static PepDBSchema _instance = null; + private static final String SCHEMA_NAME = "pepdb"; + + public static final String TABLE_PEPTIDE_GROUP = "peptide_group"; + public static final String TABLE_GROUP_TYPE = "group_type"; + public static final String TABLE_PROTEIN_CATEGORY = "protein_category"; + public static final String TABLE_PEPTIDES = "peptides"; + public static final String TABLE_PEPTIDE_POOL = "peptide_pool"; + public static final String TABLE_POOL_ASSIGNMENT = "peptide_pool_assignment"; + public static final String TABLE_SOURCE = "peptide_group_assignment"; + public static final String TABLE_PATHOGEN = "pathogen"; + public static final String TABLE_PARENT = "parent"; + public static final String TABLE_OPTIMAL_EPITOPE_LIST = "optimal_epitope_list"; + public static final String TABLE_POOL_TYPE = "pool_type"; + + public static final String VIEW_GROUP_PEPTIDES = "group_peptides"; + public static final String VIEW_POOL_PEPTIDES = "pool_peptides"; + public static final String VIEW_PARENT_CHILD_DETAILS = "parent_child_details"; + public static final String VIEW_POOL_DETAILS = "pool_details"; + + public static final String COLUMN_PEPTIDE_GROUP_ID = "peptide_group_id"; + public static final String COLUMN_PEPTIDE_GROUP_NAME = "peptide_group_name"; + public static final String COLUMN_PROTEIN_CAT_ID = "protein_cat_id"; + public static final String COLUMN_GROUP_TYPE_ID = "group_type_id"; + public static final String COLUMN_PEPTIDE_ID = "peptide_id"; + public static final String COLUMN_PEPTIDE_POOL_ID = "peptide_pool_id"; + public static final String COLUMN_PARENT_POOL_ID = "parent_pool_id"; + public static final String COLUMN_PEPTIDE_SEQUENCE = "peptide_sequence"; + public static final String COLUMN_OPTIMAL_EPITOPE_LIST_ID = "optimal_epitope_list_id"; + public static final String COLUMN_AMINO_ACID_START_POS = "amino_acid_start_pos"; + public static final String COLUMN_AMINO_ACID_END_POS = "amino_acid_end_pos"; + public static final String COLUMN_IS_CHILD = "child"; + public static final String COLUMN_PEPTIDE_ID_IN_GROUP = "peptide_id_in_group"; + public static final String COLUMN_POOL_TYPE_ID = "pool_type_id"; + public static final String COLUMN_PARENT_ID = "parent_id"; + public static final String COLUMN_PARENT_SEQUENCE = "parent_sequence"; + public static final String COLUMN_CHILD_ID = "child_id"; + public static final String COLUMN_CHILD_SEQUENCE = "child_sequence"; + public static final String COLUMN_IN_CURRENT_FILE = "in_current_file"; + public static final String COLUMN_PEPTIDE_GROUP_ASSIGNMENT_ID = "peptide_group_assignment_id"; + public static final String SEQUENCE_PEPTIDE_TABLE = SCHEMA_NAME + ".peptides_peptide_id_seq"; + + + /** + * Singleton + * + * @return the only instance allowed of this class + */ + public synchronized static PepDBSchema getInstance() + { + if (_instance == null) + _instance = new PepDBSchema(); + + return _instance; + } + + private PepDBSchema() + { + // private contructor to prevent instantiation from + // outside this class. + } + + public String getSchemaName() + { + return SCHEMA_NAME; + } + + public DbSchema getSchema() + { + return DbSchema.get(SCHEMA_NAME); + } + + public TableInfo getTableInfoParent() + { + return getSchema().getTable(PepDBSchema.TABLE_PARENT); + } + + public TableInfo getTableInfoPeptideGroups() + { + return getSchema().getTable(PepDBSchema.TABLE_PEPTIDE_GROUP); + } + + public TableInfo getTableInfoPeptideGroupTypes() + { + return getSchema().getTable(PepDBSchema.TABLE_GROUP_TYPE); + } + + public TableInfo getTableInfoPeptides() + { + return getSchema().getTable(PepDBSchema.TABLE_PEPTIDES); + } + + public TableInfo getTableInfoProteinCat() + { + return getSchema().getTable(PepDBSchema.TABLE_PROTEIN_CATEGORY); + } + + public TableInfo getTableInfoViewGroupPeptides() + { + return getSchema().getTable(PepDBSchema.VIEW_GROUP_PEPTIDES); + } + + public TableInfo getTableInfoPeptidePools() + { + return getSchema().getTable(PepDBSchema.TABLE_PEPTIDE_POOL); + } + public TableInfo getTableInfoPoolAssignment() { + return getSchema().getTable(PepDBSchema.TABLE_POOL_ASSIGNMENT); + } + public TableInfo getTableInfoViewPoolPeptides() + { + return getSchema().getTable(PepDBSchema.VIEW_POOL_PEPTIDES); + } + + public TableInfo getTableInfoSource() + { + return getSchema().getTable(PepDBSchema.TABLE_SOURCE); + } + + public TableInfo getTableInfoPathogen() + { + return getSchema().getTable(PepDBSchema.TABLE_PATHOGEN); + } + public SqlDialect getSqlDialect() + { + return getSchema().getSqlDialect(); + } + + public TableInfo getTableInfoOptimalEpitopeList() + { + return getSchema().getTable(PepDBSchema.TABLE_OPTIMAL_EPITOPE_LIST); + } + + public TableInfo getTableInfoViewParentChildDetails() + { + return getSchema().getTable(PepDBSchema.VIEW_PARENT_CHILD_DETAILS); + } + + public TableInfo getTableInfoPoolType() + { + return getSchema().getTable(PepDBSchema.TABLE_POOL_TYPE); + } + + public TableInfo getTableInfoViewPoolDetails() + { + return getSchema().getTable(PepDBSchema.VIEW_POOL_DETAILS); + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/PeptideImporter.java b/pepdb/src/org/scharp/atlas/pepdb/PeptideImporter.java new file mode 100644 index 00000000..24ba9a9b --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PeptideImporter.java @@ -0,0 +1,356 @@ +package org.scharp.atlas.pepdb; + +import org.labkey.api.attachments.AttachmentFile; +import org.labkey.api.security.User; +import org.scharp.atlas.pepdb.model.OptimalEpitopeList; +import org.scharp.atlas.pepdb.model.Parent; +import org.scharp.atlas.pepdb.model.PeptideGroup; +import org.scharp.atlas.pepdb.model.Peptides; +import org.scharp.atlas.pepdb.model.ProteinCategory; +import org.scharp.atlas.pepdb.model.Source; +import org.springframework.validation.Errors; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jan 8, 2010 + * Time: 10:51:10 AM + * To change this template use File | Settings | File Templates. + */ +public class PeptideImporter +{ + private HashMap peptideGroupMap; + private HashMap proteinCategoryMap; + private HashMap proteinCatIDMap; + private HashMap optimalElitopeListMap; + ArrayList peptideIdList; + + public HashMap getPeptideGroupMap() throws SQLException + { + if(peptideGroupMap == null) + peptideGroupMap = PepDBManager.getPeptideGroupMap(); + return peptideGroupMap; + } + + public void setPeptideGroupMap(HashMap peptideGroupMap) + { + this.peptideGroupMap = peptideGroupMap; + } + + public HashMap getProteinCategoryMap() throws SQLException + { + if(proteinCategoryMap == null) + proteinCategoryMap = PepDBManager.getProteinCatMap(); + return proteinCategoryMap; + } + + public void setProteinCategoryMap(HashMap proteinCategoryMap) + { + this.proteinCategoryMap = proteinCategoryMap; + } + + public HashMap getProteinCatIDMap() throws SQLException + { + if(proteinCatIDMap == null) + proteinCatIDMap = PepDBManager.getProteinCatIDMap(); + return proteinCatIDMap; + } + + public void setProteinCatIDMap(HashMap proteinCatIDMap) + { + this.proteinCatIDMap = proteinCatIDMap; + } + + public HashMap getOptimalElitopeListMap() throws SQLException + { + if(optimalElitopeListMap == null) + optimalElitopeListMap = PepDBManager.getOptimalEpitopeListMap(); + return optimalElitopeListMap; + } + + public void setOptimalElitopeListMap(HashMap optimalElitopeListMap) + { + this.optimalElitopeListMap = optimalElitopeListMap; + } + + public ArrayList getPeptideIdList() throws SQLException + { + if(peptideIdList == null) + { + peptideIdList = new ArrayList(); + Peptides[] peptides = PepDBManager.getPeptides(); + for(Peptides p: peptides) + { + peptideIdList.add(p); + } + } + return peptideIdList; + } + + public void setPeptideIdList(ArrayList peptideIdList) + { + this.peptideIdList = peptideIdList; + } + + public boolean process(User user, AttachmentFile peptideFile, Errors errors, List resultPeptides) throws SQLException + { + try{ + String fileName = peptideFile.getFilename(); + InputStreamReader inStream = new InputStreamReader(peptideFile.openInputStream()); + BufferedReader br = new BufferedReader(inStream); + String line = br.readLine(); + boolean validFile = validateFirstLine(line,errors); + if(!validFile) + return false; + getPeptideGroupMap(); + getProteinCategoryMap(); + getOptimalElitopeListMap(); + HashMap peptideSequenceMap = PepDBManager.getPeptideSequenceMap(); + int lineNo =1; + ArrayList newpeptidesList =new ArrayList(); + HashMap lineMap = new HashMap(); + while((line = br.readLine()) != null) + { + lineNo++; + if(line.length()>0) + { + if(validateLine(line,errors,lineNo)) + { + Peptides peptide = createPeptide(line,fileName); + if(peptide != null) + { + newpeptidesList.add(peptide); + lineMap.put(peptide.getPeptide_sequence(), line); + } + } + } + } + if(errors.getErrorCount() >0) + { + errors.reject(null,"File Import Failed.\nThere are "+errors.getErrorCount()+" errors in the file : "+fileName); + return false; + } + getPeptideIdList(); + PepDBManager.updateInCurrentFile(user); + for(Peptides p : newpeptidesList) + { + if(peptideSequenceMap.containsKey(p.getPeptide_sequence())) + { + if(p.getPeptide_id() == null || p.getPeptide_id().toString().length() == 0) + p.setPeptide_id(peptideSequenceMap.get(p.getPeptide_sequence()).getPeptide_id()); + insertGroups(p,user); + resultPeptides.add(p); + } + else + { + Peptides dbPep = PepDBManager.insertPeptide(user,p); + peptideSequenceMap.put(p.getPeptide_sequence(),dbPep); + peptideIdList.add(dbPep); + p.setPeptide_id(dbPep.getPeptide_id()); + insertGroups(p,user); + resultPeptides.add(p); + } + } + getProteinCatIDMap(); + for(Peptides p : peptideIdList) + { + if(p.isChild()) + { + Peptides[] parents; + if(proteinCatIDMap.get(p.getProtein_cat_id()).getProtein_cat_desc().contains("-")) + parents = PepDBManager.getHyphanatedParents(p); + else + parents = PepDBManager.getParentPeptides(p); + for(Peptides par : parents) + { + Parent parent = new Parent(); + parent.setLinked_parent(par.getPeptide_id()); + parent.setPeptide_id(p.getPeptide_id()); + Parent dbParent = PepDBManager.parentExists(parent); + if(dbParent == null) + dbParent = PepDBManager.insertParent(user,parent); + if(!par.isParent()) + { + par.setParent(true); + PepDBManager.updatePeptide(user,par); + } + } + } + } + + } + catch(Exception e) + { + errors.reject(null,e.getMessage()); + return false; + } + return true; + } + + private void insertGroups(Peptides p,User user) throws Exception + { + Source src = p.getSrc(); + src.setPeptide_id(p.getPeptide_id()); + PepDBManager.insertSource(user,src); + } + + private boolean validateLine(String line,Errors errors,int lineNo) + { + String [] fields = new String[10]; + for(int i =0;i0) + return false; + return true; + } + + private Peptides createPeptide(String line,String fileName) throws SQLException + { + String [] fields = new String[10]; + for(int i =0;i 0) + return false; + return true; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/PoolImporter.java b/pepdb/src/org/scharp/atlas/pepdb/PoolImporter.java new file mode 100644 index 00000000..21ec2fa0 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/PoolImporter.java @@ -0,0 +1,407 @@ +package org.scharp.atlas.pepdb; + +import org.labkey.api.attachments.AttachmentFile; +import org.labkey.api.security.User; +import org.scharp.atlas.pepdb.PepDBBaseController.FileForm; +import org.scharp.atlas.pepdb.model.PeptideGroup; +import org.scharp.atlas.pepdb.model.PeptidePool; +import org.scharp.atlas.pepdb.model.PeptidePoolAssignment; +import org.scharp.atlas.pepdb.model.Peptides; +import org.scharp.atlas.pepdb.model.PoolType; +import org.scharp.atlas.pepdb.model.Source; +import org.springframework.validation.Errors; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Oct 16, 2007 + * Time: 8:30:05 AM + * To change this template use File | Settings | File Templates. + */ +public class PoolImporter +{ + private HashMap peptidePoolMap; + private HashMap poolTypeMap; + private HashMap peptideSequenceMap; + private HashMap peptideGroupMap; + public HashMap getPeptidePoolMap() throws SQLException + { + if(peptidePoolMap == null) + peptidePoolMap = PepDBManager.getPeptidePoolMap(); + return peptidePoolMap; + } + + public void setPeptidePoolMap(HashMap peptidePoolMap) + { + this.peptidePoolMap = peptidePoolMap; + } + + public HashMap getPoolTypeMap() throws SQLException + { + if(poolTypeMap == null) + poolTypeMap = PepDBManager.getPoolTypeMap(); + return poolTypeMap; + } + + public void setPoolTypeMap(HashMap poolTypeMap) + { + this.poolTypeMap = poolTypeMap; + } + + public HashMap getPeptideSequenceMap() throws SQLException + { + if(peptideSequenceMap == null) + peptideSequenceMap = PepDBManager.getPeptideSequenceMap(); + return peptideSequenceMap; + } + + public void setPeptideSequenceMap(HashMap peptideSequenceMap) + { + this.peptideSequenceMap = peptideSequenceMap; + } + + public HashMap getPeptideGroupMap() throws SQLException + { + if(peptideGroupMap == null) + peptideGroupMap = PepDBManager.getPeptideGroupMap(); + return peptideGroupMap; + } + + public void setPeptideGroupMap(HashMap peptideGroupMap) + { + this.peptideGroupMap = peptideGroupMap; + } + + public boolean process(User user, FileForm form, AttachmentFile poolFile,Errors errors) throws SQLException + { + String actionType = form.getActionType(); + PeptidePool [] peptidePools = PepDBManager.getPeptidePools(); + //HashMap peptidepoolMap = new HashMap(); + /*for(PeptidePool pPool : peptidePools) + { + peptidepoolMap.put(pPool.getPeptide_pool_id(),pPool); + }*/ + if(actionType.equalsIgnoreCase("POOLDESC")) + { + try{ + InputStreamReader inStream = new InputStreamReader(poolFile.openInputStream()); + BufferedReader br = new BufferedReader(inStream); + String line = br.readLine(); + boolean validFile = validateFirstLine(line,actionType,errors); + if(!validFile) + return false; + getPeptidePoolMap(); + getPoolTypeMap(); + ArrayList newPPools = new ArrayList(); + int lineNo =1; + while((line = br.readLine()) != null) + { + lineNo++; + if(line.trim().length()>0) + { + if(validateLine(line,errors,lineNo)) + { + PeptidePool pPool = createPeptidePool(line); + if(pPool != null) + newPPools.add(pPool); + } + } + } + if(errors.getErrorCount() >0) + { + errors.reject(null,"File Import Failed.\nThere are "+errors.getErrorCount()+" errors in the file : "+poolFile.getFilename()); + return false; + } + for(PeptidePool pPool : newPPools) + { + if(pPool.getPool_type_id() != poolTypeMap.get("POOL").getPool_type_id()) + pPool.setParent_pool_id(peptidePoolMap.get(pPool.getParent_pool_name()).getPeptide_pool_id()); + PeptidePool dbPeptidePool = null; + if(peptidePoolMap.get(pPool.getPeptide_pool_name().trim().toUpperCase()).getPeptide_pool_id() == null || peptidePoolMap.get(pPool.getPeptide_pool_name().trim().toUpperCase()).getPeptide_pool_id().toString().length() == 0) + dbPeptidePool= PepDBManager.insertPeptidePool(user,pPool); + if(dbPeptidePool != null) + peptidePoolMap.put(dbPeptidePool.getPeptide_pool_name().trim().toUpperCase(),dbPeptidePool); + } + } + catch(Exception e) + { + errors.reject(null,e.getMessage()); + return false; + } + } + if(actionType.equalsIgnoreCase("POOLPEPTIDES")) + { + try{ + InputStreamReader inStream = new InputStreamReader(poolFile.openInputStream()); + BufferedReader br = new BufferedReader(inStream); + String line = br.readLine(); + boolean validFile = validateFirstLine(line,form.getActionType(),errors); + if(!validFile) + return false; + int lineNo =1; + getPeptidePoolMap(); + getPeptideSequenceMap(); + getPeptideGroupMap(); + ArrayList newpeptidesInPools = new ArrayList(); + HashMap> newpoolPeptides = new HashMap>(); + while((line = br.readLine()) != null) + { + lineNo++; + if(line.length()>0) + { + if(validatePPLine(line,errors,lineNo,newpoolPeptides)) + { + PeptidePoolAssignment poolAssign = createPoolAssignment(line); + if(poolAssign != null) + { + newpeptidesInPools.add(poolAssign); + if(newpoolPeptides.containsKey(poolAssign.getPeptide_pool_id())) + newpoolPeptides.get(poolAssign.getPeptide_pool_id()).add(poolAssign.getPeptide_id()); + else + { + ArrayList peps = new ArrayList(); + peps.add(poolAssign.getPeptide_id()); + newpoolPeptides.put(poolAssign.getPeptide_pool_id(),peps); + } + + } + } + } + + } + if(errors.getErrorCount()>0) + { + errors.reject(null,"File Import Failed.\nThere are "+errors.getErrorCount()+" errors in the file : "+poolFile.getFilename()); + return false; + } + for(PeptidePoolAssignment pAssignment : newpeptidesInPools) + { + PepDBManager.insertPeptidesInPool(user,pAssignment); + } + } + catch(Exception e) + { + errors.reject(null,e.getMessage()); + return false; + } + } + return true; + } + + private PeptidePoolAssignment createPoolAssignment(String line) throws SQLException + { + String [] fields = new String[3]; + for(int i =0;i0) + return false; + return true; + } + + private boolean validatePPLine(String line,Errors errors,int lineNo,HashMap> newPoolPeptides) throws SQLException + { + String [] fields = new String[3]; + for(int i =0;i0) + return false; + return true; + } + + private boolean validateFirstLine(String line,String importType,Errors errors) + { + String [] fields = line.split("\t"); + if(importType.equalsIgnoreCase("POOLDESC")) + { + if(fields.length != 4) + errors.reject(null,"Line number : 1 must be tab delimited with the fields 'Pool Name','Pool Type','Parent Pool Name' and 'Matrix Pool Id' in the Pool Descriptions file.\n"+ + "The header line does not match this format. Please check the file and try to upload again."); + else + { + if(fields[0] ==null || fields[0].trim().length() == 0 + || fields[1] ==null || fields[1].trim().length() == 0 + || fields[2] ==null || fields[2].trim().length() == 0 + || fields[3] ==null || fields[3].trim().length() == 0) + errors.reject(null,"Line number : 1 must be tab delimited with the fields 'Pool Name','Pool Type','Parent Pool Name' and 'Matrix Pool Id' in the Pool Descriptions file.\n"+ + "One of the fields in header line is null or empty. Please check the file and try to upload again."); + else + { + if(fields[0] != null && !fields[0].trim().equalsIgnoreCase("POOL NAME")) + errors.reject(null,"Pool Descriptions File Import Failed.\nThe first field in the first line (Header) must be 'POOL NAME'"); + if(fields[1] != null && !fields[1].trim().equalsIgnoreCase("POOL TYPE")) + errors.reject(null,"Pool Descriptions File Import Failed.\nThe Second field in the first line (Header) must be 'POOL TYPE'"); + if(fields[2] != null && !fields[2].trim().equalsIgnoreCase("PARENT POOL NAME")) + errors.reject(null,"Pool Descriptions File Import Failed.\nThe Third field in the first line (Header) must be 'PARENT POOL NAME'"); + if(fields[2] != null && !fields[3].trim().equalsIgnoreCase("MATRIX POOL ID")) + errors.reject(null,"Pool Descriptions File Import Failed.\nThe Fourth field in the first line (Header) must be 'MATRIX POOL ID'"); + } + } + if(errors.getErrorCount() > 0) + return false; + return true; + } + if(importType.equalsIgnoreCase("POOLPEPTIDES")) + { + if(fields.length != 3) + errors.reject(null,"Line number : 1 must be tab delimited with the fields 'POOL NAME','PEPTIDE SEQUENCE'and 'PEPTIDE GROUP' in the Peptides in Pool file.\n"+ + "The header line does not match this format. Please check the file and try to upload again."); + else + { + if(fields[0] ==null || fields[0].trim().length() == 0 ||fields[1] ==null || fields[1].trim().length() == 0 || fields[2] ==null || fields[2].trim().length() == 0) + errors.reject(null,"Line number : 1 must be tab delimited with the fields 'POOL NAME','PEPTIDE SEQUENCE' and 'PEPTIDE GROUP'in the Peptides in Pool file.\n"+ + "One of the fields in header line is null or empty. Please check the file and try to upload again."); + else + { + if(fields[0] != null && !fields[0].trim().equalsIgnoreCase("POOL NAME")) + errors.reject(null,"Peptides in Pool File Import Failed.\nThe first field in the first line (Header) must be 'POOL NAME'"); + if(fields[1] != null && !fields[1].trim().equalsIgnoreCase("PEPTIDE SEQUENCE")) + errors.reject(null,"Peptides in Pool File Import Failed.\nThe Second field in the first line (Header) must be 'PEPTIDE SEQUENCE'"); + if(fields[2] != null && !fields[2].trim().equalsIgnoreCase("PEPTIDE GROUP")) + errors.reject(null,"Peptides in Pool File Import Failed.\nThe Second field in the first line (Header) must be 'PEPTIDE GROUP'"); + } + } + if(errors.getErrorCount() > 0) + return false; + return true; + } + return true; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/GroupType.java b/pepdb/src/org/scharp/atlas/pepdb/model/GroupType.java new file mode 100644 index 00000000..3e5be433 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/GroupType.java @@ -0,0 +1,34 @@ +package org.scharp.atlas.pepdb.model; + +/** + * Created by IntelliJ IDEA. + * User: slangley + * Date: Dec 21, 2007 + * Time: 1:08:27 PM + * To change this template use File | Settings | File Templates. + */ +public class GroupType +{ + private Integer group_type_id; + private String group_type_desc; + + public Integer getGroup_type_id() + { + return group_type_id; + } + + public void setGroup_type_id(Integer group_type_id) + { + this.group_type_id = group_type_id; + } + + public String getGroup_type_desc() + { + return group_type_desc; + } + + public void setGroup_type_desc(String group_type_desc) + { + this.group_type_desc = group_type_desc; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/OptimalEpitopeList.java b/pepdb/src/org/scharp/atlas/pepdb/model/OptimalEpitopeList.java new file mode 100644 index 00000000..108c63e2 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/OptimalEpitopeList.java @@ -0,0 +1,34 @@ +package org.scharp.atlas.pepdb.model; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jan 20, 2010 + * Time: 2:10:36 PM + * To change this template use File | Settings | File Templates. + */ +public class OptimalEpitopeList +{ + private Integer optimal_epitope_list_id; + private String optimal_epitope_list_desc; + + public Integer getOptimal_epitope_list_id() + { + return optimal_epitope_list_id; + } + + public void setOptimal_epitope_list_id(Integer optimal_epitope_list_id) + { + this.optimal_epitope_list_id = optimal_epitope_list_id; + } + + public String getOptimal_epitope_list_desc() + { + return optimal_epitope_list_desc; + } + + public void setOptimal_epitope_list_desc(String optimal_epitope_list_desc) + { + this.optimal_epitope_list_desc = optimal_epitope_list_desc; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/Parent.java b/pepdb/src/org/scharp/atlas/pepdb/model/Parent.java new file mode 100644 index 00000000..cc43e605 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/Parent.java @@ -0,0 +1,34 @@ +package org.scharp.atlas.pepdb.model; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Nov 1, 2007 + * Time: 10:28:37 AM + * To change this template use File | Settings | File Templates. + */ +public class Parent +{ + private Integer peptide_id; + private Integer linked_parent; + + public Integer getPeptide_id() + { + return peptide_id; + } + + public void setPeptide_id(Integer peptide_id) + { + this.peptide_id = peptide_id; + } + + public Integer getLinked_parent() + { + return linked_parent; + } + + public void setLinked_parent(Integer linked_parent) + { + this.linked_parent = linked_parent; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/Pathogen.java b/pepdb/src/org/scharp/atlas/pepdb/model/Pathogen.java new file mode 100644 index 00000000..c9fc2913 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/Pathogen.java @@ -0,0 +1,32 @@ +package org.scharp.atlas.pepdb.model; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jul 12, 2007 + * Time: 1:19:11 PM + * To change this template use File | Settings | File Templates. + */ +public class Pathogen{ + private Integer pathogen_id; + private String pathogen_desc; + + public Pathogen() { + } + + public Integer getPathogen_id() { + return pathogen_id; + } + + public void setPathogen_id(Integer pathogen_id) { + this.pathogen_id = pathogen_id; + } + + public String getPathogen_desc() { + return pathogen_desc; + } + + public void setPathogen_desc(String pathogen_desc) { + this.pathogen_desc = pathogen_desc; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/PeptideGroup.java b/pepdb/src/org/scharp/atlas/pepdb/model/PeptideGroup.java new file mode 100644 index 00000000..f05c5521 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/PeptideGroup.java @@ -0,0 +1,84 @@ +package org.scharp.atlas.pepdb.model; + +import org.labkey.api.data.Entity; + + +public class PeptideGroup extends Entity +{ + private Integer peptide_group_id; + private String peptide_group_name; + private Integer pathogen_id; + private String seq_ref; + private Integer clade_id; + private Integer pep_align_ref_id; + private Integer group_type_id; + + public Integer getPeptide_group_id() + { + return peptide_group_id; + } + + public void setPeptide_group_id(Integer peptide_group_id) + { + this.peptide_group_id = peptide_group_id; + } + + public PeptideGroup() { + } + + public Integer getPathogen_id() { + return pathogen_id; + } + + public void setPathogen_id(Integer pathogen_id) { + this.pathogen_id = pathogen_id; + } + + public String getPeptide_group_name() { + return peptide_group_name; + } + + public void setPeptide_group_name(String peptide_group_name) { + this.peptide_group_name = peptide_group_name; + } + + public String getSeq_ref() + { + return seq_ref; + } + + public void setSeq_ref(String seq_ref) + { + this.seq_ref = seq_ref; + } + + public Integer getClade_id() + { + return clade_id; + } + + public void setClade_id(Integer clade_id) + { + this.clade_id = clade_id; + } + + public Integer getPep_align_ref_id() + { + return pep_align_ref_id; + } + + public void setPep_align_ref_id(Integer pep_align_ref_id) + { + this.pep_align_ref_id = pep_align_ref_id; + } + + public Integer getGroup_type_id() + { + return group_type_id; + } + + public void setGroup_type_id(Integer group_type_id) + { + this.group_type_id = group_type_id; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/PeptidePool.java b/pepdb/src/org/scharp/atlas/pepdb/model/PeptidePool.java new file mode 100644 index 00000000..6d8fe143 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/PeptidePool.java @@ -0,0 +1,126 @@ +package org.scharp.atlas.pepdb.model; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.labkey.api.data.Entity; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jun 7, 2007 + * Time: 12:23:53 PM + * Scott changed getDescription() + */ +public class PeptidePool extends Entity +{ + private Integer peptide_pool_id; + private String peptide_pool_name; + private String comment; + private Integer pool_type_id; + private String pool_type_desc; + private boolean archived; + private Integer parent_pool_id; + private String parent_pool_name; + private String matrix_peptide_pool_id; + private static Logger log = LogManager.getLogger(PeptidePool.class); + + public PeptidePool() + { + } + + public PeptidePool(Integer peptide_pool_id, String peptide_pool_name) + { + this.peptide_pool_id = peptide_pool_id; + this.peptide_pool_name = peptide_pool_name; + } + + public Integer getPeptide_pool_id() + { + return peptide_pool_id; + } + + public void setPeptide_pool_id(Integer peptide_pool_id) + { + this.peptide_pool_id = peptide_pool_id; + } + + public String getPeptide_pool_name() + { + return peptide_pool_name; + } + + public void setPeptide_pool_name(String peptide_pool_name) + { + this.peptide_pool_name = peptide_pool_name; + } + + public Integer getPool_type_id() + { + return pool_type_id; + } + + public void setPool_type_id(Integer pool_type_id) + { + this.pool_type_id = pool_type_id; + } + + public String getComment() + { + return comment; + } + + public void setComment(String comment) + { + this.comment = comment; + } + + public String getPool_type_desc() + { + return pool_type_desc; + } + + public void setPool_type_desc(String pool_type_desc) + { + this.pool_type_desc = pool_type_desc; + } + + public boolean getArchived() + { + return archived; + } + + public void setArchived(boolean archived) + { + this.archived = archived; + } + + public Integer getParent_pool_id() + { + return parent_pool_id; + } + + public void setParent_pool_id(Integer parent_pool_id) + { + this.parent_pool_id = parent_pool_id; + } + + public String getParent_pool_name() + { + return parent_pool_name; + } + + public void setParent_pool_name(String parent_pool_name) + { + this.parent_pool_name = parent_pool_name; + } + + public String getMatrix_peptide_pool_id() + { + return matrix_peptide_pool_id; + } + + public void setMatrix_peptide_pool_id(String matrix_peptide_pool_id) + { + this.matrix_peptide_pool_id = matrix_peptide_pool_id; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/PeptidePoolAssignment.java b/pepdb/src/org/scharp/atlas/pepdb/model/PeptidePoolAssignment.java new file mode 100644 index 00000000..ca8d0db0 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/PeptidePoolAssignment.java @@ -0,0 +1,47 @@ +package org.scharp.atlas.pepdb.model; + +import org.labkey.api.data.Entity; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Nov 5, 2007 + * Time: 9:01:23 AM + * To change this template use File | Settings | File Templates. + */ +public class PeptidePoolAssignment extends Entity +{ + private Integer peptide_pool_id; + private Integer peptide_id; + private Integer peptide_group_assignment_id; + + public Integer getPeptide_pool_id() + { + return peptide_pool_id; + } + + public void setPeptide_pool_id(Integer peptide_pool_id) + { + this.peptide_pool_id = peptide_pool_id; + } + + public Integer getPeptide_id() + { + return peptide_id; + } + + public void setPeptide_id(Integer peptide_id) + { + this.peptide_id = peptide_id; + } + + public Integer getPeptide_group_assignment_id() + { + return peptide_group_assignment_id; + } + + public void setPeptide_group_assignment_id(Integer peptide_group_assignment_id) + { + this.peptide_group_assignment_id = peptide_group_assignment_id; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/Peptides.java b/pepdb/src/org/scharp/atlas/pepdb/model/Peptides.java new file mode 100644 index 00000000..c70ad2cc --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/Peptides.java @@ -0,0 +1,237 @@ +package org.scharp.atlas.pepdb.model; + +import org.labkey.api.data.Entity; + +import java.util.List; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jul 12, 2007 + * Time: 1:11:40 PM + * To change this template use File | Settings | File Templates. + */ +public class Peptides extends Entity +{ + private Integer peptide_id; + private String peptide_sequence; + private Integer protein_cat_id; + private Integer amino_acid_start_pos; + private Integer amino_acid_end_pos; + private Integer sequence_length; + private boolean child; + private boolean parent; + private String src_file_name; + private String storage_location; + private Integer optimal_epitope_list_id; + private String hla_restriction; + private Source src; + private List peptideGroups; + private ProteinCategory proteinCat; + private Pathogen pathogen; + private Parent parentPep; + private List parents; + private boolean peptide_flag; + private String peptide_notes; + + public List getParents() + { + return parents; + } + + public void setParents(List parents) + { + this.parents = parents; + } + + + public Parent getParentPep() + { + return parentPep; + } + + public void setParentPep(Parent parentPep) + { + this.parentPep = parentPep; + } + + public ProteinCategory getProteinCat() + { + return proteinCat; + } + + public void setProteinCat(ProteinCategory proteinCat) + { + this.proteinCat = proteinCat; + } + + public Pathogen getPathogen() + { + return pathogen; + } + + public void setPathogen(Pathogen pathogen) + { + this.pathogen = pathogen; + } + + public Integer getPeptide_id() + { + return peptide_id; + } + + public void setPeptide_id(Integer peptide_id) + { + this.peptide_id = peptide_id; + } + + public String getPeptide_sequence() + { + return peptide_sequence; + } + + public void setPeptide_sequence(String peptide_sequence) + { + this.peptide_sequence = peptide_sequence; + } + + public Integer getProtein_cat_id() + { + return protein_cat_id; + } + + public void setProtein_cat_id(Integer protein_cat_id) + { + this.protein_cat_id = protein_cat_id; + } + + public boolean isChild() + { + return child; + } + + public void setChild(boolean child) + { + this.child = child; + } + + public List getPeptideGroups() + { + return peptideGroups; + } + + public void setPeptideGroups(List peptideGroups) + { + this.peptideGroups = peptideGroups; + } + + public boolean isParent() + { + return parent; + } + + public void setParent(boolean parent) + { + this.parent = parent; + } + + public String getSrc_file_name() + { + return src_file_name; + } + + public void setSrc_file_name(String src_file_name) + { + this.src_file_name = src_file_name; + } + + public Integer getAmino_acid_start_pos() + { + return amino_acid_start_pos; + } + + public void setAmino_acid_start_pos(Integer amino_acid_start_pos) + { + this.amino_acid_start_pos = amino_acid_start_pos; + } + + public Integer getAmino_acid_end_pos() + { + return amino_acid_end_pos; + } + + public void setAmino_acid_end_pos(Integer amino_acid_end_pos) + { + this.amino_acid_end_pos = amino_acid_end_pos; + } + + public Integer getSequence_length() + { + return sequence_length; + } + + public void setSequence_length(Integer sequence_length) + { + this.sequence_length = sequence_length; + } + + public String getStorage_location() + { + return storage_location; + } + + public void setStorage_location(String storage_location) + { + this.storage_location = storage_location; + } + + public Integer getOptimal_epitope_list_id() + { + return optimal_epitope_list_id; + } + + public void setOptimal_epitope_list_id(Integer optimal_epitope_list_id) + { + this.optimal_epitope_list_id = optimal_epitope_list_id; + } + + public String getHla_restriction() + { + return hla_restriction; + } + + public void setHla_restriction(String hla_restriction) + { + this.hla_restriction = hla_restriction; + } + + public Source getSrc() + { + return src; + } + + public void setSrc(Source src) + { + this.src = src; + } + + public boolean isPeptide_flag() + { + return peptide_flag; + } + + public void setPeptide_flag(boolean peptide_flag) + { + this.peptide_flag = peptide_flag; + } + + public String getPeptide_notes() + { + return peptide_notes; + } + + public void setPeptide_notes(String peptide_notes) + { + this.peptide_notes = peptide_notes; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/PoolType.java b/pepdb/src/org/scharp/atlas/pepdb/model/PoolType.java new file mode 100644 index 00000000..323d273d --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/PoolType.java @@ -0,0 +1,34 @@ +package org.scharp.atlas.pepdb.model; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jan 25, 2010 + * Time: 2:13:19 PM + * To change this template use File | Settings | File Templates. + */ +public class PoolType +{ + private Integer pool_type_id; + private String pool_type_desc; + + public Integer getPool_type_id() + { + return pool_type_id; + } + + public void setPool_type_id(Integer pool_type_id) + { + this.pool_type_id = pool_type_id; + } + + public String getPool_type_desc() + { + return pool_type_desc; + } + + public void setPool_type_desc(String pool_type_desc) + { + this.pool_type_desc = pool_type_desc; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/ProteinCategory.java b/pepdb/src/org/scharp/atlas/pepdb/model/ProteinCategory.java new file mode 100644 index 00000000..7ffeb0ac --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/ProteinCategory.java @@ -0,0 +1,44 @@ +package org.scharp.atlas.pepdb.model; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jan 9, 2007 + * Time: 1:34:16 PM + * To change this template use File | Settings | File Templates. + */ +public class ProteinCategory +{ + private Integer protein_cat_id; + private String protein_cat_desc; + + public ProteinCategory() + { + } + + public ProteinCategory(Integer protein_cat_id, String protein_cat_desc, String protein_cat_mnem, Integer protein_sort_value) + { + this.protein_cat_id = protein_cat_id; + this.protein_cat_desc = protein_cat_desc; + } + + public Integer getProtein_cat_id() + { + return protein_cat_id; + } + + public void setProtein_cat_id(Integer protein_cat_id) + { + this.protein_cat_id = protein_cat_id; + } + + public String getProtein_cat_desc() + { + return protein_cat_desc; + } + + public void setProtein_cat_desc(String protein_cat_desc) + { + this.protein_cat_desc = protein_cat_desc; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/model/Source.java b/pepdb/src/org/scharp/atlas/pepdb/model/Source.java new file mode 100644 index 00000000..d14e1638 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/model/Source.java @@ -0,0 +1,108 @@ +package org.scharp.atlas.pepdb.model; + +import org.labkey.api.data.Entity; + +import java.sql.Date; + +/** + * Created by IntelliJ IDEA. + * User: sravani + * Date: Jun 21, 2007 + * Time: 11:49:31 AM + * To change this template use File | Settings | File Templates. + */ +public class Source extends Entity +{ + private Integer peptide_group_assignment_id; + private Integer peptide_id; + private Integer peptide_group_id; + private String peptide_group_name; + private String peptide_id_in_group; + private Float frequency_number; + private Date frequency_number_date; + private boolean in_current_file; + + public Source() + { + } + + public Integer getPeptide_group_assignment_id() + { + return peptide_group_assignment_id; + } + + public void setPeptide_group_assignment_id(Integer peptide_group_assignment_id) + { + this.peptide_group_assignment_id = peptide_group_assignment_id; + } + + public Integer getPeptide_id() + { + return peptide_id; + } + + public void setPeptide_id(Integer peptide_id) + { + this.peptide_id = peptide_id; + } + + public Integer getPeptide_group_id() + { + return peptide_group_id; + } + + public void setPeptide_group_id(Integer peptide_group_id) + { + this.peptide_group_id = peptide_group_id; + } + + public String getPeptide_id_in_group() + { + return peptide_id_in_group; + } + + public void setPeptide_id_in_group(String peptide_id_in_group) + { + this.peptide_id_in_group = peptide_id_in_group; + } + + public Float getFrequency_number() + { + return frequency_number; + } + + public void setFrequency_number(Float frequency_number) + { + this.frequency_number = frequency_number; + } + + public Date getFrequency_number_date() + { + return frequency_number_date; + } + + public void setFrequency_number_date(Date frequency_number_date) + { + this.frequency_number_date = frequency_number_date; + } + + public String getPeptide_group_name() + { + return peptide_group_name; + } + + public void setPeptide_group_name(String peptide_group_name) + { + this.peptide_group_name = peptide_group_name; + } + + public boolean isIn_current_file() + { + return in_current_file; + } + + public void setIn_current_file(boolean in_current_file) + { + this.in_current_file = in_current_file; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/query/PepDBQuerySchema.java b/pepdb/src/org/scharp/atlas/pepdb/query/PepDBQuerySchema.java new file mode 100644 index 00000000..44bf18d3 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/query/PepDBQuerySchema.java @@ -0,0 +1,51 @@ +package org.scharp.atlas.pepdb.query; + +import org.jetbrains.annotations.NotNull; +import org.labkey.api.data.Container; +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.data.DbSchema; +import org.labkey.api.data.TableInfo; +import org.labkey.api.module.Module; +import org.labkey.api.query.DefaultSchema; +import org.labkey.api.query.QuerySchema; +import org.labkey.api.query.SimpleUserSchema; +import org.labkey.api.security.User; + +/** + * Created by klum on 9/17/2014. + */ +public class PepDBQuerySchema extends SimpleUserSchema +{ + public static final String SCHEMA_NAME = "pepdb"; + public static final String SCHEMA_DESCR = "Provides peptide and peptide pool information."; + + static public void register(Module module) + { + DefaultSchema.registerProvider(SCHEMA_NAME, new DefaultSchema.SchemaProvider(module) + { + @Override + public QuerySchema createSchema(DefaultSchema schema, Module module) + { + return new PepDBQuerySchema(schema.getUser(), schema.getContainer()); + } + }); + } + + public PepDBQuerySchema(User user, Container container) + { + super(SCHEMA_NAME, SCHEMA_DESCR, user, container, DbSchema.get("pepdb")); + } + + @Override + protected TableInfo createWrappedTable(String name, @NotNull TableInfo sourceTable, ContainerFilter cf) + { + TableInfo table = super.createWrappedTable(name, sourceTable, cf); + if (table instanceof SimpleTable) + { + // Setting readOnly to false so that tests can reset the data tables via Remote API commands. S. Langley. + ((SimpleTable) table).setReadOnly(false); + //((SimpleTable)table).setReadOnly(true); + } + return table; + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/PepDBWebPart.java b/pepdb/src/org/scharp/atlas/pepdb/view/PepDBWebPart.java new file mode 100644 index 00000000..64c16b1b --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/PepDBWebPart.java @@ -0,0 +1,12 @@ +package org.scharp.atlas.pepdb.view; + +import org.labkey.api.view.JspView; + +public class PepDBWebPart extends JspView +{ + public PepDBWebPart() + { + super("/org/scharp/atlas/pepdb/view/pepDBWebPart.jsp", null); + setTitle("PepDB Web Part"); + } +} diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/importPeptides.jsp b/pepdb/src/org/scharp/atlas/pepdb/view/importPeptides.jsp new file mode 100644 index 00000000..02dd4fae --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/importPeptides.jsp @@ -0,0 +1,48 @@ +<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> +<%@ page import="org.labkey.api.view.HttpView"%> +<%@ page import="org.labkey.api.view.JspView"%> +<%@ page import="org.scharp.atlas.pepdb.PepDBBaseController.FileForm" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController.ImportPeptidesAction" %> +<%@ page extends="org.labkey.api.jsp.JspBase" %> +
+ <% + JspView me = (JspView) HttpView.currentView(); + FileForm bean = me.getModelBean(); + %> + + + + + + + + + + + + + + + +
+

Import Peptides

+
File Type : +
+ File : + +
+ <%= button("Import Peptides").submit(true) %> <%= button("Back").href(urlFor(PepDBController.BeginAction.class)) %> +
+
+ Note: The File must be .txt extension and It should be tab delimited.

+
+
+
diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/importPools.jsp b/pepdb/src/org/scharp/atlas/pepdb/view/importPools.jsp new file mode 100644 index 00000000..86858df0 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/importPools.jsp @@ -0,0 +1,49 @@ +<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> +<%@ page import="org.labkey.api.view.HttpView"%> +<%@ page import="org.labkey.api.view.JspView" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController.ImportPeptidePoolsAction" %> +<%@ page extends="org.labkey.api.jsp.JspBase" %> +
+ <% + JspView me = (JspView) HttpView.currentView(); + PepDBController.FileForm bean = me.getModelBean(); + %> + + <% if (null != bean.getMessage()) {%> + <%=h(bean.getMessage())%> + <%}%> + + + + + + + + + + + + + + + + +
+

Import Peptide Pools

+
File Type : +
+ File : + +
+ <%= button("Import Peptide Pools").submit(true) %> <%= button("Back").href(urlFor(PepDBController.BeginAction.class)) %> +
+
+ Note: The File must be .txt extension and It should be tab delimited.

+
+
+
diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/index.jsp b/pepdb/src/org/scharp/atlas/pepdb/view/index.jsp new file mode 100644 index 00000000..dcd0a34b --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/index.jsp @@ -0,0 +1,53 @@ +<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> +<%@ page import="org.labkey.api.security.User"%> +<%@ page import="org.labkey.api.security.permissions.UpdatePermission" %> +<%@ page import="org.labkey.api.view.HttpView" %> +<%@ page import="org.labkey.api.view.ViewContext" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBBaseController.DisplayPeptideForm" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController.DisplayPeptideAction" %> +<%@ page extends="org.labkey.api.jsp.JspBase" %> + +<% ViewContext ctx = getViewContext(); + User user = ctx.getUser(); + final var canUpdate = ctx.getContainer().hasPermission(user, UpdatePermission.class); +%> +

If you see some of the links disabled then you don't have permission to enter data. + If you need to enter any data contact Atlas Administrator.

+

Peptide Groups :

+
    +
  • <%= link("List Peptide Groups").href(urlFor(PepDBController.ShowAllPeptideGroupsAction.class)).clearClasses() %>
  • + <% + if(canUpdate){%> +
  • <%= link("Insert a New Group").href(urlFor(PepDBController.InsertPeptideGroupAction.class)).clearClasses() %>
  • + <%}else{%> +
  • Insert a New Group
  • + <%}%> +
+

Peptides :

+
    +
  • <%= link("Search for Peptides by Criteria").href(urlFor(PepDBController.SearchForPeptidesAction.class)).clearClasses() %>
  • + <%if(canUpdate){%> +
  • <%= link("Import Peptides").href(urlFor(PepDBController.ImportPeptidesAction.class)).clearClasses() %>
  • + <%}else{%> +
  • Import Peptides
  • + <%}%> +
  • <%= link("Peptides From Last Import").href(urlFor(PepDBController.DisplayResultAction.class)).clearClasses() %>
  • +
+ +<% + DisplayPeptideForm form = (DisplayPeptideForm) (HttpView.currentModel()); +%> + +Lookup Peptide by Id:   <%= button("Find").submit(true) %> + +

+

Peptide Pools :

+
    + <%if(canUpdate){%> +
  • <%= link("Import Peptide Pools").href(urlFor(PepDBController.ImportPeptidePoolsAction.class)).clearClasses() %>
  • + <%}else{%> +
  • Import Peptide Pools
  • + <%}%> +
  • <%= link("List All Peptide Pools").href(urlFor(PepDBController.ShowAllPeptidePoolsAction.class)).clearClasses() %>
  • +
diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/pepDBWebPart.jsp b/pepdb/src/org/scharp/atlas/pepdb/view/pepDBWebPart.jsp new file mode 100644 index 00000000..e016a654 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/pepDBWebPart.jsp @@ -0,0 +1,9 @@ +<%@ page import="org.scharp.atlas.pepdb.PepDBController"%> +<%@ page import="org.scharp.atlas.pepdb.PepDBManager"%> +<%@ page import="org.scharp.atlas.pepdb.model.PeptideGroup"%> +<%@ page extends="org.labkey.api.jsp.JspBase" %> +<% + PeptideGroup[] peptides = PepDBManager.getPeptideGroups(); +%> +This container contains <%= peptides.length %> peptide groups.
+<%= button("View Grid").href(urlFor(PepDBController.ShowAllPeptideGroupsAction.class)) %> diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/peptideDetails.jsp b/pepdb/src/org/scharp/atlas/pepdb/view/peptideDetails.jsp new file mode 100644 index 00000000..120f8e98 --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/peptideDetails.jsp @@ -0,0 +1,57 @@ +<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> +<%@ page import="org.labkey.api.view.HttpView"%> +<%@ page import="org.labkey.api.view.JspView" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBBaseController.PeptideQueryForm" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBManager" %> +<%@ page import="org.scharp.atlas.pepdb.model.PeptidePool" %> +<%@ page import="org.scharp.atlas.pepdb.model.Source" %> +<%@ page extends="org.labkey.api.jsp.JspBase" %> +<% + JspView me = (JspView) HttpView.currentView(); + PeptideQueryForm bean = me.getModelBean(); +%> + + <% + Source[] sources = PepDBManager.getSourcesForPeptide(bean.getQueryValue()); + if (sources != null && sources.length > 0) + {%> +

Peptide P<%=h(bean.getQueryValue())%> is a member of these Peptide Groups:

+ <% + for (Source source : sources) + { %> + + + + + + <% }} // end for loop %> +
+ <%= link(source.getPeptide_group_name()).href(urlFor(PepDBController.DisplayPeptideGroupInformationAction.class) + .addParameter("peptide_group_id", source.getPeptide_group_id().toString())).clearClasses() %> + (PEPTIDE NUMBER =<%=h(source.getPeptide_id_in_group())%>) + <%if(source.getFrequency_number() != null){%> + - Frequency Number = + <%= source.getFrequency_number()%> + <%}if(source.getFrequency_number_date() != null){%> + - Frequency Update Date = <%=formatDateTime(source.getFrequency_number_date())%><%}%> +
+ + <% + PeptidePool[] pools = PepDBManager.getPoolsForPeptide(bean.getQueryValue()); + if (pools != null && pools.length > 0) + { + %> +

Peptide P<%=h(bean.getQueryValue())%> is a member of these Peptide Pools:

+ <% for (PeptidePool pool : pools) + {%> + + + + <% }} // end if statement %> +
+ <%= link("PP"+pool.getPeptide_pool_id()).href(urlFor(PepDBController.DisplayPeptidePoolInformationAction.class) + .addParameter("peptide_pool_id", pool.getPeptide_pool_id())).clearClasses() %> - + <%=h(pool.getPeptide_pool_name())%> + <%=h(pool.getPool_type_desc())%> +
diff --git a/pepdb/src/org/scharp/atlas/pepdb/view/peptideGroupSelect.jsp b/pepdb/src/org/scharp/atlas/pepdb/view/peptideGroupSelect.jsp new file mode 100644 index 00000000..b63268ab --- /dev/null +++ b/pepdb/src/org/scharp/atlas/pepdb/view/peptideGroupSelect.jsp @@ -0,0 +1,126 @@ +<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> +<%@ page import="org.labkey.api.view.HttpView"%> +<%@ page import="org.labkey.api.view.JspView" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBBaseController.PeptideQueryForm" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBController.SearchForPeptidesAction" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBManager" %> +<%@ page import="org.scharp.atlas.pepdb.PepDBSchema" %> +<%@ page import="org.scharp.atlas.pepdb.model.PeptideGroup" %> +<%@ page import="org.scharp.atlas.pepdb.model.PeptidePool" %> +<%@ page import="org.scharp.atlas.pepdb.model.ProteinCategory" %> +<%@ page extends="org.labkey.api.jsp.JspBase" %> +<% + JspView me = (JspView) HttpView.currentView(); + PeptideQueryForm bean = me.getModelBean(); + if(bean.getMessage() != null){ +%> +<%=h(bean.getMessage())%><%}%> + + + +

Search for Peptides using different criteria :



+ + + + + + + + + + + <%if(bean.getQueryKey() != null && bean.getQueryKey().equals(PepDBSchema.COLUMN_PROTEIN_CAT_ID)){%> + + + + + + + + + + + <%}%> + <%if(bean.getQueryKey() != null && bean.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID)){%> + + + + + + <%}%> + + + + +
Search Criteria : + <%=select() + .id("queryKey") + .name("queryKey") + .onChange("selectOptions()") + .selected(bean.getQueryKey()) + .className(null) + .addOption("") + .addOption("Peptides in a Peptide Group", PepDBSchema.COLUMN_PEPTIDE_GROUP_ID) + .addOption("Peptides in a Peptide Pool", PepDBSchema.COLUMN_PEPTIDE_POOL_ID) + .addOption("Peptides in a Protein Category", PepDBSchema.COLUMN_PROTEIN_CAT_ID) + .addOption("Peptides contain Sequence", PepDBSchema.COLUMN_PEPTIDE_SEQUENCE) + .addOption("Child Peptides By Parent Sequence", PepDBSchema.COLUMN_PARENT_SEQUENCE) + .addOption("Parent Peptides By Child Sequence", PepDBSchema.COLUMN_CHILD_SEQUENCE) + %> +
+ <%=h((bean.getQueryKey() != null && bean.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_SEQUENCE)) ? " Equals / Contains : " : " Equals : ")%> + + + <%if(bean.getQueryKey() == null || bean.getQueryKey().isEmpty()){ %> + + <%} + else if(bean.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_GROUP_ID)){ + PeptideGroup[] peptideGroups = PepDBManager.getPeptideGroups(); + %> + + <% } + else if (bean.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_POOL_ID)) { + PeptidePool[] peptidePools = PepDBManager.getPeptidePools(); + %> + + <% } + else if (bean.getQueryKey().equals(PepDBSchema.COLUMN_PROTEIN_CAT_ID)) { + ProteinCategory[] proteinCategories = PepDBManager.getProteinCategory(); + %> + + <%} + else if(bean.getQueryKey().equals(PepDBSchema.COLUMN_PEPTIDE_SEQUENCE) || bean.getQueryKey().equals(PepDBSchema.COLUMN_PARENT_SEQUENCE) || bean.getQueryKey().equals(PepDBSchema.COLUMN_CHILD_SEQUENCE)){%> +   + <%}%> +
+ Amino Acid Start Position: + +
+ Amino Acid End Position: + +
+ PEPTIDE NUMBER: + +
+ +
+
diff --git a/pepdb/test/sampledata/test_import_files/peptide_file/gagptegprac.txt b/pepdb/test/sampledata/test_import_files/peptide_file/gagptegprac.txt new file mode 100755 index 00000000..bdbf80b9 --- /dev/null +++ b/pepdb/test/sampledata/test_import_files/peptide_file/gagptegprac.txt @@ -0,0 +1,17 @@ +PEPTIDE SEQUENCE IS CHILD PROTEIN CATEGORY PEPTIDE GROUP ID SEQUENCE LENGTH AASTART AAEND IN A LIST HLA RESTRICTION +WIILGLNKIVRMYSP FALSE p24 gagptegprac GAG1-1 15 133 147 +TLEEMMTACQGVGGP FALSE p24 gagptegprac GAG1-2 15 210 224 +RQGPKEPFRDYVDRF FALSE p24 gagptegprac GAG1-3 15 154 168 +REPRGSDIAGTTSTL FALSE p24 gagptegprac GAG1-4 15 97 111 +HQMKDCTERQANFLG FALSE p2p7p1p6 gagptegprac GAG1-5 15 58 72 +LNTVGGHQAAMQMLK FALSE p24 gagptegprac GAG1-6 15 56 70 +GEIYKRWIILGLNKI FALSE p24 gagptegprac GAG1-7 15 127 141 +ALSEGATPQDLNTML FALSE p24 gagptegprac GAG1-8 15 42 56 +KCGKEGHQMKDCTER FALSE p2p7p1p6 gagptegprac GAG2-1 15 52 66 +TLLVQNANPDCKTIL FALSE p24 gagptegprac GAG2-2 15 188 202 +TERQANFLGKIWPSH FALSE p2p7p1p6 gagptegprac GAG2-3 15 64 78 +NCRAPRKKGCWKCGK FALSE p2p7p1p6 gagptegprac GAG2-4 15 41 55 +NKIVRMYSPVSILDI FALSE p24 gagptegprac GAG2-5 15 139 153 +EEKAFSPEVIPMFSA FALSE p24 gagptegprac GAG2-6 15 28 42 +GPGHKARVLAEAMSQ FALSE p24-p2p7p1p6 gagptegprac GAG2-7 15 223 6 +TINEEAAEWDRLHPV FALSE p24 gagptegprac GAG2-8 15 72 86 diff --git a/pepdb/test/sampledata/test_import_files/peptide_file/gagptegprac1.txt b/pepdb/test/sampledata/test_import_files/peptide_file/gagptegprac1.txt new file mode 100755 index 00000000..22c44b81 --- /dev/null +++ b/pepdb/test/sampledata/test_import_files/peptide_file/gagptegprac1.txt @@ -0,0 +1,4 @@ +PEPTIDE SEQUENCE IS CHILD PROTEIN CATEGORY PEPTIDE GROUP ID SEQUENCE LENGTH AASTART AAEND IN A LIST HLA RESTRICTION +WIILGLNKIVRMYSP FALSE p24 gagptegprac1 GAG1-1 15 133 147 +TLEEMMTACQGVGGP FALSE p24 gagptegprac1 GAG1-2 15 210 224 +RQGPKEPFRDYVDRF FALSE p24 gagptegprac1 GAG1-3 15 154 168 diff --git a/pepdb/test/sampledata/test_import_files/pool_description_file/pool_description.txt b/pepdb/test/sampledata/test_import_files/pool_description_file/pool_description.txt new file mode 100755 index 00000000..ecd81127 --- /dev/null +++ b/pepdb/test/sampledata/test_import_files/pool_description_file/pool_description.txt @@ -0,0 +1,2 @@ +Pool Name Pool Type Parent Pool Name Matrix Pool Id +Prac_Pool Pool diff --git a/pepdb/test/sampledata/test_import_files/pool_detail_file/pool_details.txt b/pepdb/test/sampledata/test_import_files/pool_detail_file/pool_details.txt new file mode 100755 index 00000000..03f732d1 --- /dev/null +++ b/pepdb/test/sampledata/test_import_files/pool_detail_file/pool_details.txt @@ -0,0 +1,3 @@ +POOL NAME PEPTIDE SEQUENCE PEPTIDE GROUP +Prac_Pool WIILGLNKIVRMYSP gagptegprac +Prac_Pool REPRGSDIAGTTSTL gagptegprac diff --git a/pepdb/test/src/org/labkey/test/tests/pepdb/PepDBModuleTest.java b/pepdb/test/src/org/labkey/test/tests/pepdb/PepDBModuleTest.java new file mode 100644 index 00000000..2b5ac550 --- /dev/null +++ b/pepdb/test/src/org/labkey/test/tests/pepdb/PepDBModuleTest.java @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2013-2015 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.labkey.test.tests.pepdb; + +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.labkey.remoteapi.CommandException; +import org.labkey.remoteapi.Connection; +import org.labkey.remoteapi.query.ContainerFilter; +import org.labkey.remoteapi.query.DeleteRowsCommand; +import org.labkey.remoteapi.query.Row; +import org.labkey.remoteapi.query.RowMap; +import org.labkey.remoteapi.query.SelectRowsCommand; +import org.labkey.remoteapi.query.SelectRowsResponse; +import org.labkey.test.BaseWebDriverTest; +import org.labkey.test.Locator; +import org.labkey.test.TestFileUtils; +import org.labkey.test.TestTimeoutException; +import org.labkey.test.WebTestHelper; +import org.labkey.test.categories.External; +import org.labkey.test.util.LogMethod; +import org.labkey.test.util.PostgresOnlyTest; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@Category({External.class}) +public class PepDBModuleTest extends BaseWebDriverTest implements PostgresOnlyTest +{ + + public static final String FOLDER_TYPE = "Custom"; + // Folder type defined in customFolder.foldertype.xml + public static final String MODULE_NAME = "PepDB"; + public static final String USER_SCHEMA_NAME = "pepdb"; + public static final String FOLDER_NAME = "PepDB"; + private int peptideStartIndex = 0; + + @Override + protected String getProjectName() + { + return getClass().getSimpleName() + " Project"; + } + + // Setup duplicates the folder structure and webparts used in production. + private void setupProject() + { + log("Starting setupProject()"); + assertModuleDeployed(MODULE_NAME); + _containerHelper.createProject(getProjectName(), FOLDER_TYPE); + + _containerHelper.enableModule(getProjectName(), MODULE_NAME); + _containerHelper.createSubfolder(getProjectName(), "Labs", FOLDER_TYPE); + _containerHelper.createSubfolder(getProjectName() + "/Labs", "Test", FOLDER_TYPE); + _containerHelper.createSubfolder(getProjectName() + "/Labs/Test", FOLDER_NAME, FOLDER_TYPE); + clickFolder("Labs"); + clickFolder("Test"); + clickFolder(FOLDER_NAME); + + _containerHelper.enableModules(Arrays.asList("Issues", "Wiki", "PepDB")); + _containerHelper.disableModules("Portal"); + setDefaultModule("PepDB"); + log("Finished setupProject()"); + } + + /** + * Set which view in this folder should be the default + * + * @param moduleName + */ + void setDefaultModule(String moduleName) + { + goToFolderManagement(); + clickAndWait(Locator.linkWithText("Folder Type")); + selectOptionByText(Locator.name("defaultModule"), moduleName); + clickButton("Update Folder"); + } + + @Test + public void testSteps() throws Exception + { + setupProject(); + assertModuleEnabled("Issues"); + assertModuleEnabled("Wiki"); + assertModuleEnabled("PepDB"); + log("Expected modules enabled."); + + beginAt(WebTestHelper.buildURL("pepdb", getProjectName() + "/Labs/Test/" + FOLDER_NAME, "begin")); + + /* Insert the Peptide Group" */ + clickAndWait(Locator.linkWithText("Insert a New Group")); + setFormElement(Locator.name("peptide_group_name"), "gagptegprac"); + selectOptionByText(Locator.name("pathogen_id"), "Other"); + selectOptionByText(Locator.name("clade_id"), "Other"); + selectOptionByText(Locator.name("group_type_id"), "Other"); + clickAndWait(Locator.css("a.labkey-button > span")); + clickFolder(FOLDER_NAME); + + // Import some test Peptides from a file. + clickAndWait(Locator.linkWithText("Import Peptides")); + selectOptionByText(Locator.id("actionType"), "Peptides"); + setFormElement(Locator.name("pFile"), getSampleData("/peptide_file/gagptegprac.txt")); + clickButton("Import Peptides"); + + /* Import Peptide Pool 'Pool Descriptions' file. + * ./test_import_files/pool_description_file/pool_description.txt + */ + clickFolder(FOLDER_NAME); + clickAndWait(Locator.linkWithText("Import Peptide Pools")); + selectOptionByText(Locator.name("actionType"), "Pool Descriptions"); + + setFormElement(Locator.name("pFile"), getSampleData("/pool_description_file/pool_description.txt")); + clickAndWait(Locator.css("a.labkey-button > span")); + + /* Import Peptide Pool 'Peptides in Pool' file. + ./test_import_files/pool_detail_file/pool_details.txt + */ + clickFolder(FOLDER_NAME); + clickAndWait(Locator.linkWithText("Import Peptide Pools")); + selectOptionByText(Locator.name("actionType"), "Peptides in Pool"); + + setFormElement(Locator.name("pFile"), getSampleData("/pool_detail_file/pool_details.txt")); + clickAndWait(Locator.css("a.labkey-button > span")); + + /* Search for the Peptides belonging to our just-imported pool */ + clickFolder(FOLDER_NAME); + clickAndWait(Locator.linkWithText("Search for Peptides by Criteria")); + selectOptionByText(Locator.name("queryKey"), "Peptides in a Peptide Pool"); + selectOptionByTextContaining(getDriver().findElement(Locator.name("queryValue")), "Prac_Pool"); + + clickAndWait(Locator.name("action_type")); + + // Identify the index at which our peptide IDs start. + findPeptideStartIndex(); + // List the peptides in the the 'gagptegprac' Peptide Group. We expect there to be 16 of them. + clickFolder(FOLDER_NAME); + clickAndWait(Locator.linkWithText("Search for Peptides by Criteria")); + waitForText("Search for Peptides using different criteria : "); + selectOptionByText(Locator.id("queryKey"), "Peptides in a Peptide Group"); + selectOptionByText(Locator.id("queryValue"), "gagptegprac"); + + clickAndWait(Locator.name("action_type")); + + assertTextPresentInThisOrder("There are (16) peptides in the 'gagptegprac' peptide group."); + // Select a newly uploaded peptide, #3 and edit it to have a storage location of 'Kitchen Sink' + clickAndWait(Locator.linkWithText(pepString(4))); + // Verify the expected record's content + assertTrue(getDriver().findElement(Locator.xpath("//form[@lk-region-form='peptides']/table/tbody")).getText().matches("^[\\s\\S]*Peptide Id:\\s*" + pepString(4) + "\nPeptide Sequence:\\s*REPRGSDIAGTTSTL\nProtein Category:\\s*p24\nSequence Length:\\s*15\nAAStart:\\s*97\nAAEnd:\\s*111\nIs Child:\\s*false\nIs Parent:\\s*false[\\s\\S]*$")); + + clickAndWait(Locator.linkWithText("Edit Peptide")); + setFormElement(Locator.name("storage_location"), "Kitchen Sink"); + clickAndWait(Locator.xpath("//span[text()='Save Changes']")); + + // Assert that the Storage Location now contains "Kitchen Sink" + assertTrue(getDriver().findElement(Locator.xpath("//form[@lk-region-form='peptides']/table/tbody")).getText().matches("^[\\s\\S]*Peptide Id:\\s*" + pepString(4) + "\nPeptide Sequence:\\s*REPRGSDIAGTTSTL\nProtein Category:\\s*p24\nSequence Length:\\s*15\nAAStart:\\s*97\nAAEnd:\\s*111\nIs Child:\\s*false\nIs Parent:\\s*false[\\s\\S]*$")); + clickAndWait(Locator.css("a.labkey-button > span")); + + // Search for a single, newly-uploaded peptide and verify it displays as expected. + setFormElement(Locator.name("peptide_id"), Integer.toString(peptideStartIndex + 9)); + clickButton("Find"); + // Verify the expected record's content + assertTrue(getDriver().findElement(Locator.tagWithAttribute("form", "lk-region-form", "peptides")).getText() + .matches("^[\\s\\S]*Peptide Id:\\s*" + pepString(9) + "\nPeptide Sequence:\\s*KCGKEGHQMKDCTER\nProtein Category:\\s*p2p7p1p6\nSequence Length:\\s*15\nAAStart:\\s*52\nAAEnd:\\s*66\nIs Child:\\s*false\nIs Parent:\\s*false\nStorage Location:\\s*\n[\\s\\S]*$")); + + clickAndWait(Locator.css("a.labkey-button > span")); + + + /* + * + * 'Search for Peptides by Criteria' using 'Peptides in a Peptide Pool' + * using the newly imported Peptide Pool. + * + * Verify that the peptides found match what was expected (by the pool import), and their values include the + * columns imported earlier during the importing of the peptides. + * + */ + clickFolder(FOLDER_NAME); + clickAndWait(Locator.linkWithText("Search for Peptides by Criteria")); + selectOptionByText(Locator.id("queryKey"), "Peptides in a Peptide Pool"); + + selectOptionByTextContaining(getDriver().findElement(Locator.name("queryValue")), "Prac_Pool"); + clickAndWait(Locator.name("action_type")); + clickAndWait(Locator.linkWithText(pepString(4))); + + checker().verifyEquals("", "Peptide Sequence:", getDriver().findElement(Locator.xpath("//form[@lk-region-form='peptides']/table/tbody/tr[2]/td")).getText()); + checker().verifyEquals("", "REPRGSDIAGTTSTL", getDriver().findElement(Locator.xpath("//form[@lk-region-form='peptides']/table/tbody/tr[2]/td[2]")).getText()); + checker().verifyEquals("", "gagptegprac (PEPTIDE NUMBER =GAG1-4)", getDriver().findElement(Locator.css(".lk-body-ct div:nth-of-type(2) > table > tbody > tr > td")).getText()); + } + + @LogMethod + private void cleanupSchema() throws IOException, CommandException + { + Connection cn = createDefaultConnection(); + + cleanupTable(cn, "pepdb", "peptide_pool_assignment"); + cleanupTable(cn, "pepdb", "peptide_group_assignment"); + cleanupTable(cn, "pepdb", "peptides"); + cleanupTable(cn, "pepdb", "peptide_pool"); + cleanupTable(cn, "pepdb", "peptide_group"); + + } + + @LogMethod + private void cleanupTable(Connection cn, String schemaName, String tableName) throws IOException, CommandException + { + SelectRowsCommand selectCmd = new SelectRowsCommand(schemaName, tableName); + selectCmd.setMaxRows(-1); + selectCmd.setContainerFilter(ContainerFilter.AllFolders); + selectCmd.setColumns(Arrays.asList("*")); + SelectRowsResponse selectResp = selectCmd.execute(cn, getProjectName()); + if (selectResp.getRowCount().intValue() > 0) + { + DeleteRowsCommand deleteCmd = new DeleteRowsCommand(schemaName, tableName); + deleteCmd.setRows(selectResp.getRows()); + deleteCmd.execute(cn, getProjectName()); + assertEquals("Expected no rows remaining", 0, selectCmd.execute(cn, getProjectName()).getRowCount().intValue()); + } + } + + // We have to expose our schema as an external schema in order to run the selectRow and deleteRow commands. + void ensureExternalSchema(String containerPath) + { + log("** Ensure ExternalSchema: " + USER_SCHEMA_NAME); + + beginAt(WebTestHelper.buildURL("query", containerPath, "admin")); + + if (!isTextPresent("reload")) + { + assertTextPresent("new external schema"); + log("** Creating ExternalSchema: " + USER_SCHEMA_NAME); + clickAndWait(Locator.linkWithText("new external schema")); + checkCheckbox(Locator.name("includeSystem")); + setFormElement(Locator.name("userSchemaName"), USER_SCHEMA_NAME); + setFormElement(Locator.name("sourceSchemaName"), USER_SCHEMA_NAME); + pressEnter(Locator.name("sourceSchemaName")); + checkCheckbox(Locator.name("editable")); + uncheckCheckbox(Locator.name("indexable")); + clickButton("Create"); + } + assertTextPresent(USER_SCHEMA_NAME); + assertTextNotPresent("reload all schemas"); // Present only for external schemas > 1 + } + + // Identify the index at which our peptide IDs start. + private void findPeptideStartIndex() throws IOException + { + Connection cn = createDefaultConnection(); + try + { + ensureExternalSchema(getProjectName()); + SelectRowsCommand selectCmd = new SelectRowsCommand("pepdb", "peptides"); + selectCmd.setMaxRows(1); + selectCmd.setContainerFilter(ContainerFilter.AllFolders); + selectCmd.setColumns(Arrays.asList("*")); + SelectRowsResponse selectResp = selectCmd.execute(cn, getProjectName()); + + if (selectResp.getRowCount().intValue() > 0) + { + Row convertedRow = new RowMap(selectResp.getRows().get(0)); + peptideStartIndex = ((int) convertedRow.getValue("peptide_id")) - 1; + } + } + catch (CommandException e) + { + log("** Error during findPeptideStartIndex:"); + e.printStackTrace(System.out); + } + } + + // Convert the peptide ID integer into its string representation. + private String pepString(int peptideIdOffset) + { + //return String.format("P%06d", peptideStartIndex + peptideIdOffset); + return String.format("P%d", peptideStartIndex + peptideIdOffset); + } + + protected void assertModuleDeployed(String moduleName) + { + log("Ensuring that that '" + moduleName + "' module is deployed"); + goToAdminConsole(); + assertTextPresent(moduleName); + } + + protected void assertModuleEnabled(String moduleName) + { + log("Ensuring that that '" + moduleName + "' module is enabled"); + goToFolderManagement(); + clickAndWait(Locator.linkWithText("Folder Type")); + assertElementPresent(Locator.xpath("//input[@type='checkbox' and @checked and @title='" + moduleName + "']")); + } + + protected void assertModuleEnabledByDefault(String moduleName) + { + log("Ensuring that that '" + moduleName + "' module is enabled"); + goToFolderManagement(); + clickAndWait(Locator.linkWithText("Folder Type")); + assertElementPresent(Locator.xpath("//input[@type='checkbox' and @checked and @disabled and @title='" + moduleName + "']")); + } + + @Override + protected void doCleanup(boolean afterTest) throws TestTimeoutException + { + if (afterTest) + { + try + { + cleanupSchema(); + } + catch (IOException | CommandException e) + { + throw new RuntimeException(e); + } + } + _containerHelper.deleteProject(getProjectName(), afterTest); + } + + @Override + public List getAssociatedModules() + { + return Arrays.asList("pepdb"); + } + + public static File getSampleData(String sampleDataPath) + { + return TestFileUtils.getSampleData("test_import_files" + sampleDataPath); + } +} diff --git a/trialShare/.gitattributes b/trialShare/.gitattributes new file mode 100644 index 00000000..176a458f --- /dev/null +++ b/trialShare/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/trialShare/.gitignore b/trialShare/.gitignore new file mode 100644 index 00000000..32858aad --- /dev/null +++ b/trialShare/.gitignore @@ -0,0 +1,12 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/trialShare/LICENSE.txt b/trialShare/LICENSE.txt new file mode 100644 index 00000000..8f71f43f --- /dev/null +++ b/trialShare/LICENSE.txt @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/trialShare/build.gradle b/trialShare/build.gradle new file mode 100644 index 00000000..75fb6e8b --- /dev/null +++ b/trialShare/build.gradle @@ -0,0 +1,12 @@ +import org.labkey.gradle.util.BuildUtils + +plugins { + id 'org.labkey.build.module' +} + +dependencies { + BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: BuildUtils.getPlatformModuleProjectPath(project.gradle, "study"), depProjectConfig: "apiJarFile") + BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: BuildUtils.getPlatformModuleProjectPath(project.gradle, "study"), depProjectConfig: "published", depExtension: "module") + BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: BuildUtils.getPlatformModuleProjectPath(project.gradle, "specimen"), depProjectConfig: "published", depExtension: "module") +} + diff --git a/trialShare/module.properties b/trialShare/module.properties new file mode 100644 index 00000000..e5f6e94e --- /dev/null +++ b/trialShare/module.properties @@ -0,0 +1,8 @@ +ModuleClass: org.labkey.trialshare.TrialShareModule +Label: Custom specimen behavior and Data Finder configuration for ITN +Description: Overrides some behavior of the specimen module and provides Data Finder cube definitions for ITN. +URL: https://www.itntrialshare.org +License: Apache 2.0 +LicenseURL: http://www.apache.org/licenses/LICENSE-2.0 +SupportedDatabases: mssql, pgsql +ManageVersion: true diff --git a/trialShare/resources/olap/ITN_PublicationCube.xml b/trialShare/resources/olap/ITN_PublicationCube.xml new file mode 100644 index 00000000..32705231 --- /dev/null +++ b/trialShare/resources/olap/ITN_PublicationCube.xml @@ -0,0 +1,41 @@ + + + + + + FALSE + + + + + + + + + +
+ + + true + + + + +
+
+ + + + + + + true + + + + + + + + + diff --git a/trialShare/resources/olap/ITN_StudyCube.xml b/trialShare/resources/olap/ITN_StudyCube.xml new file mode 100644 index 00000000..7fe29f68 --- /dev/null +++ b/trialShare/resources/olap/ITN_StudyCube.xml @@ -0,0 +1,51 @@ + + + + + + FALSE + + +
+ + + + + + + + + + + + + +
+ + + true + + + +
+ + + +
+ + + +
+ + + +
+ + + + + + + + + diff --git a/trialShare/src/org/labkey/trialshare/DelegatingSpecimenRequestCustomizer.java b/trialShare/src/org/labkey/trialshare/DelegatingSpecimenRequestCustomizer.java new file mode 100644 index 00000000..d72417e7 --- /dev/null +++ b/trialShare/src/org/labkey/trialshare/DelegatingSpecimenRequestCustomizer.java @@ -0,0 +1,66 @@ +package org.labkey.trialshare; + +import org.labkey.api.data.Container; +import org.labkey.api.security.User; +import org.labkey.api.settings.AdminConsole; +import org.labkey.api.settings.OptionalFeatureService; +import org.labkey.api.study.SpecimenService; +import org.labkey.api.util.HtmlString; + +/** Decides whether to supply the default behavior or an ITN-specific one based on an experimental feature flag */ +public class DelegatingSpecimenRequestCustomizer implements SpecimenService.SpecimenRequestCustomizer +{ + private final SpecimenService.SpecimenRequestCustomizer _default; + private final SpecimenService.SpecimenRequestCustomizer _itn = new ITNSpecimenRequestCustomizer(); + private SpecimenService.SpecimenRequestCustomizer _active; + + private static final String ITN_SPECIMEN_HANDLING_FEATURE_NAME = "ITNSpecimenHandling"; + + public DelegatingSpecimenRequestCustomizer(SpecimenService.SpecimenRequestCustomizer defaultCustomizer) + { + _default = defaultCustomizer; + + _active = OptionalFeatureService.get().isFeatureEnabled(ITN_SPECIMEN_HANDLING_FEATURE_NAME) ? _itn : _default; + + AdminConsole.addExperimentalFeatureFlag(ITN_SPECIMEN_HANDLING_FEATURE_NAME, "ITN specimen behavior", + "This feature allows empty specimen requests, adds ITN-specific messages, hides some reporting options, and other tweaks", false); + + OptionalFeatureService.get().addFeatureListener(ITN_SPECIMEN_HANDLING_FEATURE_NAME, (feature, enabled) -> _active = enabled ? _itn : _default); + } + + @Override + public boolean allowEmptyRequests() + { + return _active.allowEmptyRequests(); + } + + @Override + public Integer getDefaultDestinationSiteId() + { + return _active.getDefaultDestinationSiteId(); + } + + @Override + public boolean omitTypeGroupingsWhenReporting() + { + return _active.omitTypeGroupingsWhenReporting(); + } + + @Override + public boolean canChangeStatus(User user) + { + return _active.canChangeStatus(user); + } + + @Override + public boolean hideRequestWarnings() + { + return _active.hideRequestWarnings(); + } + + @Override + public HtmlString getSubmittedMessage(Container c, int requestId) + { + return _active.getSubmittedMessage(c, requestId); + } +} diff --git a/trialShare/src/org/labkey/trialshare/ITNSpecimenRequestCustomizer.java b/trialShare/src/org/labkey/trialshare/ITNSpecimenRequestCustomizer.java new file mode 100644 index 00000000..e342c72e --- /dev/null +++ b/trialShare/src/org/labkey/trialshare/ITNSpecimenRequestCustomizer.java @@ -0,0 +1,69 @@ +package org.labkey.trialshare; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.labkey.api.data.Container; +import org.labkey.api.data.ContainerManager; +import org.labkey.api.security.Group; +import org.labkey.api.security.GroupManager; +import org.labkey.api.security.User; +import org.labkey.api.study.SpecimenUrls; +import org.labkey.api.study.SpecimenService; +import org.labkey.api.util.HtmlString; +import org.labkey.api.util.PageFlowUtil; +import org.labkey.security.xml.GroupEnumType; + +import static org.labkey.api.util.PageFlowUtil.link; + +public class ITNSpecimenRequestCustomizer implements SpecimenService.SpecimenRequestCustomizer +{ + private static final Logger LOG = LogManager.getLogger(ITNSpecimenRequestCustomizer.class); + + @Override + public boolean allowEmptyRequests() + { + return true; + } + + @Override + public Integer getDefaultDestinationSiteId() + { + return 9999999; + } + + @Override + public boolean omitTypeGroupingsWhenReporting() + { + return true; + } + + @Override + public boolean canChangeStatus(User user) + { + Group specimenRequestAdmins = GroupManager.getGroup(ContainerManager.getRoot(), "Specimen Request Administrators", GroupEnumType.SITE); + if (specimenRequestAdmins != null) + { + return user.hasSiteAdminPermission() || user.isInGroup(specimenRequestAdmins.getUserId()); + } + LOG.error("Unable to find site group \"Specimen Request Administrators\", allowing user to update specimen request status"); + return true; + } + + @Override + public HtmlString getSubmittedMessage(Container c, int requestId) + { + SpecimenUrls specimenUrls = PageFlowUtil.urlProvider(SpecimenUrls.class); + return HtmlString.unsafe("Thank you for your request. A representative from the ITN will be in touch " + + "with you. You can also contact us at " + + link("trialsharesupport@immunetolerance.org").href("mailto:trialsharesupport@immunetolerance.org?Body=" + PageFlowUtil.filter(specimenUrls.getManageRequestURL(c, requestId).getURIString())).clearClasses() + + " to follow up with us regarding this request.
" + + "You may also update this request at any calendar to add comments or supporting " + + "documents by clicking here " + link("Update Request").href(specimenUrls.getManageRequestStatusURL(c, requestId))); + } + + @Override + public boolean hideRequestWarnings() + { + return true; + } +} diff --git a/trialShare/src/org/labkey/trialshare/StudyITNFolderType.java b/trialShare/src/org/labkey/trialshare/StudyITNFolderType.java new file mode 100644 index 00000000..2114a576 --- /dev/null +++ b/trialShare/src/org/labkey/trialshare/StudyITNFolderType.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.labkey.trialshare; + +import org.jetbrains.annotations.NotNull; +import org.labkey.api.module.MultiPortalFolderType; +import org.labkey.api.specimen.SpecimensPage; +import org.labkey.api.study.Study; +import org.labkey.api.study.StudyFolderTabs; +import org.labkey.api.study.StudyService; +import org.labkey.api.view.FolderTab; +import org.labkey.api.view.Portal; +import org.labkey.api.view.ViewContext; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * User: Nick + * Date: 7/22/11 + */ +public class StudyITNFolderType extends MultiPortalFolderType +{ + private static final String STUDY_ITN_FOLDER_TYPE_NAME = "Study (ITN)"; + + private static final List PAGES = List.of( + new StudyFolderTabs.OverviewPage("Overview"), + new StudyFolderTabs.DataAnalysisPage("Data & Reports"), + new StudyFolderTabs.ParticipantsPage("Participants"), + new SpecimensPage("Specimens"), + new StudyFolderTabs.ManagePage("Manage") + ); + + StudyITNFolderType(TrialShareModule module) + { + super(STUDY_ITN_FOLDER_TYPE_NAME, + "Standard Study folder type with tabs pre-configured for ITN TrialShare.", + Collections.singletonList(Portal.getPortalPart("Study Overview").createWebPart()), + null, + getDefaultModuleSet(module, getModule("Experiment"), getModule("Study"), getModule("Pipeline")), + getModule("Study")); + } + + @NotNull + @Override + public Set getLegacyNames() + { + return Collections.singleton("Study Redesign (ITN)"); + } + + @Override + protected String getFolderTitle(ViewContext ctx) + { + Study study = StudyService.get().getStudy(ctx.getContainer()); + return study != null ? study.getLabel() : ctx.getContainer().getName(); + } + + @Override + public String getStartPageLabel(ViewContext ctx) + { + Study study = StudyService.get().getStudy(ctx.getContainer()); + return study == null ? "New Study" : study.getLabel(); + } + + @Override + public List getDefaultTabs() + { + return PAGES; + } +} \ No newline at end of file diff --git a/trialShare/src/org/labkey/trialshare/TrialShareController.java b/trialShare/src/org/labkey/trialshare/TrialShareController.java new file mode 100644 index 00000000..58638335 --- /dev/null +++ b/trialShare/src/org/labkey/trialshare/TrialShareController.java @@ -0,0 +1,736 @@ +/* + * Copyright (c) 2015-2019 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.labkey.trialshare; + +import org.apache.logging.log4j.LogManager; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; +import org.junit.Test; +import org.labkey.api.action.ApiResponse; +import org.labkey.api.action.ApiSimpleResponse; +import org.labkey.api.action.Marshal; +import org.labkey.api.action.Marshaller; +import org.labkey.api.action.MutatingApiAction; +import org.labkey.api.action.SpringActionController; +import org.labkey.api.admin.AbstractFolderContext.ExportType; +import org.labkey.api.admin.FolderExportContext; +import org.labkey.api.admin.FolderSerializationRegistry; +import org.labkey.api.admin.FolderWriter; +import org.labkey.api.admin.FolderWriterImpl; +import org.labkey.api.admin.StaticLoggerGetter; +import org.labkey.api.data.Container; +import org.labkey.api.data.PHI; +import org.labkey.api.pipeline.PipeRoot; +import org.labkey.api.pipeline.PipelineService; +import org.labkey.api.pipeline.PipelineUrls; +import org.labkey.api.qc.SampleStatusService; +import org.labkey.api.security.IgnoresTermsOfUse; +import org.labkey.api.security.RequiresPermission; +import org.labkey.api.security.permissions.AdminPermission; +import org.labkey.api.util.PageFlowUtil; +import org.labkey.api.view.ActionURL; +import org.labkey.api.view.NotFoundException; +import org.labkey.api.writer.FileSystemFile; +import org.springframework.validation.BindException; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Marshal(Marshaller.Jackson) +public class TrialShareController extends SpringActionController +{ + private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(TrialShareController.class); + static final String NAME = "trialshare"; + + public TrialShareController() + { + setActionResolver(_actionResolver); + } + + /* + TrialShare: simple study export action: + + example usage (via LabKey Remote Java API): + + SimplePostCommand pc = new SimplePostCommand("pipeline","TrialShareExport"); + JSONObject jo = new JSONObject(); + pc.setJsonObject(jo); + CommandResponse cr = pc.execute(cn, "/Studies/ITN027AIOPR/Study Data/"); + System.out.println(cr.getText()); + */ + + public static class TrialShareExportForm + { + private boolean missingValueIndicators; + private boolean study; + private boolean assayDatasets; + private boolean assaySchedule; + private boolean categories; + private boolean cohortSettings; + private boolean crfDatasets; + private boolean customParticipantView; + private boolean datasetData; + private boolean etlDefinitions; + private boolean participantCommentSettings; + private boolean participantGroups; + private boolean protocolDocuments; + private boolean qcStateSettings; + private boolean specimenSettings; + private boolean specimens; + private boolean treatmentData; + private boolean visitMap; + private boolean folderTypeAndActiveModules; + private boolean fullTextSearchSettings; + private boolean webpartPropertiesAndLayout; + private boolean containerSpecificModuleProperties; + private boolean roleAssignmentsForUsersAndGroups; + private boolean listDesigns; + private boolean listData; + private boolean queries; + private boolean gridViews; + private boolean reportsAndCharts; + private boolean externalSchemaDefinitions; + private boolean wikisAndTheirAttachments; + private boolean notificationSettings; + private boolean sampleTypeDesigns; + private boolean sampleTypeData; + private boolean dataClassDesigns; + private boolean dataClassData; + private boolean inventoryLocationsAndItems; + private boolean experimentsAndRuns; + + public boolean getMissingValueIndicators() + { + return missingValueIndicators; + } + + public void setMissingValueIndicators(boolean missingValueIndicators) + { + this.missingValueIndicators = missingValueIndicators; + } + + public boolean getStudy() + { + return study; + } + + public void setStudy(boolean study) + { + this.study = study; + } + + public boolean getAssayDatasets() + { + return assayDatasets; + } + + public void setAssayDatasets(boolean assayDatasets) + { + this.assayDatasets = assayDatasets; + } + + public boolean getAssaySchedule() + { + return assaySchedule; + } + + public void setAssaySchedule(boolean assaySchedule) + { + this.assaySchedule = assaySchedule; + } + + public boolean getCategories() + { + return categories; + } + + public void setCategories(boolean categories) + { + this.categories = categories; + } + + public boolean getCohortSettings() + { + return cohortSettings; + } + + public void setCohortSettings(boolean cohortSettings) + { + this.cohortSettings = cohortSettings; + } + + public boolean getCrfDatasets() + { + return crfDatasets; + } + + public void setCrfDatasets(boolean crfDatasets) + { + this.crfDatasets = crfDatasets; + } + + public boolean getEtlDefinitions() + { + return etlDefinitions; + } + + public void setEtlDefinitions(boolean etlDefinitions) + { + this.etlDefinitions = etlDefinitions; + } + + public boolean getCustomParticipantView() + { + return customParticipantView; + } + + public void setCustomParticipantView(boolean customParticipantView) + { + this.customParticipantView = customParticipantView; + } + + public boolean getDatasetData() + { + return datasetData; + } + + public void setDatasetData(boolean datasetData) + { + this.datasetData = datasetData; + } + + public boolean getParticipantCommentSettings() + { + return participantCommentSettings; + } + + public void setParticipantCommentSettings(boolean participantCommentSettings) + { + this.participantCommentSettings = participantCommentSettings; + } + + public boolean getParticipantGroups() + { + return participantGroups; + } + + public void setParticipantGroups(boolean participantGroups) + { + this.participantGroups = participantGroups; + } + + public boolean getProtocolDocuments() + { + return protocolDocuments; + } + + public void setProtocolDocuments(boolean protocolDocuments) + { + this.protocolDocuments = protocolDocuments; + } + + public boolean getQcStateSettings() + { + return qcStateSettings; + } + + public void setQcStateSettings(boolean qcStateSettings) + { + this.qcStateSettings = qcStateSettings; + } + + public boolean getSpecimenSettings() + { + return specimenSettings; + } + + public void setSpecimenSettings(boolean specimenSettings) + { + this.specimenSettings = specimenSettings; + } + + public boolean getSpecimens() + { + return specimens; + } + + public void setSpecimens(boolean specimens) + { + this.specimens = specimens; + } + + public boolean getTreatmentData() + { + return treatmentData; + } + + public void setTreatmentData(boolean treatmentData) + { + this.treatmentData = treatmentData; + } + + public boolean getVisitMap() + { + return visitMap; + } + + public void setVisitMap(boolean visitMap) + { + this.visitMap = visitMap; + } + + public boolean getFolderTypeAndActiveModules() + { + return folderTypeAndActiveModules; + } + + public void setFolderTypeAndActiveModules(boolean folderTypeAndActiveModules) + { + this.folderTypeAndActiveModules = folderTypeAndActiveModules; + } + + public boolean getFullTextSearchSettings() + { + return fullTextSearchSettings; + } + + public void setFullTextSearchSettings(boolean fullTextSearchSettings) + { + this.fullTextSearchSettings = fullTextSearchSettings; + } + + public boolean getWebpartPropertiesAndLayout() + { + return webpartPropertiesAndLayout; + } + + public void setWebpartPropertiesAndLayout(boolean webpartPropertiesAndLayout) + { + this.webpartPropertiesAndLayout = webpartPropertiesAndLayout; + } + + public boolean getContainerSpecificModuleProperties() + { + return containerSpecificModuleProperties; + } + + public void setContainerSpecificModuleProperties(boolean containerSpecificModuleProperties) + { + this.containerSpecificModuleProperties = containerSpecificModuleProperties; + } + + public boolean getRoleAssignmentsForUsersAndGroups() + { + return roleAssignmentsForUsersAndGroups; + } + + public void setRoleAssignmentsForUsersAndGroups(boolean roleAssignmentsForUsersAndGroups) + { + this.roleAssignmentsForUsersAndGroups = roleAssignmentsForUsersAndGroups; + } + + public boolean isListDesigns() + { + return listDesigns; + } + + public void setListDesigns(boolean listDesigns) + { + this.listDesigns = listDesigns; + } + + public boolean isListData() + { + return listData; + } + + public void setListData(boolean listData) + { + this.listData = listData; + } + + public boolean getQueries() + { + return queries; + } + + public void setQueries(boolean queries) + { + this.queries = queries; + } + + public boolean getGridViews() + { + return gridViews; + } + + public void setGridViews(boolean gridViews) + { + this.gridViews = gridViews; + } + + public boolean getReportsAndCharts() + { + return reportsAndCharts; + } + + public void setReportsAndCharts(boolean reportsAndCharts) + { + this.reportsAndCharts = reportsAndCharts; + } + + public boolean getExternalSchemaDefinitions() + { + return externalSchemaDefinitions; + } + + public void setExternalSchemaDefinitions(boolean externalSchemaDefinitions) + { + this.externalSchemaDefinitions = externalSchemaDefinitions; + } + + public boolean getWikisAndTheirAttachments() + { + return wikisAndTheirAttachments; + } + + public void setWikisAndTheirAttachments(boolean wikisAndTheirAttachments) + { + this.wikisAndTheirAttachments = wikisAndTheirAttachments; + } + + public boolean getNotificationSettings() + { + return notificationSettings; + } + + public void setNotificationSettings(boolean notificationSettings) + { + this.notificationSettings = notificationSettings; + } + + public boolean getSampleTypeDesigns() + { + return sampleTypeDesigns; + } + + public void setSampleTypeDesigns(boolean sampleTypeDesigns) + { + this.sampleTypeDesigns = sampleTypeDesigns; + } + + public boolean getSampleTypeData() + { + return sampleTypeData; + } + + public void setSampleTypeData(boolean sampleTypeData) + { + this.sampleTypeData = sampleTypeData; + } + + public boolean getDataClassDesigns() + { + return dataClassDesigns; + } + + public void setDataClassDesigns(boolean dataClassDesigns) + { + this.dataClassDesigns = dataClassDesigns; + } + + public boolean getDataClassData() + { + return dataClassData; + } + + public void setDataClassData(boolean dataClassData) + { + this.dataClassData = dataClassData; + } + + public boolean getInventoryLocationsAndItems() + { + return inventoryLocationsAndItems; + } + + public void setInventoryLocationsAndItems(boolean inventoryLocationsAndItems) + { + this.inventoryLocationsAndItems = inventoryLocationsAndItems; + } + + public boolean getExperimentsAndRuns() + { + return experimentsAndRuns; + } + + public void setExperimentsAndRuns(boolean experimentsAndRuns) + { + this.experimentsAndRuns = experimentsAndRuns; + } + } + + /* + todo: explain who uses this and why + */ + @RequiresPermission(AdminPermission.class) + @IgnoresTermsOfUse + public class TrialShareExportAction extends MutatingApiAction + { + private ActionURL _successURL; + + @Override + public ApiResponse execute(TrialShareExportForm form, BindException errors) throws Exception + { + // JSONObject json = form.getJsonObject(); + ApiSimpleResponse response = new ApiSimpleResponse(); + + Container container = getContainer(); + if (container.isRoot()) + { + throw new NotFoundException(); + } + + FolderWriterImpl writer = new FolderWriterImpl(); + + Set types = new HashSet<>(); + + for (FolderDataTypes type : FolderDataTypes.values()) + { + if (type.shouldExport(form)) + types.add(type); + } + + if(types.isEmpty()) + { + types = getDefaultExportDataTypes(); + } + + // todo: super important boolean false in 17.2 replaced by PHI enum. what is new correct setting? PHI.Limited + FolderExportContext ctx = new FolderExportContext(getUser(), container, types.stream().map(FolderDataTypes::getDescription).collect(Collectors.toSet()), + "new", false, PHI.NotPHI, false, + false, false, new StaticLoggerGetter(LogManager.getLogger(FolderWriterImpl.class))); + + PipeRoot root = PipelineService.get().findPipelineRoot(container); + if (root == null || !root.isValid()) + { + throw new NotFoundException("No valid pipeline root found"); + } + File exportDir = root.resolvePath("export"); + try + { + writer.write(container, ctx, new FileSystemFile(exportDir)); + } + catch (Container.ContainerException e) + { + errors.reject(SpringActionController.ERROR_MSG, e.getMessage()); + response.put("success", false); + response.put("reason", e.getMessage()); + return response; + } + _successURL = PageFlowUtil.urlProvider(PipelineUrls.class).urlBrowse(container); + + response.put("success", true); + return response; + } + } + + @NotNull + private static Set getDefaultExportDataTypes() + { + return Set.of( + FolderDataTypes.folderTypeAndActiveModules, + FolderDataTypes.fullTextSearchSettings, + FolderDataTypes.webpartProperties, + FolderDataTypes.moduleProperties, + FolderDataTypes.qcStateSettings, + + FolderDataTypes.mvIndicators, + FolderDataTypes.study, + FolderDataTypes.assayDatasetData, + FolderDataTypes.assayDatasetDefinitions, + FolderDataTypes.assaySchedule, + FolderDataTypes.categories, + FolderDataTypes.cohortSettings, + FolderDataTypes.customParticipantView, + FolderDataTypes.sampleDatasetData, + FolderDataTypes.sampleDatasetDefinitions, + FolderDataTypes.studyDatasetData, + FolderDataTypes.studyDatasetDefinitions, + FolderDataTypes.participantCommentSettings, + FolderDataTypes.participantGroups, + FolderDataTypes.protocolDocuments, + FolderDataTypes.specimenSettings, + FolderDataTypes.specimens, + FolderDataTypes.treatmentData, + FolderDataTypes.visitMap, + FolderDataTypes.queries, + FolderDataTypes.gridViews, + FolderDataTypes.reportsAndCharts, + FolderDataTypes.externalSchemaDefinitions, + FolderDataTypes.etlDefinitions, + FolderDataTypes.listDesigns, + FolderDataTypes.listData, + FolderDataTypes.wikisAndAttachments, + FolderDataTypes.notificationSettings, + FolderDataTypes.sampleTypeDesigns, + FolderDataTypes.sampleTypeData, + FolderDataTypes.dataClassDesigns, + FolderDataTypes.dataClassData, + FolderDataTypes.inventoryLocationsAndItems, + FolderDataTypes.experiments + ); + } + + enum FolderDataTypes + { + mvIndicators("Missing value indicators", TrialShareExportForm::getMissingValueIndicators), + study("Study", TrialShareExportForm::getStudy), + assayDatasetDefinitions("Datasets: Assay Dataset Definitions", TrialShareExportForm::getAssayDatasets), + assayDatasetData("Datasets: Assay Dataset Data", TrialShareExportForm::getAssayDatasets), + assaySchedule("Assay Schedule", TrialShareExportForm::getAssaySchedule), + categories("Categories", TrialShareExportForm::getCategories), + cohortSettings("Cohort Settings", TrialShareExportForm::getCohortSettings), + customParticipantView("Custom Participant View", TrialShareExportForm::getCustomParticipantView), + sampleDatasetData("Datasets: Sample Dataset Data", TrialShareExportForm::getDatasetData), + sampleDatasetDefinitions("Datasets: Sample Dataset Definitions", TrialShareExportForm::getDatasetData), + studyDatasetData("Datasets: Study Dataset Data", TrialShareExportForm::getCrfDatasets), + studyDatasetDefinitions("Datasets: Study Dataset Definitions", TrialShareExportForm::getCrfDatasets), + etlDefinitions("ETL Definitions", TrialShareExportForm::getEtlDefinitions), + participantCommentSettings("Participant Comment Settings", TrialShareExportForm::getParticipantCommentSettings), + participantGroups("Participant Groups", TrialShareExportForm::getParticipantGroups), + protocolDocuments("Protocol Documents", TrialShareExportForm::getProtocolDocuments), + qcStateSettings(SampleStatusService.get().supportsSampleStatus() ? "Sample Status and QC State Settings" : "QC State Settings", TrialShareExportForm::getQcStateSettings), + specimenSettings("Specimen Settings", TrialShareExportForm::getSpecimenSettings), + specimens("Specimens", TrialShareExportForm::getSpecimens), + treatmentData("Treatment Data", TrialShareExportForm::getTreatmentData), + visitMap("Visit Map", TrialShareExportForm::getVisitMap), + folderTypeAndActiveModules("Folder type and active modules", TrialShareExportForm::getFolderTypeAndActiveModules), + fullTextSearchSettings("Full-text search settings", TrialShareExportForm::getFullTextSearchSettings), + webpartProperties("Webpart properties and layout", TrialShareExportForm::getWebpartPropertiesAndLayout), + moduleProperties("Container specific module properties", TrialShareExportForm::getContainerSpecificModuleProperties), + roleAssignments("Role assignments for users and groups", TrialShareExportForm::getRoleAssignmentsForUsersAndGroups), + listDesigns("List Designs", TrialShareExportForm::isListDesigns), + listData("List Data", TrialShareExportForm::isListData), + queries("Queries", TrialShareExportForm::getQueries), + gridViews("Grid Views", TrialShareExportForm::getGridViews), + reportsAndCharts("Reports and Charts", TrialShareExportForm::getReportsAndCharts), + externalSchemaDefinitions("External schema definitions", TrialShareExportForm::getExternalSchemaDefinitions), + wikisAndAttachments("Wikis and their attachments", TrialShareExportForm::getWikisAndTheirAttachments), + notificationSettings("Notification settings", TrialShareExportForm::getNotificationSettings), + sampleTypeDesigns("Sample Type Designs", TrialShareExportForm::getSampleTypeDesigns), + sampleTypeData("Sample Type Data", TrialShareExportForm::getSampleTypeData), + dataClassDesigns("Data Class Designs", TrialShareExportForm::getDataClassDesigns), + dataClassData("Data Class Data", TrialShareExportForm::getDataClassData), + inventoryLocationsAndItems("Inventory locations and items", TrialShareExportForm::getInventoryLocationsAndItems), + experiments("Experiments, Protocols, and Runs", TrialShareExportForm::getExperimentsAndRuns); + + private final String _description; + private final Function _formChecker; + + FolderDataTypes(String description, Function formChecker) + { + _description = description; + _formChecker = formChecker; + } + + public String getDescription() + { + return _description; + } + + public boolean shouldExport(TrialShareExportForm form) + { + return _formChecker.apply(form); + } + } + + public static class TrialShareExportTest + { + // ignore these export types because they won't appear in the folder export UI + private static final Set _ignoredFolderWriters = Set.of("Notebooks", "LabBooks"); + + private final Collection folderWriters = FolderSerializationRegistry.get().getRegisteredFolderWriters().stream() + .filter(fw -> !_ignoredFolderWriters.contains(fw.getDataType())) + .collect(Collectors.toList()); + + @Test + public void testDataTypes() + { + final Set expectedDataTypes = Arrays.stream(FolderDataTypes.values()).map(FolderDataTypes::getDescription).collect(Collectors.toSet()); + final Set actualDataTypes = getRegisteredDataTypes(false); + + Iterator iterator = expectedDataTypes.iterator(); + while (iterator.hasNext()) + { + String expectedDataType = iterator.next(); + if (actualDataTypes.contains(expectedDataType)) + { + iterator.remove(); + actualDataTypes.remove(expectedDataType); + } + } + + if (!expectedDataTypes.isEmpty()) + { + Assert.fail("Did not find expected data type(s): " + expectedDataTypes + ". Unaccounted for data types: " + actualDataTypes); + } + } + + @Test + public void testDefaultDataTypes() + { + final List expectedDataTypes = getDefaultExportDataTypes().stream().map(FolderDataTypes::getDescription).collect(Collectors.toList()); + final List actualDefaultDataTypes = new ArrayList<>(getRegisteredDataTypes(true)); + + // Sort to make error message more readable + Collections.sort(expectedDataTypes); + Collections.sort(actualDefaultDataTypes); + + expectedDataTypes.removeAll(actualDefaultDataTypes); + + Assert.assertTrue("TrialShareExport default data types missing expected values: " + expectedDataTypes, expectedDataTypes.isEmpty()); + } + + public Set getRegisteredDataTypes(boolean onlyDefault) + { + Set dataTypes = new HashSet<>(); + Set filteredFolderWriters; + if (onlyDefault) + filteredFolderWriters = folderWriters.stream().filter(fw -> fw.selectedByDefault(ExportType.ALL, false)).collect(Collectors.toSet()); + else + filteredFolderWriters = new HashSet<>(folderWriters); + + filteredFolderWriters.forEach(fw -> { + dataTypes.add(fw.getDataType()); + fw.getChildren(false, false) + .forEach(w -> dataTypes.add(w.getDataType())); + }); + + dataTypes.remove(null); + return dataTypes; + } + } +} diff --git a/trialShare/src/org/labkey/trialshare/TrialShareModule.java b/trialShare/src/org/labkey/trialshare/TrialShareModule.java new file mode 100644 index 00000000..8117fd2f --- /dev/null +++ b/trialShare/src/org/labkey/trialshare/TrialShareModule.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015-2017 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.labkey.trialshare; + +import org.jetbrains.annotations.NotNull; +import org.labkey.api.data.Container; +import org.labkey.api.module.CodeOnlyModule; +import org.labkey.api.module.FolderTypeManager; +import org.labkey.api.module.ModuleContext; +import org.labkey.api.study.SpecimenService; +import org.labkey.api.view.WebPartFactory; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +public class TrialShareModule extends CodeOnlyModule +{ + public static final String NAME = "TrialShare"; + + @Override + public String getName() + { + return NAME; + } + + public TrialShareModule() + { + } + + @NotNull + @Override + protected Collection createWebPartFactories() + { + return Collections.emptyList(); + } + + @Override + protected void init() + { + addController(TrialShareController.NAME, TrialShareController.class); + } + + @Override + public void doStartup(ModuleContext moduleContext) + { + FolderTypeManager.get().registerFolderType(this, new StudyITNFolderType(this)); + SpecimenService.get().registerRequestCustomizer(new DelegatingSpecimenRequestCustomizer(SpecimenService.get().getRequestCustomizer())); + } + + @Override + @NotNull + public Collection getSummary(Container c) + { + return Collections.emptyList(); + } + + @Override + @NotNull + public Set getIntegrationTests() + { + return Set.of( + TrialShareController.TrialShareExportTest.class + ); + } +} \ No newline at end of file diff --git a/trialShare/test/src/org/labkey/test/tests/trialshare/ITNSpecimenTest.java b/trialShare/test/src/org/labkey/test/tests/trialshare/ITNSpecimenTest.java new file mode 100644 index 00000000..beef8690 --- /dev/null +++ b/trialShare/test/src/org/labkey/test/tests/trialshare/ITNSpecimenTest.java @@ -0,0 +1,215 @@ +package org.labkey.test.tests.trialshare; + +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.labkey.remoteapi.Connection; +import org.labkey.test.BaseWebDriverTest; +import org.labkey.test.Locator; +import org.labkey.test.TestFileUtils; +import org.labkey.test.TestTimeoutException; +import org.labkey.test.categories.Git; +import org.labkey.test.components.study.specimen.SpecimenDetailGrid; +import org.labkey.test.pages.study.specimen.ManageRequestPage; +import org.labkey.test.pages.study.specimen.ManageRequestStatusPage; +import org.labkey.test.pages.study.specimen.ShowCreateSpecimenRequestPage; +import org.labkey.test.pages.study.specimen.TypeSummaryReportPage; +import org.labkey.test.util.ApiPermissionsHelper; +import org.labkey.test.util.OptionalFeatureHelper; +import org.labkey.test.util.LogMethod; +import org.labkey.test.util.PermissionsHelper.MemberType; +import org.labkey.test.util.TestLogger; +import org.labkey.test.util.study.specimen.SpecimenHelper; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.support.ui.UnexpectedTagNameException; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +@Category({Git.class}) +public class ITNSpecimenTest extends BaseWebDriverTest +{ + private static final File STUDY_ARCHIVE = TestFileUtils.getSampleData("studies/LabkeyDemoStudy.zip"); + private static final String ITN_SPECIMEN_HANDLING = "ITNSpecimenHandling"; + + private static final String SPECIMEN_COORDINATOR = "specimen_coordinator@itnspecimen.test"; + private static final String MAGIC_GROUP = "Specimen Request Administrators"; + + @Override + protected void doCleanup(boolean afterTest) throws TestTimeoutException + { + super.doCleanup(afterTest); + enableITNSpecimenHandling(false); + _userHelper.deleteUsers(false, SPECIMEN_COORDINATOR); + } + + @BeforeClass + public static void setupProject() + { + ITNSpecimenTest init = (ITNSpecimenTest) getCurrentTest(); + + init.doSetup(); + } + + private void doSetup() + { + _containerHelper.createProject(getProjectName(), "Study"); + _containerHelper.enableModule("Specimen"); + importStudyFromZip(STUDY_ARCHIVE); + new SpecimenHelper(this).setupRequestStatuses(); + } + + @Before + public void preTest() + { + enableITNSpecimenHandling(true); + goToProjectHome(); + } + + @Test + public void testSpecimenReportCustomization() + { + final String primaryType = "Blood (Whole)"; + final String derivativeType1 = "PBMC Cells, Viable"; + final String derivativeType2 = "Plasma, Unknown Processing"; + + TestLogger.log("Check standard specimen report behavior to ensure Locators are accurate"); + enableITNSpecimenHandling(false); + TypeSummaryReportPage typeSummaryReportPage = TypeSummaryReportPage.beginAt(this, getProjectName()); + assertThat("Default type breakdown.", typeSummaryReportPage.getTypeBreakdown(), CoreMatchers.containsString("Show results by")); + assertTextPresent(primaryType, derivativeType1, derivativeType2); + + TestLogger.log("Verify customized specimen report behavior"); + enableITNSpecimenHandling(true); + typeSummaryReportPage = TypeSummaryReportPage.beginAt(this, getProjectName()); + try + { + typeSummaryReportPage.getTypeBreakdown(); + Assert.fail("Type breakdown select should be removed from custom ITN specimen report"); + } + catch (NoSuchElementException ignore) { /* expected exception */ } + + assertTextPresent(primaryType); + assertTextNotPresent(derivativeType1, derivativeType2); + } + + @Test + public void testSpecimenRequestCustomization() + { + SpecimenHelper specimenHelper = new SpecimenHelper(this); + clickPortalTab("Specimen Data"); + + waitAndClickAndWait(Locator.linkWithText("Urine")); + SpecimenDetailGrid specimenGrid = specimenHelper.findSpecimenDetailGrid(); + specimenGrid.checkCheckbox(0); + ShowCreateSpecimenRequestPage requestPage = specimenGrid.createNewRequest(); + + // TODO: Refactor to use SampleManagementErrorLogger after it has been moved out of sampleManagement + TestLogger.log("\"Requesting Location\" should not be available for ITN specimen requests"); + assertElementNotVisible(Locator.id("destinationLocation")); + + ManageRequestPage manageRequestPage = requestPage + .setDetails("plan", "info") // required fields + .clickCreateAndViewDetails(); + + String requestingLocation = manageRequestPage.getRequestInformation("Requesting Location"); + assertEquals("Wrong 'Requesting Location'.", "User Request", requestingLocation); + + specimenGrid = specimenHelper.findSpecimenDetailGrid(); + specimenGrid.checkCheckbox(0); + specimenGrid.clickHeaderButtonAndWait("Remove Selected"); + + TestLogger.log("Should be able to submit a request without any specimens"); + manageRequestPage = manageRequestPage + .submitRequest(); + + TestLogger.log("Validate message from 'ITNSpecimenRequestCustomizer'"); + assertElementPresent(Locator.linkWithText("trialsharesupport@immunetolerance.org")); + assertTextPresent("Thank you for your request. A representative from the ITN will be in touch with you."); + } + + @Test + public void testRequestPermissionCustomization() + { + ApiPermissionsHelper permissions = new ApiPermissionsHelper(this); + + _userHelper.createUser(SPECIMEN_COORDINATOR); + permissions.addMemberToRole(SPECIMEN_COORDINATOR, "Specimen Coordinator", MemberType.user, getProjectName()); + permissions.addMemberToRole(SPECIMEN_COORDINATOR, "Reader", MemberType.user, getProjectName()); + permissions.createGlobalPermissionsGroup(MAGIC_GROUP); + + ManageRequestStatusPage manageRequestStatusPage = ShowCreateSpecimenRequestPage.beginAt(this, getProjectName()) + .setDetails("A", "B") + .clickCreateAndViewDetails() + .submitRequest() + .clickUpdateRequest(); + + TestLogger.log("Site admin should be able to set request status"); + manageRequestStatusPage + .setStatus("Processing") + .clickSave(); + + int id = Integer.parseInt(getUrlParam("id")); + + impersonate(SPECIMEN_COORDINATOR); + { + TestLogger.log("Need to be in special group to update requrest status"); + manageRequestStatusPage = ManageRequestStatusPage.beginAt(this, getProjectName(), id); + try + { + manageRequestStatusPage.getStatus(); + Assert.fail("Only users in the correct group should see 'status' dropdown"); + } + catch (UnexpectedTagNameException ignore) { /* expected exception */ } + + String readOnlyStatus = Locator.input("status").parent().findElement(getDriver()).getText(); + assertEquals("Should see status", "Processing", readOnlyStatus); + } + stopImpersonating(); + + permissions.addUserToSiteGroup(SPECIMEN_COORDINATOR, MAGIC_GROUP); + + impersonate(SPECIMEN_COORDINATOR); + { + ManageRequestStatusPage.beginAt(this, getProjectName(), id) + .setStatus("Completed") + .clickSave(); + } + stopImpersonating(); + + String status = ManageRequestPage.beginAt(this, getProjectName(), id).getRequestInformation("Status"); + assertEquals("Final Status", "Completed", status); + } + + @LogMethod(quiet = true) + public void enableITNSpecimenHandling(boolean enable) + { + Connection cn = createDefaultConnection(false); + OptionalFeatureHelper.setOptionalFeature(cn, ITN_SPECIMEN_HANDLING, enable); + } + + @Override + protected BrowserType bestBrowser() + { + return BrowserType.CHROME; + } + + @Override + protected String getProjectName() + { + return "TrialShareSpecimenTest Project"; + } + + @Override + public List getAssociatedModules() + { + return Arrays.asList("trialShare"); + } +} diff --git a/trialShare/test/src/org/labkey/test/tests/trialshare/TrialShareExportTest.java b/trialShare/test/src/org/labkey/test/tests/trialshare/TrialShareExportTest.java new file mode 100644 index 00000000..78d189ad --- /dev/null +++ b/trialShare/test/src/org/labkey/test/tests/trialshare/TrialShareExportTest.java @@ -0,0 +1,89 @@ +package org.labkey.test.tests.trialshare; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.labkey.remoteapi.Connection; +import org.labkey.remoteapi.SimplePostCommand; +import org.labkey.test.BaseWebDriverTest; +import org.labkey.test.WebTestHelper; +import org.labkey.test.categories.Git; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +@Category({Git.class}) +public class TrialShareExportTest extends BaseWebDriverTest +{ + @BeforeClass + public static void setupProject() + { + TrialShareExportTest init = (TrialShareExportTest) getCurrentTest(); + + init.doSetup(); + } + + private void doSetup() + { + _containerHelper.createProject(getProjectName(), null); + } + + @Test + public void testTrialShareExportActionDefault() throws Exception + { + String subfolder = "exportDefault"; + _containerHelper.createSubfolder(getProjectName(), subfolder); + + Connection connection = WebTestHelper.getRemoteApiConnection(); + SimplePostCommand command = new SimplePostCommand("trialShare", "trialShareExport"); + command.execute(connection, getProjectName() + "/" + subfolder); + + goToModule("FileContent"); + _fileBrowserHelper.selectFileBrowserItem("/export/folder.xml"); + List fileList = _fileBrowserHelper.getFileList(); + List expectedFiles = Arrays.asList("data-classes", "etls", "inventory", "sample-types", "wikis", "xar", "data_states.xml", "folder.xml", "pages.xml"); + assertEquals("Default export should include several folder objects", expectedFiles, fileList); + } + + @Test + public void testTrialShareExportActionCustom() throws Exception + { + String subfolder = "exportCustom"; + _containerHelper.createSubfolder(getProjectName(), subfolder); + + Connection connection = WebTestHelper.getRemoteApiConnection(); + SimplePostCommand command = new SimplePostCommand("trialShare", "trialShareExport"); + Map params = new HashMap<>(); + params.put("webpartPropertiesAndLayout", true); // Add one custom data type to override default + command.setParameters(params); + command.execute(connection, getProjectName() + "/" + subfolder); + + goToModule("FileContent"); + _fileBrowserHelper.selectFileBrowserItem("/export/folder.xml"); + List fileList = _fileBrowserHelper.getFileList(); + List expectedFiles = Arrays.asList("folder.xml", "pages.xml"); + assertEquals("Custom export should include only the specified objects", expectedFiles, fileList); + } + + @Override + protected BrowserType bestBrowser() + { + return BrowserType.CHROME; + } + + @Override + protected String getProjectName() + { + return "TrialShareExportTest Project"; + } + + @Override + public List getAssociatedModules() + { + return Arrays.asList(); + } +}