import jalview.datamodel.SequenceI;
import jalview.json.binding.biojson.v1.AlignmentAnnotationPojo;
import jalview.json.binding.biojson.v1.AlignmentPojo;
+import jalview.json.binding.biojson.v1.AnnotationDisplaySettingPojo;
import jalview.json.binding.biojson.v1.AnnotationPojo;
import jalview.json.binding.biojson.v1.ColourSchemeMapper;
import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
import jalview.json.binding.biojson.v1.SequenceGrpPojo;
import jalview.json.binding.biojson.v1.SequencePojo;
import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.UserColourScheme;
import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
import java.awt.Color;
private ArrayList<SequenceI> hiddenSequences;
+ private final static String TCOFFEE_SCORE = "TCoffeeScore";
+
public JSONFile()
{
super();
if (exportSettings.isExportAnnotations())
{
jsonAlignmentPojo
- .setAlignAnnotation(annotationToJsonPojo(annotations));
+.setAlignAnnotation(annotationToJsonPojo(
+ annotations, seqs));
}
else
{
}
public static List<AlignmentAnnotationPojo> annotationToJsonPojo(
- Vector<AlignmentAnnotation> annotations)
+ Vector<AlignmentAnnotation> annotations, Vector<SequenceI> seqs)
{
List<AlignmentAnnotationPojo> jsonAnnotations = new ArrayList<AlignmentAnnotationPojo>();
if (annotations == null)
}
for (AlignmentAnnotation annot : annotations)
{
+ AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo();
+ annotSetting.setBelowAlignment(annot.belowAlignment);
+ annotSetting.setCentreColLabels(annot.centreColLabels);
+ annotSetting.setScaleColLabel(annot.centreColLabels);
+ annotSetting.setShowAllColLabels(annot.showAllColLabels);
+ annotSetting.setVisible(annot.visible);
+
+
AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo();
+ alignAnnotPojo.setScore(annot.score);
+ alignAnnotPojo.setCalcId(annot.getCalcId());
alignAnnotPojo.setDescription(annot.description);
alignAnnotPojo.setLabel(annot.label);
+ alignAnnotPojo.setGraphType(annot.graph);
+ alignAnnotPojo.setAnnotationSettings(annotSetting);
+ int seqHash = setAnnotationRefSeq(annot, seqs);
+ alignAnnotPojo.setSequenceRef(seqHash == 0 ? null : String
+ .valueOf(seqHash));
for (Annotation annotation : annot.annotations)
{
AnnotationPojo annotationPojo = new AnnotationPojo();
annotationPojo
.setSecondaryStructure(annotation.secondaryStructure);
annotationPojo.setDisplayCharacter(annotation.displayCharacter);
+ if (annotation.colour != null)
+ {
+ annotationPojo.setColour(jalview.util.Format
+ .getHexString(annotation.colour));
+ }
alignAnnotPojo.getAnnotations().add(annotationPojo);
}
else
{
- alignAnnotPojo.getAnnotations().add(annotationPojo);
+ if (annot.getCalcId() != null
+ && annot.getCalcId().equalsIgnoreCase(TCOFFEE_SCORE))
+ {
+ // do nothing
+ }
+ else
+ {
+ alignAnnotPojo.getAnnotations().add(null);
+ }
}
}
jsonAnnotations.add(alignAnnotPojo);
return jsonAnnotations;
}
+ private static int setAnnotationRefSeq(AlignmentAnnotation annot,
+ Vector<SequenceI> seqs)
+ {
+ if (annot == null || seqs == null || seqs.size() == 0)
+ {
+ return 0;
+ }
+ for (SequenceI seq : seqs)
+ {
+ if (seq == null || seq.getAnnotation() == null)
+ {
+ continue;
+ }
+ for (AlignmentAnnotation seqAnnot : seq.getAnnotation())
+ {
+ if (seqAnnot == annot)
+ {
+ return seq.hashCode();
+ }
+ }
+ }
+ return 0;
+ }
@SuppressWarnings("unchecked")
public JSONFile parse(Reader jsonAlignmentString)
{
.hasNext();)
{
JSONObject alAnnot = alAnnotIter.next();
+ if (alAnnot == null)
+ {
+ continue;
+ }
+ JSONObject diplaySettings = (JSONObject) alAnnot
+ .get("annotationSettings");
+
JSONArray annotJsonArray = (JSONArray) alAnnot.get("annotations");
Annotation[] annotations = new Annotation[annotJsonArray.size()];
int count = 0;
+ String calcId = alAnnot.get("calcId") == null ? "" : alAnnot.get(
+ "calcId").toString();
for (Iterator<JSONObject> annotIter = annotJsonArray.iterator(); annotIter
.hasNext();)
{
.get("secondaryStructure").toString().charAt(0);
String displayChar = annot.get("displayCharacter") == null ? ""
: annot.get("displayCharacter").toString();
-
- annotations[count] = new Annotation(displayChar, desc, ss, val);
+ Color color = annot.get("colour") == null ? Color.white
+ : UserColourScheme.getColourFromString(annot.get(
+ "colour").toString());
+ annotations[count] = new Annotation(displayChar, desc, ss, val,
+ color);
}
++count;
}
AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot
.get("label").toString(), alAnnot.get("description")
.toString(), annotations);
+ alignAnnot.graph = (alAnnot.get("graphType") == null) ? 0 : Integer
+ .valueOf(alAnnot.get("graphType")
+ .toString());
+ alignAnnot.scaleColLabel = (diplaySettings.get("scaleColLabel") == null) ? false
+ : Boolean.valueOf(diplaySettings.get("scaleColLabel")
+ .toString());
+ alignAnnot.showAllColLabels = (diplaySettings
+ .get("showAllColLabels") == null) ? true : Boolean
+ .valueOf(diplaySettings.get("showAllColLabels").toString());
+ alignAnnot.centreColLabels = (diplaySettings.get("centreColLabels") == null) ? true
+ : Boolean.valueOf(diplaySettings.get("centreColLabels")
+ .toString());
+ alignAnnot.belowAlignment = (diplaySettings.get("belowAlignment") == null) ? false
+ : Boolean.valueOf(diplaySettings.get("belowAlignment")
+ .toString());
+ alignAnnot.visible = (diplaySettings.get("visible") == null) ? true
+ : Boolean.valueOf(diplaySettings.get("visible").toString());
+
+
+ alignAnnot.score = alAnnot.get("score") == null ? null : Double
+ .valueOf(alAnnot.get("score").toString());
+ alignAnnot.setCalcId(calcId);
+ String seqHash = (alAnnot.get("sequenceRef") != null) ? alAnnot
+ .get("sequenceRef").toString() : null;
+
+ Sequence sequence = (seqHash != null) ? seqMap.get(seqHash) : null;
+ if (sequence != null)
+ {
+ alignAnnot.sequenceRef = sequence;
+ sequence.addAlignmentAnnotation(alignAnnot);
+ if (alignAnnot.label.equalsIgnoreCase("T-COFFEE"))
+ {
+ alignAnnot.createSequenceMapping(sequence, sequence.getStart(),
+ false);
+ sequence.addAlignmentAnnotation(alignAnnot);
+ alignAnnot.adjustForAlignment();
+ }
+ }
this.annotations.add(alignAnnot);
+ alignAnnot.validateRangeAndDisplay();
}
} catch (Exception e)
{
{
if (annot != null && !annot.autoCalculated)
{
- if (!annot.visible)
- {
- continue;
- }
annotations.add(annot);
}
}
@Attributes(required = false)
private List<AnnotationPojo> annotations = new ArrayList<AnnotationPojo>();
+ @Attributes(
+ required = false,
+ enums = { "0", "1", "2" },
+ description = "Determines the rendered for the annotation<br><ul><li>0 - No graph</li><li>1 - Bar Graph</li><li>2 - Line graph</li></ul>")
+ private int graphType;
+
+ @Attributes(
+ required = false,
+ description = "Reference to the sequence in the alignment<br> if per-sequence annotation")
+ private String sequenceRef;
+
+ @Attributes(
+ required = false,
+ description = "Stores display settings for an annotation")
+ private AnnotationDisplaySettingPojo annotationSettings;
+
+ @Attributes(required = false, description = "Score of the annotation")
+ private double score;
+
+ private String calcId;
+
public String getLabel()
{
return label;
this.annotations = annotations;
}
+ public String getSequenceRef()
+ {
+ return sequenceRef;
+ }
+
+ public void setSequenceRef(String sequenceRef)
+ {
+ this.sequenceRef = sequenceRef;
+ }
+
+ public int getGraphType()
+ {
+ return graphType;
+ }
+
+ public void setGraphType(int graphType)
+ {
+ this.graphType = graphType;
+ }
+
+ public AnnotationDisplaySettingPojo getAnnotationSettings()
+ {
+ return annotationSettings;
+ }
+
+ public void setAnnotationSettings(
+ AnnotationDisplaySettingPojo annotationSettings)
+ {
+ this.annotationSettings = annotationSettings;
+ }
+
+ public double getScore()
+ {
+ return score;
+ }
+
+ public void setScore(double score)
+ {
+ this.score = score;
+ }
+
+ public String getCalcId()
+ {
+ return calcId;
+ }
+
+ public void setCalcId(String calcId)
+ {
+ this.calcId = calcId;
+ }
+
}
--- /dev/null
+package jalview.json.binding.biojson.v1;
+
+public class AnnotationDisplaySettingPojo
+{
+ private boolean scaleColLabel;
+
+ private boolean showAllColLabels;
+
+ private boolean centreColLabels;
+
+ private boolean belowAlignment;
+
+ private boolean visible;
+
+ public boolean isScaleColLabel()
+ {
+ return scaleColLabel;
+ }
+
+ public void setScaleColLabel(boolean scaleColLabel)
+ {
+ this.scaleColLabel = scaleColLabel;
+ }
+
+ public boolean isShowAllColLabels()
+ {
+ return showAllColLabels;
+ }
+
+ public void setShowAllColLabels(boolean showAllColLabels)
+ {
+ this.showAllColLabels = showAllColLabels;
+ }
+
+ public boolean isCentreColLabels()
+ {
+ return centreColLabels;
+ }
+
+ public void setCentreColLabels(boolean centreColLabels)
+ {
+ this.centreColLabels = centreColLabels;
+ }
+
+ public boolean isBelowAlignment()
+ {
+ return belowAlignment;
+ }
+
+ public void setBelowAlignment(boolean belowAlignment)
+ {
+ this.belowAlignment = belowAlignment;
+ }
+
+ public boolean isVisible()
+ {
+ return visible;
+ }
+
+ public void setVisible(boolean visible)
+ {
+ this.visible = visible;
+ }
+}