X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=4506742051dd57e0ac0d00462713bd13783dcfef;hb=838e4f91d4a53dd315640dbc9ff6ef7a815ee576;hp=9e9344434018382d59b303001fab3133d42f296c;hpb=70f9c4700f20a8fa57ed7eb974277d8bad0723c2;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 9e93444..4506742 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -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.0b1) + * 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. @@ -37,7 +37,7 @@ import jalview.util.StringUtils; * @author $author$ * @version $Revision$ */ -public class Sequence implements SequenceI +public class Sequence extends ASequence implements SequenceI { SequenceI datasetSequence; @@ -59,7 +59,6 @@ public class Sequence implements SequenceI RNA rna; - /** * This annotation is displayed below the alignment but the positions are tied * to the residues of this sequence @@ -91,20 +90,30 @@ public class Sequence implements SequenceI */ public Sequence(String name, String sequence, int start, int end) { - this.name = name; - this.sequence = sequence.toCharArray(); - this.start = start; - this.end = end; - parseId(); - checkValidRange(); + initSeqAndName(name, sequence.toCharArray(), start, end); } public Sequence(String name, char[] sequence, int start, int end) { - this.name = name; - this.sequence = sequence; - this.start = start; - this.end = end; + initSeqAndName(name, sequence, start, end); + } + + /** + * Stage 1 constructor - assign name, sequence, and set start and end fields. + * start and end are updated values from name2 if it ends with /start-end + * + * @param name2 + * @param sequence2 + * @param start2 + * @param end2 + */ + protected void initSeqAndName(String name2, char[] sequence2, int start2, + int end2) + { + this.name = name2; + this.sequence = sequence2; + this.start = start2; + this.end = end2; parseId(); checkValidRange(); } @@ -197,7 +206,15 @@ public class Sequence implements SequenceI */ public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation) { - this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd()); + initSeqFrom(seq, alAnnotation); + + } + + protected void initSeqFrom(SequenceI seq, + AlignmentAnnotation[] alAnnotation) + { + initSeqAndName(seq.getName(), seq.getSequence(), seq.getStart(), + seq.getEnd()); description = seq.getDescription(); if (seq.getSequenceFeatures() != null) { @@ -242,9 +259,9 @@ public class Sequence 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()) { @@ -392,7 +409,7 @@ public class Sequence implements SequenceI * @return DOCUMENT ME! */ @Override - public Vector getPDBId() + public Vector getAllPDBEntries() { return pdbIds; } @@ -730,8 +747,7 @@ public class Sequence implements SequenceI { if (lastj != -1) { - map.add(new int[] - { lastj, j - 1 }); + map.add(new int[] { lastj, j - 1 }); lastj = -1; } } @@ -739,8 +755,7 @@ public class Sequence implements SequenceI } if (lastj != -1) { - map.add(new int[] - { lastj, j - 1 }); + map.add(new int[] { lastj, j - 1 }); lastj = -1; } return map; @@ -750,7 +765,7 @@ public class Sequence 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; } @@ -938,7 +953,6 @@ public class Sequence implements SequenceI .toArray(new AlignmentAnnotation[annotation.size()]); } - @Override public boolean hasAnnotation(AlignmentAnnotation ann) { @@ -1039,7 +1053,7 @@ public class Sequence 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) @@ -1190,8 +1204,7 @@ public class Sequence 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++) @@ -1203,9 +1216,9 @@ public class Sequence 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(); @@ -1284,5 +1297,28 @@ public class Sequence 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 entries = getDatasetSequence().getAllPDBEntries(); + for (PDBEntry entry : entries) + { + if (entry.getId().equalsIgnoreCase(pdbIdStr)) + { + return entry; + } + } + return null; + } }