JAL-629 Some refactoring to allow more flexible use of PAE files. Not working as...
[jalview.git] / src / jalview / gui / StructureChooser.java
index 0823652..e2eaabd 100644 (file)
@@ -25,7 +25,6 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -44,15 +43,15 @@ import javax.swing.JTable;
 import javax.swing.SwingUtilities;
 import javax.swing.table.AbstractTableModel;
 
-import org.json.simple.parser.ParseException;
+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.AlignmentI;
 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;
@@ -67,7 +66,6 @@ import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
 import jalview.io.DataSourceType;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
-import jalview.io.StructureFile;
 import jalview.jbgui.FilterOption;
 import jalview.jbgui.GStructureChooser;
 import jalview.structure.StructureImportSettings.TFType;
@@ -78,7 +76,6 @@ import jalview.util.Platform;
 import jalview.util.StringUtils;
 import jalview.ws.DBRefFetcher;
 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
-import jalview.ws.dbsources.EBIAlfaFold;
 import jalview.ws.seqfetcher.DbSourceProxy;
 import jalview.ws.sifts.SiftsSettings;
 
@@ -688,8 +685,9 @@ public class StructureChooser extends GStructureChooser
       boolean guessTFType = localPdbPaeMatrixFileName == null;
       localPdbPaeMatrixFileName = guessPAEFilename();
       guessTFType |= localPdbPaeMatrixFileName != null;
+      Regex alphaFold = JmolParser.getNewAlphafoldValidator();
       if (guessTFType
-              && new File(selectedPdbFileName).getName().startsWith("AF-")
+              && alphaFold.search(new File(selectedPdbFileName).getName())
               && !tempFacAsChanged)
       {
         // localPdbPaeMatrixFileName was null and now isn't and filename could
@@ -1268,38 +1266,29 @@ public class StructureChooser extends GStructureChooser
         }
         else if (currentView == VIEWS_FROM_FILE)
         {
-
-          // TEMPFAC NOT WORKING
           TFType tft = (TFType) StructureChooser.this.combo_tempFacAs
                   .getSelectedItem();
-          if (tft != null && tft != TFType.DEFAULT)
-          {
-            ssm.setAddTempFacAnnot(true);
-          }
-
+          String paeFilename = StructureChooser.this.localPdbPaeMatrixFileName;
           AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
                   .getCmb_assSeq().getSelectedItem();
-
           SequenceI userSelectedSeq = assSeqOpt.getSequence();
           if (userSelectedSeq != null)
-          {
             selectedSequence = userSelectedSeq;
-          }
+          String pdbFilename = selectedPdbFileName;
+
           PDBEntry fileEntry = new AssociatePdbFileWithSeq()
-                  .associatePdbWithSeq(selectedPdbFileName,
-                          DataSourceType.FILE, selectedSequence, true,
-                          Desktop.instance);
+                  .associatePdbWithSeq(pdbFilename, DataSourceType.FILE,
+                          selectedSequence, true, Desktop.instance, tft,
+                          paeFilename);
 
-          List<SequenceI> seqList = new ArrayList<>();
-          seqList.add(selectedSequence);
+          /*
           SequenceI[] seqArray = new SequenceI[] { selectedSequence };
+          
           StructureFile sf = ssm.computeMapping(true, seqArray, null,
-                  selectedPdbFileName, DataSourceType.FILE, null);
-          // EBIAlfaFold.addAlphaFoldPAEToStructure(pdbAlignment, pae, index,
-          // structIdOrFile, isStructId);
+                  selectedPdbFileName, DataSourceType.FILE, null, tft,
+                  paeFilename);
           StructureMapping[] sm = ssm.getMapping(fileEntry.getFile());
           // DO SOMETHING WITH
-          String paeFilename = StructureChooser.this.localPdbPaeMatrixFileName;
           File paeFile = paeFilename == null ? null : new File(paeFilename);
           if (paeFilename != null && paeFile.exists())
           {
@@ -1307,14 +1296,14 @@ public class StructureChooser extends GStructureChooser
             try
             {
               EBIAlfaFold.importPaeJSONAsContactMatrixToSequence(al,
-                      paeFile, -1, selectedSequence.getName());
+                      paeFile, selectedSequence);
             } catch (IOException | ParseException e)
             {
               // TODO Auto-generated catch block
               e.printStackTrace();
             }
           }
-
+          */
           sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
                   ap, new SequenceI[]
                   { selectedSequence });
@@ -1400,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());
@@ -1447,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);