JAL-2136 New Phyre2 branch + attempt to resynced with develop
[jalview.git] / src / jalview / ws / sifts / SiftsClient.java
index fe3a25b..53a2b8c 100644 (file)
@@ -21,6 +21,8 @@
 package jalview.ws.sifts;
 
 import jalview.analysis.AlignSeq;
+import jalview.analysis.scoremodels.ScoreMatrix;
+import jalview.analysis.scoremodels.ScoreModels;
 import jalview.api.DBRefEntryI;
 import jalview.api.SiftsClientI;
 import jalview.datamodel.DBRefEntry;
@@ -29,6 +31,7 @@ import jalview.datamodel.SequenceI;
 import jalview.io.StructureFile;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureMapping;
+import jalview.structures.models.MappingOutputModel;
 import jalview.util.Comparison;
 import jalview.util.DBRefUtils;
 import jalview.util.Format;
@@ -80,9 +83,13 @@ public class SiftsClient implements SiftsClientI
    */
   private static File mockSiftsFile;
 
+  private static final int UNASSIGNED = StructureMapping.UNASSIGNED; // -1
+
+  private static final int PDB_RES_POS = StructureMapping.PDB_RES_NUM_INDEX; // 0
+
   private Entry siftsEntry;
 
-  private StructureFile pdb;
+  private StructureFile structureFile;
 
   private String pdbId;
 
@@ -92,10 +99,6 @@ public class SiftsClient implements SiftsClientI
 
   private static final int BUFFER_SIZE = 4096;
 
-  public static final int UNASSIGNED = -1;
-
-  private static final int PDB_RES_POS = 0;
-
   private static final int PDB_ATOM_POS = 1;
 
   private static final String NOT_OBSERVED = "Not_Observed";
@@ -148,10 +151,10 @@ public class SiftsClient implements SiftsClientI
    * @param pdbId
    * @throws SiftsException
    */
-  public SiftsClient(StructureFile pdb) throws SiftsException
+  public SiftsClient(StructureFile structureFile) throws SiftsException
   {
-    this.pdb = pdb;
-    this.pdbId = pdb.getId();
+    this.structureFile = structureFile;
+    this.pdbId = structureFile.getId();
     File siftsFile = getSiftsFile(pdbId);
     siftsEntry = parseSIFTs(siftsFile);
   }
@@ -530,7 +533,7 @@ public class SiftsClient implements SiftsClientI
 
     if (os != null)
     {
-      MappingOutputPojo mop = new MappingOutputPojo();
+      MappingOutputModel mop = new MappingOutputModel();
       mop.setSeqStart(seqStart);
       mop.setSeqEnd(seqEnd);
       mop.setSeqName(seq.getName());
@@ -654,7 +657,7 @@ public class SiftsClient implements SiftsClientI
   {
     try
     {
-      PDBChain chain = pdb.findChain(chainId);
+      PDBChain chain = structureFile.findChain(chainId);
 
       if (chain == null || mapping == null)
       {
@@ -963,7 +966,7 @@ public class SiftsClient implements SiftsClientI
   }
 
   @Override
-  public StringBuffer getMappingOutput(MappingOutputPojo mp)
+  public StringBuilder getMappingOutput(MappingOutputModel mp)
           throws SiftsException
   {
     String seqRes = mp.getSeqResidue();
@@ -985,7 +988,7 @@ public class SiftsClient implements SiftsClientI
     int nochunks = ((seqRes.length()) / len)
             + ((seqRes.length()) % len > 0 ? 1 : 0);
     // output mappings
-    StringBuffer output = new StringBuffer();
+    StringBuilder output = new StringBuilder(512);
     output.append(NEWLINE);
     output.append("Sequence \u27f7 Structure mapping details").append(
             NEWLINE);
@@ -1006,6 +1009,7 @@ public class SiftsClient implements SiftsClientI
     output.append(String.valueOf(pdbEnd));
     output.append(NEWLINE).append(NEWLINE);
 
+    ScoreMatrix pam250 = ScoreModels.getInstance().getPam250();
     int matchedSeqCount = 0;
     for (int j = 0; j < nochunks; j++)
     {
@@ -1024,27 +1028,29 @@ public class SiftsClient implements SiftsClientI
       output.append(NEWLINE);
       output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
 
-      // Print out the matching chars
+      /*
+       * Print out the match symbols:
+       * | for exact match (ignoring case)
+       * . if PAM250 score is positive
+       * else a space
+       */
       for (int i = 0; i < len; i++)
       {
         try
         {
           if ((i + (j * len)) < seqRes.length())
           {
-            boolean sameChar = Comparison.isSameResidue(
-                    seqRes.charAt(i + (j * len)),
-                    strRes.charAt(i + (j * len)), false);
-            if (sameChar
-                    && !jalview.util.Comparison.isGap(seqRes.charAt(i
-                            + (j * len))))
+            char c1 = seqRes.charAt(i + (j * len));
+            char c2 = strRes.charAt(i + (j * len));
+            boolean sameChar = Comparison.isSameResidue(c1, c2, false);
+            if (sameChar && !Comparison.isGap(c1))
             {
               matchedSeqCount++;
               output.append("|");
             }
             else if (type.equals("pep"))
             {
-              if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
-                      strRes.charAt(i + (j * len))) > 0)
+              if (pam250.getPairwiseScore(c1, c2) > 0)
               {
                 output.append(".");
               }
@@ -1122,4 +1128,5 @@ public class SiftsClient implements SiftsClientI
     mockSiftsFile = file;
   }
 
+
 }