From 4660fcf0745dbc1f6f6e7241b398301f93edb548 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 5 Jun 2015 17:08:15 +0100 Subject: [PATCH] JAL-1760 JAL-1641 Serialisation of Hidden Seqs and Cols in JSON output. Added ability to retrieve hidden Seqs --- resources/lang/Messages.properties | 4 +- src/jalview/api/AlignViewControllerGuiI.java | 6 + src/jalview/appletgui/AlignFrame.java | 84 ++++++---- src/jalview/bin/Jalview.java | 3 +- src/jalview/datamodel/HiddenSequences.java | 7 +- src/jalview/datamodel/Sequence.java | 14 ++ src/jalview/datamodel/SequenceI.java | 13 ++ src/jalview/gui/AlignFrame.java | 233 ++++++++++++++++---------- src/jalview/gui/CutAndPasteTransfer.java | 4 +- src/jalview/io/AppletFormatAdapter.java | 9 +- src/jalview/io/BioJsHTMLOutput.java | 6 +- src/jalview/io/FileLoader.java | 4 +- src/jalview/io/HtmlFile.java | 31 ++-- src/jalview/io/JSONFile.java | 81 ++++++--- test/jalview/io/BioJsHTMLOutputTest.java | 10 +- 15 files changed, 332 insertions(+), 177 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index c068728..9fbe2be 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -121,7 +121,7 @@ action.save_as_default = Save as default action.save_as = Save as action.save = Save action.cancel_fetch = Cancel Fetch -action.save_omit_hidden_columns = Save / Omit Hidden Columns +action.save_omit_hidden_columns = Save / Omit Hidden Regions action.change_font = Change Font action.change_font_tree_panel = Change Font (Tree Panel) action.colour = Colour @@ -361,7 +361,7 @@ label.example = Example label.example_param = Example: {0} label.select_file_format_before_saving = You must select a file format before saving! label.file_format_not_specified = File format not specified -label.alignment_contains_hidden_columns = The Alignment contains hidden columns.\nDo you want to save only the visible alignment? +label.alignment_contains_hidden_columns = The Alignment contains hidden regions (hidden sequences/columns).\nDo you want to save only the visible alignment? label.couldnt_save_file = Couldn't save file: {0} label.error_saving_file = Error Saving File label.remove_from_default_list = Remove from default list? diff --git a/src/jalview/api/AlignViewControllerGuiI.java b/src/jalview/api/AlignViewControllerGuiI.java index f768451..b08a0aa 100644 --- a/src/jalview/api/AlignViewControllerGuiI.java +++ b/src/jalview/api/AlignViewControllerGuiI.java @@ -20,6 +20,8 @@ */ package jalview.api; +import java.util.List; + import jalview.commands.CommandI; import jalview.schemes.ColourSchemeI; @@ -47,4 +49,8 @@ public interface AlignViewControllerGuiI void setMenusForViewport(); void changeColour(ColourSchemeI cs); + + void hideColumns(List colsToHide); + + void syncHiddenSequences(); } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 478aa09..ee64dda 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -20,6 +20,40 @@ */ package jalview.appletgui; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.CheckboxMenuItem; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Label; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.IOException; +import java.net.URL; +import java.net.URLEncoder; +import java.util.Arrays; +import java.util.Deque; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.Vector; + import jalview.analysis.AlignmentSorter; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.api.AlignViewControllerGuiI; @@ -71,40 +105,6 @@ import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; -import java.awt.BorderLayout; -import java.awt.Canvas; -import java.awt.CheckboxMenuItem; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.Label; -import java.awt.Menu; -import java.awt.MenuBar; -import java.awt.MenuItem; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.IOException; -import java.net.URL; -import java.net.URLEncoder; -import java.util.Arrays; -import java.util.Deque; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.Vector; - public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemListener, KeyListener, AlignViewControllerGuiI { @@ -4183,7 +4183,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, public void setShowSeqFeatures(boolean b) { // showSeqFeatures.setSelected(b); - viewport.setShowSequenceFeatures(b); + // viewport.setShowSequenceFeatures(b); } @@ -4193,4 +4193,18 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // setMenusFromViewport(viewport); } + + @Override + public void hideColumns(List colsToHide) + { + // TODO Auto-generated method stub + + } + + @Override + public void syncHiddenSequences() + { + // TODO Auto-generated method stub + + } } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index e184db7..00a042d 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -225,8 +225,7 @@ public class Jalview desktop.checkForNews(); } - BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null); - bjs.updateBioJS(); + BioJsHTMLOutput.updateBioJS(); String file = null, protocol = null, format = null, data = null; jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(); diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index 929e56e..dcc5f26 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -272,8 +272,13 @@ public class HiddenSequences index++; } } + Alignment fAlignmt = new Alignment(seq); + fAlignmt.annotations = alignment.getAlignmentAnnotation(); + fAlignmt.alignmentProperties = alignment.getProperties(); + fAlignmt.groups = alignment.getGroups(); + fAlignmt.hasRNAStructure = alignment.hasRNAStructure(); - return new Alignment(seq); + return fAlignmt; } public boolean isHidden(SequenceI seq) diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index cab1ac7..9f328ee 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -59,6 +59,8 @@ public class Sequence implements SequenceI RNA rna; + private boolean hidden; + /** * This annotation is displayed below the alignment but the positions are tied * to the residues of this sequence @@ -1283,4 +1285,16 @@ public class Sequence implements SequenceI return result; } + @Override + public boolean isHidden() + { + return this.hidden; + } + + @Override + public void setHidden(Boolean hidden) + { + this.hidden = hidden; + } + } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 38ae372..bd193fb 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -419,4 +419,17 @@ public interface SequenceI */ public List getInsertions(); + /** + * + * @return returns true if the sequence is hidden + */ + public boolean isHidden(); + + /** + * + * @param hidden + * visibility status of the sequence + */ + public void setHidden(Boolean hidden); + } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 553ddd2..ad2bbc3 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -20,6 +20,52 @@ */ package jalview.gui; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.dnd.DropTargetEvent; +import java.awt.dnd.DropTargetListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.print.PageFormat; +import java.awt.print.PrinterJob; +import java.beans.PropertyChangeEvent; +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Deque; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Set; +import java.util.Vector; + +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JEditorPane; +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentSorter; import jalview.analysis.AlignmentUtils; @@ -51,6 +97,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; import jalview.datamodel.Sequence; @@ -97,52 +144,6 @@ import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.seqfetcher.DbSourceProxy; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.DnDConstants; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.awt.dnd.DropTargetListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.print.PageFormat; -import java.awt.print.PrinterJob; -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Deque; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.List; -import java.util.Set; -import java.util.Vector; - -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JEditorPane; -import javax.swing.JInternalFrame; -import javax.swing.JLayeredPane; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; - /** * DOCUMENT ME! * @@ -1120,32 +1121,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return false; } - String[] omitHidden = null; - - if (viewport.hasHiddenColumns()) - { - int reply = JOptionPane - .showInternalConfirmDialog( - Desktop.desktop, - MessageManager - .getString("label.alignment_contains_hidden_columns"), - MessageManager - .getString("action.save_omit_hidden_columns"), - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); - - if (reply == JOptionPane.YES_OPTION) - { - omitHidden = viewport.getViewAsString(false); - } - } - FeatureRenderer fr = new FeatureRenderer(this.alignPanel); - viewport.setFeatureRenderer(fr); + ExportData exportData = getAlignmentForExport(); FormatAdapter f = new FormatAdapter(viewport); String output = f.formatSequences(format, - viewport.getAlignment(), // class cast exceptions will + exportData.getAlignment(), // class cast exceptions will // occur in the distant future - omitHidden, f.getCacheSuffixDefault(format), + exportData.getOmitHidden(), f.getCacheSuffixDefault(format), viewport.getColumnSelection()); if (output == null) @@ -1186,6 +1167,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return success; } + private void warningMessage(String warning, String title) { if (new jalview.util.Platform().isHeadless()) @@ -1210,10 +1192,38 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void outputText_actionPerformed(ActionEvent e) { + + ExportData exportData = getAlignmentForExport(); + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + cap.setForInput(null); + + try + { + cap.setText(new FormatAdapter(viewport).formatSequences( + e.getActionCommand(), + exportData.getAlignment(), + exportData.getOmitHidden(), + viewport.getColumnSelection())); + Desktop.addInternalFrame(cap, MessageManager.formatMessage( + "label.alignment_output_command", new Object[] + { e.getActionCommand() }), 600, 500); + } catch (OutOfMemoryError oom) + { + new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom); + cap.dispose(); + } + + } + + public ExportData getAlignmentForExport() + { + AlignmentI alignmentToExport = null; String[] omitHidden = null; FeatureRenderer fr = new FeatureRenderer(this.alignPanel); viewport.setFeatureRenderer(fr); - if (viewport.hasHiddenColumns()) + HiddenSequences hiddenSeqs = viewport.getAlignment() + .getHiddenSequences(); + if (viewport.hasHiddenColumns() || hiddenSeqs.getSize() > 0) { int reply = JOptionPane .showInternalConfirmDialog( @@ -1229,26 +1239,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { omitHidden = viewport.getViewAsString(false); } + else + { + alignmentToExport = viewport.getAlignment().getHiddenSequences() + .getFullAlignment(); + } } - - CutAndPasteTransfer cap = new CutAndPasteTransfer(); - cap.setForInput(null); - - try + if (alignmentToExport == null) { - cap.setText(new FormatAdapter(viewport).formatSequences( - e.getActionCommand(), - viewport.getAlignment(), omitHidden, - viewport.getColumnSelection())); - Desktop.addInternalFrame(cap, MessageManager.formatMessage( - "label.alignment_output_command", new Object[] - { e.getActionCommand() }), 600, 500); - } catch (OutOfMemoryError oom) - { - new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom); - cap.dispose(); + alignmentToExport = viewport.getAlignment(); } - + return new ExportData(alignmentToExport, omitHidden); } /** @@ -5993,6 +5994,64 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, sf.setComplementVisible(this, show); } } + + public class ExportData + { + private AlignmentI alignment; + + private String[] omitHidden; + + public ExportData(AlignmentI align, String[] ommit) + { + this.alignment = align; + this.omitHidden = ommit; + System.out.println(); + } + + public AlignmentI getAlignment() + { + return alignment; + } + + public void setAlignment(AlignmentI alignment) + { + this.alignment = alignment; + } + + public String[] getOmitHidden() + { + return omitHidden; + } + + public void setOmitHidden(String[] omitHidden) + { + this.omitHidden = omitHidden; + } + } + + @Override + public void hideColumns(List colsToHide) + { + for (int[] colRange : colsToHide) + { + viewport.hideColumns(colRange[0], colRange[1]); + } + + } + + @Override + public void syncHiddenSequences() + { + AlignmentI al = viewport.getAlignment(); + HiddenSequences hiddenSeqs = al.getHiddenSequences(); + for (SequenceI seq : al.getSequencesArray()) + { + if (seq.isHidden()) + { + hiddenSeqs.hideSequence(seq); + } + } + } } class PrintThread extends Thread diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 1981488..6f15ddf 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -228,11 +228,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer if (source instanceof HtmlFile) { - ((HtmlFile) source).applySettingsToAlignFrame(af); + ((HtmlFile) source).applySettingsToAlignmentView(af); } else if (source instanceof JSONFile) { - ((JSONFile) source).applySettingsToAlignFrame(af); + ((JSONFile) source).applySettingsToAlignmentView(af); } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 5601f27..e2cd43a 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -20,6 +20,10 @@ */ package jalview.io; +import java.io.File; +import java.io.InputStream; +import java.util.List; + import jalview.api.AlignViewportI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; @@ -28,10 +32,6 @@ import jalview.datamodel.AlignmentView; import jalview.datamodel.SequenceGroup; import jalview.util.MessageManager; -import java.io.File; -import java.io.InputStream; -import java.util.List; - /** * A low level class for alignment and feature IO with alignment formatting * methods used by both applet and application for generating flat alignment @@ -292,6 +292,7 @@ public class AppletFormatAdapter { al.addGroup(sg); } + return al; } else if (format.equals(HtmlFile.FILE_DESC)) diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index b49c2e0..a026c57 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -148,7 +148,7 @@ public class BioJsHTMLOutput return sb.toString(); } - public void refreshBioJSVersionsInfo(String dirName) + public static void refreshBioJSVersionsInfo(String dirName) throws URISyntaxException { File directory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY); @@ -181,7 +181,7 @@ public class BioJsHTMLOutput setBioJsMSAVersions(versionFileMap); } - public void updateBioJS() + public static void updateBioJS() { Thread updateThread = new Thread() { @@ -205,7 +205,7 @@ public class BioJsHTMLOutput } - public void syncUpdates(String localDir, BioJSRepositoryPojo repo) + public static void syncUpdates(String localDir, BioJSRepositoryPojo repo) { for (BioJSReleasePojo bjsRelease : repo.getReleases()) { diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 6329f58..a27777f 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -348,11 +348,11 @@ public class FileLoader implements Runnable } if (source instanceof HtmlFile) { - ((HtmlFile) source).applySettingsToAlignFrame(alignFrame); + ((HtmlFile) source).applySettingsToAlignmentView(alignFrame); } else if (source instanceof JSONFile) { - ((JSONFile) source).applySettingsToAlignFrame(alignFrame); + ((JSONFile) source).applySettingsToAlignmentView(alignFrame); } if (raiseGUI) diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 75e99a6..3dd937d 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -21,15 +21,16 @@ package jalview.io; -import jalview.api.AlignViewControllerGuiI; -import jalview.schemes.ColourSchemeI; - import java.io.IOException; +import java.util.List; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import jalview.api.AlignViewControllerGuiI; +import jalview.schemes.ColourSchemeI; + public class HtmlFile extends AlignFile { public static final String FILE_EXT = "html"; @@ -40,6 +41,8 @@ public class HtmlFile extends AlignFile private boolean showSeqFeatures; + private List hiddenColumns; + public HtmlFile() { super(); @@ -72,25 +75,27 @@ public class HtmlFile extends AlignFile String alignmentJsonString = content.val(); JSONFile jsonFile = new JSONFile().parse(alignmentJsonString); - seqs = jsonFile.getSeqs(); - seqGroups = jsonFile.getSeqGroups(); - annotations = jsonFile.getAnnotations(); - showSeqFeatures = jsonFile.isShowSeqFeatures(); - colourScheme = jsonFile.getColourScheme(); + this.seqs = jsonFile.getSeqs(); + this.seqGroups = jsonFile.getSeqGroups(); + this.annotations = jsonFile.getAnnotations(); + this.showSeqFeatures = jsonFile.isShowSeqFeatures(); + this.colourScheme = jsonFile.getColourScheme(); + this.hiddenColumns = jsonFile.getHiddenColumns(); } catch (Exception e) { e.printStackTrace(); } } - public void applySettingsToAlignFrame(AlignViewControllerGuiI af) + public void applySettingsToAlignmentView(AlignViewControllerGuiI avc) { - af.setShowSeqFeatures(isShowSeqFeatures()); - af.changeColour(getColourScheme()); - af.setMenusForViewport(); + avc.setShowSeqFeatures(isShowSeqFeatures()); + avc.changeColour(getColourScheme()); + avc.setMenusForViewport(); + avc.hideColumns(hiddenColumns); + avc.syncHiddenSequences(); } - @Override public String print() { diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 5e2139e..dca59a3 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -21,6 +21,18 @@ package jalview.io; +import java.awt.Color; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewportI; import jalview.api.FeatureRenderer; @@ -42,18 +54,6 @@ import jalview.json.binding.v1.SequencePojo; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; -import java.awt.Color; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - public class JSONFile extends AlignFile { private ColourSchemeI colourScheme; @@ -80,6 +80,10 @@ public class JSONFile extends AlignFile private JSONExportSettings jsonExportSettings; + private List hiddenColumns; + + private List hiddenSeqRefs; + public JSONFile() { super(); @@ -141,7 +145,7 @@ public class JSONFile extends AlignFile name.append(seq.getName()).append("/").append(seq.getStart()) .append("-").append(seq.getEnd()); SequencePojo jsonSeqPojo = new SequencePojo(); - jsonSeqPojo.setId(seq.getName() + "_" + seq.hashCode()); + jsonSeqPojo.setId(String.valueOf(seq.hashCode())); jsonSeqPojo.setOrder(++count); jsonSeqPojo.setEnd(seq.getEnd()); jsonSeqPojo.setStart(seq.getStart()); @@ -199,8 +203,7 @@ public class JSONFile extends AlignFile seqGrpPojo.setShowNonconserved(seqGrp.getShowNonconserved()); for (SequenceI seq : seqGrp.getSequences()) { - seqGrpPojo.getSeqsHash().add( - seq.getName() + "_" + seq.hashCode()); + seqGrpPojo.getSeqsHash().add(String.valueOf(seq.hashCode())); } jsonAlignmentPojo.getSeqGroups().add(seqGrpPojo); } @@ -294,7 +297,7 @@ public class JSONFile extends AlignFile && displayedFeatures.isVisible(sf.getType())) { SequenceFeaturesPojo jsonFeature = new SequenceFeaturesPojo( - seq.getName() + "_" + seq.hashCode()); + String.valueOf(seq.hashCode())); String featureColour = (fr == null) ? null : jalview.util.Format .getHexString(fr .findFeatureColour(Color.white, seq, @@ -376,6 +379,8 @@ public class JSONFile extends AlignFile "showSeqFeatures").toString()); setColourScheme(getJalviewColorScheme(jsColourScheme)); setShowSeqFeatures(showFeatures); + parseHiddenSeqRefsAsList(jvSettingsJsonObj); + parseHiddenCols(jvSettingsJsonObj); } seqMap = new Hashtable(); @@ -390,6 +395,10 @@ public class JSONFile extends AlignFile int end = Integer.valueOf(sequence.get("end").toString()); Sequence seq = new Sequence(sequenceName, sequcenceString, start, end); + if (hiddenSeqRefs.contains(seqUniqueId)) + { + seq.setHidden(true); + } seqs.add(seq); seqMap.put(seqUniqueId, seq); } @@ -483,6 +492,31 @@ public class JSONFile extends AlignFile return this; } + public void parseHiddenSeqRefsAsList(JSONObject jvSettingsJson) + { + hiddenSeqRefs = new ArrayList(); + String hiddenSeqs = (String) jvSettingsJson.get("hiddenSeqs"); + if(hiddenSeqs != null && !hiddenSeqs.isEmpty()){ + String[] seqRefs = hiddenSeqs.split(";"); + for(String seqRef : seqRefs){ + hiddenSeqRefs.add(seqRef); + } + } + } + + public void parseHiddenCols(JSONObject jvSettingsJson) + { + hiddenColumns = new ArrayList(); + String hiddenCols = (String) jvSettingsJson.get("hiddenCols"); + if(hiddenCols != null && !hiddenCols.isEmpty()){ + String[] rangeStrings = hiddenCols.split(";"); + for(String rangeString : rangeStrings){ + String[] range = rangeString.split("-"); + hiddenColumns.add(new int[] + { Integer.valueOf(range[0]), Integer.valueOf(range[1]) }); + } + } + } @SuppressWarnings("unchecked") private void parseFeatures(JSONArray jsonSeqFeatures) @@ -543,11 +577,13 @@ public class JSONFile extends AlignFile return jalviewColor; } - public void applySettingsToAlignFrame(AlignViewControllerGuiI af) + public void applySettingsToAlignmentView(AlignViewControllerGuiI avc) { - af.setShowSeqFeatures(isShowSeqFeatures()); - af.changeColour(getColourScheme()); - af.setMenusForViewport(); + avc.setShowSeqFeatures(isShowSeqFeatures()); + avc.changeColour(getColourScheme()); + avc.setMenusForViewport(); + avc.hideColumns(hiddenColumns); + avc.syncHiddenSequences(); } public String getGlobalColorScheme() @@ -634,6 +670,11 @@ public class JSONFile extends AlignFile return annotations; } + public List getHiddenColumns() + { + return hiddenColumns; + } + public class JSONExportSettings { private boolean exportSequence; diff --git a/test/jalview/io/BioJsHTMLOutputTest.java b/test/jalview/io/BioJsHTMLOutputTest.java index 134d84f..ac2b599 100644 --- a/test/jalview/io/BioJsHTMLOutputTest.java +++ b/test/jalview/io/BioJsHTMLOutputTest.java @@ -21,11 +21,10 @@ public class BioJsHTMLOutputTest @Test public void getJalviewAlignmentAsJsonString() { - BioJsHTMLOutput bioJsHtmlOutput = new BioJsHTMLOutput(null, null); String bjsTemplate = null; try { - bioJsHtmlOutput.updateBioJS(); + BioJsHTMLOutput.updateBioJS(); try { // allow the update some three seconds to complete before getting latest @@ -47,10 +46,9 @@ public class BioJsHTMLOutputTest @Test(expected = NullPointerException.class) public void expectedNullPointerException() { - BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null); try { - bjs.refreshBioJSVersionsInfo(null); + BioJsHTMLOutput.refreshBioJSVersionsInfo(null); } catch (URISyntaxException e) { Assert.fail("Expception occured while testing!"); @@ -61,11 +59,11 @@ public class BioJsHTMLOutputTest @Test public void getBioJsMSAVersions() { - BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null); TreeMap versions = null; try { - bjs.refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY); + BioJsHTMLOutput + .refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY); versions = BioJsHTMLOutput.getBioJsMSAVersions(); } catch (URISyntaxException e) { -- 1.7.10.2