JAL-1668 added filtering and sorting capabilites
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 6 Mar 2015 19:17:14 +0000 (19:17 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 6 Mar 2015 19:17:14 +0000 (19:17 +0000)
resources/images/loading.gif [new file with mode: 0644]
src/jalview/gui/PDBFetchPanel.java
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GStructureChooser.java
src/jalview/util/MessageManager.java
src/jalview/ws/dbsources/PDBRestClient.java
src/jalview/ws/uimodel/PDBSearchRequest.java
src/jalview/ws/uimodel/PDBSearchResponse.java

diff --git a/resources/images/loading.gif b/resources/images/loading.gif
new file mode 100644 (file)
index 0000000..23ed238
Binary files /dev/null and b/resources/images/loading.gif differ
index f576910..85231f7 100644 (file)
@@ -20,11 +20,6 @@ public class PDBFetchPanel extends GPDBFetchPanel
 {
   private SequenceFetcher seqFetcher;
 
-  public enum FieldType
-  {
-    INT, STRING, BOOLEAN;
-  }
-
   public PDBFetchPanel()
   {
   }
@@ -62,7 +57,7 @@ public class PDBFetchPanel extends GPDBFetchPanel
       PDBSearchRequest request = new PDBSearchRequest();
       request.setAllowEmptySeq(allowEmptySequence);
       request.setResponseSize(100);
-      request.setSearchTarget(searchTarget + ":");
+      request.setFieldToSearchBy(searchTarget + ":");
       request.setSearchTerm(search.getText());
       List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
       wantedFields.add(PDBDocField.MOLECULE_TYPE);
index 11fb943..9abf22f 100644 (file)
@@ -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<PDBResponseSummary> discoveredStructuresSet = new HashSet<PDBResponseSummary>();
+
   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<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
-    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<PDBResponseSummary> searchSummaries = new HashSet<PDBResponseSummary>();
+
     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<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
+        // 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<PDBResponseSummary> filteredResponse = new HashSet<PDBResponseSummary>();
+        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<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
-    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<PDBResponseSummary> list = new ArrayList<PDBResponseSummary>(
+                  discoveredStructuresSet);
+          list.removeAll(filteredResponse);
+
+          Collection<PDBResponseSummary> newSet = new ArrayList<PDBResponseSummary>();
+          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<PDBResponseSummary> searchSummaries = new HashSet<PDBResponseSummary>();
-    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);
-  // }
-  // });
-  // }
-
-
 }
index 9569006..7224b78 100644 (file)
@@ -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<PDBResponseSummary> jListFoundStructures = new JList<PDBResponseSummary>();
 
+  // 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();
 
index cd885f0..a30fc96 100644 (file)
@@ -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);
   }
 
index 8bc9ebf..e00d9ac 100644 (file)
@@ -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<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
     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<PDBDocField> wantedFields)
+          List<PDBDocField> wantedFields, String associatedSequence)
   {
     PDBSearchResponse searchResult = new PDBSearchResponse();
     List<PDBResponseSummary> 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);
index 7e97b3f..3c5f45a 100644 (file)
@@ -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<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
 
-  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;
+  }
+
+
+
 }
index 9a6e1c6..7b172de 100644 (file)
@@ -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<PDBResponseSummary> 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<PDBDocField> diplayFields)
+    public PDBResponseSummary(JSONObject doc,
+            List<PDBDocField> 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><div style=\"width:" + width
               + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
-      html.append(summary);
+      html.append(summaryRow);
       html.append("</div></html>");
       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);
     }
+
   }
 
 }