import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentView;
+import jalview.datamodel.SequenceGroup;
import jalview.util.MessageManager;
import java.io.File;
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
*/
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
this.inFile = inFile;
try
{
+ Alignment al;
if (format.equals("FASTA"))
{
afile = new FastaFile(inFile, type);
{
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)
String type = source.type;
try
{
+ Alignment al;
if (format.equals("FASTA"))
{
afile = new FastaFile(source);
{
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)
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;
}
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;
super(inFile, type);
}
- @SuppressWarnings("unchecked")
@Override
public void parse() throws IOException
{
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<JSONObject> 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<JSONObject> 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()
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;
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();
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("<html>"
- + "<style type=\"text/css\"> "
+ htmlSvg.append("<html>\n");
+ if (jsonData != null)
+ {
+ htmlSvg.append("<input type=\"hidden\" name=\"seqData\" id=\"seqData\" value='"
+ + jsonData + "'>");
+ }
+ htmlSvg.append("\n<style type=\"text/css\"> "
+ "div.parent{ width:100%;<!-- overflow: auto; -->}\n"
+ "div.titlex{ width:11%; float: left; }\n"
+ "div.align{ width:89%; float: right; }\n"
if ((data.indexOf("# STOCKHOLM") > -1))
{
reply = "STH";
-
- break;
- }
- if (data.indexOf("{\"") > -1)
- {
- reply = JSONFile.FILE_DESC;
break;
}
// if (data.matches("<(\"[^\"]*\"|'[^']*'|[^'\">])*>"))
if (data.matches("<(?i)html(\"[^\"]*\"|'[^']*'|[^'\">])*>"))
{
- reply = "HTML";
+ reply = HtmlFile.FILE_DESC;
break;
}
if (data.matches("<(?i)rnaml (\"[^\"]*\"|'[^']*'|[^'\">])*>"))
{
reply = "RNAML";
-
break;
}
+ if (data.indexOf("{\"") > -1)
+ {
+ reply = JSONFile.FILE_DESC;
+ break;
+ }
if ((data.length() < 1) || (data.indexOf("#") == 0))
{
lineswereskipped = true;