+ // ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Write the data to a new entry of given name in the output jar file
+ *
+ * @param jout
+ * @param jarEntryName
+ * @param data
+ * @throws IOException
+ */
+ protected void writeJarEntry(JarOutputStream jout, String jarEntryName,
+ byte[] data) throws IOException
+ {
+ if (jout != null)
+ {
+ System.out.println("Writing jar entry " + jarEntryName);
+ jout.putNextEntry(new JarEntry(jarEntryName));
+ DataOutputStream dout = new DataOutputStream(jout);
+ dout.write(data, 0, data.length);
+ dout.flush();
+ jout.closeEntry();
+ }
+ }
+
+ /**
+ * Save the state of a structure viewer
+ *
+ * @param ap
+ * @param jds
+ * @param pdb
+ * the archive XML element under which to save the state
+ * @param entry
+ * @param viewIds
+ * @param matchedFile
+ * @param viewFrame
+ * @return
+ */
+ protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
+ Pdbids pdb, PDBEntry entry, List<String> viewIds,
+ String matchedFile, StructureViewerBase viewFrame)
+ {
+ final AAStructureBindingModel bindingModel = viewFrame.getBinding();
+
+ /*
+ * Look for any bindings for this viewer to the PDB file of interest
+ * (including part matches excluding chain id)
+ */
+ for (int peid = 0; peid < bindingModel.getPdbCount(); peid++)
+ {
+ final PDBEntry pdbentry = bindingModel.getPdbEntry(peid);
+ final String pdbId = pdbentry.getId();
+ if (!pdbId.equals(entry.getId())
+ && !(entry.getId().length() > 4 && entry.getId().toLowerCase()
+ .startsWith(pdbId.toLowerCase())))
+ {
+ /*
+ * not interested in a binding to a different PDB entry here
+ */
+ continue;
+ }
+ if (matchedFile == null)
+ {
+ matchedFile = pdbentry.getFile();
+ }
+ else if (!matchedFile.equals(pdbentry.getFile()))
+ {
+ Cache.log.warn(
+ "Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): "
+ + pdbentry.getFile());
+ }
+ // record the
+ // file so we
+ // can get at it if the ID
+ // match is ambiguous (e.g.
+ // 1QIP==1qipA)
+
+ for (int smap = 0; smap < viewFrame.getBinding()
+ .getSequence()[peid].length; smap++)
+ {
+ // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
+ if (jds == viewFrame.getBinding().getSequence()[peid][smap])
+ {
+ StructureState state = new StructureState();
+ state.setVisible(true);
+ state.setXpos(viewFrame.getX());
+ state.setYpos(viewFrame.getY());
+ state.setWidth(viewFrame.getWidth());
+ state.setHeight(viewFrame.getHeight());
+ final String viewId = viewFrame.getViewId();
+ state.setViewId(viewId);
+ state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
+ state.setColourwithAlignPanel(viewFrame.isUsedforcolourby(ap));
+ state.setColourByJmol(viewFrame.isColouredByViewer());
+ state.setType(viewFrame.getViewerType().toString());
+ pdb.addStructureState(state);
+ }
+ }
+ }
+ return matchedFile;
+ }
+
+ /**
+ * Populates the AnnotationColours xml for save. This captures the settings of
+ * the options in the 'Colour by Annotation' dialog.
+ *
+ * @param acg
+ * @param userColours
+ * @param jms
+ * @return
+ */
+ private AnnotationColours constructAnnotationColours(
+ AnnotationColourGradient acg, List<UserColourScheme> userColours,
+ JalviewModelSequence jms)
+ {
+ AnnotationColours ac = new AnnotationColours();
+ ac.setAboveThreshold(acg.getAboveThreshold());
+ ac.setThreshold(acg.getAnnotationThreshold());
+ // 2.10.2 save annotationId (unique) not annotation label
+ ac.setAnnotation(acg.getAnnotation().annotationId);
+ if (acg.getBaseColour() instanceof UserColourScheme)
+ {
+ ac.setColourScheme(
+ setUserColourScheme(acg.getBaseColour(), userColours, jms));
+ }
+ else
+ {
+ ac.setColourScheme(
+ ColourSchemeProperty.getColourName(acg.getBaseColour()));
+ }
+
+ ac.setMaxColour(acg.getMaxColour().getRGB());
+ ac.setMinColour(acg.getMinColour().getRGB());
+ ac.setPerSequence(acg.isSeqAssociated());
+ ac.setPredefinedColours(acg.isPredefinedColours());
+ return ac;
+ }
+
+ private void storeAlignmentAnnotation(AlignmentAnnotation[] aa,
+ IdentityHashMap<SequenceGroup, String> groupRefs,
+ AlignmentViewport av, Set<String> calcIdSet, boolean storeDS,
+ SequenceSet vamsasSet)
+ {
+
+ for (int i = 0; i < aa.length; i++)
+ {
+ Annotation an = new Annotation();
+
+ AlignmentAnnotation annotation = aa[i];
+ if (annotation.annotationId != null)
+ {
+ annotationIds.put(annotation.annotationId, annotation);
+ }
+
+ an.setId(annotation.annotationId);
+
+ an.setVisible(annotation.visible);
+
+ an.setDescription(annotation.description);
+
+ if (annotation.sequenceRef != null)
+ {
+ // 2.9 JAL-1781 xref on sequence id rather than name
+ an.setSequenceRef(seqsToIds.get(annotation.sequenceRef));
+ }
+ if (annotation.groupRef != null)
+ {
+ String groupIdr = groupRefs.get(annotation.groupRef);
+ if (groupIdr == null)
+ {
+ // make a locally unique String
+ groupRefs.put(annotation.groupRef,
+ groupIdr = ("" + System.currentTimeMillis()
+ + annotation.groupRef.getName()
+ + groupRefs.size()));
+ }
+ an.setGroupRef(groupIdr.toString());
+ }
+
+ // store all visualization attributes for annotation
+ an.setGraphHeight(annotation.graphHeight);
+ an.setCentreColLabels(annotation.centreColLabels);
+ an.setScaleColLabels(annotation.scaleColLabel);
+ an.setShowAllColLabels(annotation.showAllColLabels);
+ an.setBelowAlignment(annotation.belowAlignment);
+
+ if (annotation.graph > 0)
+ {
+ an.setGraph(true);
+ an.setGraphType(annotation.graph);
+ an.setGraphGroup(annotation.graphGroup);
+ if (annotation.getThreshold() != null)
+ {
+ ThresholdLine line = new ThresholdLine();
+ line.setLabel(annotation.getThreshold().label);
+ line.setValue(annotation.getThreshold().value);
+ line.setColour(annotation.getThreshold().colour.getRGB());
+ an.setThresholdLine(line);
+ }
+ }
+ else
+ {
+ an.setGraph(false);
+ }
+
+ an.setLabel(annotation.label);
+
+ if (annotation == av.getAlignmentQualityAnnot()
+ || annotation == av.getAlignmentConservationAnnotation()
+ || annotation == av.getAlignmentConsensusAnnotation()
+ || annotation.autoCalculated)
+ {
+ // new way of indicating autocalculated annotation -
+ an.setAutoCalculated(annotation.autoCalculated);
+ }
+ if (annotation.hasScore())
+ {
+ an.setScore(annotation.getScore());
+ }
+
+ if (annotation.getCalcId() != null)
+ {
+ calcIdSet.add(annotation.getCalcId());
+ an.setCalcId(annotation.getCalcId());
+ }
+ if (annotation.hasProperties())
+ {
+ for (String pr : annotation.getProperties())
+ {
+ Property prop = new Property();
+ prop.setName(pr);
+ prop.setValue(annotation.getProperty(pr));
+ an.addProperty(prop);
+ }
+ }
+
+ AnnotationElement ae;
+ if (annotation.annotations != null)
+ {
+ an.setScoreOnly(false);
+ for (int a = 0; a < annotation.annotations.length; a++)
+ {
+ if ((annotation == null) || (annotation.annotations[a] == null))
+ {
+ continue;
+ }
+
+ ae = new AnnotationElement();
+ if (annotation.annotations[a].description != null)
+ {
+ ae.setDescription(annotation.annotations[a].description);
+ }
+ if (annotation.annotations[a].displayCharacter != null)
+ {
+ ae.setDisplayCharacter(
+ annotation.annotations[a].displayCharacter);
+ }
+
+ if (!Float.isNaN(annotation.annotations[a].value))
+ {
+ ae.setValue(annotation.annotations[a].value);
+ }
+
+ ae.setPosition(a);
+ if (annotation.annotations[a].secondaryStructure > ' ')
+ {
+ ae.setSecondaryStructure(
+ annotation.annotations[a].secondaryStructure + "");
+ }
+
+ if (annotation.annotations[a].colour != null
+ && annotation.annotations[a].colour != java.awt.Color.black)
+ {
+ ae.setColour(annotation.annotations[a].colour.getRGB());
+ }
+
+ an.addAnnotationElement(ae);
+ if (annotation.autoCalculated)
+ {
+ // only write one non-null entry into the annotation row -
+ // sufficient to get the visualization attributes necessary to
+ // display data
+ continue;
+ }
+ }
+ }
+ else
+ {
+ an.setScoreOnly(true);
+ }
+ if (!storeDS || (storeDS && !annotation.autoCalculated))
+ {
+ // skip autocalculated annotation - these are only provided for
+ // alignments
+ vamsasSet.addAnnotation(an);
+ }
+ }
+
+ }
+
+ private CalcIdParam createCalcIdParam(String calcId, AlignViewport av)
+ {
+ AutoCalcSetting settings = av.getCalcIdSettingsFor(calcId);
+ if (settings != null)
+ {
+ CalcIdParam vCalcIdParam = new CalcIdParam();
+ vCalcIdParam.setCalcId(calcId);
+ vCalcIdParam.addServiceURL(settings.getServiceURI());
+ // generic URI allowing a third party to resolve another instance of the
+ // service used for this calculation
+ for (String urls : settings.getServiceURLs())
+ {
+ vCalcIdParam.addServiceURL(urls);
+ }
+ vCalcIdParam.setVersion("1.0");
+ if (settings.getPreset() != null)
+ {
+ WsParamSetI setting = settings.getPreset();
+ vCalcIdParam.setName(setting.getName());
+ vCalcIdParam.setDescription(setting.getDescription());
+ }
+ else
+ {
+ vCalcIdParam.setName("");
+ vCalcIdParam.setDescription("Last used parameters");
+ }
+ // need to be able to recover 1) settings 2) user-defined presets or
+ // recreate settings from preset 3) predefined settings provided by
+ // service - or settings that can be transferred (or discarded)
+ vCalcIdParam.setParameters(
+ settings.getWsParamFile().replace("\n", "|\\n|"));
+ vCalcIdParam.setAutoUpdate(settings.isAutoUpdate());
+ // todo - decide if updateImmediately is needed for any projects.
+
+ return vCalcIdParam;
+ }
+ return null;
+ }
+
+ private boolean recoverCalcIdParam(CalcIdParam calcIdParam,
+ AlignViewport av)
+ {
+ if (calcIdParam.getVersion().equals("1.0"))
+ {
+ Jws2Instance service = Jws2Discoverer.getDiscoverer()
+ .getPreferredServiceFor(calcIdParam.getServiceURL());
+ if (service != null)
+ {
+ WsParamSetI parmSet = null;
+ try
+ {
+ parmSet = service.getParamStore().parseServiceParameterFile(
+ calcIdParam.getName(), calcIdParam.getDescription(),
+ calcIdParam.getServiceURL(),
+ calcIdParam.getParameters().replace("|\\n|", "\n"));
+ } catch (IOException x)
+ {
+ warn("Couldn't parse parameter data for "
+ + calcIdParam.getCalcId(), x);