Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.fts.service.uniprot

File UniprotFTSPanel.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

22
83
11
1
248
204
26
0.31
7.55
11
2.36

Classes

Class Line # Actions
UniprotFTSPanel 37 83 26 116
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21   
22    package jalview.fts.service.uniprot;
23   
24    import jalview.fts.api.FTSDataColumnI;
25    import jalview.fts.api.FTSRestClientI;
26    import jalview.fts.core.FTSRestRequest;
27    import jalview.fts.core.FTSRestResponse;
28    import jalview.fts.core.GFTSPanel;
29    import jalview.gui.SequenceFetcher;
30    import jalview.util.MessageManager;
31   
32    import java.util.HashMap;
33    import java.util.HashSet;
34    import java.util.Map;
35   
36    @SuppressWarnings("serial")
 
37    public class UniprotFTSPanel extends GFTSPanel
38    {
39   
40    private static String defaultFTSFrameTitle = MessageManager
41    .getString("label.uniprot_sequence_fetcher");
42   
43    private static Map<String, Integer> tempUserPrefs = new HashMap<>();
44   
45    private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
46   
47    private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH";
48   
 
49  0 toggle public UniprotFTSPanel(SequenceFetcher fetcher)
50    {
51  0 super(fetcher);
52  0 pageLimit = UniProtFTSRestClient.getInstance()
53    .getDefaultResponsePageSize();
54  0 this.seqFetcher = fetcher;
55  0 this.progressIndicator = (fetcher == null) ? null
56    : fetcher.getProgressIndicator();
57    }
58   
 
59  0 toggle @Override
60    public void searchAction(boolean isFreshSearch)
61    {
62  0 mainFrame.requestFocusInWindow();
63  0 if (isFreshSearch)
64    {
65  0 offSet = 0;
66    }
67  0 new Thread()
68    {
 
69  0 toggle @Override
70    public void run()
71    {
72  0 reset();
73  0 String searchInput = getTypedText();
74  0 if (searchInput.length() > 0)
75    {
76  0 setSearchInProgress(true);
77  0 long startTime = System.currentTimeMillis();
78  0 searchInput = getTypedText();
79  0 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
80    .getSelectedItem()).getAltCode();
81  0 wantedFields = UniProtFTSRestClient.getInstance()
82    .getAllDefaultDisplayedFTSDataColumns();
83  0 String searchTerm = decodeSearchTerm(searchInput, searchTarget);
84   
85  0 FTSRestRequest request = new FTSRestRequest();
86  0 request.setFieldToSearchBy(searchTarget);
87  0 request.setSearchTerm(searchTerm);
88  0 request.setOffSet(offSet);
89  0 request.setWantedFields(wantedFields);
90  0 FTSRestClientI uniProtRestClient = UniProtFTSRestClient
91    .getInstance();
92  0 FTSRestResponse resultList;
93  0 try
94    {
95  0 resultList = uniProtRestClient.executeRequest(request);
96    } catch (Exception e)
97    {
98  0 setErrorMessage(e.getMessage());
99  0 checkForErrors();
100  0 setSearchInProgress(false);
101  0 return;
102    }
103   
104  0 if (resultList.getSearchSummary() != null
105    && resultList.getSearchSummary().size() > 0)
106    {
107  0 getResultTable().setModel(FTSRestResponse.getTableModel(request,
108    resultList.getSearchSummary()));
109  0 FTSRestResponse.configureTableColumn(getResultTable(),
110    wantedFields, tempUserPrefs);
111  0 getResultTable().setVisible(true);
112    }
113   
114  0 long endTime = System.currentTimeMillis();
115  0 totalResultSetCount = resultList.getNumberOfItemsFound();
116  0 resultSetCount = resultList.getSearchSummary() == null ? 0
117    : resultList.getSearchSummary().size();
118  0 String result = (resultSetCount > 0)
119    ? MessageManager.getString("label.results")
120    : MessageManager.getString("label.result");
121  0 if (isPaginationEnabled() && resultSetCount > 0)
122    {
123  0 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
124    + " "
125    + totalNumberformatter.format((Number) (offSet + 1))
126    + " to "
127    + totalNumberformatter
128    .format((Number) (offSet + resultSetCount))
129    + " of "
130    + totalNumberformatter
131    .format((Number) totalResultSetCount)
132    + " " + " (" + (endTime - startTime) + " milli secs)");
133    }
134    else
135    {
136  0 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
137    + resultSetCount + " " + result + " ("
138    + (endTime - startTime) + " milli secs)");
139    }
140  0 setSearchInProgress(false);
141  0 refreshPaginatorState();
142  0 updateSummaryTableSelections();
143    }
144  0 txt_search.updateCache();
145    }
146    }.start();
147   
148    }
149   
 
150  0 toggle public String decodeSearchTerm(String enteredText, String targetField)
151    {
152  0 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
153    : targetField.length() + 1;
154  0 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
155    : targetField + ":";
156  0 String foundSearchTerms = enteredText;
157  0 StringBuilder foundSearchTermsBuilder = new StringBuilder();
158  0 if (enteredText.contains(";"))
159    {
160  0 String[] searchTerms = enteredText.split(";");
161  0 for (String searchTerm : searchTerms)
162    {
163  0 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
164    .append(" OR ");
165    }
166  0 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
167  0 foundSearchTerms = foundSearchTermsBuilder.toString();
168  0 if (foundSearchTerms.contains(" OR "))
169    {
170  0 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
171    endIndex);
172    }
173    }
174  0 return foundSearchTerms;
175    }
176   
 
177  0 toggle @Override
178    public boolean isPaginationEnabled()
179    {
180  0 return true;
181    }
182   
 
183  0 toggle @Override
184    public void okAction()
185    {
186  0 disableActionButtons();
187  0 StringBuilder selectedIds = new StringBuilder();
188  0 HashSet<String> selectedIdsSet = new HashSet<>();
189  0 int primaryKeyColIndex = 0;
190  0 try
191    {
192  0 primaryKeyColIndex = getFTSRestClient()
193    .getPrimaryKeyColumIndex(wantedFields, false);
194    } catch (Exception e)
195    {
196  0 e.printStackTrace();
197    }
198  0 int[] selectedRows = getResultTable().getSelectedRows();
199  0 for (int summaryRow : selectedRows)
200    {
201  0 String idStr = getResultTable()
202    .getValueAt(summaryRow, primaryKeyColIndex).toString();
203  0 selectedIdsSet.add(idStr);
204    }
205  0 selectedIdsSet.addAll(paginatorCart);
206  0 for (String selectedId : selectedIdsSet)
207    {
208  0 selectedIds.append(selectedId).append(";");
209    }
210   
211  0 String ids = selectedIds.toString();
212    // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
213  0 seqFetcher.getTextArea().setText(ids);
214  0 Thread worker = new Thread(seqFetcher);
215  0 worker.start();
216  0 delayAndEnableActionButtons();
217    }
218   
 
219  0 toggle @Override
220    public FTSRestClientI getFTSRestClient()
221    {
222  0 return UniProtFTSRestClient.getInstance();
223    }
224   
 
225  0 toggle @Override
226    public String getFTSFrameTitle()
227    {
228  0 return defaultFTSFrameTitle;
229    }
230   
 
231  0 toggle @Override
232    public Map<String, Integer> getTempUserPrefs()
233    {
234  0 return tempUserPrefs;
235    }
236   
 
237  0 toggle @Override
238    public String getCacheKey()
239    {
240  0 return UNIPROT_FTS_CACHE_KEY;
241    }
242   
 
243  0 toggle @Override
244    public String getAutosearchPreference()
245    {
246  0 return UNIPROT_AUTOSEARCH;
247    }
248    }