JAL-1925 update source version in license
[jalview.git] / src / jalview / datamodel / Sequence.java
index 37bb7a9..8b089a2 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -20,6 +20,9 @@
  */
 package jalview.datamodel;
 
+import jalview.analysis.AlignSeq;
+import jalview.util.StringUtils;
+
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
@@ -27,9 +30,6 @@ import java.util.Vector;
 
 import fr.orsay.lri.varna.models.rna.RNA;
 
-import jalview.analysis.AlignSeq;
-import jalview.util.StringUtils;
-
 /**
  * 
  * Implements the SequenceI interface for a char[] based sequence object.
@@ -59,7 +59,6 @@ public class Sequence extends ASequence implements SequenceI
 
   RNA rna;
 
-
   /**
    * This annotation is displayed below the alignment but the positions are tied
    * to the residues of this sequence
@@ -260,9 +259,9 @@ public class Sequence extends ASequence implements SequenceI
         }
       }
     }
-    if (seq.getPDBId() != null)
+    if (seq.getAllPDBEntries() != null)
     {
-      Vector ids = seq.getPDBId();
+      Vector ids = seq.getAllPDBEntries();
       Enumeration e = ids.elements();
       while (e.hasMoreElements())
       {
@@ -410,7 +409,7 @@ public class Sequence extends ASequence implements SequenceI
    * @return DOCUMENT ME!
    */
   @Override
-  public Vector<PDBEntry> getPDBId()
+  public Vector<PDBEntry> getAllPDBEntries()
   {
     return pdbIds;
   }
@@ -748,8 +747,7 @@ public class Sequence extends ASequence implements SequenceI
       {
         if (lastj != -1)
         {
-          map.add(new int[]
-          { lastj, j - 1 });
+          map.add(new int[] { lastj, j - 1 });
           lastj = -1;
         }
       }
@@ -757,8 +755,7 @@ public class Sequence extends ASequence implements SequenceI
     }
     if (lastj != -1)
     {
-      map.add(new int[]
-      { lastj, j - 1 });
+      map.add(new int[] { lastj, j - 1 });
       lastj = -1;
     }
     return map;
@@ -768,7 +765,7 @@ public class Sequence extends ASequence implements SequenceI
   public void deleteChars(int i, int j)
   {
     int newstart = start, newend = end;
-    if (i >= sequence.length)
+    if (i >= sequence.length || i < 0)
     {
       return;
     }
@@ -956,7 +953,6 @@ public class Sequence extends ASequence implements SequenceI
             .toArray(new AlignmentAnnotation[annotation.size()]);
   }
 
-
   @Override
   public boolean hasAnnotation(AlignmentAnnotation ann)
   {
@@ -1057,7 +1053,7 @@ public class Sequence extends ASequence implements SequenceI
       // move database references onto dataset sequence
       datasetSequence.setDBRef(getDBRef());
       setDBRef(null);
-      datasetSequence.setPDBId(getPDBId());
+      datasetSequence.setPDBId(getAllPDBEntries());
       setPDBId(null);
       datasetSequence.updatePDBIds();
       if (annotation != null)
@@ -1208,8 +1204,7 @@ public class Sequence extends ASequence implements SequenceI
       for (int si = 0; si < sfs.length; si++)
       {
         SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
-                : new SequenceFeature[]
-                { new SequenceFeature(sfs[si]) };
+                : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
         if (sf != null && sf.length > 0)
         {
           for (int sfi = 0; sfi < sf.length; sfi++)
@@ -1221,9 +1216,9 @@ public class Sequence extends ASequence implements SequenceI
     }
 
     // transfer PDB entries
-    if (entry.getPDBId() != null)
+    if (entry.getAllPDBEntries() != null)
     {
-      Enumeration e = entry.getPDBId().elements();
+      Enumeration e = entry.getAllPDBEntries().elements();
       while (e.hasMoreElements())
       {
         PDBEntry pdb = (PDBEntry) e.nextElement();
@@ -1302,5 +1297,28 @@ public class Sequence extends ASequence implements SequenceI
     return result;
   }
 
+  public String toString()
+  {
+    return getDisplayId(false);
+  }
+
+  @Override
+  public PDBEntry getPDBEntry(String pdbIdStr)
+  {
+    if (getDatasetSequence() == null
+            || getDatasetSequence().getAllPDBEntries() == null)
+    {
+      return null;
+    }
+    List<PDBEntry> entries = getDatasetSequence().getAllPDBEntries();
+    for (PDBEntry entry : entries)
+    {
+      if (entry.getId().equalsIgnoreCase(pdbIdStr))
+      {
+        return entry;
+      }
+    }
+    return null;
+  }
 
 }