X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructures%2Fmodels%2FAAStructureBindingModel.java;h=61597573f2b62fd5a88dc85181f0a821de0f0bde;hb=9811278f9e18ee6cb88470dbae98da046734a0af;hp=bb9ee8541fe758f334391c08084b025fe696703f;hpb=bdf1428136ce701e58a90f346973dbdf9d42b316;p=jalview.git diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index bb9ee85..6159757 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -20,13 +20,13 @@ */ package jalview.structures.models; +import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; -import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.api.StructureSelectionManagerProvider; import jalview.api.structures.JalviewStructureDisplayI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; @@ -54,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; @@ -95,6 +95,8 @@ public abstract class AAStructureBindingModel extends public String fileLoadingError; + private boolean showAlignmentOnly; + /** * Data bean class to simplify parameterisation in superposeStructures */ @@ -143,7 +145,6 @@ public abstract class AAStructureBindingModel extends * @param ssm * @param pdbentry * @param sequenceIs - * @param chains * @param protocol */ public AAStructureBindingModel(StructureSelectionManager ssm, @@ -155,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; @@ -301,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()][]); @@ -374,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)); @@ -533,7 +587,7 @@ public abstract class AAStructureBindingModel extends BitSet matched, SuperposeData[] structures) { int refStructure = -1; - String[] files = getPdbFile(); + String[] files = getStructureFiles(); if (files == null) { return -1; @@ -639,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; } @@ -658,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; } @@ -717,24 +769,13 @@ public abstract class AAStructureBindingModel extends * an array of corresponding hidden columns for each alignment * @return */ - public abstract String superposeStructures(AlignmentI[] alignments, int[] structureIndices, - ColumnSelection[] hiddenCols); + public abstract String superposeStructures(AlignmentI[] alignments, + int[] structureIndices, HiddenColumns[] hiddenCols); public abstract void setBackgroundColour(Color col); protected abstract StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, SequenceRenderer sr, FeatureRenderer fr, - AlignmentI alignment); - - /** - * returns the current featureRenderer that should be used to colour the - * structures - * - * @param alignment - * - * @return - */ - public abstract FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment); + String[] files, SequenceRenderer sr, AlignmentViewPanel avp); /** * returns the current sequenceRenderer that should be used to colour the @@ -744,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); @@ -754,35 +796,33 @@ 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) { - boolean showFeatures = alignmentv.getAlignViewport() - .isShowSequenceFeatures(); - if (!colourBySequence || !isLoadingFinished()) + if (!isLoadingFinished()) { return; } - if (getSsm() == null) + // todo: property change event for visibleAlignment + // to avoid unnecessary redraws here + if (!colourBySequence && !isShowAlignmentOnly()) { return; } - String[] files = getPdbFile(); - - SequenceRenderer sr = getSequenceRenderer(alignmentv); - - FeatureRenderer fr = null; - if (showFeatures) + if (getSsm() == null) { - fr = getFeatureRenderer(alignmentv); + return; } - AlignmentI alignment = alignmentv.getAlignment(); - + String[] files = getStructureFiles(); + + SequenceRenderer sr = getSequenceRenderer(alignmentv); + StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands( - files, sr, fr, alignment); + files, sr, alignmentv); colourBySequence(colourBySequenceCommands); } @@ -790,4 +830,56 @@ public abstract class AAStructureBindingModel extends { return fileLoadingError != null && fileLoadingError.length() > 0; } + + 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); + } + } }