X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructures%2Fmodels%2FAAStructureBindingModel.java;h=61597573f2b62fd5a88dc85181f0a821de0f0bde;hb=9811278f9e18ee6cb88470dbae98da046734a0af;hp=16376319e24c97b9ae40d3cd908eb7bcc19cd880;hpb=954039bbfbde3648ac4c795277e788e49be5181b;p=jalview.git diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 1637631..6159757 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -20,6 +20,7 @@ */ package jalview.structures.models; +import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.SequenceRenderer; import jalview.api.StructureSelectionManagerProvider; @@ -53,9 +54,9 @@ import java.util.List; * @author gmcarstairs * */ -public abstract class AAStructureBindingModel extends - SequenceStructureBindingModel implements StructureListener, - StructureSelectionManagerProvider +public abstract class AAStructureBindingModel + extends SequenceStructureBindingModel + implements StructureListener, StructureSelectionManagerProvider { private StructureSelectionManager ssm; @@ -94,6 +95,8 @@ public abstract class AAStructureBindingModel extends public String fileLoadingError; + private boolean showAlignmentOnly; + /** * Data bean class to simplify parameterisation in superposeStructures */ @@ -142,7 +145,6 @@ public abstract class AAStructureBindingModel extends * @param ssm * @param pdbentry * @param sequenceIs - * @param chains * @param protocol */ public AAStructureBindingModel(StructureSelectionManager ssm, @@ -154,8 +156,60 @@ public abstract class AAStructureBindingModel extends this.nucleotide = Comparison.isNucleotide(sequenceIs); this.pdbEntry = pdbentry; this.protocol = protocol; + resolveChains(); } + private boolean resolveChains() + { + /** + * final count of chain mappings discovered + */ + int chainmaps = 0; + // JBPNote: JAL-2693 - this should be a list of chain mappings per + // [pdbentry][sequence] + String[][] newchains = new String[pdbEntry.length][]; + int pe = 0; + for (PDBEntry pdb : pdbEntry) + { + SequenceI[] seqsForPdb = sequence[pe]; + if (seqsForPdb != null) + { + newchains[pe] = new String[seqsForPdb.length]; + int se = 0; + for (SequenceI asq : seqsForPdb) + { + String chain = (chains != null && chains[pe] != null) + ? chains[pe][se] + : null; + SequenceI sq = (asq.getDatasetSequence() == null) ? asq + : asq.getDatasetSequence(); + if (sq.getAllPDBEntries() != null) + { + for (PDBEntry pdbentry : sq.getAllPDBEntries()) + { + if (pdb.getFile() != null && pdbentry.getFile() != null + && pdb.getFile().equals(pdbentry.getFile())) + { + String chaincode = pdbentry.getChainCode(); + if (chaincode != null && chaincode.length() > 0) + { + chain = chaincode; + chainmaps++; + break; + } + } + } + } + newchains[pe][se] = chain; + se++; + } + pe++; + } + } + + chains = newchains; + return chainmaps > 0; + } public StructureSelectionManager getSsm() { return ssm; @@ -300,11 +354,12 @@ public abstract class AAStructureBindingModel extends { throw new Error(MessageManager.formatMessage( "error.implementation_error_no_pdbentry_from_index", - new Object[] { Integer.valueOf(pe).toString() })); + new Object[] + { Integer.valueOf(pe).toString() })); } final String nullChain = "TheNullChain"; - List s = new ArrayList(); - List c = new ArrayList(); + List s = new ArrayList<>(); + List c = new ArrayList<>(); if (getChains() == null) { setChains(new String[getPdbCount()][]); @@ -373,8 +428,8 @@ public abstract class AAStructureBindingModel extends public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe, SequenceI[][] seq, String[][] chns) { - List v = new ArrayList(); - List rtn = new ArrayList(); + List v = new ArrayList<>(); + List rtn = new ArrayList<>(); for (int i = 0; i < getPdbCount(); i++) { v.add(getPdbEntry(i)); @@ -638,8 +693,8 @@ public abstract class AAStructureBindingModel extends if (waiting) { - System.err - .println("Timed out waiting for structure viewer to load file " + System.err.println( + "Timed out waiting for structure viewer to load file " + notLoaded); return false; } @@ -657,10 +712,8 @@ public abstract class AAStructureBindingModel extends { for (SequenceI s : seqs) { - if (s == seq - || (s.getDatasetSequence() != null && s - .getDatasetSequence() == seq - .getDatasetSequence())) + if (s == seq || (s.getDatasetSequence() != null + && s.getDatasetSequence() == seq.getDatasetSequence())) { return true; } @@ -732,7 +785,8 @@ public abstract class AAStructureBindingModel extends * * @return */ - public abstract SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment); + public abstract SequenceRenderer getSequenceRenderer( + AlignmentViewPanel alignment); protected abstract void colourBySequence( StructureMappingcommandSet[] colourBySequenceCommands); @@ -742,13 +796,20 @@ public abstract class AAStructureBindingModel extends public abstract void colourByCharge(); /** - * colour any structures associated with sequences in the given alignment - * using the getFeatureRenderer() and getSequenceRenderer() renderers but only - * if colourBySequence is enabled. + * Recolours the displayed structures, if they are coloured by sequence, or + * 'show only visible alignment' is selected. This supports updating structure + * colours on either change of alignment colours, or change to the visible + * region of the alignment. */ public void colourBySequence(AlignmentViewPanel alignmentv) { - if (!colourBySequence || !isLoadingFinished()) + if (!isLoadingFinished()) + { + return; + } + // todo: property change event for visibleAlignment + // to avoid unnecessary redraws here + if (!colourBySequence && !isShowAlignmentOnly()) { return; } @@ -757,9 +818,9 @@ public abstract class AAStructureBindingModel extends return; } String[] files = getStructureFiles(); - + SequenceRenderer sr = getSequenceRenderer(alignmentv); - + StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands( files, sr, alignmentv); colourBySequence(colourBySequenceCommands); @@ -772,4 +833,53 @@ public abstract class AAStructureBindingModel extends public abstract jalview.api.FeatureRenderer getFeatureRenderer( AlignmentViewPanel alignment); + + /** + * Sets the flag for whether only mapped visible residues in the alignment + * should be visible in the structure viewer + * + * @param b + */ + public void setShowAlignmentOnly(boolean b) + { + showAlignmentOnly = b; + } + + /** + * Answers true if only mapped visible residues in the alignment should be + * visible in the structure viewer, else false + * + * @return + */ + public boolean isShowAlignmentOnly() + { + return showAlignmentOnly; + } + + /** + * Shows the structures in the viewer, without changing their colouring. This is + * to support toggling of whether the whole structure is shown, or only residues + * mapped to visible regions of the alignment. + * + * @param alignViewportI + */ + public void showStructures(AlignViewportI alignViewportI) + { + // override with implementation + } + + @Override + public void updateColours(Object source) + { + AlignmentViewPanel ap = (AlignmentViewPanel) source; + // ignore events from panels not used to colour this view + if (!getViewer().isUsedforcolourby(ap)) + { + return; + } + if (!isLoadingFromArchive()) + { + colourBySequence(ap); + } + } }