1 package jalview.gui.structurechooser;
3 import java.util.Collection;
5 import java.util.Objects;
6 import java.util.Vector;
8 import javax.swing.JTable;
9 import javax.swing.table.TableModel;
11 import jalview.datamodel.DBRefEntry;
12 import jalview.datamodel.PDBEntry;
13 import jalview.datamodel.SequenceI;
14 import jalview.fts.api.FTSData;
15 import jalview.fts.api.FTSDataColumnI;
16 import jalview.fts.api.FTSRestClientI;
17 import jalview.fts.core.FTSDataColumnPreferences;
18 import jalview.fts.core.FTSRestRequest;
19 import jalview.fts.core.FTSRestResponse;
20 import jalview.jbgui.FilterOption;
23 * logic for querying sources of structural data for structures of sequences
29 public abstract class StructureChooserQuerySource
31 protected FTSRestRequest lastPdbRequest;
33 protected FTSRestClientI pdbRestClient;
35 protected FTSDataColumnPreferences docFieldPrefs;
38 * max length of a GET URL (probably :( )
40 protected static int MAX_QLENGTH = 7820;
42 public StructureChooserQuerySource()
46 public static StructureChooserQuerySource getPDBfts()
48 return new PDBStructureChooserQuerySource();
51 public static StructureChooserQuerySource getTDBfts()
53 return new ThreeDBStructureChooserQuerySource();
56 public FTSDataColumnPreferences getDocFieldPrefs()
61 public void setDocFieldPrefs(FTSDataColumnPreferences docFieldPrefs)
63 this.docFieldPrefs = docFieldPrefs;
66 public FTSDataColumnPreferences getInitialFieldPreferences()
73 * Builds a query string for a given sequences using its DBRef entries
76 * the sequences to build a query for
77 * @return the built query string
80 public abstract String buildQuery(SequenceI seq);
84 * Remove the following special characters from input string +, -, &, !, (, ),
85 * {, }, [, ], ^, ", ~, *, ?, :, \
90 public static String sanitizeSeqName(String seqName)
92 Objects.requireNonNull(seqName);
93 return seqName.replaceAll("\\[\\d*\\]", "")
94 .replaceAll("[^\\dA-Za-z|_]", "").replaceAll("\\s+", "+");
98 * Ensures sequence ref names are not less than 3 characters and does not
99 * contain a database name
104 static boolean isValidSeqName(String seqName)
106 // System.out.println("seqName : " + seqName);
107 String ignoreList = "pdb,uniprot,swiss-prot";
108 if (seqName.length() < 3)
112 if (seqName.contains(":"))
116 seqName = seqName.toLowerCase();
117 for (String ignoredEntry : ignoreList.split(","))
119 if (seqName.contains(ignoredEntry))
127 static String getDBRefId(DBRefEntry dbRef)
129 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
133 static PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
135 Objects.requireNonNull(id);
136 Objects.requireNonNull(pdbEntries);
137 PDBEntry foundEntry = null;
138 for (PDBEntry entry : pdbEntries)
140 if (entry.getId().equalsIgnoreCase(id))
149 * FTSRestClient specific query builder to recover associated structure data
150 * records for a sequence
153 * - seq to generate a query for
154 * @param wantedFields
155 * - fields to retrieve
156 * @param selectedFilterOpt
157 * - criterion for ranking results (e.g. resolution)
159 * - sort ascending or descending
163 public abstract FTSRestResponse fetchStructuresMetaData(SequenceI seq,
164 Collection<FTSDataColumnI> wantedFields,
165 FilterOption selectedFilterOpt, boolean b) throws Exception;
168 * FTSRestClient specific query builder to pick top ranked entry from a
169 * fetchStructuresMetaData query
172 * - seq to generate a query for
173 * @param wantedFields
174 * - fields to retrieve
175 * @param selectedFilterOpt
176 * - criterion for ranking results (e.g. resolution)
178 * - sort ascending or descending
182 public abstract FTSRestResponse selectFirstRankedQuery(SequenceI seq,
183 Collection<FTSDataColumnI> wantedFields, String fieldToFilterBy,
184 boolean b) throws Exception;
188 * @param discoveredStructuresSet
189 * @return the table model for the given result set for this engine
191 public TableModel getTableModel(
192 Collection<FTSData> discoveredStructuresSet)
194 return FTSRestResponse.getTableModel(lastPdbRequest,
195 discoveredStructuresSet);
198 public abstract PDBEntry[] collectSelectedRows(JTable restable,
199 int[] selectedRows, List<SequenceI> selectedSeqsToView);
202 * @param VIEWS_FILTER
203 * - a String key that can be used by the caller to tag the returned filter
204 * options to distinguish them in a collection
205 * @return list of FilterOption - convention is that the last one in the list
206 * will be constructed with 'addSeparator==true'
208 public abstract List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER);