import jalview.datamodel.DBRefEntry;
import jalview.datamodel.GeneLocus;
import jalview.datamodel.GraphLine;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.Point;
import jalview.datamodel.RnaViewerModel;
import jalview.io.BackupFiles;
import jalview.io.DataSourceType;
import jalview.io.FileFormat;
+import jalview.io.HMMFile;
import jalview.io.NewickFile;
import jalview.math.Matrix;
import jalview.math.MatrixI;
import jalview.schemes.FeatureColour;
import jalview.schemes.ResidueProperties;
import jalview.schemes.UserColourScheme;
+import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.Format;
+import jalview.util.HttpUtils;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.util.StringUtils;
import jalview.viewmodel.seqfeatures.FeatureRendererModel;
import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
-import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.api.ServiceWithParameters;
+import jalview.ws.jws2.PreferredServiceRegistry;
import jalview.ws.jws2.dm.AAConSettings;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.AutoCalcSetting;
import jalview.ws.params.WsParamSetI;
private static final String RNA_PREFIX = "rna_";
+ private static final String HMMER_PREFIX = "hmmer_";
private static final String UTF_8 = "UTF-8";
/**
*/
private void saveAllFrames(List<AlignFrame> frames, JarOutputStream jout)
{
-
Hashtable<String, AlignFrame> dsses = new Hashtable<>();
/*
AlignmentI alignment = vp.getAlignment();
List<? extends AlignmentViewPanel> panels = af.getAlignPanels();
int apSize = panels.size();
+
for (int ap = 0; ap < apSize; ap++)
{
AlignmentPanel apanel = (AlignmentPanel) panels.get(ap);
}
saveState(apanel, fileName, jout, viewIds);
+
}
if (apSize > 0)
{
// Note that in saveAllFrames we have associated each specific dataset to
// ONE of its associated frames.
-
for (String dssids : dsses.keySet())
{
AlignFrame _af = dsses.get(dssids);
jseq.getFeatures().add(features);
}
+ /*
+ * save PDB entries for sequence
+ */
if (jdatasq.getAllPDBEntries() != null)
{
Enumeration<PDBEntry> en = jdatasq.getAllPDBEntries().elements();
if (frames[f] instanceof StructureViewerBase)
{
StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
- matchedFile = saveStructureState(ap, jds, pdb, entry, viewIds,
- matchedFile, viewFrame);
+ matchedFile = saveStructureViewer(ap, jds, pdb, entry,
+ viewIds, matchedFile, viewFrame);
/*
* Only store each structure viewer's state once in the project
* jar. First time through only (storeDS==false)
*/
String viewId = viewFrame.getViewId();
+ String viewerType = viewFrame.getViewerType().toString();
if (!storeDS && !viewIds.contains(viewId))
{
viewIds.add(viewId);
- try
+ File viewerState = viewFrame.saveSession();
+ if (viewerState != null)
{
- String viewerState = viewFrame.getStateInfo();
- writeJarEntry(jout, getViewerJarEntryName(viewId),
- viewerState.getBytes());
- } catch (IOException e)
+ copyFileToJar(jout, viewerState.getPath(),
+ getViewerJarEntryName(viewId), viewerType);
+ }
+ else
{
- System.err.println(
- "Error saving viewer state: " + e.getMessage());
+ Cache.log.error(
+ "Failed to save viewer state for " + viewerType);
}
}
}
if (!pdbfiles.contains(pdbId))
{
pdbfiles.add(pdbId);
- copyFileToJar(jout, matchedFile, pdbId);
+ copyFileToJar(jout, matchedFile, pdbId, pdbId);
}
}
saveRnaViewers(jout, jseq, jds, viewIds, ap, storeDS);
+ if (jds.hasHMMProfile())
+ {
+ saveHmmerProfile(jout, jseq, jds);
+ }
// jms.addJSeq(jseq);
object.getJSeq().add(jseq);
}
// using save and then load
try
{
- fileName = fileName.replace('\\', '/');
+ fileName = fileName.replace('\\', '/');
System.out.println("Writing jar entry " + fileName);
JarEntry entry = new JarEntry(fileName);
jout.putNextEntry(entry);
}
return object;
}
+ /**
+ * Saves the HMMER profile associated with the sequence as a file in the jar,
+ * in HMMER format, and saves the name of the file as a child element of the
+ * XML sequence element
+ *
+ * @param jout
+ * @param xmlSeq
+ * @param seq
+ */
+ protected void saveHmmerProfile(JarOutputStream jout, JSeq xmlSeq,
+ SequenceI seq)
+ {
+ HiddenMarkovModel profile = seq.getHMM();
+ if (profile == null)
+ {
+ warn("Want to save HMM profile for " + seq.getName()
+ + " but none found");
+ return;
+ }
+ HMMFile hmmFile = new HMMFile(profile);
+ String hmmAsString = hmmFile.print();
+ String jarEntryName = HMMER_PREFIX + nextCounter();
+ try
+ {
+ writeJarEntry(jout, jarEntryName, hmmAsString.getBytes());
+ xmlSeq.setHmmerProfile(jarEntryName);
+ } catch (IOException e)
+ {
+ warn("Error saving HMM profile: " + e.getMessage());
+ }
+ }
+
/**
* Writes PCA viewer attributes and computed values to an XML model object and
* adds it to the JalviewModel. Any exceptions are reported by logging.
String varnaStateFile = varna.getStateInfo(model.rna);
jarEntryName = RNA_PREFIX + viewId + "_" + nextCounter();
- copyFileToJar(jout, varnaStateFile, jarEntryName);
+ copyFileToJar(jout, varnaStateFile, jarEntryName, "Varna");
rnaSessions.put(model, jarEntryName);
}
SecondaryStructure ss = new SecondaryStructure();
* @param jout
* @param infilePath
* @param jarEntryName
+ * @param msg
+ * additional identifying info to log to the console
*/
protected void copyFileToJar(JarOutputStream jout, String infilePath,
- String jarEntryName)
+ String jarEntryName, String msg)
{
- DataInputStream dis = null;
- try
+ try (InputStream is = new FileInputStream(infilePath))
{
File file = new File(infilePath);
if (file.exists() && jout != null)
{
- dis = new DataInputStream(new FileInputStream(file));
- byte[] data = new byte[(int) file.length()];
- dis.readFully(data);
- writeJarEntry(jout, jarEntryName, data);
+ System.out.println(
+ "Writing jar entry " + jarEntryName + " (" + msg + ")");
+ jout.putNextEntry(new JarEntry(jarEntryName));
+ copyAll(is, jout);
+ jout.closeEntry();
+ // dis = new DataInputStream(new FileInputStream(file));
+ // byte[] data = new byte[(int) file.length()];
+ // dis.readFully(data);
+ // writeJarEntry(jout, jarEntryName, data);
}
} catch (Exception ex)
{
ex.printStackTrace();
- } finally
- {
- if (dis != null)
- {
- try
- {
- dis.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
}
}
/**
- * Write the data to a new entry of given name in the output jar file
+ * Copies input to output, in 4K buffers; handles any data (text or binary)
*
- * @param jout
- * @param jarEntryName
- * @param data
+ * @param in
+ * @param out
* @throws IOException
*/
- protected void writeJarEntry(JarOutputStream jout, String jarEntryName,
- byte[] data) throws IOException
+ protected void copyAll(InputStream in, OutputStream out)
+ throws IOException
{
- if (jout != null)
+ byte[] buffer = new byte[4096];
+ int bytesRead = 0;
+ while ((bytesRead = in.read(buffer)) != -1)
{
- jarEntryName = jarEntryName.replace('\\','/');
- 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();
+ out.write(buffer, 0, bytesRead);
}
}
* @param viewFrame
* @return
*/
- protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
+ protected String saveStructureViewer(AlignmentPanel ap, SequenceI jds,
Pdbids pdb, PDBEntry entry, List<String> viewIds,
String matchedFile, StructureViewerBase viewFrame)
{
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())))
+ && !(entry.getId().length() > 4 && entry.getId().toLowerCase(Locale.ROOT)
+ .startsWith(pdbId.toLowerCase(Locale.ROOT))))
{
/*
* not interested in a binding to a different PDB entry here
final String viewId = viewFrame.getViewId();
state.setViewId(viewId);
state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
- state.setColourwithAlignPanel(viewFrame.isUsedforcolourby(ap));
+ state.setColourwithAlignPanel(viewFrame.isUsedForColourBy(ap));
state.setColourByJmol(viewFrame.isColouredByViewer());
state.setType(viewFrame.getViewerType().toString());
// pdb.addStructureState(state);
if (calcIdParam.getVersion().equals("1.0"))
{
final String[] calcIds = calcIdParam.getServiceURL().toArray(new String[0]);
- Jws2Instance service = Jws2Discoverer.getInstance()
+ ServiceWithParameters service = PreferredServiceRegistry.getRegistry()
.getPreferredServiceFor(calcIds);
if (service != null)
{
argList = parmSet.getArguments();
parmSet = null;
}
- AAConSettings settings = new AAConSettings(
+ AutoCalcSetting settings = new AAConSettings(
calcIdParam.isAutoUpdate(), service, parmSet, argList);
av.setCalcIdSettingsFor(calcIdParam.getCalcId(), settings,
calcIdParam.isNeedsUpdate());
}
else
{
- warn("Cannot resolve a service for the parameters used in this project. Try configuring a JABAWS server.");
+ warn("Cannot resolve a service for the parameters used in this project. Try configuring a server in the Web Services preferences tab.");
return false;
}
}
dbref.setSource(ref.getSource());
dbref.setVersion(ref.getVersion());
dbref.setAccessionId(ref.getAccessionId());
+ dbref.setCanonical(ref.isCanonical());
if (ref instanceof GeneLocus)
{
dbref.setLocus(true);
for (int i = 0; i < colours.length; i++)
{
Colour col = new Colour();
- col.setName(ResidueProperties.aa[i].toLowerCase());
+ col.setName(ResidueProperties.aa[i].toLowerCase(Locale.ROOT));
col.setRGB(jalview.util.Format.getHexString(colours[i]));
// jbucs.addColour(col);
jbucs.getColour().add(col);
return id;
}
- jalview.schemes.UserColourScheme getUserColourScheme(
- JalviewModel jm, String id)
+ jalview.schemes.UserColourScheme getUserColourScheme(JalviewModel jm,
+ String id)
{
List<UserColours> uc = jm.getUserColours();
UserColours colours = null;
-/*
+ /*
for (int i = 0; i < uc.length; i++)
{
if (uc[i].getId().equals(id))
break;
}
}
-*/
+ */
for (UserColours c : uc)
{
if (c.getId().equals(id))
newColours = new java.awt.Color[23];
for (int i = 0; i < 23; i++)
{
- newColours[i] = new java.awt.Color(Integer.parseInt(
- colours.getUserColourScheme().getColour().get(i + 24)
- .getRGB(),
- 16));
+ newColours[i] = new java.awt.Color(
+ Integer.parseInt(colours.getUserColourScheme().getColour()
+ .get(i + 24).getRGB(), 16));
}
ucs.setLowerCaseColours(newColours);
}
return ucs;
}
+ /**
+ * contains last error message (if any) encountered by XML loader.
+ */
+ String errorMessage = null;
+
+ /**
+ * flag to control whether the Jalview2XML_V1 parser should be deferred to if
+ * exceptions are raised during project XML parsing
+ */
+ public boolean attemptversion1parse = false;
/**
* Load a jalview project archive from a jar file
{
this.jarFile = (File) ofile;
}
+ URL url = null;
errorMessage = null;
uniqueSetSuffix = null;
seqRefIds = null;
viewportsAdded.clear();
frefedSequence = null;
- URL url = file.startsWith("http://") ? new URL(file) : null;
+ if (HttpUtils.startsWithHttpOrHttps(file))
+ {
+ url = new URL(file);
+ }
return new jarInputStreamProvider()
{
@Override
}
@Override
+ public File getFile()
+ {
+ return jarFile;
+ }
+
+ @Override
public String getFilename()
{
return file;
AlignFrame af = null, _af = null;
IdentityHashMap<AlignmentI, AlignmentI> importedDatasets = new IdentityHashMap<>();
Map<String, AlignFrame> gatherToThisFrame = new HashMap<>();
- final String file = jprovider.getFilename();
-
+ String fileName = jprovider.getFilename();
+ File file = jprovider.getFile();
List<AlignFrame> alignFrames = new ArrayList<>();
-
try
{
JarInputStream jin = null;
JarEntry jarentry = null;
int entryCount = 1;
-
// Look for all the entry names ending with ".xml"
// This includes all panels and at least one frame.
// Platform.timeCheck(null, Platform.TIME_MARK);
// System.out.println("Jalview2XML opening " + name);
if (name != null && name.endsWith(".xml"))
{
-
// DataSet for.... is read last.
// Q: Do we have to load from the model, even if it
// does not have a viewport, could we discover that early on?
// Q: Do we need to load this object?
- _af = loadFromObject(model, file, true, jprovider);
+ _af = loadFromObject(model, fileName, file, true, jprovider);
// Platform.timeCheck("Jalview2XML.loadFromObject",
// Platform.TIME_MARK);
} catch (IOException ex)
{
ex.printStackTrace();
- errorMessage = "Couldn't locate Jalview XML file : " + file;
+ errorMessage = "Couldn't locate Jalview XML file : " + fileName;
System.err.println(
"Exception whilst loading jalview XML file : " + ex + "\n");
} catch (Exception ex)
{
alf.alignPanel.setHoldRepaint(false);
}
-
}
/*
{
suffix = "." + origFile.substring(sfpos + 1);
}
- try
+ try (JarInputStream jin = jprovider.getJarInputStream())
{
- JarInputStream jin = jprovider.getJarInputStream();
- /*
- * if (jprovider.startsWith("http://")) { jin = new JarInputStream(new
- * URL(jprovider).openStream()); } else { jin = new JarInputStream(new
- * FileInputStream(jprovider)); }
- */
JarEntry entry = null;
do
} while (entry != null && !entry.getName().equals(jarEntryName));
if (entry != null)
{
- in = new BufferedReader(new InputStreamReader(jin, UTF_8));
+ // in = new BufferedReader(new InputStreamReader(jin, UTF_8));
File outFile = File.createTempFile(prefix, suffix);
outFile.deleteOnExit();
- out = new PrintWriter(new FileOutputStream(outFile));
- String data;
-
- while ((data = in.readLine()) != null)
+ try (OutputStream os = new FileOutputStream(outFile))
{
- out.println(data);
+ copyAll(jin, os);
}
- out.flush();
String t = outFile.getAbsolutePath();
return t;
}
} catch (Exception ex)
{
ex.printStackTrace();
- } finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
- if (out != null)
- {
- out.close();
- }
}
return null;
*
* @param jalviewModel
* DOM
- * @param file
+ * @param fileName
* filename source string
+ * @param file
* @param loadTreesAndStructures
* when false only create Viewport
* @param jprovider
* data source provider
* @return alignment frame created from view stored in DOM
*/
- AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
- boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
+ AlignFrame loadFromObject(JalviewModel jalviewModel, String fileName,
+ File file, boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
{
SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet().get(0);
List<Sequence> vamsasSeqs = vamsasSet.getSequence();
-
// JalviewModelSequence jms = object.getJalviewModelSequence();
// Viewport view = (jms.getViewportCount() > 0) ? jms.getViewport(0)
}
}
}
+ /*
+ * load any HMMER profile
+ */
+ // TODO fix this
+ String hmmJarFile = jseqs.get(i).getHmmerProfile();
+ if (hmmJarFile != null && jprovider != null)
+ {
+ loadHmmerProfile(jprovider, hmmJarFile, al.getSequenceAt(i));
+ }
}
} // end !multipleview
sg.setShowNonconserved(safeBoolean(jGroup.isShowUnconserved()));
sg.thresholdTextColour = safeInt(jGroup.getTextColThreshold());
// attributes with a default in the schema are never null
- sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
- sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
- sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
+ sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
+ sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
+ sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
sg.setIgnoreGapsConsensus(jGroup.isIgnoreGapsinConsensus());
if (jGroup.getConsThreshold() != null
&& jGroup.getConsThreshold().intValue() != 0)
if (addAnnotSchemeGroup)
{
// reconstruct the annotation colourscheme
- sg.setColourScheme(constructAnnotationColour(
- jGroup.getAnnotationColours(), null, al, jalviewModel, false));
+ sg.setColourScheme(
+ constructAnnotationColour(jGroup.getAnnotationColours(),
+ null, al, jalviewModel, false));
}
}
}
if (af == null)
{
- af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view,
+ af = loadViewport(fileName, file, jseqs, hiddenSeqs, al, jalviewModel, view,
uniqueSeqSetId, viewId, autoAlan);
av = af.getViewport();
// note that this only retrieves the most recently accessed
}
/**
+ * Loads a HMMER profile from a file stored in the project, and associates it
+ * with the specified sequence
+ *
+ * @param jprovider
+ * @param hmmJarFile
+ * @param seq
+ */
+ protected void loadHmmerProfile(jarInputStreamProvider jprovider,
+ String hmmJarFile, SequenceI seq)
+ {
+ try
+ {
+ String hmmFile = copyJarEntry(jprovider, hmmJarFile, "hmm", null);
+ HMMFile parser = new HMMFile(hmmFile, DataSourceType.FILE);
+ HiddenMarkovModel hmmModel = parser.getHMM();
+ hmmModel = new HiddenMarkovModel(hmmModel, seq);
+ seq.setHMM(hmmModel);
+ } catch (IOException e)
+ {
+ warn("Error loading HMM profile for " + seq.getName() + ": "
+ + e.getMessage());
+ }
+ }
+
+ /**
* Instantiate and link any saved RNA (Varna) viewers. The state of the Varna
* panel is restored from separate jar entries, two (gapped and trimmed) per
* sequence and secondary structure.
tree.getTitle(), safeInt(tree.getWidth()),
safeInt(tree.getHeight()), safeInt(tree.getXpos()),
safeInt(tree.getYpos()));
+ if (tp == null)
+ {
+ warn("There was a problem recovering stored Newick tree: \n"
+ + tree.getNewick());
+ continue;
+ }
if (tree.getId() != null)
{
// perhaps bind the tree id to something ?
tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel;
}
tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews());
- if (tp == null)
- {
- warn("There was a problem recovering stored Newick tree: \n"
- + tree.getNewick());
- continue;
- }
tp.fitToWindow.setState(safeBoolean(tree.isFitToWindow()));
tp.fitToWindow_actionPerformed(null);
}
if (!structureViewers.containsKey(sviewid))
{
+ String viewerType = structureState.getType();
+ if (viewerType == null) // pre Jalview 2.9
+ {
+ viewerType = ViewerType.JMOL.toString();
+ }
structureViewers.put(sviewid,
new StructureViewerModel(x, y, width, height, false,
false, true, structureState.getViewId(),
- structureState.getType()));
+ viewerType));
// Legacy pre-2.7 conversion JAL-823 :
// do not assume any view has to be linked for colour by
// sequence
return;
}
- /*
- * From 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
- * "viewer_"+stateData.viewId
- */
- if (ViewerType.CHIMERA.toString().equals(stateData.getType()))
+ String type = stateData.getType();
+ try
{
- createChimeraViewer(viewerData, af, jprovider);
- }
- else
+ ViewerType viewerType = ViewerType.valueOf(type);
+ createStructureViewer(viewerType, viewerData, af, jprovider);
+ } catch (IllegalArgumentException | NullPointerException e)
{
- /*
- * else Jmol (if pre-2.9, stateData contains JMOL state string)
- */
- createJmolViewer(viewerData, af, jprovider);
+ // TODO JAL-3619 show error dialog / offer an alternative viewer
+ Cache.log.error("Invalid structure viewer type: " + type);
}
+
}
/**
- * Create a new Chimera viewer.
+ * Creates a new structure viewer window
*
- * @param data
+ * @param viewerType
+ * @param viewerData
* @param af
* @param jprovider
*/
- protected void createChimeraViewer(
- Entry<String, StructureViewerModel> viewerData, AlignFrame af,
- jarInputStreamProvider jprovider)
+ protected void createStructureViewer(ViewerType viewerType,
+ final Entry<String, StructureViewerModel> viewerData,
+ AlignFrame af, jarInputStreamProvider jprovider)
{
- StructureViewerModel data = viewerData.getValue();
- String chimeraSessionFile = data.getStateData();
+ final StructureViewerModel viewerModel = viewerData.getValue();
+ String sessionFilePath = null;
- /*
- * Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
- *
- * NB this is the 'saved' viewId as in the project file XML, _not_ the
- * 'uniquified' sviewid used to reconstruct the viewer here
- */
- String viewerJarEntryName = getViewerJarEntryName(data.getViewId());
- chimeraSessionFile = copyJarEntry(jprovider, viewerJarEntryName,
- "chimera", ".py");
-
- Set<Entry<File, StructureData>> fileData = data.getFileData()
- .entrySet();
- List<PDBEntry> pdbs = new ArrayList<>();
- List<SequenceI[]> allseqs = new ArrayList<>();
- for (Entry<File, StructureData> pdb : fileData)
- {
- String filePath = pdb.getValue().getFilePath();
- String pdbId = pdb.getValue().getPdbId();
- // pdbs.add(new PDBEntry(filePath, pdbId));
- pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
- final List<SequenceI> seqList = pdb.getValue().getSeqList();
- SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
- allseqs.add(seqs);
- }
-
- boolean colourByChimera = data.isColourByViewer();
- boolean colourBySequence = data.isColourWithAlignPanel();
-
- // TODO use StructureViewer as a factory here, see JAL-1761
- final PDBEntry[] pdbArray = pdbs.toArray(new PDBEntry[pdbs.size()]);
- final SequenceI[][] seqsArray = allseqs
- .toArray(new SequenceI[allseqs.size()][]);
- String newViewId = viewerData.getKey();
-
- ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
- af.alignPanel, pdbArray, seqsArray, colourByChimera,
- colourBySequence, newViewId);
- cvf.setSize(data.getWidth(), data.getHeight());
- cvf.setLocation(data.getX(), data.getY());
+ if (viewerType == ViewerType.JMOL)
+ {
+ sessionFilePath = rewriteJmolSession(viewerModel, jprovider);
+ }
+ else
+ {
+ String viewerJarEntryName = getViewerJarEntryName(
+ viewerModel.getViewId());
+ sessionFilePath = copyJarEntry(jprovider, viewerJarEntryName,
+ "viewerSession", ".tmp");
+ }
+ final String sessionPath = sessionFilePath;
+ final String sviewid = viewerData.getKey();
+// BH again was invokeAndWait
+ // try
+ // {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ JalviewStructureDisplayI sview = null;
+ try
+ {
+ sview = StructureViewer.createView(viewerType, af.alignPanel,
+ viewerModel, sessionPath, sviewid);
+ addNewStructureViewer(sview);
+ } catch (OutOfMemoryError ex)
+ {
+ new OOMWarning("Restoring structure view for " + viewerType,
+ (OutOfMemoryError) ex.getCause());
+ if (sview != null && sview.isVisible())
+ {
+ sview.closeViewer(false);
+ sview.setVisible(false);
+ sview.dispose();
+ }
+ }
+ }
+ });
+// } catch (InvocationTargetException | InterruptedException ex)
+// {
+// warn("Unexpected error when opening " + viewerType
+// + " structure viewer", ex);
+// }
}
/**
- * Create a new Jmol window. First parse the Jmol state to translate filenames
- * loaded into the view, and record the order in which files are shown in the
- * Jmol view, so we can add the sequence mappings in same order.
+ * Rewrites a Jmol session script, saves it to a temporary file, and returns
+ * the path of the file. "load file" commands are rewritten to change the
+ * original PDB file names to those created as the Jalview project is loaded.
*
- * @param viewerData
- * @param af
+ * @param svattrib
* @param jprovider
+ * @return
*/
- protected void createJmolViewer(
- final Entry<String, StructureViewerModel> viewerData,
- AlignFrame af, jarInputStreamProvider jprovider)
+ private String rewriteJmolSession(StructureViewerModel svattrib,
+ jarInputStreamProvider jprovider)
{
- final StructureViewerModel svattrib = viewerData.getValue();
- String state = svattrib.getStateData();
-
- /*
- * Pre-2.9: state element value is the Jmol state string
- *
- * 2.9+: @type is "JMOL", state data is in a Jar file member named "viewer_"
- * + viewId
- */
- if (ViewerType.JMOL.toString().equals(svattrib.getType()))
+ String state = svattrib.getStateData(); // Jalview < 2.9
+ if (state == null || state.isEmpty()) // Jalview >= 2.9
{
- state = readJarEntry(jprovider,
- getViewerJarEntryName(svattrib.getViewId()));
+ String jarEntryName = getViewerJarEntryName(svattrib.getViewId());
+ state = readJarEntry(jprovider, jarEntryName);
}
-
- List<String> pdbfilenames = new ArrayList<>();
- List<SequenceI[]> seqmaps = new ArrayList<>();
- List<String> pdbids = new ArrayList<>();
- StringBuilder newFileLoc = new StringBuilder(64);
+ // TODO or simpler? for each key in oldFiles,
+ // replace key.getPath() in state with oldFiles.get(key).getFilePath()
+ // (allowing for different path escapings)
+ StringBuilder rewritten = new StringBuilder(state.length());
int cp = 0, ncp, ecp;
Map<File, StructureData> oldFiles = svattrib.getFileData();
while ((ncp = state.indexOf("load ", cp)) > -1)
do
{
// look for next filename in load statement
- newFileLoc.append(state.substring(cp,
+ rewritten.append(state.substring(cp,
ncp = (state.indexOf("\"", ncp + 1) + 1)));
String oldfilenam = state.substring(ncp,
ecp = state.indexOf("\"", ncp));
// recover the new mapping data for this old filename
// have to normalize filename - since Jmol and jalview do
- // filename
- // translation differently.
+ // filename translation differently.
StructureData filedat = oldFiles.get(new File(oldfilenam));
if (filedat == null)
{
String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\");
filedat = oldFiles.get(new File(reformatedOldFilename));
}
- newFileLoc
- .append(Platform.escapeBackslashes(filedat.getFilePath()));
- pdbfilenames.add(filedat.getFilePath());
- pdbids.add(filedat.getPdbId());
- seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
- newFileLoc.append("\"");
+ rewritten.append(Platform.escapeBackslashes(filedat.getFilePath()));
+ rewritten.append("\"");
cp = ecp + 1; // advance beyond last \" and set cursor so we can
// look for next file statement.
} while ((ncp = state.indexOf("/*file*/", cp)) > -1);
if (cp > 0)
{
// just append rest of state
- newFileLoc.append(state.substring(cp));
+ rewritten.append(state.substring(cp));
}
else
{
System.err.print("Ignoring incomplete Jmol state for PDB ids: ");
- newFileLoc = new StringBuilder(state);
- newFileLoc.append("; load append ");
+ rewritten = new StringBuilder(state);
+ rewritten.append("; load append ");
for (File id : oldFiles.keySet())
{
- // add this and any other pdb files that should be present in
- // the viewer
+ // add pdb files that should be present in the viewer
StructureData filedat = oldFiles.get(id);
- newFileLoc.append(filedat.getFilePath());
- pdbfilenames.add(filedat.getFilePath());
- pdbids.add(filedat.getPdbId());
- seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
- newFileLoc.append(" \"");
- newFileLoc.append(filedat.getFilePath());
- newFileLoc.append("\"");
-
+ rewritten.append(" \"").append(filedat.getFilePath()).append("\"");
}
- newFileLoc.append(";");
+ rewritten.append(";");
}
- if (newFileLoc.length() == 0)
+ if (rewritten.length() == 0)
{
- return;
+ return null;
}
- int histbug = newFileLoc.indexOf("history = ");
- if (histbug > -1)
+ final String history = "history = ";
+ int historyIndex = rewritten.indexOf(history);
+ if (historyIndex > -1)
{
/*
* change "history = [true|false];" to "history = [1|0];"
*/
- histbug += 10;
- int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";", histbug);
- String val = (diff == -1) ? null
- : newFileLoc.substring(histbug, diff);
- if (val != null && val.length() >= 4)
+ historyIndex += history.length();
+ String val = rewritten.substring(historyIndex, historyIndex + 5);
+ if (val.startsWith("true"))
{
- if (val.contains("e")) // eh? what can it be?
- {
- if (val.trim().equals("true"))
- {
- val = "1";
- }
- else
- {
- val = "0";
- }
- newFileLoc.replace(histbug, diff, val);
- }
+ rewritten.replace(historyIndex, historyIndex + 4, "1");
+ }
+ else if (val.startsWith("false"))
+ {
+ rewritten.replace(historyIndex, historyIndex + 5, "0");
}
}
- final String[] pdbf = pdbfilenames
- .toArray(new String[pdbfilenames.size()]);
- final String[] id = pdbids.toArray(new String[pdbids.size()]);
- final SequenceI[][] sq = seqmaps
- .toArray(new SequenceI[seqmaps.size()][]);
- final String fileloc = newFileLoc.toString();
- final String sviewid = viewerData.getKey();
- final AlignFrame alf = af;
- final Rectangle rect = new Rectangle(svattrib.getX(), svattrib.getY(),
- svattrib.getWidth(), svattrib.getHeight());
-
- // BH again was invokeAndWait
- // try
- // {
- javax.swing.SwingUtilities.invokeLater(new Runnable()
+ try
+ {
+ File tmp = File.createTempFile("viewerSession", ".tmp");
+ try (OutputStream os = new FileOutputStream(tmp))
{
- @Override
- public void run()
- {
- JalviewStructureDisplayI sview = null;
- try
- {
- sview = new StructureViewer(
- alf.alignPanel.getStructureSelectionManager())
- .createView(StructureViewer.ViewerType.JMOL,
- pdbf, id, sq, alf.alignPanel, svattrib,
- fileloc, rect, sviewid);
- addNewStructureViewer(sview);
- } catch (OutOfMemoryError ex)
- {
- new OOMWarning("restoring structure view for PDB id " + id,
- (OutOfMemoryError) ex.getCause());
- if (sview != null && sview.isVisible())
- {
- sview.closeViewer(false);
- sview.setVisible(false);
- sview.dispose();
- }
- }
- }
- });
- // } catch (InvocationTargetException ex)
- // {
- // warn("Unexpected error when opening Jmol view.", ex);
- //
- // } catch (InterruptedException e)
- // {
- // // e.printStackTrace();
- // }
-
+ InputStream is = new ByteArrayInputStream(
+ rewritten.toString().getBytes());
+ copyAll(is, os);
+ return tmp.getAbsolutePath();
+ }
+ } catch (IOException e)
+ {
+ Cache.log.error("Error restoring Jmol session: " + e.toString());
+ }
+ return null;
}
/**
}
}
- AlignFrame loadViewport(String fileName, List<JSeq> JSEQ,
+ AlignFrame loadViewport(String fileName, File file, List<JSeq> JSEQ,
List<SequenceI> hiddenSeqs, AlignmentI al, JalviewModel jm,
Viewport view, String uniqueSeqSetId, String viewId,
List<JvAnnotRow> autoAlan)
//
// }
;
+
af.alignPanel.setHoldRepaint(true);
- af.setFileName(fileName, FileFormat.Jalview);
+ af.setFile(fileName, file, null, FileFormat.Jalview);
af.setFileObject(jarFile); // BH 2019 JAL-3436
final AlignViewport viewport = af.getViewport();
// recover feature settings
if (jm.getFeatureSettings() != null)
{
- FeatureRenderer fr = af.alignPanel.getSeqPanel().seqCanvas
+ FeatureRendererModel fr = af.alignPanel.getSeqPanel().seqCanvas
.getFeatureRenderer();
FeaturesDisplayed fdi;
viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
String id = object.getViewport().get(0).getSequenceSetId();
if (skipList.containsKey(id))
{
- if (Cache.log != null && Cache.log.isDebugEnabled())
- {
- Cache.log.debug("Skipping seuqence set id " + id);
- }
+ if (Cache.log != null && Cache.log.isDebugEnabled())
+ {
+ Cache.log.debug("Skipping seuqence set id " + id);
+ }
return true;
}
return false;
// try even harder to restore dataset
AlignmentI xtantDS = checkIfHasDataset(vamsasSet.getSequence());
// create a list of new dataset sequences
- dseqs = new Vector();
+ dseqs = new Vector<>();
}
for (int i = 0, iSize = vamsasSet.getSequence().size(); i < iSize; i++)
{
* vamsasSeq array ordering, to preserve ordering of dataset
*/
private void ensureJalviewDatasetSequence(Sequence vamsasSeq,
- AlignmentI ds, Vector dseqs, boolean ignoreUnrefed, int vseqpos)
+ AlignmentI ds, Vector<SequenceI> dseqs, boolean ignoreUnrefed,
+ int vseqpos)
{
// JBP TODO: Check this is called for AlCodonFrames to support recovery of
// xRef Codon Maps
{
entry.setMap(addMapping(dr.getMapping()));
}
+ entry.setCanonical(dr.isCanonical());
datasetSequence.addDBRef(entry);
}
}
viewportsAdded.clear();
- AlignFrame af = loadFromObject(jm, null, false, null);
+ AlignFrame af = loadFromObject(jm, null, null, false, null);
af.getAlignPanels().clear();
af.closeMenuItem_actionPerformed(true);
af.alignPanel.setHoldRepaint(false);
}
else
{
- Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
+ Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id);
}
}
}
boolean and)
{
jalview.xml.binding.jalview.FeatureMatcherSet result = new jalview.xml.binding.jalview.FeatureMatcherSet();
-
if (filters.hasNext())
{
/*
}
result.setMatchCondition(matcherModel);
}
-
return result;
}
featureType, e.getMessage()));
// return as much as was parsed up to the error
}
-
return result;
}
else if (filterBy == FilterBy.BY_SCORE)
{
matchCondition = FeatureMatcher.byScore(cond, pattern);
-
}
else if (filterBy == FilterBy.BY_ATTRIBUTE)
{
matchCondition = FeatureMatcher.byAttribute(cond, pattern,
attNames);
}
-
/*
* note this throws IllegalStateException if AND-ing to a
* previously OR-ed compound condition, or vice versa
public static FeatureColourI parseColour(Colour colourModel)
{
FeatureColourI colour = null;
-
if (colourModel.getMax() != null)
{
Color mincol = null;
Color maxcol = null;
Color noValueColour = null;
-
try
{
mincol = new Color(Integer.parseInt(colourModel.getMinRGB(), 16));
maxcol = new Color(Integer.parseInt(colourModel.getRGB(), 16));
} catch (Exception e)
{
- Cache.log.warn("Couldn't parse out graduated feature color.", e);
+ Cache.log.warn("Couldn't parse out graduated feature color.", e);
}
-
NoValueColour noCol = colourModel.getNoValueColour();
if (noCol == NoValueColour.MIN)
{
{
noValueColour = maxcol;
}
-
colour = new FeatureColour(maxcol, mincol, maxcol, noValueColour,
safeFloat(colourModel.getMin()),
safeFloat(colourModel.getMax()));
Color color = new Color(Integer.parseInt(colourModel.getRGB(), 16));
colour = new FeatureColour(color);
}
-
return colour;
}
}