3 import jalview.datamodel.Sequence;
4 import jalview.datamodel.SequenceFeature;
5 import jalview.gui.AlignFrame;
6 import jalview.json.binding.v1.BioJsAlignmentPojo.JalviewBioJsColorSchemeMapper;
7 import jalview.schemes.ColourSchemeI;
9 import java.io.IOException;
10 import java.util.Iterator;
12 import org.json.simple.JSONArray;
13 import org.json.simple.JSONObject;
14 import org.json.simple.parser.JSONParser;
15 import org.jsoup.Jsoup;
16 import org.jsoup.nodes.Document;
17 import org.jsoup.nodes.Element;
19 public class HtmlFile extends AlignFile
21 // public static final String FILE_EXT = "html";
23 // public static final String FILE_DESC = "HTML";
25 private ColourSchemeI cs;
32 public HtmlFile(FileParse source) throws IOException
37 public HtmlFile(String inFile, String type) throws IOException
42 @SuppressWarnings("unchecked")
44 public void parse() throws IOException
48 StringBuilder htmlData = new StringBuilder();
50 while ((currentLine = nextLine()) != null)
52 htmlData.append(currentLine);
55 Document doc = Jsoup.parse(htmlData.toString());
56 Element content = doc.getElementById("seqData");
58 String alignmentJsonString = content.val();
59 JSONParser jsonParser = new JSONParser();
60 JSONObject alignmentJsonObj = (JSONObject) jsonParser
61 .parse(alignmentJsonString);
62 JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs");
63 String bioJsColourScheme = (String) alignmentJsonObj
64 .get("globalColorScheme");
65 cs = getJalviewColorScheme(bioJsColourScheme);
67 for (Iterator<JSONObject> sequenceIter = seqJsonArray.iterator(); sequenceIter
70 JSONObject sequence = sequenceIter.next();
71 String sequcenceString = sequence.get("seq").toString();
72 Sequence seq = new Sequence(sequence.get("name").toString(),
73 sequcenceString, 0, sequcenceString.length());
75 JSONArray jsonSeqArray = (JSONArray) sequence.get("features");
76 SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures(jsonSeqArray);
77 if (retrievedSeqFeatures != null)
79 seq.setSequenceFeatures(retrievedSeqFeatures);
90 public SequenceFeature[] getJalviewSequenceFeatures(
91 JSONArray jsonSeqFeatures)
93 SequenceFeature[] seqFeatures = null;
95 if (jsonSeqFeatures != null)
97 seqFeatures = new SequenceFeature[jsonSeqFeatures.size()];
98 for (Iterator<JSONObject> seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr
102 SequenceFeature sequenceFeature = new SequenceFeature();
103 JSONObject jsonFeature = seqFeatureItr.next();
104 Long begin = (Long) jsonFeature.get("xStart");
105 Long end = (Long) jsonFeature.get("xEnd");
106 String type = (String) jsonFeature.get("text");
108 String color = (String) jsonFeature.get("fillColor");
110 sequenceFeature.setBegin(begin.intValue());
111 sequenceFeature.setEnd(end.intValue());
112 sequenceFeature.setType(type);
113 seqFeatures[count++] = sequenceFeature;
119 public void LoadAlignmentFeatures(AlignFrame af)
122 af.setShowSeqFeatures(true);
124 af.setMenusForViewport();
127 private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName)
129 ColourSchemeI jalviewColor = null;
130 for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper
133 if (cs.getBioJsName().equals(bioJsColourSchemeName))
135 jalviewColor = cs.getJvColourScheme();
143 public String print()
145 throw new UnsupportedOperationException(
146 "Print method of HtmlFile not yet supported!");