+ * Handles action event for btn_pdbFromFile
+ */
+ @Override
+ protected void pdbFromFile_actionPerformed()
+ {
+ // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
+ // StructureChooser
+ // works
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ Cache.getProperty("LAST_DIRECTORY"));
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(
+ MessageManager.formatMessage("label.select_pdb_file_for",
+ selectedSequence.getDisplayId(false)));
+ chooser.setToolTipText(MessageManager.formatMessage(
+ "label.load_pdb_file_associate_with_sequence",
+ selectedSequence.getDisplayId(false)));
+
+ int value = chooser.showOpenDialog(null);
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ selectedPdbFileName = chooser.getSelectedFile().getPath();
+ Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
+ boolean guessTFType = localPdbPaeMatrixFileName == null;
+ localPdbPaeMatrixFileName = guessPAEFilename();
+ guessTFType |= localPdbPaeMatrixFileName != null;
+ Regex alphaFold = JmolParser.getNewAlphafoldValidator();
+ if (guessTFType
+ && alphaFold.search(new File(selectedPdbFileName).getName())
+ && !tempFacAsChanged)
+ {
+ // localPdbPaeMatrixFileName was null and now isn't and filename could
+ // well be AlphaFold and user hasn't adjusted the tempFacType
+ combo_tempFacAs.setSelectedItem(TFType.PLDDT);
+ }
+ validateSelections();
+ }
+ }
+
+ /**
+ * Handles action event for btn_paeMatrixFile
+ */
+ @Override
+ protected void paeMatrixFile_actionPerformed()
+ {
+ File pdbFile = new File(selectedPdbFileName);
+ String setFile = Cache.getProperty("LAST_DIRECTORY");
+ if (localPdbPaeMatrixFileName != null)
+ {
+ File paeFile = new File(localPdbPaeMatrixFileName);
+ if (paeFile.exists())
+ setFile = paeFile.getAbsolutePath();
+ else if (paeFile.getParentFile().exists())
+ setFile = paeFile.getParentFile().getAbsolutePath();
+ }
+ else
+ {
+ String guess = guessPAEFilename();
+ if (guess != null)
+ setFile = guess;
+ }
+ JalviewFileChooser chooser = new JalviewFileChooser(setFile);
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager.formatMessage(
+ "label.select_pae_matrix_file_for", pdbFile.getName()));
+ chooser.setToolTipText(MessageManager.formatMessage(
+ "label.load_pae_matrix_file_associate_with_structure",
+ pdbFile.getName()));
+
+ // TODO convert to Callable/Promise
+ int value = chooser.showOpenDialog(null);
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String fileName = chooser.getSelectedFile().getPath();
+ try
+ {
+ PAEContactMatrix.validateContactMatrixFile(fileName);
+ } catch (Exception thr)
+ {
+ JvOptionPane.showInternalMessageDialog(this, MessageManager
+ .formatMessage("label.couldnt_load_file", new Object[]
+ { fileName }) + "<br>" + thr.getLocalizedMessage(),
+ MessageManager.getString("label.error_loading_file"),
+ JvOptionPane.WARNING_MESSAGE);
+ Console.error("Couldn't import " + fileName + " as a PAE matrix",
+ thr);
+ return;
+ }
+ localPdbPaeMatrixFileName = fileName;
+ Cache.setProperty("LAST_DIRECTORY", localPdbPaeMatrixFileName);
+ }
+ validateAssociationFromFile();
+ }
+
+ private String guessPAEFilename()
+ {
+ if (selectedPdbFileName.toLowerCase(Locale.ROOT).endsWith(".pdb")
+ || selectedPdbFileName.toLowerCase(Locale.ROOT)
+ .endsWith(".cif"))
+ {
+ String jsonExt = selectedPdbFileName.substring(0,
+ selectedPdbFileName.length() - 4) + ".json";
+ // AlphaFold naming scheme
+ String guessFile1 = StringUtils.replaceLast(jsonExt, "model",
+ "predicted_aligned_error");
+ // nf-core mode naming scheme
+ String guessFile2 = StringUtils.replaceLast(jsonExt, ".json",
+ "_scores.json");
+ if (new File(guessFile1).exists())
+ {
+ return guessFile1;
+ }
+ else if (new File(jsonExt).exists())
+ {
+ return jsonExt;
+ }
+ else if (new File(guessFile2).exists())
+ {
+ return guessFile2;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Populates the filter combo-box options dynamically depending on discovered
+ * structures