From: Charles Ofoegbu Date: Thu, 27 Nov 2014 10:15:01 +0000 (+0000) Subject: Merge branch 'bug/JAL-1604_Entire-alignment-submission' into develop X-Git-Tag: Jalview_2_9~139 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=38d52319e75f1882278928184066da1033aef332;hp=b58a17a47d215b541be4d8057eb88072c599087e;p=jalview.git Merge branch 'bug/JAL-1604_Entire-alignment-submission' into develop --- diff --git a/.classpath b/.classpath index f87dd26..4c39421 100644 --- a/.classpath +++ b/.classpath @@ -45,15 +45,15 @@ + - - + diff --git a/.gitignore b/.gitignore index c47ff62..0c12fb0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ /.DS_Store .DS_Store /.com.apple.timemachine.supported +.gitattributes + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 884491a..f72955b 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,15 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/examples/example_biojs.html b/examples/example_biojs.html new file mode 100644 index 0000000..b6f7bec --- /dev/null +++ b/examples/example_biojs.html @@ -0,0 +1,9031 @@ + +
BioJS viewer
+ + + + + + + + Jalview Logo + +
+
+ + + + +
+
+ +
press "Run with JS"
+ + + + + + + + diff --git a/lib/jsoup-1.8.1.jar b/lib/jsoup-1.8.1.jar new file mode 100644 index 0000000..ae717d4 Binary files /dev/null and b/lib/jsoup-1.8.1.jar differ diff --git a/resources/templates/BioJSTemplate.txt b/resources/templates/BioJSTemplate.txt new file mode 100644 index 0000000..bf780bb --- /dev/null +++ b/resources/templates/BioJSTemplate.txt @@ -0,0 +1,9032 @@ + +
BioJS viewer
+ + + + + + + + Jalview Logo + +
+
+ + + + +
+
+ +
press "Run with JS"
+ + + + + + + + \ No newline at end of file diff --git a/src/jalview/exceptions/JalviewException.java b/src/jalview/exceptions/JalviewException.java new file mode 100644 index 0000000..80e0b08 --- /dev/null +++ b/src/jalview/exceptions/JalviewException.java @@ -0,0 +1,25 @@ +package jalview.exceptions; + +@SuppressWarnings("serial") +public class JalviewException extends Exception +{ + public JalviewException(String exceptionMessage) + { + super(exceptionMessage); + } + + public JalviewException() + { + super(); + } + + public JalviewException(String exceptionMessage, Throwable cause) + { + super(exceptionMessage, cause); + } + + public JalviewException(Throwable cause) + { + super(cause); + } +} diff --git a/src/jalview/exceptions/NoFileSelectedException.java b/src/jalview/exceptions/NoFileSelectedException.java new file mode 100644 index 0000000..5c56f47 --- /dev/null +++ b/src/jalview/exceptions/NoFileSelectedException.java @@ -0,0 +1,10 @@ +package jalview.exceptions; + +@SuppressWarnings("serial") +public class NoFileSelectedException extends JalviewException +{ + public NoFileSelectedException(String msg) + { + super(msg); + } +} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 2a804ad..52bd121 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -54,6 +54,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AlignmentProperties; import jalview.io.AnnotationFile; +import jalview.io.BioJsHTMLOutput; import jalview.io.FeaturesFile; import jalview.io.FileLoader; import jalview.io.FormatAdapter; @@ -1232,6 +1233,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); } + @Override + public void bioJSMenuItem_actionPerformed(ActionEvent e) + { + new BioJsHTMLOutput(alignPanel, + alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); + } public void createImageMap(File file, String image) { alignPanel.makePNGImageMap(file, image); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index d24f6c4..632d2b2 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -129,7 +129,7 @@ public class AlignViewport extends AlignmentViewport implements * Keys are the feature types which are currently visible. Note: Values are * not used! */ - Hashtable featuresDisplayed = null; + private Hashtable featuresDisplayed = null; boolean antiAlias = false; @@ -1274,6 +1274,16 @@ public class AlignViewport extends AlignmentViewport implements } } + + public Hashtable getFeaturesDisplayed() + { + return featuresDisplayed; + } + + public void setFeaturesDisplayed(Hashtable featuresDisplayed) + { + this.featuresDisplayed = featuresDisplayed; + } protected SequenceAnnotationOrder getSortAnnotationsBy() { return sortAnnotationsBy; diff --git a/src/jalview/gui/AnnotationExporter.java b/src/jalview/gui/AnnotationExporter.java index 315c3e2..ecf4b8e 100644 --- a/src/jalview/gui/AnnotationExporter.java +++ b/src/jalview/gui/AnnotationExporter.java @@ -210,11 +210,11 @@ public class AnnotationExporter extends JPanel private Hashtable getDisplayedFeatureCols() { Hashtable fcols = new Hashtable(); - if (ap.av.featuresDisplayed == null) + if (ap.av.getFeaturesDisplayed() == null) { return fcols; } - Enumeration en = ap.av.featuresDisplayed.keys(); + Enumeration en = ap.av.getFeaturesDisplayed().keys(); FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider // higher // level diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index d2d9c9c..fe083b0 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -192,20 +192,20 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer // copy over the displayed feature settings if (fr.av != null) { - if (fr.av.featuresDisplayed != null) + if (fr.av.getFeaturesDisplayed() != null) { // update display settings - if (av.featuresDisplayed == null) + if (av.getFeaturesDisplayed() == null) { - av.featuresDisplayed = new Hashtable(fr.av.featuresDisplayed); + av.setFeaturesDisplayed(new Hashtable(fr.av.getFeaturesDisplayed())); } else { - av.featuresDisplayed.clear(); - Enumeration en = fr.av.featuresDisplayed.keys(); + av.getFeaturesDisplayed().clear(); + Enumeration en = fr.av.getFeaturesDisplayed().keys(); while (en.hasMoreElements()) { - av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE); + av.getFeaturesDisplayed().put(en.nextElement(), Boolean.TRUE); } } @@ -349,11 +349,11 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer fm = g.getFontMetrics(); } - if (av.featuresDisplayed == null || renderOrder == null + if (av.getFeaturesDisplayed() == null || renderOrder == null || newFeatureAdded) { findAllFeatures(); - if (av.featuresDisplayed.size() < 1) + if (av.getFeaturesDisplayed().size() < 1) { return; } @@ -388,7 +388,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { type = renderOrder[renderIndex]; - if (type == null || !av.featuresDisplayed.containsKey(type)) + if (type == null || !av.getFeaturesDisplayed().containsKey(type)) { continue; } @@ -682,9 +682,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer findingFeatures = true; - if (av.featuresDisplayed == null) + if (av.getFeaturesDisplayed() == null) { - av.featuresDisplayed = new Hashtable(); + av.setFeaturesDisplayed(new Hashtable()); } allfeatures = new Vector(); @@ -717,7 +717,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer int index = 0; while (index < features.length) { - if (!av.featuresDisplayed.containsKey(features[index].getType())) + if (!av.getFeaturesDisplayed().containsKey(features[index].getType())) { if (featureGroups.containsKey(features[index].getType())) @@ -742,7 +742,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { // this is a new feature type on the alignment. Mark it for // display. - av.featuresDisplayed.put(features[index].getType(), + av.getFeaturesDisplayed().put(features[index].getType(), new Integer(getColour(features[index].getType()) .getRGB())); setOrder(features[index].getType(), 0); @@ -1253,7 +1253,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer sf.description = lastDescriptionAdded; setColour(sf.type, fcol); - av.featuresDisplayed.put(sf.type, getColour(sf.type)); + av.getFeaturesDisplayed().put(sf.type, getColour(sf.type)); try { @@ -1281,9 +1281,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer ffile.parseDescriptionHTML(features[i], false); } - if (av.featuresDisplayed == null) + if (av.getFeaturesDisplayed() == null) { - av.featuresDisplayed = new Hashtable(); + av.setFeaturesDisplayed(new Hashtable()); } if (lastFeatureGroupAdded != null) @@ -1293,7 +1293,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer featureGroups.put(lastFeatureGroupAdded, new Boolean(true)); } setColour(lastFeatureAdded, fcol); - av.featuresDisplayed.put(lastFeatureAdded, + av.getFeaturesDisplayed().put(lastFeatureAdded, getColour(lastFeatureAdded)); findAllFeatures(false); @@ -1386,13 +1386,13 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { if (visibleNew) { - if (av.featuresDisplayed != null) + if (av.getFeaturesDisplayed() != null) { - av.featuresDisplayed.clear(); + av.getFeaturesDisplayed().clear(); } else { - av.featuresDisplayed = new Hashtable(); + av.setFeaturesDisplayed(new Hashtable()); } } if (data == null) @@ -1414,7 +1414,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer // interface object if (((Boolean) data[i][2]).booleanValue()) { - av.featuresDisplayed.put(type, new Integer(getColour(type) + av.getFeaturesDisplayed().put(type, new Integer(getColour(type) .getRGB())); } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 2210148..8f841d1 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -222,7 +222,7 @@ public class FeatureSettings extends JPanel dassourceBrowser = new DasSourceBrowser(this); dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER); - if (af.getViewport().featuresDisplayed == null + if (af.getViewport().getFeaturesDisplayed() == null || fr.renderOrder == null) { fr.findAllFeatures(true); // display everything! @@ -645,7 +645,7 @@ public class FeatureSettings extends JPanel data[dataIndex][0] = type; data[dataIndex][1] = fr.getFeatureStyle(type); data[dataIndex][2] = new Boolean( - af.getViewport().featuresDisplayed.containsKey(type)); + af.getViewport().getFeaturesDisplayed().containsKey(type)); dataIndex++; visibleChecks.removeElement(type); } @@ -1277,7 +1277,7 @@ public class FeatureSettings extends JPanel System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length); for (int i = 0; i < typ.length; i++) { - if (af.viewport.featuresDisplayed.get(typ[i]) == null) + if (af.viewport.getFeaturesDisplayed().get(typ[i]) == null) { typ[i] = null; } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index b608b95..158ae50 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1145,7 +1145,7 @@ public class Jalview2XML view.setFollowHighlight(av.followHighlight); view.setFollowSelection(av.followSelection); view.setIgnoreGapsinConsensus(av.getIgnoreGapsConsensus()); - if (av.featuresDisplayed != null) + if (av.getFeaturesDisplayed() != null) { jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings(); @@ -1180,7 +1180,7 @@ public class Jalview2XML .getColour(renderOrder[ro]).getRGB()); } - setting.setDisplay(av.featuresDisplayed + setting.setDisplay(av.getFeaturesDisplayed() .containsKey(renderOrder[ro])); float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer() .getOrder(renderOrder[ro]); @@ -3604,7 +3604,7 @@ public class Jalview2XML // recover featre settings if (jms.getFeatureSettings() != null) { - af.viewport.featuresDisplayed = new Hashtable(); + af.viewport.setFeaturesDisplayed(new Hashtable()); String[] renderOrder = new String[jms.getFeatureSettings() .getSettingCount()]; for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++) @@ -3656,7 +3656,7 @@ public class Jalview2XML } if (setting.getDisplay()) { - af.viewport.featuresDisplayed.put(setting.getType(), new Integer( + af.viewport.getFeaturesDisplayed().put(setting.getType(), new Integer( setting.getColour())); } } diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 9263cd9..3773a64 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -415,7 +415,7 @@ public class Jalview2XML_V1 if (jms.getFeatureSettings() != null) { - af.viewport.featuresDisplayed = new Hashtable(); + af.viewport.setFeaturesDisplayed(new Hashtable()); String[] renderOrder = new String[jms.getFeatureSettings() .getSettingCount()]; for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++) @@ -429,7 +429,7 @@ public class Jalview2XML_V1 if (setting.getDisplay()) { - af.viewport.featuresDisplayed.put(setting.getType(), new Integer( + af.viewport.getFeaturesDisplayed().put(setting.getType(), new Integer( setting.getColour())); } } diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index c10a4a9..5d3df1a 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -251,8 +251,9 @@ public class SeqPanel extends JPanel implements MouseListener, { for (int i = 0; i < features.length; i++) { - if (av.featuresDisplayed == null - || !av.featuresDisplayed.containsKey(features[i].getType())) + if (av.getFeaturesDisplayed() == null + || !av.getFeaturesDisplayed().containsKey( + features[i].getType())) { continue; } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index d3b19fa..505f609 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -47,7 +47,9 @@ 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 }; // , "SimpleBLAST" }; + "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, "HTML" }; // , + // "SimpleBLAST" + // }; /** * List of valid format strings for use by callers of the formatSequences @@ -79,7 +81,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "jar,jvp", "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT }; // ".blast" + "jar,jvp", "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, + "html" }; // ".blast" /** * List of readable formats by application in order corresponding to @@ -87,7 +90,7 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Jalview", - "Stockholm", "RNAML", PhylipFile.FILE_DESC };// , + "Stockholm", "RNAML", PhylipFile.FILE_DESC, "HTML" };// , // "SimpleBLAST" // }; @@ -109,7 +112,7 @@ public class AppletFormatAdapter for (int i = 0, iSize = els.length - 1; i < iSize; i++) { list.append(els[i]); - list.append(","); + list.append(", "); } list.append(" and " + els[els.length - 1] + "."); return list.toString(); @@ -268,6 +271,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("RNAML")) { afile = new RnamlFile(inFile, type); @@ -392,6 +399,10 @@ public class AppletFormatAdapter { afile = new PhylipFile(source); } + // else if (format.equals(HtmlFile.FILE_DESC)) + // { + // afile = new HtmlFile(source); + // } Alignment al = new Alignment(afile.getSeqsAsArray()); afile.addAnnotations(al); @@ -527,6 +538,10 @@ public class AppletFormatAdapter { afile = new PhylipFile(); } + // else if (format.equalsIgnoreCase(HtmlFile.FILE_DESC)) + // { + // afile = new HtmlFile(); + // } else if (format.equalsIgnoreCase("RNAML")) { afile = new RnamlFile(); diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java new file mode 100644 index 0000000..772337a --- /dev/null +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -0,0 +1,221 @@ +package jalview.io; + +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.exceptions.NoFileSelectedException; +import jalview.gui.AlignViewport; +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.schemes.ColourSchemeProperty; +import jalview.util.MessageManager; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.Hashtable; + +import com.json.JSONException; + +public class BioJsHTMLOutput +{ + private AlignViewport av; + + private FeatureRenderer fr; + + private String globalColorScheme; + + private Hashtable displayedFeatures; + + private String jalviewVersion; + + private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp"; + + public BioJsHTMLOutput(AlignmentPanel ap, + FeatureRenderer fr1) + { + + jalviewVersion = jalview.bin.Cache.getProperty("VERSION"); + webStartLaunchServletUrl = jalview.bin.Cache.getDefault( + "www.jalview.org", "http://www.jalview.org") + + "/services/launchApp"; + if (ap != null) + { + this.av = ap.av; + this.globalColorScheme = ColourSchemeProperty.getColourName(av + .getGlobalColourScheme()); + this.fr = new FeatureRenderer(ap); + fr.transferSettings(fr1); + displayedFeatures = av.getFeaturesDisplayed(); + + exportJalviewAlignmentAsBioJsHtmlFile(); + } + } + + private void exportJalviewAlignmentAsBioJsHtmlFile() + { + try + { + String outputFile = getOutputFile(); + String jalviewAlignmentJson = getJalviewAlignmentAsJsonString(av + .getAlignment()); + String bioJSTemplateString = getBioJsTemplateAsString(this); + String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString + .replaceAll( +"#sequenceData#", jalviewAlignmentJson) + .toString(); + + PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter( + outputFile)); + out.print(generatedBioJsWithJalviewAlignmentAsJson); + out.flush(); + out.close(); + jalview.util.BrowserLauncher.openURL("file:///" + outputFile); + } catch (NoFileSelectedException ex) + { + // do noting if no file was selected + } catch (Exception e) + { + e.printStackTrace(); + } + } + + public String getOutputFile() throws NoFileSelectedException + { + String selectedFile = null; + JalviewFileChooser jvFileChooser = new JalviewFileChooser( + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] + { "html" }, new String[] + { "HTML files" }, "HTML files"); + jvFileChooser.setFileView(new JalviewFileView()); + + // TODO uncomment when supported by MassageManager + jvFileChooser.setDialogTitle(MessageManager + .getString("label.save_as_biojs_html")); + jvFileChooser.setDialogTitle("save as BioJs HTML"); + jvFileChooser.setToolTipText(MessageManager.getString("action.save")); + + int fileChooserOpt = jvFileChooser.showSaveDialog(null); + if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION) + { + jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser + .getSelectedFile().getParent()); + selectedFile = jvFileChooser.getSelectedFile().getPath(); + } + else + { + throw new NoFileSelectedException("No file was selected."); + } + + return selectedFile; + } + + public String getJalviewAlignmentAsJsonString(AlignmentI alignment) + throws IOException, JSONException + { + BioJsAlignmentPojo bjsAlignment = new BioJsAlignmentPojo(); + + bjsAlignment.setGlobalColorScheme(getGlobalColorScheme()); + bjsAlignment.setJalviewVersion(jalviewVersion); + bjsAlignment.setWebStartUrl(webStartLaunchServletUrl); + + int count = 0; + for (SequenceI seq : alignment.getSequences()) + { + StringBuilder name = new StringBuilder(); + name.append(seq.getName()).append("/").append(seq.getStart()) + .append("-").append(seq.getEnd()); + + BioJsSeqPojo seqPojo = new BioJsSeqPojo(); + seqPojo.setId(String.valueOf(++count)); + seqPojo.setEnd(seq.getEnd()); + seqPojo.setStart(seq.getStart()); + seqPojo.setName(name.toString()); + seqPojo.setSeq(seq.getSequenceAsString()); + + SequenceFeature[] seqFeatures = seq.getDatasetSequence() + .getSequenceFeatures(); + if (seqFeatures != null) + { + ArrayList bjsSeqFeatures = new ArrayList(); + for (SequenceFeature sf : seqFeatures) + { + if (displayedFeatures != null + && displayedFeatures.get(sf.getType()) != null) + { + String featureColour = jalview.util.Format.getHexString(fr + .getColour(sf)); + 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); + } + } + seqPojo.setFeatures(bjsSeqFeatures); + } + bjsAlignment.getSeqs().add(seqPojo); + } + + return new com.json.JSONObject(bjsAlignment).toString() + .replaceAll("xstart", "xStart").replaceAll("xend", "xEnd"); + } + + public static String getBioJsTemplateAsString(Object currentObj) + throws IOException + { + InputStreamReader isReader = null; + BufferedReader buffReader = null; + StringBuilder sb = new StringBuilder(); + URL url = currentObj.getClass().getResource( + "/templates/BioJSTemplate.txt"); + if (url != null) + { + try + { + isReader = new InputStreamReader(url.openStream()); + buffReader = new BufferedReader(isReader); + String line; + String lineSeparator = System.getProperty("line.separator"); + while ((line = buffReader.readLine()) != null) + { + sb.append(line).append(lineSeparator); + } + + } catch (Exception ex) + { + ex.printStackTrace(); + } finally + { + if (isReader != null) + { + isReader.close(); + } + + if (buffReader != null) + { + buffReader.close(); + } + } + } + return sb.toString(); + } + + public String getGlobalColorScheme() + { + return globalColorScheme; + } + + public void setGlobalColorScheme(String globalColorScheme) + { + this.globalColorScheme = globalColorScheme; + } + +} diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 82b94c3..833f590 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -152,6 +152,7 @@ public class FileLoader implements Runnable public AlignFrame LoadFileWaitTillLoaded(FileParse source, String format) { this.source = source; + file = source.getInFile(); protocol = source.type; this.format = format; @@ -352,6 +353,11 @@ public class FileLoader implements Runnable { alignFrame.setFileName(file, format); } + if (source instanceof HtmlFile) + { + ((HtmlFile) 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 8ca0c35..df5353c 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -255,6 +255,41 @@ public class FormatAdapter extends AppletFormatAdapter return this.formatSequences(format, alignment, suffix); } + public Alignment readFile(String inFile, String type, String format) + throws java.io.IOException + { + Alignment al; + if (format.equals("HTML")) + { + afile = new HtmlFile(inFile, type); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + } + else + { + al = super.readFile(inFile, type, format); + } + + return al; + } + + public AlignmentI readFromFile(FileParse source, String format) + throws java.io.IOException + { + Alignment al; + if (format.equals("HTML")) + { + afile = new HtmlFile(source); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + } + else + { + al = (Alignment) super.readFromFile(source, format); + } + return al; + } + /** * validate format is valid for IO in Application. This is basically the * AppletFormatAdapter.isValidFormat call with additional checks for diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java new file mode 100644 index 0000000..3cb7c3f --- /dev/null +++ b/src/jalview/io/HtmlFile.java @@ -0,0 +1,152 @@ +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; + +public class HtmlFile extends AlignFile +{ + // public static final String FILE_EXT = "html"; + // + // public static final String FILE_DESC = "HTML"; + + private ColourSchemeI cs; + + public HtmlFile() + { + super(); + } + + public HtmlFile(FileParse source) throws IOException + { + super(source); + } + + public HtmlFile(String inFile, String type) throws IOException + { + super(inFile, type); + } + + @SuppressWarnings("unchecked") + @Override + public void parse() throws IOException + { + try + { + StringBuilder htmlData = new StringBuilder(); + String currentLine; + while ((currentLine = nextLine()) != null) + { + htmlData.append(currentLine); + } + + Document doc = Jsoup.parse(htmlData.toString()); + 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); + + } + } 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.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() + { + throw new UnsupportedOperationException( + "Print method of HtmlFile not yet supported!"); + } + +} diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 9c7478b..4fb2516 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -136,8 +136,14 @@ public class IdentifyFile break; } + // if (data.matches("<(\"[^\"]*\"|'[^']*'|[^'\">])*>")) + if (data.matches("<(?i)html(\"[^\"]*\"|'[^']*'|[^'\">])*>")) + { + reply = "HTML"; + break; + } - if ((data.indexOf("<") > -1)) + if (data.matches("<(?i)rnaml (\"[^\"]*\"|'[^']*'|[^'\">])*>")) { reply = "RNAML"; @@ -275,6 +281,7 @@ public class IdentifyFile break; } + /* * // TODO comment out SimpleBLAST identification for Jalview 2.4.1 else * if (!lineswereskipped && data.indexOf("BLAST")<4) { reply = @@ -320,6 +327,7 @@ public class IdentifyFile public static void main(String[] args) { + for (int i = 0; args != null && i < args.length; i++) { IdentifyFile ider = new IdentifyFile(); diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 387bb7f..4bf8176 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -214,6 +214,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem createPNG = new JMenuItem(); + JMenuItem createBioJS = new JMenuItem(); + JMenuItem createSVG = new JMenuItem(); protected JMenuItem font = new JMenuItem(); @@ -1197,6 +1199,19 @@ public class GAlignFrame extends JInternalFrame htmlMenuItem_actionPerformed(e); } }); + + // TODO uncomment when supported by MassageManager + // createBioJS.setText(MessageManager.getString("label.biojs_html_export")); + createBioJS.setText("BioJS"); + createBioJS.addActionListener(new java.awt.event.ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + bioJSMenuItem_actionPerformed(e); + } + }); + overviewMenuItem.setText(MessageManager .getString("label.overview_window")); overviewMenuItem.addActionListener(new java.awt.event.ActionListener() @@ -1603,7 +1618,6 @@ public class GAlignFrame extends JInternalFrame font_actionPerformed(e); } }); - seqLimits.setText(MessageManager .getString("label.show_sequence_limits")); seqLimits.setState(jalview.bin.Cache.getDefault("SHOW_JVSUFFIX", true)); @@ -2353,6 +2367,7 @@ public class GAlignFrame extends JInternalFrame jMenu2.add(htmlMenuItem); jMenu2.add(epsFile); jMenu2.add(createPNG); + jMenu2.add(createBioJS); jMenu2.add(createSVG); addSequenceMenu.add(addFromFile); addSequenceMenu.add(addFromText); @@ -2611,6 +2626,11 @@ public class GAlignFrame extends JInternalFrame { } + protected void bioJSMenuItem_actionPerformed(ActionEvent e) + { + + } + protected void closeMenuItem_actionPerformed(boolean b) { } diff --git a/src/jalview/json/binding/v1/BioJsAlignmentPojo.java b/src/jalview/json/binding/v1/BioJsAlignmentPojo.java new file mode 100644 index 0000000..8e8747f --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsAlignmentPojo.java @@ -0,0 +1,151 @@ +package jalview.json.binding.v1; + +import jalview.schemes.Blosum62ColourScheme; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.NucleotideColourScheme; +import jalview.schemes.PIDColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.RNAInteractionColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.ZappoColourScheme; + +import java.util.ArrayList; + +public class BioJsAlignmentPojo +{ + private String globalColorScheme = "none"; + + private String jalviewVersion; + + private String webStartUrl; + private ArrayList seqs = new ArrayList(); + + public BioJsAlignmentPojo() + { + + } + public ArrayList getSeqs() + { + return seqs; + } + + public void setSeqs(ArrayList seqs) + { + this.seqs = seqs; + } + public String getGlobalColorScheme() + { + return globalColorScheme; + } + public void setGlobalColorScheme(String globalColorScheme) + { + for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + .values()) + { + if (cs.getJalviewName().equals(globalColorScheme)) + { + this.globalColorScheme = cs.getBioJsName(); + 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; + } + + public void setJalviewVersion(String jalviewVersion) + { + this.jalviewVersion = jalviewVersion; + } + + public String getWebStartUrl() + { + return webStartUrl; + } + + public void setWebStartUrl(String webStartUrl) + { + this.webStartUrl = webStartUrl; + } + + 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( + "Purine/Pyrimidine", "purine", + new PurinePyrimidineColourScheme()), HELIX_PROPENCITY( + "Helix Propensity", "helix", new HelixColourScheme()), TURN_PROPENSITY( + "Turn Propensity", "turn", new TurnColourScheme()), STRAND_PROPENSITY( + "Strand Propensity", "strand", new StrandColourScheme()), BURIED_INDEX( + "Buried Index", "buried", new BuriedColourScheme()), HYDROPHOBIC( + "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( + "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()); + + private String jalviewName; + private String bioJsName; + + private ColourSchemeI jvColourScheme; + + private JalviewBioJsColorSchemeMapper(String jalviewName, + String bioJsName, ColourSchemeI jvColourScheme) + { + this.jalviewName = jalviewName; + this.bioJsName = bioJsName; + this.setJvColourScheme(jvColourScheme); + } + + public String getJalviewName() + { + return jalviewName; + } + + public String getBioJsName() + { + return bioJsName; + } + + public ColourSchemeI getJvColourScheme() + { + return jvColourScheme; + } + + public void setJvColourScheme(ColourSchemeI jvColourScheme) + { + this.jvColourScheme = jvColourScheme; + } + + } +} diff --git a/src/jalview/json/binding/v1/BioJsFeaturePojo.java b/src/jalview/json/binding/v1/BioJsFeaturePojo.java new file mode 100644 index 0000000..3c2fdda --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsFeaturePojo.java @@ -0,0 +1,60 @@ +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/BioJsSeqPojo.java b/src/jalview/json/binding/v1/BioJsSeqPojo.java new file mode 100644 index 0000000..bac8601 --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsSeqPojo.java @@ -0,0 +1,90 @@ +package jalview.json.binding.v1; + +import java.util.ArrayList; + + +public class BioJsSeqPojo +{ + private String seq; + + private String name; + + private String id; + + private int start; + + private int end; + + private ArrayList features = new ArrayList(); + + public BioJsSeqPojo() + { + } + + public BioJsSeqPojo(int start, int end, String id, String name, String seq) + { + this.id = id; + this.name = name; + this.seq = seq; + } + public String getSeq() + { + return seq; + } + + public void setSeq(String seq) + { + this.seq = seq; + } + + public String getName() + { + + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public int getStart() + { + return start; + } + + public void setStart(int start) + { + this.start = start; + } + + public int getEnd() + { + return end; + } + + public void setEnd(int end) + { + this.end = end; + } + + public ArrayList getFeatures() + { + return features; + } + + public void setFeatures(ArrayList features) + { + this.features = features; + } +} diff --git a/test/jalview/io/BioJsHTMLOutputTest.java b/test/jalview/io/BioJsHTMLOutputTest.java new file mode 100644 index 0000000..cbda794 --- /dev/null +++ b/test/jalview/io/BioJsHTMLOutputTest.java @@ -0,0 +1,47 @@ +package jalview.io; + +import jalview.datamodel.Alignment; +import jalview.datamodel.Sequence; + +import java.io.IOException; + +import org.junit.Test; + +import com.json.JSONException; + +public class BioJsHTMLOutputTest +{ + + + @Test + public void getJalviewAlignmentAsJsonString() + { + BioJsHTMLOutput bioJsHtmlOuput = new BioJsHTMLOutput(null, null); + bioJsHtmlOuput.setGlobalColorScheme("Zappo"); + + Sequence[] seqs = new Sequence[1]; + Sequence seq = new Sequence("name", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26); + // SequenceFeature seqFeature = new SequenceFeature("type", "desc", + // "status", 1, 5, "jalview"); + // seq.addSequenceFeature(seqFeature); + seq.setDatasetSequence(seq); + seqs[0] = seq; + + Alignment al = new Alignment(seqs); + try + { + String generatedJson = bioJsHtmlOuput + .getJalviewAlignmentAsJsonString(al); + assert (generatedJson + .equalsIgnoreCase("{\"globalColorScheme\":\"zappo\",\"seqs\":[{\"id\":\"1\",\"start\":1,\"name\":\"name/1-26\",\"features\":[],\"seq\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"end\":26}]}")); + System.out.println("Output : " + generatedJson); + } catch (IOException e) + { + e.printStackTrace(); + } catch (JSONException e) + { + e.printStackTrace(); + } + } + +} diff --git a/test/jalview/io/HtmlFileTest.java b/test/jalview/io/HtmlFileTest.java new file mode 100644 index 0000000..be228b8 --- /dev/null +++ b/test/jalview/io/HtmlFileTest.java @@ -0,0 +1,16 @@ +package jalview.io; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class HtmlFileTest +{ + + @Test + public void test() + { + fail("Not yet implemented"); + } + +} diff --git a/utils/InstallAnywhere/Jalview.iap_xml b/utils/InstallAnywhere/Jalview.iap_xml index c938a0b..41ca030 100755 --- a/utils/InstallAnywhere/Jalview.iap_xml +++ b/utils/InstallAnywhere/Jalview.iap_xml @@ -1040,6 +1040,58 @@ and any path to a file to save to the file]]> + + + + + + false + + + true + + + true + + + + + + + + + + + + false + + + + + + true + + + true + + + true + + + + + + 348699 + + + false + + + 0 + + + + @@ -6185,6 +6237,7 @@ and any path to a file to read from that file]]> + @@ -6922,6 +6975,7 @@ and any path to a file to read from that file]]> +