X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdbsources%2FEBIAlfaFold.java;h=672f0ac8ed25d5822c3653c29f3aad86eee30d68;hb=2ee5edd84da7c509efc15d241527fa62093b41c7;hp=e5f1243097f2dab35abbb80c30b9b9a3eb6f6b65;hpb=1128674a17df402a2219d278ab332c291cb93443;p=jalview.git diff --git a/src/jalview/ws/dbsources/EBIAlfaFold.java b/src/jalview/ws/dbsources/EBIAlfaFold.java index e5f1243..672f0ac 100644 --- a/src/jalview/ws/dbsources/EBIAlfaFold.java +++ b/src/jalview/ws/dbsources/EBIAlfaFold.java @@ -30,6 +30,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; import org.json.simple.parser.ParseException; import com.stevesoft.pat.Regex; @@ -290,14 +292,8 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy if (ssm != null) { String structFile = isStructId ? ssm.findFileForPDBId(id) : id; - Console.debug("##### AHA! structFile = " + structFile); - Console.debug("##### structFile " - + (ssm.isPDBFileRegistered(structFile) ? "IS " : "is NOT ") - + "registered."); StructureMapping[] smArray = ssm.getMapping(structFile); - Console.debug("##### AHA! smArray obtained with " + smArray.length - + " elements"); try { @@ -362,34 +358,25 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy } public static boolean importPaeJSONAsContactMatrixToSequence( + AlignmentI pdbAlignment, File paeFile, int index, String seqId) + throws FileNotFoundException, IOException, ParseException + { + return importPaeJSONAsContactMatrixToSequence(pdbAlignment, + new FileInputStream(paeFile), index, seqId); + } + + public static boolean importPaeJSONAsContactMatrixToSequence( AlignmentI pdbAlignment, InputStream pae_input, int index, String seqId) throws IOException, ParseException { SequenceI sequence = null; - /* debugging */ - SequenceI[] seqs = pdbAlignment.getSequencesArray(); - if (seqs == null) - Console.debug("******* sequences is null"); - else - { - for (int i = 0; i < seqs.length; i++) - { - SequenceI s = seqs[i]; - Console.debug("******* sequences[" + i + "]='" + s.getName() + "'"); - } - } - /* end debug */ if (seqId == null) { int seqToGet = index > 0 ? index : 0; sequence = pdbAlignment.getSequenceAt(seqToGet); - Console.debug("***** Got sequence at index " + seqToGet + ": " - + (sequence == null ? null : sequence.getName())); } if (sequence == null) { - Console.debug("***** Looking for sequence with id '" + seqId + "'"); - SequenceI[] sequences = pdbAlignment.findSequenceMatch(seqId); if (sequences == null || sequences.length < 1) { @@ -403,43 +390,67 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy } } - List pae_obj = (List) Platform.parseJSON(pae_input); - if (pae_obj == null) + JSONObject paeDict = parseJSONtoPAEContactMatrix(pae_input); + if (paeDict == null) { Console.debug("JSON file did not parse properly."); return false; } ContactMatrixI matrix = new PAEContactMatrix(sequence, - (Map) pae_obj.get(0)); + (Map) paeDict); AlignmentAnnotation cmannot = sequence.addContactList(matrix); pdbAlignment.addAnnotation(cmannot); + return true; } + public static JSONObject parseJSONtoPAEContactMatrix( + InputStream pae_input) throws IOException, ParseException + { + Object paeJson = Platform.parseJSON(pae_input); + JSONObject paeDict = null; + if (paeJson instanceof JSONObject) + { + paeDict = (JSONObject) paeJson; + } + else if (paeJson instanceof JSONArray) + { + JSONArray jsonArray = (JSONArray) paeJson; + if (jsonArray.size() > 0) + paeDict = (JSONObject) jsonArray.get(0); + } + + return paeDict; + } + public static boolean importPaeJSONAsContactMatrixToStructure( StructureMapping[] smArray, InputStream paeInput) throws IOException, ParseException { boolean someDone = false; - Console.debug("##### smArray.length=" + smArray.length); for (StructureMapping sm : smArray) { - Console.debug("##### sm[n]=" + sm.getPdbId()); boolean thisDone = importPaeJSONAsContactMatrixToStructure(sm, paeInput); - Console.debug("##### thisDone = " + thisDone); someDone |= thisDone; } return someDone; } public static boolean importPaeJSONAsContactMatrixToStructure( + StructureMapping sm, File paeFile) + throws FileNotFoundException, IOException, ParseException + { + return importPaeJSONAsContactMatrixToStructure(sm, + new FileInputStream(paeFile)); + } + + public static boolean importPaeJSONAsContactMatrixToStructure( StructureMapping sm, InputStream paeInput) throws IOException, ParseException { - - List pae_obj = (List) Platform.parseJSON(paeInput); + JSONObject pae_obj = parseJSONtoPAEContactMatrix(paeInput); if (pae_obj == null) { Console.debug("JSON file did not parse properly."); @@ -447,7 +458,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy } ContactMatrixI matrix = new PAEContactMatrix(sm.getSequence(), - (Map) pae_obj.get(0)); + (Map) pae_obj); AlignmentAnnotation cmannot = sm.getSequence().addContactList(matrix); // sm.getSequence().addAlignmentAnnotation(cmannot);