From a40bbc57a85658544e2e5d7cc2a7596b762566dc Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Mon, 11 May 2015 10:40:47 +0100 Subject: [PATCH] JAL-1641 cherry-picked changes into develop compatible branch --- src/jalview/gui/AlignFrame.java | 5 +- src/jalview/gui/CutAndPasteTransfer.java | 7 + src/jalview/gui/Desktop.java | 54 +- src/jalview/gui/PopupMenu.java | 42 +- src/jalview/io/AlignFile.java | 21 + src/jalview/io/AppletFormatAdapter.java | 60 ++- src/jalview/io/BioJsHTMLOutput.java | 32 +- src/jalview/io/FileLoader.java | 9 +- src/jalview/io/FormatAdapter.java | 15 +- src/jalview/io/HtmlFile.java | 150 +++--- src/jalview/io/IdentifyFile.java | 5 + src/jalview/io/JSONFile.java | 546 ++++++++++++++++++++ .../json/binding/v1/AlignmentAnnotationPojo.java | 43 ++ src/jalview/json/binding/v1/AlignmentPojo.java | 74 +++ src/jalview/json/binding/v1/AnnotationPojo.java | 54 ++ src/jalview/json/binding/v1/BioJsFeaturePojo.java | 60 --- ...AlignmentPojo.java => JalviewSettingsPojo.java} | 67 ++- .../json/binding/v1/SequenceFeaturesPojo.java | 137 +++++ src/jalview/json/binding/v1/SequenceGrpPojo.java | 126 +++++ .../v1/{BioJsSeqPojo.java => SequencePojo.java} | 30 +- 20 files changed, 1276 insertions(+), 261 deletions(-) create mode 100644 src/jalview/io/JSONFile.java create mode 100644 src/jalview/json/binding/v1/AlignmentAnnotationPojo.java create mode 100644 src/jalview/json/binding/v1/AlignmentPojo.java create mode 100644 src/jalview/json/binding/v1/AnnotationPojo.java delete mode 100644 src/jalview/json/binding/v1/BioJsFeaturePojo.java rename src/jalview/json/binding/v1/{BioJsAlignmentPojo.java => JalviewSettingsPojo.java} (75%) create mode 100644 src/jalview/json/binding/v1/SequenceFeaturesPojo.java create mode 100644 src/jalview/json/binding/v1/SequenceGrpPojo.java rename src/jalview/json/binding/v1/{BioJsSeqPojo.java => SequencePojo.java} (59%) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 80838e2..1b2410a 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1306,6 +1306,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, try { + Desktop.setCurrentAlignFrame(this); cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), viewport.getAlignment(), omitHidden, viewport.getColumnSelection())); @@ -5787,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 22f0a59..6511cd8 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.datamodel.Alignment; import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; +import jalview.io.JSONFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GCutAndPasteTransfer; @@ -219,6 +220,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer af.statusBar.setText(MessageManager .getString("label.successfully_pasted_alignment_file")); + af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled()); + + af.changeColour(JSONFile.getColourScheme()); + af.setMenusForViewport(); + try { af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", @@ -230,6 +236,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } } + /** * DOCUMENT ME! * diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 5f45dc1..9e5bbff 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -20,6 +20,23 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; +import jalview.io.FileLoader; +import jalview.io.FormatAdapter; +import jalview.io.IdentifyFile; +import jalview.io.JSONFile; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.jbgui.GSplitFrame; +import jalview.jbgui.GStructureViewer; +import jalview.structure.StructureSelectionManager; +import jalview.util.ImageMaker; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; +import jalview.ws.params.ParamManager; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -84,22 +101,6 @@ import javax.swing.event.HyperlinkEvent.EventType; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.bin.Cache; -import jalview.io.FileLoader; -import jalview.io.FormatAdapter; -import jalview.io.IdentifyFile; -import jalview.io.JalviewFileChooser; -import jalview.io.JalviewFileView; -import jalview.jbgui.GSplitFrame; -import jalview.jbgui.GStructureViewer; -import jalview.structure.StructureSelectionManager; -import jalview.util.ImageMaker; -import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; -import jalview.ws.params.ParamManager; - /** * Jalview Desktop * @@ -169,6 +170,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements private static final int THREE = 3; + private static AlignFrame currentAlignFrame; + public static jalview.ws.jws1.Discoverer discoverer; public static Object[] jalviewClipboard; @@ -1022,6 +1025,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format); + viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled()); + AlignFrame af = viewport.getAlignPanel().alignFrame; + if (af != null) + { + af.changeColour(JSONFile.getColourScheme()); + af.setMenusForViewport(); + } } else { @@ -3073,4 +3083,16 @@ public class Desktop extends jalview.jbgui.GDesktop implements myTopFrame.setDisplayedView(myTopFrame.alignPanel); } + + public static AlignFrame getCurrentAlignFrame() + { + return currentAlignFrame; + } + + public static void setCurrentAlignFrame(AlignFrame currentAlignFrame) + { + Desktop.currentAlignFrame = currentAlignFrame; + } + + } 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 e902ccf..b2f8b2b 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -22,13 +22,17 @@ package jalview.io; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; import java.io.IOException; +import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; +import java.util.List; import java.util.Vector; /** @@ -54,6 +58,11 @@ public abstract class AlignFile extends FileParse protected Vector annotations; /** + * SequenceGroups to be added to the alignment object + */ + protected List seqGroups; + + /** * Properties to be added to generated alignment object */ protected Hashtable properties; @@ -165,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 */ @@ -206,6 +220,12 @@ public abstract class AlignFile extends FileParse } + public void addSeqGroups(AlignmentI al) + { + this.seqGroups = al.getGroups(); + + } + /** * Add any additional information extracted from the file to the alignment * properties. @@ -269,6 +289,7 @@ public abstract class AlignFile extends FileParse { seqs = new Vector(); annotations = new Vector(); + seqGroups = new ArrayList(); parseCalled=false; } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index c69a0c7..649aad3 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -47,7 +47,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", - "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, "HTML" }; + "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, + "HTML" }; /** * List of readable format file extensions by application in order @@ -55,7 +56,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, "jar,jvp", "html" }; + "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, + "jar,jvp", "html" }; /** * List of readable formats by application in order corresponding to @@ -63,7 +65,7 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", - "RNAML", PhylipFile.FILE_DESC, "Jalview", "HTML" }; + "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview", "HTML" }; /** * List of valid format strings for use by callers of the formatSequences @@ -71,7 +73,7 @@ public class AppletFormatAdapter */ public static final String[] WRITEABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", - "STH", PhylipFile.FILE_DESC }; + "STH", PhylipFile.FILE_DESC, JSONFile.FILE_DESC }; /** * List of extensions corresponding to file format types in WRITABLE_FNAMES @@ -79,7 +81,7 @@ public class AppletFormatAdapter */ public static final String[] WRITABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", PhylipFile.FILE_EXT, "jvp" }; + "sto,stk", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, "jvp" }; /** * List of writable formats by the application. Order must correspond with the @@ -87,7 +89,7 @@ public class AppletFormatAdapter */ public static final String[] WRITABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH", - PhylipFile.FILE_DESC, "Jalview" }; + PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview" }; public static String INVALID_CHARACTERS = "Contains invalid characters"; @@ -265,10 +267,10 @@ public class AppletFormatAdapter { afile = new PhylipFile(inFile, type); } - // else if (format.equals(HtmlFile.FILE_DESC)) - // { - // afile = new HtmlFile(inFile, type); - // } + else if (format.equals(JSONFile.FILE_DESC)) + { + afile = new JSONFile(inFile, type); + } else if (format.equals("RNAML")) { afile = new RnamlFile(inFile, type); @@ -277,6 +279,7 @@ public class AppletFormatAdapter Alignment al = new Alignment(afile.getSeqsAsArray()); afile.addAnnotations(al); + afile.addSeqGroups(al); return al; } catch (Exception e) @@ -299,6 +302,8 @@ public class AppletFormatAdapter // Possible sequence is just residues with no label afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); Alignment al = new Alignment(afile.getSeqsAsArray()); + + afile.addSeqGroups(al); afile.addAnnotations(al); return al; @@ -393,13 +398,14 @@ public class AppletFormatAdapter { afile = new PhylipFile(source); } - // else if (format.equals(HtmlFile.FILE_DESC)) - // { - // afile = new HtmlFile(source); - // } + else if (format.equals(JSONFile.FILE_DESC)) + { + afile = new JSONFile(source); + } Alignment al = new Alignment(afile.getSeqsAsArray()); afile.addAnnotations(al); + afile.addSeqGroups(al); return al; } catch (Exception e) @@ -423,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) @@ -491,7 +498,6 @@ public class AppletFormatAdapter try { AlignFile afile = null; - if (format.equalsIgnoreCase("FASTA")) { afile = new FastaFile(); @@ -532,10 +538,25 @@ public class AppletFormatAdapter { afile = new PhylipFile(); } - // else if (format.equalsIgnoreCase(HtmlFile.FILE_DESC)) - // { - // afile = new HtmlFile(); - // } + else if (format.equalsIgnoreCase(JSONFile.FILE_DESC)) + { + afile = new JSONFile(); + // Add groups to AlignFile + afile.seqGroups = alignment.getGroups(); + + // Add non auto calculated annotation to AlignFile + for (AlignmentAnnotation annot : alignment.getAlignmentAnnotation()) + { + if (annot != null && !annot.autoCalculated) + { + if (annot.label.equals("PDB.CATempFactor")) + { + continue; + } + afile.annotations.add(annot); + } + } + } else if (format.equalsIgnoreCase("RNAML")) { afile = new RnamlFile(); @@ -550,6 +571,7 @@ public class AppletFormatAdapter afile.setSeqs(alignment.getSequencesArray()); + String afileresp = afile.print(); if (afile.hasWarningMessage()) { diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index d2c4a7f..4945306 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -7,9 +7,9 @@ import jalview.datamodel.SequenceI; import jalview.exceptions.NoFileSelectedException; import jalview.gui.AlignmentPanel; import jalview.gui.FeatureRenderer; -import jalview.json.binding.v1.BioJsAlignmentPojo; -import jalview.json.binding.v1.BioJsFeaturePojo; -import jalview.json.binding.v1.BioJsSeqPojo; +import jalview.json.binding.v1.AlignmentPojo; +import jalview.json.binding.v1.SequenceFeaturesPojo; +import jalview.json.binding.v1.SequencePojo; import jalview.schemes.ColourSchemeProperty; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -117,11 +117,11 @@ public class BioJsHTMLOutput public String getJalviewAlignmentAsJsonString(AlignmentI alignment) throws IOException, JSONException { - BioJsAlignmentPojo bjsAlignment = new BioJsAlignmentPojo(); + AlignmentPojo bjsAlignment = new AlignmentPojo(); - bjsAlignment.setGlobalColorScheme(getGlobalColorScheme()); - bjsAlignment.setJalviewVersion(jalviewVersion); - bjsAlignment.setWebStartUrl(webStartLaunchServletUrl); + // bjsAlignment.setGlobalColorScheme(getGlobalColorScheme()); + // bjsAlignment.setJalviewVersion(jalviewVersion); + // bjsAlignment.setWebStartUrl(webStartLaunchServletUrl); int count = 0; for (SequenceI seq : alignment.getSequences()) @@ -130,7 +130,7 @@ public class BioJsHTMLOutput name.append(seq.getName()).append("/").append(seq.getStart()) .append("-").append(seq.getEnd()); - BioJsSeqPojo seqPojo = new BioJsSeqPojo(); + SequencePojo seqPojo = new SequencePojo(); seqPojo.setId(String.valueOf(++count)); seqPojo.setEnd(seq.getEnd()); seqPojo.setStart(seq.getStart()); @@ -140,7 +140,7 @@ public class BioJsHTMLOutput SequenceFeature[] seqFeatures = seq.getSequenceFeatures(); if (seqFeatures != null) { - ArrayList bjsSeqFeatures = new ArrayList(); + ArrayList bjsSeqFeatures = new ArrayList(); for (SequenceFeature sf : seqFeatures) { if (displayedFeatures != null @@ -151,15 +151,15 @@ public class BioJsHTMLOutput String featureColour = jalview.util.Format.getHexString(fr .findFeatureColour(Color.white, seq, seq.findIndex(sf.getBegin()))); - BioJsFeaturePojo bjsFeature = new BioJsFeaturePojo(); - bjsFeature.setFillColor(featureColour); - bjsFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); - bjsFeature.setXend(seq.findIndex(sf.getEnd())); - bjsFeature.setText(sf.getType()); - bjsSeqFeatures.add(bjsFeature); + // SequenceFeaturesPojo bjsFeature = new SequenceFeaturesPojo(); + // bjsFeature.setFillColor(featureColour); + // bjsFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); + // bjsFeature.setXend(seq.findIndex(sf.getEnd())); + // bjsFeature.setType(sf.getType()); + // bjsSeqFeatures.add(bjsFeature); } } - seqPojo.setFeatures(bjsSeqFeatures); + // seqPojo.setFeatures(bjsSeqFeatures); } bjsAlignment.getSeqs().add(seqPojo); } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 3322689..cd9258c 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -30,7 +30,6 @@ import jalview.gui.Jalview2XML; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; -import java.util.List; import java.util.StringTokenizer; import java.util.Vector; @@ -323,7 +322,7 @@ public class FileLoader implements Runnable } if (sq.getPDBId() != null) { - for (PDBEntry pdbe : (List) sq.getPDBId()) + for (PDBEntry pdbe : sq.getPDBId()) { StructureSelectionManager.getStructureSelectionManager( Desktop.instance).registerPDBEntry(pdbe); @@ -350,8 +349,12 @@ public class FileLoader implements Runnable if (source instanceof HtmlFile) { ((HtmlFile) source).LoadAlignmentFeatures(alignFrame); - } + else if (source instanceof JSONFile) + { + ((JSONFile) source).LoadAlignmentFeatures(alignFrame); + } + if (raiseGUI) { // add the window to the GUI diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index dfbdf86..74410a1 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -259,17 +259,20 @@ public class FormatAdapter extends AppletFormatAdapter throws java.io.IOException { Alignment al; - if (format.equals("HTML")) + if (format.equals(JSONFile.FILE_DESC)) { - afile = new HtmlFile(inFile, type); + 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); } - return al; } @@ -277,11 +280,12 @@ public class FormatAdapter extends AppletFormatAdapter throws java.io.IOException { Alignment al; - if (format.equals("HTML")) + if (format.equals(JSONFile.FILE_DESC)) { - afile = new HtmlFile(source); + afile = new JSONFile(source); al = new Alignment(afile.getSeqsAsArray()); afile.addAnnotations(al); + afile.addSeqGroups(al); } else { @@ -323,4 +327,5 @@ public class FormatAdapter extends AppletFormatAdapter return formatSequences(format, getCacheSuffixDefault(format), av, selectedOnly); } + } diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 3cb7c3f..aadf246 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -1,17 +1,10 @@ package jalview.io; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceFeature; import jalview.gui.AlignFrame; -import jalview.json.binding.v1.BioJsAlignmentPojo.JalviewBioJsColorSchemeMapper; import jalview.schemes.ColourSchemeI; import java.io.IOException; -import java.util.Iterator; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -56,68 +49,73 @@ public class HtmlFile extends AlignFile Element content = doc.getElementById("seqData"); String alignmentJsonString = content.val(); - JSONParser jsonParser = new JSONParser(); - JSONObject alignmentJsonObj = (JSONObject) jsonParser - .parse(alignmentJsonString); - JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs"); - String bioJsColourScheme = (String) alignmentJsonObj - .get("globalColorScheme"); - cs = getJalviewColorScheme(bioJsColourScheme); - - for (Iterator sequenceIter = seqJsonArray.iterator(); sequenceIter - .hasNext();) - { - JSONObject sequence = sequenceIter.next(); - String sequcenceString = sequence.get("seq").toString(); - Sequence seq = new Sequence(sequence.get("name").toString(), - sequcenceString, Integer.valueOf(sequence.get("start") - .toString()), Integer.valueOf(sequence.get("end") - .toString())); - - JSONArray jsonSeqArray = (JSONArray) sequence.get("features"); - SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures( - jsonSeqArray, seq); - if (retrievedSeqFeatures != null) - { - seq.setSequenceFeatures(retrievedSeqFeatures); - } - seqs.add(seq); - } + new JSONFile().parse(alignmentJsonString); + + // JSONParser jsonParser = new JSONParser(); + // JSONObject alignmentJsonObj = (JSONObject) jsonParser + // .parse(alignmentJsonString); + // JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs"); + // String bioJsColourScheme = (String) alignmentJsonObj + // .get("globalColorScheme"); + // cs = getJalviewColorScheme(bioJsColourScheme); + // + // for (Iterator sequenceIter = seqJsonArray.iterator(); + // sequenceIter + // .hasNext();) + // { + // JSONObject sequence = sequenceIter.next(); + // String sequcenceString = sequence.get("seq").toString(); + // Sequence seq = new Sequence(sequence.get("name").toString(), + // sequcenceString, Integer.valueOf(sequence.get("start") + // .toString()), Integer.valueOf(sequence.get("end") + // .toString())); + // + // JSONArray jsonSeqArray = (JSONArray) sequence.get("features"); + // SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures( + // jsonSeqArray, seq); + // if (retrievedSeqFeatures != null) + // { + // seq.setSequenceFeatures(retrievedSeqFeatures); + // } + // seqs.add(seq); + // + // } } catch (Exception e) { e.printStackTrace(); } } - public SequenceFeature[] getJalviewSequenceFeatures( - JSONArray jsonSeqFeatures, Sequence seq) - { - SequenceFeature[] seqFeatures = null; - int count = 0; - if (jsonSeqFeatures != null) - { - seqFeatures = new SequenceFeature[jsonSeqFeatures.size()]; - for (@SuppressWarnings("unchecked") - Iterator seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr - .hasNext();) - { - - SequenceFeature sequenceFeature = new SequenceFeature(); - JSONObject jsonFeature = seqFeatureItr.next(); - Long begin = (Long) jsonFeature.get("xStart"); - Long end = (Long) jsonFeature.get("xEnd"); - String type = (String) jsonFeature.get("text"); - // String color = (String) jsonFeature.get("fillColor"); - - sequenceFeature.setBegin(seq.findPosition(begin.intValue())); - sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1); - sequenceFeature.setType(type); - seqFeatures[count++] = sequenceFeature; - } - } - return seqFeatures; - } + // public SequenceFeature[] getJalviewSequenceFeatures( + // JSONArray jsonSeqFeatures, Sequence seq) + // { + // SequenceFeature[] seqFeatures = null; + // int count = 0; + // if (jsonSeqFeatures != null) + // { + // seqFeatures = new SequenceFeature[jsonSeqFeatures.size()]; + // for (@SuppressWarnings("unchecked") + // Iterator seqFeatureItr = jsonSeqFeatures.iterator(); + // seqFeatureItr + // .hasNext();) + // { + // + // SequenceFeature sequenceFeature = new SequenceFeature(); + // JSONObject jsonFeature = seqFeatureItr.next(); + // Long begin = (Long) jsonFeature.get("xStart"); + // Long end = (Long) jsonFeature.get("xEnd"); + // String type = (String) jsonFeature.get("text"); + // // String color = (String) jsonFeature.get("fillColor"); + // + // sequenceFeature.setBegin(seq.findPosition(begin.intValue())); + // sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1); + // sequenceFeature.setType(type); + // seqFeatures[count++] = sequenceFeature; + // } + // } + // return seqFeatures; + // } public void LoadAlignmentFeatures(AlignFrame af) { @@ -127,20 +125,20 @@ public class HtmlFile extends AlignFile af.setMenusForViewport(); } - private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName) - { - ColourSchemeI jalviewColor = null; - for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper - .values()) - { - if (cs.getBioJsName().equals(bioJsColourSchemeName)) - { - jalviewColor = cs.getJvColourScheme(); - break; - } - } - return jalviewColor; - } + // private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName) + // { + // ColourSchemeI jalviewColor = null; + // for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + // .values()) + // { + // if (cs.getBioJsName().equals(bioJsColourSchemeName)) + // { + // jalviewColor = cs.getJvColourScheme(); + // break; + // } + // } + // return jalviewColor; + // } @Override public String print() diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 25cef72..a87f34a 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -136,6 +136,11 @@ public class IdentifyFile break; } + if (data.indexOf("{\"") > -1) + { + reply = JSONFile.FILE_DESC; + break; + } // if (data.matches("<(\"[^\"]*\"|'[^']*'|[^'\">])*>")) if (data.matches("<(?i)html(\"[^\"]*\"|'[^']*'|[^'\">])*>")) { diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java new file mode 100644 index 0000000..26ffb7c --- /dev/null +++ b/src/jalview/io/JSONFile.java @@ -0,0 +1,546 @@ +package jalview.io; + +import jalview.api.FeaturesDisplayedI; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Annotation; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.json.binding.v1.AlignmentAnnotationPojo; +import jalview.json.binding.v1.AlignmentPojo; +import jalview.json.binding.v1.AnnotationPojo; +import jalview.json.binding.v1.JalviewSettingsPojo; +import jalview.json.binding.v1.JalviewSettingsPojo.JalviewBioJsColorSchemeMapper; +import jalview.json.binding.v1.SequenceFeaturesPojo; +import jalview.json.binding.v1.SequenceGrpPojo; +import jalview.json.binding.v1.SequencePojo; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ColourSchemeProperty; +import jalview.viewmodel.AlignmentViewport; + +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 static ColourSchemeI colourScheme; + + private static boolean seqFeaturesEnabled; + + private String jalviewVersion; + + private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp"; + + public static final String FILE_EXT = "json"; + + public static final String FILE_DESC = "JSON"; + + private String globalColorScheme; + + private boolean showSeqFeatures; + + private Hashtable seqMap; + + private FeaturesDisplayedI displayedFeatures; + + private AlignmentViewport av; + + private jalview.api.FeatureRenderer fr; + + public JSONFile() + { + super(); + } + + public JSONFile(FileParse source) throws IOException + { + super(source); + } + + public JSONFile(String inFile, String type) throws IOException + { + super(inFile, type); + } + + @Override + public void parse() throws IOException + { + StringBuilder jsonStringBuilder = new StringBuilder(); + String currentLine; + while ((currentLine = nextLine()) != null) + { + jsonStringBuilder.append(currentLine); + } + parse(jsonStringBuilder.toString()); + + } + + @Override + public String print() + { + try + { + JSONExportSettings exportSettings = new JSONExportSettings(); + exportSettings.setExportAnnotations(true); + exportSettings.setExportGroups(true); + exportSettings.setExportJalviewSettings(true); + exportSettings.setExportSequenceFeatures(true); + + AlignmentPojo jsonAlignmentPojo = new AlignmentPojo(); + if (Desktop.getCurrentAlignFrame() != null) + { + globalColorScheme = ColourSchemeProperty.getColourName(Desktop + .getCurrentAlignFrame().getViewport() + .getGlobalColourScheme()); + this.av = Desktop.getCurrentAlignFrame().getCurrentView(); + this.fr = Desktop.getCurrentAlignFrame().alignPanel + .cloneFeatureRenderer(); + displayedFeatures = av.getFeaturesDisplayed(); + showSeqFeatures = Desktop.getCurrentAlignFrame().showSeqFeatures + .isSelected(); + } + + int count = 0; + for (SequenceI seq : seqs) + { + StringBuilder name = new StringBuilder(); + name.append(seq.getName()).append("/").append(seq.getStart()) + .append("-").append(seq.getEnd()); + SequencePojo jsonSeqPojo = new SequencePojo(); + jsonSeqPojo.setId(seq.getName() + "_" + seq.hashCode()); + jsonSeqPojo.setOrder(++count); + jsonSeqPojo.setEnd(seq.getEnd()); + jsonSeqPojo.setStart(seq.getStart()); + jsonSeqPojo.setName(name.toString()); + jsonSeqPojo.setSeq(seq.getSequenceAsString()); + jsonAlignmentPojo.getSeqs().add(jsonSeqPojo); + } + + if (exportSettings.isExportJalviewSettings()) + { + JalviewSettingsPojo jvSettings = new JalviewSettingsPojo(); + jvSettings.setGlobalColorScheme(globalColorScheme); + jvSettings.setJalviewVersion(jalviewVersion); + jvSettings.setWebStartUrl(webStartLaunchServletUrl); + jvSettings.setShowSeqFeatures(showSeqFeatures); + jsonAlignmentPojo.setJalviewSettings(jvSettings); + } + + if (exportSettings.isExportAnnotations()) + { + jsonAlignmentPojo + .setAlignAnnotation(annotationToJsonPojo(annotations)); + } + + if (exportSettings.isExportSequenceFeatures()) + { + jsonAlignmentPojo.setSeqFeatures(sequenceFeatureToJsonPojo(seqs, + displayedFeatures)); + } + + if (exportSettings.isExportGroups() && seqGroups.size() > 0) + { + ArrayList sequenceGroupsPojo = new ArrayList(); + for (SequenceGroup seqGrp : seqGroups) + { + SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo(); + seqGrpPojo.setGroupName(seqGrp.getName()); + seqGrpPojo.setColourScheme(ColourSchemeProperty + .getColourName(seqGrp.cs)); + seqGrpPojo.setColourText(seqGrp.getColourText()); + seqGrpPojo.setDescription(seqGrp.getDescription()); + seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes()); + seqGrpPojo.setDisplayText(seqGrp.getDisplayText()); + seqGrpPojo.setEndRes(seqGrp.getEndRes()); + seqGrpPojo.setStartRes(seqGrp.getStartRes()); + seqGrpPojo.setShowNonconserved(seqGrp.getShowNonconserved()); + for (SequenceI seq : seqGrp.getSequences()) + { + seqGrpPojo.getSeqsHash().add( + seq.getName() + "_" + seq.hashCode()); + } + jsonAlignmentPojo.getSeqGroups().add(seqGrpPojo); + } + } + com.json.JSONObject generatedJSon = new com.json.JSONObject( + jsonAlignmentPojo); + String jsonOutput = generatedJSon.toString(); + return jsonOutput.replaceAll("xstart", "xStart").replaceAll("xend", + "xEnd"); + } catch (Exception e) + { + e.printStackTrace(); + throw e; + } + } + + public static List sequenceFeatureToJsonPojo( + List seqs, FeaturesDisplayedI displayedFeatures) + { + List sequenceFeaturesPojo = new ArrayList(); + for (SequenceI seq : seqs) + { + SequenceI dataSetSequence = seq.getDatasetSequence(); + SequenceFeature[] seqFeatures = (dataSetSequence == null) ? null + : seq.getDatasetSequence().getSequenceFeatures(); + for (SequenceFeature sf : seqFeatures) + { + if (displayedFeatures != null + && displayedFeatures.isVisible(sf.getType())) + { + // String fillColor = ((fr != null) ? jalview.util.Format + // .getHexString(fr.findFeatureColour(Color.white, seq, + // seq.findIndex(sf.getBegin()))) : null); + SequenceFeaturesPojo jsonFeature = new SequenceFeaturesPojo( + seq.getName() + "_" + seq.hashCode()); + jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); + jsonFeature.setXend(seq.findIndex(sf.getEnd())); + jsonFeature.setType(sf.getType()); + jsonFeature.setDescription(sf.getDescription()); + jsonFeature.setLinks(sf.links); + jsonFeature.setOtherDetails(sf.otherDetails); + jsonFeature.setScore(sf.getScore()); + // jsonFeature.setFillColor(fillColor); + jsonFeature.setFeatureGroup(sf.getFeatureGroup()); + sequenceFeaturesPojo.add(jsonFeature); + } + } + } + return sequenceFeaturesPojo; + } + + public static List annotationToJsonPojo( + Vector annotations) + { + List jsonAnnotations = new ArrayList(); + for (AlignmentAnnotation annot : annotations) + { + AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo(); + alignAnnotPojo.setDescription(annot.description); + alignAnnotPojo.setLabel(annot.label); + for (Annotation annotation : annot.annotations) + { + AnnotationPojo annotationPojo = new AnnotationPojo(); + if (annotation != null) + { + annotationPojo.setDescription(annotation.description); + annotationPojo.setValue(annotation.value); + annotationPojo + .setSecondaryStructure(annotation.secondaryStructure); + annotationPojo.setDisplayCharacter(annotation.displayCharacter); + alignAnnotPojo.getAnnotations().add(annotationPojo); + } + else + { + alignAnnotPojo.getAnnotations().add(annotationPojo); + } + } + jsonAnnotations.add(alignAnnotPojo); + } + return jsonAnnotations; + } + + public void parse(String jsonAlignmentString) + { + try + { + JSONParser jsonParser = new JSONParser(); + JSONObject alignmentJsonObj = (JSONObject) jsonParser + .parse(jsonAlignmentString); + JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs"); + JSONArray alAnnotJsonArray = (JSONArray) alignmentJsonObj + .get("alignAnnotation"); + JSONArray jsonSeqArray = (JSONArray) alignmentJsonObj + .get("seqFeatures"); + JSONArray seqGrpJsonArray = (JSONArray) alignmentJsonObj + .get("seqGroups"); + JSONObject jvSettingsJsonObj = (JSONObject) alignmentJsonObj + .get("jalviewSettings"); + + if (jvSettingsJsonObj != null) + { + String jsColourScheme = (String) jvSettingsJsonObj + .get("globalColorScheme"); + Boolean showFeatures = Boolean.valueOf(jvSettingsJsonObj.get( + "showSeqFeatures").toString()); + setColourScheme(getJalviewColorScheme(jsColourScheme)); + JSONFile.setSeqFeaturesEnabled(showFeatures); + // Desktop.setCurrentSeqFeaturesVisible(showFeatures); + } + + seqMap = new Hashtable(); + // Desktop.setCurrentGlobalColourScheme(cs); + for (Iterator sequenceIter = seqJsonArray.iterator(); sequenceIter + .hasNext();) + { + JSONObject sequence = sequenceIter.next(); + String sequcenceString = sequence.get("seq").toString(); + String sequenceName = sequence.get("name").toString(); + String seqUniqueId = sequence.get("id").toString(); + int start = Integer.valueOf(sequence.get("start").toString()); + int end = Integer.valueOf(sequence.get("end").toString()); + Sequence seq = new Sequence(sequenceName, sequcenceString, start, + end); + seqs.add(seq); + seqMap.put(seqUniqueId, seq); + } + parseFeatures(jsonSeqArray); + + 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 + .hasNext();) + { + JSONObject alAnnot = alAnnotIter.next(); + JSONArray annotJsonArray = (JSONArray) alAnnot.get("annotations"); + Annotation[] annotations = new Annotation[annotJsonArray.size()]; + int count = 0; + for (Iterator annotIter = annotJsonArray.iterator(); annotIter + .hasNext();) + { + JSONObject annot = annotIter.next(); + if (annot == null) + { + annotations[count] = null; + } + else + { + float val = annot.get("value") == null ? null : Float + .valueOf(annot.get("value").toString()); + String desc = annot.get("description") == null ? null : annot + .get("description").toString(); + + char ss = annot.get("secondaryStructure") == null ? null + : annot.get("secondaryStructure").toString().charAt(0); + String displayChar = annot.get("displayCharacter").toString(); + + annotations[count] = new Annotation(displayChar, desc, ss, val); + } + ++count; + } + + AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot + .get("label").toString(), alAnnot.get("description") + .toString(), annotations); + this.annotations.add(alignAnnot); + } + + } catch (Exception e) + { + e.printStackTrace(); + } + } + + + private void parseFeatures(JSONArray jsonSeqFeatures) + { + if (jsonSeqFeatures != null) + { + for (@SuppressWarnings("unchecked") + Iterator seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr + .hasNext();) + { + JSONObject jsonFeature = seqFeatureItr.next(); + 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 featureGrp = (String) jsonFeature.get("featureGroup"); + String descripiton = (String) jsonFeature.get("description"); + String seqRef = (String) jsonFeature.get("sequenceRef"); + Float score = Float.valueOf(jsonFeature.get("score").toString()); + // Hashtable otherDetails = (Hashtable) jsonFeature + // .get("otherDetails"); + // sequenceFeature.otherDetails = otherDetails; + + Sequence seq = seqMap.get(seqRef); + SequenceFeature sequenceFeature = new SequenceFeature(); + JSONArray linksJsonArray = (JSONArray) jsonFeature.get("links"); + if (linksJsonArray != null && linksJsonArray.size() > 0) + { + Iterator linkList = linksJsonArray.iterator(); + while (linkList.hasNext()) + { + String link = linkList.next(); + sequenceFeature.addLink(link); + } + } + sequenceFeature.setFeatureGroup(featureGrp); + sequenceFeature.setScore(score); + sequenceFeature.setDescription(descripiton); + sequenceFeature.setType(type); + sequenceFeature.setBegin(seq.findPosition(begin.intValue())); + sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1); + seq.addSequenceFeature(sequenceFeature); + } + } + } + + private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName) + { + ColourSchemeI jalviewColor = null; + for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + .values()) + { + if (cs.getBioJsName().equalsIgnoreCase(bioJsColourSchemeName)) + { + jalviewColor = cs.getJvColourScheme(); + break; + } + } + return jalviewColor; + } + + public void LoadAlignmentFeatures(AlignFrame af) + { + af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled()); + af.changeColour(getColourScheme()); + af.setMenusForViewport(); + } + + public String getGlobalColorScheme() + { + return globalColorScheme; + } + + public void setGlobalColorScheme(String globalColorScheme) + { + this.globalColorScheme = globalColorScheme; + } + + public static ColourSchemeI getColourScheme() + { + return colourScheme; + } + + public static void setColourScheme(ColourSchemeI colourScheme) + { + JSONFile.colourScheme = colourScheme; + } + + public static boolean isSeqFeaturesEnabled() + { + return seqFeaturesEnabled; + } + + public static void setSeqFeaturesEnabled(boolean seqFeaturesEnabled) + { + JSONFile.seqFeaturesEnabled = seqFeaturesEnabled; + } + + public class JSONExportSettings + { + private boolean exportSequence; + + private boolean exportSequenceFeatures; + + private boolean exportAnnotations; + + private boolean exportGroups; + + private boolean exportJalviewSettings; + + public boolean isExportSequence() + { + return exportSequence; + } + + public void setExportSequence(boolean exportSequence) + { + this.exportSequence = exportSequence; + } + + public boolean isExportSequenceFeatures() + { + return exportSequenceFeatures; + } + + public void setExportSequenceFeatures(boolean exportSequenceFeatures) + { + this.exportSequenceFeatures = exportSequenceFeatures; + } + + public boolean isExportAnnotations() + { + return exportAnnotations; + } + + public void setExportAnnotations(boolean exportAnnotations) + { + this.exportAnnotations = exportAnnotations; + } + + public boolean isExportGroups() + { + return exportGroups; + } + + public void setExportGroups(boolean exportGroups) + { + this.exportGroups = exportGroups; + } + + public boolean isExportJalviewSettings() + { + return exportJalviewSettings; + } + + public void setExportJalviewSettings(boolean exportJalviewSettings) + { + this.exportJalviewSettings = exportJalviewSettings; + } + } +} diff --git a/src/jalview/json/binding/v1/AlignmentAnnotationPojo.java b/src/jalview/json/binding/v1/AlignmentAnnotationPojo.java new file mode 100644 index 0000000..4cdc3d1 --- /dev/null +++ b/src/jalview/json/binding/v1/AlignmentAnnotationPojo.java @@ -0,0 +1,43 @@ +package jalview.json.binding.v1; + +import java.util.ArrayList; +import java.util.List; + +public class AlignmentAnnotationPojo +{ + private String label; + + private String description; + + private List annotations = new ArrayList(); + + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String annotationId) + { + this.description = annotationId; + } + + public List getAnnotations() + { + return annotations; + } + + public void setAnnotations(List annotations) + { + this.annotations = annotations; + } +} diff --git a/src/jalview/json/binding/v1/AlignmentPojo.java b/src/jalview/json/binding/v1/AlignmentPojo.java new file mode 100644 index 0000000..ccf55a4 --- /dev/null +++ b/src/jalview/json/binding/v1/AlignmentPojo.java @@ -0,0 +1,74 @@ +package jalview.json.binding.v1; + +import java.util.ArrayList; +import java.util.List; + +public class AlignmentPojo +{ + private List seqs = new ArrayList(); + + private List alignAnnotation = new ArrayList(); + + private List seqGroups = new ArrayList(); + + private List seqFeatures = new ArrayList(); + + private JalviewSettingsPojo jalviewSettings; + + public AlignmentPojo() + { + } + + public List getSeqs() + { + return seqs; + } + + public void setSeqs(ArrayList seqs) + { + this.seqs = seqs; + } + + public JalviewSettingsPojo getJalviewSettings() + { + return jalviewSettings; + } + + public void setJalviewSettings(JalviewSettingsPojo jalviewSettings) + { + this.jalviewSettings = jalviewSettings; + } + + public List getAlignAnnotation() + { + return alignAnnotation; + } + + public void setAlignAnnotation( + List alignAnnotation) + { + this.alignAnnotation = alignAnnotation; + } + + public List getSeqGroups() + { + return seqGroups; + } + + public void setSeqGroups(List seqGroups) + { + this.seqGroups = seqGroups; + } + + public List getSeqFeatures() + { + return seqFeatures; + } + + public void setSeqFeatures(List seqFeatures) + { + this.seqFeatures = seqFeatures; + } + + +} diff --git a/src/jalview/json/binding/v1/AnnotationPojo.java b/src/jalview/json/binding/v1/AnnotationPojo.java new file mode 100644 index 0000000..2e5aac4 --- /dev/null +++ b/src/jalview/json/binding/v1/AnnotationPojo.java @@ -0,0 +1,54 @@ +package jalview.json.binding.v1; + + +public class AnnotationPojo +{ + private String displayCharacter = ""; + + private String description; + + private char secondaryStructure; + + private float value; + + + public String getDisplayCharacter() + { + return displayCharacter; + } + + public void setDisplayCharacter(String displayCharacter) + { + this.displayCharacter = displayCharacter; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public char getSecondaryStructure() + { + return secondaryStructure; + } + + public void setSecondaryStructure(char secondaryStructure) + { + this.secondaryStructure = secondaryStructure; + } + + public float getValue() + { + return value; + } + + public void setValue(float value) + { + this.value = value; + } +} diff --git a/src/jalview/json/binding/v1/BioJsFeaturePojo.java b/src/jalview/json/binding/v1/BioJsFeaturePojo.java deleted file mode 100644 index 3c2fdda..0000000 --- a/src/jalview/json/binding/v1/BioJsFeaturePojo.java +++ /dev/null @@ -1,60 +0,0 @@ -package jalview.json.binding.v1; - -public class BioJsFeaturePojo -{ - - private int xstart; - - private int xend; - - private String text; - - private String fillColor; - - public BioJsFeaturePojo() - { - } - - - public String getText() - { - return text; - } - - public void setText(String text) - { - this.text = text; - } - - public String getFillColor() - { - return "#" + fillColor; - } - - public void setFillColor(String fillColor) - { - this.fillColor = fillColor; - } - - public int getXstart() - { - return xstart; - } - - public void setXstart(int xstart) - { - this.xstart = xstart; - } - - public int getXend() - { - return xend; - } - - public void setXend(int xend) - { - this.xend = xend; - } - - -} diff --git a/src/jalview/json/binding/v1/BioJsAlignmentPojo.java b/src/jalview/json/binding/v1/JalviewSettingsPojo.java similarity index 75% rename from src/jalview/json/binding/v1/BioJsAlignmentPojo.java rename to src/jalview/json/binding/v1/JalviewSettingsPojo.java index 8e8747f..3cc8824 100644 --- a/src/jalview/json/binding/v1/BioJsAlignmentPojo.java +++ b/src/jalview/json/binding/v1/JalviewSettingsPojo.java @@ -14,34 +14,28 @@ import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; import jalview.schemes.ZappoColourScheme; -import java.util.ArrayList; - -public class BioJsAlignmentPojo +public class JalviewSettingsPojo { private String globalColorScheme = "none"; private String jalviewVersion; private String webStartUrl; - private ArrayList seqs = new ArrayList(); - public BioJsAlignmentPojo() - { + private boolean showSeqFeatures; - } - public ArrayList getSeqs() - { - return seqs; - } + private boolean wrapModeEnabled; - public void setSeqs(ArrayList seqs) + public JalviewSettingsPojo() { - this.seqs = seqs; + } + public String getGlobalColorScheme() { return globalColorScheme; } + public void setGlobalColorScheme(String globalColorScheme) { for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper @@ -53,22 +47,8 @@ public class BioJsAlignmentPojo break; } } - - // JALVIEW colors not in biojs - // Blosum62 - // T-Coffee Scores (almost same with Blosom62 - // RNA Interaction type - no color applied - // RNA Helices - missing - - // BIOJS Colour not in jalview - // schemes.push name: "Lesk", id: "lesk" - // schemes.push name: "Cinema", id: "cinema" - // schemes.push name: "MAE", id: "mae" - // schemes.push name: "Clustal2", id: "clustal2" - } - public String getJalviewVersion() { return jalviewVersion; @@ -89,13 +69,33 @@ public class BioJsAlignmentPojo this.webStartUrl = webStartUrl; } + public boolean isShowSeqFeatures() + { + return showSeqFeatures; + } + + public void setShowSeqFeatures(boolean showSeqFeatures) + { + this.showSeqFeatures = showSeqFeatures; + } + + public boolean isWrapModeEnabled() + { + return wrapModeEnabled; + } + + public void setWrapModeEnabled(boolean wrapModeEnabled) + { + this.wrapModeEnabled = wrapModeEnabled; + } + public enum JalviewBioJsColorSchemeMapper { USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo", null), CLUSTAL("Clustal", "clustal", null), ZAPPO("Zappo", - "zappo", new ZappoColourScheme()), TAYLOR( - "Taylor", "taylor", new TaylorColourScheme()), NUCLEOTIDE( - "Nucleotide", "nucleotide", new NucleotideColourScheme()), PURINE_PYRIMIDINE( + "zappo", new ZappoColourScheme()), TAYLOR("Taylor", "taylor", + new TaylorColourScheme()), NUCLEOTIDE("Nucleotide", + "nucleotide", new NucleotideColourScheme()), PURINE_PYRIMIDINE( "Purine/Pyrimidine", "purine", new PurinePyrimidineColourScheme()), HELIX_PROPENCITY( "Helix Propensity", "helix", new HelixColourScheme()), TURN_PROPENSITY( @@ -105,16 +105,15 @@ public class BioJsAlignmentPojo "Hydrophobic", "hydro", new HydrophobicColourScheme()), // The color types below are not yet supported by BioJs MSA viewer - T_COFFE_SCORES("T-Coffee Scores", "T-Coffee Scores", - null), RNA_INT_TYPE( + T_COFFE_SCORES("T-Coffee Scores", "T-Coffee Scores", null), RNA_INT_TYPE( "RNA Interaction type", "RNA Interaction type", new RNAInteractionColourScheme()), BLOSUM62("Blosum62", "Blosum62", new Blosum62ColourScheme()), RNA_HELICES( "RNA Helices", "RNA Helices", null), PERCENTAGE_IDENTITY( - "% Identity", "pid", - new PIDColourScheme()); + "% Identity", "pid", new PIDColourScheme()); private String jalviewName; + private String bioJsName; private ColourSchemeI jvColourScheme; diff --git a/src/jalview/json/binding/v1/SequenceFeaturesPojo.java b/src/jalview/json/binding/v1/SequenceFeaturesPojo.java new file mode 100644 index 0000000..c970191 --- /dev/null +++ b/src/jalview/json/binding/v1/SequenceFeaturesPojo.java @@ -0,0 +1,137 @@ +package jalview.json.binding.v1; + +import java.util.Hashtable; +import java.util.Vector; + +public class SequenceFeaturesPojo +{ + + private int xstart; + + private int xend; + + private String sequenceRef; + + private String type; + + // private String fillColor; + + private Float score; + + private String description; + + private Hashtable otherDetails; + + private String featureGroup; + + private Vector links; + + public SequenceFeaturesPojo() + { + } + + public SequenceFeaturesPojo(String sequenceRef) + { + this.sequenceRef = sequenceRef; + } + + // public String getFillColor() + // { + // return "#" + fillColor; + // } + // + // public void setFillColor(String fillColor) + // { + // this.fillColor = fillColor; + // } + + public int getXstart() + { + return xstart; + } + + public void setXstart(int xstart) + { + this.xstart = xstart; + } + + public int getXend() + { + return xend; + } + + public void setXend(int xend) + { + this.xend = xend; + } + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public Float getScore() + { + return score; + } + + public void setScore(Float score) + { + this.score = score; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public Hashtable getOtherDetails() + { + return otherDetails; + } + + public void setOtherDetails(Hashtable otherDetails) + { + this.otherDetails = otherDetails; + } + + public Vector getLinks() + { + return links; + } + + public void setLinks(Vector links) + { + this.links = links; + } + + public String getFeatureGroup() + { + return featureGroup; + } + + public void setFeatureGroup(String featureGroup) + { + this.featureGroup = featureGroup; + } + + public String getSequenceRef() + { + return sequenceRef; + } + + public void setSequenceRef(String sequenceRef) + { + this.sequenceRef = sequenceRef; + } +} diff --git a/src/jalview/json/binding/v1/SequenceGrpPojo.java b/src/jalview/json/binding/v1/SequenceGrpPojo.java new file mode 100644 index 0000000..bb0e724 --- /dev/null +++ b/src/jalview/json/binding/v1/SequenceGrpPojo.java @@ -0,0 +1,126 @@ +package jalview.json.binding.v1; + +import java.util.ArrayList; + +public class SequenceGrpPojo +{ + private String colourScheme; + + private String groupName; + + private String description; + + private boolean displayBoxes; + + private boolean displayText; + + private boolean colourText; + + private boolean showNonconserved; + + private int startRes; + + private int endRes; + + private ArrayList seqsHash = new ArrayList(); + + public String getColourScheme() + { + return colourScheme; + } + + public void setColourScheme(String colourScheme) + { + this.colourScheme = colourScheme; + } + + public String getGroupName() + { + return groupName; + } + + public void setGroupName(String groupName) + { + this.groupName = groupName; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public boolean isDisplayBoxes() + { + return displayBoxes; + } + + public void setDisplayBoxes(boolean displayBoxes) + { + this.displayBoxes = displayBoxes; + } + + public boolean isDisplayText() + { + return displayText; + } + + public void setDisplayText(boolean displayText) + { + this.displayText = displayText; + } + + public boolean isColourText() + { + return colourText; + } + + public void setColourText(boolean colourText) + { + this.colourText = colourText; + } + + public boolean isShowNonconserved() + { + return showNonconserved; + } + + public void setShowNonconserved(boolean showNonconserved) + { + this.showNonconserved = showNonconserved; + } + + public int getStartRes() + { + return startRes; + } + + public void setStartRes(int startRes) + { + this.startRes = startRes; + } + + public int getEndRes() + { + return endRes; + } + + public void setEndRes(int endRes) + { + this.endRes = endRes; + } + + public ArrayList getSeqsHash() + { + return seqsHash; + } + + public void setSeqsHash(ArrayList seqsHash) + { + this.seqsHash = seqsHash; + } +} diff --git a/src/jalview/json/binding/v1/BioJsSeqPojo.java b/src/jalview/json/binding/v1/SequencePojo.java similarity index 59% rename from src/jalview/json/binding/v1/BioJsSeqPojo.java rename to src/jalview/json/binding/v1/SequencePojo.java index bac8601..232cefb 100644 --- a/src/jalview/json/binding/v1/BioJsSeqPojo.java +++ b/src/jalview/json/binding/v1/SequencePojo.java @@ -1,9 +1,8 @@ package jalview.json.binding.v1; -import java.util.ArrayList; -public class BioJsSeqPojo +public class SequencePojo { private String seq; @@ -11,17 +10,20 @@ public class BioJsSeqPojo private String id; + private int order; + private int start; private int end; - private ArrayList features = new ArrayList(); + // private ArrayList features = new + // ArrayList(); - public BioJsSeqPojo() + public SequencePojo() { } - public BioJsSeqPojo(int start, int end, String id, String name, String seq) + public SequencePojo(int start, int end, String id, String name, String seq) { this.id = id; this.name = name; @@ -78,13 +80,23 @@ public class BioJsSeqPojo this.end = end; } - public ArrayList getFeatures() + // public ArrayList getFeatures() + // { + // return features; + // } + // + // public void setFeatures(ArrayList features) + // { + // this.features = features; + // } + + public int getOrder() { - return features; + return order; } - public void setFeatures(ArrayList features) + public void setOrder(int order) { - this.features = features; + this.order = order; } } -- 1.7.10.2