From bc4b17d7c6b2e7df9262371e644abcdfb8ac3e91 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 25 Aug 2021 18:10:50 +0100 Subject: [PATCH] JAL-3829 proof in principle 3d-beacons sequence fetcher - still some TODOs ! --- resources/fts/tdbeacons_data_columns.txt | 35 ++--- .../service/threedbeacons/TDBeaconsFTSPanel.java | 160 +++++++++----------- .../threedbeacons/TDBeaconsFTSRestClient.java | 5 +- 3 files changed, 94 insertions(+), 106 deletions(-) diff --git a/resources/fts/tdbeacons_data_columns.txt b/resources/fts/tdbeacons_data_columns.txt index 4eb9b98..5cd9f0d 100644 --- a/resources/fts/tdbeacons_data_columns.txt +++ b/resources/fts/tdbeacons_data_columns.txt @@ -24,11 +24,12 @@ tdbeacons_data_columns _group.id _group.name _group.sort_order -g1;Miscellaneous;2 -g2;Name;1 -g3;Quality;3 +g1;ModelInfo;1 +g2;Quality;2 +g3;Miscellaneous;3 + # -_data_column.primary_key;model_identifier +_data_column.primary_key;model_url _data_column.default_response_page_size;100 # _data_column.name @@ -40,18 +41,18 @@ _data_column.max_col_width _data_column.preferred_col_width _data_column.is_shown_by_default _data_column.is_searchable -Model id;model_identifier;String;g2;80;150;85;true;false -Sequence;aligned_sequence;String;g1;80;150;85;false;false +Model id;model_identifier;String;g3;80;150;85;true;false +Sequence;aligned_sequence;String;g3;80;150;85;false;false Provider;provider;String;g1;80;150;85;true;false -Uniprot Id;id;String;g2;80;150;85;false;false -UniProt Accession;uniprot_accession;String;g2;50;400;95;false;true -Entry Name;entry_name;String;g2;100;150;105;true;false -Url;model_url;String;g1;100;150;105;false;false +Model Category;model_category;String;g1;80;150;85;true;false +Uniprot Id;id;String;g1;80;150;85;false;false +Uniprot Start;uniprot_start;Integer;g1;80;150;85;true;false +Uniprot End;uniprot_end;Integer;g1;80;150;85;true;false +Resolution;resolution;double;g2;80;150;85;true;false Qmean;qmean_avg_local_score;double;g2;100;150;105;true;false -Uniprot Start;uniprot_start;Integer;g3;3;8;3;true;false -Uniprot End;uniprot_end;Integer;g3;3;8;3;true;false -Resolution;resolution;double;g3;3;8;3;true;false -Coverage;coverage;double;g3;3;8;3;true;false -Sequence Identity;sequence_identity;Float;g3;3;8;3;false;false -Model Category;model_category;String;g3;3;8;3;true;false -Created Date;created;string;g3;3;8;3;true;false \ No newline at end of file +Coverage;coverage;double;g2;80;150;85;true;false +Sequence Identity;sequence_identity;Float;g2;80;150;85;false;false +Created Date;created;string;g3;80;150;85;true;false +UniProt Accession;uniprot_accession;String;g1;50;400;95;false;true +Entry Name;entry_name;String;g3;100;150;105;true;false +Url;model_url;String;g3;100;150;105;true;false diff --git a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSPanel.java b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSPanel.java index c368e7b..7fa6aa5 100644 --- a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSPanel.java +++ b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSPanel.java @@ -10,9 +10,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import javax.swing.SwingUtilities; + import org.json.JSONArray; import org.json.JSONObject; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; import jalview.fts.core.FTSRestRequest; @@ -20,11 +24,16 @@ import jalview.fts.core.FTSRestResponse; import jalview.fts.core.GFTSPanel; import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.gui.SequenceFetcher; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; +import jalview.io.FileLoader; +import jalview.io.FormatAdapter; import jalview.util.MessageManager; @SuppressWarnings("serial") public class TDBeaconsFTSPanel extends GFTSPanel -{ +{ private static String defaultFTSFrameTitle = MessageManager .getString("label.pdb_sequence_fetcher"); @@ -33,81 +42,19 @@ public class TDBeaconsFTSPanel extends GFTSPanel private static final String THREEDB_FTS_CACHE_KEY = "CACHE.THREEDB_FTS"; private static final String THREEDB_AUTOSEARCH = "FTS.THREEDB.AUTOSEARCH"; - + private static HttpURLConnection connection; - + public TDBeaconsFTSPanel(SequenceFetcher fetcher) { - super(fetcher); - pageLimit = TDBeaconsFTSRestClient.getInstance().getDefaultResponsePageSize(); + // no ID retrieval option for TD Beacons just now + super(null); + pageLimit = TDBeaconsFTSRestClient.getInstance() + .getDefaultResponsePageSize(); this.seqFetcher = fetcher; this.progressIndicator = (fetcher == null) ? null : fetcher.getProgressIndicator(); } - -// public int TDBeaconsFTSPanel2(String result) -// { -// int seqlength = executeParse(result); -// return seqlength; -// } - - public static int executeParse(String query) { - BufferedReader reader; - String line; - StringBuffer responseContent = new StringBuffer(); - try { - URL url = new URL("https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons-hub-api/uniprot/summary/" + query + ".json"); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setConnectTimeout(5000); // <=>5seconds - connection.setReadTimeout(5000); - // Status check up, 200 = connection succesful - int status = connection.getResponseCode(); - // System.out.println(status); - - if (status > 299) { - reader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); - while ((line = reader.readLine()) != null) { - responseContent.append(line); - } - reader.close(); - } else { - reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - while ((line = reader.readLine()) != null) { - responseContent.append(line); - } - reader.close(); - } - //System.out.println(responseContent.toString()); - int seq = parse(responseContent.toString()); - return seq; - - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - connection.disconnect(); - } - return (Integer) null; - - } - - public static int parse(String jsonString) { - JSONObject entry = new JSONObject(jsonString); - System.out.println(entry); - int length = entry.getJSONObject("uniprot_entry").getInt("sequence_length"); - String ac = entry.getJSONObject("uniprot_entry").getString("ac"); - - JSONArray structures = entry.getJSONArray("structures"); - for (int i=0 ; i < structures.length() ; i++) { - String id = structures.getJSONObject(i).getString("model_identifier"); - //System.out.println("identifier num " + i + " : " + id); - } - System.out.println("length : " + length + "; access name : " + ac); - return length; - -} @Override public void searchAction(boolean isFreshSearch) @@ -138,11 +85,12 @@ public class TDBeaconsFTSPanel extends GFTSPanel FTSRestRequest request = new FTSRestRequest(); request.setAllowEmptySeq(allowEmptySequence); request.setResponseSize(100); - request.setFieldToSearchBy("(" + searchTarget + ":"); - request.setSearchTerm(searchTerm + ")"); + // expect it to be uniprot accesssion + request.setSearchTerm(searchTerm + ".json"); request.setOffSet(offSet); request.setWantedFields(wantedFields); - FTSRestClientI tdbRestClient = TDBeaconsFTSRestClient.getInstance(); + FTSRestClientI tdbRestClient = TDBeaconsFTSRestClient + .getInstance(); FTSRestResponse resultList; try { @@ -175,7 +123,8 @@ public class TDBeaconsFTSPanel extends GFTSPanel if (isPaginationEnabled() && resultSetCount > 0) { - String f1 = totalNumberformatter.format(Integer.valueOf(offSet + 1)); + String f1 = totalNumberformatter + .format(Integer.valueOf(offSet + 1)); String f2 = totalNumberformatter .format(Integer.valueOf(offSet + resultSetCount)); String f3 = totalNumberformatter @@ -199,14 +148,14 @@ public class TDBeaconsFTSPanel extends GFTSPanel } }.start(); } - + @Override public void okAction() { // mainFrame.dispose(); disableActionButtons(); StringBuilder selectedIds = new StringBuilder(); - HashSet selectedIdsSet = new HashSet<>(); + final HashSet selectedIdsSet = new HashSet<>(); int primaryKeyColIndex = 0; try { @@ -222,12 +171,12 @@ public class TDBeaconsFTSPanel extends GFTSPanel { String idStr = getResultTable() .getValueAt(summaryRow, primaryKeyColIndex).toString(); - selectedIdsSet.add(searchTerm); + selectedIdsSet.add(idStr); } for (String idStr : paginatorCart) { - selectedIdsSet.add(searchTerm); + selectedIdsSet.add(idStr); } for (String selectedId : selectedIdsSet) @@ -235,19 +184,57 @@ public class TDBeaconsFTSPanel extends GFTSPanel selectedIds.append(selectedId).append(";"); } - String ids = selectedIds.toString(); - seqFetcher.setQuery(ids); - Thread worker = new Thread(seqFetcher); - worker.start(); + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + AlignmentI allSeqs = null; + FormatAdapter fl = new jalview.io.FormatAdapter(); + for (String tdbURL : selectedIdsSet) + { + try + { + // retrieve the structure via its URL + AlignmentI tdbAl = fl.readFile(tdbURL, DataSourceType.URL, + FileFormat.MMCif); + + // TODO: pad structure according to its Uniprot Start so all line up w.r.t. the Uniprot reference sequence + // TODO: give the structure a sensible name (not the giant URL *:o) ) + if (tdbAl != null) + { + if (allSeqs != null) + { + allSeqs.append(tdbAl); + } + else + { + allSeqs = tdbAl; + } + } + } catch (Exception x) + { + Cache.log.warn( + "Couldn't retrieve 3d-beacons model for uniprot id" + + searchTerm + " : " + tdbURL, + x); + } + } + seqFetcher.parseResult(allSeqs, + "3D-Beacons models for " + searchTerm, FileFormat.MMCif, + null); + + } + }); delayAndEnableActionButtons(); } - + @Override public FTSRestClientI getFTSRestClient() { return TDBeaconsFTSRestClient.getInstance(); } - + @Override public String getFTSFrameTitle() { @@ -282,10 +269,11 @@ public class TDBeaconsFTSPanel extends GFTSPanel protected void showHelp() { System.out.println("No help implemented yet."); - + } - - public static String decodeSearchTerm(String enteredText) { + + public static String decodeSearchTerm(String enteredText) + { // no multiple query support yet return enteredText; } diff --git a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java index 7a556b5..e956461 100644 --- a/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java +++ b/src/jalview/fts/service/threedbeacons/TDBeaconsFTSRestClient.java @@ -47,8 +47,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient { try { - String query = tdbRestRequest.getFieldToSearchBy() - + tdbRestRequest.getSearchTerm(); + String query = tdbRestRequest.getSearchTerm(); Client client; Class clientResponseClass; if (Platform.isJS()) @@ -190,7 +189,7 @@ private static FTSData getFTSData(Map tdbJsonStructure, for (FTSDataColumnI field : displayFields) { String fieldData = (tdbJsonStructure.get(field.getCode()) == null) ? " " : tdbJsonStructure.get(field.getCode()).toString(); - System.out.println("Field : " + field + " Data : " + fieldData); + // System.out.println("Field : " + field + " Data : " + fieldData); if (field.isPrimaryKeyColumn()) { primaryKey = fieldData; -- 1.7.10.2