From 3312480ec09b9f2087a79304f14ab359dbdfbeeb Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Wed, 6 May 2015 17:21:48 +0100 Subject: [PATCH] JAL-1641 added support for persisting and retrieveing SequenceGroup --- src/jalview/gui/AlignFrame.java | 4 +- src/jalview/gui/CutAndPasteTransfer.java | 6 +- src/jalview/gui/Desktop.java | 24 +++-- src/jalview/gui/PopupMenu.java | 42 ++++----- src/jalview/io/AlignFile.java | 6 ++ src/jalview/io/AppletFormatAdapter.java | 1 + src/jalview/io/FormatAdapter.java | 46 +++++----- src/jalview/io/JSONFile.java | 112 ++++++++++++------------ src/jalview/json/binding/v1/AlignmentPojo.java | 12 +++ 9 files changed, 143 insertions(+), 110 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 1963523..5432155 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -5788,8 +5788,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void setShowSeqFeatures(boolean b) { - showSeqFeatures.setSelected(true); - viewport.setShowSequenceFeatures(true); + showSeqFeatures.setSelected(b); + viewport.setShowSequenceFeatures(b); } /* diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 24e464a..081f5eb 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -219,8 +219,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer af.statusBar.setText(MessageManager .getString("label.successfully_pasted_alignment_file")); + System.out.println(">>>>>>>>>>>>>>>> showFeatures : " + + Desktop.isCurrentSeqFeaturesVisible()); + + af.setShowSeqFeatures(Desktop.isCurrentSeqFeaturesVisible()); - af.setShowSeqFeatures(true); af.changeColour(Desktop.getCurrentGlobalColourScheme()); af.setMenusForViewport(); @@ -235,6 +238,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } } + /** * DOCUMENT ME! * diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 53237f9..5038e4d 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -174,6 +174,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements private static ColourSchemeI currentGlobalColourScheme; + private static boolean currentSeqFeaturesVisible; + public static jalview.ws.jws1.Discoverer discoverer; public static Object[] jalviewClipboard; @@ -1027,11 +1029,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format); - - viewport.setShowSequenceFeatures(true); - viewport.getAlignPanel().alignFrame.changeColour(Desktop - .getCurrentGlobalColourScheme()); - viewport.getAlignPanel().alignFrame.setMenusForViewport(); + viewport.setShowSequenceFeatures(isCurrentSeqFeaturesVisible()); + AlignFrame af = viewport.getAlignPanel().alignFrame; + if (af != null) + { + af.changeColour(getCurrentGlobalColourScheme()); + af.setMenusForViewport(); + } } else { @@ -3105,5 +3109,15 @@ public class Desktop extends jalview.jbgui.GDesktop implements Desktop.currentGlobalColourScheme = currentGlobalColourScheme; } + public static boolean isCurrentSeqFeaturesVisible() + { + return currentSeqFeaturesVisible; + } + + public static void setCurrentSeqFeaturesVisible( + boolean currentSeqFeaturesVisible) + { + Desktop.currentSeqFeaturesVisible = currentSeqFeaturesVisible; + } } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 1263b71..013f4d2 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -20,27 +20,6 @@ */ package jalview.gui; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Arrays; -import java.util.Collections; -import java.util.Hashtable; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.Vector; - -import javax.swing.ButtonGroup; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JColorChooser; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButtonMenuItem; - import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; @@ -80,6 +59,27 @@ import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.MessageManager; import jalview.util.UrlLink; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.Collections; +import java.util.Hashtable; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.Vector; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JColorChooser; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; + /** * DOCUMENT ME! * diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 993a1e8..e3c75a5 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -174,6 +174,11 @@ public abstract class AlignFile extends FileParse return seqs; } + public List getSeqGroups() + { + return seqGroups; + } + /** * Return the Sequences in the seqs Vector as an array of Sequences */ @@ -218,6 +223,7 @@ public abstract class AlignFile extends FileParse public void addSeqGroups(AlignmentI al) { this.seqGroups = al.getGroups(); + } /** diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 39b0819..526e8e9 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -429,6 +429,7 @@ public class AppletFormatAdapter afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); Alignment al = new Alignment(afile.getSeqsAsArray()); afile.addAnnotations(al); + afile.addSeqGroups(al); return al; } catch (Exception ex) diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 8f47317..74410a1 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -259,19 +259,20 @@ public class FormatAdapter extends AppletFormatAdapter throws java.io.IOException { Alignment al; - // if (format.equals(JSONFile.FILE_DESC)) - // { - // // afile = new HtmlFile(inFile, type); - // al = new Alignment(afile.getSeqsAsArray()); - // afile.addAnnotations(al); - // } - // else - // { + if (format.equals(JSONFile.FILE_DESC)) + { + afile = new JSONFile(inFile, type); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + for (SequenceGroup sg : afile.getSeqGroups()) + { + al.addGroup(sg); + } + } + else + { al = super.readFile(inFile, type, format); - // } - - afile.addSeqGroups(al); - afile.addAnnotations(al); + } return al; } @@ -279,18 +280,17 @@ public class FormatAdapter extends AppletFormatAdapter throws java.io.IOException { Alignment al; - // if (format.equals(JSONFile.FILE_DESC)) - // { - // // afile = new HtmlFile(source); - // al = new Alignment(afile.getSeqsAsArray()); - // afile.addAnnotations(al); - // } - // else - // { + if (format.equals(JSONFile.FILE_DESC)) + { + afile = new JSONFile(source); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + afile.addSeqGroups(al); + } + else + { al = (Alignment) super.readFromFile(source, format); - // } - afile.addSeqGroups(al); - afile.addAnnotations(al); + } return al; } diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 8b38d84..d3d2ef7 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -48,8 +48,6 @@ public class JSONFile extends AlignFile private FeaturesDisplayedI displayedFeatures; - // private AlignmentI al; - private AlignmentViewport av; private jalview.api.FeatureRenderer fr; @@ -96,17 +94,18 @@ public class JSONFile extends AlignFile this.fr = Desktop.getCurrentAlignFrame().alignPanel .cloneFeatureRenderer(); displayedFeatures = av.getFeaturesDisplayed(); + jsonAlignmentPojo + .setShowSeqFeatures(Desktop.getCurrentAlignFrame().showSeqFeatures + .isSelected()); } jsonAlignmentPojo.setJalviewVersion(jalviewVersion); jsonAlignmentPojo.setWebStartUrl(webStartLaunchServletUrl); - System.out.println(">>>>>>>>>>>>>> found grps : " + seqGroups.size()); if (seqGroups.size() > 0) { ArrayList sequenceGroupsPojo = new ArrayList(); for (SequenceGroup seqGrp : seqGroups) { - System.out.println(">>>>>>>>>>>> grp : " + seqGrp.getName()); SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo(); seqGrpPojo.setGroupName(seqGrp.getName()); seqGrpPojo.setColourScheme(ColourSchemeProperty @@ -118,13 +117,13 @@ public class JSONFile extends AlignFile seqGrpPojo.setEndRes(seqGrp.getEndRes()); seqGrpPojo.setStartRes(seqGrp.getStartRes()); seqGrpPojo.setShowNonconserved(seqGrp.getShowNonconserved()); - jsonAlignmentPojo.getSequenceGroups().add(seqGrpPojo); for(SequenceI seq : seqGrp.getSequences()){ seqGrpPojo.getSeqsHash().add(seq.getName() + "_" + seq.hashCode()); } - // sequenceGroupsPojo.add(seqGrpPojo); + jsonAlignmentPojo.getSequenceGroups().add(seqGrpPojo); } } + for (AlignmentAnnotation annot : annotations) { AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo(); @@ -214,10 +213,12 @@ public class JSONFile extends AlignFile JSONArray seqGrpJsonArray = (JSONArray) alignmentJsonObj.get("sequenceGroups"); String jsColourScheme = (String) alignmentJsonObj .get("globalColorScheme"); - System.out.println(">>>>>>>>>>>>>>>> global cs : " + jsColourScheme); + Boolean showFeatures = Boolean.valueOf(alignmentJsonObj.get( + "showSeqFeatures").toString()); cs = getJalviewColorScheme(jsColourScheme); seqMap = new Hashtable(); Desktop.setCurrentGlobalColourScheme(cs); + Desktop.setCurrentSeqFeaturesVisible(showFeatures); for (Iterator sequenceIter = seqJsonArray.iterator(); sequenceIter .hasNext();) { @@ -240,54 +241,49 @@ public class JSONFile extends AlignFile seqMap.put(seqUniqueId, seq); } - // for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); - // seqGrpIter - // .hasNext();) - // { - // JSONObject seqGrpObj = seqGrpIter.next(); - // String grpName = seqGrpObj.get("groupName").toString(); - // String colourScheme = seqGrpObj.get("colourScheme").toString(); - // String description = (seqGrpObj.get("description") == null) ? null - // : seqGrpObj.get("description").toString(); - // boolean displayBoxes = Boolean.valueOf(seqGrpObj - // .get("displayBoxes").toString()); - // boolean displayText = Boolean.valueOf(seqGrpObj.get("displayText") - // .toString()); - // boolean colourText = Boolean.valueOf(seqGrpObj.get("colourText") - // .toString()); - // boolean showNonconserved = Boolean.valueOf(seqGrpObj.get( - // "showNonconserved").toString()); - // int startRes = Integer - // .valueOf(seqGrpObj.get("startRes").toString()); - // int endRes = Integer.valueOf(seqGrpObj.get("endRes").toString()); - // JSONArray seqsHashArray = (JSONArray) seqGrpObj.get("seqsHash"); - // - // ArrayList grpSeqs = new ArrayList(); - // if (seqsHashArray.size() > 0) - // { - // Iterator seqHashIter = seqsHashArray.iterator(); - // - // while (seqHashIter.hasNext()) - // { - // String seqHash = seqHashIter.next(); - // Sequence sequence = seqMap.get(seqHash); - // if (sequence != null) - // { - // grpSeqs.add(sequence); - // } - // // System.out.println(">>>>>>>>>>>>>>>>>>>>>>> seqHash : " - // // + seqHash); - // } - // } - // System.out.println(">>>>>>>>>>>>>>>>>> scheme string : " - // + colourScheme); - // ColourSchemeI scheme = getJalviewColorScheme(colourScheme); - // System.out.println(">>>>>>>>>>>>>>>>>> scheme: " + scheme); - // SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, scheme, - // displayBoxes, displayText, colourText, startRes, endRes); - // this.seqGroups.add(seqGrp); - // - // } + for (Iterator seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter + .hasNext();) + { + JSONObject seqGrpObj = seqGrpIter.next(); + String grpName = seqGrpObj.get("groupName").toString(); + String colourScheme = seqGrpObj.get("colourScheme").toString(); + String description = (seqGrpObj.get("description") == null) ? null + : seqGrpObj.get("description").toString(); + boolean displayBoxes = Boolean.valueOf(seqGrpObj + .get("displayBoxes").toString()); + boolean displayText = Boolean.valueOf(seqGrpObj.get("displayText") + .toString()); + boolean colourText = Boolean.valueOf(seqGrpObj.get("colourText") + .toString()); + boolean showNonconserved = Boolean.valueOf(seqGrpObj.get( + "showNonconserved").toString()); + int startRes = Integer + .valueOf(seqGrpObj.get("startRes").toString()); + int endRes = Integer.valueOf(seqGrpObj.get("endRes").toString()); + JSONArray seqsHashArray = (JSONArray) seqGrpObj.get("seqsHash"); + + ArrayList grpSeqs = new ArrayList(); + if (seqsHashArray.size() > 0) + { + Iterator seqHashIter = seqsHashArray.iterator(); + while (seqHashIter.hasNext()) + { + String seqHash = seqHashIter.next(); + Sequence sequence = seqMap.get(seqHash); + if (sequence != null) + { + grpSeqs.add(sequence); + } + } + } + ColourSchemeI scheme = getJalviewColorScheme(colourScheme); + SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, scheme, + displayBoxes, displayText, colourText, startRes, endRes); + seqGrp.setShowNonconserved(showNonconserved); + seqGrp.setDescription(description); + this.seqGroups.add(seqGrp); + + } for (Iterator alAnnotIter = alAnnotJsonArray.iterator(); alAnnotIter @@ -355,7 +351,7 @@ public class JSONFile extends AlignFile Long begin = (Long) jsonFeature.get("xStart"); Long end = (Long) jsonFeature.get("xEnd"); String type = (String) jsonFeature.get("type"); - // String color = (String) jsonFeature.get("fillColor"); + String color = (String) jsonFeature.get("fillColor"); String featureGrp = (String) jsonFeature.get("featureGroup"); String descripiton = (String) jsonFeature.get("description"); Float score = Float.valueOf(jsonFeature.get("score").toString()); @@ -394,8 +390,8 @@ public class JSONFile extends AlignFile public void LoadAlignmentFeatures(AlignFrame af) { - af.setShowSeqFeatures(true); - af.changeColour(cs); + af.setShowSeqFeatures(Desktop.isCurrentSeqFeaturesVisible()); + af.changeColour(Desktop.getCurrentGlobalColourScheme()); af.setMenusForViewport(); } diff --git a/src/jalview/json/binding/v1/AlignmentPojo.java b/src/jalview/json/binding/v1/AlignmentPojo.java index 48c477d..163b6ab 100644 --- a/src/jalview/json/binding/v1/AlignmentPojo.java +++ b/src/jalview/json/binding/v1/AlignmentPojo.java @@ -25,6 +25,8 @@ public class AlignmentPojo private String webStartUrl; + private boolean showSeqFeatures; + private List seqs = new ArrayList(); private List alignmentAnnotation = new ArrayList(); @@ -116,6 +118,16 @@ public class AlignmentPojo this.sequenceGroups = sequenceGroups; } + public boolean isShowSeqFeatures() + { + return showSeqFeatures; + } + + public void setShowSeqFeatures(boolean showSeqFeatures) + { + this.showSeqFeatures = showSeqFeatures; + } + public enum JalviewBioJsColorSchemeMapper { USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo", -- 1.7.10.2