JAL-2136 JAL-2137 Improvements: enable STRUCTMODEL annotation statement to be less...
[jalview.git] / src / jalview / io / AnnotationFile.java
index 571ed79..01f6e6f 100755 (executable)
@@ -1017,9 +1017,11 @@ public class AnnotationFile
         {
           boolean failedtoadd = true;
           // expect
-          // STRUCTMODEL <TemplateSeqId> <ModelFile> <FastaMappingFile>
+          // STRUCTMODEL <Query> <TemplateSeqId> <ModelFile> <FastaMappingFile>
           // <Confidence> <%.I.D>
           // <MatchStart> <MatchEnd> <Coverage> [<Other Information>]
+          String querySeqId = !st.hasMoreTokens() ? "" : st.nextToken();
+          SequenceI querySeq = al.findName(querySeqId);
           if (st.hasMoreTokens()) {
             refSeq = al.findName(refSeqId = st.nextToken());
             if (refSeq == null)
@@ -1032,12 +1034,15 @@ public class AnnotationFile
             {
               String tempId = st.nextToken();
               String fastaMapping = st.nextToken();
-              String confidence = 100 * Double.valueOf(st.nextToken()) + "";
-              String pid = st.nextToken();
-              String alignRange = st.nextToken() + "-" + st.nextToken();
-              String otherInfo = st.hasMoreTokens() ? st.nextToken() : "";
+              String confidence = !st.hasMoreTokens() ? "" : 100
+                      * Double.valueOf(st.nextToken()) + "";
+              String pid = !st.hasMoreTokens() ? "" : st.nextToken();
+              String alignRange = !st.hasMoreTokens() ? "" : st.nextToken()
+                      + "-" + st.nextToken();
+              String otherInfo = !st.hasMoreTokens() ? "" : st.nextToken();
               String coverage = "";
-              if (add_structmodel(al, refSeq, tempId, fastaMapping,
+              if (add_structmodel(al, querySeq, refSeq, tempId,
+                      fastaMapping,
                       alignRange, coverage,
                       confidence, pid, otherInfo))
               {
@@ -1048,7 +1053,7 @@ public class AnnotationFile
           if (failedtoadd)
           {
             System.err
-                    .println("Need <TemplateSeqId> <ModelFile> <FastaMappingFile> <Confidence> <%.I.D> <MatchStart> <MatchEnd> <Coverage> [<Other Information>] as tab separated fields after"
+                    .println("Need <Query> <TemplateSeqId> <ModelFile> <FastaMappingFile> <Confidence> <%.I.D> <MatchStart> <MatchEnd> <Coverage> [<Other Information>] as tab separated fields after"
                             + STRUCTMODEL
                             + ".\nNote: other information could be provided in html format ");
           } else {
@@ -1265,7 +1270,8 @@ public class AnnotationFile
    * @param urlToPairwise
    * @return true if model and sequence was added
    */
-  private boolean add_structmodel(AlignmentI al, SequenceI refSeq,
+  private boolean add_structmodel(AlignmentI al, SequenceI querySequence,
+          SequenceI templateSeq,
           String modelFile, String fastaFile, String aRange,
           String coverage, String confidence,
           String pid, String otherInfo)
@@ -1274,15 +1280,20 @@ public class AnnotationFile
     boolean added = false;
     try {
       String structureModelFile = resolveAbsolute(modelFile);
-      String fastaMappingFile = resolveAbsolute(fastaFile);
-      // System.out.println("Model File >> " + fastaMappingFile);
-      // System.out.println("Fasta File >> " + structureModelFile);
+      String fastaMappingFile = resolveAbsolute(fastaFile.replaceAll(
+              ".fasta.jal", ".fasta"));
+      // System.out.println("Model File >> " + structureModelFile);
+      // System.out.println("Fasta File >> " + fastaMappingFile);
       PDBEntry phyre2PDBEntry = new PDBEntry(modelFile, null, Type.FILE,
               structureModelFile);
       String phyre2ModelDesc = generatePhyre2InfoHTMLTable(aRange,
               coverage, confidence, pid, otherInfo);
       phyre2PDBEntry.setProperty("PHYRE2_MODEL_INFO", phyre2ModelDesc);
-      refSeq.getDatasetSequence().addPDBId(phyre2PDBEntry);
+      templateSeq.getDatasetSequence().addPDBId(phyre2PDBEntry);
+      if (querySequence != null)
+      {
+        querySequence.getDatasetSequence().addPDBId(phyre2PDBEntry);
+      }
       StructureSelectionManager ssm = StructureSelectionManager
               .getStructureSelectionManager(Desktop.instance);
       ssm.registerPhyre2Template(structureModelFile, fastaMappingFile);