package jalview.io;
+import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.json.binding.v1.AlignmentAnnotationPojo;
import jalview.json.binding.v1.AlignmentPojo;
import jalview.json.binding.v1.AlignmentPojo.JalviewBioJsColorSchemeMapper;
+import jalview.json.binding.v1.AnnotationPojo;
+import jalview.json.binding.v1.FeaturePojo;
import jalview.json.binding.v1.SequencePojo;
import jalview.schemes.ColourSchemeI;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import org.json.simple.JSONArray;
private AlignmentI al;
+ private AlignFrame af;
+
private jalview.api.FeatureRenderer fr;
public JSONFile(AlignmentI al)
// .getColourName(af.getViewport().getGlobalColourScheme()));
jsonAlignmentPojo.setJalviewVersion(jalviewVersion);
jsonAlignmentPojo.setWebStartUrl(webStartLaunchServletUrl);
+ for (AlignmentAnnotation annot : annotations)
+ {
+ AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo();
+ alignAnnotPojo.setDescription(annot.description);
+ alignAnnotPojo.setLabel(annot.label);
+
+ for (Annotation annotation : annot.annotations)
+ {
+ AnnotationPojo annotationPojo = new AnnotationPojo();
+ if (annotation != null)
+ {
+ annotationPojo.setDescription(annotation.description);
+ annotationPojo.setValue(annotation.value);
+ annotationPojo
+ .setSecondaryStructure(annotation.secondaryStructure);
+ annotationPojo.setDisplayCharacter(annotation.displayCharacter);
+ alignAnnotPojo.getAnnotations().add(annotationPojo);
+ }
+ else
+ {
+ alignAnnotPojo.getAnnotations().add(annotationPojo);
+ }
+ }
+ jsonAlignmentPojo.getAlignmentAnnotation().add(alignAnnotPojo);
+ }
int count = 0;
for (SequenceI seq : seqs)
jsonSeqPojo.setName(name.toString());
jsonSeqPojo.setSeq(seq.getSequenceAsString());
jsonAlignmentPojo.getSeqs().add(jsonSeqPojo);
+
+ if (seq.getDatasetSequence() != null
+ && seq.getDatasetSequence().getSequenceFeatures() != null)
+ {
+ ArrayList<FeaturePojo> seqFeaturesPojo = new ArrayList<FeaturePojo>();
+ for (SequenceFeature sf : seq.getDatasetSequence()
+ .getSequenceFeatures())
+ {
+ FeaturePojo jsonFeature = new FeaturePojo();
+ jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1);
+ jsonFeature.setXend(seq.findIndex(sf.getEnd()));
+ jsonFeature.setText(sf.getType());
+ seqFeaturesPojo.add(jsonFeature);
+ }
+ jsonSeqPojo.setFeatures(seqFeaturesPojo);
+ }
+
}
- /**
- * TODO add logic to export Sequence features, non-auto-generated
- * annotations, colour schemes
- */
return new com.json.JSONObject(jsonAlignmentPojo).toString()
.replaceAll("xstart", "xStart").replaceAll("xend", "xEnd");
}
JSONObject alignmentJsonObj = (JSONObject) jsonParser
.parse(jsonAlignmentString);
JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs");
+ JSONArray alAnnotJsonArray = (JSONArray) alignmentJsonObj.get("alignmentAnnotation");
+
String bioJsColourScheme = (String) alignmentJsonObj
.get("globalColorScheme");
cs = getJalviewColorScheme(bioJsColourScheme);
}
seqs.add(seq);
}
+
+ for (Iterator<JSONObject> alAnnotIter = alAnnotJsonArray.iterator(); alAnnotIter
+ .hasNext();)
+ {
+ JSONObject alAnnot = alAnnotIter.next();
+ JSONArray annotJsonArray = (JSONArray) alAnnot
+ .get("annotations");
+ Annotation[] annotations = new Annotation[annotJsonArray.size()];
+ int count = 0;
+ for (Iterator<JSONObject> annotIter = annotJsonArray.iterator(); annotIter
+ .hasNext();)
+ {
+ JSONObject annot = annotIter.next();
+ if (annot == null)
+ {
+ annotations[count] = null;
+ }
+ else
+ {
+ float val = annot.get("value") == null ? null
+ : Float.valueOf(annot.get("value")
+ .toString());
+ String desc = annot.get("description") == null ? null : annot
+ .get("description").toString();
+
+ char ss = annot.get("secondaryStructure") == null ? null
+ : annot
+ .get("secondaryStructure").toString().charAt(0);
+ String displayChar = annot.get(
+ "displayCharacter").toString();
+
+ annotations[count] = new Annotation(displayChar, desc, ss, val);
+ }
+ ++count;
+ }
+
+ AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot
+ .get("label").toString(), alAnnot.get("description")
+ .toString(), annotations);
+ this.annotations.add(alignAnnot);
+ }
+
} catch (Exception e)
{
e.printStackTrace();
return seqFeatures;
}
-
private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName)
{
ColourSchemeI jalviewColor = null;
return jalviewColor;
}
+
public String getGlobalColorScheme()
{
return globalColorScheme;
import jalview.schemes.ZappoColourScheme;
import java.util.ArrayList;
+import java.util.List;
public class AlignmentPojo
{
private String jalviewVersion;
private String webStartUrl;
- private ArrayList<SequencePojo> seqs = new ArrayList<SequencePojo>();
+
+ private List<SequencePojo> seqs = new ArrayList<SequencePojo>();
+
+ private List<AlignmentAnnotationPojo> alignmentAnnotation = new ArrayList<AlignmentAnnotationPojo>();
public AlignmentPojo()
{
}
- public ArrayList<SequencePojo> getSeqs()
+
+ public List<SequencePojo> getSeqs()
{
return seqs;
}
this.webStartUrl = webStartUrl;
}
+ public List<AlignmentAnnotationPojo> getAlignmentAnnotation()
+ {
+ return alignmentAnnotation;
+ }
+
+ public void setAlignmentAnnotation(List<AlignmentAnnotationPojo> alignmentAnnotation)
+ {
+ this.alignmentAnnotation = alignmentAnnotation;
+ }
+
public enum JalviewBioJsColorSchemeMapper
{
USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo",
--- /dev/null
+package jalview.json.binding.v1;
+
+
+public class AnnotationPojo
+{
+ private String displayCharacter = "";
+
+ private String description;
+
+ private char secondaryStructure;
+
+ private float value;
+
+
+ public String getDisplayCharacter()
+ {
+ return displayCharacter;
+ }
+
+ public void setDisplayCharacter(String displayCharacter)
+ {
+ this.displayCharacter = displayCharacter;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ }
+
+ public char getSecondaryStructure()
+ {
+ return secondaryStructure;
+ }
+
+ public void setSecondaryStructure(char secondaryStructure)
+ {
+ this.secondaryStructure = secondaryStructure;
+ }
+
+ public float getValue()
+ {
+ return value;
+ }
+
+ public void setValue(float value)
+ {
+ this.value = value;
+ }
+}