From c47a2af3da1aa257ecbb870b421c761e4acb7630 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 6 Oct 2022 17:25:53 +0100 Subject: [PATCH] JAL-3895 alphafold colours via pluggable annotation row builder. Also ensures min/max set correctly --- .../annotations/AlphaFoldAnnotationRowBuilder.java | 38 ++++++++ .../annotations/AnnotationRowBuilder.java | 101 ++++++++++++++++++++ src/jalview/ext/jmol/JmolParser.java | 31 +++--- src/mc_view/PDBChain.java | 47 +++++---- 4 files changed, 184 insertions(+), 33 deletions(-) create mode 100644 src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java create mode 100644 src/jalview/datamodel/annotations/AnnotationRowBuilder.java diff --git a/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java b/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java new file mode 100644 index 0000000..60e6866 --- /dev/null +++ b/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java @@ -0,0 +1,38 @@ +package jalview.datamodel.annotations.AnnotationRowBuilder; + +import jalview.datamodel.Annotation; + +public class AlphaFoldAnnotationRowBuilder extends AnnotationRowBuilder +{ + public AlphaFoldAnnotationRowBuilder() + { + super("Alphafold Reliability"); + min = 0; + max = 100; + hasMinMax = true; + } + + @Override + public void processAnnotation(Annotation annotation) + { + if (annotation.value > 90) + { + // Very High + annotation.colour = new java.awt.Color(0, 83, 214); + } + if (annotation.value <= 90) + { + // High + annotation.colour = new java.awt.Color(101, 203, 243); + } + if (annotation.value <= 70) + { + // Confident + annotation.colour = new java.awt.Color(255, 219, 19); + } + if (annotation.value < 50) + { + annotation.colour = new java.awt.Color(255, 125, 69); + } + } +} \ No newline at end of file diff --git a/src/jalview/datamodel/annotations/AnnotationRowBuilder.java b/src/jalview/datamodel/annotations/AnnotationRowBuilder.java new file mode 100644 index 0000000..b802612 --- /dev/null +++ b/src/jalview/datamodel/annotations/AnnotationRowBuilder.java @@ -0,0 +1,101 @@ +package jalview.datamodel.annotations.AnnotationRowBuilder; + +import jalview.datamodel.Annotation; + +public class AnnotationRowBuilder +{ + + String name; + + boolean hasDescription = false; + + String description; + + boolean hasMinMax = false; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public boolean isHasDescription() + { + return hasDescription; + } + + public void setHasDescription(boolean hasDescription) + { + this.hasDescription = hasDescription; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public boolean isHasMinMax() + { + return hasMinMax; + } + + public void setHasMinMax(boolean hasMinMax) + { + this.hasMinMax = hasMinMax; + } + + public float getMin() + { + return min; + } + + public void setMin(float min) + { + this.min = min; + } + + public float getMax() + { + return max; + } + + public void setMax(float max) + { + this.max = max; + } + + float min, max; + + public AnnotationRowBuilder(String string) + { + name = string; + } + + public AnnotationRowBuilder(String name, float min, float max) + { + this(name); + this.min = min; + this.max = max; + this.hasMinMax = true; + } + + /** + * override this to apply some form of transformation to the annotation - eg a + * colourscheme + * + * @param annotation + */ + public void processAnnotation(Annotation annotation) + { + + } +} diff --git a/src/jalview/ext/jmol/JmolParser.java b/src/jalview/ext/jmol/JmolParser.java index ab6bbcc..05c3f7a 100644 --- a/src/jalview/ext/jmol/JmolParser.java +++ b/src/jalview/ext/jmol/JmolParser.java @@ -20,23 +20,11 @@ */ package jalview.ext.jmol; -import java.util.Locale; - -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.Annotation; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.io.DataSourceType; -import jalview.io.FileParse; -import jalview.io.StructureFile; -import jalview.schemes.ResidueProperties; -import jalview.util.Format; -import jalview.util.MessageManager; - import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Vector; @@ -49,6 +37,18 @@ import org.jmol.viewer.Viewer; import com.stevesoft.pat.Regex; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Annotation; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.datamodel.annotations.AnnotationRowBuilder.AlphaFoldAnnotationRowBuilder; +import jalview.datamodel.annotations.AnnotationRowBuilder.AnnotationRowBuilder; +import jalview.io.DataSourceType; +import jalview.io.FileParse; +import jalview.io.StructureFile; +import jalview.schemes.ResidueProperties; +import jalview.util.Format; +import jalview.util.MessageManager; import mc_view.Atom; import mc_view.PDBChain; import mc_view.Residue; @@ -238,13 +238,14 @@ public class JmolParser extends StructureFile implements JmolStatusListener } else { + AnnotationRowBuilder builder = null; String tempFString = null; if (isAlphafoldModel()) { - tempFString = "Alphafold Reliability"; + builder = new AlphaFoldAnnotationRowBuilder(); } - tmpchain = new PDBChain(getId(), tmpatom.chain, tempFString); + tmpchain = new PDBChain(getId(), tmpatom.chain, builder); getChains().add(tmpchain); tmpchain.atoms.addElement(tmpatom); } diff --git a/src/mc_view/PDBChain.java b/src/mc_view/PDBChain.java index 72d276e..d9e7ec9 100755 --- a/src/mc_view/PDBChain.java +++ b/src/mc_view/PDBChain.java @@ -20,6 +20,11 @@ */ package mc_view; +import java.awt.Color; +import java.util.List; +import java.util.Locale; +import java.util.Vector; + import jalview.analysis.AlignSeq; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -27,17 +32,13 @@ import jalview.datamodel.Mapping; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import jalview.datamodel.annotations.AnnotationRowBuilder.AnnotationRowBuilder; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; import jalview.structure.StructureImportSettings; import jalview.structure.StructureMapping; import jalview.util.Comparison; -import java.awt.Color; -import java.util.List; -import java.util.Locale; -import java.util.Vector; - public class PDBChain { public static final String RESNUM_FEATURE = "RESNUM"; @@ -79,17 +80,16 @@ public class PDBChain public String pdbid = ""; - String tfacName = "Temperature Factor"; + AnnotationRowBuilder tfacTemplate = new AnnotationRowBuilder( + "TemperatureFactor"); public PDBChain(String thePdbid, String theId, - String tempFactorColumnName) + AnnotationRowBuilder template) { - this.pdbid = thePdbid == null ? thePdbid - : thePdbid.toLowerCase(Locale.ROOT); - this.id = theId; - if (tempFactorColumnName != null && tempFactorColumnName.length() > 0) + this(thePdbid, theId); + if (template != null) { - tfacName = tempFactorColumnName; + tfacTemplate = template; } } @@ -102,7 +102,9 @@ public class PDBChain */ public PDBChain(String thePdbid, String theId) { - this(thePdbid, theId, null); + this.pdbid = thePdbid == null ? thePdbid + : thePdbid.toLowerCase(Locale.ROOT); + this.id = theId; } /** @@ -516,14 +518,23 @@ public class PDBChain for (int i = 0; i < iSize; i++) { annots[i] = resAnnotation.elementAt(i); + tfacTemplate.processAnnotation(annots[i]); max = Math.max(max, annots[i].value); min = Math.min(min, annots[i].value); resAnnotation.setElementAt(null, i); } - AlignmentAnnotation tfactorann = new AlignmentAnnotation(tfacName, - tfacName + " for " + pdbid + id, annots, min, max, - AlignmentAnnotation.LINE_GRAPH); + if (tfacTemplate.isHasMinMax()) + { + max = tfacTemplate.getMax(); + min = tfacTemplate.getMin(); + } + AlignmentAnnotation tfactorann = new AlignmentAnnotation( + tfacTemplate.getName(), + (tfacTemplate.isHasDescription() + ? tfacTemplate.getDescription() + : tfacTemplate.getName()) + " for " + pdbid + id, + annots, min, max, AlignmentAnnotation.LINE_GRAPH); tfactorann.setCalcId(getClass().getName()); tfactorann.setSequenceRef(sequence); @@ -694,8 +705,8 @@ public class PDBChain // Useful for debugging mappings - adds annotation for mapped position float min = -1, max = 0; Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1]; - for (int i = sq.getStart(), j = sq - .getEnd(), k = 0; i <= j; i++, k++) + for (int i = sq.getStart(), j = sq.getEnd(), + k = 0; i <= j; i++, k++) { int prn = mapping.getPDBResNum(k + 1); -- 1.7.10.2