wantedFields = PDBDocFieldPreferences
.getSearchSummaryFields();
+ String searchTerm = decodeSearchTerm(txt_search.getText(),
+ searchTarget);
+
PDBRestRequest request = new PDBRestRequest();
request.setAllowEmptySeq(allowEmptySequence);
request.setResponseSize(100);
- request.setFieldToSearchBy(searchTarget + ":");
- request.setSearchTerm(txt_search.getText());
+ request.setFieldToSearchBy("(" + searchTarget + ":");
+ request.setSearchTerm(searchTerm + ")");
request.setWantedFields(wantedFields);
-
+ // System.out.println(">>>>>>>>>>>>>> " + request.getQuery());
PDBRestClient pdbRestCleint = new PDBRestClient();
PDBRestResponse resultList = pdbRestCleint.executeRequest(request);
if (resultList.getSearchSummary() != null)
}
}
+ public static String decodeSearchTerm(String enteredText,
+ String targetField)
+ {
+ String foundSearchTerms = enteredText;
+ StringBuilder foundSearchTermsBuilder = new StringBuilder();
+ if (enteredText.contains(";"))
+ {
+ String[] searchTerms = enteredText.split(";");
+ for (String searchTerm : searchTerms)
+ {
+ if (searchTerm.contains(":"))
+ {
+ foundSearchTermsBuilder.append(targetField).append(":")
+ .append(searchTerm.split(":")[0]).append(" OR ");
+ }
+ else
+ {
+ foundSearchTermsBuilder.append(targetField).append(":")
+ .append(searchTerm).append(" OR ");
+ }
+ }
+ int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
+ foundSearchTerms = foundSearchTermsBuilder.toString();
+ if (foundSearchTerms.contains(" OR "))
+ {
+ foundSearchTerms = foundSearchTerms.substring(
+ targetField.length() + 1, endIndex);
+ }
+ }
+ else if (enteredText.contains(":"))
+ {
+ foundSearchTerms = foundSearchTerms.split(":")[0];
+ }
+ return foundSearchTerms;
+ }
+
+
@Override
public void btn_ok_ActionPerformed()
{
{
String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol)
.toString();
- selectedIds.append(";").append(pdbIdStr);
+
+ String searchTerm = txt_search.getText();
+ selectedIds.append(getPDBIdwithSpecifiedChain(pdbIdStr, searchTerm))
+ .append(";");
}
- String ids = selectedIds.deleteCharAt(0).toString();
+ String ids = selectedIds.toString();
+ // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
seqFetcher.textArea.setText(ids);
Thread worker = new Thread(seqFetcher);
worker.start();
}
+ public static String getPDBIdwithSpecifiedChain(String pdbId,
+ String searchTerm)
+ {
+ String pdbIdWithChainCode = "";
+ if (searchTerm.contains(";"))
+ {
+ String[] foundTerms = searchTerm.split(";");
+ for (String foundTerm : foundTerms)
+ {
+ if (foundTerm.contains(pdbId))
+ {
+ pdbIdWithChainCode = foundTerm;
+ }
+ }
+ }
+ else if (searchTerm.contains(pdbId))
+ {
+ pdbIdWithChainCode = searchTerm;
+ }
+ else
+ {
+ pdbIdWithChainCode = pdbId;
+ }
+ return pdbIdWithChainCode;
+ }
+
/**
* Populates search target combo-box options
*/
package jalview.gui;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javax.swing.JInternalFrame;
}
@Test
+ public void testDecodeSearchTerm()
+ {
+ String expectedString = "1xyz OR text:2xyz OR text:3xyz";
+ String outcome = PDBSearchPanel.decodeSearchTerm("1xyz:A;2xyz;3xyz",
+ "text");
+ // System.out.println("1 >>>>>>>>>>> " + outcome);
+ assertEquals(expectedString, outcome);
+
+ expectedString = "1xyz";
+ outcome = PDBSearchPanel.decodeSearchTerm("1xyz", "text");
+ // System.out.println("2 >>>>>>>>>>> " + outcome);
+ assertEquals(expectedString, outcome);
+ }
+
+ @Test
+ public void testgetPDBIdwithSpecifiedChain()
+ {
+
+ String expectedString = "1xyz:A";
+ String outcome = PDBSearchPanel.getPDBIdwithSpecifiedChain("1xyz",
+ "2xyz;3xyz;1xyz:A");
+ System.out.println("1 >>>>>>>>>>> " + outcome);
+ assertEquals(expectedString, outcome);
+
+ expectedString = "2xyz";
+ outcome = PDBSearchPanel.getPDBIdwithSpecifiedChain("2xyz",
+ "1xyz:A;2xyz;3xyz");
+ System.out.println("2 >>>>>>>>>>> " + outcome);
+ assertEquals(expectedString, outcome);
+
+ expectedString = "2xyz:A";
+ outcome = PDBSearchPanel.getPDBIdwithSpecifiedChain("2xyz", "2xyz:A");
+ System.out.println("3 >>>>>>>>>>> " + outcome);
+ assertEquals(expectedString, outcome);
+ }
+
+ @Test
public void txt_search_ActionPerformedTest()
{
PDBSearchPanel searchPanel = new PDBSearchPanel(null);
assertTrue(!mainFrame.getTitle().equalsIgnoreCase(
"PDB Sequence Fetcher"));
}
+
}