javadoc
[jalview.git] / src / jalview / datamodel / Sequence.java
1 /*
2 * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 */
19 package jalview.datamodel;
20
21
22 import java.util.*;
23
24 import jalview.analysis.*;
25
26 /**
27  * 
28  * Implements the SequenceI interface for a char[] based sequence object.
29  *
30  * @author $author$
31  * @version $Revision$
32  */
33 public class Sequence
34     implements SequenceI
35 {
36   SequenceI datasetSequence;
37   String name;
38   private char [] sequence;
39   String description;
40   int start;
41   int end;
42   Vector pdbIds;
43   String vamsasId;
44   DBRefEntry[] dbrefs;
45
46   /** This annotation is displayed below the alignment but the
47    * positions are tied to the residues of this sequence */
48   Vector annotation;
49
50   /** array of seuqence features - may not be null for a valid sequence object */
51   public SequenceFeature[] sequenceFeatures;
52
53
54   /**
55    * Creates a new Sequence object.
56    *
57    * @param name display name string
58    * @param sequence string to form a possibly gapped sequence out of
59    * @param start first position of non-gap residue in the sequence
60    * @param end last position of ungapped residues (nearly always only used for display purposes)
61    */
62   public Sequence(String name, String sequence, int start, int end)
63   {
64     this.name = name;
65     this.sequence = sequence.toCharArray();
66     this.start = start;
67     this.end = end;
68     parseId();
69     checkValidRange();
70   }
71
72   public Sequence(String name, char [] sequence, int start, int end)
73   {
74     this.name = name;
75     this.sequence = sequence;
76     this.start = start;
77     this.end = end;
78     parseId();
79     checkValidRange();
80   }
81
82   com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
83       "[/][0-9]{1,}[-][0-9]{1,}$");
84   com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(
85       "[0-9]{1,}$");
86
87   void parseId()
88   {
89     if (name==null)
90     {
91       System.err.println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
92       name = "";
93     }
94     // Does sequence have the /start-end signiature?
95     if (limitrx.search(name))
96     {
97       name = limitrx.left();
98       endrx.search(limitrx.stringMatched());
99       setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
100           endrx.matchedFrom() - 1)));
101       setEnd(Integer.parseInt(endrx.stringMatched()));
102     }
103   }
104
105   void checkValidRange()
106   {
107     if (end < 1)
108     {
109       int endRes = 0;
110       for (int j = 0; j < sequence.length; j++)
111       {
112         if (!jalview.util.Comparison.isGap( sequence[j] ))
113         {
114           endRes++;
115         }
116       }
117       if (endRes > 0)
118       {
119         endRes += start - 1;
120       }
121
122       this.end = endRes;
123     }
124
125   }
126
127   /**
128    * Creates a new Sequence object.
129    *
130    * @param name DOCUMENT ME!
131    * @param sequence DOCUMENT ME!
132    */
133   public Sequence(String name, String sequence)
134   {
135     this(name, sequence, 1, -1);
136   }
137
138   /**
139    * Creates a new Sequence object with new features, DBRefEntries, AlignmentAnnotations, and PDBIds
140    * but inherits any existing dataset sequence reference.
141    * @param seq DOCUMENT ME!
142    */
143   public Sequence(SequenceI seq)
144   {
145     this(seq, seq.getAnnotation());
146   }
147   /**
148    * Create a new sequence object with new features, DBRefEntries, and PDBIds
149    * but inherits any existing dataset sequence reference, and duplicate of
150    * any annotation that is present in the given annotation array.
151    * @param seq the sequence to be copied
152    * @param alAnnotation an array of annotation including some associated with seq 
153    */
154   public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
155   {
156     this(seq.getName(),
157             seq.getSequence(),
158             seq.getStart(),
159             seq.getEnd());
160     description = seq.getDescription();
161     if (seq.getSequenceFeatures()!=null) {
162       SequenceFeature[] sf = seq.getSequenceFeatures();
163       for (int i=0; i<sf.length; i++) {
164         addSequenceFeature(new SequenceFeature(sf[i]));
165       }
166     }
167     if (seq.getDBRef()!=null) {
168       DBRefEntry[] dbr = seq.getDBRef();
169       for (int i=0; i<dbr.length; i++) {
170         addDBRef(new DBRefEntry(dbr[i]));
171       }
172     }
173     setDatasetSequence(seq.getDatasetSequence());
174     if (seq.getAnnotation()!=null) {
175       AlignmentAnnotation[] sqann = seq.getAnnotation();
176       for (int i=0;i<sqann.length; i++)
177       {
178         if (sqann[i]==null)
179         {
180           continue;
181         }
182         boolean found = (alAnnotation==null);
183         if (!found)
184         {
185           for (int apos = 0; !found && apos<alAnnotation.length; apos++)
186           {
187             found = (alAnnotation[apos] == sqann[i]);
188           }
189         }
190         if (found)
191         {
192           // only copy the given annotation
193           AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
194           addAlignmentAnnotation(newann);
195         }
196       }
197     }
198     if (seq.getPDBId()!=null) {
199       Vector ids = seq.getPDBId();
200       Enumeration e = ids.elements();
201       while (e.hasMoreElements()) {
202         this.addPDBId(new PDBEntry((PDBEntry) e.nextElement()));
203       }
204     }
205   }
206
207   /**
208    * DOCUMENT ME!
209    *
210    * @param v DOCUMENT ME!
211    */
212   public void setSequenceFeatures(SequenceFeature[] features)
213   {
214     sequenceFeatures = features;
215   }
216
217   public synchronized void addSequenceFeature(SequenceFeature sf)
218   {
219     if (sequenceFeatures == null)
220     {
221       sequenceFeatures = new SequenceFeature[0];
222     }
223
224     for (int i = 0; i < sequenceFeatures.length; i++)
225     {
226       if (sequenceFeatures[i].equals(sf))
227       {
228         return;
229       }
230     }
231
232     SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
233     System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
234     temp[sequenceFeatures.length] = sf;
235
236     sequenceFeatures = temp;
237   }
238
239   public void deleteFeature(SequenceFeature sf)
240   {
241     if(sequenceFeatures==null)
242     {
243       return;
244     }
245
246     int index=0;
247     for (index = 0; index < sequenceFeatures.length; index++)
248     {
249       if (sequenceFeatures[index].equals(sf))
250       {
251         break;
252       }
253     }
254
255
256     if(index==sequenceFeatures.length)
257     {
258       return;
259     }
260
261     int sfLength = sequenceFeatures.length;
262     if(sfLength<2)
263     {
264       sequenceFeatures = null;
265     }
266     else
267     {
268       SequenceFeature[] temp = new SequenceFeature[sfLength-1];
269       System.arraycopy(sequenceFeatures, 0, temp, 0, index);
270
271       if(index<sfLength)
272       {
273         System.arraycopy(sequenceFeatures,
274                          index + 1,
275                          temp,
276                          index, sequenceFeatures.length - index -1);
277       }
278
279       sequenceFeatures = temp;
280     }
281   }
282
283   /**
284    * DOCUMENT ME!
285    *
286    * @return DOCUMENT ME!
287    */
288   public SequenceFeature[] getSequenceFeatures()
289   {
290     return sequenceFeatures;
291   }
292
293   public void addPDBId(PDBEntry entry)
294   {
295     if (pdbIds == null)
296     {
297       pdbIds = new Vector();
298     }
299
300     pdbIds.addElement(entry);
301   }
302
303   /**
304    * DOCUMENT ME!
305    *
306    * @param id DOCUMENT ME!
307    */
308   public void setPDBId(Vector id)
309   {
310     pdbIds = id;
311   }
312
313   /**
314    * DOCUMENT ME!
315    *
316    * @return DOCUMENT ME!
317    */
318   public Vector getPDBId()
319   {
320     return pdbIds;
321   }
322
323   /**
324    * DOCUMENT ME!
325    *
326    * @return DOCUMENT ME!
327    */
328   public String getDisplayId(boolean jvsuffix)
329   {
330     StringBuffer result = new StringBuffer(name);
331     if (jvsuffix)
332     {
333       result.append("/" + start + "-" + end);
334     }
335
336     return result.toString();
337   }
338
339   /**
340    * DOCUMENT ME!
341    *
342    * @param name DOCUMENT ME!
343    */
344   public void setName(String name)
345   {
346     this.name = name;
347     this.parseId();
348   }
349
350   /**
351    * DOCUMENT ME!
352    *
353    * @return DOCUMENT ME!
354    */
355   public String getName()
356   {
357     return this.name;
358   }
359
360   /**
361    * DOCUMENT ME!
362    *
363    * @param start DOCUMENT ME!
364    */
365   public void setStart(int start)
366   {
367     this.start = start;
368   }
369
370   /**
371    * DOCUMENT ME!
372    *
373    * @return DOCUMENT ME!
374    */
375   public int getStart()
376   {
377     return this.start;
378   }
379
380   /**
381    * DOCUMENT ME!
382    *
383    * @param end DOCUMENT ME!
384    */
385   public void setEnd(int end)
386   {
387     this.end = end;
388   }
389
390   /**
391    * DOCUMENT ME!
392    *
393    * @return DOCUMENT ME!
394    */
395   public int getEnd()
396   {
397     return this.end;
398   }
399
400   /**
401    * DOCUMENT ME!
402    *
403    * @return DOCUMENT ME!
404    */
405   public int getLength()
406   {
407     return this.sequence.length;
408   }
409
410   /**
411    * DOCUMENT ME!
412    *
413    * @param seq DOCUMENT ME!
414    */
415   public void setSequence(String seq)
416   {
417     this.sequence = seq.toCharArray();
418     checkValidRange();
419   }
420
421
422   public String getSequenceAsString()
423   {
424     return new String(sequence);
425   }
426
427   public String getSequenceAsString(int start, int end)
428   {
429     return new String(getSequence(start, end));
430   }
431
432
433   public char [] getSequence()
434   {
435     return sequence;
436   }
437   /* (non-Javadoc)
438    * @see jalview.datamodel.SequenceI#getSequence(int, int)
439    */
440   public char [] getSequence(int start, int end)
441   {
442     if (start<0)
443       start=0;
444     // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
445     if (start >= sequence.length)
446     {
447       return new char[0];
448     }
449
450     if (end >= sequence.length)
451     {
452       end = sequence.length;
453     }
454
455     char [] reply = new char[end-start];
456     System.arraycopy(sequence, start, reply, 0, end-start);
457
458     return reply;
459   }
460
461
462   /**
463    * make a new Sequence object from start to end (including gaps) over this seqeunce
464    * @param start int
465    * @param end int
466    * @return SequenceI
467    */
468   public SequenceI getSubSequence(int start, int end)
469   {
470     if (start < 0)
471     {
472       start = 0;
473     }
474     char [] seq = getSequence(start, end);
475     if (seq.length == 0)
476     {
477       return null;
478     }
479     int nstart = findPosition(start);
480     int nend = findPosition(end) - 1;
481     // JBPNote - this is an incomplete copy.
482     SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
483     nseq.setDescription(description);
484     if (datasetSequence!=null)
485     {
486         nseq.setDatasetSequence(datasetSequence);
487     }
488     else
489     {
490         nseq.setDatasetSequence(this);
491     }
492     return nseq;
493   }
494
495   /**
496    * DOCUMENT ME!
497    *
498    * @param i DOCUMENT ME!
499    *
500    * @return DOCUMENT ME!
501    */
502   public char getCharAt(int i)
503   {
504     if (i < sequence.length)
505     {
506       return sequence[i];
507     }
508     else
509     {
510       return ' ';
511     }
512   }
513
514   /**
515    * DOCUMENT ME!
516    *
517    * @param desc DOCUMENT ME!
518    */
519   public void setDescription(String desc)
520   {
521     this.description = desc;
522   }
523
524   /**
525    * DOCUMENT ME!
526    *
527    * @return DOCUMENT ME!
528    */
529   public String getDescription()
530   {
531     return this.description;
532   }
533
534   /**
535    * Return the alignment position for a sequence position
536    *
537    * @param pos lying from start to end
538    *
539    * @return aligned position of residue pos
540    */
541   public int findIndex(int pos)
542   {
543     // returns the alignment position for a residue
544     int j = start;
545     int i = 0;
546
547     while ( (i < sequence.length) && (j <= end) && (j <= pos))
548     {
549       if (!jalview.util.Comparison.isGap(sequence[i]))
550       {
551         j++;
552       }
553
554       i++;
555     }
556
557     if ( (j == end) && (j < pos))
558     {
559       return end + 1;
560     }
561     else
562     {
563       return i;
564     }
565   }
566
567   /**
568    * Returns the sequence position for an alignment position
569    *
570    * @param i column index in alignment (from 1)
571    *
572    * @return residue number for residue (left of and) nearest ith column
573    */
574   public int findPosition(int i)
575   {
576     int j = 0;
577     int pos = start;
578     int seqlen = sequence.length;
579     while ( (j < i) && (j < seqlen))
580     {
581       if (!jalview.util.Comparison.isGap( sequence[j] ))
582       {
583         pos++;
584       }
585
586       j++;
587     }
588
589     return pos;
590   }
591
592   /**
593    * Returns an int array where indices correspond to each residue in the sequence and the element value gives its position in the alignment
594    *
595    * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no residues in SequenceI object
596    */
597   public int[] gapMap()
598   {
599     String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.
600         GapChars, new String(sequence));
601     int[] map = new int[seq.length()];
602     int j = 0;
603     int p = 0;
604
605     while (j < sequence.length)
606     {
607       if (!jalview.util.Comparison.isGap(sequence[j]))
608       {
609         map[p++] = j;
610       }
611
612       j++;
613     }
614
615     return map;
616   }
617
618   /* (non-Javadoc)
619    * @see jalview.datamodel.SequenceI#deleteChars(int, int)
620    */
621   public void deleteChars(int i, int j)
622   {
623     int newstart=start,newend=end;
624     if (i >= sequence.length)
625     {
626       return;
627     }
628
629     char [] tmp;
630
631     if (j >= sequence.length)
632     {
633       tmp = new char[i];
634       System.arraycopy(sequence,0,tmp,0,i);
635     }
636     else
637     {
638       tmp = new char[sequence.length-j+i];
639       System.arraycopy(sequence,0,tmp,0,i);
640       System.arraycopy(sequence,j,tmp,i,sequence.length-j);
641     }
642     boolean createNewDs=false;
643     for (int s = i; s < j; s++)
644     {
645       if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
646       {
647         if (createNewDs)
648         {
649           newend--;
650         } else {
651           int sindex = findIndex(start)-1;
652           if (sindex==s)
653         {
654           // delete characters including start of sequence
655           newstart = findPosition(j);
656           break; // don't need to search for any more residue characters.
657         } else {
658           // delete characters after start.
659           int eindex = findIndex(end)-1;
660           if (eindex<j)
661           {
662             // delete characters at end of sequence
663             newend = findPosition(i-1);
664             break; // don't need to search for any more residue characters.
665           } else {
666             createNewDs=true;
667             newend--; // decrease end position by one for the deleted residue and search further
668           }
669         }
670         }
671       }
672     }
673     // deletion occured in the middle of the sequence
674     if (createNewDs && this.datasetSequence != null)
675     {
676       // construct a new sequence
677       Sequence ds = new Sequence(datasetSequence);
678       // TODO: remove any non-inheritable properties ?
679       // TODO: create a sequence mapping (since there is a relation here ?)
680       ds.deleteChars(i, j);
681       datasetSequence = ds;
682     }
683     start = newstart;
684     end = newend;
685     sequence = tmp;
686   }
687
688
689   /**
690    * DOCUMENT ME!
691    *
692    * @param i DOCUMENT ME!
693    * @param c DOCUMENT ME!
694    * @param chop DOCUMENT ME!
695    */
696   public void insertCharAt(int i, int length, char c)
697   {
698     char [] tmp = new char[sequence.length+length];
699
700     if (i >= sequence.length)
701     {
702       System.arraycopy(sequence, 0, tmp, 0, sequence.length);
703       i = sequence.length;
704     }
705     else
706    {
707       System.arraycopy(sequence, 0, tmp, 0, i);
708    }
709
710
711     int index = i;
712     while (length > 0)
713     {
714       tmp[ index++ ] = c;
715       length--;
716     }
717
718     if (i < sequence.length)
719     {
720       System.arraycopy(sequence, i, tmp, index, sequence.length-i );
721     }
722
723     sequence = tmp;
724   }
725
726   public void insertCharAt(int i, char c)
727   {
728     insertCharAt(i, 1, c);
729   }
730
731   public String getVamsasId()
732   {
733     return vamsasId;
734   }
735
736   public void setVamsasId(String id)
737   {
738     vamsasId = id;
739   }
740
741   public void setDBRef(DBRefEntry[] dbref)
742   {
743     dbrefs = dbref;
744   }
745
746   public DBRefEntry[] getDBRef()
747   {
748     return dbrefs;
749   }
750
751   public void addDBRef(DBRefEntry entry)
752   {
753     if (dbrefs == null)
754     {
755       dbrefs = new DBRefEntry[0];
756     }
757
758     int i, iSize = dbrefs.length;
759
760     for(i=0; i<iSize; i++)
761     {
762       if(dbrefs[i].equalRef(entry))
763       {
764         if (entry.getMap()!=null)
765         {
766           if (dbrefs[i].getMap()==null)
767           {
768             // overwrite with 'superior' entry that contains a mapping.
769             dbrefs[i] = entry;
770           }
771         }
772         return;
773       }
774     }
775
776     DBRefEntry[] temp = new DBRefEntry[iSize + 1];
777     System.arraycopy(dbrefs, 0, temp, 0, iSize);
778     temp[temp.length - 1] = entry;
779
780     dbrefs = temp;
781   }
782
783   public void setDatasetSequence(SequenceI seq)
784   {
785     datasetSequence = seq;
786   }
787
788   public SequenceI getDatasetSequence()
789   {
790     return datasetSequence;
791   }
792
793   public AlignmentAnnotation[] getAnnotation()
794   {
795     if (annotation == null)
796     {
797       return null;
798     }
799
800     AlignmentAnnotation[] ret = new AlignmentAnnotation[annotation.size()];
801     for (int r = 0; r < ret.length; r++)
802     {
803       ret[r] = (AlignmentAnnotation) annotation.elementAt(r);
804     }
805
806     return ret;
807   }
808
809   public void addAlignmentAnnotation(AlignmentAnnotation annotation)
810   {
811     if (this.annotation == null)
812     {
813       this.annotation = new Vector();
814     }
815
816     this.annotation.addElement(annotation);
817     annotation.setSequenceRef(this);
818   }
819
820   public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
821   {
822     if(this.annotation!=null)
823     {
824       this.annotation.removeElement(annotation);
825       if(this.annotation.size()==0)
826         this.annotation = null;
827     }
828   }
829
830
831   /**
832    * test if this is a valid candidate for another
833    * sequence's dataset sequence.
834    *
835    */
836   private boolean isValidDatasetSequence()
837   {
838     if (datasetSequence!=null)
839     {
840           return false;
841     }
842       for (int i=0;i<sequence.length; i++)
843     {
844           if (jalview.util.Comparison.isGap(sequence[i]))
845       {
846               return false;
847       }
848     }
849       return true;
850   }
851   /* (non-Javadoc)
852    * @see jalview.datamodel.SequenceI#deriveSequence()
853    */
854   public SequenceI deriveSequence()
855   {
856     SequenceI seq=new Sequence(this);
857     if (datasetSequence != null)
858     {
859       // duplicate current sequence with same dataset
860       seq.setDatasetSequence(datasetSequence);
861     }
862     else
863     {
864       if (isValidDatasetSequence())
865       {
866         // Use this as dataset sequence
867         seq.setDatasetSequence(this);
868       } else {
869         // Create a new, valid dataset sequence
870         SequenceI ds = seq;
871         ds.setSequence(AlignSeq.extractGaps(jalview.util.Comparison.GapChars, new String(sequence)));
872         setDatasetSequence(ds);
873         ds.setSequenceFeatures(getSequenceFeatures());
874         seq = this; // and return this sequence as the derived sequence.
875       }
876     }
877     return seq;
878   }
879
880   /* (non-Javadoc)
881    * @see jalview.datamodel.SequenceI#createDatasetSequence()
882    */
883   public SequenceI createDatasetSequence()
884   {
885     if (datasetSequence==null)
886     {
887       datasetSequence = new Sequence(getName(),
888               AlignSeq.extractGaps(
889                 jalview.util.Comparison.GapChars,
890                 getSequenceAsString()),
891             getStart(),
892             getEnd());
893       datasetSequence.setSequenceFeatures(getSequenceFeatures());
894       datasetSequence.setDescription(getDescription());
895       setSequenceFeatures(null);
896       // move database references onto dataset sequence
897       datasetSequence.setDBRef(getDBRef());
898       setDBRef(null);
899     }
900     return datasetSequence;
901   }
902   /* (non-Javadoc)
903    * @see jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[] annotations)
904    */
905   public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
906   {
907     if (annotation!=null) {
908       annotation.removeAllElements();
909     }
910     if (annotations!=null) {
911       for (int i=0; i<annotations.length; i++)
912       {
913         if (annotations[i]!=null)
914           addAlignmentAnnotation(annotations[i]);
915       }
916     }
917   }
918
919   /* (non-Javadoc)
920    * @see jalview.datamodel.SequenceI#getAnnotation(java.lang.String)
921    */
922   public AlignmentAnnotation[] getAnnotation(String label)
923   {
924     if (annotation==null || annotation.size()==0)
925     {
926       return null;
927     }
928     
929     Vector subset = new Vector();
930     Enumeration e = annotation.elements();
931     while (e.hasMoreElements())
932     {
933       AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
934       if (ann.label!=null && ann.label.equals(label))
935       {
936         subset.addElement(ann);
937       }
938     }
939     if (subset.size()==0)
940     {
941       return null;
942     }
943     AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
944     int i=0;
945     e = subset.elements();
946     while (e.hasMoreElements())
947     {
948       anns[i++] = (AlignmentAnnotation) e.nextElement();
949     }
950     subset.removeAllElements();
951     return anns;
952   }
953
954   public boolean updatePDBIds()
955   {
956     if (dbrefs==null || dbrefs.length==0)
957     {
958       return false;
959     }
960     Vector newpdb = new Vector();
961     for (int i=0; i<dbrefs.length;i++)
962     {
963       if (DBRefSource.PDB.equals(dbrefs[i].getSource()))
964       {
965         PDBEntry pdbe = new PDBEntry();
966         pdbe.setId(dbrefs[i].getAccessionId());
967         if (pdbIds==null || pdbIds.size()==0)
968         {
969           newpdb.addElement(pdbe);
970         } else {
971           Enumeration en  = pdbIds.elements();
972           boolean matched=false;
973           while (!matched && en.hasMoreElements())
974           {
975             PDBEntry anentry = (PDBEntry) en.nextElement();
976             if (anentry.getId().equals(pdbe.getId()))
977             {
978               matched=true;
979             }
980           }
981           if (!matched)
982           {
983             newpdb.addElement(pdbe);
984           }
985         }
986       }
987     }
988     if (newpdb.size()>0)
989     {
990       Enumeration en = newpdb.elements();
991       while (en.hasMoreElements())
992       {
993         addPDBId((PDBEntry) en.nextElement());
994       }
995       return true;
996     }
997     return false;
998   }
999
1000 }
1001
1002