X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FHtmlFile.java;h=72728300b8b1c627631ca6a383cb4b29a2d9e71f;hb=5d59bb58f5bcecc6b240d125e13bbe1f1868f681;hp=3cb7c3fc612c7af895aa948d02e0c7d7780c8587;hpb=36c3d72e0344f1aaa2137dca8eba829e7395f05a;p=jalview.git diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 3cb7c3f..7272830 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -1,26 +1,19 @@ 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"; + public static final String FILE_EXT = "html"; + + public static final String FILE_DESC = "HTML"; private ColourSchemeI cs; @@ -39,7 +32,6 @@ public class HtmlFile extends AlignFile super(inFile, type); } - @SuppressWarnings("unchecked") @Override public void parse() throws IOException { @@ -54,93 +46,25 @@ public class HtmlFile extends AlignFile 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); - } + 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()