From 007af0c9001900071f6d8e9214143f79e10f4938 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 22 Apr 2016 16:33:47 +0100 Subject: [PATCH] JAL-2071 further refactoring, optimisation, and house keeping for the generic Free Text Search implementation --- resources/fts/pdb_data_columns.conf | 173 +++++----- src/jalview/fts/api/FTSData.java | 38 +++ src/jalview/fts/api/FTSDataColumnGroupI.java | 10 - src/jalview/fts/api/FTSDataColumnI.java | 107 ++++++ src/jalview/fts/api/FTSRestClientI.java | 114 ++++++- src/jalview/fts/api/GFTSPanelI.java | 95 ++++++ src/jalview/fts/core/FTSDataColumnPreferences.java | 12 +- src/jalview/fts/core/FTSRestClient.java | 348 ++++++++++++-------- src/jalview/fts/core/FTSRestRequest.java | 6 +- src/jalview/fts/core/FTSRestResponse.java | 17 +- src/jalview/fts/core/GFTSPanel.java | 81 +++-- src/jalview/fts/service/pdb/PDBFTSPanel.java | 65 ++-- src/jalview/fts/service/pdb/PDBFTSRestClient.java | 45 +-- .../fts/service/uniprot/UniProtFTSRestClient.java | 91 +++++ .../fts/service/uniprot/UniprotFTSPanel.java | 47 +++ src/jalview/gui/SequenceFetcher.java | 21 +- src/jalview/gui/StructureChooser.java | 13 +- src/jalview/jbgui/GStructureChooser.java | 10 +- .../fts/service/pdb/PDBFTSRestClientTest.java | 3 +- 19 files changed, 936 insertions(+), 360 deletions(-) delete mode 100644 src/jalview/fts/api/FTSDataColumnGroupI.java create mode 100644 src/jalview/fts/api/GFTSPanelI.java create mode 100644 src/jalview/fts/service/uniprot/UniProtFTSRestClient.java create mode 100644 src/jalview/fts/service/uniprot/UniprotFTSPanel.java diff --git a/resources/fts/pdb_data_columns.conf b/resources/fts/pdb_data_columns.conf index 5eebd15..95f2dd1 100644 --- a/resources/fts/pdb_data_columns.conf +++ b/resources/fts/pdb_data_columns.conf @@ -10,97 +10,100 @@ g4;Procedures & Softwares;4 g5;Date Of;5 g6;Miscellenous;6 # +_data_column.primary_key;pdb_id +_data_column.default_response_page_size;100 +# _data_column.name _data_column.code _data_column.group_id +_data_column.data_type _data_column.min_col_width _data_column.max_col_width _data_column.preferred_col_width -_data_column.is_primary_key _data_column.is_shown_by_default _data_column.is_searchable -PDB Id;pdb_id;g2;40;60;45;true;true;true -Title;title;g6;300;1500;400;false;true;false -Molecule;molecule_name;g3;50;400;95;false;false;true -Molecule Type;molecule_type;g3;50;400;95;false;false;true -Sequence;molecule_sequence;g6;50;400;95;false;false;false -PFAM Accession;pfam_accession;g2;50;400;95;false;false;true -PFAM Name;pfam_name;g3;50;400;95;false;false;true -InterPro Name;interpro_name;g3;50;400;95;false;false;false -InterPro Accession;interpro_accession;g2;50;400;95;false;false;false -UniProt Id;uniprot_id;g2;50;400;95;false;false;true -UniProt Accession;uniprot_accession;g2;50;400;95;false;false;false -UniProt Coverage;uniprot_coverage;g6;50;400;95;false;false;false -Uniprot Features;uniprot_features;g6;50;400;95;false;false;false -R Factor;r_factor;g1;50;150;85;false;false;false -Resolution;resolution;g1;50;150;85;false;true;false -Data Quality;data_quality;g1;50;150;85;false;false;false -Overall Quality;overall_quality;g1;50;150;85;false;false;false -Number of Polymers;number_of_polymers;g6;50;400;95;false;false;false -Number of Protein Chains;number_of_protein_chains;g6;50;400;95;false;false;false -Number of Bound Molecule;number_of_bound_molecules;g6;50;400;95;false;false;false -Number of Polymer Residue;number_of_polymer_residues;g6;50;400;95;false;false;false -GENUS;genus;g3;50;400;95;false;false;true -Gene Name;gene_name;g3;50;400;95;false;false;true -Experimental Method;experimental_method;g4;50;400;95;false;false;false -GO Id;go_id;g2;50;400;95;false;false;false -Assembly Id;assembly_id;g2;50;400;95;false;false;false -Assembly Form;assembly_form;g6;50;400;95;false;false;false -Assembly Type;assembly_type;g6;50;400;95;false;false;false -Space Group;spacegroup;g6;50;400;95;false;false;false -Cath Code;cath_code;g2;50;400;95;false;false;false -Tax Id;tax_id;g2;50;400;95;false;false;false -Tax Query;tax_query;g2;50;400;95;false;false;false -Interacting Entity Id;interacting_entity_id;g2;50;400;95;false;false;false -Interacting Molecules;interacting_molecules;g6;50;400;95;false;false;false -Pubmed Id;pubmed_id;g2;50;400;95;false;false;false -Status;status;g6;50;400;95;false;false;false -Model Quality;model_quality;g1;50;150;85;false;false;false -Pivot Resolution;pivot_resolution;g1;50;150;85;false;false;false -Data reduction software;data_reduction_software;g4;50;400;95;false;false;false -Max observed residues;max_observed_residues;g6;50;400;95;false;false;false -Organism scientific name;organism_scientific_name;g3;50;400;95;false;false;false -Super kingdom;superkingdom;g3;50;400;95;false;false;false -Rank;rank;g3;50;400;95;false;false;false -Crystallisation Ph;crystallisation_ph;g6;50;400;95;false;false;false -Biological Function;biological_function;g6;50;400;95;false;false;false -Biological Process;biological_process;g6;50;400;95;false;false;false -Biological Cell Component;biological_cell_component;g6;50;400;95;false;false;false -Compound Name;compound_name;g3;50;400;95;false;false;false -Compound Id;compound_id;g2;50;400;95;false;false;false -Compound Weight;compound_weight;g6;50;400;95;false;false;false -Compound Systematic Name;compound_systematic_name;g3;50;400;95;false;false;false -Interacting Ligands;interacting_ligands;g6;50;400;95;false;false;false -Journal;journal;g6;50;400;95;false;false;false -All Authors;all_authors;g6;50;400;95;false;false;false -Experiment Data Available;experiment_data_available;g6;50;400;95;false;false;false -Diffraction Protocol;diffraction_protocol;g4;50;400;95;false;false;false -Refinement Software;refinement_software;g4;50;400;95;false;false;false -Structure Determination Method;structure_determination_method;g4;50;400;95;false;false;false -Synchrotron Site;synchrotron_site;g6;50;400;95;false;false;false -Sample Preparation Method;sample_preparation_method;g4;50;400;95;false;false;false -Entry Authors;entry_authors;g6;50;400;95;false;false;false -Citation Title;citation_title;g6;50;400;95;false;false;false -Structure Solution Software;structure_solution_software;g4;50;400;95;false;false;false -Entry Entity;entry_entity;g6;50;400;95;false;false;false -R Free;r_free;g1;50;150;85;false;false;false -Number of Polymer Entities;number_of_polymer_entities;g6;50;400;95;false;false;false -Number of Bound Entities;number_of_bound_entities;g6;50;400;95;false;false;false -Crystallisation Reservoir;crystallisation_reservoir;g6;50;400;95;false;false;false -Data Scalling Software;data_scaling_software;g4;50;400;95 ;false;false;false -Detector;detector;g6;50;400;95;false;false;false -Detector Type;detector_type;g6;50;400;95;false;false;false -Modified Residue Flag;modified_residue_flag;g6;50;400;95;false;false;false -Number of Copies;number_of_copies;g6;50;400;95;false;false;false -Struc Asym Id;struct_asym_id;g2;50;400;95;false;false;false -Homologus PDB Entity Id;homologus_pdb_entity_id;g2;50;400;95;false;false;false -Molecule Synonym;molecule_synonym;g6;50;400;95;false;false;false -Deposition Site;deposition_site;g6;50;400;95;false;false;false -Synchrotron Beamline;synchrotron_beamline;g6;50;400;95;false;false;false -Entity Id; entity_id;g2;50;400;95;false;false;false -Beam Source Name;beam_source_name;g3;50;400;95;false;false;false -Processing Site;processing_site;g6;50;400;95;false;false;false -Entity Weight;entity_weight;g6;50;400;95;false;false;false -Version;_version_;g6;50;400;95;false;false;false -ALL;text;g6;50;400;95;false;false;true +PDB Id;pdb_id;String;g2;40;60;45;true;true +Title;title;String;g6;300;1500;400;true;false +Molecule;molecule_name;String;g3;50;400;95;false;true +Molecule Type;molecule_type;String;g3;50;400;95;false;true +Sequence;molecule_sequence;String;g6;50;400;95;false;false +PFAM Accession;pfam_accession;String;g2;50;400;95;false;true +PFAM Name;pfam_name;String;g3;50;400;95;false;true +InterPro Name;interpro_name;String;g3;50;400;95;false;false +InterPro Accession;interpro_accession;String;g2;50;400;95;false;false +UniProt Id;uniprot_id;String;g2;50;400;95;false;true +UniProt Accession;uniprot_accession;String;g2;50;400;95;false;false +UniProt Coverage;uniprot_coverage;String;g6;50;400;95;false;false +Uniprot Features;uniprot_features;String;g6;50;400;95;false;false +R Factor;r_factor;Double;g1;50;150;85;false;false +Resolution;resolution;Double;g1;50;150;85;true;false +Data Quality;data_quality;Double;g1;50;150;85;false;false +Overall Quality;overall_quality;Double;g1;50;150;85;false;false +Number of Polymers;number_of_polymers;int;g6;50;400;95;false;false +Number of Protein Chains;number_of_protein_chains;int;g6;50;400;95;false;false +Number of Bound Molecule;number_of_bound_molecules;int;g6;50;400;95;false;false +Number of Polymer Residue;number_of_polymer_residues;int;g6;50;400;95;false;false +GENUS;genus;String;g3;50;400;95;false;true +Gene Name;gene_name;String;g3;50;400;95;false;true +Experimental Method;experimental_method;String;g4;50;400;95;false;false +GO Id;go_id;String;g2;50;400;95;false;false +Assembly Id;assembly_id;String;g2;50;400;95;false;false +Assembly Form;assembly_form;String;g6;50;400;95;false;false +Assembly Type;assembly_type;String;g6;50;400;95;false;false +Space Group;spacegroup;String;g6;50;400;95;false;false +Cath Code;cath_code;String;g2;50;400;95;false;false +Tax Id;tax_id;String;g2;50;400;95;false;false +Tax Query;tax_query;String;g2;50;400;95;false;false +Interacting Entity Id;interacting_entity_id;String;g2;50;400;95;false;false +Interacting Molecules;interacting_molecules;String;g6;50;400;95;false;false +Pubmed Id;pubmed_id;int;g2;50;400;95;false;false +Status;status;String;g6;50;400;95;false;false +Model Quality;model_quality;Double;g1;50;150;85;false;false +Pivot Resolution;pivot_resolution;Double;g1;50;150;85;false;false +Data reduction software;data_reduction_software;String;g4;50;400;95;false;false +Max observed residues;max_observed_residues;String;g6;50;400;95;false;false +Organism scientific name;organism_scientific_name;String;g3;50;400;95;false;false +Super kingdom;superkingdom;String;g3;50;400;95;false;false +Rank;rank;String;g3;50;400;95;false;false +Crystallisation Ph;crystallisation_ph;String;g6;50;400;95;false;false +Biological Function;biological_function;String;g6;50;400;95;false;false +Biological Process;biological_process;String;g6;50;400;95;false;false +Biological Cell Component;biological_cell_component;String;g6;50;400;95;false;false +Compound Name;compound_name;String;g3;50;400;95;false;false +Compound Id;compound_id;String;g2;50;400;95;false;false +Compound Weight;compound_weight;String;g6;50;400;95;false;false +Compound Systematic Name;compound_systematic_name;String;g3;50;400;95;false;false +Interacting Ligands;interacting_ligands;String;g6;50;400;95;false;false +Journal;journal;String;g6;50;400;95;false;false +All Authors;all_authors;String;g6;50;400;95;false;false +Experiment Data Available;experiment_data_available;String;g6;50;400;95;false;false +Diffraction Protocol;diffraction_protocol;String;g4;50;400;95;false;false +Refinement Software;refinement_software;String;g4;50;400;95;false;false +Structure Determination Method;structure_determination_method;String;g4;50;400;95;false;false +Synchrotron Site;synchrotron_site;String;g6;50;400;95;false;false +Sample Preparation Method;sample_preparation_method;String;g4;50;400;95;false;false +Entry Authors;entry_authors;String;g6;50;400;95;false;false +Citation Title;citation_title;String;g6;50;400;95;false;false +Structure Solution Software;structure_solution_software;String;g4;50;400;95;false;false +Entry Entity;entry_entity;String;g6;50;400;95;false;false +R Free;r_free;Double;g1;50;150;85;false;false +Number of Polymer Entities;number_of_polymer_entities;int;g6;50;400;95;false;false +Number of Bound Entities;number_of_bound_entities;int;g6;50;400;95;false;false +Crystallisation Reservoir;crystallisation_reservoir;String;g6;50;400;95;false;false +Data Scalling Software;data_scaling_software;String;g4;50;400;95;false;false +Detector;detector;String;g6;50;400;95;false;false +Detector Type;detector_type;String;g6;50;400;95;false;false +Modified Residue Flag;modified_residue_flag;String;g6;50;400;95;false;false +Number of Copies;number_of_copies;int;g6;50;400;95;false;false +Struc Asym Id;struct_asym_id;String;g2;50;400;95;false;false +Homologus PDB Entity Id;homologus_pdb_entity_id;String;g2;50;400;95;false;false +Molecule Synonym;molecule_synonym;String;g6;50;400;95;false;false +Deposition Site;deposition_site;String;g6;50;400;95;false;false +Synchrotron Beamline;synchrotron_beamline;String;g6;50;400;95;false;false +Entity Id; entity_id;String;g2;50;400;95;false;false +Beam Source Name;beam_source_name;String;g3;50;400;95;false;false +Processing Site;processing_site;String;g6;50;400;95;false;false +Entity Weight;entity_weight;Double;g6;50;400;95;false;false +Version;_version_;String;g6;50;400;95;false;false +ALL;text;String;g6;50;400;95;false;true # diff --git a/src/jalview/fts/api/FTSData.java b/src/jalview/fts/api/FTSData.java index 83a704a..9e9d62c 100644 --- a/src/jalview/fts/api/FTSData.java +++ b/src/jalview/fts/api/FTSData.java @@ -1,8 +1,46 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.fts.api; +/** + * This interface provides a model for the summary data; + * + * @author tcnofoegbu + * + */ public interface FTSData { + + /** + * Return an array of Objects representing the retrieved FTS data + * + * @return + */ public Object[] getSummaryData(); + /** + * The primary key object for the retrieved FTS data + * + * @return + */ public Object getPrimaryKey(); } diff --git a/src/jalview/fts/api/FTSDataColumnGroupI.java b/src/jalview/fts/api/FTSDataColumnGroupI.java deleted file mode 100644 index 1f23976..0000000 --- a/src/jalview/fts/api/FTSDataColumnGroupI.java +++ /dev/null @@ -1,10 +0,0 @@ -package jalview.fts.api; - -public interface FTSDataColumnGroupI -{ - public String getID(); - - public String getName(); - - public int getSortOrder(); -} diff --git a/src/jalview/fts/api/FTSDataColumnI.java b/src/jalview/fts/api/FTSDataColumnI.java index f6fc5da..ea30d01 100644 --- a/src/jalview/fts/api/FTSDataColumnI.java +++ b/src/jalview/fts/api/FTSDataColumnI.java @@ -1,22 +1,129 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.fts.api; +/** + * This interface provides a model for the dynamic data column configuration + * + * @author tcnofoegbu + * + */ public interface FTSDataColumnI { + /** + * Returns the name of the data column + * + * @return the data column's name + */ public String getName(); + /** + * Returns the code of the data column + * + * @return the data column's code + */ public String getCode(); + /** + * Returns the minimum width of the data column + * + * @return the data column's minimum width + */ public int getMinWidth(); + /** + * Returns the maximum width of the data column + * + * @return the data column's maximum width + */ public int getMaxWidth(); + /** + * Returns the preferred width of the data column + * + * @return the data column's preferred width + */ public int getPreferredWidth(); + /** + * Determines if the data column is the primary key column + * + * @return true if data column is the primary key column, otherwise false + */ public boolean isPrimaryKeyColumn(); + /** + * Checks if the data column field can be used to perform a search query + * + * @return true means the data column is searchable + */ public boolean isSearchable(); + /** + * Checks if the data column is displayed by default + * + * @return true means the data column is shown by default + */ public boolean isVisibleByDefault(); + /** + * Returns the data column's data type class + * + * @return the Class for the data column's data type + */ + public Class getDataColumnClass(); + + /** + * Returns the data colum's FTS data column group + * + * @return the FTSDataColumnGroupI for the column + */ public FTSDataColumnGroupI getGroup(); + + /** + * This interface provides a model for the dynamic data column group + * + */ + public interface FTSDataColumnGroupI + { + /** + * Returns the Id of the data column's group + * + * @return the data column's group Id + */ + public String getID(); + + /** + * Returns the name of the group + * + * @return the group's name + */ + public String getName(); + + /** + * Returns the sort order of the group + * + * @return the group's sort order + */ + public int getSortOrder(); + } } diff --git a/src/jalview/fts/api/FTSRestClientI.java b/src/jalview/fts/api/FTSRestClientI.java index b7ce5df..2266ca0 100644 --- a/src/jalview/fts/api/FTSRestClientI.java +++ b/src/jalview/fts/api/FTSRestClientI.java @@ -1,34 +1,142 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.fts.api; +import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import java.util.Collection; +/** + * Methods for FTS Rest client. + * + * @author tcnofoegbu + */ public interface FTSRestClientI { - public FTSRestResponse executeRequest(FTSRestRequest pdbRestRequest) + /** + * Execute a given FTS request, process the response and return it as an + * FTSRestResponse object + * + * @param ftsRestRequest + * the FTS request to execute + * @return FTSRestResponse - the response after executing an FTS request + * @throws Exception + */ + public FTSRestResponse executeRequest(FTSRestRequest ftsRequest) throws Exception; - public String getColumnDataConfigFile(); + /** + * Return the resource file path for the data columns configuration file + * + * @return + */ + public String getColumnDataConfigFileName(); - public FTSDataColumnGroupI getDataColumnGroupById(String id) + /** + * Fetch FTSDataColumnGroupI by the group's Id + * + * @param groupId + * @return FTSDataColumnGroupI + * @throws Exception + */ + public FTSDataColumnGroupI getDataColumnGroupById(String groupId) throws Exception; + /** + * Fetch FTSDataColumnI by name or code + * + * @param nameOrCode + * @return FTSDataColumnI + * @throws Exception + */ public FTSDataColumnI getDataColumnByNameOrCode(String nameOrCode) throws Exception; + + /** + * Convert collection of FTSDataColumnI objects to a comma delimited string of + * the 'code' values + * + * @param wantedFields + * the collection of FTSDataColumnI to process + * @return the generated comma delimited string from the supplied + * FTSDataColumnI collection + */ + public String getDataColumnsFieldsAsCommaDelimitedString( + Collection wantedFields); + + + /** + * Fetch index of the primary key column for the dynamic table + * + * @param wantedFields + * the available table columns + * @param hasRefSeq + * true if the data columns has an additional column for reference + * sequence + * @return index of the primary key column + * @throws Exception + */ public int getPrimaryKeyColumIndex( Collection wantedFields, boolean hasRefSeq) throws Exception; + /** + * Fetch the primary key data column object + * + * @return the FTSDataColumnI object for the primary key column + */ public FTSDataColumnI getPrimaryKeyColumn(); + /** + * Returns list of FTSDataColumnI objects to be displayed by default + * + * @return list of columns to display by default + */ public Collection getAllDefaulDisplayedDataColumns(); + /** + * Return list of FTSDataColumnI objects that can be used to perform a search + * query + * + * @return list of searchable FTSDataColumnI object + */ public Collection getSearchableDataColumns(); + /** + * Return list of all available FTSDataColumnI object + * + * @return list of all FTSColumnI objcet + */ public Collection getAllFTSDataColumns(); + + /** + * Return the default response page limit + * + * @return the default response page size + */ + public int getDefaultResponsePageSize(); } diff --git a/src/jalview/fts/api/GFTSPanelI.java b/src/jalview/fts/api/GFTSPanelI.java new file mode 100644 index 0000000..46121fc --- /dev/null +++ b/src/jalview/fts/api/GFTSPanelI.java @@ -0,0 +1,95 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + +package jalview.fts.api; + +import javax.swing.JTable; + +/** + * + * @author tcnofoegbu + * + */ +public interface GFTSPanelI +{ + + /** + * Action performed when a text is entered in the search field. + */ + public void searchAction(); + + /** + * Action performed when search results are selected and the 'ok' button is + * pressed. + */ + public void okAction(); + + /** + * Return the entered text + * + * @return the entered text + */ + public String getTypedText(); + + /** + * The JTable for presenting the query result + * + * @return JTable + */ + public JTable getResultTable(); + + /** + * Return the title to display on the search interface main panel + * + * @return String - the title + */ + public String getFTSFrameTitle(); + + /** + * Return a singleton instance of FTSRestClientI + * + * @return FTSRestClientI + */ + public FTSRestClientI getFTSRestClient(); + + /** + * Set error message when one occurs + * + * @param message + * the error message to set + */ + public void setErrorMessage(String message); + + /** + * Updates the title displayed on the search interface's main panel + * + * @param newTitle + */ + public void updateSearchFrameTitle(String newTitle); + + /** + * Controls the progress spinner, set to 'true' while search operation is in + * progress and 'false' after it completes + * + * @param isSearchInProgress + */ + public void setSearchInProgress(Boolean isSearchInProgress); +} diff --git a/src/jalview/fts/core/FTSDataColumnPreferences.java b/src/jalview/fts/core/FTSDataColumnPreferences.java index 1828610..cddcc8e 100644 --- a/src/jalview/fts/core/FTSDataColumnPreferences.java +++ b/src/jalview/fts/core/FTSDataColumnPreferences.java @@ -20,8 +20,8 @@ */ package jalview.fts.core; -import jalview.fts.api.FTSDataColumnGroupI; import jalview.fts.api.FTSDataColumnI; +import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI; import jalview.fts.api.FTSRestClientI; import java.util.ArrayList; @@ -50,7 +50,7 @@ public class FTSDataColumnPreferences extends JScrollPane private HashMap map = new HashMap(); - private static Collection structSummaryColumns = new LinkedHashSet(); + private Collection structSummaryColumns = new LinkedHashSet(); private Collection allFTSDataColumns = new LinkedHashSet(); @@ -179,17 +179,11 @@ public class FTSDataColumnPreferences extends JScrollPane } - public static Collection getStructureSummaryFields() + public Collection getStructureSummaryFields() { return structSummaryColumns; } - public static void setStructureSummaryFields( - Collection structureSummaryFields) - { - FTSDataColumnPreferences.structSummaryColumns = structureSummaryFields; - } - class FTSDataColumnPrefsTableModel extends AbstractTableModel { diff --git a/src/jalview/fts/core/FTSRestClient.java b/src/jalview/fts/core/FTSRestClient.java index 77b94c4..eeb7ec6 100644 --- a/src/jalview/fts/core/FTSRestClient.java +++ b/src/jalview/fts/core/FTSRestClient.java @@ -1,7 +1,7 @@ package jalview.fts.core; -import jalview.fts.api.FTSDataColumnGroupI; import jalview.fts.api.FTSDataColumnI; +import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI; import jalview.fts.api.FTSRestClientI; import java.io.BufferedReader; @@ -11,6 +11,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Objects; +/** + * Base class providing implementation for common methods defined in + * FTSRestClientI + * + * @author tcnofoegbu + * + * @note implementations MUST be accessed as a singleton. + */ public abstract class FTSRestClient implements FTSRestClientI { protected Collection dataColumns = new ArrayList(); @@ -23,170 +31,212 @@ public abstract class FTSRestClient implements FTSRestClientI protected FTSDataColumnI primaryKeyColumn; + private String primaryKeyColumnCode = null; + + private int defaultResponsePageSize = 100; + protected FTSRestClient() { } - public void parseDataColumnsFile() + public void parseDataColumnsConfigFile() { - String fileName = getColumnDataConfigFile(); + String fileName = getColumnDataConfigFileName(); try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { String line; while ((line = br.readLine()) != null) { final String[] lineData = line.split(";"); - if (lineData.length == 3) + try { - dataColumnGroups.add(new FTSDataColumnGroupI() + if (lineData.length == 2) { - @Override - public String getID() + if (lineData[0].equalsIgnoreCase("_data_column.primary_key")) { - return lineData[0]; + primaryKeyColumnCode = lineData[1]; } - - @Override - public String getName() + if (lineData[0] + .equalsIgnoreCase("_data_column.default_response_page_size")) { - return lineData[1]; + defaultResponsePageSize = Integer.valueOf(lineData[1]); } - - @Override - public int getSortOrder() + } + else if (lineData.length == 3) + { + dataColumnGroups.add(new FTSDataColumnGroupI() { - return Integer.valueOf(lineData[2]); - } + @Override + public String getID() + { + return lineData[0]; + } - @Override - public String toString() - { - return lineData[1]; - } + @Override + public String getName() + { + return lineData[1]; + } - @Override - public int hashCode() - { - return Objects.hash(this.getID(), this.getName(), - this.getSortOrder()); - } + @Override + public int getSortOrder() + { + return Integer.valueOf(lineData[2]); + } - @Override - public boolean equals(Object otherObject) - { - FTSDataColumnGroupI that = (FTSDataColumnGroupI) otherObject; - return this.getID().equals(that.getID()) - && this.getName().equals(that.getName()) - && this.getSortOrder() == that.getSortOrder(); - } - }); - } - else if (lineData.length > 6) - { - FTSDataColumnI dataCol = new FTSDataColumnI() + @Override + public String toString() + { + return lineData[1]; + } + + @Override + public int hashCode() + { + return Objects.hash(this.getID(), this.getName(), + this.getSortOrder()); + } + + @Override + public boolean equals(Object otherObject) + { + FTSDataColumnGroupI that = (FTSDataColumnGroupI) otherObject; + return this.getID().equals(that.getID()) + && this.getName().equals(that.getName()) + && this.getSortOrder() == that.getSortOrder(); + } + }); + } + else if (lineData.length > 6) { - @Override - public String toString() + FTSDataColumnI dataCol = new FTSDataColumnI() { - return lineData[0]; - } + @Override + public String toString() + { + return lineData[0]; + } - @Override - public String getName() - { - return lineData[0]; - } + @Override + public String getName() + { + return lineData[0]; + } - @Override - public String getCode() - { - return lineData[1]; - } + @Override + public String getCode() + { + return lineData[1]; + } - @Override - public FTSDataColumnGroupI getGroup() - { - FTSDataColumnGroupI group = null; - try + @Override + public Class getDataColumnClass() { - group = getDataColumnGroupById(lineData[2]); - } catch (Exception e) + String classString = lineData[2]; + classString = classString.toUpperCase(); + switch (classString) + { + case "INT": + case "INTEGER": + return Integer.class; + case "DOUBLE": + return Double.class; + case "STRING": + default: + return String.class; + } + } + + @Override + public FTSDataColumnGroupI getGroup() { - e.printStackTrace(); + FTSDataColumnGroupI group = null; + try + { + group = getDataColumnGroupById(lineData[3]); + } catch (Exception e) + { + e.printStackTrace(); + } + return group; } - return group; - } - @Override - public int getMinWidth() - { - return Integer.valueOf(lineData[3]); - } + @Override + public int getMinWidth() + { + return Integer.valueOf(lineData[4]); + } - @Override - public int getMaxWidth() - { - return Integer.valueOf(lineData[4]); - } + @Override + public int getMaxWidth() + { + return Integer.valueOf(lineData[5]); + } - @Override - public int getPreferredWidth() - { - return Integer.valueOf(lineData[5]); - } + @Override + public int getPreferredWidth() + { + return Integer.valueOf(lineData[6]); + } + @Override + public boolean isPrimaryKeyColumn() + { + return getName().equalsIgnoreCase(primaryKeyColumnCode) + || getCode().equalsIgnoreCase(primaryKeyColumnCode); + } - @Override - public boolean isPrimaryKeyColumn() - { - return Boolean.valueOf(lineData[6]); - } + @Override + public boolean isVisibleByDefault() + { + return Boolean.valueOf(lineData[7]); + } - @Override - public boolean isVisibleByDefault() - { - return Boolean.valueOf(lineData[7]); - } + @Override + public boolean isSearchable() + { + return Boolean.valueOf(lineData[8]); + } - @Override - public boolean isSearchable() - { - return Boolean.valueOf(lineData[8]); - } + @Override + public int hashCode() + { + return Objects.hash(this.getName(), this.getCode(), + this.getGroup()); + } - @Override - public int hashCode() + + @Override + public boolean equals(Object otherObject) + { + FTSDataColumnI that = (FTSDataColumnI) otherObject; + return this.getCode().equals(that.getCode()) + && this.getName().equals(that.getName()) + && this.getGroup().equals(that.getGroup()); + } + + }; + dataColumns.add(dataCol); + + if (dataCol.isSearchable()) { - return Objects.hash(this.getName(), this.getCode(), - this.getGroup()); + searchableDataColumns.add(dataCol); } - @Override - public boolean equals(Object otherObject) + if (dataCol.isVisibleByDefault()) { - FTSDataColumnI that = (FTSDataColumnI) otherObject; - return this.getCode().equals(that.getCode()) - && this.getName().equals(that.getName()) - && this.getGroup().equals(that.getGroup()); + defaulDisplayedDataColumns.add(dataCol); } - }; - dataColumns.add(dataCol); - if (dataCol.isSearchable()) - { - searchableDataColumns.add(dataCol); } - - if (dataCol.isVisibleByDefault()) + else { - defaulDisplayedDataColumns.add(dataCol); + continue; } - - } - else + } catch (Exception e) { - continue; + e.printStackTrace(); } } } catch (IOException e) @@ -195,19 +245,10 @@ public abstract class FTSRestClient implements FTSRestClientI } } - /** - * Determines the column index for 'Primary key' Fields in the dynamic summary - * table. - * - * @param wantedFields - * the available table columns in no particular order - * @return the primary key column index - * @throws Exception - */ @Override public int getPrimaryKeyColumIndex( - Collection wantedFields, - boolean hasRefSeq) throws Exception + Collection wantedFields, boolean hasRefSeq) + throws Exception { // If a reference sequence is attached then start counting from 1 else @@ -225,16 +266,34 @@ public abstract class FTSRestClient implements FTSRestClientI return pdbFieldIndexCounter; } + @Override + public String getDataColumnsFieldsAsCommaDelimitedString( + Collection dataColumnFields) + { + String result = ""; + if (dataColumnFields != null && !dataColumnFields.isEmpty()) + { + StringBuilder returnedFields = new StringBuilder(); + for (FTSDataColumnI field : dataColumnFields) + { + returnedFields.append(",").append(field.getCode()); + } + returnedFields.deleteCharAt(0); + result = returnedFields.toString(); + } + return result; + } + /** * Takes a collection of FTSDataColumnI and converts its 'code' values into a - * comma delimited string. + * tab delimited string. * * @param dataColumnFields * the collection of FTSDataColumnI to process * @return the generated comma delimited string from the supplied * FTSDataColumnI collection */ - public static String getDataColumnsFieldsAsCommaDelimitedString( + public String getDataColumnsFieldsAsTabDelimitedString( Collection dataColumnFields) { String result = ""; @@ -243,7 +302,7 @@ public abstract class FTSRestClient implements FTSRestClientI StringBuilder returnedFields = new StringBuilder(); for (FTSDataColumnI field : dataColumnFields) { - returnedFields.append(",").append(field.getCode()); + returnedFields.append("\t").append(field.getName()); } returnedFields.deleteCharAt(0); result = returnedFields.toString(); @@ -256,7 +315,7 @@ public abstract class FTSRestClient implements FTSRestClientI { if (dataColumns == null || dataColumns.isEmpty()) { - parseDataColumnsFile(); + parseDataColumnsConfigFile(); } return dataColumns; } @@ -266,7 +325,7 @@ public abstract class FTSRestClient implements FTSRestClientI { if (searchableDataColumns == null || searchableDataColumns.isEmpty()) { - parseDataColumnsFile(); + parseDataColumnsConfigFile(); } return searchableDataColumns; } @@ -277,7 +336,7 @@ public abstract class FTSRestClient implements FTSRestClientI if (defaulDisplayedDataColumns == null || defaulDisplayedDataColumns.isEmpty()) { - parseDataColumnsFile(); + parseDataColumnsConfigFile(); } return defaulDisplayedDataColumns; } @@ -289,9 +348,13 @@ public abstract class FTSRestClient implements FTSRestClientI } @Override - public FTSDataColumnI getDataColumnByNameOrCode( - String nameOrCode) throws Exception + public FTSDataColumnI getDataColumnByNameOrCode(String nameOrCode) + throws Exception { + if (dataColumns == null || dataColumns.isEmpty()) + { + parseDataColumnsConfigFile(); + } for (FTSDataColumnI column : dataColumns) { if (column.getName().equalsIgnoreCase(nameOrCode) @@ -308,6 +371,10 @@ public abstract class FTSRestClient implements FTSRestClientI public FTSDataColumnGroupI getDataColumnGroupById(String id) throws Exception { + if (dataColumns == null || dataColumns.isEmpty()) + { + parseDataColumnsConfigFile(); + } for (FTSDataColumnGroupI columnGroup : dataColumnGroups) { if (columnGroup.getID().equalsIgnoreCase(id)) @@ -318,10 +385,9 @@ public abstract class FTSRestClient implements FTSRestClientI throw new Exception("Couldn't find data column group with id : " + id); } - protected String getFile(String fileName) + protected String getResourceFile(String fileName) { ClassLoader classLoader = getClass().getClassLoader(); - // File file = new File(classLoader.getResource(fileName).getFile()); String result = ""; try { @@ -334,4 +400,10 @@ public abstract class FTSRestClient implements FTSRestClientI } + @Override + public int getDefaultResponsePageSize() + { + return defaultResponsePageSize; + } + } diff --git a/src/jalview/fts/core/FTSRestRequest.java b/src/jalview/fts/core/FTSRestRequest.java index 94f9bfb..68068d7 100644 --- a/src/jalview/fts/core/FTSRestRequest.java +++ b/src/jalview/fts/core/FTSRestRequest.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -28,7 +28,7 @@ import jalview.fts.api.FTSDataColumnI; import java.util.Collection; /** - * Represents the PDB request to be consumed by the PDBRestClient + * Represents the FTS request to be consumed by the FTSRestClient * * @author tcnofoegbu * diff --git a/src/jalview/fts/core/FTSRestResponse.java b/src/jalview/fts/core/FTSRestResponse.java index 17204d7..c56b8c8 100644 --- a/src/jalview/fts/core/FTSRestResponse.java +++ b/src/jalview/fts/core/FTSRestResponse.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -30,8 +30,8 @@ import javax.swing.JTable; import javax.swing.table.DefaultTableModel; /** - * Represents the response model produced by the PDBRestClient upon successful - * execution of a given request + * Represents the response model generated by the FTSRestClient upon successful + * execution of a given FTS request * * @author tcnofoegbu * @@ -79,7 +79,7 @@ public class FTSRestResponse * on the request parameters * * @param request - * the PDBRestRequest object which holds useful information for + * the FTSRestRequest object which holds useful information for * creating a table model * @param summariesList * the summary list which contains the data for populating the @@ -107,12 +107,7 @@ public class FTSRestResponse { return String.class; } - if (cols[columnIndex - colOffset].getGroup().getName() - .equalsIgnoreCase("Quality Measures")) - { - return Double.class; - } - return String.class; + return cols[columnIndex - colOffset].getDataColumnClass(); } }; diff --git a/src/jalview/fts/core/GFTSPanel.java b/src/jalview/fts/core/GFTSPanel.java index 2e50386..67983a1 100644 --- a/src/jalview/fts/core/GFTSPanel.java +++ b/src/jalview/fts/core/GFTSPanel.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -22,9 +22,8 @@ package jalview.fts.core; import jalview.fts.api.FTSDataColumnI; -import jalview.fts.api.FTSRestClientI; +import jalview.fts.api.GFTSPanelI; import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource; -import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.gui.Desktop; import jalview.gui.IProgressIndicator; import jalview.gui.JvSwingUtils; @@ -62,16 +61,18 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.table.DefaultTableModel; /** - * GUI layout for PDB Fetch Panel + * This class provides the swing GUI layout for FTS Panel and implements most of + * the contracts defined in GFSPanelI * * @author tcnofoegbu * */ @SuppressWarnings("serial") -public abstract class GFTSPanel extends JPanel +public abstract class GFTSPanel extends JPanel implements GFTSPanelI { protected JInternalFrame mainFrame = new JInternalFrame( getFTSFrameTitle()); @@ -92,7 +93,7 @@ public abstract class GFTSPanel extends JPanel protected Collection wantedFields; - protected JTable tbl_summary = new JTable() + private JTable tbl_summary = new JTable() { @Override public String getToolTipText(MouseEvent evt) @@ -205,7 +206,7 @@ public abstract class GFTSPanel extends JPanel case KeyEvent.VK_ENTER: // enter key if (btn_ok.isEnabled()) { - btn_ok_ActionPerformed(); + okAction(); } evt.consume(); break; @@ -256,7 +257,7 @@ public abstract class GFTSPanel extends JPanel @Override public void actionPerformed(ActionEvent e) { - btn_ok_ActionPerformed(); + okAction(); } }); btn_ok.addKeyListener(new KeyAdapter() @@ -266,7 +267,7 @@ public abstract class GFTSPanel extends JPanel { if (evt.getKeyCode() == KeyEvent.VK_ENTER) { - btn_ok_ActionPerformed(); + okAction(); } } }); @@ -324,7 +325,7 @@ public abstract class GFTSPanel extends JPanel } txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true, tooltipText)); - txt_search_ActionPerformed(); + searchAction(); } }); @@ -358,19 +359,19 @@ public abstract class GFTSPanel extends JPanel @Override public void insertUpdate(DocumentEvent e) { - txt_search_ActionPerformed(); + searchAction(); } @Override public void removeUpdate(DocumentEvent e) { - txt_search_ActionPerformed(); + searchAction(); } @Override public void changedUpdate(DocumentEvent e) { - txt_search_ActionPerformed(); + searchAction(); } }); @@ -398,7 +399,7 @@ public abstract class GFTSPanel extends JPanel btn_back.setEnabled(false); btn_cancel.setEnabled(false); btn_ok.setEnabled(false); - previousWantedFields = PDBFTSRestClient.getInstance() + previousWantedFields = getFTSRestClient() .getAllDefaulDisplayedDataColumns() .toArray(new Object[0]); } @@ -408,7 +409,7 @@ public abstract class GFTSPanel extends JPanel btn_cancel.setEnabled(true); if (wantedFieldsUpdated()) { - txt_search_ActionPerformed(); + searchAction(); } else { @@ -450,7 +451,7 @@ public abstract class GFTSPanel extends JPanel return true; } - return Arrays.equals(PDBFTSRestClient.getInstance() + return Arrays.equals(getFTSRestClient() .getAllDefaulDisplayedDataColumns() .toArray(new Object[0]), previousWantedFields) ? false : true; @@ -575,12 +576,50 @@ public abstract class GFTSPanel extends JPanel worker.start(); } - public abstract String getFTSFrameTitle(); + @Override + public String getTypedText() + { + return txt_search.getText().trim(); + } - public abstract FTSRestClientI getFTSRestClient(); + @Override + public JTable getResultTable() + { + return tbl_summary; + } - public abstract void txt_search_ActionPerformed(); + public void reset() + { + lbl_loading.setVisible(false); + errorWarning.setLength(0); + lbl_warning.setVisible(false); + btn_ok.setEnabled(false); + mainFrame.setTitle(getFTSFrameTitle()); + referesh(); + tbl_summary.setModel(new DefaultTableModel()); + tbl_summary.setVisible(false); + } - public abstract void btn_ok_ActionPerformed(); + @Override + public void setErrorMessage(String message) + { + errorWarning.append(message); + } + + @Override + public void updateSearchFrameTitle(String title) + { + mainFrame.setTitle(title); + } + + @Override + public void setSearchInProgress(Boolean isSearchInProgress) + { + lbl_loading.setVisible(isSearchInProgress); + } + public void referesh() + { + mainFrame.setTitle(getFTSFrameTitle()); + } } diff --git a/src/jalview/fts/service/pdb/PDBFTSPanel.java b/src/jalview/fts/service/pdb/PDBFTSPanel.java index 0b8917d..826a505 100644 --- a/src/jalview/fts/service/pdb/PDBFTSPanel.java +++ b/src/jalview/fts/service/pdb/PDBFTSPanel.java @@ -31,11 +31,13 @@ import jalview.util.MessageManager; import java.util.HashSet; -import javax.swing.table.DefaultTableModel; - @SuppressWarnings("serial") public class PDBFTSPanel extends GFTSPanel { + private static String defaultFTSFrameTitle = MessageManager + .getString("label.pdb_sequence_fetcher"); + + private String ftsFrameTitle = defaultFTSFrameTitle; public PDBFTSPanel(SequenceFetcher seqFetcher) { @@ -45,34 +47,24 @@ public class PDBFTSPanel extends GFTSPanel } - /** - * Action performed when an input is detected on txt_search field. - */ @Override - public void txt_search_ActionPerformed() + public void searchAction() { new Thread() { @Override public void run() { - lbl_loading.setVisible(false); - errorWarning.setLength(0); - lbl_warning.setVisible(false); - btn_ok.setEnabled(false); + ftsFrameTitle = defaultFTSFrameTitle; + reset(); boolean allowEmptySequence = false; - mainFrame.setTitle(getFTSFrameTitle()); - tbl_summary.setModel(new DefaultTableModel()); - tbl_summary.setVisible(false); - if (txt_search.getText().trim().length() > 0) + if (getTypedText().length() > 0) { - lbl_loading.setVisible(true); + setSearchInProgress(true); long startTime = System.currentTimeMillis(); String searchTarget = ((FTSDataColumnI) cmb_searchTarget .getSelectedItem()).getCode(); - - // wantedFields = FTSDataColumnPreferences.getSearchSummaryFields(); wantedFields = PDBFTSRestClient.getInstance() .getAllDefaulDisplayedDataColumns(); String searchTerm = decodeSearchTerm(txt_search.getText(), @@ -84,7 +76,6 @@ public class PDBFTSPanel extends GFTSPanel request.setFieldToSearchBy("(" + searchTarget + ":"); request.setSearchTerm(searchTerm + ")"); request.setWantedFields(wantedFields); - // System.out.println(">>>>>>>>>>>>>> " + request.getQuery()); FTSRestClientI pdbRestCleint = PDBFTSRestClient.getInstance(); FTSRestResponse resultList; try @@ -92,30 +83,31 @@ public class PDBFTSPanel extends GFTSPanel resultList = pdbRestCleint.executeRequest(request); } catch (Exception e) { - // e.printStackTrace(); - errorWarning.append(e.getMessage()); + setErrorMessage(e.getMessage()); checkForErrors(); return; } - if (resultList.getSearchSummary() != null) + if (resultList.getSearchSummary() != null + && resultList.getSearchSummary().size() > 0) { - tbl_summary.setModel(FTSRestResponse.getTableModel(request, + getResultTable().setModel( + FTSRestResponse.getTableModel(request, resultList.getSearchSummary())); - FTSRestResponse.configureTableColumn(tbl_summary, wantedFields); - tbl_summary.setVisible(true); + FTSRestResponse.configureTableColumn(getResultTable(), + wantedFields); + getResultTable().setVisible(true); } - long endTime = System.currentTimeMillis(); int resultSetCount = resultList.getNumberOfItemsFound(); String result = (resultSetCount > 1) ? MessageManager .getString("label.results") : MessageManager .getString("label.result"); - mainFrame.setTitle(getFTSFrameTitle() + " - " + resultSetCount - + " " - + result + " (" + (endTime - startTime) + " milli secs)"); - lbl_loading.setVisible(false); + updateSearchFrameTitle(defaultFTSFrameTitle + " - " + + resultSetCount + " " + result + " (" + + (endTime - startTime) + " milli secs)"); + setSearchInProgress(false); } } }.start(); @@ -158,26 +150,28 @@ public class PDBFTSPanel extends GFTSPanel } @Override - public void btn_ok_ActionPerformed() + public void okAction() { // mainFrame.dispose(); disableActionButtons(); StringBuilder selectedIds = new StringBuilder(); HashSet selectedIdsSet = new HashSet(); - int pdbIdCol = 0; + int primaryKeyColIndex = 0; try { - pdbIdCol = getFTSRestClient().getPrimaryKeyColumIndex(wantedFields, + primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex( + wantedFields, false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - int[] selectedRows = tbl_summary.getSelectedRows(); + int[] selectedRows = getResultTable().getSelectedRows(); for (int summaryRow : selectedRows) { - String idStr = tbl_summary.getValueAt(summaryRow, pdbIdCol) + String idStr = getResultTable().getValueAt(summaryRow, + primaryKeyColIndex) .toString(); String searchTerm = txt_search.getText(); selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm)); @@ -234,7 +228,8 @@ public class PDBFTSPanel extends GFTSPanel @Override public String getFTSFrameTitle() { - return MessageManager.getString("label.pdb_sequence_fetcher"); + return ftsFrameTitle; } + } diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index be1c9ee..6e097dd 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -49,7 +49,7 @@ import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; /** - * A rest client for querying the Search endpoint of the PDB REST API + * A rest client for querying the Search endpoint of the PDB API * * @author tcnofoegbu * @@ -61,8 +61,6 @@ public class PDBFTSRestClient extends FTSRestClient public static final String PDB_SEARCH_ENDPOINT = "http://www.ebi.ac.uk/pdbe/search/pdb/select?"; - private static int DEFAULT_RESPONSE_SIZE = 200; - protected PDBFTSRestClient() { } @@ -86,7 +84,7 @@ public class PDBFTSRestClient extends FTSRestClient String wantedFields = getDataColumnsFieldsAsCommaDelimitedString(pdbRestRequest .getWantedFields()); - int responseSize = (pdbRestRequest.getResponseSize() == 0) ? DEFAULT_RESPONSE_SIZE + int responseSize = (pdbRestRequest.getResponseSize() == 0) ? getDefaultResponsePageSize() : pdbRestRequest.getResponseSize(); String sortParam = null; if (pdbRestRequest.getFieldToSortBy() == null @@ -347,32 +345,23 @@ public class PDBFTSRestClient extends FTSRestClient primaryKey = fieldData; summaryRowData[colCounter++] = primaryKey; } + else if (fieldData == null || fieldData.isEmpty()) + { + summaryRowData[colCounter++] = null; + } else { - if (field.getGroup().getName().equals("Quality Measures")) + try { - try - { - if (fieldData == null || fieldData.isEmpty()) - { - summaryRowData[colCounter++] = null; - } - else - { - Double value = Double.valueOf(fieldData); - summaryRowData[colCounter++] = value; - } - } catch (Exception e) - { - e.printStackTrace(); - System.out.println("offending value:" + fieldData); - summaryRowData[colCounter++] = 0.0; - } - } - else + summaryRowData[colCounter++] = (field.getDataColumnClass() == Integer.class) ? Integer + .valueOf(fieldData) + : (field.getDataColumnClass() == Double.class) ? Double + .valueOf(fieldData) + : fieldData; + } catch (Exception e) { - summaryRowData[colCounter++] = (fieldData == null || fieldData - .isEmpty()) ? null : fieldData; + e.printStackTrace(); + System.out.println("offending value:" + fieldData); } } } @@ -422,9 +411,9 @@ public class PDBFTSRestClient extends FTSRestClient } @Override - public String getColumnDataConfigFile() + public String getColumnDataConfigFileName() { - return getFile("fts/pdb_data_columns.conf"); + return getResourceFile("fts/pdb_data_columns.conf"); } diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java new file mode 100644 index 0000000..2930468 --- /dev/null +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -0,0 +1,91 @@ +package jalview.fts.service.uniprot; + +import jalview.fts.api.FTSRestClientI; +import jalview.fts.core.FTSRestClient; +import jalview.fts.core.FTSRestRequest; +import jalview.fts.core.FTSRestResponse; + +import javax.ws.rs.core.MediaType; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; + +public class UniProtRestClient extends FTSRestClient +{ + private static FTSRestClientI instance = null; + + public static final String UNIPROT_SEARCH_ENDPOINT = "http://www.uniprot.org/uniprot/?"; + + private static int DEFAULT_RESPONSE_SIZE = 200; + + @Override + public FTSRestResponse executeRequest(FTSRestRequest uniportRestRequest) + { + ClientConfig clientConfig = new DefaultClientConfig(); + Client client = Client.create(clientConfig); + + @SuppressWarnings("unchecked") + // String wantedFields = + // getUniProtDocFieldsAsCommaDelimitedString((Collection) + // uniportRestRequest + // .getWantedFields()); + int responseSize = (uniportRestRequest.getResponseSize() == 0) ? DEFAULT_RESPONSE_SIZE + : uniportRestRequest.getResponseSize(); + + WebResource webResource = null; + + webResource = client.resource(UNIPROT_SEARCH_ENDPOINT) + .queryParam("format", "tab") + // .queryParam("columns", wantedFields) + .queryParam("limit", String.valueOf(responseSize)) + .queryParam("query", "name:filaggrin"); + // Execute the REST request + ClientResponse clientResponse = webResource + .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class); + String responseString = clientResponse.getEntity(String.class); + String[] results = responseString.split("\n"); + for (String result : results) + { + String[] columns = result.split("\t"); + System.out.println("Entry : " + columns[0]); + System.out.println("Entry name : " + columns[1]); + System.out.println("Status : " + columns[2]); + System.out.println("Protein names : " + columns[3]); + System.out.println("Gene name : " + columns[4]); + System.out.println("Organism : " + columns[5]); + System.out.println("Lenght : " + columns[6]); + System.out.println(""); + } + + // Make redundant objects eligible for garbage collection to conserve + // memory + clientResponse = null; + client = null; + return null; + + // Process the response and return the result to the caller. + // return parsePDBJsonResponse(responseString, pdbRestRequest); + // System.out.println(">>>>> " + responseString); + + } + + + public static FTSRestClientI getInstance() + { + if (instance == null) + { + instance = new UniProtRestClient(); + } + return instance; + } + + @Override + public String getColumnDataConfigFile() + { + return "fts/uniprot_data_columns.conf"; + } + +} diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java new file mode 100644 index 0000000..51d7735 --- /dev/null +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -0,0 +1,47 @@ +package jalview.fts.service.uniprot; + +import jalview.fts.api.FTSRestClientI; +import jalview.fts.core.GFTSPanel; +import jalview.gui.SequenceFetcher; +import jalview.util.MessageManager; + +@SuppressWarnings("serial") +public class UniprotFTSPanel extends GFTSPanel +{ + + + public UniprotFTSPanel(SequenceFetcher seqFetcher) + { + this.seqFetcher = seqFetcher; + this.progressIdicator = (seqFetcher == null) ? null : seqFetcher + .getProgressIndicator(); + } + + @Override + public void txt_search_ActionPerformed() + { + // TODO Auto-generated method stub + + } + + @Override + public void btn_ok_ActionPerformed() + { + // TODO Auto-generated method stub + + } + + + @Override + public FTSRestClientI getFTSRestClient() + { + return UniProtRestClient.getInstance(); + } + + @Override + public String getFTSFrameTitle() + { + return MessageManager.getString("label.uniprot_sequence_fetcher"); + } + +} diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index da88b12..ab78ad3 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -27,6 +27,7 @@ import jalview.datamodel.DBRefEntry; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.fts.service.pdb.PDBFTSPanel; +import jalview.fts.service.uniprot.UniprotFTSPanel; import jalview.io.gff.SequenceOntologyI; import jalview.util.DBRefUtils; import jalview.util.MessageManager; @@ -373,15 +374,21 @@ public class SequenceFetcher extends JPanel implements Runnable { debounceTrap++; String currentSelection = database.getSelectedItem(); - if (!currentSelection.equalsIgnoreCase("pdb")) - { - otherSourceAction(); - } + if (currentSelection.equalsIgnoreCase("pdb") && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0))) { pdbSourceAction(); } + else if (currentSelection.equalsIgnoreCase("uniprot") + && (database.action == KeyEvent.VK_ENTER || ((debounceTrap % 2) == 0))) + { + uniprotSourceAction(); + } + else + { + otherSourceAction(); + } database.action = -1; } }); @@ -409,6 +416,12 @@ public class SequenceFetcher extends JPanel implements Runnable frame.dispose(); } + private void uniprotSourceAction() + { + databaseButt.setText(database.getSelectedItem()); + new UniprotFTSPanel(this); + frame.dispose(); + } private void otherSourceAction() { try diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 2d9028a..d924e73 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -29,7 +29,6 @@ import jalview.datamodel.SequenceI; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; -import jalview.fts.core.FTSDataColumnPreferences; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.fts.service.pdb.PDBFTSRestClient; @@ -147,8 +146,9 @@ public class StructureChooser extends GStructureChooser implements public void fetchStructuresMetaData() { long startTime = System.currentTimeMillis(); - Collection wantedFields = FTSDataColumnPreferences - .getStructureSummaryFields(); + pdbRestCleint = PDBFTSRestClient.getInstance(); + Collection wantedFields = pdbRestCleint + .getAllDefaulDisplayedDataColumns(); discoveredStructuresSet = new LinkedHashSet(); HashSet errors = new HashSet(); @@ -161,7 +161,6 @@ public class StructureChooser extends GStructureChooser implements pdbRequest.setWantedFields(wantedFields); pdbRequest.setSearchTerm(buildQuery(seq) + ")"); pdbRequest.setAssociatedSequence(seq); - pdbRestCleint = PDBFTSRestClient.getInstance(); FTSRestResponse resultList; try { @@ -395,9 +394,10 @@ public class StructureChooser extends GStructureChooser implements public void run() { long startTime = System.currentTimeMillis(); + pdbRestCleint = PDBFTSRestClient.getInstance(); lbl_loading.setVisible(true); - Collection wantedFields = FTSDataColumnPreferences - .getStructureSummaryFields(); + Collection wantedFields = pdbRestCleint + .getAllDefaulDisplayedDataColumns(); Collection filteredResponse = new HashSet(); HashSet errors = new HashSet(); @@ -428,7 +428,6 @@ public class StructureChooser extends GStructureChooser implements pdbRequest.setWantedFields(wantedFields); pdbRequest.setAssociatedSequence(seq); } - pdbRestCleint = PDBFTSRestClient.getInstance(); FTSRestResponse resultList; try { diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index ed94172..a5b03d8 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -474,9 +474,9 @@ public abstract class GStructureChooser extends JPanel implements btn_cancel.setEnabled(false); btn_view.setVisible(false); btn_cancel.setVisible(false); - previousWantedFields = FTSDataColumnPreferences - .getStructureSummaryFields().toArray( - new FTSDataColumnI[0]); + previousWantedFields = PDBFTSRestClient.getInstance() + .getAllDefaulDisplayedDataColumns() + .toArray(new FTSDataColumnI[0]); } if (sourceTabbedPane.getTitleAt(index) .equals(foundStructureSummary)) @@ -528,7 +528,9 @@ public abstract class GStructureChooser extends JPanel implements return true; } - return Arrays.equals(FTSDataColumnPreferences.getStructureSummaryFields() + return Arrays.equals( + PDBFTSRestClient.getInstance() + .getAllDefaulDisplayedDataColumns() .toArray(new FTSDataColumnI[0]), previousWantedFields) ? false : true; diff --git a/test/jalview/fts/service/pdb/PDBFTSRestClientTest.java b/test/jalview/fts/service/pdb/PDBFTSRestClientTest.java index 39d9aa5..d6203c6 100644 --- a/test/jalview/fts/service/pdb/PDBFTSRestClientTest.java +++ b/test/jalview/fts/service/pdb/PDBFTSRestClientTest.java @@ -26,7 +26,6 @@ import static org.testng.AssertJUnit.assertTrue; import jalview.fts.api.FTSDataColumnI; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; -import jalview.fts.service.pdb.PDBFTSRestClient; import java.io.BufferedReader; import java.io.FileReader; @@ -134,7 +133,7 @@ public class PDBFTSRestClientTest } String expectedResult = "molecule_type,pdb_id,genus,gene_name,title"; - String actualResult = PDBFTSRestClient + String actualResult = PDBFTSRestClient.getInstance() .getDataColumnsFieldsAsCommaDelimitedString(wantedFields); assertEquals("", expectedResult, actualResult); -- 1.7.10.2