X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=44522a85d0977ecc5bbd5fd8ad1042b626507a51;hb=33ad2b9a53a0e7faec7afddf91de829d98df07bc;hp=ec8aa81a1c598f4876984ec79d0cc0b9222e482e;hpb=af2dbf10bbcc54d9b9e4d398e9283b3c4a758e06;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index ec8aa81..44522a8 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -28,6 +28,7 @@ import jalview.util.StringUtils; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Vector; @@ -59,8 +60,6 @@ public class Sequence extends ASequence implements SequenceI String vamsasId; - DBRefEntryI sourceDBRef; - DBRefEntry[] dbrefs; RNA rna; @@ -307,8 +306,9 @@ public class Sequence extends ASequence implements SequenceI && datasetSequence.getSequenceFeatures() != null && datasetSequence.getSequenceFeatures().length > 0) { - System.err - .println("Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment"); + new Exception( + "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment") + .printStackTrace(); } datasetSequence.setSequenceFeatures(features); } @@ -412,28 +412,24 @@ public class Sequence extends ASequence implements SequenceI } @Override - public void addPDBId(PDBEntry entry) + public boolean addPDBId(PDBEntry entry) { if (pdbIds == null) { pdbIds = new Vector(); + pdbIds.add(entry); + return true; } - if (pdbIds.contains(entry)) - { - updatePDBEntry(pdbIds.get(pdbIds.indexOf(entry)), entry); - } - else - { - pdbIds.addElement(entry); - } - } - private static void updatePDBEntry(PDBEntry oldEntry, PDBEntry newEntry) - { - if (newEntry.getFile() != null) + for (PDBEntry pdbe : pdbIds) { - oldEntry.setFile(newEntry.getFile()); + if (pdbe.updateFrom(entry)) + { + return false; + } } + pdbIds.addElement(entry); + return true; } /** @@ -1225,46 +1221,22 @@ public class Sequence extends ASequence implements SequenceI { return false; } - Vector newpdb = new Vector(); - for (int i = 0; i < dbrefs.length; i++) + boolean added = false; + for (DBRefEntry dbr : dbrefs) { - if (DBRefSource.PDB.equals(dbrefs[i].getSource())) + if (DBRefSource.PDB.equals(dbr.getSource())) { - PDBEntry pdbe = new PDBEntry(); - pdbe.setId(dbrefs[i].getAccessionId()); - if (pdbIds == null || pdbIds.size() == 0) - { - newpdb.addElement(pdbe); - } - else - { - Enumeration en = pdbIds.elements(); - boolean matched = false; - while (!matched && en.hasMoreElements()) - { - PDBEntry anentry = (PDBEntry) en.nextElement(); - if (anentry.getId().equals(pdbe.getId())) - { - matched = true; - } - } - if (!matched) - { - newpdb.addElement(pdbe); - } - } - } - } - if (newpdb.size() > 0) - { - Enumeration en = newpdb.elements(); - while (en.hasMoreElements()) - { - addPDBId((PDBEntry) en.nextElement()); + /* + * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the + * PDB id is not already present in a 'matching' PDBEntry + * Constructor parses out a chain code if appended to the accession id + * (a fudge used to 'store' the chain code in the DBRef) + */ + PDBEntry pdbe = new PDBEntry(dbr); + added |= addPDBId(pdbe); } - return true; } - return false; + return added; } @Override @@ -1423,15 +1395,15 @@ public class Sequence extends ASequence implements SequenceI } if (dbrefs==null || dbrefs.length==0) { - return Arrays.asList(new DBRefEntry[0]); + return Collections.emptyList(); } synchronized (dbrefs) { List primaries = new ArrayList(); - DBRefEntry tmp[] = new DBRefEntry[1], res[] = null; + DBRefEntry[] tmp = new DBRefEntry[1]; for (DBRefEntry ref : dbrefs) { - if (!ref.isPrimary()) + if (!ref.isPrimaryCandidate()) { continue; } @@ -1449,7 +1421,13 @@ public class Sequence extends ASequence implements SequenceI DBRefUtils.getCanonicalName(ref.getSource()))) { // PDB dbrefs imply there should be a PDBEntry associated - if (getPDBEntry(ref.getAccessionId()) != null) + // TODO: tighten PDB dbrefs + // formally imply Jalview has actually downloaded 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.getFile() != null) { primaries.add(ref); } @@ -1457,7 +1435,7 @@ public class Sequence extends ASequence implements SequenceI } // check standard protein or dna sources tmp[0] = ref; - res = DBRefUtils.selectDbRefs(!isProtein(), tmp); + DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp); if (res != null && res[0] == tmp[0]) { primaries.add(ref);