JAL-629 Some refactoring to allow more flexible use of PAE files. Not working as...
[jalview.git] / src / jalview / gui / StructureChooser.java
index 47bec31..e2eaabd 100644 (file)
@@ -43,12 +43,15 @@ import javax.swing.JTable;
 import javax.swing.SwingUtilities;
 import javax.swing.table.AbstractTableModel;
 
+import com.stevesoft.pat.Regex;
+
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.bin.Console;
 import jalview.bin.Jalview;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.ext.jmol.JmolParser;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
@@ -679,7 +682,18 @@ public class StructureChooser extends GStructureChooser
     {
       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();
     }
   }
@@ -725,7 +739,9 @@ public class StructureChooser extends GStructureChooser
 
   private String guessPAEFilename()
   {
-    if (selectedPdbFileName.toLowerCase(Locale.ROOT).endsWith(".pdb"))
+    if (selectedPdbFileName.toLowerCase(Locale.ROOT).endsWith(".pdb")
+            || selectedPdbFileName.toLowerCase(Locale.ROOT)
+                    .endsWith(".cif"))
     {
       String jsonExt = selectedPdbFileName.substring(0,
               selectedPdbFileName.length() - 4) + ".json";
@@ -1250,17 +1266,44 @@ public class StructureChooser extends GStructureChooser
         }
         else if (currentView == VIEWS_FROM_FILE)
         {
-          SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
-                  .getCmb_assSeq().getSelectedItem()).getSequence();
+          TFType tft = (TFType) StructureChooser.this.combo_tempFacAs
+                  .getSelectedItem();
+          String paeFilename = StructureChooser.this.localPdbPaeMatrixFileName;
+          AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
+                  .getCmb_assSeq().getSelectedItem();
+          SequenceI userSelectedSeq = assSeqOpt.getSequence();
           if (userSelectedSeq != null)
-          {
             selectedSequence = userSelectedSeq;
-          }
-          PDBEntry fileEntry = new AssociatePdbFileWithSeq()
-                  .associatePdbWithSeq(selectedPdbFileName,
-                          DataSourceType.FILE, selectedSequence, true,
-                          Desktop.instance);
+          String pdbFilename = selectedPdbFileName;
 
+          PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+                  .associatePdbWithSeq(pdbFilename, DataSourceType.FILE,
+                          selectedSequence, true, Desktop.instance, tft,
+                          paeFilename);
+
+          /*
+          SequenceI[] seqArray = new SequenceI[] { selectedSequence };
+          
+          StructureFile sf = ssm.computeMapping(true, seqArray, null,
+                  selectedPdbFileName, DataSourceType.FILE, null, tft,
+                  paeFilename);
+          StructureMapping[] sm = ssm.getMapping(fileEntry.getFile());
+          // DO SOMETHING WITH
+          File paeFile = paeFilename == null ? null : new File(paeFilename);
+          if (paeFilename != null && paeFile.exists())
+          {
+            AlignmentI al = StructureChooser.this.ap.getAlignment();
+            try
+            {
+              EBIAlfaFold.importPaeJSONAsContactMatrixToSequence(al,
+                      paeFile, selectedSequence);
+            } catch (IOException | ParseException e)
+            {
+              // TODO Auto-generated catch block
+              e.printStackTrace();
+            }
+          }
+          */
           sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
                   ap, new SequenceI[]
                   { selectedSequence });
@@ -1346,6 +1389,10 @@ public class StructureChooser extends GStructureChooser
       for (SequenceI seq : sequences)
       {
         PDBEntry pdbe = pdbEntriesToView[p++];
+        Console.debug(
+                "##### pdbe=" + pdbe == null ? null : pdbe.toString());
+        Console.debug("##### pdbe.getFile()=" + pdbe == null ? null
+                : pdbe.getFile());
         if (pdbe != null && pdbe.getFile() != null)
         {
           StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
@@ -1393,6 +1440,7 @@ public class StructureChooser extends GStructureChooser
       setProgressBar(MessageManager.formatMessage(
               "status.fetching_3d_structures_for",
               pdbEntriesToView[0].getId()), progressId);
+      // Can we pass a pre-computeMappinged pdbFile?
       theViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
     }
     setProgressBar(null, progressId);