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, Integer.valueOf(sequence.get("start")
74 .toString()), Integer.valueOf(sequence.get("end")
77 JSONArray jsonSeqArray = (JSONArray) sequence.get("features");
78 SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures(
80 if (retrievedSeqFeatures != null)
82 seq.setSequenceFeatures(retrievedSeqFeatures);
93 public SequenceFeature[] getJalviewSequenceFeatures(
94 JSONArray jsonSeqFeatures, Sequence seq)
96 SequenceFeature[] seqFeatures = null;
98 if (jsonSeqFeatures != null)
100 seqFeatures = new SequenceFeature[jsonSeqFeatures.size()];
101 for (@SuppressWarnings("unchecked")
102 Iterator<JSONObject> seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr
106 SequenceFeature sequenceFeature = new SequenceFeature();
107 JSONObject jsonFeature = seqFeatureItr.next();
108 Long begin = (Long) jsonFeature.get("xStart");
109 Long end = (Long) jsonFeature.get("xEnd");
110 String type = (String) jsonFeature.get("text");
111 // String color = (String) jsonFeature.get("fillColor");
113 sequenceFeature.setBegin(seq.findPosition(begin.intValue()));
114 sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1);
115 sequenceFeature.setType(type);
116 seqFeatures[count++] = sequenceFeature;
122 public void LoadAlignmentFeatures(AlignFrame af)
125 af.setShowSeqFeatures(true);
127 af.setMenusForViewport();
130 private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName)
132 ColourSchemeI jalviewColor = null;
133 for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper
136 if (cs.getBioJsName().equals(bioJsColourSchemeName))
138 jalviewColor = cs.getJvColourScheme();
146 public String print()
148 throw new UnsupportedOperationException(
149 "Print method of HtmlFile not yet supported!");