import jalview.api.AlignmentViewPanel;
import jalview.api.ComplexAlignFile;
import jalview.api.FeatureRenderer;
+import jalview.api.FeatureSettingsModelI;
import jalview.api.FeaturesDisplayedI;
import jalview.bin.BuildDetails;
import jalview.datamodel.AlignmentAnnotation;
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.schemes.JalviewColourScheme;
+import jalview.schemes.ResidueColourScheme;
+import jalview.util.ColorUtils;
import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
import java.awt.Color;
private String application = "Jalview";
- public static final String FILE_EXT = "json";
-
- public static final String FILE_DESC = "JSON";
-
private String globalColourScheme;
private boolean showSeqFeatures;
super(source);
}
- public JSONFile(String inFile, String type) throws IOException
+ public JSONFile(String inFile, DataSourceType sourceType)
+ throws IOException
{
- super(inFile, type);
+ super(inFile, sourceType);
}
@Override
}
@Override
- public String print()
+ public String print(SequenceI[] sqs, boolean jvsuffix)
{
String jsonOutput = null;
try
}
int count = 0;
- for (SequenceI seq : seqs)
+ for (SequenceI seq : sqs)
{
StringBuilder name = new StringBuilder();
name.append(seq.getName()).append("/").append(seq.getStart())
if (exportSettings.isExportAnnotations())
{
jsonAlignmentPojo
-.setAlignAnnotation(annotationToJsonPojo(
- annotations, seqs));
+ .setAlignAnnotation(annotationToJsonPojo(annotations));
}
else
{
- if (globalColourScheme.equalsIgnoreCase("RNA Helices"))
+ // These color schemes require annotation, disable them if annotations
+ // are not exported
+ if (globalColourScheme
+ .equalsIgnoreCase(JalviewColourScheme.RNAHelices.toString())
+ || globalColourScheme
+ .equalsIgnoreCase(JalviewColourScheme.TCoffee
+ .toString()))
{
- jsonAlignmentPojo.setGlobalColorScheme("None");
+ jsonAlignmentPojo.setGlobalColorScheme(ResidueColourScheme.NONE);
}
}
if (exportSettings.isExportFeatures())
{
jsonAlignmentPojo
- .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr));
+ .setSeqFeatures(sequenceFeatureToJsonPojo(sqs, fr));
}
if (exportSettings.isExportGroups() && seqGroups != null
{
SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
seqGrpPojo.setGroupName(seqGrp.getName());
- seqGrpPojo.setColourScheme(ColourSchemeProperty
- .getColourName(seqGrp.cs));
+ seqGrpPojo.setColourScheme(seqGrp.cs.getSchemeName());
seqGrpPojo.setColourText(seqGrp.getColourText());
seqGrpPojo.setDescription(seqGrp.getDescription());
seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
}
public List<SequenceFeaturesPojo> sequenceFeatureToJsonPojo(
- List<SequenceI> seqs, FeatureRenderer fr)
+ SequenceI[] sqs, FeatureRenderer fr)
{
displayedFeatures = (fr == null) ? null : fr.getFeaturesDisplayed();
List<SequenceFeaturesPojo> sequenceFeaturesPojo = new ArrayList<SequenceFeaturesPojo>();
- for (SequenceI seq : seqs)
+ if (sqs == null)
+ {
+ return sequenceFeaturesPojo;
+ }
+
+ for (SequenceI seq : sqs)
{
SequenceI dataSetSequence = seq.getDatasetSequence();
SequenceFeature[] seqFeatures = (dataSetSequence == null) ? null
}
public static List<AlignmentAnnotationPojo> annotationToJsonPojo(
- Vector<AlignmentAnnotation> annotations, Vector<SequenceI> seqs)
+ Vector<AlignmentAnnotation> annotations)
{
List<AlignmentAnnotationPojo> jsonAnnotations = new ArrayList<AlignmentAnnotationPojo>();
if (annotations == null)
}
for (AlignmentAnnotation annot : annotations)
{
+ AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo();
+ alignAnnotPojo.setDescription(annot.description);
+ alignAnnotPojo.setLabel(annot.label);
+ if (!Double.isNaN(annot.score))
+ {
+ alignAnnotPojo.setScore(annot.score);
+ }
+ alignAnnotPojo.setCalcId(annot.getCalcId());
+ alignAnnotPojo.setGraphType(annot.graph);
+
AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo();
annotSetting.setBelowAlignment(annot.belowAlignment);
annotSetting.setCentreColLabels(annot.centreColLabels);
- annotSetting.setScaleColLabel(annot.centreColLabels);
+ annotSetting.setScaleColLabel(annot.scaleColLabel);
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);
+ annotSetting.setHasIcon(annot.hasIcons);
alignAnnotPojo.setAnnotationSettings(annotSetting);
- int seqHash = setAnnotationRefSeq(annot, seqs);
- alignAnnotPojo.setSequenceRef(seqHash == 0 ? null : String
- .valueOf(seqHash));
+ SequenceI refSeq = annot.sequenceRef;
+ if (refSeq != null)
+ {
+ alignAnnotPojo.setSequenceRef(String.valueOf(refSeq.hashCode()));
+ }
for (Annotation annotation : annot.annotations)
{
AnnotationPojo annotationPojo = new AnnotationPojo();
annotationPojo.setValue(annotation.value);
annotationPojo
.setSecondaryStructure(annotation.secondaryStructure);
- annotationPojo.setDisplayCharacter(annotation.displayCharacter);
+ String displayChar = annotation.displayCharacter == null ? null
+ : annotation.displayCharacter;
+ // System.out.println("--------------------->[" + displayChar + "]");
+ annotationPojo.setDisplayCharacter(displayChar);
if (annotation.colour != null)
{
annotationPojo.setColour(jalview.util.Format
}
else
{
- alignAnnotPojo.getAnnotations().add(null);
+ alignAnnotPojo.getAnnotations().add(annotationPojo);
}
}
}
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)
{
seqMap.put(seqUniqueId, seq);
}
-
parseFeatures(jsonSeqArray);
for (Iterator<JSONObject> seqGrpIter = seqGrpJsonArray.iterator(); seqGrpIter
}
}
SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null,
- displayBoxes, displayText, colourText,
- startRes, endRes);
+ displayBoxes, displayText, colourText, startRes, endRes);
seqGrp.cs = ColourSchemeMapper.getJalviewColourScheme(colourScheme,
seqGrp);
seqGrp.setShowNonconserved(showNonconserved);
.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();
- Color color = annot.get("colour") == null ? Color.white
- : UserColourScheme.getColourFromString(annot.get(
- "colour").toString());
- annotations[count] = new Annotation(displayChar, desc, ss, val,
- color);
+
+ annotations[count] = new Annotation(displayChar, desc, ss, val);
+ if (annot.get("colour") != null)
+ {
+ Color color = ColorUtils.parseColourString(annot.get(
+ "colour").toString());
+ annotations[count].colour = color;
+ }
}
++count;
}
.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());
+ .valueOf(alAnnot.get("graphType").toString());
+
+ JSONObject diplaySettings = (JSONObject) alAnnot
+ .get("annotationSettings");
+ if (diplaySettings != null)
+ {
+
+ 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.hasIcons = (diplaySettings.get("hasIcon") == null) ? true
+ : Boolean.valueOf(diplaySettings.get("hasIcon")
+ .toString());
+
+ }
+ if (alAnnot.get("score") != null)
+ {
+ alignAnnot.score = Double
+ .valueOf(alAnnot.get("score").toString());
+ }
+
+ String calcId = (alAnnot.get("calcId") == null) ? "" : alAnnot.get(
+ "calcId").toString();
alignAnnot.setCalcId(calcId);
String seqHash = (alAnnot.get("sequenceRef") != null) ? alAnnot
.get("sequenceRef").toString() : null;
alignAnnot.adjustForAlignment();
}
}
- this.annotations.add(alignAnnot);
alignAnnot.validateRangeAndDisplay();
+ this.annotations.add(alignAnnot);
+
}
} catch (Exception e)
{
}
}
+ @Override
public String getGlobalColourScheme()
{
return globalColourScheme;
this.displayedFeatures = displayedFeatures;
}
+ @Override
public void configureForView(AlignmentViewPanel avpanel)
{
+ if (avpanel == null)
+ {
+ return;
+ }
super.configureForView(avpanel);
AlignViewportI viewport = avpanel.getAlignViewport();
AlignmentI alignment = viewport.getAlignment();
fr = avpanel.cloneFeatureRenderer();
// Add non auto calculated annotation to AlignFile
- for (AlignmentAnnotation annot : annots)
+ if (annots != null)
{
- if (annot != null && !annot.autoCalculated)
+ for (AlignmentAnnotation annot : annots)
{
- annotations.add(annot);
+ if (annot != null && !annot.autoCalculated)
+ {
+ annotations.add(annot);
+ }
}
}
- globalColourScheme = ColourSchemeProperty.getColourName(viewport
- .getGlobalColourScheme());
+ globalColourScheme = viewport.getGlobalColourScheme().getSchemeName();
setDisplayedFeatures(viewport.getFeaturesDisplayed());
showSeqFeatures = viewport.isShowSequenceFeatures();
}
+ @Override
public boolean isShowSeqFeatures()
{
return showSeqFeatures;
return hiddenColumns;
}
+ @Override
public ColumnSelection getColumnSelection()
{
return columnSelection;
this.columnSelection = columnSelection;
}
+ @Override
public SequenceI[] getHiddenSequences()
{
if (hiddenSequences == null || hiddenSequences.isEmpty())
this.exportJalviewSettings = exportJalviewSettings;
}
}
+
+ /**
+ * Returns a descriptor for suitable feature display settings with
+ * <ul>
+ * <li>ResNums or insertions features visible</li>
+ * <li>insertions features coloured red</li>
+ * <li>ResNum features coloured by label</li>
+ * <li>Insertions displayed above (on top of) ResNums</li>
+ * </ul>
+ */
+ @Override
+ public FeatureSettingsModelI getFeatureColourScheme()
+ {
+ return new PDBFeatureSettings();
+ }
}