X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJalview2XML.java;h=aab41cabccd92614870e97a0bff4796afaeb69c5;hb=6a91de2e48559da8034762a7d77a143435362029;hp=061dfca64f0fad12b5c43c11ed94ac15c90a21cb;hpb=266c4e2544701f88a8d21294b4a4f4cc42cf76cc;p=jalview.git diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 061dfca..aab41ca 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -26,12 +26,22 @@ import java.util.jar.*; import javax.swing.*; import org.exolab.castor.xml.*; + +import uk.ac.vamsas.objects.utils.MapList; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceI; import jalview.schemabinding.version2.*; import jalview.schemes.*; import jalview.structure.StructureSelectionManager; /** - * DOCUMENT ME! + * Write out the current jalview desktop state + * as a Jalview XML stream. + * + * Note: the vamsas objects referred to here are primitive + * versions of the VAMSAS project schema elements - they are + * not the same and most likely never will be :) * * @author $author$ * @version $Revision$ @@ -39,7 +49,54 @@ import jalview.structure.StructureSelectionManager; public class Jalview2XML { - Hashtable seqRefIds; + Hashtable seqRefIds = null; + + Vector frefedSequence = null; + + public void resolveFrefedSequences() + { + if (frefedSequence.size() > 0) + { + int r = 0, rSize = frefedSequence.size(); + while (r < rSize) + { + Object[] ref = (Object[]) frefedSequence.elementAt(r); + if (ref != null) + { + String sref = (String) ref[0]; + if (seqRefIds.containsKey(sref)) + { + if (ref[1] instanceof jalview.datamodel.Mapping) + { + SequenceI seq = (SequenceI) seqRefIds.get(sref); + while (seq.getDatasetSequence() != null) + { + seq = seq.getDatasetSequence(); + } + ((jalview.datamodel.Mapping) ref[1]).setTo(seq); + } + else + { + System.err + .println("IMPLEMENTATION ERROR: Unimplemented forward sequence references for " + + ref[1].getClass() + " type objects."); + } + frefedSequence.remove(r); + rSize--; + } + else + { + r++; + } + } + else + { + frefedSequence.remove(r); + rSize--; + } + } + } + } /** * This maintains a list of viewports, the key being the @@ -51,6 +108,7 @@ public class Jalview2XML Hashtable annotationIds = new Hashtable(); String uniqueSetSuffix = ""; + /** * List of pdbfiles added to Jar */ @@ -74,7 +132,7 @@ public class Jalview2XML //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS //////////////////////////////////////////////////// PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, - "UTF-8")); + "UTF-8")); Vector shortNames = new Vector(); @@ -89,8 +147,8 @@ public class Jalview2XML if (shortName.indexOf(File.separatorChar) > -1) { - shortName = shortName.substring(shortName.lastIndexOf( - File.separatorChar) + 1); + shortName = shortName.substring(shortName + .lastIndexOf(File.separatorChar) + 1); } int count = 1; @@ -99,8 +157,8 @@ public class Jalview2XML { if (shortName.endsWith("_" + (count - 1))) { - shortName = shortName.substring(0, - shortName.lastIndexOf("_")); + shortName = shortName + .substring(0, shortName.lastIndexOf("_")); } shortName = shortName.concat("_" + count); @@ -117,28 +175,27 @@ public class Jalview2XML int ap, apSize = af.alignPanels.size(); for (ap = 0; ap < apSize; ap++) { - AlignmentPanel apanel = (AlignmentPanel) af.alignPanels. - elementAt(ap); + AlignmentPanel apanel = (AlignmentPanel) af.alignPanels + .elementAt(ap); - SaveState(apanel, - apSize == 1 ? shortName : ap + shortName, - jout, out); + SaveState(apanel, apSize == 1 ? shortName : ap + shortName, + jout, out); } } } out.close(); jout.close(); - } - catch (Exception ex) + } catch (Exception ex) { + //TODO: inform user of the problem - they need to know if their data was not saved ! ex.printStackTrace(); } } // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW public boolean SaveAlignment(AlignFrame af, String jarFile, - String fileName) + String fileName) { try { @@ -146,21 +203,19 @@ public class Jalview2XML FileOutputStream fos = new FileOutputStream(jarFile); JarOutputStream jout = new JarOutputStream(fos); PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, - "UTF-8")); + "UTF-8")); for (ap = 0; ap < apSize; ap++) { - AlignmentPanel apanel = (AlignmentPanel) af.alignPanels.elementAt(ap); + AlignmentPanel apanel = (AlignmentPanel) af.alignPanels + .elementAt(ap); - SaveState(apanel, - apSize == 1 ? fileName : fileName + ap, - jout, out); + SaveState(apanel, apSize == 1 ? fileName : fileName + ap, jout, out); } out.close(); jout.close(); return true; - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); return false; @@ -176,10 +231,8 @@ public class Jalview2XML * @param jout DOCUMENT ME! * @param out DOCUMENT ME! */ - public JalviewModel SaveState(AlignmentPanel ap, - String fileName, - JarOutputStream jout, - PrintWriter out) + public JalviewModel SaveState(AlignmentPanel ap, String fileName, + JarOutputStream jout, PrintWriter out) { if (seqRefIds == null) { @@ -209,10 +262,15 @@ public class Jalview2XML vamsasSet.setGapChar(jal.getGapCharacter() + ""); - if(jal.getProperties()!=null) + if (jal.getDataset() != null) + { + // dataset id is the dataset's hashcode + vamsasSet.setDatasetId(jal.getDataset().hashCode() + ""); + } + if (jal.getProperties() != null) { Enumeration en = jal.getProperties().keys(); - while(en.hasMoreElements()) + while (en.hasMoreElements()) { String key = en.nextElement().toString(); SequenceSetProperties ssp = new SequenceSetProperties(); @@ -238,27 +296,7 @@ public class Jalview2XML } else { - vamsasSeq = new Sequence(); - vamsasSeq.setId(id + ""); - vamsasSeq.setName(jds.getName()); - vamsasSeq.setSequence(jds.getSequenceAsString()); - vamsasSeq.setDescription(jds.getDescription()); - - if (jds.getDatasetSequence().getDBRef() != null) - { - jalview.datamodel.DBRefEntry[] dbrefs = - jds.getDatasetSequence().getDBRef(); - - for (int d = 0; d < dbrefs.length; d++) - { - DBRef dbref = new DBRef(); - dbref.setSource(dbrefs[d].getSource()); - dbref.setVersion(dbrefs[d].getVersion()); - dbref.setAccessionId(dbrefs[d].getAccessionId()); - vamsasSeq.addDBRef(dbref); - } - } - + vamsasSeq = createVamsasSequence(id, jds); vamsasSet.addSequence(vamsasSeq); seqRefIds.put(id + "", jal.getSequenceAt(i)); } @@ -275,20 +313,16 @@ public class Jalview2XML jseq.setHidden(av.alignment.getHiddenSequences().isHidden(jds)); if (av.hiddenRepSequences != null - && av.hiddenRepSequences.containsKey(jal.getSequenceAt(i))) + && av.hiddenRepSequences.containsKey(jal.getSequenceAt(i))) { - jalview.datamodel.SequenceI[] reps = - ( (jalview.datamodel.SequenceGroup) - av.hiddenRepSequences.get( - jal.getSequenceAt(i))).getSequencesInOrder(jal); + jalview.datamodel.SequenceI[] reps = ((jalview.datamodel.SequenceGroup) av.hiddenRepSequences + .get(jal.getSequenceAt(i))).getSequencesInOrder(jal); for (int h = 0; h < reps.length; h++) { if (reps[h] != jal.getSequenceAt(i)) { - jseq.addHiddenSequences( - jal.findIndex(reps[h]) - ); + jseq.addHiddenSequences(jal.findIndex(reps[h])); } } } @@ -296,8 +330,8 @@ public class Jalview2XML if (jds.getDatasetSequence().getSequenceFeatures() != null) { - jalview.datamodel.SequenceFeature[] sf - = jds.getDatasetSequence().getSequenceFeatures(); + jalview.datamodel.SequenceFeature[] sf = jds.getDatasetSequence() + .getSequenceFeatures(); int index = 0; while (index < sf.length) { @@ -328,8 +362,7 @@ public class Jalview2XML key = keys.nextElement().toString(); OtherData keyValue = new OtherData(); keyValue.setKey(key); - keyValue.setValue( - sf[index].otherDetails.get(key).toString()); + keyValue.setValue(sf[index].otherDetails.get(key).toString()); features.addOtherData(keyValue); } } @@ -345,8 +378,8 @@ public class Jalview2XML while (en.hasMoreElements()) { Pdbids pdb = new Pdbids(); - jalview.datamodel.PDBEntry entry - = (jalview.datamodel.PDBEntry) en.nextElement(); + jalview.datamodel.PDBEntry entry = (jalview.datamodel.PDBEntry) en + .nextElement(); pdb.setId(entry.getId()); pdb.setType(entry.getType()); @@ -362,7 +395,6 @@ public class Jalview2XML if (!jmol.pdbentry.getId().equals(entry.getId())) continue; - StructureState state = new StructureState(); state.setVisible(true); state.setXpos(jmol.getX()); @@ -371,7 +403,7 @@ public class Jalview2XML state.setHeight(jmol.getHeight()); String statestring = jmol.viewer.getStateInfo(); - if(state!=null) + if (state != null) { state.setContent(statestring.replaceAll("\n", "")); } @@ -385,7 +417,6 @@ public class Jalview2XML } } - if (entry.getFile() != null) { pdb.setFile(entry.getFile()); @@ -402,20 +433,19 @@ public class Jalview2XML File file = new File(entry.getFile()); if (file.exists() && jout != null) { - byte[] data = new byte[ (int) file.length()]; + byte[] data = new byte[(int) file.length()]; jout.putNextEntry(new JarEntry(entry.getId())); - DataInputStream dis = new DataInputStream(new - FileInputStream(file)); + DataInputStream dis = new DataInputStream( + new FileInputStream(file)); dis.readFully(data); DataOutputStream dout = new DataOutputStream(jout); dout.write(data, 0, data.length); jout.closeEntry(); } - } - catch (Exception ex) + } catch (Exception ex) { - ex.printStackTrace(); + ex.printStackTrace(); } } @@ -448,6 +478,38 @@ public class Jalview2XML { jal = av.alignment; } + // SAVE MAPPINGS + if (jal.getCodonFrames() != null && jal.getCodonFrames().length > 0) + { + jalview.datamodel.AlignedCodonFrame[] jac = jal.getCodonFrames(); + for (int i = 0; i < jac.length; i++) + { + AlcodonFrame alc = new AlcodonFrame(); + vamsasSet.addAlcodonFrame(alc); + for (int p = 0; p < jac[i].aaWidth; i++) + { + Alcodon cmap = new Alcodon(); + cmap.setPos1(jac[i].codons[p][0]); + cmap.setPos2(jac[i].codons[p][1]); + cmap.setPos3(jac[i].codons[p][2]); + alc.addAlcodon(cmap); + } + if (jac[i].getProtMappings() != null + && jac[i].getProtMappings().length > 0) + { + SequenceI[] dnas = jac[i].getdnaSeqs(); + jalview.datamodel.Mapping[] pmaps = jac[i].getProtMappings(); + for (int m = 0; m < pmaps.length; m++) + { + AlcodMap alcmap = new AlcodMap(); + alcmap.setDnasq("" + dnas[m].hashCode()); + alcmap.setMapping(createVamsasMapping(pmaps[m], dnas[m], null, + false)); + alc.addAlcodMap(alcmap); + } + } + } + } //SAVE TREES /////////////////////////////////// @@ -469,7 +531,7 @@ public class Jalview2XML { Tree tree = new Tree(); tree.setTitle(tp.getTitle()); - tree.setCurrentTree( (av.currentTree == tp.getTree())); + tree.setCurrentTree((av.currentTree == tp.getTree())); tree.setNewick(tp.getTree().toString()); tree.setThreshold(tp.treeCanvas.threshold); @@ -497,7 +559,8 @@ public class Jalview2XML //SAVE ANNOTATIONS if (jal.getAlignmentAnnotation() != null) { - jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation(); + jalview.datamodel.AlignmentAnnotation[] aa = jal + .getAlignmentAnnotation(); for (int i = 0; i < aa.length; i++) { @@ -510,9 +573,8 @@ public class Jalview2XML an.setId(aa[i].annotationId); - if (aa[i] == av.quality || - aa[i] == av.conservation || - aa[i] == av.consensus) + if (aa[i] == av.quality || aa[i] == av.conservation + || aa[i] == av.consensus) { an.setLabel(aa[i].label); an.setGraph(true); @@ -554,7 +616,7 @@ public class Jalview2XML an.setScore(aa[i].getScore()); } AnnotationElement ae; - if (aa[i].annotations!=null) + if (aa[i].annotations != null) { an.setScoreOnly(false); for (int a = 0; a < aa[i].annotations.length; a++) @@ -567,7 +629,7 @@ public class Jalview2XML ae = new AnnotationElement(); if (aa[i].annotations[a].description != null) ae.setDescription(aa[i].annotations[a].description); - if(aa[i].annotations[a].displayCharacter!=null) + if (aa[i].annotations[a].displayCharacter != null) ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter); if (!Float.isNaN(aa[i].annotations[a].value)) @@ -575,19 +637,22 @@ public class Jalview2XML ae.setPosition(a); if (aa[i].annotations[a].secondaryStructure != ' ' - && aa[i].annotations[a].secondaryStructure != '\0') - ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure - + ""); + && aa[i].annotations[a].secondaryStructure != '\0') + ae + .setSecondaryStructure(aa[i].annotations[a].secondaryStructure + + ""); - if (aa[i].annotations[a].colour!=null - && aa[i].annotations[a].colour != java.awt.Color.black) + if (aa[i].annotations[a].colour != null + && aa[i].annotations[a].colour != java.awt.Color.black) { ae.setColour(aa[i].annotations[a].colour.getRGB()); } an.addAnnotationElement(ae); } - } else { + } + else + { an.setScoreOnly(true); } vamsasSet.addAnnotation(an); @@ -603,9 +668,8 @@ public class Jalview2XML { groups[i] = new JGroup(); - jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) - jal.getGroups() - .elementAt(i); + jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal + .getGroups().elementAt(i); groups[i].setStart(sg.getStartRes()); groups[i].setEnd(sg.getEndRes()); groups[i].setName(sg.getName()); @@ -617,32 +681,30 @@ public class Jalview2XML if (sg.cs instanceof jalview.schemes.UserColourScheme) { - groups[i].setColour(SetUserColourScheme(sg.cs, - userColours, - jms)); + groups[i].setColour(SetUserColourScheme(sg.cs, userColours, + jms)); } else { - groups[i].setColour(ColourSchemeProperty.getColourName(sg. - cs)); + groups[i] + .setColour(ColourSchemeProperty.getColourName(sg.cs)); } } else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient) { - groups[i].setColour( - ColourSchemeProperty.getColourName( - ( (jalview.schemes.AnnotationColourGradient) sg.cs). - getBaseColour())); + groups[i] + .setColour(ColourSchemeProperty + .getColourName(((jalview.schemes.AnnotationColourGradient) sg.cs) + .getBaseColour())); } else if (sg.cs instanceof jalview.schemes.UserColourScheme) { - groups[i].setColour(SetUserColourScheme(sg.cs, userColours, - jms)); + groups[i] + .setColour(SetUserColourScheme(sg.cs, userColours, jms)); } else { - groups[i].setColour(ColourSchemeProperty.getColourName( - sg.cs)); + groups[i].setColour(ColourSchemeProperty.getColourName(sg.cs)); } groups[i].setPidThreshold(sg.cs.getThreshold()); @@ -658,8 +720,8 @@ public class Jalview2XML for (int s = 0; s < sg.getSize(); s++) { - jalview.datamodel.Sequence seq = - (jalview.datamodel.Sequence) sg.getSequenceAt(s); + jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg + .getSequenceAt(s); groups[i].addSeq(seq.hashCode()); } } @@ -674,8 +736,6 @@ public class Jalview2XML view.setViewName(av.viewName); view.setGatheredViews(av.gatherViewsHere); - - if (ap.av.explodedPosition != null) { view.setXpos(av.explodedPosition.x); @@ -697,13 +757,12 @@ public class Jalview2XML if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme) { view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(), - userColours, jms)); + userColours, jms)); } - else if (av.getGlobalColourScheme() instanceof jalview.schemes. - AnnotationColourGradient) + else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient) { - jalview.schemes.AnnotationColourGradient acg - = (jalview.schemes.AnnotationColourGradient) av.getGlobalColourScheme(); + jalview.schemes.AnnotationColourGradient acg = (jalview.schemes.AnnotationColourGradient) av + .getGlobalColourScheme(); AnnotationColours ac = new AnnotationColours(); ac.setAboveThreshold(acg.getAboveThreshold()); @@ -712,11 +771,12 @@ public class Jalview2XML if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme) { ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(), - userColours, jms)); + userColours, jms)); } else { - ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour())); + ac.setColourScheme(ColourSchemeProperty.getColourName(acg + .getBaseColour())); } ac.setMaxColour(acg.getMaxColour().getRGB()); @@ -726,8 +786,8 @@ public class Jalview2XML } else { - view.setBgColour(ColourSchemeProperty.getColourName( - av.getGlobalColourScheme())); + view.setBgColour(ColourSchemeProperty.getColourName(av + .getGlobalColourScheme())); } ColourSchemeI cs = av.getGlobalColourScheme(); @@ -769,27 +829,24 @@ public class Jalview2XML if (av.featuresDisplayed != null) { - jalview.schemabinding.version2.FeatureSettings fs - = new jalview.schemabinding.version2.FeatureSettings(); + jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings(); - String[] renderOrder = - ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder; + String[] renderOrder = ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder; Vector settingsAdded = new Vector(); for (int ro = 0; ro < renderOrder.length; ro++) { Setting setting = new Setting(); setting.setType(renderOrder[ro]); - setting.setColour( - ap.seqPanel.seqCanvas.getFeatureRenderer().getColour(renderOrder[ro]). - getRGB() - ); - - setting.setDisplay( - av.featuresDisplayed.containsKey(renderOrder[ro]) - ); - float rorder=ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder(renderOrder[ro]); - if (rorder>-1) { + setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer() + .getColour(renderOrder[ro]).getRGB()); + + setting.setDisplay(av.featuresDisplayed + .containsKey(renderOrder[ro])); + float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder( + renderOrder[ro]); + if (rorder > -1) + { setting.setOrder(rorder); } fs.addSetting(setting); @@ -797,8 +854,8 @@ public class Jalview2XML } //Make sure we save none displayed feature settings - Enumeration en = - ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours.keys(); + Enumeration en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours + .keys(); while (en.hasMoreElements()) { String key = en.nextElement().toString(); @@ -809,13 +866,13 @@ public class Jalview2XML Setting setting = new Setting(); setting.setType(key); - setting.setColour( - ap.seqPanel.seqCanvas.getFeatureRenderer().getColour(key).getRGB() - ); + setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer() + .getColour(key).getRGB()); setting.setDisplay(false); - float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder(key); - if (rorder>-1) + float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer().getOrder( + key); + if (rorder > -1) { setting.setOrder(rorder); } @@ -823,7 +880,7 @@ public class Jalview2XML settingsAdded.addElement(key); } en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups.keys(); - Vector groupsAdded=new Vector(); + Vector groupsAdded = new Vector(); while (en.hasMoreElements()) { String grp = en.nextElement().toString(); @@ -833,7 +890,10 @@ public class Jalview2XML } Group g = new Group(); g.setName(grp); - g.setDisplay(((Boolean)ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups.get(grp)).booleanValue()); + g + .setDisplay(((Boolean) ap.seqPanel.seqCanvas + .getFeatureRenderer().featureGroups.get(grp)) + .booleanValue()); fs.addGroup(g); groupsAdded.addElement(grp); } @@ -845,8 +905,8 @@ public class Jalview2XML { for (int c = 0; c < av.getColumnSelection().getHiddenColumns().size(); c++) { - int[] region = (int[]) av.getColumnSelection().getHiddenColumns(). - elementAt(c); + int[] region = (int[]) av.getColumnSelection().getHiddenColumns() + .elementAt(c); HiddenColumns hc = new HiddenColumns(); hc.setStart(region[0]); hc.setEnd(region[1]); @@ -875,8 +935,7 @@ public class Jalview2XML jout.putNextEntry(entry); object.marshal(out); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } @@ -884,27 +943,138 @@ public class Jalview2XML return object; } + private Sequence createVamsasSequence(int id, SequenceI jds) + { + return createVamsasSequence(true, id, jds, null); + } + + private Sequence createVamsasSequence(boolean recurse, int id, + SequenceI jds, SequenceI parentseq) + { + Sequence vamsasSeq = new Sequence(); + vamsasSeq.setId(id + ""); + vamsasSeq.setName(jds.getName()); + vamsasSeq.setSequence(jds.getSequenceAsString()); + vamsasSeq.setDescription(jds.getDescription()); + jalview.datamodel.DBRefEntry[] dbrefs = null; + if (jds.getDatasetSequence() != null) + { + vamsasSeq.setDsseqid(jds.getDatasetSequence().hashCode() + ""); + if (jds.getDatasetSequence().getDBRef() != null) + { + dbrefs = jds.getDatasetSequence().getDBRef(); + } + } + else + { + vamsasSeq.setDsseqid(id + ""); // so we can tell which sequences really are dataset sequences only + dbrefs = jds.getDBRef(); + } + if (dbrefs != null) + { + for (int d = 0; d < dbrefs.length; d++) + { + DBRef dbref = new DBRef(); + dbref.setSource(dbrefs[d].getSource()); + dbref.setVersion(dbrefs[d].getVersion()); + dbref.setAccessionId(dbrefs[d].getAccessionId()); + if (dbrefs[d].hasMap()) + { + Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq, + jds, recurse); + dbref.setMapping(mp); + } + vamsasSeq.addDBRef(dbref); + } + } + return vamsasSeq; + } + + private Mapping createVamsasMapping(jalview.datamodel.Mapping jmp, + SequenceI parentseq, SequenceI jds, boolean recurse) + { + Mapping mp = null; + if (jmp.getMap() != null) + { + mp = new Mapping(); + + jalview.util.MapList mlst = jmp.getMap(); + int r[] = mlst.getFromRanges(); + for (int s = 0; s < r.length; s += 2) + { + MapListFrom mfrom = new MapListFrom(); + mfrom.setStart(r[s]); + mfrom.setEnd(r[s + 1]); + mp.addMapListFrom(mfrom); + } + r = mlst.getToRanges(); + for (int s = 0; s < r.length; s += 2) + { + MapListTo mto = new MapListTo(); + mto.setStart(r[s]); + mto.setEnd(r[s + 1]); + mp.addMapListTo(mto); + } + mp.setMapFromUnit(mlst.getFromRatio()); + mp.setMapToUnit(mlst.getToRatio()); + if (jmp.getTo() != null) + { + MappingChoice mpc = new MappingChoice(); + if (recurse + && (parentseq != jmp.getTo() || parentseq + .getDatasetSequence() != jmp.getTo())) + { + mpc.setSequence(createVamsasSequence(false, jmp.getTo() + .hashCode(), jmp.getTo(), jds)); + } + else + { + long jmpid = 0; + SequenceI ps = null; + if (parentseq != jmp.getTo() + && parentseq.getDatasetSequence() != jmp.getTo()) + { + // chaining dbref rather than a handshaking one + jmpid = (ps = jmp.getTo()).hashCode(); + } + else + { + jmpid = (ps = parentseq).hashCode(); + } + mpc.setDseqFor("" + jmpid); + if (!seqRefIds.containsKey(mpc.getDseqFor())) + { + jalview.bin.Cache.log.debug("creatign new DseqFor ID"); + seqRefIds.put(mpc.getDseqFor(), ps); + } + else + { + jalview.bin.Cache.log.debug("reusing DseqFor ID"); + } + } + mp.setMappingChoice(mpc); + } + } + return mp; + } + String SetUserColourScheme(jalview.schemes.ColourSchemeI cs, - Vector userColours, JalviewModelSequence jms) + Vector userColours, JalviewModelSequence jms) { String id = null; - jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) - cs; + jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs; if (!userColours.contains(ucs)) { userColours.add(ucs); java.awt.Color[] colours = ucs.getColours(); - jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding. - version2.UserColours(); - jalview.schemabinding.version2.UserColourScheme jbucs = new jalview. - schemabinding.version2.UserColourScheme(); + jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours(); + jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme(); for (int i = 0; i < colours.length; i++) { - jalview.schemabinding.version2.Colour col = new jalview.schemabinding. - version2.Colour(); + jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour(); col.setName(ResidueProperties.aa[i]); col.setRGB(jalview.util.Format.getHexString(colours[i])); jbucs.addColour(col); @@ -914,8 +1084,7 @@ public class Jalview2XML colours = ucs.getLowerCaseColours(); for (int i = 0; i < colours.length; i++) { - jalview.schemabinding.version2.Colour col = new jalview.schemabinding. - version2.Colour(); + jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour(); col.setName(ResidueProperties.aa[i].toLowerCase()); col.setRGB(jalview.util.Format.getHexString(colours[i])); jbucs.addColour(col); @@ -932,7 +1101,7 @@ public class Jalview2XML } jalview.schemes.UserColourScheme GetUserColourScheme( - JalviewModelSequence jms, String id) + JalviewModelSequence jms, String id) { UserColours[] uc = jms.getUserColours(); UserColours colours = null; @@ -951,20 +1120,20 @@ public class Jalview2XML for (int i = 0; i < 24; i++) { - newColours[i] = new java.awt.Color(Integer.parseInt( - colours.getUserColourScheme().getColour(i).getRGB(), 16)); + newColours[i] = new java.awt.Color(Integer.parseInt(colours + .getUserColourScheme().getColour(i).getRGB(), 16)); } - jalview.schemes.UserColourScheme ucs = - new jalview.schemes.UserColourScheme(newColours); + jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme( + newColours); if (colours.getUserColourScheme().getColourCount() > 24) { newColours = new java.awt.Color[23]; for (int i = 0; i < 23; i++) { - newColours[i] = new java.awt.Color(Integer.parseInt( - colours.getUserColourScheme().getColour(i + 24).getRGB(), 16)); + newColours[i] = new java.awt.Color(Integer.parseInt(colours + .getUserColourScheme().getColour(i + 24).getRGB(), 16)); } ucs.setLowerCaseColours(newColours); } @@ -985,7 +1154,7 @@ public class Jalview2XML seqRefIds = new Hashtable(); viewportsAdded = new Hashtable(); - + frefedSequence = new Vector(); Hashtable gatherToThisFrame = new Hashtable(); String errorMessage = null; @@ -1041,24 +1210,21 @@ public class Jalview2XML //Some other file here. entryCount++; } - } - while (jarentry != null); - } - catch(java.io.FileNotFoundException ex) + } while (jarentry != null); + resolveFrefedSequences(); + } catch (java.io.FileNotFoundException ex) { ex.printStackTrace(); - errorMessage = "Couldn't locate Jalview XML file : "+file; - System.err.println("Exception whilst loading jalview XML file : " + - ex + "\n"); - } - catch (java.net.UnknownHostException ex) + errorMessage = "Couldn't locate Jalview XML file : " + file; + System.err.println("Exception whilst loading jalview XML file : " + + ex + "\n"); + } catch (java.net.UnknownHostException ex) { ex.printStackTrace(); - errorMessage = "Couldn't locate Jalview XML file : " +file; - System.err.println("Exception whilst loading jalview XML file : " + - ex + "\n"); - } - catch (Exception ex) + errorMessage = "Couldn't locate Jalview XML file : " + file; + System.err.println("Exception whilst loading jalview XML file : " + + ex + "\n"); + } catch (Exception ex) { //Is Version 1 Jar file? af = new Jalview2XML_V1().LoadJalviewAlign(file); @@ -1070,8 +1236,8 @@ public class Jalview2XML } ex.printStackTrace(); - System.err.println("Exception whilst loading jalview XML file : " + - ex + "\n"); + System.err.println("Exception whilst loading jalview XML file : " + + ex + "\n"); } if (Desktop.instance != null) @@ -1080,13 +1246,12 @@ public class Jalview2XML } Enumeration en = gatherToThisFrame.elements(); - while(en.hasMoreElements()) + while (en.hasMoreElements()) { - Desktop.instance.gatherViews( - (AlignFrame) en.nextElement()); + Desktop.instance.gatherViews((AlignFrame) en.nextElement()); } - if(errorMessage!=null) + if (errorMessage != null) { final String finalErrorMessage = errorMessage; javax.swing.SwingUtilities.invokeLater(new Runnable() @@ -1094,9 +1259,8 @@ public class Jalview2XML public void run() { JOptionPane.showInternalMessageDialog(Desktop.desktop, - finalErrorMessage, - "Error loading Jalview file", - JOptionPane.WARNING_MESSAGE); + finalErrorMessage, "Error loading Jalview file", + JOptionPane.WARNING_MESSAGE); } }); } @@ -1105,6 +1269,7 @@ public class Jalview2XML } Hashtable alreadyLoadedPDB; + String loadPDBFile(String file, String pdbId) { if (alreadyLoadedPDB == null) @@ -1130,8 +1295,7 @@ public class Jalview2XML do { entry = jin.getNextJarEntry(); - } - while (!entry.getName().equals(pdbId)); + } while (!entry.getName().equals(pdbId)); BufferedReader in = new BufferedReader(new InputStreamReader(jin)); File outFile = File.createTempFile("jalview_pdb", ".txt"); @@ -1139,7 +1303,7 @@ public class Jalview2XML PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); String data; - while ( (data = in.readLine()) != null) + while ((data = in.readLine()) != null) { out.println(data); } @@ -1148,8 +1312,7 @@ public class Jalview2XML alreadyLoadedPDB.put(pdbId, outFile.getAbsolutePath()); return outFile.getAbsolutePath(); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } @@ -1157,9 +1320,8 @@ public class Jalview2XML return null; } - AlignFrame LoadFromObject(JalviewModel object, - String file, - boolean loadTreesAndStructures) + AlignFrame LoadFromObject(JalviewModel object, String file, + boolean loadTreesAndStructures) { SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0); Sequence[] vamsasSeq = vamsasSet.getSequence(); @@ -1185,16 +1347,17 @@ public class Jalview2XML if (seqRefIds.get(seqId) != null) { - tmpseqs.add( (jalview.datamodel.Sequence) seqRefIds.get(seqId)); + tmpseqs.add((jalview.datamodel.Sequence) seqRefIds.get(seqId)); multipleView = true; } else { jseq = new jalview.datamodel.Sequence(vamsasSeq[i].getName(), - vamsasSeq[i].getSequence()); + vamsasSeq[i].getSequence()); jseq.setDescription(vamsasSeq[i].getDescription()); jseq.setStart(JSEQ[i].getStart()); jseq.setEnd(JSEQ[i].getEnd()); + jseq.setVamsasId(uniqueSetSuffix + seqId); seqRefIds.put(vamsasSeq[i].getId(), jseq); tmpseqs.add(jseq); } @@ -1206,38 +1369,46 @@ public class Jalview2XML hiddenSeqs = new Vector(); } - hiddenSeqs.addElement( - (jalview.datamodel.Sequence) seqRefIds.get(seqId)); + hiddenSeqs.addElement((jalview.datamodel.Sequence) seqRefIds + .get(seqId)); } } - ///SequenceFeatures are added to the DatasetSequence, - // so we must create the dataset before loading features + /// + // Create the alignment object from the sequence set ///////////////////////////////// - - - jalview.datamodel.Sequence[] orderedSeqs = new jalview.datamodel.Sequence[ - tmpseqs.size()]; + jalview.datamodel.Sequence[] orderedSeqs = new jalview.datamodel.Sequence[tmpseqs + .size()]; tmpseqs.toArray(orderedSeqs); - jalview.datamodel.Alignment al = - new jalview.datamodel.Alignment(orderedSeqs); + jalview.datamodel.Alignment al = new jalview.datamodel.Alignment( + orderedSeqs); - for(int i=0; i 0) + { + addDBRefs(al.getSequenceAt(i).getDatasetSequence(), vamsasSeq[i]); + } if (JSEQ[i].getPdbidsCount() > 0) { Pdbids[] ids = JSEQ[i].getPdbids(); for (int p = 0; p < ids.length; p++) { - jalview.datamodel.PDBEntry entry = new jalview.datamodel. - PDBEntry(); + jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry(); entry.setId(ids[p].getId()); entry.setType(ids[p].getType()); if (ids[p].getFile() != null) @@ -1296,29 +1468,57 @@ public class Jalview2XML al.getSequenceAt(i).getDatasetSequence().addPDBId(entry); } } - if (vamsasSeq[i].getDBRefCount() > 0) + } + } + + ///////////////////////////////// + // LOAD SEQUENCE MAPPINGS + if (vamsasSet.getAlcodonFrameCount() > 0) + { + AlcodonFrame[] alc = vamsasSet.getAlcodonFrame(); + for (int i = 0; i < alc.length; i++) + { + jalview.datamodel.AlignedCodonFrame cf = new jalview.datamodel.AlignedCodonFrame( + alc[i].getAlcodonCount()); + if (alc[i].getAlcodonCount() > 0) { - for (int d = 0; d < vamsasSeq[i].getDBRefCount(); d++) + Alcodon[] alcods = alc[i].getAlcodon(); + for (int p = 0; p < cf.codons.length; p++) { - jalview.datamodel.DBRefEntry entry = - new jalview.datamodel.DBRefEntry( - vamsasSeq[i].getDBRef(d).getSource(), - vamsasSeq[i].getDBRef(d).getVersion(), - vamsasSeq[i].getDBRef(d).getAccessionId() - ); - al.getSequenceAt(i).getDatasetSequence().addDBRef(entry); + cf.codons[p] = new int[3]; + cf.codons[p][0] = (int) alcods[p].getPos1(); + cf.codons[p][1] = (int) alcods[p].getPos2(); + cf.codons[p][2] = (int) alcods[p].getPos3(); + } + } + if (alc[i].getAlcodMapCount() > 0) + { + AlcodMap[] maps = alc[i].getAlcodMap(); + for (int m = 0; m < maps.length; m++) + { + SequenceI dnaseq = (SequenceI) seqRefIds + .get(maps[m].getDnasq()); + // Load Mapping + // attach to dna sequence reference. + if (dnaseq != null) + { + if (maps[m].getMapping() != null) + { + jalview.datamodel.Mapping mapping = addMapping(maps[m] + .getMapping()); + cf.addMap(dnaseq, mapping.getTo(), mapping.getMap()); + } + } } - } + al.addCodonFrame(cf); } + } - ///////////////////////////////// ////////////////////////////////// //LOAD ANNOTATIONS - boolean hideQuality = true, - hideConservation = true, - hideConsensus = true; + boolean hideQuality = true, hideConservation = true, hideConsensus = true; if (vamsasSet.getAnnotationCount() > 0) { @@ -1343,11 +1543,10 @@ public class Jalview2XML } if (an[i].getId() != null - && annotationIds.containsKey(an[i].getId())) + && annotationIds.containsKey(an[i].getId())) { - jalview.datamodel.AlignmentAnnotation jda = - (jalview.datamodel.AlignmentAnnotation) annotationIds.get(an[i]. - getId()); + jalview.datamodel.AlignmentAnnotation jda = (jalview.datamodel.AlignmentAnnotation) annotationIds + .get(an[i].getId()); if (an[i].hasVisible()) jda.visible = an[i].getVisible(); @@ -1361,27 +1560,24 @@ public class Jalview2XML if (!an[i].getScoreOnly()) { - anot = new jalview.datamodel.Annotation[ - al.getWidth()]; + anot = new jalview.datamodel.Annotation[al.getWidth()]; for (int aa = 0; aa < ae.length && aa < anot.length; aa++) { - if(ae[aa].getPosition()>=anot.length) + if (ae[aa].getPosition() >= anot.length) continue; anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation( - ae[aa].getDisplayCharacter(), - ae[aa].getDescription(), - (ae[aa].getSecondaryStructure()==null || ae[aa].getSecondaryStructure().length() == 0) ? ' ' : - ae[aa].getSecondaryStructure().charAt(0), - ae[aa].getValue() - - ); + ae[aa].getDisplayCharacter(), ae[aa].getDescription(), (ae[aa] + .getSecondaryStructure() == null || ae[aa] + .getSecondaryStructure().length() == 0) ? ' ' : ae[aa] + .getSecondaryStructure().charAt(0), ae[aa].getValue() + ); - anot[ae[aa].getPosition()].colour = new java.awt.Color(ae[aa]. - getColour()); + anot[ae[aa].getPosition()].colour = new java.awt.Color(ae[aa] + .getColour()); } } jalview.datamodel.AlignmentAnnotation jaa = null; @@ -1389,18 +1585,16 @@ public class Jalview2XML if (an[i].getGraph()) { jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot, 0, 0, - an[i].getGraphType()); + an[i].getDescription(), anot, 0, 0, an[i].getGraphType()); jaa.graphGroup = an[i].getGraphGroup(); if (an[i].getThresholdLine() != null) { - jaa.setThreshold(new jalview.datamodel.GraphLine( - an[i].getThresholdLine().getValue(), - an[i].getThresholdLine().getLabel(), - new java.awt.Color(an[i].getThresholdLine().getColour())) - ); + jaa.setThreshold(new jalview.datamodel.GraphLine(an[i] + .getThresholdLine().getValue(), an[i] + .getThresholdLine().getLabel(), new java.awt.Color( + an[i].getThresholdLine().getColour()))); } @@ -1408,7 +1602,7 @@ public class Jalview2XML else { jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot); + an[i].getDescription(), anot); } if (an[i].getId() != null) @@ -1421,9 +1615,8 @@ public class Jalview2XML { if (al.findName(an[i].getSequenceRef()) != null) { - jaa.createSequenceMapping( - al.findName(an[i].getSequenceRef()), 1, true - ); + jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()), + 1, true); al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa); } } @@ -1432,8 +1625,8 @@ public class Jalview2XML jaa.setScore(an[i].getScore()); } - if(an[i].hasVisible()) - jaa.visible = an[i].getVisible(); + if (an[i].hasVisible()) + jaa.visible = an[i].getVisible(); al.addAnnotation(jaa); } @@ -1457,8 +1650,7 @@ public class Jalview2XML } else { - cs = ColourSchemeProperty.getColour(al, - groups[i].getColour()); + cs = ColourSchemeProperty.getColour(al, groups[i].getColour()); } if (cs != null) @@ -1472,8 +1664,8 @@ public class Jalview2XML for (int s = 0; s < groups[i].getSeqCount(); s++) { String seqId = groups[i].getSeq(s) + ""; - jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) - seqRefIds.get(seqId); + jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) seqRefIds + .get(seqId); if (ts != null) { @@ -1486,14 +1678,14 @@ public class Jalview2XML continue; } - jalview.datamodel.SequenceGroup sg = new jalview.datamodel. - SequenceGroup(seqs, - groups[i].getName(), cs, groups[i].getDisplayBoxes(), - groups[i].getDisplayText(), groups[i].getColourText(), - groups[i].getStart(), groups[i].getEnd()); + jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup( + seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(), + groups[i].getDisplayText(), groups[i].getColourText(), + groups[i].getStart(), groups[i].getEnd()); - sg.setOutlineColour(new java.awt.Color( - groups[i].getOutlineColour())); + sg + .setOutlineColour(new java.awt.Color(groups[i] + .getOutlineColour())); sg.textColour = new java.awt.Color(groups[i].getTextCol1()); sg.textColour2 = new java.awt.Color(groups[i].getTextCol2()); @@ -1502,9 +1694,8 @@ public class Jalview2XML if (groups[i].getConsThreshold() != 0) { jalview.analysis.Conservation c = new jalview.analysis.Conservation( - "All", - ResidueProperties.propHash, 3, sg.getSequences(null), 0, - sg.getWidth() - 1); + "All", ResidueProperties.propHash, 3, sg + .getSequences(null), 0, sg.getWidth() - 1); c.calculate(); c.verdict(false, 25); sg.cs.setConservation(c); @@ -1517,18 +1708,14 @@ public class Jalview2XML ///////////////////////////////// // LOAD VIEWPORT - AlignFrame af = new AlignFrame(al, - view.getWidth(), - view.getHeight()); + AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight()); af.setFileName(file, "Jalview"); for (int i = 0; i < JSEQ.length; i++) { - af.viewport.setSequenceColour( - af.viewport.alignment.getSequenceAt(i), - new java.awt.Color( - JSEQ[i].getColour())); + af.viewport.setSequenceColour(af.viewport.alignment.getSequenceAt(i), + new java.awt.Color(JSEQ[i].getColour())); } //If we just load in the same jar file again, the sequenceSetId @@ -1541,9 +1728,8 @@ public class Jalview2XML if (view.getSequenceSetId() != null) { - jalview.gui.AlignViewport av = - (jalview.gui.AlignViewport) - viewportsAdded.get(uniqueSeqSetId); + jalview.gui.AlignViewport av = (jalview.gui.AlignViewport) viewportsAdded + .get(uniqueSeqSetId); af.viewport.sequenceSetID = uniqueSeqSetId; if (av != null) @@ -1563,21 +1749,18 @@ public class Jalview2XML { for (int s = 0; s < JSEQ.length; s++) { - jalview.datamodel.SequenceGroup hidden = - new jalview.datamodel.SequenceGroup(); + jalview.datamodel.SequenceGroup hidden = new jalview.datamodel.SequenceGroup(); for (int r = 0; r < JSEQ[s].getHiddenSequencesCount(); r++) { - hidden.addSequence( - al.getSequenceAt(JSEQ[s].getHiddenSequences(r)) - , false - ); + hidden.addSequence(al + .getSequenceAt(JSEQ[s].getHiddenSequences(r)), false); } af.viewport.hideRepSequences(al.getSequenceAt(s), hidden); } - jalview.datamodel.SequenceI[] hseqs = new - jalview.datamodel.SequenceI[hiddenSeqs.size()]; + jalview.datamodel.SequenceI[] hseqs = new jalview.datamodel.SequenceI[hiddenSeqs + .size()]; for (int s = 0; s < hiddenSeqs.size(); s++) { @@ -1588,21 +1771,18 @@ public class Jalview2XML } - if ( (hideConsensus || hideQuality || hideConservation) - && al.getAlignmentAnnotation() != null) + if ((hideConsensus || hideQuality || hideConservation) + && al.getAlignmentAnnotation() != null) { int hSize = al.getAlignmentAnnotation().length; for (int h = 0; h < hSize; h++) { - if ( - (hideConsensus && - al.getAlignmentAnnotation()[h].label.equals("Consensus")) - || - (hideQuality && - al.getAlignmentAnnotation()[h].label.equals("Quality")) - || - (hideConservation && - al.getAlignmentAnnotation()[h].label.equals("Conservation"))) + if ((hideConsensus && al.getAlignmentAnnotation()[h].label + .equals("Consensus")) + || (hideQuality && al.getAlignmentAnnotation()[h].label + .equals("Quality")) + || (hideConservation && al.getAlignmentAnnotation()[h].label + .equals("Conservation"))) { al.deleteAnnotation(al.getAlignmentAnnotation()[h]); hSize--; @@ -1617,8 +1797,8 @@ public class Jalview2XML af.viewport.viewName = view.getViewName(); af.setInitialTabVisible(); } - af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), - view.getHeight()); + af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), view + .getHeight()); af.viewport.setShowAnnotation(view.getShowAnnotation()); af.viewport.setAbovePIDThreshold(view.getPidSelected()); @@ -1628,8 +1808,8 @@ public class Jalview2XML af.viewport.setConservationSelected(view.getConservationSelected()); af.viewport.setShowJVSuffix(view.getShowFullId()); af.viewport.rightAlignIds = view.getRightAlignIds(); - af.viewport.setFont(new java.awt.Font(view.getFontName(), - view.getFontStyle(), view.getFontSize())); + af.viewport.setFont(new java.awt.Font(view.getFontName(), view + .getFontStyle(), view.getFontSize())); af.alignPanel.fontChanged(); af.viewport.setRenderGaps(view.getRenderGaps()); af.viewport.setWrapAlignment(view.getWrapAlignment()); @@ -1659,54 +1839,47 @@ public class Jalview2XML else if (view.getBgColour().startsWith("Annotation")) { //int find annotation - for (int i = 0; - i < af.viewport.alignment.getAlignmentAnnotation().length; i++) + for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++) { - if (af.viewport.alignment.getAlignmentAnnotation()[i].label. - equals(view.getAnnotationColours().getAnnotation())) + if (af.viewport.alignment.getAlignmentAnnotation()[i].label + .equals(view.getAnnotationColours().getAnnotation())) { - if (af.viewport.alignment.getAlignmentAnnotation()[i]. - getThreshold() == null) + if (af.viewport.alignment.getAlignmentAnnotation()[i] + .getThreshold() == null) { - af.viewport.alignment.getAlignmentAnnotation()[i]. - setThreshold( - new jalview.datamodel.GraphLine( - view.getAnnotationColours().getThreshold(), - "Threshold", java.awt.Color.black) + af.viewport.alignment.getAlignmentAnnotation()[i] + .setThreshold(new jalview.datamodel.GraphLine(view + .getAnnotationColours().getThreshold(), + "Threshold", java.awt.Color.black) - ); + ); } - if (view.getAnnotationColours().getColourScheme().equals( - "None")) + if (view.getAnnotationColours().getColourScheme() + .equals("None")) { - cs = new AnnotationColourGradient( - af.viewport.alignment.getAlignmentAnnotation()[i], - new java.awt.Color(view.getAnnotationColours(). - getMinColour()), - new java.awt.Color(view.getAnnotationColours(). - getMaxColour()), - view.getAnnotationColours().getAboveThreshold()); + cs = new AnnotationColourGradient(af.viewport.alignment + .getAlignmentAnnotation()[i], new java.awt.Color(view + .getAnnotationColours().getMinColour()), + new java.awt.Color(view.getAnnotationColours() + .getMaxColour()), view.getAnnotationColours() + .getAboveThreshold()); } - else if (view.getAnnotationColours().getColourScheme(). - startsWith("ucs")) + else if (view.getAnnotationColours().getColourScheme() + .startsWith("ucs")) { - cs = new AnnotationColourGradient( - af.viewport.alignment.getAlignmentAnnotation()[i], - GetUserColourScheme(jms, view.getAnnotationColours(). - getColourScheme()), - view.getAnnotationColours().getAboveThreshold() - ); + cs = new AnnotationColourGradient(af.viewport.alignment + .getAlignmentAnnotation()[i], GetUserColourScheme( + jms, view.getAnnotationColours().getColourScheme()), + view.getAnnotationColours().getAboveThreshold()); } else { - cs = new AnnotationColourGradient( - af.viewport.alignment.getAlignmentAnnotation()[i], - ColourSchemeProperty.getColour(al, - view.getAnnotationColours(). - getColourScheme()), - view.getAnnotationColours().getAboveThreshold() - ); + cs = new AnnotationColourGradient(af.viewport.alignment + .getAlignmentAnnotation()[i], ColourSchemeProperty + .getColour(al, view.getAnnotationColours() + .getColourScheme()), view + .getAnnotationColours().getAboveThreshold()); } // Also use these settings for all the groups @@ -1714,9 +1887,8 @@ public class Jalview2XML { for (int g = 0; g < al.getGroups().size(); g++) { - jalview.datamodel.SequenceGroup sg - = (jalview.datamodel.SequenceGroup) al.getGroups(). - elementAt(g); + jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) al + .getGroups().elementAt(g); if (sg.cs == null) { @@ -1736,10 +1908,9 @@ public class Jalview2XML else*/ { sg.cs = new AnnotationColourGradient( - af.viewport.alignment.getAlignmentAnnotation()[i], - sg.cs, - view.getAnnotationColours().getAboveThreshold() - ); + af.viewport.alignment.getAlignmentAnnotation()[i], + sg.cs, view.getAnnotationColours() + .getAboveThreshold()); } } @@ -1782,31 +1953,32 @@ public class Jalview2XML if (jms.getFeatureSettings() != null) { af.viewport.featuresDisplayed = new Hashtable(); - String[] renderOrder = new String[jms.getFeatureSettings(). - getSettingCount()]; + String[] renderOrder = new String[jms.getFeatureSettings() + .getSettingCount()]; for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++) { Setting setting = jms.getFeatureSettings().getSetting(fs); - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting. - getType(), - new java.awt.Color(setting.getColour())); + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour( + setting.getType(), new java.awt.Color(setting.getColour())); renderOrder[fs] = setting.getType(); if (setting.hasOrder()) - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(setting.getType(), setting.getOrder()); + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder( + setting.getType(), setting.getOrder()); else - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder(setting.getType(), fs/jms.getFeatureSettings().getSettingCount()); + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder( + setting.getType(), + fs / jms.getFeatureSettings().getSettingCount()); if (setting.getDisplay()) { - af.viewport.featuresDisplayed.put( - setting.getType(), new Integer(setting.getColour())); + af.viewport.featuresDisplayed.put(setting.getType(), new Integer( + setting.getColour())); } } - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = - renderOrder; + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder; Hashtable fgtable; - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureGroups = fgtable=new Hashtable(); - for (int gs=0;gs dsq.getEnd(); + //if (pre || post) + if (sq!=dsq) + { + StringBuffer sb = new StringBuffer(); + String newres = jalview.analysis.AlignSeq.extractGaps( + jalview.util.Comparison.GapChars, sq.getSequenceAsString()); + if (!newres.equalsIgnoreCase(dsq.getSequenceAsString()) && newres.length()>dsq.getLength()) + { + // Update with the longer sequence. + synchronized (dsq) + { + /*if (pre) + { + sb.insert(0, newres + .substring(0, dsq.getStart() - sq.getStart())); + dsq.setStart(sq.getStart()); + } + if (post) + { + sb.append(newres.substring(newres.length() - sq.getEnd() + - dsq.getEnd())); + dsq.setEnd(sq.getEnd()); + } + */ + dsq.setSequence(sb.toString()); + } + //TODO: merges will never happen if we 'know' we have the real dataset sequence - this should be detected when id==dssid + System.err + .println("DEBUG Notice: Merged dataset sequence"); // (" + // + (pre ? "prepended" : "") + " " + //+ (post ? "appended" : "")); + } + } + } + + java.util.Hashtable datasetIds = null; + + private Alignment getDatasetFor(String datasetId) + { + if (datasetIds == null) + { + datasetIds = new Hashtable(); + return null; + } + if (datasetIds.containsKey(datasetId)) + { + return (Alignment) datasetIds.get(datasetId); + } + return null; + } + + private void addDatasetRef(String datasetId, Alignment dataset) + { + if (datasetIds == null) + { + datasetIds = new Hashtable(); + } + datasetIds.put(datasetId, dataset); + } + + private void addDBRefs(SequenceI datasetSequence, Sequence sequence) + { + for (int d = 0; d < sequence.getDBRefCount(); d++) + { + DBRef dr = sequence.getDBRef(d); + jalview.datamodel.DBRefEntry entry = new jalview.datamodel.DBRefEntry( + sequence.getDBRef(d).getSource(), sequence.getDBRef(d) + .getVersion(), sequence.getDBRef(d).getAccessionId()); + if (dr.getMapping() != null) + { + entry.setMap(addMapping(dr.getMapping())); + } + datasetSequence.addDBRef(entry); + } + } + + private jalview.datamodel.Mapping addMapping(Mapping m) + { + SequenceI dsto = null; + // Mapping m = dr.getMapping(); + int fr[] = new int[m.getMapListFromCount() * 2]; + Enumeration f = m.enumerateMapListFrom(); + for (int _i = 0; f.hasMoreElements(); _i += 2) + { + MapListFrom mf = (MapListFrom) f.nextElement(); + fr[_i] = mf.getStart(); + fr[_i + 1] = mf.getEnd(); + } + int fto[] = new int[m.getMapListToCount() * 2]; + f = m.enumerateMapListTo(); + for (int _i = 0; f.hasMoreElements(); _i += 2) + { + MapListTo mf = (MapListTo) f.nextElement(); + fto[_i] = mf.getStart(); + fto[_i + 1] = mf.getEnd(); + } + jalview.datamodel.Mapping jmap = new jalview.datamodel.Mapping(dsto, + fr, fto, (int) m.getMapFromUnit(), (int) m.getMapToUnit()); + if (m.getMappingChoice() != null) + { + MappingChoice mc = m.getMappingChoice(); + if (mc.getDseqFor() != null) + { + if (seqRefIds.containsKey(mc.getDseqFor())) + { + /** + * recover from hash + */ + jmap.setTo((SequenceI) seqRefIds.get(mc.getDseqFor())); + } + else + { + frefedSequence.add(new Object[] + { mc.getDseqFor(), jmap }); + } + } + else + { + /** + * local sequence definition + */ + Sequence ms = mc.getSequence(); + jalview.datamodel.Sequence djs=null; + String sqid = ms.getDsseqid(); + if (sqid!=null && sqid.length()>0) + { + /* + * recover dataset sequence + */ + djs = (jalview.datamodel.Sequence) seqRefIds.get(sqid); + } else { + System.err.println("Warning - making up dataset sequence id for DbRef sequence map reference"); + sqid = ""+ms.hashCode(); // make up a new hascode for undefined dataset sequence hash (unlikely to happen) + } + + if (djs==null) { + /** + * make a new dataset sequence and add it to refIds hash + */ + djs = new jalview.datamodel.Sequence(ms + .getName(), ms.getSequence()); + djs.setStart(jmap.getMap().getToLowest()); + djs.setEnd(jmap.getMap().getToHighest()); + djs.setVamsasId(uniqueSetSuffix + sqid); + jmap.setTo(djs); + seqRefIds.put(sqid, djs); + + } + jalview.bin.Cache.log.debug("about to recurse on addDBRefs."); + addDBRefs(djs, ms); + + } + } + return (jmap); + + } + public jalview.gui.AlignmentPanel copyAlignPanel(AlignmentPanel ap, - boolean keepSeqRefs) + boolean keepSeqRefs) { - jalview.schemabinding.version2.JalviewModel jm - = SaveState(ap, null, null, null); + jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null, + null, null); if (!keepSeqRefs) {