/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.io; import org.vamsas.objects.core.*; import jalview.gui.*; import java.io.*; import java.util.jar.*; import org.exolab.castor.xml.*; import org.exolab.castor.mapping.Mapping; /* static { org.exolab.castor.util.LocalConfiguration.getInstance().getProperties().setProperty( "org.exolab.castor.serializer", "org.apache.xml.serialize.XMLSerilazizer"); } */ public class VamsasDatastore { AlignViewport av; org.exolab.castor.types.Date date = new org.exolab.castor.types.Date(new java.util.Date()); public VamsasDatastore(AlignViewport av) { this.av = av; } public void store(String file) { storeVAMSAS(file); } public void storeJalview(String file, AlignFrame af) { try { // 1. Load the mapping information from the file Mapping map = new Mapping(getClass().getClassLoader()); java.net.URL url = getClass().getResource("/jalview_mapping.xml"); map.loadMapping(url); // 2. Unmarshal the data // Unmarshaller unmar = new Unmarshaller(); //unmar.setIgnoreExtraElements(true); //unmar.setMapping(map); // uni = (UniprotFile) unmar.unmarshal(new FileReader(file)); // 3. marshal the data with the total price back and print the XML in the console Marshaller marshaller = new Marshaller( new FileWriter(file) ); marshaller.setMapping(map); marshaller.marshal(af); } catch (Exception e) { e.printStackTrace(); } } public VAMSAS storeVAMSAS(String file) { long time = System.currentTimeMillis(); VAMSAS vamsas = new VAMSAS(); try { FileOutputStream fos = new FileOutputStream(file); JarOutputStream jout = new JarOutputStream(fos); //////////////////////////////////////////////////// //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS PrintWriter out = new PrintWriter(new OutputStreamWriter(jout, "UTF-8")); jalview.datamodel.AlignmentI jal = av.getAlignment(); /////////////////////////////////////////// // SAVE THE DATASET DataSet dataset = new DataSet(); vamsas.addDataSet(dataset); Sequence sequence; DbRef dbref; for (int i = 0; i < jal.getHeight(); i++) { sequence = new Sequence(); sequence.setSequence(jal.getDataset().getSequenceAt(i).getSequence()); sequence.setName(jal.getDataset().getSequenceAt(i).getName()); sequence.setStart(jal.getDataset().getSequenceAt(i).getStart()); sequence.setEnd(jal.getDataset().getSequenceAt(i).getEnd()); if(jal.getDataset().getSequenceAt(i).getSequenceFeatures()!=null) { int sfSize = jal.getDataset().getSequenceAt(i).getSequenceFeatures().size(); for (int sf = 0; sf < sfSize; sf++) { jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) jal.getDataset().getSequenceAt(i).getSequenceFeatures().elementAt(sf); DataSetAnnotations dsa = new DataSetAnnotations(); dsa.setType(feature.getType()); dsa.setBegin(feature.getBegin()); dsa.setEnd(feature.getEnd()); dsa.setDescription(feature.getDescription()); dsa.setStatus(feature.getStatus()); dsa.addProvenance(dummyProvenance()); dsa.setSeqRef(sequence); dsa.setId("sf"+(time++)); dataset.addDataSetAnnotations(dsa); } } if(jal.getDataset().getSequenceAt(i).getDBRef()!=null) { java.util.Vector entries = jal.getDataset().getSequenceAt(i).getDBRef(); jalview.datamodel.DBRefEntry dbentry; for(int db=0; db0) { for(int db=0; db0) { AlignmentAnnotations[] an = alignment.getAlignmentAnnotations(); for (j = 0; j < an.length; j++) { boolean topaliBreakpoint = false; AnnotationElement[] ae = an[j].getAnnotationElement(); jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[jal. getWidth()]; try{ for (int aa = 0; aa < ae.length; aa++) { String dc = ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter(); String desc = ae[aa].getDescription()==null ? "desc" : ae[aa].getDescription(); String ss = ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure(); float value = ae[aa].getValue(); if(an[j].getGraph()) { dc = value+""; desc = value + ""; } anot[ae[aa].getPosition()-1] = new jalview.datamodel. Annotation(dc,desc,ss.charAt(0),value); if(desc.equals("TOPALi Partition Breakpoint")) topaliBreakpoint = true; } }catch(Exception ex) { ex.printStackTrace(); System.out.println("problem parsing annotations\n"+ex);} jalview.datamodel.AlignmentAnnotation jaa = null; if (an[j].getGraph()) { jaa = new jalview.datamodel.AlignmentAnnotation(an[j].getLabel(), an[j].getDescription(), anot, 0, 0, 1); } else { String label = an[j].getLabel(); if(topaliBreakpoint) label = "TOPALi Partition Breakpoint"; jaa = new jalview.datamodel.AlignmentAnnotation(label, an[j].getDescription(), anot); } jal.addAnnotation(jaa); } } ///////////////////////////////// AlignFrame alignFrame = new AlignFrame(jal); jalview.gui.Desktop.addInternalFrame(alignFrame, "VAMSAS LOAD", AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); //LOAD TREES /////////////////////////////////////// if (alignment.getTreeCount() > 0) { for (int t = 0; t < alignment.getTreeCount(); t++) { Tree tree = alignment.getTree(t); alignFrame.ShowNewickTree( new jalview.io.NewickFile(tree.getNewick(0).getContent()), tree.getNewick(0).getTitle(), 600, 500, t * 20 + 50, t * 20 + 50); } } in.close(); jin.close(); } catch (Exception ex) { ex.printStackTrace(); } } Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov) { jalview.datamodel.ProvenanceEntry [] entries = null; Provenance prov = new Provenance(); org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( new java.util.Date()); Entry provEntry; if(jprov!=null) { entries = jprov.getEntries(); for (int i = 0; i < entries.length; i++) { provEntry = new Entry(); try { date = new org.exolab.castor.types.Date(entries[i].getDate()); } catch (Exception ex) { ex.printStackTrace(); date = new org.exolab.castor.types.Date(entries[i].getDate()); } provEntry.setDate(date); provEntry.setUser(entries[i].getUser()); provEntry.setAction(entries[i].getAction()); prov.addEntry(provEntry); } } else { provEntry = new Entry(); provEntry.setDate(date); provEntry.setUser(System.getProperty("user.name")); provEntry.setAction("Jalview"); prov.addEntry(provEntry); } return prov; } jalview.datamodel.Provenance getJalviewProvenance(Provenance prov) { jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance(); for (int i = 0; i < prov.getEntryCount(); i++) { jprov.addEntry( prov.getEntry(i).getUser(), prov.getEntry(i).getAction(), prov.getEntry(i).getDate().toDate(), prov.getEntry(i).getId() ); } return jprov; } Provenance dummyProvenance() { Provenance prov = new Provenance(); Entry entry = new Entry(); entry.setAction("Jalview"); entry.setDate(new org.exolab.castor.types.Date(new java.util.Date())); entry.setUser(System.getProperty("user.name")); prov.addEntry(entry); return prov; } }