X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fproject%2FJalview2XML.java;h=d045a3c9816413aee819701b9c241240896812ea;hb=c9150af4f9655e743ec53ec60ac5553f95e17636;hp=cf5974c4922a816f6b63124fd4f645735b81b875;hpb=8aa94d348698138bb5c30715ef0aa15349f47fbb;p=jalview.git diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index cf5974c..d045a3c 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -39,6 +39,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.GraphLine; +import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.PDBEntry; import jalview.datamodel.Point; import jalview.datamodel.RnaViewerModel; @@ -71,6 +72,7 @@ import jalview.gui.TreePanel; 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; @@ -212,6 +214,8 @@ public class Jalview2XML private static final String RNA_PREFIX = "rna_"; + private static final String HMMER_PREFIX = "hmmer_"; + private static final String UTF_8 = "UTF-8"; /** @@ -1050,6 +1054,9 @@ public class Jalview2XML jseq.getFeatures().add(features); } + /* + * save PDB entries for sequence + */ if (jdatasq.getAllPDBEntries() != null) { Enumeration en = jdatasq.getAllPDBEntries().elements(); @@ -1142,6 +1149,11 @@ public class Jalview2XML saveRnaViewers(jout, jseq, jds, viewIds, ap, storeDS); + if (jds.hasHMMProfile()) + { + saveHmmerProfile(jout, jseq, jds); + } + // jms.addJSeq(jseq); object.getJSeq().add(jseq); } @@ -1686,7 +1698,39 @@ public class Jalview2XML } 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. @@ -2080,9 +2124,9 @@ public class Jalview2XML } 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()); + 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 @@ -3573,6 +3617,15 @@ public class Jalview2XML } } } + + /* + * load any HMMER profile + */ + String hmmJarFile = jseqs.get(i).getHmmerProfile(); + if (hmmJarFile != null && jprovider != null) + { + loadHmmerProfile(jprovider, hmmJarFile, al.getSequenceAt(i)); + } } } // end !multipleview @@ -4047,6 +4100,31 @@ public class Jalview2XML } /** + * 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. @@ -4187,10 +4265,8 @@ public class Jalview2XML // TODO: verify 'associate with all views' works still tp.getTreeCanvas().setViewport(av); // af.viewport; tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel; - // FIXME: should we use safeBoolean here ? - tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews()); - } + tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews()); if (tp == null) { warn("There was a problem recovering stored Newick tree: \n" @@ -4522,7 +4598,7 @@ public class Jalview2XML String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\"); filedat = oldFiles.get(new File(reformatedOldFilename)); } - newFileLoc.append(Platform.escapeString(filedat.getFilePath())); + newFileLoc.append(Platform.escapeBackslashes(filedat.getFilePath())); pdbfilenames.add(filedat.getFilePath()); pdbids.add(filedat.getPdbId()); seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0])); @@ -5115,7 +5191,7 @@ public class Jalview2XML } else { - featureOrder.put(featureType, new Float( + featureOrder.put(featureType, Float.valueOf( fs / jm.getFeatureSettings().getSetting().size())); } if (safeBoolean(setting.isDisplay())) @@ -5127,7 +5203,7 @@ public class Jalview2XML for (int gs = 0; gs < jm.getFeatureSettings().getGroup().size(); gs++) { Group grp = jm.getFeatureSettings().getGroup().get(gs); - fgtable.put(grp.getName(), new Boolean(grp.isDisplay())); + fgtable.put(grp.getName(), Boolean.valueOf(grp.isDisplay())); } // FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder, // fgtable, featureColours, jms.getFeatureSettings().hasTransparency() ? @@ -5433,10 +5509,10 @@ public class Jalview2XML 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; @@ -5894,7 +5970,6 @@ public class Jalview2XML jmap.setTo(djs); incompleteSeqs.put(sqid, djs); seqRefIds.put(sqid, djs); - } jalview.bin.Cache.log.debug("about to recurse on addDBRefs."); addDBRefs(djs, ms); @@ -6078,7 +6153,7 @@ public class Jalview2XML } else { - Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id); + Cache.log.debug("Ignoring " + jvobj.getClass() + " (ID = " + id); } } } @@ -6552,7 +6627,7 @@ public class Jalview2XML 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();