equals operation used for canonicalisation of DBRefList (rather than explict 'equals...
authorjprocter <Jim Procter>
Mon, 19 Mar 2007 13:43:23 +0000 (13:43 +0000)
committerjprocter <Jim Procter>
Mon, 19 Mar 2007 13:43:23 +0000 (13:43 +0000)
src/jalview/datamodel/Sequence.java

index 2303d5d..92c8dff 100755 (executable)
@@ -1,23 +1,24 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer
+* Jalview - A Sequence Alignment Editor and Viewer
  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- */
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+*/
 package jalview.datamodel;
 
+
 import java.util.*;
 
 import jalview.analysis.*;
@@ -33,7 +34,7 @@ public class Sequence
 {
   SequenceI datasetSequence;
   String name;
-  private char[] sequence;
+  private char [] sequence;
   String description;
   int start;
   int end;
@@ -48,6 +49,7 @@ public class Sequence
   /** DOCUMENT ME!! */
   public SequenceFeature[] sequenceFeatures;
 
+
   /**
    * Creates a new Sequence object.
    *
@@ -66,7 +68,7 @@ public class Sequence
     checkValidRange();
   }
 
-  public Sequence(String name, char[] sequence, int start, int end)
+  public Sequence(String name, char [] sequence, int start, int end)
   {
     this.name = name;
     this.sequence = sequence;
@@ -101,7 +103,7 @@ public class Sequence
       int endRes = 0;
       for (int j = 0; j < sequence.length; j++)
       {
-        if (!jalview.util.Comparison.isGap(sequence[j]))
+        if (!jalview.util.Comparison.isGap( sequence[j] ))
         {
           endRes++;
         }
@@ -141,6 +143,7 @@ public class Sequence
     description = seq.getDescription();
   }
 
+
   /**
    * DOCUMENT ME!
    *
@@ -175,12 +178,12 @@ public class Sequence
 
   public void deleteFeature(SequenceFeature sf)
   {
-    if (sequenceFeatures == null)
+    if(sequenceFeatures==null)
     {
       return;
     }
 
-    int index = 0;
+    int index=0;
     for (index = 0; index < sequenceFeatures.length; index++)
     {
       if (sequenceFeatures[index].equals(sf))
@@ -189,27 +192,28 @@ public class Sequence
       }
     }
 
-    if (index == sequenceFeatures.length)
+
+    if(index==sequenceFeatures.length)
     {
       return;
     }
 
     int sfLength = sequenceFeatures.length;
-    if (sfLength < 2)
+    if(sfLength<2)
     {
       sequenceFeatures = null;
     }
     else
     {
-      SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
+      SequenceFeature[] temp = new SequenceFeature[sfLength-1];
       System.arraycopy(sequenceFeatures, 0, temp, 0, index);
 
-      if (index < sfLength)
+      if(index<sfLength)
       {
         System.arraycopy(sequenceFeatures,
                          index + 1,
                          temp,
-                         index, sequenceFeatures.length - index - 1);
+                         index, sequenceFeatures.length - index -1);
       }
 
       sequenceFeatures = temp;
@@ -354,6 +358,7 @@ public class Sequence
     checkValidRange();
   }
 
+
   public String getSequenceAsString()
   {
     return new String(sequence);
@@ -364,7 +369,8 @@ public class Sequence
     return new String(getSequence(start, end));
   }
 
-  public char[] getSequence()
+
+  public char [] getSequence()
   {
     return sequence;
   }
@@ -377,7 +383,7 @@ public class Sequence
    *
    * @return DOCUMENT ME!
    */
-  public char[] getSequence(int start, int end)
+  public char [] getSequence(int start, int end)
   {
     // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
     if (start >= sequence.length)
@@ -390,12 +396,13 @@ public class Sequence
       end = sequence.length;
     }
 
-    char[] reply = new char[end - start];
-    System.arraycopy(sequence, start, reply, 0, end - start);
+    char [] reply = new char[end-start];
+    System.arraycopy(sequence, start, reply, 0, end-start);
 
     return reply;
   }
 
+
   /**
    * make a new Sequence object from start to end (including gaps) over this seqeunce
    * @param start int
@@ -408,7 +415,7 @@ public class Sequence
     {
       start = 0;
     }
-    char[] seq = getSequence(start, end);
+    char [] seq = getSequence(start, end);
     if (seq.length == 0)
     {
       return null;
@@ -418,13 +425,13 @@ public class Sequence
     // JBPNote - this is an incomplete copy.
     SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
     nseq.setDescription(description);
-    if (datasetSequence != null)
+    if (datasetSequence!=null)
     {
-      nseq.setDatasetSequence(datasetSequence);
+        nseq.setDatasetSequence(datasetSequence);
     }
     else
     {
-      nseq.setDatasetSequence(this);
+        nseq.setDatasetSequence(this);
     }
     return nseq;
   }
@@ -515,7 +522,7 @@ public class Sequence
     int seqlen = sequence.length;
     while ( (j < i) && (j < seqlen))
     {
-      if (!jalview.util.Comparison.isGap(sequence[j]))
+      if (!jalview.util.Comparison.isGap( sequence[j] ))
       {
         pos++;
       }
@@ -565,18 +572,18 @@ public class Sequence
       return;
     }
 
-    char[] tmp;
+    char [] tmp;
 
     if (j >= sequence.length)
     {
       tmp = new char[i];
-      System.arraycopy(sequence, 0, tmp, 0, i);
+      System.arraycopy(sequence,0,tmp,0,i);
     }
     else
     {
-      tmp = new char[sequence.length - j + i];
-      System.arraycopy(sequence, 0, tmp, 0, i);
-      System.arraycopy(sequence, j, tmp, i, sequence.length - j);
+      tmp = new char[sequence.length-j+i];
+      System.arraycopy(sequence,0,tmp,0,i);
+      System.arraycopy(sequence,j,tmp,i,sequence.length-j);
     }
 
     if (this.datasetSequence != null)
@@ -603,6 +610,7 @@ public class Sequence
 
   }
 
+
   /**
    * DOCUMENT ME!
    *
@@ -612,7 +620,7 @@ public class Sequence
    */
   public void insertCharAt(int i, int length, char c)
   {
-    char[] tmp = new char[sequence.length + length];
+    char [] tmp = new char[sequence.length+length];
 
     if (i >= sequence.length)
     {
@@ -620,20 +628,21 @@ public class Sequence
       i = sequence.length;
     }
     else
-    {
+   {
       System.arraycopy(sequence, 0, tmp, 0, i);
-    }
+   }
+
 
     int index = i;
     while (length > 0)
     {
-      tmp[index++] = c;
+      tmp[ index++ ] = c;
       length--;
     }
 
     if (i < sequence.length)
     {
-      System.arraycopy(sequence, i, tmp, index, sequence.length - i);
+      System.arraycopy(sequence, i, tmp, index, sequence.length-i );
     }
 
     sequence = tmp;
@@ -673,11 +682,9 @@ public class Sequence
 
     int i, iSize = dbrefs.length;
 
-    for (i = 0; i < iSize; i++)
+    for(i=0; i<iSize; i++)
     {
-      if (dbrefs[i].getAccessionId().equals(entry.getAccessionId())
-          && dbrefs[i].getSource().equals(entry.getSource())
-          && dbrefs[i].getVersion().equals(entry.getVersion()))
+      if(dbrefs[i].equals(entry))
       {
         return;
       }
@@ -726,6 +733,7 @@ public class Sequence
     this.annotation.addElement(annotation);
   }
 
+
   /**
    * test if this is a valid candidate for another
    * sequence's dataset sequence.
@@ -733,39 +741,40 @@ public class Sequence
    */
   private boolean isValidDatasetSequence()
   {
-    if (datasetSequence != null)
+    if (datasetSequence!=null)
     {
-      return false;
+          return false;
     }
-    for (int i = 0; i < sequence.length; i++)
+      for (int i=0;i<sequence.length; i++)
     {
-      if (jalview.util.Comparison.isGap(sequence[i]))
+          if (jalview.util.Comparison.isGap(sequence[i]))
       {
-        return false;
+              return false;
       }
     }
-    return true;
+      return true;
   }
-
   /* (non-Javadoc)
    * @see jalview.datamodel.SequenceI#deriveSequence()
    */
   public SequenceI deriveSequence()
   {
-    SequenceI seq = new Sequence(name, sequence, start, end);
-    seq.setDescription(description);
+      SequenceI seq = new Sequence(name, sequence, start, end);
+      seq.setDescription(description);
     if (datasetSequence != null)
     {
-      seq.setDatasetSequence(datasetSequence);
+          seq.setDatasetSequence(datasetSequence);
     }
     else
     {
-      if (isValidDatasetSequence())
+          if (isValidDatasetSequence())
       {
-        seq.setDatasetSequence(this);
+              seq.setDatasetSequence(this);
       }
     }
-    return seq;
+      return seq;
   }
 
 }
+
+