JAL-1641 added support for persisting and retrieveing SequenceGroup
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 6 May 2015 16:21:48 +0000 (17:21 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 6 May 2015 16:21:48 +0000 (17:21 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/CutAndPasteTransfer.java
src/jalview/gui/Desktop.java
src/jalview/gui/PopupMenu.java
src/jalview/io/AlignFile.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FormatAdapter.java
src/jalview/io/JSONFile.java
src/jalview/json/binding/v1/AlignmentPojo.java

index 1963523..5432155 100644 (file)
@@ -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);
   }
 
   /*
index 24e464a..081f5eb 100644 (file)
@@ -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!
    * 
index 53237f9..5038e4d 100644 (file)
@@ -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;
+  }
 
 }
index 1263b71..013f4d2 100644 (file)
  */
 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!
  * 
index 993a1e8..e3c75a5 100755 (executable)
@@ -174,6 +174,11 @@ public abstract class AlignFile extends FileParse
     return seqs;
   }
 
+  public List<SequenceGroup> 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();
+
   }
 
   /**
index 39b0819..526e8e9 100755 (executable)
@@ -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)
index 8f47317..74410a1 100755 (executable)
@@ -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;
   }
 
index 8b38d84..d3d2ef7 100644 (file)
@@ -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<SequenceGrpPojo> sequenceGroupsPojo = new ArrayList<SequenceGrpPojo>();
       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<String, Sequence>();
       Desktop.setCurrentGlobalColourScheme(cs);
+      Desktop.setCurrentSeqFeaturesVisible(showFeatures);
       for (Iterator<JSONObject> sequenceIter = seqJsonArray.iterator(); sequenceIter
               .hasNext();)
       {
@@ -240,54 +241,49 @@ public class JSONFile extends AlignFile
         seqMap.put(seqUniqueId, seq);
       }
       
-      // for (Iterator<JSONObject> 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<SequenceI> grpSeqs = new ArrayList<SequenceI>();
-      // if (seqsHashArray.size() > 0)
-      // {
-      // Iterator<String> 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<JSONObject> 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<SequenceI> grpSeqs = new ArrayList<SequenceI>();
+        if (seqsHashArray.size() > 0)
+        {
+          Iterator<String> 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<JSONObject> 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();
   }
 
index 48c477d..163b6ab 100644 (file)
@@ -25,6 +25,8 @@ public class AlignmentPojo
 
   private String webStartUrl;
 
+  private boolean showSeqFeatures;
+
   private List<SequencePojo> seqs = new ArrayList<SequencePojo>();
 
   private List<AlignmentAnnotationPojo> alignmentAnnotation = new ArrayList<AlignmentAnnotationPojo>();
@@ -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",