import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
}
@Override
- public void addPDBId(PDBEntry entry)
+ public boolean addPDBId(PDBEntry entry)
{
if (pdbIds == null)
{
pdbIds = new Vector<PDBEntry>();
+ 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;
}
/**
@Override
public void setDBRefs(DBRefEntry[] dbref)
{
+ if (dbrefs == null && datasetSequence != null
+ && this != datasetSequence)
+ {
+ datasetSequence.setDBRefs(dbref);
+ return;
+ }
dbrefs = dbref;
+ if (dbrefs != null)
+ {
+ DBRefUtils.ensurePrimaries(this);
+ }
}
@Override
@Override
public void addDBRef(DBRefEntry entry)
{
- // TODO add to dataset sequence instead if there is one?
+ if (datasetSequence != null)
+ {
+ datasetSequence.addDBRef(entry);
+ return;
+ }
+
if (dbrefs == null)
{
dbrefs = new DBRefEntry[0];
temp[temp.length - 1] = entry;
dbrefs = temp;
+
+ DBRefUtils.ensurePrimaries(this);
}
@Override
public void setDatasetSequence(SequenceI seq)
{
- // TODO check for circular reference before setting?
+ if (seq == this)
+ {
+ throw new Error(
+ "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
+ }
+ if (seq != null && seq.getDatasetSequence() != null)
+ {
+ throw new Error(
+ "Implementation error: cascading dataset sequences are not allowed.");
+ }
datasetSequence = seq;
}
{
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
}
if (dbrefs==null || dbrefs.length==0)
{
- return Arrays.asList(new DBRefEntry[0]);
+ return Collections.emptyList();
}
synchronized (dbrefs)
{
List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
- DBRefEntry tmp[] = new DBRefEntry[1], res[] = null;
+ DBRefEntry[] tmp = new DBRefEntry[1];
for (DBRefEntry ref : dbrefs)
{
- if (!ref.isPrimary())
+ if (!ref.isPrimaryCandidate())
{
continue;
}
{
// PDB dbrefs imply there should be a PDBEntry associated
// TODO: tighten PDB dbrefs
- // formally imply Jalview has actually downlaoded and
+ // 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.getType() != null
- && pdbentry.getType().equalsIgnoreCase("PDB"))
+ if (pdbentry != null && pdbentry.getFile() != null)
{
primaries.add(ref);
}
}
// 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);