From d2219b397cfed501534b85976023e7045c35ff67 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 24 May 2012 19:53:06 +0100 Subject: [PATCH 1/1] JAL-1078 - removed 'Load Score File' menu item and extended annotation file loader to recognise and load T-COFFEE files. --- src/jalview/gui/AlignFrame.java | 200 +++++++++++++++--------------------- src/jalview/jbgui/GAlignFrame.java | 13 --- 2 files changed, 81 insertions(+), 132 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 8b71a54..bfcab9e 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3926,89 +3926,13 @@ 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 = new TCoffeeScoreFile(sFilePath, FormatAdapter.FILE); - if (!result.isValid()) { - JOptionPane.showMessageDialog(Desktop.desktop, result.getWarningMessage(), - "Problem reading T-COFFEE score file", JOptionPane.WARNING_MESSAGE); - return; - } - - /* - * 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. - JOptionPane.showMessageDialog(Desktop.desktop, "The scores matrix does not match the alignment dimensions", - "Problem reading T-COFFEE score file", JOptionPane.WARNING_MESSAGE); - } - 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); - } - if (result.getWarningMessage()!=null) - { - JOptionPane.showMessageDialog(Desktop.desktop, result.getWarningMessage(),"Problem reading T-COFEEE score file", JOptionPane.WARNING_MESSAGE); - } - } - catch (Exception ex) { - JOptionPane.showMessageDialog( - Desktop.desktop, - ex.getMessage(), - "unexpected problem reading T-COFFEE score file", - JOptionPane.WARNING_MESSAGE); - - ex.printStackTrace(); - } - } - - } - @Override - protected void tcoffeeColorScheme_actionPerformed(ActionEvent e) { - changeColour( new TCoffeeColourScheme(alignPanel.getAlignment()) ); + 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); @@ -4825,54 +4749,92 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (!isAnnotation) { - // try to see if its a JNet 'concise' style annotation file *before* we - // try to parse it as a features file - if (format == null) + // first see if its a T-COFFEE score file + TCoffeeScoreFile tcf = null; + try { - format = new IdentifyFile().Identify(file, protocol); - } - if (format.equalsIgnoreCase("JnetFile")) + tcf = new TCoffeeScoreFile(file, protocol); + if (tcf.isValid()) + { + if (tcf.annotateAlignment(viewport.getAlignment(), true)) + { + tcoffeeColour.setEnabled(true); + tcoffeeColour.setSelected(true); + changeColour(new TCoffeeColourScheme(viewport.getAlignment())); + isAnnotation = true; + statusBar + .setText("Successfully pasted T-Coffee scores to alignment."); + } + else + { + // some problem - if no warning its probable that the ID matching process didn't work + JOptionPane.showMessageDialog(Desktop.desktop, + tcf.getWarningMessage()==null ? "Check that the file matches sequence IDs in the alignment." : tcf.getWarningMessage(), + "Problem reading T-COFFEE score file", + JOptionPane.WARNING_MESSAGE); + } + } + else + { + tcf = null; + } + } catch (Exception x) { - jalview.io.JPredFile predictions = new jalview.io.JPredFile(file, - protocol); - new JnetAnnotationMaker().add_annotation(predictions, - viewport.getAlignment(), 0, false); - isAnnotation = true; + Cache.log.debug("Exception when processing data source as T-COFFEE score file",x); + tcf = null; } - else + if (tcf == null) { - /* - * if (format.equalsIgnoreCase("PDB")) { - * - * String pdbfn = ""; // try to match up filename with sequence id try - * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new - * File(file); pdbfn = fl.getName(); } else if (protocol == - * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn = - * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null) - * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport - * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { // - * attempt to find a match in the alignment SequenceI mtch = - * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while - * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l) - * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch = - * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate - * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq() - * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) { - * System.err.println("Associated file : " + file + " with " + - * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } // - * TODO: maybe need to load as normal otherwise return; } } - */ + // try to see if its a JNet 'concise' style annotation file *before* + // we // try to parse it as a features file - boolean isGroupsFile = parseFeaturesFile(file, protocol); - // if it wasn't a features file then we just treat it as a general - // alignment file to load into the current view. - if (!isGroupsFile) + if (format == null) + { + format = new IdentifyFile().Identify(file, protocol); + } + if (format.equalsIgnoreCase("JnetFile")) { - new FileLoader().LoadFile(viewport, file, protocol, format); + jalview.io.JPredFile predictions = new jalview.io.JPredFile( + file, protocol); + new JnetAnnotationMaker().add_annotation(predictions, + viewport.getAlignment(), 0, false); + isAnnotation = true; } else { - alignPanel.paintAlignment(true); + /* + * if (format.equalsIgnoreCase("PDB")) { + * + * String pdbfn = ""; // try to match up filename with sequence id + * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = + * new File(file); pdbfn = fl.getName(); } else if (protocol == + * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn = + * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == + * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport + * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { + * // attempt to find a match in the alignment SequenceI mtch = + * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while + * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > + * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch + * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and + * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq() + * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) + * { System.err.println("Associated file : " + file + " with " + + * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } // + * TODO: maybe need to load as normal otherwise return; } } + */ + // try to parse it as a features file + boolean isGroupsFile = parseFeaturesFile(file, protocol); + // if it wasn't a features file then we just treat it as a general + // alignment file to load into the current view. + if (!isGroupsFile) + { + new FileLoader().LoadFile(viewport, file, protocol, format); + } + else + { + alignPanel.paintAlignment(true); + } } } } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 6e8b420..6c1c8c6 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -207,8 +207,6 @@ public class GAlignFrame extends JInternalFrame JMenuItem LoadtreeMenuItem = new JMenuItem(); - JMenuItem loadScoresMenuItem = new JMenuItem(); - public JCheckBoxMenuItem scaleAbove = new JCheckBoxMenuItem(); public JCheckBoxMenuItem scaleLeft = new JCheckBoxMenuItem(); @@ -1311,16 +1309,6 @@ public class GAlignFrame extends JInternalFrame } }); - loadScoresMenuItem.setActionCommand("Load T-Coffee scores"); - loadScoresMenuItem.setText("Load T-Coffee scores"); - loadScoresMenuItem.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - loadScores_actionPerformed(e); - } - }); - scaleAbove.setVisible(false); scaleAbove.setText("Scale Above"); scaleAbove.addActionListener(new java.awt.event.ActionListener() @@ -1817,7 +1805,6 @@ public class GAlignFrame extends JInternalFrame fileMenu.add(exportAnnotations); fileMenu.add(LoadtreeMenuItem); fileMenu.add(associatedData); - fileMenu.add(loadScoresMenuItem); fileMenu.addSeparator(); fileMenu.add(closeMenuItem); editMenu.add(undoMenuItem); -- 1.7.10.2