From: tcofoegbu Date: Tue, 12 May 2015 15:42:44 +0000 (+0100) Subject: Merge branch 'features/JAL-793_Embed_data_HTML' into develop X-Git-Tag: Release_2_10_0~681^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4609be9dc7b290edf0c2fbcad9e6b6fc7f919d18;hp=f3b869801edcd73a57ddbb6adbfa02d40652625d;p=jalview.git Merge branch 'features/JAL-793_Embed_data_HTML' into develop --- diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 649aad3..f97a341 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -25,6 +25,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; +import jalview.datamodel.SequenceGroup; import jalview.util.MessageManager; import java.io.File; @@ -57,7 +58,7 @@ 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, JSONFile.FILE_EXT, - "jar,jvp", "html" }; + "jar,jvp", HtmlFile.FILE_EXT }; /** * List of readable formats by application in order corresponding to @@ -65,7 +66,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", - "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview", "HTML" }; + "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview", + HtmlFile.FILE_DESC }; /** * List of valid format strings for use by callers of the formatSequences @@ -215,6 +217,7 @@ public class AppletFormatAdapter this.inFile = inFile; try { + Alignment al; if (format.equals("FASTA")) { afile = new FastaFile(inFile, type); @@ -267,19 +270,37 @@ public class AppletFormatAdapter { afile = new PhylipFile(inFile, type); } - else if (format.equals(JSONFile.FILE_DESC)) - { - afile = new JSONFile(inFile, type); - } + 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); + } + return al; + } + else if (format.equals(HtmlFile.FILE_DESC)) + { + afile = new HtmlFile(inFile, type); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + for (SequenceGroup sg : afile.getSeqGroups()) + { + al.addGroup(sg); + } + return al; + } else if (format.equals("RNAML")) { afile = new RnamlFile(inFile, type); } - Alignment al = new Alignment(afile.getSeqsAsArray()); + al = new Alignment(afile.getSeqsAsArray()); - afile.addAnnotations(al); - afile.addSeqGroups(al); + // afile.addAnnotations(al); + // afile.addSeqGroups(al); return al; } catch (Exception e) @@ -344,6 +365,7 @@ public class AppletFormatAdapter String type = source.type; try { + Alignment al; if (format.equals("FASTA")) { afile = new FastaFile(source); @@ -398,14 +420,19 @@ public class AppletFormatAdapter { afile = new PhylipFile(source); } - else if (format.equals(JSONFile.FILE_DESC)) - { - afile = new JSONFile(source); - } - Alignment al = new Alignment(afile.getSeqsAsArray()); - - afile.addAnnotations(al); - afile.addSeqGroups(al); + else if (format.equals(JSONFile.FILE_DESC)) + { + afile = new JSONFile(source); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + afile.addSeqGroups(al); + return al; + } + else if (format.equals(HtmlFile.FILE_DESC)) + { + afile = new HtmlFile(source); + } + al = new Alignment(afile.getSeqsAsArray()); return al; } catch (Exception e) diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 74410a1..86ec140 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -258,39 +258,14 @@ public class FormatAdapter extends AppletFormatAdapter public Alignment readFile(String inFile, String type, String format) throws java.io.IOException { - Alignment al; - 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); - } + Alignment al = super.readFile(inFile, type, format); return al; } public AlignmentI readFromFile(FileParse source, String format) throws java.io.IOException { - Alignment al; - 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); - } + Alignment al = (Alignment) super.readFromFile(source, format); return al; } diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index aadf246..7272830 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -11,9 +11,9 @@ import org.jsoup.nodes.Element; public class HtmlFile extends AlignFile { - // public static final String FILE_EXT = "html"; - // - // public static final String FILE_DESC = "HTML"; + public static final String FILE_EXT = "html"; + + public static final String FILE_DESC = "HTML"; private ColourSchemeI cs; @@ -32,7 +32,6 @@ public class HtmlFile extends AlignFile super(inFile, type); } - @SuppressWarnings("unchecked") @Override public void parse() throws IOException { @@ -47,98 +46,25 @@ public class HtmlFile extends AlignFile Document doc = Jsoup.parse(htmlData.toString()); Element content = doc.getElementById("seqData"); - String alignmentJsonString = content.val(); - 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); - // - // } + JSONFile jsonFile = new JSONFile().parse(alignmentJsonString); + seqs = jsonFile.seqs; + seqGroups = jsonFile.seqGroups; + annotations = jsonFile.annotations; } 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 void LoadAlignmentFeatures(AlignFrame af) { - - af.setShowSeqFeatures(true); - af.changeColour(cs); + af.setShowSeqFeatures(JSONFile.isSeqFeaturesEnabled()); + af.changeColour(JSONFile.getColourScheme()); 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; - // } @Override public String print() diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index 3c9c608..64dfc1c 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -1,9 +1,12 @@ package jalview.io; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.AnnotationPanel; +import jalview.gui.Desktop; import jalview.gui.FeatureRenderer; import jalview.gui.HTMLOptions; import jalview.math.AlignmentDimension; @@ -100,7 +103,8 @@ public class HtmlSvgOutput String titleSvgData = g1.getSVGDocument(); String alignSvgData = g2.getSVGDocument(); - String htmlData = getHtml(titleSvgData, alignSvgData); + String jsonData = getJSONData(); + String htmlData = getHtml(titleSvgData, alignSvgData, jsonData); out.write(htmlData.getBytes()); out.flush(); @@ -257,11 +261,50 @@ public class HtmlSvgOutput return Printable.PAGE_EXISTS; } - private String getHtml(String titleSvg, String alignmentSvg) + private String getJSONData() + { + JSONFile jsonFile = new JSONFile(); + Alignment al = new Alignment(av.getAlignment().getSequencesArray()); + jsonFile.seqGroups = av.getAlignment().getGroups(); + // jsonFile.addAnnotations(al); + jsonFile.setDisplayedFeatures(av.getFeaturesDisplayed()); + Desktop.setCurrentAlignFrame(av.getAlignPanel().alignFrame); + for (SequenceI seq : av.getAlignment().getSequences()) + { + jsonFile.seqs.add(seq); + } + + // Add non auto calculated annotation to AlignFile + for (AlignmentAnnotation annot : av.getAlignment() + .getAlignmentAnnotation()) + { + if (annot != null && !annot.autoCalculated) + { + if (annot.label.equals("PDB.CATempFactor")) + { + continue; + } + jsonFile.annotations.add(annot); + } + } + + // jsonFile.setGlobalColorScheme(av.getGlobalColourScheme()); + String jsonString = jsonFile.print(); + System.out.println(">>>>>>>>>>> JSONFile : " + jsonString); + return jsonString; + } + + private String getHtml(String titleSvg, String alignmentSvg, + String jsonData) { StringBuilder htmlSvg = new StringBuilder(); - htmlSvg.append("" - + "