2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
22 import jalview.schemes.*;
\r
24 import jalview.gui.*;
\r
32 import java.util.jar.*;
\r
34 import javax.swing.*;
\r
36 import org.exolab.castor.xml.*;
\r
38 import jalview.schemabinding.version2.*;
\r
47 * @version $Revision$
\r
49 public class Jalview2XML
\r
51 // SAVES SEVERAL ALIGNEMENT WINDOWS TO SAME JARFILE
\r
52 public void SaveState(File statefile)
\r
54 long creation = System.currentTimeMillis();
\r
55 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
\r
64 FileOutputStream fos = new FileOutputStream(statefile);
\r
65 JarOutputStream jout = new JarOutputStream(fos);
\r
67 //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
\r
68 ////////////////////////////////////////////////////
\r
69 PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,
\r
72 Vector shortNames = new Vector();
\r
75 for (int i = frames.length - 1; i > -1; i--)
\r
77 if (frames[i] instanceof AlignFrame)
\r
79 AlignFrame af = (AlignFrame) frames[i];
\r
81 String shortName = af.getTitle();
\r
83 if (shortName.indexOf(File.separatorChar) > -1)
\r
85 shortName = shortName.substring(shortName.lastIndexOf(
\r
86 File.separatorChar) + 1);
\r
91 while (shortNames.contains(shortName))
\r
93 if (shortName.endsWith("_" + (count - 1)))
\r
95 shortName = shortName.substring(0,
\r
96 shortName.lastIndexOf("_"));
\r
99 shortName = shortName.concat("_" + count);
\r
103 shortNames.addElement(shortName);
\r
105 if (!shortName.endsWith(".xml"))
\r
107 shortName = shortName + ".xml";
\r
110 SaveState(af, creation, shortName, jout, out);
\r
117 catch (Exception ex)
\r
119 ex.printStackTrace();
\r
123 // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
\r
124 public void SaveAlignment(AlignFrame af, String jarFile,
\r
129 FileOutputStream fos = new FileOutputStream(jarFile);
\r
130 JarOutputStream jout = new JarOutputStream(fos);
\r
132 //NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
\r
133 ////////////////////////////////////////////////////
\r
134 PrintWriter out = new PrintWriter(new OutputStreamWriter(jout,
\r
137 SaveState(af, System.currentTimeMillis(), fileName, jout, out);
\r
141 catch (Exception ex)
\r
143 ex.printStackTrace();
\r
150 * @param af DOCUMENT ME!
\r
151 * @param timeStamp DOCUMENT ME!
\r
152 * @param fileName DOCUMENT ME!
\r
153 * @param jout DOCUMENT ME!
\r
154 * @param out DOCUMENT ME!
\r
156 public void SaveState(AlignFrame af, long timeStamp,
\r
157 String fileName, JarOutputStream jout, PrintWriter out)
\r
159 Vector seqids = new Vector();
\r
160 Vector userColours = new Vector();
\r
162 AlignViewport av = af.viewport;
\r
164 JalviewModel object = new JalviewModel();
\r
165 object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel());
\r
167 object.setCreationDate(new java.util.Date(timeStamp));
\r
168 object.setVersion(jalview.bin.Cache.getProperty("VERSION"));
\r
170 jalview.datamodel.AlignmentI jal = af.viewport.alignment;
\r
171 jalview.datamodel.AlignmentI jalhidden = null;
\r
173 if(av.hasHiddenRows)
\r
176 jal = jal.getHiddenSequences().getFullAlignment();
\r
180 SequenceSet vamsasSet = new SequenceSet();
\r
181 Sequence vamsasSeq;
\r
182 JalviewModelSequence jms = new JalviewModelSequence();
\r
184 vamsasSet.setGapChar(jal.getGapCharacter() + "");
\r
190 for (int i = 0; i < jal.getHeight(); i++)
\r
192 seqids.add(jal.getSequenceAt(i));
\r
193 vamsasSeq = new Sequence();
\r
194 vamsasSeq.setId(id + "");
\r
195 vamsasSeq.setName(jal.getSequenceAt(i).getName());
\r
196 vamsasSeq.setSequence(jal.getSequenceAt(i).getSequence());
\r
197 vamsasSeq.setDescription(jal.getSequenceAt(i).getDescription());
\r
199 if(jal.getSequenceAt(i).getDatasetSequence().getDBRef()!=null)
\r
201 jalview.datamodel.DBRefEntry [] dbrefs =
\r
202 jal.getSequenceAt(i).getDatasetSequence().getDBRef();
\r
204 for(int d=0; d<dbrefs.length; d++)
\r
206 DBRef dbref = new DBRef();
\r
207 dbref.setSource( dbrefs[d].getSource() );
\r
208 dbref.setVersion( dbrefs[d].getVersion());
\r
209 dbref.setAccessionId(dbrefs[d].getAccessionId());
\r
210 vamsasSeq.addDBRef(dbref);
\r
215 jseq.setStart(jal.getSequenceAt(i).getStart());
\r
216 jseq.setEnd(jal.getSequenceAt(i).getEnd());
\r
217 jseq.setColour(jal.getSequenceAt(i).getColor().getRGB());
\r
221 if (av.hasHiddenRows)
\r
223 jseq.setHidden(jalhidden.getHiddenSequences().isHidden(
\r
224 jal.getSequenceAt(i)));
\r
226 if(jal.getSequenceAt(i).getHiddenSequences()!=null)
\r
228 jalview.datamodel.SequenceI [] reps =
\r
229 jal.getSequenceAt(i).getHiddenSequences().getSequencesInOrder(jal);
\r
231 for(int h=0; h<reps.length; h++)
\r
233 jseq.addHiddenSequences(
\r
234 jal.findIndex(reps[h])
\r
241 if(jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures()!=null)
\r
243 jalview.datamodel.SequenceFeature[] sf
\r
244 = jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures();
\r
246 while(index < sf.length)
\r
248 Features features = new Features();
\r
250 features.setBegin(sf[index].getBegin());
\r
251 features.setEnd(sf[index].getEnd());
\r
252 features.setDescription(sf[index].getDescription());
\r
253 features.setType(sf[index].getType());
\r
254 features.setFeatureGroup(sf[index].getFeatureGroup());
\r
255 jseq.addFeatures(features);
\r
260 if(jal.getSequenceAt(i).getDatasetSequence().getPDBId()!=null)
\r
262 Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getPDBId().elements();
\r
263 while(en.hasMoreElements())
\r
265 Pdbids pdb = new Pdbids();
\r
266 jalview.datamodel.PDBEntry entry
\r
267 = (jalview.datamodel.PDBEntry)en.nextElement();
\r
269 pdb.setId(entry.getId());
\r
270 pdb.setType(entry.getType());
\r
272 if(entry.getProperty()!=null)
\r
274 PdbentryItem item = new PdbentryItem();
\r
275 Hashtable properties = entry.getProperty();
\r
276 Enumeration en2 = properties.keys();
\r
277 while(en2.hasMoreElements())
\r
279 Property prop = new Property();
\r
280 String key = en2.nextElement().toString();
\r
282 prop.setValue( properties.get(key).toString() );
\r
283 item.addProperty(prop);
\r
285 pdb.addPdbentryItem(item);
\r
288 jseq.addPdbids(pdb);
\r
293 vamsasSet.addSequence(vamsasSeq);
\r
298 ///////////////////////////////////
\r
299 if (af.viewport.currentTree != null)
\r
301 // FIND ANY ASSOCIATED TREES
\r
302 // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
\r
303 if (Desktop.desktop != null)
\r
305 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
\r
307 for (int t = 0; t < frames.length; t++)
\r
309 if (frames[t] instanceof TreePanel)
\r
311 TreePanel tp = (TreePanel) frames[t];
\r
313 if (tp.treeCanvas.av.alignment == jal)
\r
315 Tree tree = new Tree();
\r
316 tree.setTitle(tp.getTitle());
\r
317 tree.setCurrentTree( (af.viewport.currentTree == tp.getTree()));
\r
318 tree.setNewick(tp.getTree().toString());
\r
319 tree.setThreshold(tp.treeCanvas.threshold);
\r
321 tree.setFitToWindow(tp.fitToWindow.getState());
\r
322 tree.setFontName(tp.getTreeFont().getName());
\r
323 tree.setFontSize(tp.getTreeFont().getSize());
\r
324 tree.setFontStyle(tp.getTreeFont().getStyle());
\r
325 tree.setMarkUnlinked(tp.placeholdersMenu.getState());
\r
327 tree.setShowBootstrap(tp.bootstrapMenu.getState());
\r
328 tree.setShowDistances(tp.distanceMenu.getState());
\r
330 tree.setHeight(tp.getHeight());
\r
331 tree.setWidth(tp.getWidth());
\r
332 tree.setXpos(tp.getX());
\r
333 tree.setYpos(tp.getY());
\r
343 if (jal.getAlignmentAnnotation() != null)
\r
345 jalview.datamodel.AlignmentAnnotation[] aa = jal.getAlignmentAnnotation();
\r
347 for (int i = 0; i < aa.length; i++)
\r
349 Annotation an = new Annotation();
\r
351 if (aa[i].label.equals("Quality") ||
\r
352 aa[i].label.equals("Conservation") ||
\r
353 aa[i].label.equals("Consensus"))
\r
355 an.setLabel(aa[i].label);
\r
357 vamsasSet.addAnnotation(an);
\r
362 an.setDescription(aa[i].description);
\r
364 if(aa[i].sequenceRef!=null)
\r
366 an.setSequenceRef(aa[i].sequenceRef.getName());
\r
372 an.setGraphType(aa[i].graph);
\r
373 an.setGraphGroup(aa[i].graphGroup);
\r
374 if(aa[i].getThreshold()!=null)
\r
376 ThresholdLine line = new ThresholdLine();
\r
377 line.setLabel(aa[i].getThreshold().label);
\r
378 line.setValue(aa[i].getThreshold().value);
\r
379 line.setColour(aa[i].getThreshold().colour.getRGB());
\r
380 an.setThresholdLine(line);
\r
384 an.setGraph(false);
\r
386 an.setLabel(aa[i].label);
\r
388 AnnotationElement ae;
\r
390 for (int a = 0; a < aa[i].annotations.length; a++)
\r
392 if ((aa[i] == null) || (aa[i].annotations[a] == null))
\r
397 ae = new AnnotationElement();
\r
398 ae.setDescription(aa[i].annotations[a].description);
\r
399 ae.setDisplayCharacter(aa[i].annotations[a].displayCharacter);
\r
400 ae.setValue(aa[i].annotations[a].value);
\r
402 ae.setSecondaryStructure(aa[i].annotations[a].secondaryStructure +
\r
405 if(aa[i].annotations[a].colour!=java.awt.Color.black)
\r
406 ae.setColour(aa[i].annotations[a].colour.getRGB());
\r
408 an.addAnnotationElement(ae);
\r
411 vamsasSet.addAnnotation(an);
\r
416 if (jal.getGroups() != null)
\r
418 JGroup[] groups = new JGroup[jal.getGroups().size()];
\r
420 for (int i = 0; i < groups.length; i++)
\r
422 groups[i] = new JGroup();
\r
424 jalview.datamodel.SequenceGroup sg = (jalview.datamodel.SequenceGroup) jal.getGroups()
\r
426 groups[i].setStart(sg.getStartRes());
\r
427 groups[i].setEnd(sg.getEndRes());
\r
428 groups[i].setName(sg.getName());
\r
431 if (sg.cs.conservationApplied())
\r
433 groups[i].setConsThreshold(sg.cs.getConservationInc());
\r
435 if (sg.cs instanceof jalview.schemes.UserColourScheme)
\r
437 groups[i].setColour(SetUserColourScheme(sg.cs,
\r
443 groups[i].setColour(ColourSchemeProperty.getColourName(sg.
\r
447 else if(sg.cs instanceof jalview.schemes.AnnotationColourGradient)
\r
449 groups[i].setColour(
\r
450 ColourSchemeProperty.getColourName(
\r
451 ( (jalview.schemes.AnnotationColourGradient) sg.cs).getBaseColour()));
\r
453 else if (sg.cs instanceof jalview.schemes.UserColourScheme)
\r
455 groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
\r
460 groups[i].setColour(ColourSchemeProperty.getColourName(
\r
464 groups[i].setPidThreshold(sg.cs.getThreshold());
\r
467 groups[i].setOutlineColour(sg.getOutlineColour().getRGB());
\r
468 groups[i].setDisplayBoxes(sg.getDisplayBoxes());
\r
469 groups[i].setDisplayText(sg.getDisplayText());
\r
470 groups[i].setColourText(sg.getColourText());
\r
472 for (int s = 0; s < sg.getSize(false); s++)
\r
474 jalview.datamodel.Sequence seq = (jalview.datamodel.Sequence) sg.getSequenceAt(s);
\r
475 int index = seqids.indexOf(seq);
\r
476 groups[i].addSeq(index);
\r
480 jms.setJGroup(groups);
\r
484 ///////////SAVE VIEWPORT
\r
485 Viewport view = new Viewport();
\r
486 view.setTitle(af.getTitle());
\r
487 view.setXpos(af.getX());
\r
488 view.setYpos(af.getY());
\r
489 view.setWidth(af.getWidth());
\r
490 view.setHeight(af.getHeight());
\r
491 view.setStartRes(av.startRes);
\r
492 view.setStartSeq(av.startSeq);
\r
494 if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
\r
496 view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
\r
497 userColours, jms));
\r
499 else if(av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
\r
501 jalview.schemes.AnnotationColourGradient acg
\r
502 = (jalview.schemes.AnnotationColourGradient)av.getGlobalColourScheme();
\r
504 AnnotationColours ac = new AnnotationColours();
\r
505 ac.setAboveThreshold(acg.getAboveThreshold());
\r
506 ac.setThreshold(acg.getAnnotationThreshold());
\r
507 ac.setAnnotation(acg.getAnnotation());
\r
508 if(acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
\r
509 ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
\r
510 userColours, jms));
\r
512 ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));
\r
514 ac.setMaxColour(acg.getMaxColour().getRGB());
\r
515 ac.setMinColour(acg.getMinColour().getRGB());
\r
516 view.setAnnotationColours(ac);
\r
517 view.setBgColour("AnnotationColourGradient");
\r
521 view.setBgColour(ColourSchemeProperty.getColourName(
\r
522 av.getGlobalColourScheme()));
\r
525 ColourSchemeI cs = av.getGlobalColourScheme();
\r
529 if (cs.conservationApplied())
\r
531 view.setConsThreshold(cs.getConservationInc());
\r
532 if (cs instanceof jalview.schemes.UserColourScheme)
\r
533 view.setBgColour(SetUserColourScheme(cs, userColours, jms));
\r
536 if (cs instanceof ResidueColourScheme)
\r
538 view.setPidThreshold(cs.getThreshold());
\r
542 view.setConservationSelected(av.getConservationSelected());
\r
543 view.setPidSelected(av.getAbovePIDThreshold());
\r
544 view.setFontName(av.font.getName());
\r
545 view.setFontSize(av.font.getSize());
\r
546 view.setFontStyle(av.font.getStyle());
\r
547 view.setRenderGaps(av.renderGaps);
\r
548 view.setShowAnnotation(av.getShowAnnotation());
\r
549 view.setShowBoxes(av.getShowBoxes());
\r
550 view.setShowColourText(av.getColourText());
\r
551 view.setShowConservation(av.showConservation);
\r
552 view.setShowFullId(av.getShowJVSuffix());
\r
553 view.setShowIdentity(av.showIdentity);
\r
554 view.setShowQuality(av.showQuality);
\r
555 view.setShowSequenceFeatures(av.showSequenceFeatures);
\r
556 view.setShowText(av.getShowText());
\r
557 view.setWrapAlignment(av.getWrapAlignment());
\r
559 if(av.featuresDisplayed!=null)
\r
561 jalview.schemabinding.version2.FeatureSettings fs
\r
562 = new jalview.schemabinding.version2.FeatureSettings();
\r
564 String [] renderOrder =
\r
565 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
\r
566 for(int ro=0; ro<renderOrder.length; ro++)
\r
568 Setting setting = new Setting();
\r
569 setting.setType(renderOrder[ro]);
\r
571 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(renderOrder[ro]).getRGB()
\r
574 setting.setDisplay(
\r
575 av.featuresDisplayed.containsKey(renderOrder[ro])
\r
578 fs.addSetting(setting);
\r
581 jms.setFeatureSettings(fs);
\r
585 if(av.hasHiddenColumns)
\r
587 for(int c=0; c<av.getColumnSelection().getHiddenColumns().size(); c++)
\r
589 int [] region = (int[]) av.getColumnSelection().getHiddenColumns().elementAt(c);
\r
590 HiddenColumns hc = new HiddenColumns();
\r
591 hc.setStart(region[0]);
\r
592 hc.setEnd(region[1]);
\r
593 view.addHiddenColumns(hc);
\r
597 if(av.hasHiddenRows)
\r
599 // av.alignment.getHiddenSequences().get
\r
600 // HiddenSequences hs = new HiddenSequences();
\r
602 // view.addHiddenSequences();
\r
603 // av.showAllHiddenSeqs();.alignment.getHiddenSequences().
\r
606 jms.addViewport(view);
\r
609 object.setJalviewModelSequence(jms);
\r
610 object.getVamsasModel().addSequenceSet(vamsasSet);
\r
614 if (!fileName.endsWith(".xml"))
\r
616 fileName = fileName + ".xml";
\r
619 JarEntry entry = new JarEntry(fileName);
\r
620 jout.putNextEntry(entry);
\r
622 object.marshal(out);
\r
624 catch (Exception ex)
\r
626 ex.printStackTrace();
\r
630 String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
\r
631 Vector userColours, JalviewModelSequence jms)
\r
634 jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs;
\r
636 if (!userColours.contains(ucs))
\r
638 userColours.add(ucs);
\r
640 java.awt.Color[] colours = ucs.getColours();
\r
641 jalview.schemabinding.version2.UserColours uc = new jalview.schemabinding.version2.UserColours();
\r
642 jalview.schemabinding.version2.UserColourScheme jbucs = new jalview.schemabinding.version2.UserColourScheme();
\r
644 for (int i = 0; i < colours.length; i++)
\r
646 jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
\r
647 col.setRGB(jalview.util.Format.getHexString(colours[i]));
\r
648 jbucs.addColour(col);
\r
651 id = "ucs" + userColours.indexOf(ucs);
\r
653 uc.setUserColourScheme(jbucs);
\r
654 jms.addUserColours(uc);
\r
660 jalview.schemes.UserColourScheme GetUserColourScheme(
\r
661 JalviewModelSequence jms, String id)
\r
663 UserColours[] uc = jms.getUserColours();
\r
664 UserColours colours = null;
\r
666 for (int i = 0; i < uc.length; i++)
\r
668 if (uc[i].getId().equals(id))
\r
676 int csize = colours.getUserColourScheme().getColourCount();
\r
677 java.awt.Color[] newColours = new java.awt.Color[csize];
\r
679 for (int i = 0; i < csize; i++)
\r
681 newColours[i] = new java.awt.Color(Integer.parseInt(
\r
682 colours.getUserColourScheme().getColour(i).getRGB(), 16));
\r
685 return new jalview.schemes.UserColourScheme(newColours);
\r
691 * @param file DOCUMENT ME!
\r
693 public AlignFrame LoadJalviewAlign(String file)
\r
696 jalview.gui.AlignFrame af = null;
\r
700 //UNMARSHALLER SEEMS TO CLOSE JARINPUTSTREAM, MOST ANNOYING
\r
703 if (file.startsWith("http://"))
\r
705 url = new URL(file);
\r
708 JarInputStream jin = null;
\r
709 JarEntry jarentry = null;
\r
710 int entryCount = 1;
\r
716 jin = new JarInputStream(url.openStream());
\r
720 jin = new JarInputStream(new FileInputStream(file));
\r
723 for (int i = 0; i < entryCount; i++)
\r
725 jarentry = jin.getNextJarEntry();
\r
730 class NoDescIDResolver implements IDResolver
\r
732 public Object resolve(String idref)
\r
734 System.out.println(idref+" used");
\r
740 if (jarentry != null)
\r
742 InputStreamReader in = new InputStreamReader(jin, "UTF-8");
\r
743 JalviewModel object = new JalviewModel();
\r
745 Unmarshaller unmar = new Unmarshaller(object);
\r
746 unmar.setValidation(false);
\r
747 object = (JalviewModel) unmar.unmarshal( in );
\r
749 af = LoadFromObject(object);
\r
753 while (jarentry != null);
\r
755 catch(java.net.UnknownHostException ex)
\r
757 ex.printStackTrace();
\r
758 System.err.println("Couldn't locate Jalview XML file : " +
\r
760 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
761 "Couldn't locate " + file,
\r
763 JOptionPane.WARNING_MESSAGE);
\r
766 catch (Exception ex)
\r
768 //Is Version 1 Jar file?
\r
769 af = new Jalview2XML_V1().LoadJalviewAlign(file);
\r
773 System.out.println("Successfully loaded archive file");
\r
776 ex.printStackTrace();
\r
777 System.err.println("Exception whilst loading jalview XML file : " +
\r
779 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
780 "Error loading " + file,
\r
781 "Error loading Jalview file",
\r
782 JOptionPane.WARNING_MESSAGE);
\r
789 AlignFrame LoadFromObject(JalviewModel object)
\r
791 Vector seqids = new Vector();
\r
792 SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
\r
793 Sequence[] vamsasSeq = vamsasSet.getSequence();
\r
795 JalviewModelSequence jms = object.getJalviewModelSequence();
\r
797 //////////////////////////////////
\r
799 Vector hiddenSeqs = null;
\r
800 jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length];
\r
801 JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
\r
802 for (int i = 0; i < vamsasSeq.length; i++)
\r
804 jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(),
\r
805 vamsasSeq[i].getSequence());
\r
806 jseqs[i].setDescription( vamsasSeq[i].getDescription() );
\r
808 if(JSEQ[i].getHidden())
\r
810 if(hiddenSeqs == null)
\r
811 hiddenSeqs = new Vector();
\r
812 hiddenSeqs.addElement(jseqs[i]);
\r
814 jseqs[i].setStart(JSEQ[i].getStart());
\r
815 jseqs[i].setEnd(JSEQ[i].getEnd());
\r
816 jseqs[i].setColor(new java.awt.Color(JSEQ[i].getColour()));
\r
817 seqids.add(jseqs[i]);
\r
820 ///SequenceFeatures are added to the DatasetSequence,
\r
821 // so we must create the dataset before loading features
\r
822 /////////////////////////////////
\r
823 jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs);
\r
824 al.setDataset(null);
\r
825 /////////////////////////////////
\r
828 for (int i = 0; i < vamsasSeq.length; i++)
\r
830 if (JSEQ[i].getFeaturesCount() > 0)
\r
832 Features[] features = JSEQ[i].getFeatures();
\r
833 for (int f = 0; f < features.length; f++)
\r
835 jalview.datamodel.SequenceFeature sf
\r
836 = new jalview.datamodel.SequenceFeature(features[f].getType(),
\r
837 features[f].getDescription(), features[f].getStatus(),
\r
838 features[f].getBegin(), features[f].getEnd(),
\r
839 features[f].getFeatureGroup());
\r
841 al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf);
\r
844 if (JSEQ[i].getPdbidsCount() > 0)
\r
846 Pdbids[] ids = JSEQ[i].getPdbids();
\r
847 for (int p = 0; p < ids.length; p++)
\r
849 jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
\r
850 entry.setId(ids[p].getId());
\r
851 entry.setType(ids[p].getType());
\r
852 al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
\r
856 if(vamsasSeq[i].getDBRefCount()>0)
\r
858 for(int d=0; d<vamsasSeq[i].getDBRefCount(); d++)
\r
860 jalview.datamodel.DBRefEntry entry =
\r
861 new jalview.datamodel.DBRefEntry(
\r
862 vamsasSeq[i].getDBRef(d).getSource(),
\r
863 vamsasSeq[i].getDBRef(d).getVersion(),
\r
864 vamsasSeq[i].getDBRef(d).getAccessionId()
\r
866 al.getSequenceAt(i).getDatasetSequence().addDBRef(entry);
\r
874 /////////////////////////////////
\r
875 //////////////////////////////////
\r
877 boolean hideQuality = true,
\r
878 hideConservation = true,
\r
879 hideConsensus = true;
\r
881 if (vamsasSet.getAnnotation() != null)
\r
883 Annotation[] an = vamsasSet.getAnnotation();
\r
885 for (int i = 0; i < an.length; i++)
\r
887 if (an[i].getLabel().equals("Quality"))
\r
889 hideQuality = false;
\r
892 else if(an[i].getLabel().equals("Conservation"))
\r
894 hideConservation = false;
\r
897 else if(an[i].getLabel().equals("Consensus"))
\r
899 hideConsensus = false;
\r
903 AnnotationElement[] ae = an[i].getAnnotationElement();
\r
904 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];
\r
906 for (int aa = 0; aa < ae.length; aa++)
\r
908 anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),
\r
909 ae[aa].getDescription(),
\r
910 ae[aa].getSecondaryStructure().length()==0?' ':ae[aa].getSecondaryStructure().charAt(0),
\r
911 ae[aa].getValue());
\r
912 anot[ae[aa].getPosition()].colour = new java.awt.Color( ae[aa].getColour() );
\r
915 jalview.datamodel.AlignmentAnnotation jaa = null;
\r
917 if (an[i].getGraph())
\r
919 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
\r
920 an[i].getDescription(), anot, 0, 0,
\r
921 an[i].getGraphType());
\r
923 jaa.graphGroup = an[i].getGraphGroup();
\r
925 if (an[i].getThresholdLine() != null)
\r
927 jaa.setThreshold(new jalview.datamodel.GraphLine(
\r
928 an[i].getThresholdLine().getValue(),
\r
929 an[i].getThresholdLine().getLabel(),
\r
930 new java.awt.Color(an[i].getThresholdLine().getColour()))
\r
938 jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
\r
939 an[i].getDescription(), anot);
\r
942 if(an[i].getSequenceRef()!=null)
\r
944 jaa.createSequenceMapping(
\r
945 al.findName(an[i].getSequenceRef()), 1
\r
947 al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
\r
950 al.addAnnotation(jaa);
\r
955 // af.changeColour() );
\r
956 /////////////////////////
\r
958 if (jms.getJGroupCount() > 0)
\r
960 JGroup[] groups = jms.getJGroup();
\r
962 for (int i = 0; i < groups.length; i++)
\r
964 ColourSchemeI cs = null;
\r
966 if (groups[i].getColour() != null)
\r
968 if (groups[i].getColour().startsWith("ucs"))
\r
970 cs = GetUserColourScheme(jms, groups[i].getColour());
\r
974 cs = ColourSchemeProperty.getColour(al,
\r
975 groups[i].getColour());
\r
979 cs.setThreshold(groups[i].getPidThreshold(), true);
\r
982 Vector seqs = new Vector();
\r
983 int[] ids = groups[i].getSeq();
\r
985 for (int s = 0; s < ids.length; s++)
\r
987 seqs.addElement((jalview.datamodel.SequenceI) seqids.elementAt(
\r
991 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,
\r
992 groups[i].getName(), cs, groups[i].getDisplayBoxes(),
\r
993 groups[i].getDisplayText(), groups[i].getColourText(),
\r
994 groups[i].getStart(), groups[i].getEnd());
\r
996 sg.setOutlineColour(new java.awt.Color(
\r
997 groups[i].getOutlineColour()));
\r
999 if (groups[i].getConsThreshold() != 0)
\r
1001 jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",
\r
1002 ResidueProperties.propHash, 3, sg.getSequences(false), 0,
\r
1003 sg.getWidth() - 1);
\r
1005 c.verdict(false, 25);
\r
1006 sg.cs.setConservation(c);
\r
1014 /////////////////////////////////
\r
1016 Viewport[] views = jms.getViewport();
\r
1017 Viewport view = views[0]; // DEAL WITH MULTIPLE VIEWPORTS LATER
\r
1020 AlignFrame af = new AlignFrame(al);
\r
1022 if(hiddenSeqs!=null)
\r
1024 for(int s=0; s<JSEQ.length; s++)
\r
1026 for(int r=0; r<JSEQ[s].getHiddenSequencesCount(); r++)
\r
1028 al.getSequenceAt(s).addHiddenSequence(
\r
1029 al.getSequenceAt( JSEQ[s].getHiddenSequences(r) )
\r
1034 for(int s=0; s<hiddenSeqs.size(); s++)
\r
1036 af.viewport.hideSequence(
\r
1037 (jalview.datamodel.SequenceI)hiddenSeqs.elementAt(s));
\r
1042 if(hideConsensus || hideQuality || hideConservation)
\r
1044 int hSize = al.getAlignmentAnnotation().length;
\r
1045 for (int h = 0; h < hSize; h++)
\r
1049 al.getAlignmentAnnotation()[h].label.equals("Consensus"))
\r
1052 al.getAlignmentAnnotation()[h].label.equals("Quality"))
\r
1054 (hideConservation &&
\r
1055 al.getAlignmentAnnotation()[h].label.equals("Conservation")))
\r
1057 al.deleteAnnotation(al.getAlignmentAnnotation()[h]);
\r
1062 af.alignPanel.adjustAnnotationHeight();
\r
1065 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(),
\r
1066 view.getHeight());
\r
1067 af.viewport.setStartRes(view.getStartRes());
\r
1068 af.viewport.setStartSeq(view.getStartSeq());
\r
1069 af.viewport.setShowAnnotation(view.getShowAnnotation());
\r
1070 af.viewport.showConservation = view.getShowConservation();
\r
1071 af.viewport.showQuality = view.getShowQuality();
\r
1072 af.viewport.showIdentity = view.getShowIdentity();
\r
1073 af.viewport.setAbovePIDThreshold(view.getPidSelected());
\r
1074 af.abovePIDThreshold.setSelected(view.getPidSelected());
\r
1075 af.viewport.setColourText(view.getShowColourText());
\r
1076 af.colourTextMenuItem.setSelected(view.getShowColourText());
\r
1077 af.viewport.setConservationSelected(view.getConservationSelected());
\r
1078 af.conservationMenuItem.setSelected(view.getConservationSelected());
\r
1080 af.viewport.setShowJVSuffix(view.getShowFullId());
\r
1081 af.seqLimits.setSelected(view.getShowFullId());
\r
1083 af.viewport.setFont(new java.awt.Font(view.getFontName(),
\r
1084 view.getFontStyle(), view.getFontSize()));
\r
1085 af.alignPanel.fontChanged();
\r
1087 af.viewport.setRenderGaps(view.getRenderGaps());
\r
1088 af.renderGapsMenuItem.setSelected(view.getRenderGaps());
\r
1090 af.viewport.setWrapAlignment(view.getWrapAlignment());
\r
1091 af.wrapMenuItem.setSelected(view.getWrapAlignment());
\r
1093 if (view.getWrapAlignment())
\r
1095 af.alignPanel.setWrapAlignment(view.getWrapAlignment());
\r
1099 af.annotationPanelMenuItem.setState(view.getShowAnnotation());
\r
1100 af.viewport.setShowAnnotation(view.getShowAnnotation());
\r
1101 af.alignPanel.setAnnotationVisible(view.getShowAnnotation());
\r
1104 af.viewport.setShowBoxes(view.getShowBoxes());
\r
1105 af.viewBoxesMenuItem.setSelected(view.getShowBoxes());
\r
1106 af.viewport.setShowText(view.getShowText());
\r
1107 af.viewTextMenuItem.setSelected(view.getShowText());
\r
1109 ColourSchemeI cs = null;
\r
1111 if (view.getBgColour() != null)
\r
1113 if (view.getBgColour().startsWith("ucs"))
\r
1115 cs = GetUserColourScheme(jms, view.getBgColour());
\r
1117 else if(view.getBgColour().startsWith("Annotation"))
\r
1119 //int find annotation
\r
1120 for (int i = 0; i < af.viewport.alignment.getAlignmentAnnotation().length; i++)
\r
1122 if (af.viewport.alignment.getAlignmentAnnotation()[i].label.
\r
1123 equals(view.getAnnotationColours().getAnnotation()))
\r
1125 if (af.viewport.alignment.getAlignmentAnnotation()[i].
\r
1126 getThreshold() == null)
\r
1128 af.viewport.alignment.getAlignmentAnnotation()[i].
\r
1130 new jalview.datamodel.GraphLine(
\r
1131 view.getAnnotationColours().getThreshold(),
\r
1132 "Threshold", java.awt.Color.black)
\r
1138 if (view.getAnnotationColours().getColourScheme().equals(
\r
1141 cs = new AnnotationColourGradient(
\r
1142 af.viewport.alignment.getAlignmentAnnotation()[i],
\r
1143 new java.awt.Color(view.getAnnotationColours().
\r
1145 new java.awt.Color(view.getAnnotationColours().
\r
1147 view.getAnnotationColours().getAboveThreshold());
\r
1149 else if (view.getAnnotationColours().getColourScheme().
\r
1150 startsWith("ucs"))
\r
1152 cs = new AnnotationColourGradient(
\r
1153 af.viewport.alignment.getAlignmentAnnotation()[i],
\r
1154 GetUserColourScheme(jms, view.getAnnotationColours().
\r
1155 getColourScheme()),
\r
1156 view.getAnnotationColours().getAboveThreshold()
\r
1161 cs = new AnnotationColourGradient(
\r
1162 af.viewport.alignment.getAlignmentAnnotation()[i],
\r
1163 ColourSchemeProperty.getColour(al,
\r
1164 view.getAnnotationColours().getColourScheme()),
\r
1165 view.getAnnotationColours().getAboveThreshold()
\r
1169 // Also use these settings for all the groups
\r
1170 if (al.getGroups() != null)
\r
1171 for (int g = 0; g < al.getGroups().size(); g++)
\r
1173 jalview.datamodel.SequenceGroup sg
\r
1174 = (jalview.datamodel.SequenceGroup)al.getGroups().elementAt(g);
\r
1180 /* if (view.getAnnotationColours().getColourScheme().equals("None"))
\r
1182 sg.cs = new AnnotationColourGradient(
\r
1183 af.viewport.alignment.getAlignmentAnnotation()[i],
\r
1184 new java.awt.Color(view.getAnnotationColours().
\r
1186 new java.awt.Color(view.getAnnotationColours().
\r
1188 view.getAnnotationColours().getAboveThreshold());
\r
1192 sg.cs = new AnnotationColourGradient(
\r
1193 af.viewport.alignment.getAlignmentAnnotation()[i],
\r
1195 view.getAnnotationColours().getAboveThreshold()
\r
1209 cs = ColourSchemeProperty.getColour(al, view.getBgColour());
\r
1214 cs.setThreshold(view.getPidThreshold(), true);
\r
1215 cs.setConsensus(af.viewport.vconsensus);
\r
1219 af.setColourSelected(view.getBgColour());
\r
1220 af.viewport.setGlobalColourScheme(cs);
\r
1221 af.viewport.setColourAppliesToAllGroups(false);
\r
1222 af.changeColour(cs);
\r
1223 if (view.getConservationSelected() && cs!=null)
\r
1225 cs.setConservationInc(view.getConsThreshold());
\r
1228 af.viewport.setColourAppliesToAllGroups(true);
\r
1230 if (view.getShowSequenceFeatures())
\r
1232 af.viewport.showSequenceFeatures = true;
\r
1233 af.showSeqFeatures.setSelected(true);
\r
1236 if(jms.getFeatureSettings()!=null)
\r
1238 af.viewport.featuresDisplayed = new Hashtable();
\r
1239 String [] renderOrder = new String[jms.getFeatureSettings().getSettingCount()];
\r
1240 for(int fs=0; fs<jms.getFeatureSettings().getSettingCount(); fs++)
\r
1242 Setting setting = jms.getFeatureSettings().getSetting(fs);
\r
1244 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(setting.getType(),
\r
1245 new java.awt.Color(setting.getColour()));
\r
1247 renderOrder[fs] = setting.getType();
\r
1249 if(setting.getDisplay())
\r
1250 af.viewport.featuresDisplayed.put(
\r
1251 setting.getType(), new Integer(setting.getColour()));
\r
1253 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder;
\r
1256 if (view.getHiddenColumnsCount() > 0)
\r
1258 for (int c = 0; c < view.getHiddenColumnsCount(); c++)
\r
1260 af.viewport.hideColumns(
\r
1261 view.getHiddenColumns(c).getStart(),
\r
1262 view.getHiddenColumns(c).getEnd()+1
\r
1268 Desktop.addInternalFrame(af, view.getTitle(),
\r
1269 view.getWidth(), view.getHeight());
\r
1272 ///////////////////////////////////////
\r
1273 if (jms.getTreeCount() > 0)
\r
1277 for (int t = 0; t < jms.getTreeCount(); t++)
\r
1280 Tree tree = jms.getTree(t);
\r
1282 TreePanel tp = af.ShowNewickTree(new jalview.io.NewickFile(
\r
1283 tree.getNewick()), tree.getTitle(),
\r
1284 tree.getWidth(), tree.getHeight(),
\r
1285 tree.getXpos(), tree.getYpos());
\r
1287 tp.fitToWindow.setState(tree.getFitToWindow());
\r
1288 tp.fitToWindow_actionPerformed(null);
\r
1290 if(tree.getFontName()!=null)
\r
1291 tp.setTreeFont(new java.awt.Font(tree.getFontName(),
\r
1292 tree.getFontStyle(),
\r
1293 tree.getFontSize()));
\r
1295 tp.setTreeFont(new java.awt.Font(view.getFontName(),
\r
1296 view.getFontStyle(),
\r
1297 tree.getFontSize()));
\r
1299 tp.showPlaceholders(tree.getMarkUnlinked());
\r
1300 tp.showBootstrap(tree.getShowBootstrap());
\r
1301 tp.showDistances(tree.getShowDistances());
\r
1303 tp.treeCanvas.threshold = tree.getThreshold();
\r
1305 if (tree.getCurrentTree())
\r
1306 af.viewport.setCurrentTree(tp.getTree());
\r
1310 catch (Exception ex)
\r
1312 ex.printStackTrace();
\r