From: Ben Soares Date: Wed, 11 Jan 2023 11:55:14 +0000 (+0000) Subject: JAL-629 refactoring TFType. Remove i18n identification of annotation. X-Git-Tag: Release_2_11_4_0~502 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=34ce5193c8766085422c32544246d92f12d0c975;p=jalview.git JAL-629 refactoring TFType. Remove i18n identification of annotation. --- diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 2a71e74..c08dd23 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -16,7 +16,9 @@ import jalview.bin.ArgParser.Arg; import jalview.bin.ArgParser.ArgValues; import jalview.bin.ArgParser.SubVal; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; +import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder; import jalview.gui.AlignFrame; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; @@ -28,6 +30,8 @@ import jalview.io.FileFormatI; import jalview.io.FileLoader; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; +import jalview.structure.StructureImportSettings; +import jalview.structure.StructureImportSettings.TFType; import jalview.util.HttpUtils; import jalview.util.MessageManager; import jalview.util.Platform; @@ -187,13 +191,13 @@ public class Commands */ // get kind of temperature factor annotation - AlignmentAnnotation.TFType tempfacType = null; + StructureImportSettings.TFType tempfacType = TFType.DEFAULT; if ((!ArgParser.getBoolean(m, Arg.NOTEMPFAC)) && ArgParser.getArgValues(m, Arg.TEMPFAC) != null) { try { - tempfacType = AlignmentAnnotation.TFType.valueOf(ArgParser + tempfacType = StructureImportSettings.TFType.valueOf(ArgParser .getValue(m, Arg.TEMPFAC).toUpperCase(Locale.ROOT)); Console.debug("Obtained Temperature Factor type of '" + tempfacType + "'"); @@ -204,8 +208,8 @@ public class Commands .append(Arg.TEMPFAC.getName()).append(" to '") .append(tempfacType) .append("', ignoring. Valid values are: "); - Iterator it = Arrays - .stream(AlignmentAnnotation.TFType.values()) + Iterator it = Arrays + .stream(StructureImportSettings.TFType.values()) .iterator(); while (it.hasNext()) { @@ -220,8 +224,11 @@ public class Commands Console.debug( "Opening '" + openFile + "' in new alignment frame"); FileLoader fileLoader = new FileLoader(!headless); - af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, format, - tempfacType); + + StructureImportSettings.setTemperatureFactorType(tempfacType); + + af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, + format); // wrap alignment? if (ArgParser.getBoolean(m, Arg.WRAP)) @@ -250,8 +257,7 @@ public class Commands // do this better (annotation types?) List hideThese = new ArrayList<>(); hideThese.add("Temperature Factor"); - hideThese.add(MessageManager - .getString("label.alphafold_reliability")); + hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL); AlignmentUtils.showOrHideSequenceAnnotations( af.getCurrentView().getAlignment(), hideThese, null, false, false); @@ -322,11 +328,20 @@ public class Commands { SubVal subVal = ArgParser.getSubVal(val); File paeFile = new File(subVal.content); - EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), - paeFile, subVal.index, - "id".equals(subVal.keyName) ? subVal.keyValue : null); - // required to readjust the height and position of the pAE - // annotation + if ("structid".equals(subVal.index)) + { + EBIAlfaFold.addAlphaFoldPAEToStructure( + af.getCurrentView().getAlignment(), paeFile, + subVal.index, subVal.keyValue); + } + else + { + EBIAlfaFold.addAlphaFoldPAEToSequence(af.getCurrentView().getAlignment(), + paeFile, subVal.index, + "id".equals(subVal.keyName) ? subVal.keyValue : null); + // required to readjust the height and position of the pAE + // annotation + } for (AlignmentViewPanel ap : af.getAlignPanels()) { ap.adjustAnnotationHeight(); @@ -429,15 +444,21 @@ public class Commands switch (type) { case "svg": + Console.debug("Outputting type '" + type + "' to " + fileName); af.createSVG(file); break; case "png": + Console.debug("Outputting type '" + type + "' to " + fileName); af.createPNG(file); break; case "html": + Console.debug("Outputting type '" + type + "' to " + fileName); HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel); htmlSVG.exportHTML(fileName); break; + default: + Console.warn("--image type '" + type + "' not known. Ignoring"); + break; } } } @@ -445,24 +466,15 @@ public class Commands private SequenceI getSpecifiedSequence(AlignFrame af, SubVal subId) { - SequenceI seq = null; - SequenceI[] sequences = af.getCurrentView().getAlignment() - .getSequencesArray(); - if (-1 < subId.index && subId.index < sequences.length) + AlignmentI al = af.getCurrentView().getAlignment(); + if (-1 < subId.index && subId.index < al.getSequences().size()) { - seq = sequences[subId.index]; + return al.getSequenceAt(subId.index); } else if ("id".equals(subId.keyName)) { - for (SequenceI s : sequences) - { - if (s.getDisplayId(false).equals(subId.keyValue)) - { - seq = s; - break; - } - } + return al.findName(subId.keyValue); } - return seq; + return null; } } diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 636088b..3f9c2d9 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -34,6 +34,7 @@ import java.util.Map.Entry; import jalview.analysis.Rna; import jalview.analysis.SecStrConsensus.SimpleBP; import jalview.analysis.WUSSParseException; +import jalview.structure.StructureImportSettings; /** * DOCUMENT ME! @@ -96,22 +97,17 @@ public class AlignmentAnnotation */ private long invalidrnastruc = -2; - public static enum TFType - { - DEFAULT, PLDDT, DOSE; - } - /** * the type of temperature factor plot (if it is one) */ - private TFType tfType = TFType.DEFAULT; + private StructureImportSettings.TFType tfType = StructureImportSettings.TFType.DEFAULT; - public void setTFType(TFType t) + public void setTFType(StructureImportSettings.TFType t) { tfType = t; } - public TFType getTFType() + public StructureImportSettings.TFType getTFType() { return tfType; } diff --git a/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java b/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java index fa48968..4e9553e 100644 --- a/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java +++ b/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java @@ -1,18 +1,20 @@ package jalview.datamodel.annotations; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.Annotation; -import jalview.util.MessageManager; +import jalview.structure.StructureImportSettings; +import jalview.structure.StructureImportSettings.TFType; public class AlphaFoldAnnotationRowBuilder extends AnnotationRowBuilder { + public static final String LABEL = "Alphafold Reliability"; + public AlphaFoldAnnotationRowBuilder() { - super(MessageManager.getString("label.alphafold_reliability")); + super(LABEL); min = 0; max = 100; hasMinMax = true; - this.setTFType(TFType.PLDDT); + this.setTFType(StructureImportSettings.TFType.PLDDT); } @Override diff --git a/src/jalview/datamodel/annotations/AnnotationRowBuilder.java b/src/jalview/datamodel/annotations/AnnotationRowBuilder.java index 573b1a9..b3d567a 100644 --- a/src/jalview/datamodel/annotations/AnnotationRowBuilder.java +++ b/src/jalview/datamodel/annotations/AnnotationRowBuilder.java @@ -1,7 +1,8 @@ package jalview.datamodel.annotations; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.Annotation; +import jalview.structure.StructureImportSettings; +import jalview.structure.StructureImportSettings.TFType; public class AnnotationRowBuilder { @@ -17,14 +18,14 @@ public class AnnotationRowBuilder /** * the type of temperature factor plot (if it is one) */ - private TFType tfType = TFType.DEFAULT; + private StructureImportSettings.TFType tfType = StructureImportSettings.TFType.DEFAULT; - public void setTFType(TFType t) + public void setTFType(StructureImportSettings.TFType t) { tfType = t; } - public TFType getTFType() + public StructureImportSettings.TFType getTFType() { return tfType; } @@ -96,7 +97,7 @@ public class AnnotationRowBuilder name = string; } - public AnnotationRowBuilder(String name, float min, float max, TFType tft) + public AnnotationRowBuilder(String name, float min, float max, StructureImportSettings.TFType tft) { this(name, min, max); setTFType(tft); diff --git a/src/jalview/ext/jmol/JmolParser.java b/src/jalview/ext/jmol/JmolParser.java index 9306388..37b3d68 100644 --- a/src/jalview/ext/jmol/JmolParser.java +++ b/src/jalview/ext/jmol/JmolParser.java @@ -40,7 +40,6 @@ import com.stevesoft.pat.Regex; import jalview.bin.Console; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.Annotation; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; @@ -50,6 +49,7 @@ import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.StructureFile; import jalview.schemes.ResidueProperties; +import jalview.structure.StructureImportSettings; import jalview.util.Format; import jalview.util.MessageManager; import jalview.ws.dbsources.EBIAlfaFold; @@ -84,7 +84,7 @@ public class JmolParser extends StructureFile implements JmolStatusListener } public JmolParser(Object inFile, DataSourceType sourceType, - AlignmentAnnotation.TFType tempfacType) throws IOException + StructureImportSettings.TFType tempfacType) throws IOException { super(inFile, sourceType, tempfacType); } @@ -251,8 +251,8 @@ public class JmolParser extends StructureFile implements JmolStatusListener { AnnotationRowBuilder builder = null; String tempFString = null; - if (isAlphafoldModel() - || this.getTemperatureFactorType() == AlignmentAnnotation.TFType.PLDDT) + if (isAlphafoldModel() || this + .getTemperatureFactorType() == StructureImportSettings.TFType.PLDDT) { builder = new AlphaFoldAnnotationRowBuilder(); } @@ -321,6 +321,11 @@ public class JmolParser extends StructureFile implements JmolStatusListener } } + public void setAlphafoldModel(boolean afm) + { + alphaFoldModel = afm; + } + private boolean isAlphafoldModel() { return alphaFoldModel; diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 889d72e..3202ac9 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Vector; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; @@ -82,13 +81,6 @@ public abstract class AlignFile extends FileParse private boolean dataClosed = false; - private AlignmentAnnotation.TFType temperatureFactorType = null; - - public AlignmentAnnotation.TFType getTemperatureFactorType() - { - return this.temperatureFactorType; - } - /** * @return if doParse() was called at construction time */ @@ -125,13 +117,7 @@ public abstract class AlignFile extends FileParse public AlignFile(Object dataObject, DataSourceType sourceType) throws IOException { - this(dataObject, sourceType, null); - } - - public AlignFile(Object dataObject, DataSourceType sourceType, - AlignmentAnnotation.TFType tempfacType) throws IOException - { - this(true, dataObject, sourceType, tempfacType); + this(true, dataObject, sourceType); } /** @@ -149,16 +135,9 @@ public abstract class AlignFile extends FileParse public AlignFile(boolean parseImmediately, Object dataObject, DataSourceType sourceType) throws IOException { - this(parseImmediately, dataObject, sourceType, null); - } - - public AlignFile(boolean parseImmediately, Object dataObject, - DataSourceType sourceType, AlignmentAnnotation.TFType tempfacType) throws IOException - { // BH allows File or String super(dataObject, sourceType); initData(); - this.temperatureFactorType = tempfacType; if (parseImmediately) { doParse(); diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 8b1525c..60eb9cc 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -30,13 +30,13 @@ import jalview.api.AlignExportSettingsI; import jalview.api.AlignmentViewPanel; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; +import jalview.structure.StructureImportSettings.TFType; import jalview.util.Platform; /** @@ -164,7 +164,7 @@ public class AppletFormatAdapter public AlignmentI readFile(File selectedFile, String file, DataSourceType sourceType, FileFormatI fileFormat, - AlignmentAnnotation.TFType tempfacType) throws IOException + StructureImportSettings.TFType tempfacType) throws IOException { this.selectedFile = selectedFile; diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index c7ade20..d3ac53f 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -33,8 +33,6 @@ import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; import jalview.bin.Cache; import jalview.bin.Jalview; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; @@ -75,8 +73,6 @@ public class FileLoader implements Runnable private File selectedFile; - private AlignmentAnnotation.TFType temperatureFactorType = null; - /** * default constructor always raised errors in GUI dialog boxes */ @@ -162,26 +158,9 @@ public class FileLoader implements Runnable public AlignFrame LoadFileWaitTillLoaded(String file, DataSourceType sourceType, FileFormatI format) { - return LoadFileWaitTillLoaded(file, sourceType, format, null); - } - - /** - * Load alignment from (file, protocol) of type format with specified - * temperature factor type and wait till loaded - * - * @param file - * @param sourceType - * @param format - * @param tempfacType - * @return alignFrame constructed from file contents - */ - public AlignFrame LoadFileWaitTillLoaded(String file, - DataSourceType sourceType, FileFormatI format, AlignmentAnnotation.TFType tempfacType) - { this.file = file; this.protocol = sourceType; this.format = format; - this.temperatureFactorType = tempfacType; return _LoadFileWaitTillLoaded(); } @@ -400,14 +379,12 @@ public class FileLoader implements Runnable { if (selectedFile == null) { - al = fa.readFile(null, file, protocol, format, - temperatureFactorType); + al = fa.readFile(null, file, protocol, format); } else { - al = fa.readFile(selectedFile, null, protocol, format, - temperatureFactorType); + al = fa.readFile(selectedFile, null, protocol, format); } source = fa.getAlignFile(); // keep reference for later if diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 0ca2b50..d6e6767 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -29,12 +29,13 @@ import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.structure.StructureImportSettings; +import jalview.structure.StructureImportSettings.TFType; import jalview.util.Comparison; /** @@ -230,7 +231,7 @@ public class FormatAdapter extends AppletFormatAdapter @Override public AlignmentI readFile(File selectedFile, String file, DataSourceType sourceType, FileFormatI fileFormat, - AlignmentAnnotation.TFType tempfacType) throws IOException + StructureImportSettings.TFType tempfacType) throws IOException { AlignmentI al = super.readFile(selectedFile, file, sourceType, fileFormat, tempfacType); diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index c816f6d..7ecbc2d 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -30,7 +30,6 @@ import jalview.analysis.AlignSeq; import jalview.api.FeatureSettingsModelI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; @@ -38,6 +37,7 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.structure.StructureImportSettings; +import jalview.structure.StructureImportSettings.TFType; import mc_view.PDBChain; public abstract class StructureFile extends AlignFile @@ -68,6 +68,18 @@ public abstract class StructureFile extends AlignFile private boolean pdbIdAvailable; + private StructureImportSettings.TFType temperatureFactorType = TFType.DEFAULT; + + public void setTemperatureFactorType(StructureImportSettings.TFType t) + { + this.temperatureFactorType = t; + } + + public StructureImportSettings.TFType getTemperatureFactorType() + { + return temperatureFactorType; + } + public StructureFile(Object inFile, DataSourceType sourceType) throws IOException { @@ -75,9 +87,10 @@ public abstract class StructureFile extends AlignFile } public StructureFile(Object inFile, DataSourceType sourceType, - AlignmentAnnotation.TFType tempfacType) throws IOException + StructureImportSettings.TFType tempfacType) throws IOException { - super(inFile, sourceType, tempfacType); + super(inFile, sourceType); + this.setTemperatureFactorType(tempfacType); } public StructureFile(FileParse fp) throws IOException @@ -101,7 +114,8 @@ public abstract class StructureFile extends AlignFile .isProcessSecondaryStructure(); this.externalSecondaryStructure = StructureImportSettings .isExternalSecondaryStructure(); - + this.temperatureFactorType = StructureImportSettings + .getTemperatureFactorType(); } public StructureFile(boolean parseImmediately, Object dataObject, diff --git a/src/jalview/structure/StructureImportSettings.java b/src/jalview/structure/StructureImportSettings.java index cbd59b1..597338e 100644 --- a/src/jalview/structure/StructureImportSettings.java +++ b/src/jalview/structure/StructureImportSettings.java @@ -59,6 +59,11 @@ public class StructureImportSettings JMOL_PARSER, JALVIEW_PARSER } + public static enum TFType + { + DEFAULT, PLDDT, DOSE; + } + /** * Determines the default file format for structure files to be downloaded * from the PDB sequence fetcher. Possible options include: PDB|mmCIF @@ -71,6 +76,8 @@ public class StructureImportSettings */ private static StructureParser defaultPDBFileParser = StructureParser.JMOL_PARSER; + private static TFType temperatureFactorType; + public static void addSettings(boolean addAlignmentAnnotations, boolean processSecStr, boolean externalSecStr) { @@ -85,6 +92,11 @@ public class StructureImportSettings return visibleChainAnnotation; } + public static void setTemperatureFactorType(TFType t) + { + StructureImportSettings.temperatureFactorType = t; + } + public static void setVisibleChainAnnotation( boolean visibleChainAnnotation) { @@ -152,4 +164,9 @@ public class StructureImportSettings .valueOf(defaultPDBFileParser.toUpperCase(Locale.ROOT)); } + public static TFType getTemperatureFactorType() + { + return temperatureFactorType; + } + } diff --git a/src/jalview/ws/dbsources/EBIAlfaFold.java b/src/jalview/ws/dbsources/EBIAlfaFold.java index 5575cb8..859ac05 100644 --- a/src/jalview/ws/dbsources/EBIAlfaFold.java +++ b/src/jalview/ws/dbsources/EBIAlfaFold.java @@ -43,11 +43,13 @@ import jalview.datamodel.DBRefEntry; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import jalview.gui.Desktop; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import jalview.io.PDBFeatureSettings; +import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.datamodel.alphafold.PAEContactMatrix; @@ -249,11 +251,11 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy Console.debug("Downloading pae from " + paeURL + " to " + pae.toString() + ""); UrlDownloadClient.download(paeURL, pae); - addAlphaFoldPAE(pdbAlignment, pae, 0, null); + addAlphaFoldPAEToSequence(pdbAlignment, pae, 0, null); } - public static void addAlphaFoldPAE(AlignmentI pdbAlignment, File pae, - int index, String seqId) + public static void addAlphaFoldPAEToSequence(AlignmentI pdbAlignment, + File pae, int index, String seqId) { FileInputStream pae_input = null; try @@ -286,6 +288,21 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy } + public static void addAlphaFoldPAEToStructure(AlignmentI pdbAlignment, + File pae, int index, String structId) + { + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(Desktop.instance); + if (ssm != null) + { + /* + ssm.setAddTempFacAnnot(showTemperatureFactor); + ssm.setProcessSecondaryStructure(showSecondaryStructure); + */ + } + + } + /** * parses the given pAE matrix and adds it to sequence 0 in the given * alignment @@ -336,7 +353,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy Console.debug("***** Got sequence at index " + seqToGet + ": " + (sequence == null ? null : sequence.getName())); } - else + if (sequence == null) { Console.debug("***** Looking for sequence with id '" + seqId + "'");