From: Charles Ofoegbu Date: Wed, 18 Mar 2015 10:58:26 +0000 (+0000) Subject: JAL-1668 added PDBDocFieldPreference for configuring rest response summary fields X-Git-Tag: Jalview_2_9~71^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fd235cc7542d6e308e054a8a76580a6c511ae631;p=jalview.git JAL-1668 added PDBDocFieldPreference for configuring rest response summary fields --- diff --git a/src/jalview/gui/PDBSearchPanel.java b/src/jalview/gui/PDBSearchPanel.java index 7aa0bb3..bb75413 100644 --- a/src/jalview/gui/PDBSearchPanel.java +++ b/src/jalview/gui/PDBSearchPanel.java @@ -22,20 +22,19 @@ package jalview.gui; import jalview.jbgui.GPDBSearchPanel; +import jalview.jbgui.PDBDocFieldPreferences; import jalview.util.MessageManager; import jalview.ws.dbsources.PDBRestClient; import jalview.ws.dbsources.PDBRestClient.PDBDocField; import jalview.ws.uimodel.PDBRestRequest; import jalview.ws.uimodel.PDBRestResponse; -import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; -import javax.swing.DefaultListModel; - @SuppressWarnings("serial") public class PDBSearchPanel extends GPDBSearchPanel { @@ -43,6 +42,8 @@ public class PDBSearchPanel extends GPDBSearchPanel private IProgressIndicator progressIdicator; + private Collection wantedFields; + public PDBSearchPanel(SequenceFetcher seqFetcher) { this.seqFetcher = seqFetcher; @@ -51,11 +52,13 @@ public class PDBSearchPanel extends GPDBSearchPanel } + /** + * Action performed when an input is detected on txt_search field. + */ @Override public void txt_search_ActionPerformed() { boolean allowEmptySequence = false; - lst_searchResult.setModel(new DefaultListModel()); mainFrame.setTitle(MessageManager .getString("label.pdb_sequence_getcher")); if (txt_search.getText().trim().length() > 0) @@ -65,14 +68,8 @@ public class PDBSearchPanel extends GPDBSearchPanel String searchTarget = ((PDBDocField) cmb_searchTarget .getSelectedItem()).getCode(); - List wantedFields = new ArrayList(); - wantedFields.add(PDBDocField.MOLECULE_TYPE); - wantedFields.add(PDBDocField.PDB_ID); - // wantedFields.add(PDBDocField.GENUS); - wantedFields.add(PDBDocField.GENE_NAME); - wantedFields.add(PDBDocField.TITLE); - // wantedFields.add(PDBDocField.RESOLUTION); - // wantedFields.add(PDBDocField.EXPERIMENTAL_METHOD); + wantedFields = PDBDocFieldPreferences + .getSearchSummaryFields(); PDBRestRequest request = new PDBRestRequest(); request.setAllowEmptySeq(allowEmptySequence); @@ -85,8 +82,8 @@ public class PDBSearchPanel extends GPDBSearchPanel PDBRestResponse resultList = pdbRestCleint.executeRequest(request); if (resultList.getSearchSummary() != null) { - lst_searchResult.setModel(PDBRestResponse - .getListModel(resultList.getSearchSummary())); + tbl_summary.setModel(PDBRestResponse.getTableModel(request, + resultList.getSearchSummary())); } long endTime = System.currentTimeMillis(); @@ -125,11 +122,15 @@ public class PDBSearchPanel extends GPDBSearchPanel { mainFrame.dispose(); StringBuilder selectedIds = new StringBuilder(); - for (PDBResponseSummary dataSelected : lst_searchResult - .getSelectedValuesList()) + int pdbIdCol = PDBRestClient.getPDBIdColumIndex(wantedFields, false); + int[] selectedRows = tbl_summary.getSelectedRows(); + for (int summaryRow : selectedRows) { - selectedIds.append(";").append(dataSelected.getPdbId()); + String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol) + .toString(); + selectedIds.append(";").append(pdbIdStr); } + String ids = selectedIds.deleteCharAt(0).toString(); seqFetcher.textArea.setText(ids); Thread worker = new Thread(seqFetcher); diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index a01c1b8..f28ef68 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -25,6 +25,7 @@ import jalview.datamodel.DBRefEntry; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.jbgui.GStructureChooser; +import jalview.jbgui.PDBDocFieldPreferences; import jalview.util.MessageManager; import jalview.ws.dbsources.PDBRestClient; import jalview.ws.dbsources.PDBRestClient.PDBDocField; @@ -126,12 +127,9 @@ public class StructureChooser extends GStructureChooser public void fetchStructuresMetaData() { long startTime = System.currentTimeMillis(); - List wantedFields = new ArrayList(); - // wantedFields.add(PDBDocField.MOLECULE_TYPE); - wantedFields.add(PDBDocField.PDB_ID); - // wantedFields.add(PDBDocField.GENUS); - // wantedFields.add(PDBDocField.GENE_NAME); - wantedFields.add(PDBDocField.TITLE); + Collection wantedFields = PDBDocFieldPreferences + .getStructureSummaryFields(); + pdbRequest = new PDBRestRequest(); pdbRequest.setAllowEmptySeq(false); pdbRequest.setResponseSize(500); @@ -307,27 +305,7 @@ public class StructureChooser extends GStructureChooser filterThread.start(); } - /** - * Determines the column index for the pdb id in the summary table. The pdb id - * serves as a unique identifier for a given row in the summary table - * - * @param wantedFeilds - * the available table columns in no particular order - * @return the pdb id field column index - */ - public static int getPDBIdColumIndex(Collection wantedFeilds) - { - int pdbFeildIndex = 1; - for (PDBDocField feild : wantedFeilds) - { - if (feild.equals(PDBDocField.PDB_ID)) - { - break; - } - ++pdbFeildIndex; - } - return pdbFeildIndex; - } + /** * Handles action event for btn_pdbFromFile @@ -525,7 +503,8 @@ public class StructureChooser extends GStructureChooser String currentView = selectedFilterOpt.getView(); if (currentView == VIEWS_FILTER) { - int pdbIdCol = getPDBIdColumIndex(pdbRequest.getWantedFields()); + int pdbIdCol = PDBRestClient.getPDBIdColumIndex( + pdbRequest.getWantedFields(), true); int[] selectedRows = tbl_summary.getSelectedRows(); PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length]; int count = 0; diff --git a/src/jalview/jbgui/GPDBSearchPanel.java b/src/jalview/jbgui/GPDBSearchPanel.java index a236a5a..b350a0f 100644 --- a/src/jalview/jbgui/GPDBSearchPanel.java +++ b/src/jalview/jbgui/GPDBSearchPanel.java @@ -24,7 +24,6 @@ package jalview.jbgui; import jalview.gui.Desktop; import jalview.util.MessageManager; import jalview.ws.dbsources.PDBRestClient.PDBDocField; -import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary; import java.awt.BorderLayout; import java.awt.Dimension; @@ -35,11 +34,10 @@ import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JInternalFrame; -import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.ListSelectionModel; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -67,10 +65,16 @@ public abstract class GPDBSearchPanel extends JPanel protected JTextField txt_search = new JTextField(20); - protected JList lst_searchResult = new JList(); + // protected JList lst_searchResult = new + // JList(); + + // protected JScrollPane scrl_searchResult = new JScrollPane( + // lst_searchResult); + + protected JTable tbl_summary = new JTable(); protected JScrollPane scrl_searchResult = new JScrollPane( - lst_searchResult); +tbl_summary); private JPanel pnl_actions = new JPanel(); @@ -131,10 +135,11 @@ public abstract class GPDBSearchPanel extends JPanel pnl_actions.add(btn_ok); pnl_actions.add(btn_cancel); - lst_searchResult - .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - lst_searchResult.setLayoutOrientation(JList.VERTICAL); - lst_searchResult.setVisibleRowCount(-1); + // lst_searchResult + // .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + // lst_searchResult.setLayoutOrientation(JList.VERTICAL); + // lst_searchResult.setVisibleRowCount(-1); + scrl_searchResult.setPreferredSize(new Dimension(500, 300)); scrl_searchResult .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 3596619..713a747 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -149,6 +149,7 @@ public class GPreferences extends JPanel protected JTextField chimeraPath = new JTextField(); + /* * Colours tab components */ @@ -729,8 +730,8 @@ public class GPreferences extends JPanel .getString("label.structure_options"))); structureTab.setLayout(null); final int width = 400; - final int height = 23; - final int lineSpacing = 30; + final int height = 22; + final int lineSpacing = 25; int ypos = 30; structFromPdb.setFont(verdana11); @@ -824,9 +825,22 @@ public class GPreferences extends JPanel }); structureTab.add(chimeraPath); + ypos += lineSpacing; + // scrl_pdbDocFieldConfig.setPreferredSize(new Dimension(450, 100)); + // scrl_pdbDocFieldConfig + // .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + // scrl_pdbDocFieldConfig.setBounds(); + PDBDocFieldPreferences docFieldPref = new PDBDocFieldPreferences( + new Rectangle(10, ypos + 5, 450, 120)); + structureTab.add(docFieldPref); + + + + return structureTab; } + /** * Action on choosing a structure viewer from combobox options. * diff --git a/src/jalview/jbgui/PDBDocFieldPreferences.java b/src/jalview/jbgui/PDBDocFieldPreferences.java new file mode 100644 index 0000000..9380380 --- /dev/null +++ b/src/jalview/jbgui/PDBDocFieldPreferences.java @@ -0,0 +1,178 @@ +package jalview.jbgui; + +import jalview.ws.dbsources.PDBRestClient.PDBDocField; + +import java.awt.Rectangle; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; + +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.AbstractTableModel; + +@SuppressWarnings("serial") +public class PDBDocFieldPreferences extends JScrollPane +{ + + protected JTable tbl_pdbDocFieldConfig = new JTable(); + + protected JScrollPane scrl_pdbDocFieldConfig = new JScrollPane( + tbl_pdbDocFieldConfig); + + private HashMap map = new HashMap(); + + private static Collection searchSummaryFields = new HashSet(); + + private static Collection structureSummaryFields = new HashSet(); + + static + { + searchSummaryFields.add(PDBDocField.PDB_ID); + searchSummaryFields.add(PDBDocField.TITLE); + structureSummaryFields.add(PDBDocField.PDB_ID); + structureSummaryFields.add(PDBDocField.TITLE); + } + + public PDBDocFieldPreferences(Rectangle position) + { + this.setBounds(position); + this.getViewport().add(tbl_pdbDocFieldConfig); + + Object[][] data = new Object[PDBDocField.values().length - 1][3]; + int x = 0; + for (PDBDocField field : PDBDocField.values()) + { + if (field.getName().equalsIgnoreCase("all")) + { + continue; + } + + data[x++] = new Object[] + { field.getName(), searchSummaryFields.contains(field), + structureSummaryFields.contains(field) }; + map.put(field.getName(), field); + } + + PDBFieldTableModel model = new PDBFieldTableModel(data); + tbl_pdbDocFieldConfig.setModel(model); + } + + public static Collection getSearchSummaryFields() + { + return searchSummaryFields; + } + + public static void setSearchSummaryFields( + Collection searchSummaryFields) + { + PDBDocFieldPreferences.searchSummaryFields = searchSummaryFields; + } + + public static Collection getStructureSummaryFields() + { + return structureSummaryFields; + } + + public static void setStructureSummaryFields( + Collection structureSummaryFields) + { + PDBDocFieldPreferences.structureSummaryFields = structureSummaryFields; + } + + class PDBFieldTableModel extends AbstractTableModel + { + + public PDBFieldTableModel(Object[][] data) + { + this.data = data; + } + + private String[] columnNames = new String[] + { "PDB Feild", "Show in search summary", + "Show in structure chooser summary" }; + + private Object[][] data; + + public int getColumnCount() + { + return columnNames.length; + } + + public int getRowCount() + { + return data.length; + } + + public String getColumnName(int col) + { + return columnNames[col]; + } + + public Object getValueAt(int row, int col) + { + return data[row][col]; + } + + /* + * JTable uses this method to determine the default renderer/ editor for + * each cell. If we didn't implement this method, then the last column would + * contain text ("true"/"false"), rather than a check box. + */ + public Class getColumnClass(int c) + { + return getValueAt(0, c).getClass(); + } + + /* + * Don't need to implement this method unless your table's editable. + */ + public boolean isCellEditable(int row, int col) + { + // Note that the data/cell address is constant, + // no matter where the cell appears onscreen. + return col == 1 || col == 2; + + } + + /* + * Don't need to implement this method unless your table's data can change. + */ + public void setValueAt(Object value, int row, int col) + { + data[row][col] = value; + fireTableCellUpdated(row, col); + + String name = getValueAt(row, 0).toString(); + boolean selected = ((Boolean) value).booleanValue(); + + PDBDocField pdbField = map.get(name); + + if (col == 1) + { + if (searchSummaryFields.contains(pdbField) && !selected) + { + searchSummaryFields.remove(pdbField); + } + + if (!searchSummaryFields.contains(pdbField) && selected) + { + searchSummaryFields.add(pdbField); + } + } + else if (col == 2) + { + if (structureSummaryFields.contains(pdbField) && !selected) + { + structureSummaryFields.remove(pdbField); + } + + if (!structureSummaryFields.contains(pdbField) && selected) + { + structureSummaryFields.add(pdbField); + } + } + + } + } +} diff --git a/src/jalview/ws/dbsources/PDBRestClient.java b/src/jalview/ws/dbsources/PDBRestClient.java index 85701b2..1a80d65 100644 --- a/src/jalview/ws/dbsources/PDBRestClient.java +++ b/src/jalview/ws/dbsources/PDBRestClient.java @@ -5,6 +5,7 @@ import jalview.ws.uimodel.PDBRestResponse; import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -172,7 +173,7 @@ public class PDBRestClient * @return */ public static String getPDBDocFieldsAsCommaDelimitedString( - List pdbDocfields) + Collection pdbDocfields) { String result = ""; if (pdbDocfields != null && !pdbDocfields.isEmpty()) @@ -188,6 +189,28 @@ public class PDBRestClient return result; } + /** + * Determines the column index for the pdb id in the summary table. The pdb id + * serves as a unique identifier for a given row in the summary table + * + * @param wantedFeilds + * the available table columns in no particular order + * @return the pdb id field column index + */ + public static int getPDBIdColumIndex( + Collection wantedFeilds, boolean hasRefSeq) + { + int pdbFeildIndex = hasRefSeq ? 1 : 0; + for (PDBDocField feild : wantedFeilds) + { + if (feild.equals(PDBDocField.PDB_ID)) + { + break; + } + ++pdbFeildIndex; + } + return pdbFeildIndex; + } /** * Represents the fields retrievable from a PDB Document response @@ -198,21 +221,76 @@ public class PDBRestClient PDB_ID("PDB Id", "pdb_id"), TITLE("Title", "title"), MOLECULE_NAME( "Molecule", "molecule_name"), MOLECULE_TYPE("Molecule Type", "molecule_type"), MOLECULE_SEQUENCE("Sequence", - "molecule_sequence"), UNIPROT_FEATURES("Uniprot Features", - "uniprot_features"), PFAM_ACCESSION("PFAM Accession", - "pfam_accession"), INTERPRO_ACCESSION("InterPro Accession", - "interpro_accession"), UNIPROT_ACCESSION("UniProt Accession", - "uniprot_accession"), R_FACTOR("R Factor", "r_factor"), RESOLUTION( - "Resolution", "resolution"), DATA_QUALITY("Data Quality", - "data_quality"), OVERALL_QUALITY("Overall Quality", - "overall_quality"), POLYMER_COUNT("Polymer Count", - "number_of_polymers"), PROTEIN_CHAIN_COUNT( - "Protein Chain Count", "number_of_protein_chains"), BOUND_MOLECULE_COUNT( - "Bound Molecule Count", "number_of_bound_molecules"), POLYMER_RESIDUE_COUNT( - "Polymer Residue Count", "number_of_polymer_residues"), UNIPROT_COVERAGE( - "UniProt Coverage", "uniprot_coverage"), GENUS("GENUS", "genus"), GENE_NAME( - "Gene Name", "gene_name"), EXPERIMENTAL_METHOD( - "Experimental Method", "experimental_method"), ALL("ALL", + "molecule_sequence"), PFAM_ACCESSION("PFAM Accession", + "pfam_accession"), PFAM_NAME("PFAM Name", "pfam_name"), INTERPRO_NAME( + "InterPro Name", "interpro_name"), INTERPRO_ACCESSION( + "InterPro Accession", "interpro_accession"), UNIPROT_ID( + "UniProt Id", "uniprot_id"), UNIPROT_ACCESSION( + "UniProt Accession", "uniprot_accession"), UNIPROT_COVERAGE( + "UniProt Coverage", "uniprot_coverage"), UNIPROT_FEATURES( + "Uniprot Features", "uniprot_features"), R_FACTOR("R Factor", + "r_factor"), RESOLUTION("Resolution", "resolution"), DATA_QUALITY( + "Data Quality", "data_quality"), OVERALL_QUALITY( + "Overall Quality", "overall_quality"), POLYMER_COUNT( + "Number of Polymers", "number_of_polymers"), PROTEIN_CHAIN_COUNT( + "Number of Protein Chains", "number_of_protein_chains"), BOUND_MOLECULE_COUNT( + "Number of Bound Molecule", "number_of_bound_molecules"), POLYMER_RESIDUE_COUNT( + "Number of Polymer Residue", "number_of_polymer_residues"), GENUS( + "GENUS", "genus"), GENE_NAME("Gene Name", "gene_name"), EXPERIMENTAL_METHOD( + "Experimental Method", "experimental_method"), GO_ID("GO Id", + "go_id"), ASSEMBLY_ID("Assembly Id", "assembly_form"), ASSEMBLY_FORM( + "Assembly Form", "assembly_id"), ASSEMBLY_TYPE("Assembly Type", + "assembly_type"), SPACE_GROUP("Space Group", "spacegroup"), CATH_CODE( + "Cath Code", "cath_code"), TAX_ID("Tax Id", "tax_id"), TAX_QUERY( + "Tax Query", "tax_query"), INTERACTING_ENTRY_ID( + "Interacting Entry Id", "interacting_entry_id"), INTERACTING_ENTITY_ID( + "Interacting Entity Id", "interacting_entity_id"), INTERACTING_MOLECULES( + "Interacting Molecules", "interacting_molecules"), PUBMED_ID( + "Pubmed Id", "pubmed_id"), STATUS("Status", "status"), MODEL_QUALITY( + "Model Quality", "model_quality"), PIVOT_RESOLUTION( + "Pivot Resolution", "pivot_resolution"), DATA_REDUCTION_SOFTWARE( + "Data reduction software", "data_reduction_software"), MAX_OBSERVED_RES( + "Max observed residues", "max_observed_residues"), ORG_SCI_NAME( + "Organism scientific name", "organism_scientific_name"), SUPER_KINGDOM( + "Super kingdom", "superkingdom"), RANK("Rank", "rank"), CRYSTALLISATION_PH( + "Crystallisation Ph", "crystallisation_ph"), BIO_FUNCTION( + "Biological Function", "biological_function"), BIO_PROCESS( + "Biological Process", "biological_process"), BIO_CELL_COMP( + "Biological Cell Component", "biological_cell_component"), COMPOUND_NAME( + "Compound Name", "compound_name"), COMPOUND_ID("Compound Id", + "compound_id"), COMPOUND_WEIGHT("Compound Weight", + "compound_weight"), COMP_SYS_NAME("Compound Systematic Name", + "compound_systematic_name"), INTERACTING_LIG( + "Interacting Ligands", "interacting_ligands"), JOURNAL( + "Journal", "journal"), ALL_AUTHORS("All Authors", "all_authors"), EXPERIMENTAL_DATA_AVAILABLE( + "Experiment Data Available", "experiment_data_available"), DIFFRACTION_PROTOCOL( + "Diffraction Protocol", "diffraction_protocol"), REFINEMENT_SOFTWARE( + "Refinement Software", "refinement_software"), STRUCTURE_DETERMINATION_METHOD( + "Structure Determination Method", + "structure_determination_method"), SYNCHROTON_SITE( + "Synchrotron Site", "synchrotron_site"), SAMPLE_PREP_METHOD( + "Sample Preparation Method", "sample_preparation_method"), ENTRY_AUTHORS( + "Entry Authors", "entry_authors"), CITATION_TITLE( + "Citation Title", "citation_title"), STRUCTURE_SOLUTION_SOFTWARE( + "Structure Solution Software", "structure_solution_software"), ENTRY_ENTITY( + "Entry Entity", "entry_entity"), R_FREE("R Free", "r_free"), NO_OF_POLYMER_ENTITIES( + "Number of Polymer Entities", "number_of_polymer_entities"), NO_OF_BOUND_ENTITIES( + "Number of Bound Entities", "number_of_bound_entities"), CRYSTALLISATION_RESERVOIR( + "Crystallisation Reservoir", "crystallisation_reservoir"), DATA_SCALING_SW( + "Data Scalling Software", "data_scaling_software"), DETECTOR( + "Detector", "detector"), DETECTOR_TYPE("Detector Type", + "detector_type"), MODIFIED_RESIDUE_FLAG( + "Modified Residue Flag", "modified_residue_flag"), NUMBER_OF_COPIES( + "Number of Copies", "number_of_copies"), STRUCT_ASYM_ID( + "Struc Asym Id", "struct_asym_id"), HOMOLOGUS_PDB_ENTITY_ID( + "Homologus PDB Entity Id", "homologus_pdb_entity_id"), MOLECULE_SYNONYM( + "Molecule Synonym", "molecule_synonym"), DEPOSITION_SITE( + "Deposition Site", "deposition_site"), SYNCHROTRON_BEAMLINE( + "Synchrotron Beamline", "synchrotron_beamline"), ENTITY_ID( + "Entity Id", "entity_id"), BEAM_SOURCE_NAME("Beam Source Name", + "beam_source_name"), PROCESSING_SITE("Processing Site", + "processing_site"), ENTITY_WEIGHT("Entity Weight", + "entity_weight"), VERSION("Version", "_version_"), ALL("ALL", "text"); private String name; diff --git a/src/jalview/ws/uimodel/PDBRestRequest.java b/src/jalview/ws/uimodel/PDBRestRequest.java index 168811f..2b9a7f3 100644 --- a/src/jalview/ws/uimodel/PDBRestRequest.java +++ b/src/jalview/ws/uimodel/PDBRestRequest.java @@ -24,8 +24,7 @@ package jalview.ws.uimodel; import jalview.ws.dbsources.PDBRestClient.PDBDocField; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; /** * Represents the PDB request to be consumed by the PDBRestClient @@ -49,7 +48,8 @@ public class PDBRestRequest private boolean isSortAscending; - private List wantedFields = new ArrayList(); + private Collection wantedFields;// = new + // Collection(); public String getFieldToSearchBy() { @@ -91,12 +91,12 @@ public class PDBRestRequest this.responseSize = responseSize; } - public List getWantedFields() + public Collection getWantedFields() { return wantedFields; } - public void setWantedFields(List wantedFields) + public void setWantedFields(Collection wantedFields) { this.wantedFields = wantedFields; } diff --git a/src/jalview/ws/uimodel/PDBRestResponse.java b/src/jalview/ws/uimodel/PDBRestResponse.java index 5a1f53d..889a324 100644 --- a/src/jalview/ws/uimodel/PDBRestResponse.java +++ b/src/jalview/ws/uimodel/PDBRestResponse.java @@ -24,7 +24,6 @@ package jalview.ws.uimodel; import jalview.ws.dbsources.PDBRestClient.PDBDocField; import java.util.Collection; -import java.util.List; import java.util.Objects; import javax.swing.DefaultListModel; @@ -149,8 +148,8 @@ public class PDBRestResponse public PDBResponseSummary(JSONObject doc, PDBRestRequest request) { - StringBuilder summaryBuilder = new StringBuilder(); - List diplayFields = request.getWantedFields(); + StringBuilder summaryBuilder = new StringBuilder(); + Collection diplayFields = request.getWantedFields(); String associatedSeq = request.getAssociatedSequence(); int colCounter = 0; summaryData = new String[(associatedSeq != null) ? diplayFields @@ -165,54 +164,22 @@ public class PDBRestResponse for (PDBDocField field : diplayFields) { - if (field.equals(PDBDocField.MOLECULE_TYPE) - && doc.get(PDBDocField.MOLECULE_TYPE.getCode()) != null) - { - String moleculeType = doc - .get(PDBDocField.MOLECULE_TYPE.getCode()).toString(); - if (moleculeType.equalsIgnoreCase("protein")) - { - summaryBuilder.append(""); - } - if (moleculeType.equalsIgnoreCase("dna")) - { - summaryBuilder.append(""); - } - if (moleculeType.equalsIgnoreCase("rna")) - { - summaryBuilder.append(""); - } - if (moleculeType.equalsIgnoreCase("sugar")) - { - summaryBuilder.append(""); - } - summaryData[colCounter++] = moleculeType; - } - else if (field.equals(PDBDocField.PDB_ID) + if (field.equals(PDBDocField.PDB_ID) && doc.get(PDBDocField.PDB_ID.getCode()) != null) { this.pdbId = doc.get(PDBDocField.PDB_ID.getCode()).toString(); - summaryBuilder.append(this.pdbId).append(" | "); summaryData[colCounter++] = this.pdbId; } - else if (doc.get(field.getCode()) != null) + else { - summaryBuilder.append(field.getName()).append(": ") - .append(doc.get(field.getCode())).append(" | "); - summaryData[colCounter++] = doc.get(field.getCode()).toString(); + String value = (doc.get(field.getCode()) == null) ? "" : doc.get( + field.getCode()).toString(); + summaryBuilder.append(field.getName()).append(": ").append(value) + .append(" | "); + summaryData[colCounter++] = value; } } - int endIndex = summaryBuilder.lastIndexOf(" | "); - String fSummary = summaryBuilder.toString().substring(0, endIndex); - this.concatenatedSummaryData = fSummary.trim(); + this.concatenatedSummaryData = summaryBuilder.toString(); summaryBuilder = null; } diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java index 078174f..24e8bc9 100644 --- a/test/jalview/gui/StructureChooserTest.java +++ b/test/jalview/gui/StructureChooserTest.java @@ -6,10 +6,7 @@ import jalview.datamodel.DBRefEntry; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; -import jalview.ws.dbsources.PDBRestClient.PDBDocField; -import java.util.ArrayList; -import java.util.List; import java.util.Vector; import org.junit.After; @@ -47,17 +44,7 @@ public class StructureChooserTest seq = null; } - @Test - public void getPDBIdColumIndexTest() - { - List wantedFields = new ArrayList(); - wantedFields.add(PDBDocField.MOLECULE_TYPE); - wantedFields.add(PDBDocField.GENUS); - wantedFields.add(PDBDocField.GENE_NAME); - wantedFields.add(PDBDocField.TITLE); - wantedFields.add(PDBDocField.PDB_ID); - assertEquals(5, StructureChooser.getPDBIdColumIndex(wantedFields)); - } + @Test public void buildQueryTest() diff --git a/test/jalview/ws/dbsources/PDBRestClientTest.java b/test/jalview/ws/dbsources/PDBRestClientTest.java index 3f33ffe..ba07562 100644 --- a/test/jalview/ws/dbsources/PDBRestClientTest.java +++ b/test/jalview/ws/dbsources/PDBRestClientTest.java @@ -141,6 +141,19 @@ public class PDBRestClientTest assertTrue(response.getSearchSummary().size() == 14); } + @Test + public void getPDBIdColumIndexTest() + { + List wantedFields = new ArrayList(); + wantedFields.add(PDBDocField.MOLECULE_TYPE); + wantedFields.add(PDBDocField.GENUS); + wantedFields.add(PDBDocField.GENE_NAME); + wantedFields.add(PDBDocField.TITLE); + wantedFields.add(PDBDocField.PDB_ID); + assertEquals(5, PDBRestClient.getPDBIdColumIndex(wantedFields, true)); + assertEquals(4, PDBRestClient.getPDBIdColumIndex(wantedFields, false)); + } + public String readJsonStringFromFile(String filePath) throws IOException { String fileContent;