\r
package jalview.io;\r
\r
+import org.vamsas.client.Vobject;\r
+import org.vamsas.client.VorbaId;\r
import org.vamsas.objects.core.*;\r
+import org.vamsas.objects.utils.DocumentStuff;\r
+import org.vamsas.test.simpleclient.ClientDoc;\r
\r
+import jalview.bin.Cache;\r
+import jalview.datamodel.SequenceI;\r
import jalview.gui.*;\r
import java.io.*;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Hashtable;\r
+import java.util.IdentityHashMap;\r
import java.util.jar.*;\r
import org.exolab.castor.xml.*;\r
import org.exolab.castor.mapping.Mapping;\r
"org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer");\r
}\r
\r
-*/\r
+ */\r
\r
public class VamsasDatastore\r
{\r
+ Entry provEntry=null;\r
AlignViewport av;\r
- org.exolab.castor.types.Date date\r
- = new org.exolab.castor.types.Date(new java.util.Date());\r
-\r
- public VamsasDatastore(AlignViewport av)\r
- {\r
- this.av = av;\r
+ org.exolab.castor.types.Date date\r
+ = new org.exolab.castor.types.Date(new java.util.Date());\r
+ ClientDoc cdoc;\r
+ Hashtable vobj2jv;\r
+ IdentityHashMap jv2vobj;\r
+ public VamsasDatastore(ClientDoc cdoc, Hashtable vobj2jv, IdentityHashMap jv2vobj, Entry provEntry) {\r
+ \r
+ this.cdoc = cdoc;\r
+ this.vobj2jv = vobj2jv;\r
+ this.jv2vobj = jv2vobj;\r
+ this.provEntry = provEntry;\r
}\r
-\r
- public void store(String file)\r
- {\r
- storeVAMSAS(file);\r
- }\r
-\r
- public void storeJalview(String file, AlignFrame af)\r
+ \r
+ /* public void storeJalview(String file, AlignFrame af)\r
{\r
try\r
{\r
}\r
\r
\r
-\r
- public VAMSAS storeVAMSAS(String file)\r
- {\r
- long time = System.currentTimeMillis();\r
- VAMSAS vamsas = new VAMSAS();\r
-\r
- try\r
- {\r
- FileOutputStream fos = new FileOutputStream(file);\r
- JarOutputStream jout = new JarOutputStream(fos);\r
-\r
-\r
- ////////////////////////////////////////////////////\r
- //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
- PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,\r
- "UTF-8"));\r
-\r
- jalview.datamodel.AlignmentI jal = av.getAlignment();\r
-\r
-\r
- ///////////////////////////////////////////\r
- // SAVE THE DATASET\r
- DataSet dataset = new DataSet();\r
- vamsas.addDataSet(dataset);\r
-\r
- Sequence sequence;\r
- DbRef dbref;\r
- for (int i = 0; i < jal.getHeight(); i++)\r
- {\r
- sequence = new Sequence();\r
- sequence.setSequence(jal.getDataset().getSequenceAt(i).getSequence());\r
- sequence.setName(jal.getDataset().getSequenceAt(i).getName());\r
- sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());\r
- sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());\r
-\r
-\r
- if(jal.getDataset().getSequenceAt(i).getSequenceFeatures()!=null)\r
- {\r
- int sfSize = jal.getDataset().getSequenceAt(i).getSequenceFeatures().length;\r
-\r
- for (int sf = 0; sf < sfSize; sf++)\r
- {\r
- jalview.datamodel.SequenceFeature feature =\r
- (jalview.datamodel.SequenceFeature)\r
- jal.getDataset().getSequenceAt(i).getSequenceFeatures()[sf];\r
-\r
- DataSetAnnotations dsa = new DataSetAnnotations();\r
- dsa.setType(feature.getType());\r
- dsa.setBegin(feature.getBegin());\r
- dsa.setEnd(feature.getEnd());\r
- dsa.setDescription(feature.getDescription());\r
- dsa.setStatus(feature.getStatus());\r
- dsa.addProvenance(dummyProvenance());\r
- dsa.setSeqRef(sequence);\r
- dsa.setId("sf"+(time++));\r
- dataset.addDataSetAnnotations(dsa);\r
- }\r
- }\r
-\r
- if(jal.getDataset().getSequenceAt(i).getDBRef()!=null)\r
- {\r
- java.util.Vector entries = jal.getDataset().getSequenceAt(i).getDBRef();\r
- jalview.datamodel.DBRefEntry dbentry;\r
- for(int db=0; db<entries.size(); db++)\r
- {\r
- dbentry = (jalview.datamodel.DBRefEntry)entries.elementAt(db);\r
- dbref = new DbRef();\r
- dbref.setAccessionId( dbentry.getAccessionId() );\r
- dbref.setSource( dbentry.getSource() );\r
- dbref.setVersion( dbentry.getVersion() );\r
- dbref.setId("db"+(time++));\r
- sequence.addDbRef(dbref);\r
- }\r
-\r
- }\r
-\r
-\r
- if(jal.getDataset().getSequenceAt(i).getVamsasId()==null)\r
- sequence.setId("ds" + (time++));\r
- else\r
- sequence.setId(jal.getDataset().getSequenceAt(i).getVamsasId());\r
-\r
- dataset.addSequence(sequence);\r
- }\r
- // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));\r
- //////////////////////////////////////////////\r
-\r
-\r
- //////////////////////////////////////////////\r
- //Save the Alignments\r
- Alignment alignment = new Alignment();\r
- alignment.setGapChar(av.getGapCharacter() + "");\r
- AlignmentSequence alseq = null;\r
- for (int i = 0; i < jal.getHeight(); i++)\r
- {\r
- alseq = new AlignmentSequence();\r
- alseq.setSequence(\r
- jal.getSequenceAt(i).getSequence()\r
- );\r
- alseq.setName(jal.getSequenceAt(i).getName());\r
- alseq.setStart(jal.getSequenceAt(i).getStart());\r
- alseq.setEnd(jal.getSequenceAt(i).getEnd());\r
- alseq.setRefid(dataset.getSequence(i));\r
- alseq.setId("as" + (time++));\r
- alignment.addAlignmentSequence(alseq);\r
- }\r
- // alignment.setProvenance(getVamsasProvenance(jal.getProvenance()));\r
- dataset.addAlignment(alignment);\r
- //////////////////////////////////////////////\r
-\r
-\r
-\r
- //////////////////////////////////////////////\r
- //SAVE ANNOTATIONS\r
- if (jal.getAlignmentAnnotation() != null)\r
- {\r
- jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();\r
-\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- if (aa[i].label.equals("Quality") ||\r
- aa[i].label.equals("Conservation") ||\r
- aa[i].label.equals("Consensus"))\r
- {\r
- continue;\r
- }\r
-\r
- AlignmentAnnotations an = new AlignmentAnnotations();\r
-\r
- an.setDescription(aa[i].description);\r
- // JBPNote - have to deal with the many lines for one graph thing\r
- if (aa[i].graph>0)\r
- an.setGraph(true); //aa[i].graph);\r
- // JBPNote - store graphGroup in the Jalview specific bits.\r
- an.setLabel(aa[i].label);\r
- an.setProvenance(dummyProvenance());\r
-\r
- AnnotationElement ae;\r
-\r
- for (int a = 0; a < aa[i].annotations.length; a++)\r
- {\r
- if ((aa[i] == null) || (aa[i].annotations[a] == null))\r
- {\r
- continue;\r
- }\r
-\r
- ae = new AnnotationElement();\r
- ae.setDescription(aa[i].annotations[a].description);\r
- ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);\r
- ae.setValue(aa[i].annotations[a].value);\r
- ae.setPosition(a);\r
- ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +\r
- "");\r
- an.addAnnotationElement(ae);\r
- }\r
-\r
- alignment.addAlignmentAnnotations(an);\r
- }\r
- }\r
- ///////////////////////////////////////////////////////\r
-\r
-\r
- ////////////////////////////////////////////////\r
- ///SAVE THE TREES\r
- ///////////////////////////////////\r
- // FIND ANY ASSOCIATED TREES\r
- if (Desktop.desktop != null)\r
- {\r
- javax.swing.JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
-\r
- for (int t = 0; t < frames.length; t++)\r
- {\r
- if (frames[t] instanceof TreePanel)\r
- {\r
- TreePanel tp = (TreePanel) frames[t];\r
-\r
- if (tp.getAlignment() == jal)\r
- {\r
- Tree tree = new Tree();\r
- tree.setTitle(tp.getTitle());\r
- Newick newick = new Newick();\r
- newick.setContent( tp.getTree().toString() );\r
- newick.setTitle( tp.getTitle() );\r
- newick.setId("t"+(time++));\r
- tree.addNewick( newick );\r
- tree.setProvenance(dummyProvenance());\r
- alignment.addTree(tree);\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- JarEntry entry = new JarEntry("vamsas.xml");\r
- jout.putNextEntry(entry);\r
-\r
- vamsas.marshal(out);\r
-\r
- out.close();\r
- jout.close();\r
-\r
-\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
-\r
- return vamsas;\r
+ */\r
+ \r
+ protected Vobject getjv2vObj(Object jvobj) {\r
+ if (jv2vobj.containsKey(jvobj))\r
+ return cdoc.getObject(((VorbaId)jv2vobj.get(jvobj)));\r
+ return null;\r
}\r
-\r
- Tree jalview2VamsasTree()\r
- {\r
- Tree tree = new Tree();\r
-\r
- return tree;\r
- }\r
-\r
-\r
- public void load(String file)\r
+ \r
+ protected Object getvObj2jv(org.vamsas.client.Vobject vobj) {\r
+ VorbaId id = vobj.getVorbaId();\r
+ if (id==null) {\r
+ id = cdoc.registerObject(vobj);\r
+ Cache.log.debug("Registering new object and returning null for getvObj2jv");\r
+ return null;\r
+ }\r
+ if (vobj2jv.containsKey(vobj.getVorbaId()))\r
+ return vobj2jv.get(id);\r
+ return null;\r
+ }\r
+ protected void bindjvvobj(Object jvobj, org.vamsas.client.Vobject vobj) {\r
+ VorbaId id = vobj.getVorbaId();\r
+ if (id==null) {\r
+ id = cdoc.registerObject(vobj);\r
+ }\r
+ if (vobj2jv.containsKey(vobj.getVorbaId())||jv2vobj.containsKey(jvobj)) {\r
+ Cache.log.error("Duplicate object binding!");\r
+ } else {\r
+ vobj2jv.put(vobj.getVorbaId(),jvobj);// JBPNote - better implementing a hybrid invertible hash.\r
+ jv2vobj.put(jvobj,vobj.getVorbaId()); \r
+ }\r
+ }\r
+ \r
+ public void storeVAMSAS(AlignViewport av) \r
{\r
- VAMSAS vamsas = new VAMSAS() ;\r
-\r
- try\r
- {\r
- FileInputStream fis = new FileInputStream(file);\r
- JarInputStream jin = new JarInputStream(fis);\r
-\r
-\r
- ////////////////////////////////////////////////////\r
- //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS\r
- InputStreamReader in = new InputStreamReader(jin, "UTF-8");\r
- JarEntry jarentry = jin.getNextJarEntry();\r
- System.out.println("reading: "+jarentry.getName());\r
- vamsas = (VAMSAS) vamsas.unmarshal(in);\r
-\r
-\r
- /////////////////////////////////////\r
- /////LOAD DATASET\r
- DataSet dataset = vamsas.getDataSet(0);\r
-\r
- int i, iSize = dataset.getSequenceCount();\r
- jalview.datamodel.Sequence [] seqs = new jalview.datamodel.Sequence[iSize];\r
- DbRef [] dbref;\r
-\r
- for (i = 0; i < iSize ; i++)\r
- {\r
- seqs[i] = new jalview.datamodel.Sequence(\r
- dataset.getSequence(i).getName(),\r
- dataset.getSequence(i).getSequence(),\r
- dataset.getSequence(i).getStart(),\r
- dataset.getSequence(i).getEnd() );\r
- seqs[i].setVamsasId(dataset.getSequence(i).getId());\r
-\r
- if (dataset.getDataSetAnnotations() != null)\r
- {\r
- for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)\r
- {\r
- if (dataset.getDataSetAnnotations(dsa).getSeqRef() ==\r
- dataset.getSequence(i))\r
- {\r
- seqs[i].addSequenceFeature(new jalview.datamodel.\r
- SequenceFeature(\r
- dataset.getDataSetAnnotations(dsa).getType(),\r
- dataset.getDataSetAnnotations(dsa).getDescription(),\r
- dataset.getDataSetAnnotations(dsa).getStatus(),\r
- dataset.getDataSetAnnotations(dsa).getBegin(),\r
- dataset.getDataSetAnnotations(dsa).getEnd(),\r
- "vamsas"));\r
- }\r
- }\r
- }\r
- dbref = dataset.getSequence(i).getDbRef();\r
-\r
- if(dbref.length>0)\r
- {\r
- for(int db=0; db<dbref.length; db++)\r
- {\r
- seqs[i].addDBRef( new jalview.datamodel.DBRefEntry\r
- (\r
- dbref[db].getSource().toString(),\r
- dbref[db].getVersion().toString(),\r
- dbref[db].getAccessionId().toString()));\r
- }\r
- }\r
- }\r
- jalview.datamodel.Alignment jdataset = new jalview.datamodel.Alignment(seqs);\r
- ////////////////////////////////////////////////\r
-\r
-\r
- //////////////////////////////////////\r
- ////LOAD ALIGNMENT\r
- Alignment alignment = dataset.getAlignment(0);\r
- iSize = alignment.getAlignmentSequenceCount();\r
- seqs = new jalview.datamodel.Sequence[iSize];\r
- String id;\r
- int j, jSize = jdataset.getHeight();\r
- for (i = 0; i < iSize; i++)\r
- {\r
- seqs[i] = new jalview.datamodel.Sequence(\r
- alignment.getAlignmentSequence(i).getName(),\r
- alignment.getAlignmentSequence(i).getSequence(),\r
- alignment.getAlignmentSequence(i).getStart(),\r
- alignment.getAlignmentSequence(i).getEnd());\r
-\r
- id = ( (Sequence) alignment.getAlignmentSequence(i).getRefid()).getId();\r
-\r
- for(j=0; j<jSize; j++)\r
- {\r
- if(jdataset.getSequenceAt(j).getVamsasId().equals(id))\r
- {\r
- seqs[i].setDatasetSequence( jdataset.getSequenceAt(j) );\r
- break;\r
- }\r
- }\r
- }\r
- jalview.datamodel.Alignment jal = new jalview.datamodel.Alignment(seqs);\r
- jal.setDataset(jdataset);\r
- /*jal.getDataset().setProvenance(\r
- getJalviewProvenance(dataset.getProvenance()));\r
- jal.setProvenance(\r
- getJalviewProvenance(alignment.getProvenance()));\r
- */\r
- //////////////////////////////////////////////\r
-\r
-\r
- ////////////////////////////////////////////\r
- ////LOAD ANNOTATIONS\r
- ////////////////////\r
- if (alignment.getAlignmentAnnotationsCount()>0)\r
- {\r
- AlignmentAnnotations[] an = alignment.getAlignmentAnnotations();\r
-\r
- for (j = 0; j < an.length; j++)\r
- {\r
- boolean topaliBreakpoint = false;\r
-\r
- AnnotationElement[] ae = an[j].getAnnotationElement();\r
- jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[jal.\r
- getWidth()];\r
-\r
- try{\r
-\r
- for (int aa = 0; aa < ae.length; aa++)\r
- {\r
- String dc = ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter();\r
- String desc = ae[aa].getDescription()==null ? "desc" : ae[aa].getDescription();\r
- String ss = ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure();\r
- float value = ae[aa].getValue();\r
-\r
- if(an[j].getGraph())\r
- {\r
- dc = value+"";\r
- desc = value + "";\r
- }\r
- anot[ae[aa].getPosition()-1] = new jalview.datamodel.\r
- Annotation(dc,desc,ss.charAt(0),value);\r
-\r
- if(desc.equals("TOPALi Partition Breakpoint"))\r
- topaliBreakpoint = true;\r
-\r
- }\r
- }catch(Exception ex)\r
- {\r
- ex.printStackTrace();\r
- System.out.println("problem parsing annotations\n"+ex);}\r
-\r
- jalview.datamodel.AlignmentAnnotation jaa = null;\r
-\r
- if (an[j].getGraph())\r
- {\r
- jaa = new jalview.datamodel.AlignmentAnnotation(an[j].getLabel(),\r
- an[j].getDescription(), anot, 0, 0, 1);\r
- }\r
- else\r
- {\r
- String label = an[j].getLabel();\r
- if(topaliBreakpoint)\r
- label = "TOPALi Partition Breakpoint";\r
- jaa = new jalview.datamodel.AlignmentAnnotation(label,\r
- an[j].getDescription(), anot);\r
- }\r
-\r
- jal.addAnnotation(jaa);\r
- }\r
- }\r
- /////////////////////////////////\r
-\r
- AlignFrame alignFrame = new AlignFrame(jal);\r
- jalview.gui.Desktop.addInternalFrame(alignFrame, "VAMSAS LOAD",\r
- AlignFrame.NEW_WINDOW_WIDTH,\r
- AlignFrame.NEW_WINDOW_HEIGHT);\r
-\r
- //LOAD TREES\r
- ///////////////////////////////////////\r
- if (alignment.getTreeCount() > 0)\r
- {\r
- for (int t = 0; t < alignment.getTreeCount(); t++)\r
- {\r
- Tree tree = alignment.getTree(t);\r
-\r
- alignFrame.ShowNewickTree(\r
- new jalview.io.NewickFile(tree.getNewick(0).getContent()),\r
- tree.getNewick(0).getTitle(),\r
- 600, 500,\r
- t * 20 + 50, t * 20 + 50);\r
- }\r
- }\r
-\r
-\r
- in.close();\r
- jin.close();\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
-\r
-\r
+ long time = System.currentTimeMillis();\r
+ \r
+ try\r
+ {\r
+ \r
+ jalview.datamodel.AlignmentI jal = av.getAlignment();\r
+ \r
+ \r
+ ///////////////////////////////////////////\r
+ // SAVE THE DATASET\r
+ VAMSAS root = cdoc.getVamsasRoots()[0];\r
+ if (jal.getDataset()==null) {\r
+ Cache.log.warn("Creating new dataset for an alignment.");\r
+ jal.setDataset(null); // \r
+ }\r
+ boolean nw=false;\r
+ DataSet dataset = (DataSet) getjv2vObj(jal.getDataset());\r
+ if (dataset==null) {\r
+ dataset = new DataSet();\r
+ root.addDataSet(dataset);\r
+ bindjvvobj(jal.getDataset(),dataset);\r
+ nw=true;\r
+ } //else {\r
+ // should really check root corresponds to dataset.\r
+ // }\r
+ // update dataset\r
+ Sequence sequence;\r
+ DbRef dbref;\r
+ for (int i = 0; i < jal.getHeight(); i++)\r
+ {\r
+ SequenceI sq = jal.getDataset().getSequenceAt(i);\r
+ sequence = (Sequence) getjv2vObj(sq);\r
+ if (sequence==null) {\r
+ sequence=new Sequence();\r
+ bindjvvobj(sq, sequence);\r
+ sq.setVamsasId(sequence.getVorbaId().getId());\r
+ sequence.setSequence(sq.getSequence());\r
+ sequence.setName(jal.getDataset().getSequenceAt(i).getName());\r
+ sequence.setStart(jal.getDataset().getSequenceAt(i).getStart());\r
+ sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd());\r
+ dataset.addSequence(sequence);\r
+ } else {\r
+ // verify principal attributes.\r
+ \r
+ }\r
+ \r
+ if(jal.getDataset().getSequenceAt(i).getSequenceFeatures()!=null)\r
+ {\r
+ int sfSize = jal.getDataset().getSequenceAt(i).getSequenceFeatures().length;\r
+ \r
+ for (int sf = 0; sf < sfSize; sf++)\r
+ {\r
+ jalview.datamodel.SequenceFeature feature =\r
+ (jalview.datamodel.SequenceFeature)\r
+ jal.getDataset().getSequenceAt(i).getSequenceFeatures()[sf];\r
+ \r
+ DataSetAnnotations dsa = (DataSetAnnotations) getjv2vObj(feature); \r
+ if (dsa==null) {\r
+ dsa = new DataSetAnnotations();\r
+ bindjvvobj(feature, dsa);\r
+ dsa.setType(feature.getType());\r
+ dsa.setBegin(feature.getBegin());\r
+ dsa.setEnd(feature.getEnd());\r
+ dsa.setDescription(feature.getDescription());\r
+ dsa.setStatus(feature.getStatus());\r
+ if (dsa.getProvenance()==null) {\r
+ dsa.setProvenance(new Provenance());\r
+ }\r
+ \r
+ dsa.getProvenance().addEntry(provEntry); // JBPNote - need to update jalview datamodel.\r
+ dsa.setSeqRef(sequence);\r
+ dataset.addDataSetAnnotations(dsa);\r
+ } else {\r
+ // todo: verify\r
+ }\r
+ }\r
+ }\r
+ \r
+ if(jal.getDataset().getSequenceAt(i).getDBRef()!=null)\r
+ {\r
+ java.util.Vector entries = jal.getDataset().getSequenceAt(i).getDBRef();\r
+ jalview.datamodel.DBRefEntry dbentry;\r
+ for(int db=0; db<entries.size(); db++)\r
+ {\r
+ dbentry = (jalview.datamodel.DBRefEntry)entries.elementAt(db);\r
+ dbref = (DbRef) getjv2vObj(dbentry);\r
+ if (dbref==null) {\r
+ dbref = new DbRef();\r
+ bindjvvobj(dbentry, dbref);\r
+ dbref.setAccessionId( dbentry.getAccessionId() );\r
+ dbref.setSource( dbentry.getSource() );\r
+ dbref.setVersion( dbentry.getVersion() );\r
+ dbref.setId("db"+(time++));\r
+ sequence.addDbRef(dbref);\r
+ } else {\r
+ // todo: verify\r
+ }\r
+ }\r
+ \r
+ }\r
+ \r
+ /* not needed any more.\r
+ if(jal.getDataset().getSequenceAt(i).getVamsasId()==null)\r
+ sequence.setId("ds" + (time++));\r
+ else\r
+ sequence.setId(jal.getDataset().getSequenceAt(i).getVamsasId());\r
+ */\r
+ }\r
+ // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));\r
+ //////////////////////////////////////////////\r
+ \r
+ \r
+ //////////////////////////////////////////////\r
+ //Save the Alignments\r
+ \r
+ Alignment alignment = (Alignment) getjv2vObj(jal);\r
+ if (alignment==null) {\r
+ alignment=new Alignment();\r
+ bindjvvobj(jal, alignment);\r
+ if (alignment.getProvenance()==null)\r
+ alignment.setProvenance(new Provenance());\r
+ alignment.getProvenance().addEntry(provEntry);\r
+ dataset.addAlignment(alignment);\r
+ alignment.setGapChar(av.getGapCharacter() + "");\r
+ AlignmentSequence alseq = null;\r
+ for (int i = 0; i < jal.getHeight(); i++)\r
+ {\r
+ alseq = new AlignmentSequence();\r
+ alseq.setSequence(\r
+ jal.getSequenceAt(i).getSequence()\r
+ );\r
+ alseq.setName(jal.getSequenceAt(i).getName());\r
+ alseq.setStart(jal.getSequenceAt(i).getStart());\r
+ alseq.setEnd(jal.getSequenceAt(i).getEnd());\r
+ // how is this going to work ? find alseq in DataSet by..\r
+ if (nw) {\r
+ // order is conserved because we just created a new dataset.\r
+ alseq.setRefid(dataset.getSequence(i));\r
+ }\r
+ alignment.addAlignmentSequence(alseq);\r
+ }\r
+ } else {\r
+ // todo: verify and update mutable alignment props.\r
+ }\r
+ //////////////////////////////////////////////\r
+ \r
+ \r
+ \r
+ //////////////////////////////////////////////\r
+ //SAVE ANNOTATIONS\r
+ if (jal.getAlignmentAnnotation() != null)\r
+ {\r
+ jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();\r
+ \r
+ for (int i = 0; i < aa.length; i++)\r
+ {\r
+ if (aa[i].label.equals("Quality") ||\r
+ aa[i].label.equals("Conservation") ||\r
+ aa[i].label.equals("Consensus"))\r
+ {\r
+ continue;\r
+ }\r
+ AlignmentAnnotations an = (AlignmentAnnotations) getjv2vObj(aa[i]);\r
+ if (an==null) {\r
+ an = new AlignmentAnnotations();\r
+ an.setDescription(aa[i].description);\r
+ // JBPNote - have to deal with the many lines for one graph thing\r
+ if (aa[i].graph>0)\r
+ an.setGraph(true); //aa[i].graph);\r
+ // JBPNote - store graphGroup in the Jalview specific bits.\r
+ an.setLabel(aa[i].label);\r
+ an.setProvenance(dummyProvenance());\r
+ \r
+ AnnotationElement ae;\r
+ \r
+ for (int a = 0; a < aa[i].annotations.length; a++)\r
+ {\r
+ if ((aa[i] == null) || (aa[i].annotations[a] == null))\r
+ {\r
+ continue;\r
+ }\r
+ \r
+ ae = new AnnotationElement();\r
+ ae.setDescription(aa[i].annotations[a].description);\r
+ ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);\r
+ ae.setValue(aa[i].annotations[a].value);\r
+ ae.setPosition(a);\r
+ ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +\r
+ "");\r
+ an.addAnnotationElement(ae);\r
+ }\r
+ \r
+ alignment.addAlignmentAnnotations(an);\r
+ } else {\r
+ // verify annotation - update (perhaps)\r
+ }\r
+ }\r
+ }\r
+ ///////////////////////////////////////////////////////\r
+ \r
+ ////////////////////////////////////////////////\r
+ ///SAVE THE TREES\r
+ ///////////////////////////////////\r
+ // FIND ANY ASSOCIATED TREES\r
+ if (Desktop.desktop != null)\r
+ {\r
+ javax.swing.JInternalFrame[] frames = Desktop.desktop.getAllFrames();\r
+ \r
+ for (int t = 0; t < frames.length; t++)\r
+ {\r
+ if (frames[t] instanceof TreePanel)\r
+ {\r
+ TreePanel tp = (TreePanel) frames[t];\r
+ \r
+ if (tp.getAlignment() == jal)\r
+ {\r
+ // JBPNote - can recover alignment and Vamsas Alignment for an associated tree using the getjv2vObj()\r
+ \r
+ Tree tree = (Tree) getjv2vObj(tp);\r
+ if (tree==null) {\r
+ tree = new Tree();\r
+ bindjvvobj(tp,tree);\r
+ tree.setTitle(tp.getTitle());\r
+ Newick newick = new Newick();\r
+ newick.setContent( tp.getTree().toString() );\r
+ newick.setTitle( tp.getTitle() );\r
+ tree.addNewick( newick );\r
+ tree.setProvenance(dummyProvenance());\r
+ alignment.addTree(tree);\r
+ } else {\r
+ // verify any changes.\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ \r
}\r
-\r
-\r
-\r
- Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov)\r
- {\r
- jalview.datamodel.ProvenanceEntry [] entries = null;\r
-\r
-\r
- Provenance prov = new Provenance();\r
- org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(\r
- new java.util.Date());\r
- Entry provEntry;\r
-\r
- if(jprov!=null)\r
- {\r
- entries = jprov.getEntries();\r
- for (int i = 0; i < entries.length; i++)\r
- {\r
- provEntry = new Entry();\r
- try\r
- {\r
- date = new org.exolab.castor.types.Date(entries[i].getDate());\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
-\r
- date = new org.exolab.castor.types.Date(entries[i].getDate());\r
- }\r
- provEntry.setDate(date);\r
- provEntry.setUser(entries[i].getUser());\r
- provEntry.setAction(entries[i].getAction());\r
- prov.addEntry(provEntry);\r
- }\r
- }\r
- else\r
- {\r
- provEntry = new Entry();\r
- provEntry.setDate(date);\r
- provEntry.setUser(System.getProperty("user.name"));\r
- provEntry.setAction("Jalview");\r
- prov.addEntry(provEntry);\r
- }\r
-\r
- return prov;\r
- }\r
-\r
- jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)\r
- {\r
-\r
- jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();\r
- for (int i = 0; i < prov.getEntryCount(); i++)\r
- {\r
- jprov.addEntry(\r
- prov.getEntry(i).getUser(),\r
- prov.getEntry(i).getAction(),\r
- prov.getEntry(i).getDate().toDate(),\r
- prov.getEntry(i).getId()\r
- );\r
- }\r
-\r
- return jprov;\r
- }\r
-\r
- Provenance dummyProvenance()\r
- {\r
- Provenance prov = new Provenance();\r
- Entry entry = new Entry();\r
- entry.setAction("Jalview");\r
- entry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));\r
- entry.setUser(System.getProperty("user.name"));\r
- prov.addEntry(entry);\r
- return prov;\r
- }\r
-\r
-}\r
+ \r
+ \r
+ \r
+ public void updateJalview()\r
+ {\r
+ VAMSAS root = cdoc.getVamsasRoots()[0];\r
+ try\r
+ {\r
+ boolean newds=false;\r
+ for (int _ds=0,_nds=root.getDataSetCount(); _ds<_nds; _ds++) {\r
+ /////////////////////////////////////\r
+ /////LOAD DATASET\r
+ DataSet dataset = vamsas.getDataSet(_ds);\r
+ int i, iSize = dataset.getSequenceCount();\r
+ jalview.datamodel.Alignment jdataset = (jalview.datamodel.Alignment) vobj2jv(dataset);\r
+ if (jdataset!=null) {\r
+ // recover\r
+ } else {\r
+ newds=true;\r
+ // construct new dataset\r
+ jalview.datamodel.Sequence [] seqs = new jalview.datamodel.Sequence[iSize];\r
+ DbRef [] dbref;\r
+ for (i = 0; i < iSize ; i++)\r
+ {\r
+ seqs[i] = new jalview.datamodel.Sequence(\r
+ dataset.getSequence(i).getName(),\r
+ dataset.getSequence(i).getSequence(),\r
+ dataset.getSequence(i).getStart(),\r
+ dataset.getSequence(i).getEnd() );\r
+ bindjvvobj(seqs[i], dataset.getSequence(i));\r
+ seqs[i].setVamsasId(dataset.getSequence(i).getVorbaId().getId());\r
+ \r
+ if (dataset.getDataSetAnnotations() != null)\r
+ {\r
+ for (int dsa = 0; dsa < dataset.getDataSetAnnotationsCount(); dsa++)\r
+ {\r
+ // could be optimised\r
+ if (dataset.getDataSetAnnotations(dsa).getSeqRef() ==\r
+ dataset.getSequence(i))\r
+ {\r
+ jalview.datamodel.SequenceFeature sf;\r
+ seqs[i].addSequenceFeature(sf=new jalview.datamodel.\r
+ SequenceFeature(\r
+ dataset.getDataSetAnnotations(dsa).getType(),\r
+ dataset.getDataSetAnnotations(dsa).getDescription(),\r
+ dataset.getDataSetAnnotations(dsa).getStatus(),\r
+ dataset.getDataSetAnnotations(dsa).getBegin(),\r
+ dataset.getDataSetAnnotations(dsa).getEnd(),\r
+ "vamsas"));\r
+ bindjvvobj(sf, dataset.getDataSetAnnotations(dsa));\r
+ }\r
+ }\r
+ }\r
+ dbref = dataset.getSequence(i).getDbRef();\r
+ \r
+ if(dbref.length>0)\r
+ {\r
+ for(int db=0; db<dbref.length; db++)\r
+ {\r
+ jalview.datamodel.DBRefEntry dbr;\r
+ seqs[i].addDBRef(dbr= new jalview.datamodel.DBRefEntry\r
+ (\r
+ dbref[db].getSource().toString(),\r
+ dbref[db].getVersion().toString(),\r
+ dbref[db].getAccessionId().toString()));\r
+ bindjvvobj(dbr, dvref[db]);\r
+ }\r
+ }\r
+ }\r
+ jdataset = jalview.datamodel.Alignment(seqs); // complete construction\r
+ bindjvvobj(jdataset, dataset);\r
+ }\r
+ ////////////////////////////////////////////////\r
+ }\r
+ for (int _al=0,_nal=dataset.getAlignmentCount(); _al<_nal; _al++) {\r
+ //////////////////////////////////////\r
+ ////LOAD ALIGNMENT\r
+ Alignment alignment = dataset.getAlignment(_al);\r
+ iSize = alignment.getAlignmentSequenceCount();\r
+ jalview.datamodel.Alignment jal = getvObj2jv(alignment); \r
+ if (jal!=null) {\r
+ // merge/update\r
+ } else {\r
+ seqs = new jalview.datamodel.Sequence[iSize];\r
+ String id;\r
+ int j, jSize = jdataset.getHeight();\r
+ for (i = 0; i < iSize; i++)\r
+ {\r
+ seqs[i] = new jalview.datamodel.Sequence(\r
+ alignment.getAlignmentSequence(i).getName(),\r
+ alignment.getAlignmentSequence(i).getSequence(),\r
+ alignment.getAlignmentSequence(i).getStart(),\r
+ alignment.getAlignmentSequence(i).getEnd());\r
+ bindjvvobj(seqs[i], alignment.getAlignmentSequence(i));\r
+ id = ( (Sequence) alignment.getAlignmentSequence(i).getRefid()).getVorbaId().getId();\r
+ \r
+ for(j=0; j<jSize; j++)\r
+ {\r
+ if(jdataset.getSequenceAt(j).getVamsasId().equals(id))\r
+ {\r
+ seqs[i].setDatasetSequence( jdataset.getSequenceAt(j) );\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ jalview.datamodel.Alignment jal = new jalview.datamodel.Alignment(seqs);\r
+ bindjvvobj(jal, alignment);\r
+ jal.setDataset(jdataset);\r
+ /*jal.getDataset().setProvenance(\r
+ getJalviewProvenance(dataset.getProvenance()));\r
+ jal.setProvenance(\r
+ getJalviewProvenance(alignment.getProvenance()));\r
+ */\r
+ //////////////////////////////////////////////\r
+ \r
+ \r
+ ////////////////////////////////////////////\r
+ ////LOAD ANNOTATIONS\r
+ ////////////////////\r
+ if (alignment.getAlignmentAnnotationsCount()>0)\r
+ {\r
+ AlignmentAnnotations[] an = alignment.getAlignmentAnnotations();\r
+ \r
+ for (j = 0; j < an.length; j++)\r
+ {\r
+ boolean topaliBreakpoint = false;\r
+ \r
+ AnnotationElement[] ae = an[j].getAnnotationElement();\r
+ jalview.datamodel.Annotation[] anot = getvObj2jv(ae);\r
+ if (anot!=null) {\r
+ // update or stay the same.\r
+ } else {\r
+ // new one\r
+ anot=new jalview.datamodel.Annotation[jal.\r
+ getWidth()];\r
+ bindjvvobj(anot, ae);\r
+ try{\r
+ for (int aa = 0; aa < ae.length; aa++)\r
+ {\r
+ String dc = ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter();\r
+ String desc = ae[aa].getDescription()==null ? "desc" : ae[aa].getDescription();\r
+ String ss = ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure();\r
+ float value = ae[aa].getValue();\r
+ if(an[j].getGraph())\r
+ {\r
+ dc = value+"";\r
+ desc = value + "";\r
+ }\r
+ anot[ae[aa].getPosition()-1] = new jalview.datamodel.\r
+ Annotation(dc,desc,ss.charAt(0),value);\r
+ \r
+ if(desc.equals("TOPALi Partition Breakpoint"))\r
+ topaliBreakpoint = true;\r
+ \r
+ }\r
+ }catch(Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ System.out.println("problem parsing annotations\n"+ex);}\r
+ }\r
+ jalview.datamodel.AlignmentAnnotation jaa = null;\r
+ if (an[j].getGraph())\r
+ {\r
+ jaa = new jalview.datamodel.AlignmentAnnotation(an[j].getLabel(),\r
+ an[j].getDescription(), anot, 0, 0, 1);\r
+ }\r
+ else\r
+ {\r
+ String label = an[j].getLabel();\r
+ if(topaliBreakpoint)\r
+ label = "TOPALi Partition Breakpoint";\r
+ jaa = new jalview.datamodel.AlignmentAnnotation(label,\r
+ an[j].getDescription(), anot);\r
+ }\r
+ \r
+ jal.addAnnotation(jaa);\r
+ }\r
+ }\r
+ /////////////////////////////////\r
+ \r
+ AlignFrame alignFrame = new AlignFrame(jal);\r
+ jalview.gui.Desktop.addInternalFrame(alignFrame, "VAMSAS LOAD",\r
+ AlignFrame.NEW_WINDOW_WIDTH,\r
+ AlignFrame.NEW_WINDOW_HEIGHT);\r
+ \r
+ //LOAD TREES\r
+ ///////////////////////////////////////\r
+ if (alignment.getTreeCount() > 0)\r
+ {\r
+ for (int t = 0; t < alignment.getTreeCount(); t++)\r
+ {\r
+ Tree tree = alignment.getTree(t);\r
+ \r
+ alignFrame.ShowNewickTree(\r
+ new jalview.io.NewickFile(tree.getNewick(0).getContent()),\r
+ tree.getNewick(0).getTitle(),\r
+ 600, 500,\r
+ t * 20 + 50, t * 20 + 50);\r
+ }\r
+ }\r
+ \r
+ \r
+ in.close();\r
+ jin.close();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ \r
+ \r
+ }\r
+ \r
+ \r
+ \r
+ Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov)\r
+ {\r
+ jalview.datamodel.ProvenanceEntry [] entries = null;\r
+ \r
+ \r
+ Provenance prov = new Provenance();\r
+ org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(\r
+ new java.util.Date());\r
+ Entry provEntry;\r
+ \r
+ if(jprov!=null)\r
+ {\r
+ entries = jprov.getEntries();\r
+ for (int i = 0; i < entries.length; i++)\r
+ {\r
+ provEntry = new Entry();\r
+ try\r
+ {\r
+ date = new org.exolab.castor.types.Date(entries[i].getDate());\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ \r
+ date = new org.exolab.castor.types.Date(entries[i].getDate());\r
+ }\r
+ provEntry.setDate(date);\r
+ provEntry.setUser(entries[i].getUser());\r
+ provEntry.setAction(entries[i].getAction());\r
+ prov.addEntry(provEntry);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ provEntry = new Entry();\r
+ provEntry.setDate(date);\r
+ provEntry.setUser(System.getProperty("user.name"));\r
+ provEntry.setAction("Jalview");\r
+ prov.addEntry(provEntry);\r
+ }\r
+ \r
+ return prov;\r
+ }\r
+ \r
+ jalview.datamodel.Provenance getJalviewProvenance(Provenance prov)\r
+ {\r
+ \r
+ jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance();\r
+ for (int i = 0; i < prov.getEntryCount(); i++)\r
+ {\r
+ jprov.addEntry(\r
+ prov.getEntry(i).getUser(),\r
+ prov.getEntry(i).getAction(),\r
+ prov.getEntry(i).getDate().toDate(),\r
+ prov.getEntry(i).getId()\r
+ );\r
+ }\r
+ \r
+ return jprov;\r
+ }\r
+ \r
+ Provenance dummyProvenance()\r
+ {\r
+ Provenance prov = new Provenance();\r
+ Entry entry = new Entry();\r
+ entry.setAction("Jalview");\r
+ entry.setDate(new org.exolab.castor.types.Date(new java.util.Date()));\r
+ entry.setUser(System.getProperty("user.name"));\r
+ prov.addEntry(entry);\r
+ return prov;\r
+ }\r
+ \r
+ }\r