X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=2bbc278ba8396491b70feaf11a6e6ccba30cd315;hb=5665f47f06e60c4a3c2715fde7adc02ab4c0186f;hp=5bfdb04946a25dfa30ad01c208c3c35bd16586d6;hpb=6819fa797b45769bb38a80230e5961e09582ed9e;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 5bfdb04..2bbc278 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -22,6 +22,8 @@ package jalview.datamodel; import jalview.analysis.AlignSeq; import jalview.api.DBRefEntryI; +import jalview.util.DBRefUtils; +import jalview.util.MapList; import jalview.util.StringUtils; import java.util.ArrayList; @@ -57,8 +59,6 @@ public class Sequence extends ASequence implements SequenceI String vamsasId; - DBRefEntryI sourceDBRef; - DBRefEntry[] dbrefs; RNA rna; @@ -235,8 +235,6 @@ public class Sequence extends ASequence implements SequenceI seq.getEnd()); } description = seq.getDescription(); - sourceDBRef = seq.getSourceDBRef() == null ? null : new DBRefEntry( - seq.getSourceDBRef()); if (seq != datasetSequence) { setDatasetSequence(seq.getDatasetSequence()); @@ -303,8 +301,14 @@ public class Sequence extends ASequence implements SequenceI } else { - System.err - .println("Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment"); + if (datasetSequence.getSequenceFeatures() != features + && datasetSequence.getSequenceFeatures() != null + && datasetSequence.getSequenceFeatures().length > 0) + { + new Exception( + "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment") + .printStackTrace(); + } datasetSequence.setSequenceFeatures(features); } } @@ -312,7 +316,11 @@ public class Sequence extends ASequence implements SequenceI @Override public synchronized void addSequenceFeature(SequenceFeature sf) { - // TODO add to dataset sequence instead if there is one? + if (sequenceFeatures==null && datasetSequence != null) + { + datasetSequence.addSequenceFeature(sf); + return; + } if (sequenceFeatures == null) { sequenceFeatures = new SequenceFeature[0]; @@ -338,6 +346,9 @@ public class Sequence extends ASequence implements SequenceI { if (sequenceFeatures == null) { + if (datasetSequence!=null) { + datasetSequence.deleteFeature(sf); + } return; } @@ -959,26 +970,25 @@ public class Sequence extends ASequence implements SequenceI dbrefs = new DBRefEntry[0]; } - int i, iSize = dbrefs.length; - - for (i = 0; i < iSize; i++) + for (DBRefEntryI dbr : dbrefs) { - if (dbrefs[i].equalRef(entry)) + if (dbr.updateFrom(entry)) { - if (entry.getMap() != null) - { - if (dbrefs[i].getMap() == null) - { - // overwrite with 'superior' entry that contains a mapping. - dbrefs[i] = entry; - } - } + /* + * found a dbref that either matched, or could be + * updated from, the new entry - no need to add it + */ return; } } - DBRefEntry[] temp = new DBRefEntry[iSize + 1]; - System.arraycopy(dbrefs, 0, temp, 0, iSize); + /* + * extend the array to make room for one more + */ + // TODO use an ArrayList instead + int j = dbrefs.length; + DBRefEntry[] temp = new DBRefEntry[j + 1]; + System.arraycopy(dbrefs, 0, temp, 0, j); temp[temp.length - 1] = entry; dbrefs = temp; @@ -1080,6 +1090,25 @@ public class Sequence extends ASequence implements SequenceI return new Sequence(this); } + private boolean _isNa; + + private long _seqhash = 0; + + @Override + public boolean isProtein() + { + if (datasetSequence != null) + { + return datasetSequence.isProtein(); + } + if (_seqhash != sequence.hashCode()) + { + _seqhash = sequence.hashCode(); + _isNa=jalview.util.Comparison.isNucleotide(new SequenceI[] { this }); + } + return !_isNa; + }; + /* * (non-Javadoc) * @@ -1364,12 +1393,15 @@ public class Sequence extends ASequence implements SequenceI @Override public PDBEntry getPDBEntry(String pdbIdStr) { - if (getDatasetSequence() == null - || getDatasetSequence().getAllPDBEntries() == null) + if (getDatasetSequence() != null) + { + return getDatasetSequence().getPDBEntry(pdbIdStr); + } + if (pdbIds == null) { return null; } - List entries = getDatasetSequence().getAllPDBEntries(); + List entries = getAllPDBEntries(); for (PDBEntry entry : entries) { if (entry.getId().equalsIgnoreCase(pdbIdStr)) @@ -1380,16 +1412,66 @@ public class Sequence extends ASequence implements SequenceI return null; } - @Override - public void setSourceDBRef(DBRefEntryI dbRef) - { - this.sourceDBRef = dbRef; - } @Override - public DBRefEntryI getSourceDBRef() + public List getPrimaryDBRefs() { - return this.sourceDBRef; + if (datasetSequence!=null) + { + return datasetSequence.getPrimaryDBRefs(); + } + if (dbrefs==null || dbrefs.length==0) + { + return Arrays.asList(new DBRefEntry[0]); + } + synchronized (dbrefs) + { + List primaries = new ArrayList(); + DBRefEntry tmp[] = new DBRefEntry[1], res[] = null; + for (DBRefEntry ref : dbrefs) + { + if (!ref.isPrimary()) + { + continue; + } + if (ref.hasMap()) + { + MapList mp = ref.getMap().getMap(); + if (mp.getFromLowest() > start || mp.getFromHighest() < end) + { + // map only involves a subsequence, so cannot be primary + continue; + } + } + // whilst it looks like it is a primary ref, we also sanity check type + if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals( + DBRefUtils.getCanonicalName(ref.getSource()))) + { + // PDB dbrefs imply there should be a PDBEntry associated + // TODO: tighten PDB dbrefs + // formally imply Jalview has actually downlaoded and + // parsed the pdb file. That means there should be a cached file + // handle on the PDBEntry, and a real mapping between sequence and + // extracted sequence from PDB file + PDBEntry pdbentry = getPDBEntry(ref.getAccessionId()); + if (pdbentry != null && pdbentry.getType() != null + && pdbentry.getType().equalsIgnoreCase("PDB")) + { + primaries.add(ref); + } + continue; + } + // check standard protein or dna sources + tmp[0] = ref; + res = DBRefUtils.selectDbRefs(!isProtein(), tmp); + if (res != null && res[0] == tmp[0]) + { + primaries.add(ref); + continue; + } + } + return primaries; + } } }