From 0ae0771700df811f421f8548e40dae2cd11cfae0 Mon Sep 17 00:00:00 2001 From: Charles Ofoegbu Date: Fri, 6 Mar 2015 19:17:14 +0000 Subject: [PATCH] JAL-1668 added filtering and sorting capabilites --- resources/images/loading.gif | Bin 0 -> 1849 bytes src/jalview/gui/PDBFetchPanel.java | 7 +- src/jalview/gui/StructureChooser.java | 309 ++++++++++++++++--------- src/jalview/jbgui/GStructureChooser.java | 56 ++++- src/jalview/util/MessageManager.java | 5 + src/jalview/ws/dbsources/PDBRestClient.java | 18 +- src/jalview/ws/uimodel/PDBSearchRequest.java | 34 ++- src/jalview/ws/uimodel/PDBSearchResponse.java | 88 ++++++- 8 files changed, 366 insertions(+), 151 deletions(-) create mode 100644 resources/images/loading.gif diff --git a/resources/images/loading.gif b/resources/images/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..23ed2386e24170024eb4d39c0974c205cfbd0b82 GIT binary patch literal 1849 zcmb8wdr(tX9tZI2z31lM+(&YVNJFGHgrG@CNO*-PR&N3b0%d_Jv^m!C{h8HX}bj>(owg=R;JFj-L^B@Wp}jN7Iyp4PFtJsNB>Iy=$=8oHUmLu3TUh_@)%&{}w+I!Rw_`6y=BiXBbT}kynhpBk5tD zn^(POMdxQNW7umcPA~i~C;j7Ou<_1Q_j_}OxaBuxJ6+E6xe@$-+%h?elTOalmt)R| z7%^V`{-#*DWFN)>O5UiB145c&fwMFMC3y(D8?+<SSWn|Aphubw1TdN*r1LP5RMP3e)hFu})BDGYt z@VQQ`d5vAF+EyU`YH{OKR?bjrTog({g%dT&SRP&8^GHV@) z#@fJ`m0UiK_hH=OWcsq~J(Z|uEqy(=N6Wd!+cg3xa>TblfL}gshw*~Wyr}Qr(TIqX zw=dd9$*ZrM7jhIw^rY+7;0ejnPVJ9UK1r+8z^w$BB1&5#tNcT&_JGRxOkeZi4mz{H zv!le=q}LDX1Ljh>(ju`x7a4hFd7Y2aww7k5rV&i@PlGNUh@9gsk7p;HVy^!^XooxX z-gP(?^2VC4YSuu>?V&Hnt*R$Fi0+UhB9 zia6vsqVGQ(5fISi2fU^B0h}_@wJe!aQ3sM3d*1m-)IAoV;|(1%pOVf)92IqK*-kZcgxBM0=Hz_vSW^GDncE={4xT7Sb{ zQ^6IszV3POc94{De;vt<0*Ke2EmTUO+g^z&sGc^*jnQtBtogQ1wK{|#^46E}AfGT3 zLZwo{5E$`Xb7@8|Xx~y=EFd-r(y9{4PI+L>%0RDZP?h?iR57QTR{Us6C=$hpS4~L& zS~&5+cFUe{UfR(!)&}tl6ZbN7?bb{B884ULxN`&t%kghdrc_O|M#=^AuiUkZ8H!&_ z;Asffz~{635iSZe0)|0_#N$yE5p!6>PqieVmCC@Dm1LC17l&WnU_73A`p~(X|LRiz zdGaR#IP6I+R#du;eP2=kE*&9Kj(|v>E?}bdy zuU=eG@I}Pcsj)|;fF^m7)E10jNt|Y=SQQ|IXa~v@+Eg@Oi{qQ%K$INA_663|`CrY7 zrn2aa{1!El0c(o>;;mug2F$rd_XP>79rrhd3OZg|0^6So*Ui)#Qw(AzdEZFywP5_y z^qg{A(Db4W$?XR{E@KX7Ukj6YY-9?;=I|g8=Emz8+=pRpWi}L&*%i8a)~yUYQonX7 znyHx{rqpRD{YC~vY8B_gGI|XR*_OPts0!+6J7Bt?9*}gmez9J>nQC=(Uic(bv}c?t zXwtxU`pgSzKGSyO+aa;~-WCjnyd;V>tavA75x`C~EMow{l LO_Kj3TB% wantedFields = new ArrayList(); wantedFields.add(PDBDocField.MOLECULE_TYPE); diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 11fb943..9abf22f 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -11,12 +11,19 @@ import jalview.ws.uimodel.PDBSearchRequest; import jalview.ws.uimodel.PDBSearchResponse; import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary; +import java.awt.Component; +import java.awt.event.ItemEvent; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import javax.swing.JCheckBox; import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; @SuppressWarnings("serial") public class StructureChooser extends GStructureChooser @@ -28,105 +35,133 @@ public class StructureChooser extends GStructureChooser private SequenceI[] selectedSequences; + IProgressIndicator af; + + Collection discoveredStructuresSet = new HashSet(); + public StructureChooser(AlignmentPanel ap, final SequenceI sequence) { this.ap = ap; + this.af = ap.alignFrame; this.selectedSequence = sequence; - selectedSequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[] - { sequence } : ap.av.getSequenceSelection()); - fetchStructures(); - populateFilterOptions(); - updateCurrentView(); - } - - @Override - public void ok_ActionPerformed() - { - // TODO code to load selected structures to jmol or chimera + this.selectedSequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[] + { sequence } + : ap.av.getSequenceSelection()); + init(); } - protected void populateFilterOptions() + private void init() { - if (structuresWereFound) + Thread discPDBThread = new Thread(new Runnable() { - filterOptionsComboBox.addItem(new FilterOptions( - "- Filter Criteria -", "", - VIEWS_FILTER)); - filterOptionsComboBox.addItem(new FilterOptions("All", "all", - VIEWS_FILTER)); - filterOptionsComboBox.addItem(new FilterOptions("Best Coverage", - "coverage", - VIEWS_FILTER)); - filterOptionsComboBox.addItem(new FilterOptions("Best Resolution", - PDBDocField.RESOLUTION.getCode(), - VIEWS_FILTER)); - filterOptionsComboBox.addItem(new FilterOptions("Best Quality", - PDBDocField.OVERALL_QUALITY.getCode(), - VIEWS_FILTER)); - - // "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( - } - filterOptionsComboBox.addItem(new FilterOptions("Enter PDB Id", "-", - VIEWS_ENTER_ID)); - filterOptionsComboBox.addItem(new FilterOptions("From File", "-", - VIEWS_FROM_FILE)); + @Override + public void run() + { + long startTime = System.currentTimeMillis(); + af.setProgressBar( + MessageManager.getString("status.fetching_db_refs"), + startTime); + + fetchStructures(); + populateFilterOptions(); + af.setProgressBar(null, startTime); + mainFrame.setVisible(true); + updateCurrentView(); + } + }); + discPDBThread.start(); } private void fetchStructures() { long startTime = System.currentTimeMillis(); - // final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new - // SequenceI[] - // { sequence } - // : ap.av.getSequenceSelection()); - - int foundStructures = 0; List wantedFields = new ArrayList(); - wantedFields.add(PDBDocField.MOLECULE_TYPE); + // wantedFields.add(PDBDocField.MOLECULE_TYPE); wantedFields.add(PDBDocField.PDB_ID); - wantedFields.add(PDBDocField.GENUS); - wantedFields.add(PDBDocField.GENE_NAME); + // wantedFields.add(PDBDocField.GENUS); + // wantedFields.add(PDBDocField.GENE_NAME); wantedFields.add(PDBDocField.TITLE); PDBSearchRequest request = new PDBSearchRequest(); request.setAllowEmptySeq(false); request.setResponseSize(500); - request.setSearchTarget("(text:"); + request.setFieldToSearchBy("(text:"); request.setWantedFields(wantedFields); - - Collection searchSummaries = new HashSet(); + for (SequenceI seq : selectedSequences) { request.setSearchTerm(buildQuery(seq) + ")"); + request.setAssociatedSequence(seq.getName()); PDBRestClient pdbRestCleint = new PDBRestClient(); - PDBSearchResponse resultList = pdbRestCleint - .executeRequest(request); + PDBSearchResponse resultList = pdbRestCleint.executeRequest(request); if (resultList.getSearchSummary() != null && !resultList.getSearchSummary().isEmpty()) { - searchSummaries.addAll(resultList.getSearchSummary()); + discoveredStructuresSet.addAll(resultList.getSearchSummary()); } } - foundStructures = searchSummaries.size(); - if (searchSummaries != null) + int noOfStructuresFound = 0; + if (discoveredStructuresSet != null) { jListFoundStructures.setModel(PDBSearchResponse - .getListModel(searchSummaries)); + .getListModel(discoveredStructuresSet)); + summaryTable.setModel(PDBSearchResponse.getTableModel(request, + discoveredStructuresSet)); + // resizeColumnWidth(summaryTable); structuresWereFound = true; + noOfStructuresFound = discoveredStructuresSet.size(); } String totalTime = (System.currentTimeMillis() - startTime) + " milli secs"; - mainFrame.setTitle("Structure Chooser - " + foundStructures + mainFrame.setTitle("Structure Chooser - " + noOfStructuresFound + " Found (" + totalTime + ")"); } + public void resizeColumnWidth(JTable table) + { + // table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + final TableColumnModel columnModel = table.getColumnModel(); + for (int column = 0; column < table.getColumnCount(); column++) + { + int width = 50; // Min width + for (int row = 0; row < table.getRowCount(); row++) + { + TableCellRenderer renderer = table.getCellRenderer(row, column); + Component comp = table.prepareRenderer(renderer, row, column); + width = Math.max(comp.getPreferredSize().width, width); + } + columnModel.getColumn(column).setPreferredWidth(width); + } + } + + protected void populateFilterOptions() + { + if (structuresWereFound) + { + filterOptionsComboBox.addItem(new FilterOptions("Best Quality", + PDBDocField.OVERALL_QUALITY.getCode(), VIEWS_FILTER)); + filterOptionsComboBox.addItem(new FilterOptions( + "Best UniProt Coverage", PDBDocField.UNIPROT_COVERAGE + .getCode(), VIEWS_FILTER)); + filterOptionsComboBox.addItem(new FilterOptions("Highest Resolution", + PDBDocField.RESOLUTION.getCode(), VIEWS_FILTER)); + filterOptionsComboBox.addItem(new FilterOptions( + "Highest Protein Chain", PDBDocField.PROTEIN_CHAIN_COUNT + .getCode(), VIEWS_FILTER)); + filterOptionsComboBox.addItem(new FilterOptions( + "Highest Bound Molecules", PDBDocField.BOUND_MOLECULE_COUNT + .getCode(), VIEWS_FILTER)); + filterOptionsComboBox.addItem(new FilterOptions( + "Highest Polymer Residues", PDBDocField.POLYMER_RESIDUE_COUNT + .getCode(), VIEWS_FILTER)); + } + filterOptionsComboBox.addItem(new FilterOptions("Enter PDB Id", "-", + VIEWS_ENTER_ID)); + filterOptionsComboBox.addItem(new FilterOptions("From File", "-", + VIEWS_FROM_FILE)); + } + private String buildQuery(SequenceI seq) { String query = seq.getName(); @@ -150,66 +185,131 @@ public class StructureChooser extends GStructureChooser return query; } - @Override - protected void stateChanged() - { - updateCurrentView(); - } - - int debounceCount = 0; protected void updateCurrentView() { FilterOptions currentOption = ((FilterOptions) filterOptionsComboBox .getSelectedItem()); switchableViewsLayout.show(switchableViewsPanel, currentOption.getView()); - ++debounceCount; - if (currentOption.getView() == VIEWS_FILTER && debounceCount % 2 == 0) + invertFilter.setEnabled(false); + if (currentOption.getView() == VIEWS_FILTER) { + invertFilter.setEnabled(true); filterResultSet(currentOption.getValue()); } } - public void filterResultSet(String filterTarget) + public void filterResultSet(final String fieldToFilterBy) { - System.out.println("-----------------> Filter by : " + filterTarget); + Thread filterThread = new Thread(new Runnable() + { + @Override + public void run() + { + try + { + loadingImageLabel.setVisible(true); + 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); + + PDBSearchRequest request = new PDBSearchRequest(); + request.setAllowEmptySeq(false); + request.setResponseSize(1); + request.setFieldToSearchBy("(text:"); + request.setFieldToSortBy(fieldToFilterBy, + !invertFilter.isSelected()); + + request.setWantedFields(wantedFields); + + Collection filteredResponse = new HashSet(); + for (SequenceI seq : selectedSequences) + { + request.setSearchTerm(buildQuery(seq) + ")"); + request.setAssociatedSequence(seq.getName()); + PDBRestClient pdbRestCleint = new PDBRestClient(); + PDBSearchResponse resultList = pdbRestCleint + .executeRequest(request); + if (resultList.getSearchSummary() != null + && !resultList.getSearchSummary().isEmpty()) + { + filteredResponse.addAll(resultList.getSearchSummary()); + } + } - 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); - PDBSearchRequest request = new PDBSearchRequest(); - request.setAllowEmptySeq(false); - request.setResponseSize(1); - request.setSearchTarget("(text:"); - request.setSortTarget(filterTarget, true); + if (filteredResponse != null) + { + // + // for (PDBResponseSummary s : filteredResponse) + // { + // System.out.println("-----------> " + s.getPdbId()); + // } + + int filterResponseCount = filteredResponse.size(); + List list = new ArrayList( + discoveredStructuresSet); + list.removeAll(filteredResponse); + + Collection newSet = new ArrayList(); + newSet.addAll(filteredResponse); + newSet.addAll(list); + + jListFoundStructures.setModel(PDBSearchResponse + .getListModel(newSet)); + summaryTable.setModel(PDBSearchResponse.getTableModel(request, + newSet)); + // resizeColumnWidth(summaryTable); + list = null; + newSet = null; + + int[] filterIndice = new int[filterResponseCount]; + ListSelectionModel model = summaryTable.getSelectionModel(); + model.clearSelection(); + // int x = 0; + for (int x = 0; x < filterResponseCount; x++) + { + filterIndice[x] = x; + model.addSelectionInterval(x, x); + } + jListFoundStructures.setSelectedIndices(filterIndice); + } - request.setWantedFields(wantedFields); + loadingImageLabel.setVisible(false); + } catch (Exception e) + { + e.printStackTrace(); + } + } + }); + filterThread.start(); - Collection searchSummaries = new HashSet(); - for (SequenceI seq : selectedSequences) + } + + @Override + protected void stateChanged(ItemEvent e) + { + if (e.getSource() instanceof JCheckBox) { - request.setSearchTerm(buildQuery(seq) + ")"); - PDBRestClient pdbRestCleint = new PDBRestClient(); - PDBSearchResponse resultList = pdbRestCleint.executeRequest(request); - if (resultList.getSearchSummary() != null - && !resultList.getSearchSummary().isEmpty()) + updateCurrentView(); + } + else + { + if (e.getStateChange() == ItemEvent.SELECTED) { - searchSummaries.addAll(resultList.getSearchSummary()); - + updateCurrentView(); } } - for (PDBResponseSummary summary : searchSummaries) - { - jListFoundStructures.setSelectedValue(summary, true); - // jListFoundStructures. - break; - } - System.out.println("Found item count : " + searchSummaries.size()); + } + + @Override + public void ok_ActionPerformed() + { + // TODO code to load selected structures to jmol or chimera } public void pdbFromFile_actionPerformed() @@ -237,7 +337,6 @@ public class StructureChooser extends GStructureChooser } - // rpdbview.addActionListener(new ActionListener() // { // @@ -263,16 +362,4 @@ public class StructureChooser extends GStructureChooser } } - // public static void main(String[] args) - // { - // SwingUtilities.invokeLater(new Runnable() - // { - // public void run() - // { - // new StructureChooser(null, null); - // } - // }); - // } - - } diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index 9569006..7224b78 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -9,10 +9,12 @@ import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -22,6 +24,7 @@ import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.ListSelectionModel; @@ -39,7 +42,7 @@ public abstract class GStructureChooser extends JPanel implements protected AlignmentPanel ap; - protected JLabel resultLabel = new JLabel("View : "); + protected JLabel resultLabel = new JLabel("Select : "); protected JButton ok = new JButton(); @@ -70,6 +73,12 @@ public abstract class GStructureChooser extends JPanel implements protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again"); + protected JCheckBox invertFilter = new JCheckBox("Invert"); + + protected ImageIcon loadingImage = new ImageIcon(getClass().getResource( + "/images/loading.gif")); + + protected JLabel loadingImageLabel = new JLabel(loadingImage); protected static final String VIEWS_FILTER = "VIEWS_FILTER"; @@ -79,14 +88,19 @@ public abstract class GStructureChooser extends JPanel implements protected JList jListFoundStructures = new JList(); + // protected JScrollPane foundStructuresScroller = new JScrollPane( + // jListFoundStructures); + + protected JTable summaryTable = new JTable(); protected JScrollPane foundStructuresScroller = new JScrollPane( - jListFoundStructures); + summaryTable); public GStructureChooser() { try { jbInit(); + mainFrame.setVisible(false); mainFrame.invalidate(); mainFrame.pack(); } catch (Exception e) @@ -97,9 +111,8 @@ public abstract class GStructureChooser extends JPanel implements private void jbInit() throws Exception { - ok.setFont(new java.awt.Font("Verdana", 0, 12)); - ok.setText(MessageManager.getString("action.ok")); + ok.setText(MessageManager.getString("action.view")); ok.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) @@ -135,14 +148,25 @@ public abstract class GStructureChooser extends JPanel implements foundStructuresScroller .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + filterOptionsComboBox.setFont(new java.awt.Font("Verdana", 0, 12)); + invertFilter.setFont(new java.awt.Font("Verdana", 0, 12)); + rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12)); + + filterOptionsComboBox.addItemListener(this); + invertFilter.addItemListener(this); + actionPanel.add(rememberSettings); actionPanel.add(ok); actionPanel.add(cancel); - filterOptionsComboBox.addItemListener(this); filterPanel.add(resultLabel); filterPanel.add(filterOptionsComboBox); + loadingImageLabel.setVisible(false); + + filterPanel.add(loadingImageLabel); + + filterPanel.add(invertFilter); idInputPanel.setLayout(new FlowLayout()); idInputPanel.add(search); @@ -167,10 +191,21 @@ public abstract class GStructureChooser extends JPanel implements Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); } + + private ImageIcon scaleImageIcone(ImageIcon imageIcon, int width, int height) + { + Image image = imageIcon.getImage(); // transform it + + Image newimg = image.getScaledInstance(width, height, + java.awt.Image.SCALE_SMOOTH); // scale it the smooth way + + return new ImageIcon(newimg); + } + @Override public void itemStateChanged(ItemEvent e) { - stateChanged(); + stateChanged(e); } public class FilterOptions @@ -188,6 +223,13 @@ public abstract class GStructureChooser extends JPanel implements this.view = view; } + // public FilterOptions(PDBDocField field, String view) + // { + // this.name = "Best " + field.getName(); + // this.value = field.getCode(); + // this.view = view; + // } + public String getName() { return name; @@ -224,7 +266,7 @@ public abstract class GStructureChooser extends JPanel implements } } - protected abstract void stateChanged(); + protected abstract void stateChanged(ItemEvent e); protected abstract void updateCurrentView(); diff --git a/src/jalview/util/MessageManager.java b/src/jalview/util/MessageManager.java index cd885f0..a30fc96 100644 --- a/src/jalview/util/MessageManager.java +++ b/src/jalview/util/MessageManager.java @@ -92,6 +92,11 @@ public class MessageManager public static String formatMessage(String key, Object... params) { + return MessageFormat.format(rb.getString(key), params); + } + + public static String formatMessage(String key, String[] params) + { return MessageFormat.format(rb.getString(key), (Object[]) params); } diff --git a/src/jalview/ws/dbsources/PDBRestClient.java b/src/jalview/ws/dbsources/PDBRestClient.java index 8bc9ebf..e00d9ac 100644 --- a/src/jalview/ws/dbsources/PDBRestClient.java +++ b/src/jalview/ws/dbsources/PDBRestClient.java @@ -31,7 +31,7 @@ public class PDBRestClient PDBSearchRequest request = new PDBSearchRequest(); request.setAllowEmptySeq(false); request.setResponseSize(100); - request.setSearchTarget("pfam_name"); + request.setFieldToSearchBy("pfam_name"); request.setSearchTerm("Lipoc*"); List wantedFields = new ArrayList(); wantedFields.add(PDBDocField.MOLECULE_TYPE); @@ -50,7 +50,7 @@ public class PDBRestClient Boolean.TRUE); Client client = Client.create(clientConfig); - String query = request.getSearchTarget() + String query = request.getFieldToSearchBy() + request.getSearchTerm() + ((request.isAllowEmptySeq()) ? "" : " AND molecule_sequence:['' TO *]"); @@ -60,10 +60,10 @@ public class PDBRestClient String responseSize = (request.getResponseSize() == 0) ? "200" : String .valueOf(request.getResponseSize()); - String sortParam = (request.getSortTarget() == null || request - .getSortTarget().trim().isEmpty()) ? "" + String sortParam = (request.getFieldToSortBy() == null || request + .getFieldToSortBy().trim().isEmpty()) ? "" : (request - .getSortTarget() + (request.isAscending() ? " asc" : " desc")); + .getFieldToSortBy() + (request.isAscending() ? " asc" : " desc")); WebResource webResource = client.resource(pdbSearchEndpoint) .queryParam("wt", "json").queryParam("fl", wantedFields) @@ -87,7 +87,8 @@ public class PDBRestClient } } // System.out.println("--------------> " + responseString); - return parseResponse(responseString, request.getWantedFields()); + return parseResponse(responseString, request.getWantedFields(), + request.getAssociatedSequence()); } private String parseException(String jsonResponse) @@ -112,7 +113,7 @@ public class PDBRestClient @SuppressWarnings("unchecked") private PDBSearchResponse parseResponse(String jsonResponse, - List wantedFields) + List wantedFields, String associatedSequence) { PDBSearchResponse searchResult = new PDBSearchResponse(); List result = null; @@ -137,7 +138,8 @@ public class PDBRestClient JSONObject doc = docIter.next(); // if (doc.get("molecule_sequence") != null) // { - result.add(searchResult.new PDBResponseSummary(doc, wantedFields)); + result.add(searchResult.new PDBResponseSummary(doc, wantedFields, + associatedSequence)); // } } searchResult.setItemsFound(numFound); diff --git a/src/jalview/ws/uimodel/PDBSearchRequest.java b/src/jalview/ws/uimodel/PDBSearchRequest.java index 7e97b3f..3c5f45a 100644 --- a/src/jalview/ws/uimodel/PDBSearchRequest.java +++ b/src/jalview/ws/uimodel/PDBSearchRequest.java @@ -8,11 +8,13 @@ import java.util.List; public class PDBSearchRequest { - private String searchTarget; + private String fieldToSearchBy; private String searchTerm; - private String sortTarget; + private String fieldToSortBy; + + private String associatedSequence; private boolean allowEmptySeq; @@ -22,14 +24,14 @@ public class PDBSearchRequest private List wantedFields = new ArrayList(); - public String getSearchTarget() + public String getFieldToSearchBy() { - return searchTarget; + return fieldToSearchBy; } - public void setSearchTarget(String searchTarget) + public void setFieldToSearchBy(String fieldToSearchBy) { - this.searchTarget = searchTarget; + this.fieldToSearchBy = fieldToSearchBy; } public String getSearchTerm() @@ -72,14 +74,14 @@ public class PDBSearchRequest this.wantedFields = wantedFields; } - public String getSortTarget() + public String getFieldToSortBy() { - return sortTarget; + return fieldToSortBy; } - public void setSortTarget(String sortTarget, boolean isAscending) + public void setFieldToSortBy(String fieldToSortBy, boolean isAscending) { - this.sortTarget = sortTarget; + this.fieldToSortBy = fieldToSortBy; this.isAscending = isAscending; } @@ -88,4 +90,16 @@ public class PDBSearchRequest return isAscending; } + public String getAssociatedSequence() + { + return associatedSequence; + } + + public void setAssociatedSequence(String associatedSequence) + { + this.associatedSequence = associatedSequence; + } + + + } diff --git a/src/jalview/ws/uimodel/PDBSearchResponse.java b/src/jalview/ws/uimodel/PDBSearchResponse.java index 9a6e1c6..7b172de 100644 --- a/src/jalview/ws/uimodel/PDBSearchResponse.java +++ b/src/jalview/ws/uimodel/PDBSearchResponse.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Objects; import javax.swing.DefaultListModel; +import javax.swing.table.DefaultTableModel; import org.json.simple.JSONObject; @@ -59,18 +60,57 @@ public class PDBSearchResponse return defaultListModel; } + public static DefaultTableModel getTableModel(PDBSearchRequest request, + Collection summariesList) + { + DefaultTableModel model = new DefaultTableModel(); + + if (request.getAssociatedSequence() != null) + { + model.addColumn("Sequence"); + } + for (PDBDocField field : request.getWantedFields()) + { + model.addColumn(field.getName()); + } + + for (PDBResponseSummary res : summariesList) + { + model.addRow(res.getSummaryColums()); + } + return model; + } + + + public class PDBResponseSummary { private String pdbId; - private String summary; + private String summaryRow; + + private String[] summaryColums; + + private String associatedSequence; private int width = 480; - public PDBResponseSummary(JSONObject doc, List diplayFields) + public PDBResponseSummary(JSONObject doc, + List diplayFields, String associatedSeq) { StringBuilder summaryBuilder = new StringBuilder(); + int colCounter = 0; + summaryColums = new String[(associatedSeq != null) ? diplayFields + .size() + 1 : diplayFields.size()]; + if (associatedSeq != null) + { + this.associatedSequence = (associatedSeq.length() > 18) ? associatedSeq + .substring(0, 18) : associatedSeq; + summaryColums[0] = associatedSequence; + colCounter = 1; + } + for (PDBDocField field : diplayFields) { if (field.equals(PDBDocField.MOLECULE_TYPE) @@ -102,21 +142,25 @@ public class PDBSearchResponse + getClass().getResource("/images/sugar.png") .toString() + "\">"); } + summaryColums[colCounter++] = moleculeType; } else 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(" | "); + summaryColums[colCounter++] = this.pdbId; } else if (doc.get(field.getCode()) != null) { summaryBuilder.append(field.getName()).append(": ") .append(doc.get(field.getCode())).append(" | "); + summaryColums[colCounter++] = doc.get(field.getCode()).toString(); } } int endIndex = summaryBuilder.lastIndexOf(" | "); String fSummary = summaryBuilder.toString().substring(0, endIndex); - this.summary = fSummary.trim(); + this.summaryRow = fSummary.trim(); summaryBuilder = null; } @@ -130,14 +174,24 @@ public class PDBSearchResponse this.pdbId = pdbId; } - public String getSummary() + public String getSummaryRow() + { + return summaryRow; + } + + public void setSummaryRow(String summary) { - return summary; + this.summaryRow = summary; } - public void setSummary(String summary) + public String[] getSummaryColums() { - this.summary = summary; + return summaryColums; + } + + public void setSummaryColums(String[] summaryColums) + { + this.summaryColums = summaryColums; } public String toString() @@ -145,7 +199,7 @@ public class PDBSearchResponse StringBuilder html = new StringBuilder(); html.append("
"); - html.append(summary); + html.append(summaryRow); html.append("
"); return html.toString(); } @@ -153,8 +207,24 @@ public class PDBSearchResponse @Override public int hashCode() { - return Objects.hash(this.pdbId, this.summary); + return Objects.hash(this.pdbId, this.summaryRow); + } + + @Override + public boolean equals(Object other) + { + if (!(other instanceof PDBResponseSummary)) + { + return false; + } + + PDBResponseSummary that = (PDBResponseSummary) other; + + // Custom equality check here. + return this.pdbId.equals(that.pdbId) + && this.summaryRow.equals(that.summaryRow); } + } } -- 1.7.10.2