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.datamodel.DBRefEntry;
12 import jalview.datamodel.DBRefSource;
13 import jalview.datamodel.SequenceI;
14 import jalview.fts.api.FTSData;
15 import jalview.fts.api.FTSDataColumnI;
16 import jalview.fts.core.FTSRestRequest;
17 import jalview.util.DBRefUtils;
18 import jalview.util.HttpUtils;
19 import jalview.ws.dbsources.EBIAlfaFold;
21 public class AlphafoldRestClient
25 * turns a uniprot ID into a fake alphafold entry for the structure chooser -
26 * fakes PDB fields in response
29 * @return null or an FTS Record (if alphafold thinks it has a structure)
31 public static List<FTSData> getFTSData(// Map<String, Object> pdbJsonDoc,
32 FTSRestRequest request)
34 List<FTSData> records = new ArrayList<FTSData>();
35 String primaryKey = null;
37 Object[] summaryRowData;
39 SequenceI associatedSequence;
41 Collection<FTSDataColumnI> diplayFields = request.getWantedFields();
42 SequenceI associatedSeq = request.getAssociatedSequence();
44 for (DBRefEntry upref : DBRefUtils
45 .selectRefs(associatedSeq.getPrimaryDBRefs(), new String[]
46 { DBRefSource.UNIPROT }))
48 String alphaFoldId = "AF-" + upref.getAccessionId() + "-F1";
51 String urls = EBIAlfaFold.getAlphaFoldCifDownloadUrl(alphaFoldId);
52 URL url = new URL(urls);
53 if (!HttpUtils.checkUrlAvailable(url, 50))
57 } catch (Exception mfe)
59 jalview.bin.Cache.log.debug("Exception accessing urls", mfe);
63 summaryRowData = new Object[(associatedSeq != null)
64 ? diplayFields.size() + 1
65 : diplayFields.size()];
66 if (associatedSeq != null)
68 associatedSequence = associatedSeq;
69 summaryRowData[0] = associatedSequence;
73 for (FTSDataColumnI field : diplayFields)
75 String fieldData = "alphafold";// (pdbJsonDoc.get(field.getCode()) ==
77 // : pdbJsonDoc.get(field.getCode()).toString();
78 if (field.isPrimaryKeyColumn())
80 primaryKey = alphaFoldId;
81 summaryRowData[colCounter++] = alphaFoldId;
83 else if (fieldData == null || fieldData.isEmpty())
85 summaryRowData[colCounter++] = null;
91 summaryRowData[colCounter++] = (field.getDataType()
92 .getDataTypeClass() == Integer.class)
94 : (field.getDataType()
95 .getDataTypeClass() == Double.class)
97 : "AlphaFold clarity";
101 System.out.println("offending value:" + fieldData);
106 final String primaryKey1 = primaryKey;
108 final Object[] summaryRowData1 = summaryRowData;
109 records.add(new FTSData()
112 public Object[] getSummaryData()
114 return summaryRowData1;
118 public Object getPrimaryKey()
124 * Returns a string representation of this object;
127 public String toString()
129 StringBuilder summaryFieldValues = new StringBuilder();
130 for (Object summaryField : summaryRowData1)
132 summaryFieldValues.append(
133 summaryField == null ? " " : summaryField.toString())
136 return summaryFieldValues.toString();
140 * Returns hash code value for this object
143 public int hashCode()
145 return Objects.hash(primaryKey1, this.toString());
149 public boolean equals(Object that)
151 return this.toString().equals(that.toString());