import jalview.jbgui.GPDBFetchPanel;
import jalview.ws.dbsources.PDBRestClient;
+import jalview.ws.dbsources.PDBRestClient.PDBDocField;
import jalview.ws.uimodel.PDBSearchRequest;
import jalview.ws.uimodel.PDBSearchResponse;
-import jalview.ws.uimodel.PDBSummaryListModel;
-import jalview.ws.uimodel.PDBSummaryListModel.PDBDocField;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import javax.swing.DefaultListModel;
public void searchStringAction()
{
boolean allowEmptySequence = false;
- jListSearchResult.setModel(new DefaultListModel<PDBSummaryListModel>());
+ jListSearchResult.setModel(new DefaultListModel<PDBResponseSummary>());
mainFrame.setTitle("PDB Sequence Fetcher");
if (search.getText().trim().length() > 0)
{
long startTime = System.currentTimeMillis();
PDBRestClient pdbRestCleint = new PDBRestClient();
- String searchTarget = ((PDBSearchOptionList) searchTargetOptions
+ String searchTarget = ((PDBDocField) searchTargetOptions
.getSelectedItem()).getCode();
PDBSearchRequest request = new PDBSearchRequest();
@Override
public void okActionPerformed()
{
- processPDBResponseData();
+ importSelectedPDBSequencesToAlignment();
}
mainFrame.dispose();
}
- private void processPDBResponseData()
+ private void importSelectedPDBSequencesToAlignment()
{
mainFrame.dispose();
StringBuilder selectedIds = new StringBuilder();
- for (PDBSummaryListModel dataSelected : jListSearchResult
+ for (PDBResponseSummary dataSelected : jListSearchResult
.getSelectedValuesList())
{
selectedIds.append(";").append(dataSelected.getPdbId());
worker.start();
}
- @SuppressWarnings("unchecked")
- public void populateSearchOptionCombo()
-
+ public void populateSearchOptionComboBox()
{
- List<PDBSearchOptionList> searchOptions = new ArrayList<PDBSearchOptionList>();
- searchOptions.add(new PDBSearchOptionList("PDB ID", "pdb_id",
- FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("PFAM Name", "pfam_name",
- FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("ALL", "text",
- FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("Molecule Type",
- "molecule_type", FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("Title", "title",
- FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("Molecule Name",
- "molecule_name", FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("Tax ID", "tax_id",
- FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("UniProt Accession",
- "uniprot_accession", FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("Gene Name", "gene_name",
- FieldType.STRING));
- searchOptions.add(new PDBSearchOptionList("Genus", "genus",
- FieldType.STRING));
-
- java.util.Collections.sort(searchOptions);
-
- for (PDBSearchOptionList pdbSO : searchOptions)
- {
- searchTargetOptions.addItem(pdbSO);
- }
- }
-
- @SuppressWarnings("rawtypes")
- public class PDBSearchOptionList implements Comparable
- {
- private String name;
-
- private String code;
-
- private boolean showInSummary;
-
- private boolean searchFilter;
-
- private FieldType type;
-
- public PDBSearchOptionList(String name, String code, FieldType type)
- {
- this.name = name;
- this.code = code;
- this.type = type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String getCode()
- {
- return code;
- }
-
- public void setCode(String code)
- {
- this.code = code;
- }
-
- public boolean isShowInSummary()
- {
- return showInSummary;
- }
-
- public void setShowInSummary(boolean showInSummary)
- {
- this.showInSummary = showInSummary;
- }
-
- public boolean isSearchFilter()
- {
- return searchFilter;
- }
-
- public void setSearchFilter(boolean searchFilter)
- {
- this.searchFilter = searchFilter;
- }
-
- public FieldType getFieldType()
- {
- return type;
- }
-
- public void setFieldType(FieldType type)
- {
- this.type = type;
- }
-
- public String toString()
- {
- return name;
- }
-
- public PDBSearchOptionList()
- {
-
- }
+ List<PDBDocField> searchableTargets = new ArrayList<PDBDocField>();
+ searchableTargets.add(PDBDocField.PDB_ID);
+ searchableTargets.add(PDBDocField.PFAM_ACCESSION);
+ searchableTargets.add(PDBDocField.MOLECULE_TYPE);
+ searchableTargets.add(PDBDocField.MOLECULE_NAME);
+ searchableTargets.add(PDBDocField.UNIPROT_ACCESSION);
+ searchableTargets.add(PDBDocField.GENE_NAME);
+ searchableTargets.add(PDBDocField.GENUS);
+ searchableTargets.add(PDBDocField.ALL);
+
+ Collections.sort(searchableTargets, new Comparator<PDBDocField>()
+ {
+ @Override
+ public int compare(PDBDocField o1, PDBDocField o2)
+ {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
- @Override
- public int compareTo(Object o)
+ for (PDBDocField searchTarget : searchableTargets)
{
- return this.name.compareTo(((PDBSearchOptionList) o).getName());
+ searchTargetOptions.addItem(searchTarget);
}
-
}
+
}
import jalview.jbgui.GStructureChooser;
import jalview.util.MessageManager;
import jalview.ws.dbsources.PDBRestClient;
+import jalview.ws.dbsources.PDBRestClient.PDBDocField;
import jalview.ws.uimodel.PDBSearchRequest;
import jalview.ws.uimodel.PDBSearchResponse;
-import jalview.ws.uimodel.PDBSummaryListModel;
-import jalview.ws.uimodel.PDBSummaryListModel.PDBDocField;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
@SuppressWarnings("serial")
public class StructureChooser extends GStructureChooser
{
+ private boolean structuresWereFound = false;
- private SequenceI sequence;
+ private SequenceI selectedSequence;
+ private SequenceI[] selectedSequences;
public StructureChooser(AlignmentPanel ap, final SequenceI sequence)
{
this.ap = ap;
- this.sequence = sequence;
+ this.selectedSequence = sequence;
+ selectedSequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
+ { sequence } : ap.av.getSequenceSelection());
fetchStructures();
+ populateFilterOptions();
+ updateCurrentView();
}
@Override
public void ok_ActionPerformed()
{
- jListFoundStructures.setSelectedValue("op1x", true);
+ // TODO code to load selected structures to jmol or chimera
}
- public void pdbFromFile_actionPerformed()
- {
- jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
- chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle(MessageManager.formatMessage(
- "label.select_pdb_file_for", new String[]
- { sequence.getDisplayId(false) }));
- chooser.setToolTipText(MessageManager.formatMessage(
- "label.load_pdb_file_associate_with_sequence", new String[]
- { sequence.getDisplayId(false) }));
-
- int value = chooser.showOpenDialog(null);
-
- if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
- {
- String choice = chooser.getSelectedFile().getPath();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
- new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
- jalview.io.AppletFormatAdapter.FILE, sequence, true,
- Desktop.instance);
- }
-
- }
-
- public void discoverPDB_actionPerformed()
- {
-
- final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
- { sequence }
- : ap.av.getSequenceSelection());
- Thread discpdb = new Thread(new Runnable()
- {
- @Override
- public void run()
- {
-
- new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
- .fetchDBRefs(false);
- }
-
- });
- discpdb.start();
- }
-
- // rpdbview.addActionListener(new ActionListener()
- // {
- //
- // @Override
- // public void actionPerformed(ActionEvent e)
- // {
- // new StructureViewer(ap.getStructureSelectionManager())
- // .viewStructures(ap, pr, ap.av.collateForPDB(pr));
- // }
- // });
-
- public void enterPDB_actionPerformed()
+ protected void populateFilterOptions()
{
- String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
- MessageManager.getString("label.enter_pdb_id"),
- MessageManager.getString("label.enter_pdb_id"),
- JOptionPane.QUESTION_MESSAGE);
- if (id != null && id.length() > 0)
+ if (structuresWereFound)
{
- PDBEntry entry = new PDBEntry();
- entry.setId(id.toUpperCase());
- sequence.getDatasetSequence().addPDBId(entry);
+ 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(
}
- }
-
- public static void main(String[] args)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- new StructureChooser(null, null);
- }
- });
- }
-
- @SuppressWarnings("unchecked")
- protected void populateFilterOptions()
- {
- filterOptions.addItem(new FilterOptions("- Filter Criteria -", "",
- VIEWS_AUTO));
- filterOptions.addItem(new FilterOptions("All", "all", VIEWS_AUTO));
- filterOptions
- .addItem(new FilterOptions("Best Coverage", "", VIEWS_AUTO));
- filterOptions.addItem(new FilterOptions("Best Resolution", "",
- VIEWS_AUTO));
- filterOptions
- .addItem(new FilterOptions("Best Quality", "", VIEWS_AUTO));
- filterOptions.addItem(new FilterOptions("Enter PDB Id", "", VIEWS_ID));
- filterOptions.addItem(new FilterOptions("From File", "", VIEWS_FILE));
- }
-
- protected void updateCurrentView()
- {
- String currentView = ((FilterOptions) filterOptions.getSelectedItem())
- .getView();
- switchableViewsLayout.show(switchableViewsPanel, currentView);
+ filterOptionsComboBox.addItem(new FilterOptions("Enter PDB Id", "-",
+ VIEWS_ENTER_ID));
+ filterOptionsComboBox.addItem(new FilterOptions("From File", "-",
+ VIEWS_FROM_FILE));
}
private void fetchStructures()
{
long startTime = System.currentTimeMillis();
- final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
- { sequence }
- : ap.av.getSequenceSelection());
+ // final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new
+ // SequenceI[]
+ // { sequence }
+ // : ap.av.getSequenceSelection());
+
int foundStructures = 0;
- PDBSearchRequest request = new PDBSearchRequest();
- request.setAllowEmptySeq(false);
- request.setResponseSize(500);
- request.setSearchTarget("(text:");
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(500);
+ request.setSearchTarget("(text:");
request.setWantedFields(wantedFields);
- Collection<PDBSummaryListModel> searchSummaries = new HashSet<PDBSummaryListModel>();
- // searchSummaries.
- for (SequenceI seq : sequences)
+ Collection<PDBResponseSummary> searchSummaries = new HashSet<PDBResponseSummary>();
+ for (SequenceI seq : selectedSequences)
{
- // System.out.println("Selected : " + seq.getName());
request.setSearchTerm(buildQuery(seq) + ")");
-
PDBRestClient pdbRestCleint = new PDBRestClient();
-
PDBSearchResponse resultList = pdbRestCleint
.executeRequest(request);
if (resultList.getSearchSummary() != null
{
jListFoundStructures.setModel(PDBSearchResponse
.getListModel(searchSummaries));
+ structuresWereFound = true;
}
-
String totalTime = (System.currentTimeMillis() - startTime)
+ " milli secs";
mainFrame.setTitle("Structure Chooser - " + foundStructures
{
for (DBRefEntry dbRef : seq.getDBRef())
{
- System.out.println("dbref : " + dbRef.getAccessionId());
queryBuilder.append("text:").append(dbRef.getAccessionId())
.append(" OR ");
++count;
break;
}
}
- // int beginIndex = queryBuilder. firstIndexOf("text");
int endIndex = queryBuilder.lastIndexOf(" OR ");
query = queryBuilder.toString().substring(5, endIndex);
}
- System.out.println("------------> " + query);
return query;
}
- public class FilterOptions
+ @Override
+ protected void stateChanged()
{
- private String name;
-
- private String value;
-
- private String view;
+ updateCurrentView();
+ }
- public FilterOptions(String name, String value, String view)
+ 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)
{
- this.name = name;
- this.value = value;
- this.view = view;
+ filterResultSet(currentOption.getValue());
}
+ }
- public String getName()
- {
- return name;
- }
+ public void filterResultSet(String filterTarget)
+ {
+ System.out.println("-----------------> Filter by : " + filterTarget);
- public void setName(String name)
- {
- this.name = name;
- }
+ 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);
- public String getValue()
- {
- return value;
- }
+ PDBSearchRequest request = new PDBSearchRequest();
+ request.setAllowEmptySeq(false);
+ request.setResponseSize(1);
+ request.setSearchTarget("(text:");
+ request.setSortTarget(filterTarget, true);
- public void setValue(String value)
+ request.setWantedFields(wantedFields);
+
+ Collection<PDBResponseSummary> searchSummaries = new HashSet<PDBResponseSummary>();
+ for (SequenceI seq : selectedSequences)
{
- this.value = value;
+ request.setSearchTerm(buildQuery(seq) + ")");
+ PDBRestClient pdbRestCleint = new PDBRestClient();
+ PDBSearchResponse resultList = pdbRestCleint.executeRequest(request);
+ if (resultList.getSearchSummary() != null
+ && !resultList.getSearchSummary().isEmpty())
+ {
+ searchSummaries.addAll(resultList.getSearchSummary());
+
+ }
}
- public String getView()
+ for (PDBResponseSummary summary : searchSummaries)
{
- return view;
+ jListFoundStructures.setSelectedValue(summary, true);
+ // jListFoundStructures.
+ break;
}
+ System.out.println("Found item count : " + searchSummaries.size());
+ }
+
+ public void pdbFromFile_actionPerformed()
+ {
+ jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
+ chooser.setFileView(new jalview.io.JalviewFileView());
+ chooser.setDialogTitle(MessageManager.formatMessage(
+ "label.select_pdb_file_for", new String[]
+ { selectedSequence.getDisplayId(false) }));
+ chooser.setToolTipText(MessageManager.formatMessage(
+ "label.load_pdb_file_associate_with_sequence", new String[]
+ { selectedSequence.getDisplayId(false) }));
+
+ int value = chooser.showOpenDialog(null);
- public void setView(String view)
+ if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
{
- this.view = view;
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+ new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
+ jalview.io.AppletFormatAdapter.FILE, selectedSequence, true,
+ Desktop.instance);
}
- public String toString()
+ }
+
+
+ // rpdbview.addActionListener(new ActionListener()
+ // {
+ //
+ // @Override
+ // public void actionPerformed(ActionEvent e)
+ // {
+ // new StructureViewer(ap.getStructureSelectionManager())
+ // .viewStructures(ap, pr, ap.av.collateForPDB(pr));
+ // }
+ // });
+
+ public void enterPDB_actionPerformed()
+ {
+ String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
+ MessageManager.getString("label.enter_pdb_id"),
+ MessageManager.getString("label.enter_pdb_id"),
+ JOptionPane.QUESTION_MESSAGE);
+ if (id != null && id.length() > 0)
{
- return this.name;
+ PDBEntry entry = new PDBEntry();
+ entry.setId(id.toUpperCase());
+ selectedSequence.getDatasetSequence().addPDBId(entry);
}
}
+
+ // public static void main(String[] args)
+ // {
+ // SwingUtilities.invokeLater(new Runnable()
+ // {
+ // public void run()
+ // {
+ // new StructureChooser(null, null);
+ // }
+ // });
+ // }
+
+
}
package jalview.jbgui;
import jalview.gui.Desktop;
-import jalview.gui.PDBFetchPanel.PDBSearchOptionList;
import jalview.util.MessageManager;
-import jalview.ws.uimodel.PDBSummaryListModel;
+import jalview.ws.dbsources.PDBRestClient.PDBDocField;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
import java.awt.BorderLayout;
import java.awt.Dimension;
protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
- protected JComboBox<PDBSearchOptionList> searchTargetOptions = new JComboBox<PDBSearchOptionList>();
+ protected JComboBox<PDBDocField> searchTargetOptions = new JComboBox<PDBDocField>();
protected JButton ok = new JButton();
protected JTextField search = new JTextField(20);
- protected JList<PDBSummaryListModel> jListSearchResult = new JList<PDBSummaryListModel>();
+ protected JList<PDBResponseSummary> jListSearchResult = new JList<PDBResponseSummary>();
protected JScrollPane searchResultScroller = new JScrollPane(
jListSearchResult);
private BorderLayout mainLayout = new BorderLayout();
-
-
public GPDBFetchPanel()
{
try
}
});
- populateSearchOptionCombo();
+ populateSearchOptionComboBox();
search.setFont(new java.awt.Font("Verdana", 0, 12));
search.getDocument().addDocumentListener(new DocumentListener()
inputPanel.add(searchTargetOptions);
inputPanel.add(search);
-
this.setLayout(mainLayout);
this.add(inputPanel, java.awt.BorderLayout.NORTH);
this.add(resultPanel, java.awt.BorderLayout.CENTER);
public abstract void cancelActionPerformed();
- protected abstract void populateSearchOptionCombo();
+ protected abstract void populateSearchOptionComboBox();
}
import jalview.gui.AlignmentPanel;
import jalview.gui.Desktop;
import jalview.util.MessageManager;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
import java.awt.BorderLayout;
import java.awt.CardLayout;
- protected JComboBox filterOptions = new JComboBox();
+ protected JComboBox<FilterOptions> filterOptionsComboBox = new JComboBox<FilterOptions>();
protected AlignmentPanel ap;
protected JButton cancel = new JButton();
- protected JButton selectFile = new JButton();
+ protected JButton pdbFromFile = new JButton();
protected JTextField search = new JTextField(16);
protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again");
- protected static final String VIEWS_AUTO = "auto_view";
+ protected static final String VIEWS_FILTER = "VIEWS_FILTER";
- protected static final String VIEWS_FILE = "file_view";
+ protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
- protected static final String VIEWS_ID = "id_view";
+ protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
- protected JList jListFoundStructures = new JList();
+ protected JList<PDBResponseSummary> jListFoundStructures = new JList<PDBResponseSummary>();
protected JScrollPane foundStructuresScroller = new JScrollPane(
jListFoundStructures);
}
});
+ pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
+ pdbFromFile.setText(" Select PDB File ");
+ pdbFromFile.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ pdbFromFile_actionPerformed();
+ }
+ });
+
jListFoundStructures
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jListFoundStructures.setLayoutOrientation(JList.VERTICAL);
actionPanel.add(ok);
actionPanel.add(cancel);
- filterOptions.addItemListener(this);
+ filterOptionsComboBox.addItemListener(this);
filterPanel.add(resultLabel);
- filterPanel.add(filterOptions);
+ filterPanel.add(filterOptionsComboBox);
idInputPanel.setLayout(new FlowLayout());
idInputPanel.add(search);
- selectFile.setText(" Select File ");
fileChooserPanel.setLayout(new FlowLayout());
- fileChooserPanel.add(selectFile);
+ fileChooserPanel.add(pdbFromFile);
- switchableViewsPanel.add(fileChooserPanel, VIEWS_FILE);
- switchableViewsPanel.add(idInputPanel, VIEWS_ID);
- switchableViewsPanel.add(foundStructuresScroller, VIEWS_AUTO);
+ switchableViewsPanel.add(fileChooserPanel, VIEWS_FROM_FILE);
+ switchableViewsPanel.add(idInputPanel, VIEWS_ENTER_ID);
+ switchableViewsPanel.add(foundStructuresScroller, VIEWS_FILTER);
this.setLayout(mainLayout);
this.add(filterPanel, java.awt.BorderLayout.NORTH);
this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
this.add(actionPanel, java.awt.BorderLayout.SOUTH);
- populateFilterOptions();
- updateCurrentView();
+
mainFrame.setVisible(true);
mainFrame.setContentPane(this);
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
@Override
public void itemStateChanged(ItemEvent e)
{
- updateCurrentView();
+ stateChanged();
+ }
+
+ public class FilterOptions
+ {
+ private String name;
+
+ private String value;
+
+ private String view;
+
+ public FilterOptions(String name, String value, String view)
+ {
+ this.name = name;
+ this.value = value;
+ this.view = view;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+
+ public String getView()
+ {
+ return view;
+ }
+
+ public void setView(String view)
+ {
+ this.view = view;
+ }
+
+ public String toString()
+ {
+ return this.name;
+ }
}
+ protected abstract void stateChanged();
+
protected abstract void updateCurrentView();
protected abstract void ok_ActionPerformed();
protected abstract void populateFilterOptions();
+
+ protected abstract void pdbFromFile_actionPerformed();
}
import jalview.ws.uimodel.PDBSearchRequest;
import jalview.ws.uimodel.PDBSearchResponse;
-import jalview.ws.uimodel.PDBSummaryListModel;
-import jalview.ws.uimodel.PDBSummaryListModel.PDBDocField;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
import java.util.ArrayList;
import java.util.Iterator;
String responseSize = (request.getResponseSize() == 0) ? "200" : String
.valueOf(request.getResponseSize());
+ String sortParam = (request.getSortTarget() == null || request
+ .getSortTarget().trim().isEmpty()) ? ""
+ : (request
+ .getSortTarget() + (request.isAscending() ? " asc" : " desc"));
+
WebResource webResource = client.resource(pdbSearchEndpoint)
.queryParam("wt", "json").queryParam("fl", wantedFields)
.queryParam("rows", responseSize)
- .queryParam("q", query);
+ .queryParam("q", query)
+ .queryParam("sort", sortParam);
ClientResponse clientResponse = webResource.accept(
MediaType.APPLICATION_JSON).get(ClientResponse.class);
String responseString = clientResponse.getEntity(String.class);
if (clientResponse.getStatus() != 200)
{
+ if (clientResponse.getStatus() == 400)
+ {
+ throw new RuntimeException(parseException(responseString));
+ }
+ else
+ {
throw new RuntimeException("Failed : HTTP error code : "
+ clientResponse.getStatus());
+ }
}
// System.out.println("--------------> " + responseString);
return parseResponse(responseString, request.getWantedFields());
}
+ private String parseException(String jsonResponse)
+ {
+ String errorMessage = "RunTime error";
+ try
+ {
+ JSONParser jsonParser = new JSONParser();
+ JSONObject jsonObj = (JSONObject) jsonParser.parse(jsonResponse);
+ JSONObject errorResponse = (JSONObject) jsonObj.get("error");
+ errorMessage = errorResponse.get("msg").toString();
+
+ JSONObject responseHeader = (JSONObject) jsonObj
+ .get("responseHeader");
+ errorMessage += responseHeader.get("params").toString();
+ } catch (ParseException e)
+ {
+ e.printStackTrace();
+ }
+ return errorMessage;
+ }
+
+ @SuppressWarnings("unchecked")
private PDBSearchResponse parseResponse(String jsonResponse,
List<PDBDocField> wantedFields)
{
PDBSearchResponse searchResult = new PDBSearchResponse();
- List<PDBSummaryListModel> result = null;
+ List<PDBResponseSummary> result = null;
try
{
JSONParser jsonParser = new JSONParser();
.valueOf(pdbResponse.get("numFound").toString());
if (numFound > 0)
{
- result = new ArrayList<PDBSummaryListModel>();
+ result = new ArrayList<PDBResponseSummary>();
JSONArray docs = (JSONArray) pdbResponse.get("docs");
for (Iterator<JSONObject> docIter = docs.iterator(); docIter
.hasNext();)
JSONObject doc = docIter.next();
// if (doc.get("molecule_sequence") != null)
// {
- result.add(new PDBSummaryListModel(doc, wantedFields));
+ result.add(searchResult.new PDBResponseSummary(doc, wantedFields));
// }
}
searchResult.setItemsFound(numFound);
}
+ public enum PDBDocField
+ {
+ 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"), ALL("ALL", "text");
+
+ private String name;
+
+ private String code;
+
+ PDBDocField(String name, String code)
+ {
+ this.name = name;
+ this.code = code;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getCode()
+ {
+ return code;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+ }
}
package jalview.ws.uimodel;
-import jalview.ws.uimodel.PDBSummaryListModel.PDBDocField;
+
+import jalview.ws.dbsources.PDBRestClient.PDBDocField;
import java.util.ArrayList;
import java.util.List;
private String searchTerm;
+ private String sortTarget;
+
private boolean allowEmptySeq;
private int responseSize;
+ private boolean isAscending;
+
private List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
public String getSearchTarget()
{
this.wantedFields = wantedFields;
}
+
+ public String getSortTarget()
+ {
+ return sortTarget;
+ }
+
+ public void setSortTarget(String sortTarget, boolean isAscending)
+ {
+ this.sortTarget = sortTarget;
+ this.isAscending = isAscending;
+ }
+
+ public boolean isAscending()
+ {
+ return isAscending;
+ }
+
}
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;
+import org.json.simple.JSONObject;
+
public class PDBSearchResponse
{
private int itemsFound;
private String responseTime;
- private Collection<PDBSummaryListModel> searchSummary;
+ private Collection<PDBResponseSummary> searchSummary;
public int getItemsFound()
{
this.responseTime = responseTime;
}
- public Collection<PDBSummaryListModel> getSearchSummary()
+ public Collection<PDBResponseSummary> getSearchSummary()
{
return searchSummary;
}
- public void setSearchSummary(Collection<PDBSummaryListModel> searchSummary)
+ public void setSearchSummary(Collection<PDBResponseSummary> searchSummary)
{
this.searchSummary = searchSummary;
}
- public static DefaultListModel<PDBSummaryListModel> getListModel(
- Collection<PDBSummaryListModel> summariesList)
+ public static DefaultListModel<PDBResponseSummary> getListModel(
+ Collection<PDBResponseSummary> summariesList)
{
- DefaultListModel<PDBSummaryListModel> defaultListModel = new DefaultListModel<PDBSummaryListModel>();
- for (PDBSummaryListModel summaryList : summariesList)
+ DefaultListModel<PDBResponseSummary> defaultListModel = new DefaultListModel<PDBResponseSummary>();
+ for (PDBResponseSummary summaryList : summariesList)
{
defaultListModel.addElement(summaryList);
}
return defaultListModel;
}
+
+ public class PDBResponseSummary
+ {
+ private String pdbId;
+
+ private String summary;
+
+ private int width = 480;
+
+ public PDBResponseSummary(JSONObject doc, List<PDBDocField> diplayFields)
+ {
+ StringBuilder summaryBuilder = new StringBuilder();
+
+ 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("<img src=\""
+ + getClass().getResource("/images/protein.png")
+ .toString() + "\">");
+ }
+ if (moleculeType.equalsIgnoreCase("dna"))
+ {
+ summaryBuilder.append("<img src=\""
+ + getClass().getResource("/images/dna.png").toString()
+ + "\">");
+ }
+ if (moleculeType.equalsIgnoreCase("rna"))
+ {
+ summaryBuilder.append("<img src=\""
+ + getClass().getResource("/images/dna.png").toString()
+ + "\">");
+ }
+ if (moleculeType.equalsIgnoreCase("sugar"))
+ {
+ summaryBuilder.append("<img src=\""
+ + getClass().getResource("/images/sugar.png")
+ .toString() + "\">");
+ }
+ }
+ else if (field.equals(PDBDocField.PDB_ID)
+ && doc.get(PDBDocField.PDB_ID.getCode()) != null)
+ {
+ this.pdbId = doc.get(PDBDocField.PDB_ID.getCode()).toString();
+ }
+ else if (doc.get(field.getCode()) != null)
+ {
+ summaryBuilder.append(field.getName()).append(": ")
+ .append(doc.get(field.getCode())).append(" | ");
+ }
+ }
+ int endIndex = summaryBuilder.lastIndexOf(" | ");
+ String fSummary = summaryBuilder.toString().substring(0, endIndex);
+ this.summary = fSummary.trim();
+ summaryBuilder = null;
+ }
+
+ public String getPdbId()
+ {
+ return pdbId;
+ }
+
+ public void setPdbId(String pdbId)
+ {
+ this.pdbId = pdbId;
+ }
+
+ public String getSummary()
+ {
+ return summary;
+ }
+
+ public void setSummary(String summary)
+ {
+ this.summary = summary;
+ }
+
+ public String toString()
+ {
+ StringBuilder html = new StringBuilder();
+ html.append("<html><div style=\"width:" + width
+ + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
+ html.append(summary);
+ html.append("</div></html>");
+ return html.toString();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(this.pdbId, this.summary);
+ }
+ }
+
}
+++ /dev/null
-package jalview.ws.uimodel;
-
-import java.util.List;
-
-import javax.swing.DefaultListModel;
-
-import org.json.simple.JSONObject;
-
-
-@SuppressWarnings(
-{ "serial", "rawtypes" })
-public class PDBSummaryListModel extends DefaultListModel
-{
- private String pdbId;
-
- private String summary;
-
- private int width = 480;
-
-
- public PDBSummaryListModel(JSONObject doc, List<PDBDocField> diplayFields)
- {
- StringBuilder summaryBuilder = new StringBuilder();
-
- for (PDBDocField field : diplayFields)
- {
- if (field.equals(PDBDocField.MOLECULE_TYPE)
- && doc.get("molecule_type") != null)
- {
- String moleculeType = doc.get("molecule_type").toString();
- if (moleculeType.equalsIgnoreCase("protein"))
- {
- summaryBuilder.append("<img src=\""
- + getClass().getResource("/images/protein.png").toString()
- + "\">");
- }
- if (moleculeType.equalsIgnoreCase("dna"))
- {
- summaryBuilder.append("<img src=\""
- + getClass().getResource("/images/dna.png").toString()
- + "\">");
- }
- if (moleculeType.equalsIgnoreCase("rna"))
- {
- summaryBuilder.append("<img src=\""
- + getClass().getResource("/images/dna.png").toString()
- + "\">");
- }
- if (moleculeType.equalsIgnoreCase("sugar"))
- {
- summaryBuilder.append("<img src=\""
- + getClass().getResource("/images/sugar.png").toString()
- + "\">");
- }
- }else if (doc.get(field.getCode()) != null)
- {
- summaryBuilder.append(field.getName()).append(": ")
- .append(doc.get(field.getCode())).append(" | ");
- }
- }
- int endIndex = summaryBuilder.lastIndexOf(" | ");
- String fSummary = summaryBuilder.toString().substring(0, endIndex);
- this.summary = fSummary.trim();
-
- }
-
- public String getPdbId()
- {
- return pdbId;
- }
-
- public void setPdbId(String pdbId)
- {
- this.pdbId = pdbId;
- }
-
- public String getSummary()
- {
- return summary;
- }
-
- public void setSummary(String summary)
- {
- this.summary = summary;
- }
-
-
- public String toString()
- {
- StringBuilder html = new StringBuilder();
- html.append("<html><div style=\"width:" + width
- + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
- html.append(summary);
- html.append("</div></html>");
- return html.toString();
- }
-
-
- public enum PDBDocField
- {
- 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");
-
- private String name;
-
- private String code;
-
- PDBDocField(String name, String code)
- {
- this.name = name;
- this.code = code;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getCode()
- {
- return code;
- }
-
- public String toString()
- {
- return name;
- }
- }
-}