1 package jalview.fts.service.alphafold;
3 import java.net.MalformedURLException;
5 import java.util.ArrayList;
6 import java.util.Collection;
9 import java.util.Objects;
11 import jalview.bin.Console;
12 import jalview.datamodel.DBRefEntry;
13 import jalview.datamodel.DBRefSource;
14 import jalview.datamodel.SequenceI;
15 import jalview.fts.api.FTSData;
16 import jalview.fts.api.FTSDataColumnI;
17 import jalview.fts.core.FTSRestRequest;
18 import jalview.util.DBRefUtils;
19 import jalview.util.HttpUtils;
20 import jalview.ws.dbsources.EBIAlfaFold;
22 public class AlphafoldRestClient
26 * turns a uniprot ID into a fake alphafold entry for the structure chooser -
27 * fakes PDB fields in response
30 * @return null or an FTS Record (if alphafold thinks it has a structure)
32 public static List<FTSData> getFTSData(// Map<String, Object> pdbJsonDoc,
33 FTSRestRequest request)
35 List<FTSData> records = new ArrayList<FTSData>();
36 String primaryKey = null;
38 Object[] summaryRowData;
40 SequenceI associatedSequence;
42 Collection<FTSDataColumnI> diplayFields = request.getWantedFields();
43 SequenceI associatedSeq = request.getAssociatedSequence();
45 for (DBRefEntry upref : DBRefUtils
46 .selectRefs(associatedSeq.getPrimaryDBRefs(), new String[]
47 { DBRefSource.UNIPROT }))
49 String alphaFoldId = "AF-" + upref.getAccessionId() + "-F1";
52 String urls = EBIAlfaFold.getAlphaFoldCifDownloadUrl(alphaFoldId);
53 URL url = new URL(urls);
54 if (!HttpUtils.checkUrlAvailable(url, 50))
58 } catch (Exception mfe)
60 Console.debug("Exception accessing urls", mfe);
64 summaryRowData = new Object[(associatedSeq != null)
65 ? diplayFields.size() + 1
66 : diplayFields.size()];
67 if (associatedSeq != null)
69 associatedSequence = associatedSeq;
70 summaryRowData[0] = associatedSequence;
74 for (FTSDataColumnI field : diplayFields)
76 String fieldData = "alphafold";// (pdbJsonDoc.get(field.getCode()) ==
78 // : pdbJsonDoc.get(field.getCode()).toString();
79 if (field.isPrimaryKeyColumn())
81 primaryKey = alphaFoldId;
82 summaryRowData[colCounter++] = alphaFoldId;
84 else if (fieldData == null || fieldData.isEmpty())
86 summaryRowData[colCounter++] = null;
92 summaryRowData[colCounter++] = (field.getDataType()
93 .getDataTypeClass() == Integer.class)
95 : (field.getDataType()
96 .getDataTypeClass() == Double.class)
98 : "AlphaFold clarity";
102 System.out.println("offending value:" + fieldData);
107 final String primaryKey1 = primaryKey;
109 final Object[] summaryRowData1 = summaryRowData;
110 records.add(new FTSData()
113 public Object[] getSummaryData()
115 return summaryRowData1;
119 public Object getPrimaryKey()
125 * Returns a string representation of this object;
128 public String toString()
130 StringBuilder summaryFieldValues = new StringBuilder();
131 for (Object summaryField : summaryRowData1)
133 summaryFieldValues.append(
134 summaryField == null ? " " : summaryField.toString())
137 return summaryFieldValues.toString();
141 * Returns hash code value for this object
144 public int hashCode()
146 return Objects.hash(primaryKey1, this.toString());
150 public boolean equals(Object that)
152 return this.toString().equals(that.toString());