Merge remote-tracking branch 'origin/Tcoffee_JAL-1065' into develop
[jalview.git] / src / jalview / gui / AlignFrame.java
index 9b571f2..6896fb7 100755 (executable)
@@ -55,6 +55,7 @@ import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.io.JnetAnnotationMaker;
 import jalview.io.NewickFile;
+import jalview.io.TCoffeeScoreFile;
 import jalview.jbgui.GAlignFrame;
 import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.BuriedColourScheme;
@@ -69,6 +70,7 @@ import jalview.schemes.PurinePyrimidineColourScheme;
 import jalview.schemes.RNAHelicesColourChooser;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TCoffeeColourScheme;
 import jalview.schemes.TaylorColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.schemes.UserColourScheme;
@@ -144,7 +146,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   AlignViewport viewport;
 
   Vector alignPanels = new Vector();
-
+  
   /**
    * Last format used to load or save alignments in this window
    */
@@ -3053,6 +3055,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   public void changeColour(ColourSchemeI cs)
   {
+    // TODO: compare with applet and pull up to model method
     int threshold = 0;
 
     if (cs != null)
@@ -3124,7 +3127,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
           try
           {
-            sg.cs = (ColourSchemeI) cs.getClass().newInstance();
+            sg.cs = cs.getClass().newInstance();
           } catch (Exception ex)
           {
           }
@@ -3922,7 +3925,84 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
     }
   }
-
+  
+  @Override
+  public void loadScores_actionPerformed(ActionEvent e)
+  {
+           // Pick the tree file
+           JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
+           chooser.setFileView(new JalviewFileView());
+           chooser.setDialogTitle("Select a T-Coffee scores ascii file");
+           chooser.setToolTipText("Load a score file");
+
+           int value = chooser.showOpenDialog(null);
+
+           if (value == JalviewFileChooser.APPROVE_OPTION)
+           {
+             String sFilePath = chooser.getSelectedFile().getPath();
+             jalview.bin.Cache.setProperty("LAST_DIRECTORY", sFilePath);
+           
+             
+             try 
+             {
+                 TCoffeeScoreFile result = TCoffeeScoreFile.load(new File(sFilePath));
+                 if( result == null ) { 
+                      // TODO: raise a dialog box here rather than bomb out.
+                 
+                         throw new RuntimeException("The file provided does not match the T-Coffee scores file format"); 
+                 }
+
+                 /*
+                  * check that the score matrix matches the alignment dimensions
+                  */
+                 AlignmentI aln; 
+                 if( (aln=viewport.getAlignment()) != null && (aln.getHeight() != result.getHeight() || aln.getWidth() != result.getWidth()) ) {
+                     // TODO: raise a dialog box here rather than bomb out.
+                   throw new RuntimeException("The scores matrix does not match the alignment dimensions");
+                 }
+                 if (result.annotateAlignment(alignPanel.getAlignment(), true))
+                 {
+                         tcoffeeColour.setEnabled(true);
+                         tcoffeeColour.setSelected(true);
+                         // switch to this color
+                         changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
+                 } else {
+                   tcoffeeColour.setEnabled(false);
+                   tcoffeeColour.setSelected(false);
+                 }
+             } 
+             catch (Exception ex) {
+               JOptionPane.showMessageDialog(
+                                       Desktop.desktop, 
+                                       ex.getMessage(), 
+                                       "Problem reading tree file", 
+                                       JOptionPane.WARNING_MESSAGE);
+
+               ex.printStackTrace();
+             }
+           }
+
+  } 
+
+  
+  @Override
+  protected void tcoffeeColorScheme_actionPerformed(ActionEvent e) {
+         changeColour( new TCoffeeColourScheme(alignPanel.getAlignment()) );
+  }
+  
+//  /**
+//   * Load the (T-Coffee) score file from the specified url 
+//   * 
+//   * @param url The absolute path from where download and read the score file
+//   * @throws IOException 
+//   */
+//  public void loadScoreFile(URL url ) throws IOException {
+//       
+//       TCoffeeScoreFile result = new TCoffeeScoreFile();
+//       result.parse( new InputStreamReader( url.openStream() ) );
+//       tcoffeeScoreFile = result;
+//  }  
+  
   public TreePanel ShowNewickTree(NewickFile nf, String title)
   {
     return ShowNewickTree(nf, title, 600, 500, 4, 5);