2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.fts.service.alphafold;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Objects;
29 import jalview.bin.Console;
30 import jalview.datamodel.DBRefEntry;
31 import jalview.datamodel.DBRefSource;
32 import jalview.datamodel.SequenceI;
33 import jalview.fts.api.FTSData;
34 import jalview.fts.api.FTSDataColumnI;
35 import jalview.fts.core.FTSRestRequest;
36 import jalview.util.DBRefUtils;
37 import jalview.util.HttpUtils;
38 import jalview.ws.dbsources.EBIAlfaFold;
40 public class AlphafoldRestClient
44 * turns a uniprot ID into a fake alphafold entry for the structure chooser -
45 * fakes PDB fields in response
48 * @return null or an FTS Record (if alphafold thinks it has a structure)
50 public static List<FTSData> getFTSData(// Map<String, Object> pdbJsonDoc,
51 FTSRestRequest request)
53 List<FTSData> records = new ArrayList<FTSData>();
54 String primaryKey = null;
56 Object[] summaryRowData;
58 SequenceI associatedSequence;
60 Collection<FTSDataColumnI> diplayFields = request.getWantedFields();
61 SequenceI associatedSeq = request.getAssociatedSequence();
63 for (DBRefEntry upref : DBRefUtils
64 .selectRefs(associatedSeq.getPrimaryDBRefs(), new String[]
65 { DBRefSource.UNIPROT }))
67 String alphaFoldId = "AF-" + upref.getAccessionId() + "-F1";
70 String urls = EBIAlfaFold.getAlphaFoldCifDownloadUrl(alphaFoldId,
72 URL url = new URL(urls);
73 if (!HttpUtils.checkUrlAvailable(url, 50))
77 } catch (Exception mfe)
79 Console.debug("Exception accessing urls", mfe);
83 summaryRowData = new Object[(associatedSeq != null)
84 ? diplayFields.size() + 1
85 : diplayFields.size()];
86 if (associatedSeq != null)
88 associatedSequence = associatedSeq;
89 summaryRowData[0] = associatedSequence;
93 for (FTSDataColumnI field : diplayFields)
95 String fieldData = "alphafold";// (pdbJsonDoc.get(field.getCode()) ==
97 // : pdbJsonDoc.get(field.getCode()).toString();
98 if (field.isPrimaryKeyColumn())
100 primaryKey = alphaFoldId;
101 summaryRowData[colCounter++] = alphaFoldId;
103 else if (fieldData == null || fieldData.isEmpty())
105 summaryRowData[colCounter++] = null;
111 summaryRowData[colCounter++] = (field.getDataType()
112 .getDataTypeClass() == Integer.class)
114 : (field.getDataType()
115 .getDataTypeClass() == Double.class)
117 : "AlphaFold clarity";
118 } catch (Exception e)
121 jalview.bin.Console.outPrintln("offending value:" + fieldData);
126 final String primaryKey1 = primaryKey;
128 final Object[] summaryRowData1 = summaryRowData;
129 records.add(new FTSData()
132 public Object[] getSummaryData()
134 return summaryRowData1;
138 public Object getPrimaryKey()
144 * Returns a string representation of this object;
147 public String toString()
149 StringBuilder summaryFieldValues = new StringBuilder();
150 for (Object summaryField : summaryRowData1)
152 summaryFieldValues.append(
153 summaryField == null ? " " : summaryField.toString())
156 return summaryFieldValues.toString();
160 * Returns hash code value for this object
163 public int hashCode()
165 return Objects.hash(primaryKey1, this.toString());
169 public boolean equals(Object that)
171 return this.toString().equals(that.toString());