JAL-2694 StructureSelectionManager.getMapping takes a list of Chain IDs per sequence...
[jalview.git] / src / jalview / structures / models / AAStructureBindingModel.java
index 2528286..b9dc58d 100644 (file)
@@ -72,9 +72,9 @@ public abstract class AAStructureBindingModel
   private SequenceI[][] sequence;
 
   /*
-   * array of target chains for sequences - tied to pdbentry and sequence[]
+   * array of list of target chains for sequences - tied to pdbentry and sequence[]
    */
-  private String[][] chains;
+  private List<String>[][] chains;
 
   /*
    * datasource protocol for access to PDBEntrylatest
@@ -164,20 +164,26 @@ public abstract class AAStructureBindingModel
     int chainmaps = 0;
     // JBPNote: JAL-2693 - this should be a list of chain mappings per
     // [pdbentry][sequence]
-    String[][] newchains = new String[pdbEntry.length][];
+    List<String>[][] newchains = new List[pdbEntry.length][];
     int pe = 0;
     for (PDBEntry pdb : pdbEntry)
     {
       SequenceI[] seqsForPdb = sequence[pe];
       if (seqsForPdb != null)
       {
-        newchains[pe] = new String[seqsForPdb.length];
+        newchains[pe] = new List[seqsForPdb.length];
         int se = 0;
         for (SequenceI asq : seqsForPdb)
         {
-          String chain = (chains != null && chains[pe] != null)
+          List<String> chain = (chains != null && chains[pe] != null)
                   ? chains[pe][se]
                   : null;
+          if (chain == null)
+          {
+            chain = new ArrayList<>();
+          }
+          newchains[pe][se] = chain;
+
           SequenceI sq = (asq.getDatasetSequence() == null) ? asq
                   : asq.getDatasetSequence();
           if (sq.getAllPDBEntries() != null)
@@ -190,14 +196,12 @@ public abstract class AAStructureBindingModel
                 String chaincode = pdbentry.getChainCode();
                 if (chaincode != null && chaincode.length() > 0)
                 {
-                  chain = chaincode;
+                  newchains[pe][se].add(chaincode);
                   chainmaps++;
-                  break;
                 }
               }
             }
           }
-          newchains[pe][se] = chain;
           se++;
         }
         pe++;
@@ -259,7 +263,7 @@ public abstract class AAStructureBindingModel
     return sequence;
   }
 
-  public String[][] getChains()
+  public List<String>[][] getChains()
   {
     return chains;
   }
@@ -280,7 +284,7 @@ public abstract class AAStructureBindingModel
     this.sequence = sequence;
   }
 
-  protected void setChains(String[][] chains)
+  protected void setChains(List<String>[][] chains)
   {
     this.chains = chains;
   }
@@ -354,12 +358,11 @@ public abstract class AAStructureBindingModel
               new Object[]
               { Integer.valueOf(pe).toString() }));
     }
-    final String nullChain = "TheNullChain";
-    List<SequenceI> s = new ArrayList<SequenceI>();
-    List<String> c = new ArrayList<String>();
+    List<SequenceI> s = new ArrayList<>();
+    List<List<String>> c = new ArrayList<>();
     if (getChains() == null)
     {
-      setChains(new String[getPdbCount()][]);
+      setChains(new List[getPdbCount()][]);
     }
     if (getSequence()[pe] != null)
     {
@@ -374,14 +377,14 @@ public abstract class AAStructureBindingModel
           }
           else
           {
-            c.add(nullChain);
+            c.add(new ArrayList());
           }
         }
         else
         {
           if (tchain != null && tchain.length > 0)
           {
-            c.add(nullChain);
+            c.add(new ArrayList());
           }
         }
       }
@@ -393,7 +396,12 @@ public abstract class AAStructureBindingModel
         s.add(seq[i]);
         if (tchain != null && i < tchain.length)
         {
-          c.add(tchain[i] == null ? nullChain : tchain[i]);
+          List<String> clist = new ArrayList();
+          c.add(clist);
+          if (tchain[i] != null)
+          {
+            clist.add(tchain[i]);
+          }
         }
       }
     }
@@ -401,14 +409,7 @@ public abstract class AAStructureBindingModel
     getSequence()[pe] = tmp;
     if (c.size() > 0)
     {
-      String[] tch = c.toArray(new String[c.size()]);
-      for (int i = 0; i < tch.length; i++)
-      {
-        if (tch[i] == nullChain)
-        {
-          tch[i] = null;
-        }
-      }
+      List<String>[] tch = c.toArray(new List[c.size()]);
       getChains()[pe] = tch;
     }
     else
@@ -425,8 +426,8 @@ public abstract class AAStructureBindingModel
   public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe,
           SequenceI[][] seq, String[][] chns)
   {
-    List<PDBEntry> v = new ArrayList<PDBEntry>();
-    List<int[]> rtn = new ArrayList<int[]>();
+    List<PDBEntry> v = new ArrayList<>();
+    List<int[]> rtn = new ArrayList<>();
     for (int i = 0; i < getPdbCount(); i++)
     {
       v.add(getPdbEntry(i));
@@ -451,7 +452,7 @@ public abstract class AAStructureBindingModel
     {
       // expand the tied sequence[] and string[] arrays
       SequenceI[][] sqs = new SequenceI[getPdbCount()][];
-      String[][] sch = new String[getPdbCount()][];
+      List<String>[][] sch = new List[getPdbCount()][];
       System.arraycopy(getSequence(), 0, sqs, 0, getSequence().length);
       System.arraycopy(getChains(), 0, sch, 0, this.getChains().length);
       setSequence(sqs);