From 892e857760e779796e156b4fa36d97d8d31e73e1 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 5 Dec 2022 09:32:24 +0000 Subject: [PATCH] JAL-629 implementation of --tempfac options --- resources/lang/Messages.properties | 1 + resources/lang/Messages_es.properties | 2 +- src/jalview/analysis/AlignmentUtils.java | 19 +++- src/jalview/bin/ArgParser.java | 4 +- src/jalview/bin/Commands.java | 96 ++++++++++++++++++-- src/jalview/datamodel/AlignmentAnnotation.java | 33 +++++-- .../annotations/AlphaFoldAnnotationRowBuilder.java | 5 +- .../annotations/AnnotationRowBuilder.java | 22 +++++ src/jalview/ext/jmol/JmolParser.java | 13 ++- src/jalview/io/AlignFile.java | 23 ++++- src/jalview/io/AppletFormatAdapter.java | 21 +++-- src/jalview/io/FeaturesFile.java | 3 +- src/jalview/io/FileLoader.java | 28 +++++- src/jalview/io/FormatAdapter.java | 16 +++- src/jalview/io/StructureFile.java | 22 +++-- .../ws/datamodel/alphafold/PAEContactMatrix.java | 2 - src/jalview/ws/dbsources/EBIAlfaFold.java | 52 +++++++++-- src/mc_view/PDBChain.java | 1 + src/mc_view/PDBfile.java | 16 ++-- 19 files changed, 316 insertions(+), 63 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 30a154d..7f6e9a5 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1426,3 +1426,4 @@ label.memory_example_text = Maximum memory that would be used with these setting label.memory_example_tooltip = The memory allocated to Jalview is the smaller of the percentage of physical memory (default 90%) and the maximum absolute memory (default 32GB). If your computer's memory cannot be ascertained then the maximum absolute memory defaults to 8GB (if not customised).
Jalview will always try and reserve 512MB for the OS and at least 512MB for itself. warning.wrong_jvm_version_title = Wrong Java Version warning.wrong_jvm_version_message = The Java version being used (Java {0}) may lead to problems.\nThis installation of Jalview should be used with Java {1}. +label.alphafold_reliability = Alphafold Reliability diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index d0bfd65..13eb15e 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1411,4 +1411,4 @@ label.memory_example_text = Memoria m label.memory_example_tooltip = La memoria asignada a Jalview es el menor entre el porcentaje de memoria física (predeterminado 90%) y la memoria absoluta máxima (predeterminado 32 GB). Si no se puede determinar la memoria de su computadora, la memoria absoluta máxima predeterminada es de 8 GB (si no está personalizada).
Jalview siempre intentará reservar 512 MB para el sistema operativo y al menos 512 MB para sí mismo. warning.wrong_jvm_version_title = Versión incorrecta de Java warning.wrong_jvm_version_message = La versión de Java que se está utilizando (Java {0}) puede generar problemas.\nEsta instalación de Jalview debe usarse con Java {1}. - +label.alphafold_reliability = Fiabilidad Alphafold diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index a1a7fef..42c4b76 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -184,10 +184,10 @@ public class AlignmentUtils // TODO use Character.toLowerCase to avoid creating String objects? char[] upstream = new String(ds .getSequence(s.getStart() - 1 - ustream_ds, s.getStart() - 1)) - .toLowerCase(Locale.ROOT).toCharArray(); + .toLowerCase(Locale.ROOT).toCharArray(); char[] downstream = new String( ds.getSequence(s_end - 1, s_end + dstream_ds)) - .toLowerCase(Locale.ROOT).toCharArray(); + .toLowerCase(Locale.ROOT).toCharArray(); char[] coreseq = s.getSequence(); char[] nseq = new char[offset + upstream.length + downstream.length + coreseq.length]; @@ -1581,6 +1581,21 @@ public class AlignmentUtils } } + public static AlignmentAnnotation getFirstSequenceAnnotationOfType( + AlignmentI al, int graphType) + { + AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); + if (anns != null) + { + for (AlignmentAnnotation aa : anns) + { + if (aa.sequenceRef != null && aa.graph == graphType) + return aa; + } + } + return null; + } + /** * Returns true if either sequence has a cross-reference to the other * diff --git a/src/jalview/bin/ArgParser.java b/src/jalview/bin/ArgParser.java index be65a9b..bcd4498 100644 --- a/src/jalview/bin/ArgParser.java +++ b/src/jalview/bin/ArgParser.java @@ -58,7 +58,7 @@ public class ArgParser ANNOTATION2, DISPLAY, GUI, NEWS, NOQUESTIONNAIRE, SORTBYTREE, USAGESTATS, OPEN, OPEN2, PROPS, QUESTIONNAIRE, SETPROP, TREE, VDOC, VSESS, OUTPUT, OUTPUTTYPE, SSANNOTATION, NOTEMPFAC, TEMPFAC, - TEMPFAC_LABEL, TEMPFAC_DESC, TEMPFAC_SHADING, TITLE; + TEMPFAC_LABEL, TEMPFAC_DESC, TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP; static { @@ -104,6 +104,8 @@ public class ArgParser TEMPFAC_DESC.setOptions(Opt.STRING, Opt.LINKED); TEMPFAC_SHADING.setOptions(Opt.STRING, Opt.LINKED); TITLE.setOptions(Opt.STRING, Opt.LINKED); + PAEMATRIX.setOptions(Opt.STRING, Opt.LINKED); + WRAP.setOptions(Opt.BOOLEAN, Opt.LINKED); } private final String[] argNames; diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 420e1d1..4ff82aa 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -1,13 +1,19 @@ package jalview.bin; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; import java.util.Map; import jalview.analysis.AlignmentUtils; import jalview.bin.ArgParser.Arg; import jalview.bin.ArgParser.ArgValues; +import jalview.datamodel.AlignmentAnnotation; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.io.AppletFormatAdapter; @@ -19,6 +25,7 @@ import jalview.io.IdentifyFile; import jalview.util.HttpUtils; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.ws.dbsources.EBIAlfaFold; public class Commands { @@ -67,7 +74,6 @@ public class Commands protected void processLinked(String id) { Map m = argParser.linkedArgs(id); - FileLoader fileLoader = new FileLoader(!headless); /* // script to execute after all loading is completed one way or another @@ -90,7 +96,6 @@ public class Commands { if (openFile == null) continue OPEN; - Console.debug("********** id = " + id + ", openFile = " + openFile); if (first) { @@ -136,12 +141,55 @@ public class Commands af = afMap.get(id); if (af == null) { + // get kind of temperature factor annotation + AlignmentAnnotation.TFType tempfacType = null; + if ((m.get(Arg.NOTEMPFAC) == null + || !m.get(Arg.NOTEMPFAC).getBoolean()) + && m.get(Arg.TEMPFAC) != null) + { + try + { + tempfacType = AlignmentAnnotation.TFType + .valueOf(m.get(Arg.TEMPFAC).getValue() + .toUpperCase(Locale.ROOT)); + Console.debug("Obtained Temperature Factor type of '" + + tempfacType + "'"); + } catch (IllegalArgumentException e) + { + StringBuilder sb = new StringBuilder().append("Cannot set --") + .append(Arg.TEMPFAC.getName()).append(" to '") + .append(tempfacType) + .append("', ignoring. Valid values are: "); + Iterator it = Arrays + .stream(AlignmentAnnotation.TFType.values()) + .iterator(); + while (it.hasNext()) + { + sb.append(it.next().toString().toLowerCase(Locale.ROOT)); + if (it.hasNext()) + sb.append(", "); + } + Console.warn(sb.toString()); + } + } + Console.debug( "Opening '" + openFile + "' in new alignment frame"); - af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, - format); + FileLoader fileLoader = new FileLoader(!headless); + af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, format, + tempfacType); + + // wrap alignment? + if (m.get(Arg.WRAP) != null && m.get(Arg.WRAP).getBoolean()) + { + af.getCurrentView().setWrapAlignment(true); + } + + // change alignment frame title if (m.get(Arg.TITLE) != null) af.setTitle(m.get(Arg.TITLE).getValue()); + + // show secondary structure annotations? if (m.get(Arg.SSANNOTATION) != null && !m.get(Arg.SSANNOTATION).getBoolean()) { @@ -151,19 +199,47 @@ public class Commands Collections.singleton("Secondary Structure"), null, false, false); } + + // show temperature factor annotations? if (m.get(Arg.NOTEMPFAC) != null && m.get(Arg.NOTEMPFAC).getBoolean()) { // do this better (annotation types?) + List hideThese = new ArrayList<>(); + hideThese.add("Temperature Factor"); + hideThese.add(MessageManager + .getString("label.alphafold_reliability")); AlignmentUtils.showOrHideSequenceAnnotations( - af.getCurrentView().getAlignment(), - Collections.singleton("Temperature Factor"), null, - false, false); - AlignmentUtils.showOrHideSequenceAnnotations( - af.getCurrentView().getAlignment(), - Collections.singleton("Alphafold Reliability"), null, + af.getCurrentView().getAlignment(), hideThese, null, false, false); } + else + { + if (m.get(Arg.TEMPFAC_LABEL) != null) + { + AlignmentAnnotation aa = AlignmentUtils + .getFirstSequenceAnnotationOfType( + af.getCurrentView().getAlignment(), + AlignmentAnnotation.LINE_GRAPH); + Console.debug("***** Trying to change label from '" + + (aa == null ? aa : aa.label) + "' to '" + + m.get(Arg.TEMPFAC_LABEL).getValue() + "'"); + if (aa != null) + { + aa.label = m.get(Arg.TEMPFAC_LABEL).getValue(); + } + } + } + + // + + // load a pAE file? + if (m.get(Arg.PAEMATRIX) != null) + { + File paeFile = new File(m.get(Arg.PAEMATRIX).getValue()); + EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), + paeFile); + } // store the AlignFrame for this id afMap.put(id, af); diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index b6e48dc..636088b 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -43,6 +43,7 @@ import jalview.analysis.WUSSParseException; */ public class AlignmentAnnotation { + private static final String ANNOTATION_ID_PREFIX = "ann"; /* @@ -95,6 +96,26 @@ 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; + + public void setTFType(TFType t) + { + tfType = t; + } + + public TFType getTFType() + { + return tfType; + } + /** * Updates the _rnasecstr field Determines the positions that base pair and * the positions of helices based on secondary structure from a Stockholm file @@ -551,12 +572,12 @@ public class AlignmentAnnotation : annotations[index + offset].displayCharacter == null || annotations[index + offset].displayCharacter - .length() == 0 - ? annotations[index - + offset].secondaryStructure - : annotations[index - + offset].displayCharacter - .charAt(0)); + .length() == 0 + ? annotations[index + + offset].secondaryStructure + : annotations[index + + offset].displayCharacter + .charAt(0)); } @Override diff --git a/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java b/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java index a0befe0..fa48968 100644 --- a/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java +++ b/src/jalview/datamodel/annotations/AlphaFoldAnnotationRowBuilder.java @@ -1,15 +1,18 @@ package jalview.datamodel.annotations; +import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.Annotation; +import jalview.util.MessageManager; public class AlphaFoldAnnotationRowBuilder extends AnnotationRowBuilder { public AlphaFoldAnnotationRowBuilder() { - super("Alphafold Reliability"); + super(MessageManager.getString("label.alphafold_reliability")); min = 0; max = 100; hasMinMax = true; + this.setTFType(TFType.PLDDT); } @Override diff --git a/src/jalview/datamodel/annotations/AnnotationRowBuilder.java b/src/jalview/datamodel/annotations/AnnotationRowBuilder.java index 15f83e9..573b1a9 100644 --- a/src/jalview/datamodel/annotations/AnnotationRowBuilder.java +++ b/src/jalview/datamodel/annotations/AnnotationRowBuilder.java @@ -1,5 +1,6 @@ package jalview.datamodel.annotations; +import jalview.datamodel.AlignmentAnnotation.TFType; import jalview.datamodel.Annotation; public class AnnotationRowBuilder @@ -13,6 +14,21 @@ public class AnnotationRowBuilder boolean hasMinMax = false; + /** + * the type of temperature factor plot (if it is one) + */ + private TFType tfType = TFType.DEFAULT; + + public void setTFType(TFType t) + { + tfType = t; + } + + public TFType getTFType() + { + return tfType; + } + public String getName() { return name; @@ -80,6 +96,12 @@ public class AnnotationRowBuilder name = string; } + public AnnotationRowBuilder(String name, float min, float max, TFType tft) + { + this(name, min, max); + setTFType(tft); + } + public AnnotationRowBuilder(String name, float min, float max) { this(name); diff --git a/src/jalview/ext/jmol/JmolParser.java b/src/jalview/ext/jmol/JmolParser.java index 269fc31..9306388 100644 --- a/src/jalview/ext/jmol/JmolParser.java +++ b/src/jalview/ext/jmol/JmolParser.java @@ -40,6 +40,7 @@ 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; @@ -73,12 +74,19 @@ public class JmolParser extends StructureFile implements JmolStatusListener { // BH 2018 File or String for filename super(immediate, inFile, sourceType); + } public JmolParser(Object inFile, DataSourceType sourceType) throws IOException { - super(inFile, sourceType); + this(inFile, sourceType, null); + } + + public JmolParser(Object inFile, DataSourceType sourceType, + AlignmentAnnotation.TFType tempfacType) throws IOException + { + super(inFile, sourceType, tempfacType); } public JmolParser(FileParse fp) throws IOException @@ -243,7 +251,8 @@ public class JmolParser extends StructureFile implements JmolStatusListener { AnnotationRowBuilder builder = null; String tempFString = null; - if (isAlphafoldModel()) + if (isAlphafoldModel() + || this.getTemperatureFactorType() == AlignmentAnnotation.TFType.PLDDT) { builder = new AlphaFoldAnnotationRowBuilder(); } diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 3202ac9..889d72e 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -28,6 +28,7 @@ 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; @@ -81,6 +82,13 @@ 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 */ @@ -117,7 +125,13 @@ public abstract class AlignFile extends FileParse public AlignFile(Object dataObject, DataSourceType sourceType) throws IOException { - this(true, dataObject, sourceType); + this(dataObject, sourceType, null); + } + + public AlignFile(Object dataObject, DataSourceType sourceType, + AlignmentAnnotation.TFType tempfacType) throws IOException + { + this(true, dataObject, sourceType, tempfacType); } /** @@ -135,9 +149,16 @@ 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 5de14a4..8b1525c 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -20,26 +20,25 @@ */ package jalview.io; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; import java.util.Locale; 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.SeqDistanceContactMatrix; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; import jalview.util.Platform; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - /** * A low level class for alignment and feature IO with alignment formatting * methods used by both applet and application for generating flat alignment @@ -160,6 +159,13 @@ public class AppletFormatAdapter DataSourceType sourceType, FileFormatI fileFormat) throws IOException { + return readFile(selectedFile, file, sourceType, fileFormat, null); + } + + public AlignmentI readFile(File selectedFile, String file, + DataSourceType sourceType, FileFormatI fileFormat, + AlignmentAnnotation.TFType tempfacType) throws IOException + { this.selectedFile = selectedFile; if (selectedFile != null) @@ -182,7 +188,8 @@ public class AppletFormatAdapter { // needs a File option alignFile = new JmolParser( - selectedFile == null ? inFile : selectedFile, sourceType); + selectedFile == null ? inFile : selectedFile, sourceType, + tempfacType); } else { diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index 745bce3..6332561 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -20,8 +20,6 @@ */ package jalview.io; -import java.util.Locale; - import java.awt.Color; import java.io.IOException; import java.util.ArrayList; @@ -30,6 +28,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 4016e71..c7ade20 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -33,6 +33,8 @@ 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; @@ -73,6 +75,8 @@ public class FileLoader implements Runnable private File selectedFile; + private AlignmentAnnotation.TFType temperatureFactorType = null; + /** * default constructor always raised errors in GUI dialog boxes */ @@ -158,9 +162,26 @@ 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(); } @@ -272,6 +293,7 @@ public class FileLoader implements Runnable ? "Copied From Clipboard" : file; Runtime rt = Runtime.getRuntime(); + try { if (Desktop.instance != null) @@ -378,12 +400,14 @@ public class FileLoader implements Runnable { if (selectedFile == null) { - al = fa.readFile(file, protocol, format); + al = fa.readFile(null, file, protocol, format, + temperatureFactorType); } else { - al = fa.readFile(selectedFile, protocol, format); + al = fa.readFile(selectedFile, null, protocol, format, + temperatureFactorType); } source = fa.getAlignFile(); // keep reference for later if diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 735619f..0ca2b50 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -20,6 +20,8 @@ */ package jalview.io; +import java.io.File; +import java.io.IOException; import java.util.Locale; import jalview.api.AlignExportSettingsI; @@ -27,6 +29,7 @@ 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; @@ -34,9 +37,6 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.Comparison; -import java.io.File; -import java.io.IOException; - /** * Additional formatting methods used by the application in a number of places. * @@ -228,6 +228,16 @@ public class FormatAdapter extends AppletFormatAdapter } @Override + public AlignmentI readFile(File selectedFile, String file, + DataSourceType sourceType, FileFormatI fileFormat, + AlignmentAnnotation.TFType tempfacType) throws IOException + { + AlignmentI al = super.readFile(selectedFile, file, sourceType, + fileFormat, tempfacType); + return al; + } + + @Override public AlignmentI readFile(String file, DataSourceType sourceType, FileFormatI fileFormat) throws IOException { diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index 6b623a1..c816f6d 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -20,10 +20,17 @@ */ package jalview.io; +import java.awt.Color; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.List; +import java.util.Vector; + 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; @@ -31,13 +38,6 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.structure.StructureImportSettings; - -import java.awt.Color; -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.util.List; -import java.util.Vector; - import mc_view.PDBChain; public abstract class StructureFile extends AlignFile @@ -71,7 +71,13 @@ public abstract class StructureFile extends AlignFile public StructureFile(Object inFile, DataSourceType sourceType) throws IOException { - super(inFile, sourceType); + this(inFile, sourceType, null); + } + + public StructureFile(Object inFile, DataSourceType sourceType, + AlignmentAnnotation.TFType tempfacType) throws IOException + { + super(inFile, sourceType, tempfacType); } public StructureFile(FileParse fp) throws IOException diff --git a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java index 0ac3e00..3298a96 100644 --- a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java +++ b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java @@ -30,7 +30,6 @@ public class PAEContactMatrix implements ContactMatrixI @SuppressWarnings("unchecked") public PAEContactMatrix(SequenceI _refSeq, Map pae_obj) - throws Exception { refSeq = _refSeq; while (refSeq.getDatasetSequence() != null) @@ -184,6 +183,5 @@ public class PAEContactMatrix implements ContactMatrixI public String getAnnotLabel() { return "pAE Matrix"; - } } diff --git a/src/jalview/ws/dbsources/EBIAlfaFold.java b/src/jalview/ws/dbsources/EBIAlfaFold.java index f98ae6d..5314207 100644 --- a/src/jalview/ws/dbsources/EBIAlfaFold.java +++ b/src/jalview/ws/dbsources/EBIAlfaFold.java @@ -23,11 +23,15 @@ package jalview.ws.dbsources; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.json.simple.parser.ParseException; + import com.stevesoft.pat.Regex; import jalview.api.FeatureSettingsModelI; @@ -217,14 +221,14 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy * @param retrievalUrl * - URL of .mmcif from EBI-AlphaFold - will be used to generate the * pAE URL automatically + * @throws IOException * @throws Exception */ public static void retrieve_AlphaFold_pAE(String id, - AlignmentI pdbAlignment, String retrievalUrl) throws Exception + AlignmentI pdbAlignment, String retrievalUrl) throws IOException { // import PAE as contact matrix - assume this will work if there was a // model - File pae = File.createTempFile(id, "pae_json"); String paeURL = getAlphaFoldPaeDownloadUrl(id, AF_VERSION); if (retrievalUrl != null) @@ -233,22 +237,49 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy paeURL = retrievalUrl.replace("model", "predicted_aligned_error") .replace(".cif", ".json"); } + + File pae = null; + try + { + pae = File.createTempFile(id == null ? "af_pae" : id, "pae_json"); + } catch (IOException e) + { + e.printStackTrace(); + } Console.debug("Downloading pae from " + paeURL + " to " + pae.toString() + ""); + UrlDownloadClient.download(paeURL, pae); + addAlphaFoldPAE(pdbAlignment, pae); + } + public static void addAlphaFoldPAE(AlignmentI pdbAlignment, File pae) + { + FileInputStream pae_input = null; try { - UrlDownloadClient.download(paeURL, pae); - FileInputStream pae_input = new FileInputStream(pae); + pae_input = new FileInputStream(pae); + } catch (FileNotFoundException e) + { + Console.error( + "Could not find pAE file '" + pae.getAbsolutePath() + "'", e); + } + try + { if (!importPaeJSONAsContactMatrix(pdbAlignment, pae_input)) { - Console.warn("Couln't import contact matrix from " + paeURL - + " (stored in " + pae.toString() + ")"); + Console.warn("Could not import contact matrix from '" + + pae.getAbsolutePath() + "'"); } - } catch (Exception pae_ex) + } catch (IOException e1) + { + Console.error("Error when importing pAE file '" + + pae.getAbsolutePath() + "'", e1); + } catch (ParseException e2) { - Console.error("Couldn't download PAE", pae_ex); + Console.error( + "Error when parsing pAE file '" + pae.getAbsolutePath() + "'", + e2); } } @@ -260,10 +291,13 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy * @param pdbAlignment * @param pae_input * @return true if there was a pAE matrix added + * @throws ParseException + * @throws IOException * @throws Exception */ public static boolean importPaeJSONAsContactMatrix( - AlignmentI pdbAlignment, InputStream pae_input) throws Exception + AlignmentI pdbAlignment, InputStream pae_input) + throws IOException, ParseException { List pae_obj = (List) Platform.parseJSON(pae_input); diff --git a/src/mc_view/PDBChain.java b/src/mc_view/PDBChain.java index 5413a3c..6d02630 100755 --- a/src/mc_view/PDBChain.java +++ b/src/mc_view/PDBChain.java @@ -536,6 +536,7 @@ public class PDBChain ? tfacTemplate.getDescription() : tfacTemplate.getName()) + " for " + pdbid + id, annots, min, max, AlignmentAnnotation.LINE_GRAPH); + tfactorann.setTFType(tfacTemplate.getTFType()); tfactorann.setCalcId(getClass().getName()); tfactorann.setSequenceRef(sequence); diff --git a/src/mc_view/PDBfile.java b/src/mc_view/PDBfile.java index 54bdca9..2a89e61 100755 --- a/src/mc_view/PDBfile.java +++ b/src/mc_view/PDBfile.java @@ -20,6 +20,13 @@ */ package mc_view; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; + +import jalview.bin.Console; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.DBRefSource; import jalview.datamodel.SequenceI; @@ -28,12 +35,6 @@ import jalview.io.FileParse; import jalview.io.StructureFile; import jalview.util.MessageManager; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.Vector; - public class PDBfile extends StructureFile { private static String CALC_ID_PREFIX = "JalviewPDB"; @@ -51,7 +52,9 @@ public class PDBfile extends StructureFile DataSourceType sourceType) throws IOException { super(false, dataObject, sourceType); + Console.debug("***** PDBfile constructor"); addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr); + Console.debug("***** About to doParse() 1"); doParse(); } @@ -60,6 +63,7 @@ public class PDBfile extends StructureFile { super(false, source); addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr); + Console.debug("***** About to doParse() 2"); doParse(); } -- 1.7.10.2