From: Charles Ofoegbu Date: Thu, 27 Nov 2014 09:22:29 +0000 (+0000) Subject: Merge branch 'bug/JAL-1583_MSA_webservice_validation' into develop X-Git-Tag: Jalview_2_9~140 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dd41808ee328f03b297334934937e86546be0fd0;hp=02a721469b0aa9d336db4e3b243250ba0eb9d372;p=jalview.git Merge branch 'bug/JAL-1583_MSA_webservice_validation' into develop --- diff --git a/.classpath b/.classpath index 38d2106..4c39421 100644 --- a/.classpath +++ b/.classpath @@ -45,15 +45,15 @@ + - - + diff --git a/.gitignore b/.gitignore index c47ff62..0c12fb0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ /.DS_Store .DS_Store /.com.apple.timemachine.supported +.gitattributes + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 884491a..f72955b 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,15 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/examples/example_biojs.html b/examples/example_biojs.html new file mode 100644 index 0000000..b6f7bec --- /dev/null +++ b/examples/example_biojs.html @@ -0,0 +1,9031 @@ + +
BioJS viewer
+ + + + + + + + Jalview Logo + +
+
+ + + + +
+
+ +
press "Run with JS"
+ + + + + + + + diff --git a/help/html/features/chimera.html b/help/html/features/chimera.html index e866597..236701a 100644 --- a/help/html/features/chimera.html +++ b/help/html/features/chimera.html @@ -133,6 +133,8 @@ atoms in the displayed structures. For comprehensive details of Chimera's comman they are insertions (relative to the associated sequence in the alignment) and grey if they are N or C terminal flanks outside the region mapped to the alignment window's sequence. +
  • By Chain
    +
    Uses the Chimera 'rainbow chain' command to apply a different colour to each chain.
  • Charge & Cysteine
    Highlights cysteines in yellow, anionic (Aspartic Acid or Glutamic Acid) residues in red, and cationic (Lysine or Arginine) diff --git a/lib/jsoup-1.8.1.jar b/lib/jsoup-1.8.1.jar new file mode 100644 index 0000000..ae717d4 Binary files /dev/null and b/lib/jsoup-1.8.1.jar differ diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 5d3667b..cabee76 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -107,7 +107,7 @@ action.change_params = Change Parameters action.apply = Apply action.apply_threshold_all_groups = Apply threshold to all groups action.apply_all_groups = Apply to all Groups -action.by_chain = By chain +action.by_chain = By Chain action.by_sequence = By Sequence action.paste_annotations = Paste Annotations action.format = Format diff --git a/resources/templates/BioJSTemplate.txt b/resources/templates/BioJSTemplate.txt new file mode 100644 index 0000000..bf780bb --- /dev/null +++ b/resources/templates/BioJSTemplate.txt @@ -0,0 +1,9032 @@ + +
    BioJS viewer
    + + + + + + + + Jalview Logo + +
    +
    + + + + +
    +
    + +
    press "Run with JS"
    + + + + + + + + \ No newline at end of file diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java index e8f1bc9..408108b 100755 --- a/src/MCview/PDBChain.java +++ b/src/MCview/PDBChain.java @@ -392,8 +392,8 @@ public class PDBChain } AlignmentAnnotation tfactorann = new AlignmentAnnotation( - "PDB.TempFactor", "Temperature Factor for " - + sequence.getName(), annots, 0, max, + "Temperature Factor", "Temperature Factor for " + pdbid + id, + annots, 0, max, AlignmentAnnotation.LINE_GRAPH); tfactorann.setSequenceRef(sequence); sequence.addAlignmentAnnotation(tfactorann); @@ -552,34 +552,37 @@ public class PDBChain } } } - float min = -1, max = 0; - Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1]; - for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++) + if (false) { - int prn = mapping.getPDBResNum(k + 1); - - an[k] = new Annotation(prn); - if (min == -1) + // Useful for debugging mappings - adds annotation for mapped position + float min = -1, max = 0; + Annotation[] an = new Annotation[sq.getEnd() - sq.getStart() + 1]; + for (int i = sq.getStart(), j = sq.getEnd(), k = 0; i <= j; i++, k++) { - min = k; - max = k; - } - else - { - if (min > k) + int prn = mapping.getPDBResNum(k + 1); + + an[k] = new Annotation(prn); + if (min == -1) { min = k; + max = k; } - else if (max < k) + else { - max = k; + if (min > k) + { + min = k; + } + else if (max < k) + { + max = k; + } } } + sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM", + "PDB Residue Numbering for " + this.pdbid + ":" + this.id, + an, min, max, AlignmentAnnotation.LINE_GRAPH)); } - sq.addAlignmentAnnotation(new AlignmentAnnotation("PDB.RESNUM", - "PDB Residue Numbering for " + this.pdbid + ":" + this.id, - an, min, max, AlignmentAnnotation.LINE_GRAPH)); - } } } diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index e1c4dc5..691fdcd 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -361,8 +361,8 @@ public class PDBfile extends jalview.io.AlignFile AlignmentI al, String pep, boolean b) { List> replaced = AlignSeq - .replaceMatchingSeqsWith(seqs, annotations, prot, al, - AlignSeq.PEP, false); + .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep, + false); for (PDBChain ch : chains) { int p = 0; diff --git a/src/jalview/analysis/AnnotationSorter.java b/src/jalview/analysis/AnnotationSorter.java index a5d2164..81398eb 100644 --- a/src/jalview/analysis/AnnotationSorter.java +++ b/src/jalview/analysis/AnnotationSorter.java @@ -209,6 +209,10 @@ public class AnnotationSorter public void sort(AlignmentAnnotation[] alignmentAnnotations, SequenceAnnotationOrder order) { + if (alignmentAnnotations == null) + { + return; + } // cache 'alignment sequence position' for the annotations saveSequenceIndices(alignmentAnnotations); diff --git a/src/jalview/analysis/Rna.java b/src/jalview/analysis/Rna.java index e4a0d76..227bf09 100644 --- a/src/jalview/analysis/Rna.java +++ b/src/jalview/analysis/Rna.java @@ -26,6 +26,10 @@ package jalview.analysis; +import jalview.analysis.SecStrConsensus.SimpleBP; +import jalview.datamodel.SequenceFeature; +import jalview.util.MessageManager; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -33,10 +37,6 @@ import java.util.Hashtable; import java.util.Stack; import java.util.Vector; -import jalview.analysis.SecStrConsensus.SimpleBP; -import jalview.datamodel.SequenceFeature; -import jalview.util.MessageManager; - public class Rna { @@ -65,7 +65,7 @@ public class Rna { for (int i = 0; i < openingPars.length; i++) { - System.out.println(closingPars[i] + "->" + openingPars[i]); + // System.out.println(closingPars[i] + "->" + openingPars[i]); put(closingPars[i], openingPars[i]); } } @@ -107,7 +107,6 @@ public class Rna public static Vector GetSimpleBPs(CharSequence line) throws WUSSParseException { - System.out.println(line); Hashtable> stacks = new Hashtable>(); Vector pairs = new Vector(); int i = 0; diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index eba1200..98a4a1c 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -20,19 +20,43 @@ */ package jalview.appletgui; -import java.util.*; - -import java.awt.*; -import java.awt.event.*; - -import jalview.analysis.*; -import jalview.commands.*; -import jalview.datamodel.*; -import jalview.schemes.*; -import jalview.util.MessageManager; -import jalview.util.UrlLink; +import jalview.analysis.AAFrequency; +import jalview.analysis.Conservation; +import jalview.commands.ChangeCaseCommand; +import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; +import jalview.datamodel.DBRefEntry; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; import jalview.io.SequenceAnnotationReport; +import jalview.schemes.Blosum62ColourScheme; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.ClustalxColourScheme; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.NucleotideColourScheme; +import jalview.schemes.PIDColourScheme; +import jalview.schemes.ResidueProperties; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.ZappoColourScheme; +import jalview.util.MessageManager; +import jalview.util.UrlLink; + +import java.awt.CheckboxMenuItem; +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.Vector; public class APopupMenu extends java.awt.PopupMenu implements ActionListener, ItemListener @@ -549,7 +573,9 @@ public class APopupMenu extends java.awt.PopupMenu implements if (sg != null) { if (seq == null) + { seq = (Sequence) sg.getSequenceAt(0); + } EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString( sg.getStartRes(), sg.getEndRes() + 1), null, @@ -560,7 +586,7 @@ public class APopupMenu extends java.awt.PopupMenu implements if (dialog.accept) { EditCommand editCommand = new EditCommand(MessageManager.getString("label.edit_sequences"), - EditCommand.REPLACE, dialog.getName().replace(' ', + Action.REPLACE, dialog.getName().replace(' ', ap.av.getGapCharacter()), sg.getSequencesAsArray(ap.av.getHiddenRepSequences()), sg.getStartRes(), sg.getEndRes() + 1, @@ -742,11 +768,15 @@ public class APopupMenu extends java.awt.PopupMenu implements PDBEntry entry = (PDBEntry) seq.getPDBId().firstElement(); if (ap.av.applet.jmolAvailable) + { new jalview.appletgui.AppletJmol(entry, new Sequence[] { seq }, null, ap, AppletFormatAdapter.URL); + } else + { new MCview.AppletPDBViewer(entry, new Sequence[] { seq }, null, ap, AppletFormatAdapter.URL); + } } else diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 34ec2cf..ed64215 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -27,6 +27,7 @@ import jalview.api.SequenceStructureBinding; import jalview.bin.JalviewLite; import jalview.commands.CommandI; import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; import jalview.commands.OrderCommand; import jalview.commands.RemoveGapColCommand; import jalview.commands.RemoveGapsCommand; @@ -1833,7 +1834,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } // !newAlignment - addHistoryItem(new EditCommand(MessageManager.getString("label.add_sequences"), EditCommand.PASTE, + addHistoryItem(new EditCommand( + MessageManager.getString("label.add_sequences"), Action.PASTE, seqs, 0, viewport.getAlignment().getWidth(), viewport.getAlignment())); @@ -1883,8 +1885,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, /* * //ADD HISTORY ITEM */ - addHistoryItem(new EditCommand(MessageManager.getString("label.cut_sequences"), EditCommand.CUT, cut, - sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, + addHistoryItem(new EditCommand( + MessageManager.getString("label.cut_sequences"), Action.CUT, + cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, viewport.getAlignment())); viewport.setSelectionGroup(null); diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 4b9fa67..22996f7 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -256,7 +256,9 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, anot[index] = new Annotation(label, "", type, 0); } - anot[index].secondaryStructure = type; + + anot[index].secondaryStructure = type != 'S' ? type : label + .length() == 0 ? ' ' : label.charAt(0); anot[index].displayCharacter = label; } } diff --git a/src/jalview/appletgui/PairwiseAlignPanel.java b/src/jalview/appletgui/PairwiseAlignPanel.java index 9afc70b..5a3b56c 100644 --- a/src/jalview/appletgui/PairwiseAlignPanel.java +++ b/src/jalview/appletgui/PairwiseAlignPanel.java @@ -20,15 +20,21 @@ */ package jalview.appletgui; -import java.util.*; - -import java.awt.*; -import java.awt.event.*; - -import jalview.analysis.*; -import jalview.datamodel.*; +import jalview.analysis.AlignSeq; +import jalview.datamodel.Alignment; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; import jalview.util.MessageManager; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Panel; +import java.awt.ScrollPane; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; + public class PairwiseAlignPanel extends Panel implements ActionListener { Vector sequences = new Vector(); @@ -89,13 +95,8 @@ public class PairwiseAlignPanel extends Panel implements ActionListener totscore = totscore + scores[i][j]; textarea.append(as.getOutput()); - seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1() - .getStart(), as.getS1().getEnd()); - sequences.addElement(seq); - - seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2() - .getStart(), as.getS2().getEnd()); - sequences.addElement(seq); + sequences.add(as.getAlignedSeq1()); + sequences.add(as.getAlignedSeq1()); } } diff --git a/src/jalview/appletgui/RedundancyPanel.java b/src/jalview/appletgui/RedundancyPanel.java index 1547862..8e364f0 100644 --- a/src/jalview/appletgui/RedundancyPanel.java +++ b/src/jalview/appletgui/RedundancyPanel.java @@ -20,16 +20,26 @@ */ package jalview.appletgui; -import java.util.*; -import java.util.List; -import java.awt.*; -import java.awt.event.*; - import jalview.analysis.AlignSeq; -import jalview.commands.*; -import jalview.datamodel.*; +import jalview.commands.CommandI; +import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; import jalview.util.MessageManager; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import java.util.Vector; + public class RedundancyPanel extends SliderPanel implements Runnable, WindowListener { @@ -197,7 +207,7 @@ public class RedundancyPanel extends SliderPanel implements Runnable, } EditCommand cut = new EditCommand(MessageManager.getString("action.remove_redundancy"), - EditCommand.CUT, deleted, 0, width, ap.av.getAlignment()); + Action.CUT, deleted, 0, width, ap.av.getAlignment()); AlignmentI alignment = ap.av.getAlignment(); for (int i = 0; i < del.size(); i++) { diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index de4d979..592fd4f 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -20,19 +20,31 @@ */ package jalview.appletgui; -import java.util.*; - -import java.awt.*; -import java.awt.event.*; - -import jalview.commands.*; -import jalview.datamodel.*; -import jalview.schemes.*; +import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SearchResults; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.schemes.ResidueProperties; import jalview.structure.SelectionSource; import jalview.structure.SequenceListener; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Panel; +import java.awt.Point; +import java.awt.event.InputEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.Vector; + public class SeqPanel extends Panel implements MouseMotionListener, MouseListener, SequenceListener { @@ -147,7 +159,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, void setCursorPosition() { - SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt( + SequenceI sequence = av.getAlignment().getSequenceAt( seqCanvas.cursorY); seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1; @@ -240,7 +252,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, void setSelectionAreaAtCursor(boolean topLeft) { - SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt( + SequenceI sequence = av.getAlignment().getSequenceAt( seqCanvas.cursorY); if (av.getSelectionGroup() != null) @@ -648,7 +660,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, { String tmp = sequence.hashCode() + index + ""; if (lastMessage == null || !lastMessage.equals(tmp)) + { ssm.mouseOverSequence(sequence, index, pos, av); + } lastMessage = tmp; } @@ -698,7 +712,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, int respos = sequence.findPosition(res); if (ssm != null) + { mouseOverSequence(sequence, res, respos); + } StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + sequence.getName()); @@ -813,7 +829,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, .containsKey(features[i].featureGroup) && !((Boolean) seqCanvas.fr.featureGroups .get(features[i].featureGroup)).booleanValue()) + { continue; + } if ((features[i].getBegin() <= res) && (features[i].getEnd() >= res)) @@ -938,7 +956,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { if (av.isHiddenRepSequence(seq)) { - sg = (SequenceGroup) av.getRepresentedSequences(seq); + sg = av.getRepresentedSequences(seq); groupEditing = true; } } @@ -1164,7 +1182,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - editCommand.appendEdit(EditCommand.INSERT_GAP, groupSeqs, + editCommand.appendEdit(Action.INSERT_GAP, groupSeqs, startres, startres - lastres, av.getAlignment(), true); } } @@ -1180,7 +1198,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - editCommand.appendEdit(EditCommand.DELETE_GAP, groupSeqs, + editCommand.appendEdit(Action.DELETE_GAP, groupSeqs, startres, lastres - startres, av.getAlignment(), true); } @@ -1202,7 +1220,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[] + editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres, startres - lastres, av.getAlignment(), true); } } @@ -1237,7 +1255,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (max > 0) { - editCommand.appendEdit(EditCommand.DELETE_GAP, new SequenceI[] + editCommand.appendEdit(Action.DELETE_GAP, new SequenceI[] { seq }, startres, max, av.getAlignment(), true); } } @@ -1273,10 +1291,10 @@ public class SeqPanel extends Panel implements MouseMotionListener, } } - editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1, + editCommand.appendEdit(Action.DELETE_GAP, seq, blankColumn, 1, av.getAlignment(), true); - editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1, + editCommand.appendEdit(Action.INSERT_GAP, seq, j, 1, av.getAlignment(), true); } @@ -1284,10 +1302,10 @@ public class SeqPanel extends Panel implements MouseMotionListener, void deleteChar(int j, SequenceI[] seq, int fixedColumn) { - editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1, + editCommand.appendEdit(Action.DELETE_GAP, seq, j, 1, av.getAlignment(), true); - editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1, + editCommand.appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1, av.getAlignment(), true); } @@ -1312,7 +1330,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, return; } - SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); + SequenceI sequence = av.getAlignment().getSequenceAt(seq); if (sequence == null || res > sequence.getLength()) { diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 24ed1b4..3b0a23e 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -150,6 +150,7 @@ import org.apache.log4j.SimpleLayout; *
  • FOLLOW_SELECTIONS (true) Controls whether a new alignment view should * respond to selections made in other alignments containing the same sequences. *
  • + *
  • JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services
  • *
  • SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery * warning dialog box is displayed.
  • *
  • ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 184c267..f80f341 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -24,6 +24,7 @@ import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.ws.jws2.Jws2Discoverer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -34,6 +35,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.lang.reflect.Constructor; +import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.net.URLDecoder; @@ -106,40 +108,7 @@ public class Jalview if (aparser.contains("help") || aparser.contains("h")) { - System.out - .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" - + "-nodisplay\tRun Jalview without User Interface.\n" - + "-props FILE\tUse the given Jalview properties file instead of users default.\n" - + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n" - + "-annotations FILE\tAdd precalculated annotations to the alignment.\n" - + "-tree FILE\tLoad the given newick format tree file onto the alignment\n" - + "-features FILE\tUse the given file to mark features on the alignment.\n" - + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n" - + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n" - + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n" - + "-msf FILE\tCreate alignment file FILE in MSF format.\n" - + "-pileup FILE\tCreate alignment file FILE in Pileup format\n" - + "-pir FILE\tCreate alignment file FILE in PIR format.\n" - + "-blc FILE\tCreate alignment file FILE in BLC format.\n" - + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n" - + "-png FILE\tCreate PNG image FILE from alignment.\n" - + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" - + "-eps FILE\tCreate EPS file FILE from alignment.\n" - + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n" - + "-noquestionnaire\tTurn off questionnaire check.\n" - + "-nousagestats\tTurn off google analytics tracking for this session.\n" - + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n" - // + - // "-setprop PROPERTY=VALUE\tSet the given Jalview property, after all other properties files have been read\n\t (quote the 'PROPERTY=VALUE' pair to ensure spaces are passed in correctly)" - + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n" - + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n" - + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n" - + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n" - // + - // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n" - // + "-vses vamsas-session\tJoin session with given URN\n" - + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n" - + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n"); + showUsage(); System.exit(0); } if (aparser.contains("nodisplay") || aparser.contains("nogui") @@ -150,6 +119,20 @@ public class Jalview } Cache.loadProperties(aparser.getValue("props")); // must do this before // anything else! + + final String jabawsUrl = aparser.getValue("jabaws"); + if (jabawsUrl != null) + { + try + { + Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl); + } catch (MalformedURLException e) + { + System.err.println("Invalid jabaws parameter: " + jabawsUrl + + " ignored"); + } + } + String defs = aparser.getValue("setprop"); while (defs != null) { @@ -619,6 +602,45 @@ public class Jalview } } + private static void showUsage() + { + System.out + .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" + + "-nodisplay\tRun Jalview without User Interface.\n" + + "-props FILE\tUse the given Jalview properties file instead of users default.\n" + + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n" + + "-annotations FILE\tAdd precalculated annotations to the alignment.\n" + + "-tree FILE\tLoad the given newick format tree file onto the alignment\n" + + "-features FILE\tUse the given file to mark features on the alignment.\n" + + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n" + + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n" + + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n" + + "-msf FILE\tCreate alignment file FILE in MSF format.\n" + + "-pileup FILE\tCreate alignment file FILE in Pileup format\n" + + "-pir FILE\tCreate alignment file FILE in PIR format.\n" + + "-blc FILE\tCreate alignment file FILE in BLC format.\n" + + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n" + + "-png FILE\tCreate PNG image FILE from alignment.\n" + + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" + + "-eps FILE\tCreate EPS file FILE from alignment.\n" + + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n" + + "-noquestionnaire\tTurn off questionnaire check.\n" + + "-nousagestats\tTurn off google analytics tracking for this session.\n" + + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n" + // + + // "-setprop PROPERTY=VALUE\tSet the given Jalview property, after all other properties files have been read\n\t (quote the 'PROPERTY=VALUE' pair to ensure spaces are passed in correctly)" + + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n" + + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n" + + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n" + + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n" + + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n" + // + + // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n" + // + "-vses vamsas-session\tJoin session with given URN\n" + + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n" + + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n"); + } + private static void startUsageStats(final Desktop desktop) { /** diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 5c698a8..82de3b2 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -27,8 +27,10 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import java.util.ListIterator; /** * @@ -54,19 +56,12 @@ import java.util.List; */ public class EditCommand implements CommandI { - public static final int INSERT_GAP = 0; - - public static final int DELETE_GAP = 1; - - public static final int CUT = 2; - - public static final int PASTE = 3; - - public static final int REPLACE = 4; - - public static final int INSERT_NUC = 5; + public enum Action + { + INSERT_GAP, DELETE_GAP, CUT, PASTE, REPLACE, INSERT_NUC + }; - Edit[] edits; + private List edits = new ArrayList(); String description; @@ -79,32 +74,75 @@ public class EditCommand implements CommandI this.description = description; } - public EditCommand(String description, int command, SequenceI[] seqs, + public EditCommand(String description, Action command, SequenceI[] seqs, int position, int number, AlignmentI al) { this.description = description; - if (command == CUT || command == PASTE) + if (command == Action.CUT || command == Action.PASTE) { - edits = new Edit[] - { new Edit(command, seqs, position, number, al) }; + setEdit(new Edit(command, seqs, position, number, al)); } performEdit(0, null); } - public EditCommand(String description, int command, String replace, + public EditCommand(String description, Action command, String replace, SequenceI[] seqs, int position, int number, AlignmentI al) { this.description = description; - if (command == REPLACE) + if (command == Action.REPLACE) { - edits = new Edit[] - { new Edit(command, seqs, position, number, al, replace) }; + setEdit(new Edit(command, seqs, position, number, al, replace)); } performEdit(0, null); } + /** + * Set the list of edits to the specified item (only). + * + * @param e + */ + protected void setEdit(Edit e) + { + edits.clear(); + edits.add(e); + } + + /** + * Add the given edit command to the stored list of commands. + * + * @param e + */ + protected void addEdit(Edit e) + { + edits.add(e); + } + + /** + * Clear the list of stored edit commands. + * + */ + protected void clearEdits() + { + edits.clear(); + } + + /** + * Returns the i'th stored Edit command. + * + * @param i + * @return + */ + protected Edit getEdit(int i) + { + if (i >= 0 && i < edits.size()) + { + return edits.get(i); + } + return null; + } + @Override final public String getDescription() { @@ -114,12 +152,17 @@ public class EditCommand implements CommandI @Override public int getSize() { - return edits == null ? 0 : edits.length; + return edits.size(); } + /** + * Return the alignment for the first edit (or null if no edit). + * + * @return + */ final public AlignmentI getAlignment() { - return edits[0].al; + return (edits.isEmpty() ? null : edits.get(0).al); } /** @@ -135,7 +178,8 @@ public class EditCommand implements CommandI * @param al * @param performEdit */ - final public void appendEdit(int command, SequenceI[] seqs, int position, + final public void appendEdit(Action command, SequenceI[] seqs, + int position, int number, AlignmentI al, boolean performEdit) { appendEdit(command, seqs, position, number, al, performEdit, null); @@ -153,7 +197,8 @@ public class EditCommand implements CommandI * @param performEdit * @param views */ - final public void appendEdit(int command, SequenceI[] seqs, int position, + final public void appendEdit(Action command, SequenceI[] seqs, + int position, int number, AlignmentI al, boolean performEdit, AlignmentI[] views) { Edit edit = new Edit(command, seqs, position, number, @@ -164,52 +209,62 @@ public class EditCommand implements CommandI edit.fullAlignmentHeight = true; } - if (edits != null) - { - Edit[] temp = new Edit[edits.length + 1]; - System.arraycopy(edits, 0, temp, 0, edits.length); - edits = temp; - edits[edits.length - 1] = edit; - } - else - { - edits = new Edit[] - { edit }; - } + edits.add(edit); if (performEdit) { - performEdit(edits.length - 1, views); + performEdit(edit, views); } } + /** + * Execute all the edit commands, starting at the given commandIndex + * + * @param commandIndex + * @param views + */ final void performEdit(int commandIndex, AlignmentI[] views) { - int eSize = edits.length; - for (int e = commandIndex; e < eSize; e++) + ListIterator iterator = edits.listIterator(commandIndex); + while (iterator.hasNext()) { - switch (edits[e].command) - { - case INSERT_GAP: - insertGap(edits[e]); - break; - case DELETE_GAP: - deleteGap(edits[e]); - break; - case CUT: - cut(edits[e], views); - break; - case PASTE: - paste(edits[e], views); - break; - case REPLACE: - replace(edits[e]); - break; + Edit edit = iterator.next(); + performEdit(edit, views); + } + } + + /** + * Execute one edit command in all the specified alignment views + * + * @param edit + * @param views + */ + protected void performEdit(Edit edit, AlignmentI[] views) + { + switch (edit.command) + { + case INSERT_GAP: + insertGap(edit); + break; + case DELETE_GAP: + deleteGap(edit); + break; + case CUT: + cut(edit, views); + break; + case PASTE: + paste(edit, views); + break; + case REPLACE: + replace(edit); + break; + case INSERT_NUC: // TODO:add deleteNuc for UNDO // case INSERT_NUC: // insertNuc(edits[e]); - // break; - } + break; + default: + break; } } @@ -219,32 +274,49 @@ public class EditCommand implements CommandI performEdit(0, views); } + /** + * Undo the stored list of commands, in reverse order. + */ @Override final public void undoCommand(AlignmentI[] views) { - for(Edit e : edits){ - switch (e.command) - { - case INSERT_GAP: - deleteGap(e); - break; - case DELETE_GAP: - insertGap(e); - break; - case CUT: - paste(e, views); - break; - case PASTE: - cut(e, views); - break; - case REPLACE: - replace(e); - break; - } + ListIterator iterator = edits.listIterator(edits.size()); + while (iterator.hasPrevious()) + { + Edit e = iterator.previous(); + switch (e.command) + { + case INSERT_GAP: + deleteGap(e); + break; + case DELETE_GAP: + insertGap(e); + break; + case CUT: + paste(e, views); + break; + case PASTE: + cut(e, views); + break; + case REPLACE: + replace(e); + break; + case INSERT_NUC: + // not implemented + break; + default: + break; + } } } - final void insertGap(Edit command) + /** + * Insert gap(s) in sequences as specified by the command, and adjust + * annotations. + * + * @param command + */ + final private void insertGap(Edit command) { for (int s = 0; s < command.seqs.length; s++) @@ -270,7 +342,13 @@ public class EditCommand implements CommandI // adjustAnnotations(command, true, false, null); // } - final void deleteGap(Edit command) + /** + * Delete gap(s) in sequences as specified by the command, and adjust + * annotations. + * + * @param command + */ + final private void deleteGap(Edit command) { for (int s = 0; s < command.seqs.length; s++) { @@ -281,6 +359,13 @@ public class EditCommand implements CommandI adjustAnnotations(command, false, false, null); } + /** + * Carry out a Cut action. The cut characters are saved in case Undo is + * requested. + * + * @param command + * @param views + */ void cut(Edit command, AlignmentI[] views) { boolean seqDeleted = false; @@ -288,29 +373,30 @@ public class EditCommand implements CommandI for (int i = 0; i < command.seqs.length; i++) { - if (command.seqs[i].getLength() > command.position) + final SequenceI sequence = command.seqs[i]; + if (sequence.getLength() > command.position) { - command.string[i] = command.seqs[i].getSequence(command.position, + command.string[i] = sequence.getSequence(command.position, command.position + command.number); - SequenceI oldds = command.seqs[i].getDatasetSequence(); + SequenceI oldds = sequence.getDatasetSequence(); if (command.oldds != null && command.oldds[i] != null) { // we are redoing an undone cut. - command.seqs[i].setDatasetSequence(null); + sequence.setDatasetSequence(null); } - command.seqs[i].deleteChars(command.position, command.position + sequence.deleteChars(command.position, command.position + command.number); if (command.oldds != null && command.oldds[i] != null) { // oldds entry contains the cut dataset sequence. - command.seqs[i].setDatasetSequence(command.oldds[i]); + sequence.setDatasetSequence(command.oldds[i]); command.oldds[i] = oldds; } else { // modify the oldds if necessary - if (oldds != command.seqs[i].getDatasetSequence() - || command.seqs[i].getSequenceFeatures() != null) + if (oldds != sequence.getDatasetSequence() + || sequence.getSequenceFeatures() != null) { if (command.oldds == null) { @@ -320,16 +406,16 @@ public class EditCommand implements CommandI adjustFeatures( command, i, - command.seqs[i].findPosition(command.position), - command.seqs[i].findPosition(command.position + sequence.findPosition(command.position), + sequence.findPosition(command.position + command.number), false); } } } - if (command.seqs[i].getLength() < 1) + if (sequence.getLength() < 1) { - command.al.deleteSequence(command.seqs[i]); + command.al.deleteSequence(sequence); seqDeleted = true; } } @@ -337,6 +423,13 @@ public class EditCommand implements CommandI adjustAnnotations(command, false, seqDeleted, views); } + /** + * Perform the given Paste command. This may be to add cut or copied sequences + * to an alignment, or to undo a 'Cut' action on a region of the alignment. + * + * @param command + * @param views + */ void paste(Edit command, AlignmentI[] views) { StringBuffer tmp; @@ -540,7 +633,7 @@ public class EditCommand implements CommandI if (modifyVisibility && !insert) { // only occurs if a sequence was added or deleted. - command.deletedAnnotationRows = new Hashtable(); + command.deletedAnnotationRows = new Hashtable(); } if (command.fullAlignmentHeight) { @@ -624,7 +717,7 @@ public class EditCommand implements CommandI && command.deletedAnnotationRows .containsKey(command.seqs[s])) { - AlignmentAnnotation[] revealed = (AlignmentAnnotation[]) command.deletedAnnotationRows + AlignmentAnnotation[] revealed = command.deletedAnnotationRows .get(command.seqs[s]); command.seqs[s].setAlignmentAnnotation(revealed); if (revealed != null) @@ -695,7 +788,7 @@ public class EditCommand implements CommandI if (!insert) { - command.deletedAnnotations = new Hashtable(); + command.deletedAnnotations = new Hashtable(); } int aSize; @@ -758,7 +851,7 @@ public class EditCommand implements CommandI && command.deletedAnnotations .containsKey(annotations[a].annotationId)) { - Annotation[] restore = (Annotation[]) command.deletedAnnotations + Annotation[] restore = command.deletedAnnotations .get(annotations[a].annotationId); System.arraycopy(restore, 0, temp, command.position, @@ -776,7 +869,7 @@ public class EditCommand implements CommandI && command.deletedAnnotations .containsKey(annotations[a].annotationId)) { - Annotation[] restore = (Annotation[]) command.deletedAnnotations + Annotation[] restore = command.deletedAnnotations .get(annotations[a].annotationId); temp = new Annotation[annotations[a].annotations.length @@ -871,7 +964,7 @@ public class EditCommand implements CommandI if (command.editedFeatures != null && command.editedFeatures.containsKey(seq)) { - sequence.setSequenceFeatures((SequenceFeature[]) command.editedFeatures + sequence.setSequenceFeatures(command.editedFeatures .get(seq)); } @@ -927,7 +1020,7 @@ public class EditCommand implements CommandI if (command.editedFeatures == null) { - command.editedFeatures = new Hashtable(); + command.editedFeatures = new Hashtable(); } command.editedFeatures.put(seq, oldsf); @@ -940,15 +1033,15 @@ public class EditCommand implements CommandI boolean fullAlignmentHeight = false; - Hashtable deletedAnnotationRows; + Hashtable deletedAnnotationRows; - Hashtable deletedAnnotations; + Hashtable deletedAnnotations; - Hashtable editedFeatures; + Hashtable editedFeatures; AlignmentI al; - int command; + Action command; char[][] string; @@ -960,7 +1053,7 @@ public class EditCommand implements CommandI char gapChar; - Edit(int command, SequenceI[] seqs, int position, int number, + Edit(Action command, SequenceI[] seqs, int position, int number, char gapChar) { this.command = command; @@ -970,7 +1063,7 @@ public class EditCommand implements CommandI this.gapChar = gapChar; } - Edit(int command, SequenceI[] seqs, int position, int number, + Edit(Action command, SequenceI[] seqs, int position, int number, AlignmentI al) { this.gapChar = al.getGapCharacter(); @@ -989,7 +1082,7 @@ public class EditCommand implements CommandI fullAlignmentHeight = (al.getHeight() == seqs.length); } - Edit(int command, SequenceI[] seqs, int position, int number, + Edit(Action command, SequenceI[] seqs, int position, int number, AlignmentI al, String replace) { this.command = command; diff --git a/src/jalview/commands/RemoveGapColCommand.java b/src/jalview/commands/RemoveGapColCommand.java index 6172ce8..ac93d4e 100644 --- a/src/jalview/commands/RemoveGapColCommand.java +++ b/src/jalview/commands/RemoveGapColCommand.java @@ -39,7 +39,8 @@ package jalview.commands; * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -import jalview.datamodel.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceI; public class RemoveGapColCommand extends EditCommand { @@ -55,7 +56,7 @@ public class RemoveGapColCommand extends EditCommand int startCol = -1, endCol = -1; columnsDeleted = 0; - edits = new Edit[0]; + clearEdits(); boolean delete = true; for (int i = start; i <= end; i++) @@ -86,7 +87,8 @@ public class RemoveGapColCommand extends EditCommand if (!delete && startCol > -1) { - this.appendEdit(DELETE_GAP, seqs, startCol - columnsDeleted, endCol + this.appendEdit(Action.DELETE_GAP, seqs, startCol - columnsDeleted, + endCol - startCol, al, false, null); columnsDeleted += (endCol - startCol); @@ -100,7 +102,8 @@ public class RemoveGapColCommand extends EditCommand // This is for empty columns at the // end of the alignment - this.appendEdit(DELETE_GAP, seqs, startCol - columnsDeleted, end + this.appendEdit(Action.DELETE_GAP, seqs, startCol - columnsDeleted, + end - startCol + 1, al, false, null); columnsDeleted += (end - startCol + 1); diff --git a/src/jalview/commands/RemoveGapsCommand.java b/src/jalview/commands/RemoveGapsCommand.java index 2e8d744..60d09f7 100644 --- a/src/jalview/commands/RemoveGapsCommand.java +++ b/src/jalview/commands/RemoveGapsCommand.java @@ -39,7 +39,8 @@ package jalview.commands; * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -import jalview.datamodel.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceI; public class RemoveGapsCommand extends EditCommand { @@ -74,7 +75,7 @@ public class RemoveGapsCommand extends EditCommand int j, jSize; - edits = new Edit[0]; + clearEdits(); boolean delete = true; char[] sequence; @@ -108,7 +109,7 @@ public class RemoveGapsCommand extends EditCommand if (!delete && startCol > -1) { - this.appendEdit(DELETE_GAP, new SequenceI[] + this.appendEdit(Action.DELETE_GAP, new SequenceI[] { seqs[s] }, start + startCol - deletedCols, endCol - startCol, al, false, null); @@ -119,7 +120,7 @@ public class RemoveGapsCommand extends EditCommand } if (delete && startCol > -1) { - this.appendEdit(DELETE_GAP, new SequenceI[] + this.appendEdit(Action.DELETE_GAP, new SequenceI[] { seqs[s] }, start + startCol - deletedCols, jSize - startCol, al, false, null); } diff --git a/src/jalview/commands/SlideSequencesCommand.java b/src/jalview/commands/SlideSequencesCommand.java index 1ad3d9e..382085c 100644 --- a/src/jalview/commands/SlideSequencesCommand.java +++ b/src/jalview/commands/SlideSequencesCommand.java @@ -20,7 +20,7 @@ */ package jalview.commands; -import jalview.datamodel.*; +import jalview.datamodel.SequenceI; public class SlideSequencesCommand extends EditCommand { @@ -37,21 +37,29 @@ public class SlideSequencesCommand extends EditCommand for (i = 0; i < lSize; i++) { for (j = 0; j < slideSize; j++) + { if (!jalview.util.Comparison.isGap(seqsLeft[i].getCharAt(j))) { gapsInsertedBegin = true; break; } + } } + Edit e = null; + if (!gapsInsertedBegin) - edits = new Edit[] - { new Edit(DELETE_GAP, seqsLeft, 0, slideSize, gapChar) }; + { + e = new Edit(Action.DELETE_GAP, seqsLeft, 0, slideSize, gapChar); + setEdit(e); + } else - edits = new Edit[] - { new Edit(INSERT_GAP, seqsRight, 0, slideSize, gapChar) }; + { + e = new Edit(Action.INSERT_GAP, seqsRight, 0, slideSize, gapChar); + setEdit(e); + } - performEdit(0, null); + performEdit(e, null); } public boolean getGapsInsertedBegin() @@ -63,12 +71,12 @@ public class SlideSequencesCommand extends EditCommand { boolean same = false; - if (command.edits[0].seqs.length == edits[0].seqs.length) + if (command.getEdit(0).seqs.length == getEdit(0).seqs.length) { same = true; - for (int i = 0; i < command.edits[0].seqs.length; i++) + for (int i = 0; i < command.getEdit(0).seqs.length; i++) { - if (edits[0].seqs[i] != command.edits[0].seqs[i]) + if (getEdit(0).seqs[i] != command.getEdit(0).seqs[i]) { same = false; } @@ -77,10 +85,7 @@ public class SlideSequencesCommand extends EditCommand if (same) { - Edit[] temp = new Edit[command.edits.length + 1]; - System.arraycopy(command.edits, 0, temp, 0, command.edits.length); - command.edits = temp; - command.edits[command.edits.length - 1] = edits[0]; + command.addEdit(getEdit(0)); } return same; diff --git a/src/jalview/commands/TrimRegionCommand.java b/src/jalview/commands/TrimRegionCommand.java index a757d1a..ebbe827 100644 --- a/src/jalview/commands/TrimRegionCommand.java +++ b/src/jalview/commands/TrimRegionCommand.java @@ -20,10 +20,13 @@ */ package jalview.commands; -import java.util.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.util.ShiftList; -import jalview.datamodel.*; -import jalview.util.*; +import java.util.List; public class TrimRegionCommand extends EditCommand { @@ -39,7 +42,7 @@ public class TrimRegionCommand extends EditCommand SequenceGroup selectionGroup; - Vector deletedHiddenColumns; + List deletedHiddenColumns; int columnsDeleted; @@ -59,8 +62,7 @@ public class TrimRegionCommand extends EditCommand columnsDeleted = column; - edits = new Edit[] - { new Edit(CUT, seqs, 0, column, al) }; + setEdit(new Edit(Action.CUT, seqs, 0, column, al)); } else if (command.equalsIgnoreCase(TRIM_RIGHT)) { @@ -72,17 +74,16 @@ public class TrimRegionCommand extends EditCommand columnsDeleted = width - 1; - edits = new Edit[] - { new Edit(CUT, seqs, column + 1, width, al) }; + setEdit(new Edit(Action.CUT, seqs, column + 1, width, al)); } // We need to keep a record of the sequence start // in order to restore the state after a redo - int i, isize = edits[0].seqs.length; + int i, isize = getEdit(0).seqs.length; start = new int[isize]; for (i = 0; i < isize; i++) { - start[i] = edits[0].seqs[i].getStart(); + start[i] = getEdit(0).seqs[i].getStart(); } performEdit(0, null); @@ -160,7 +161,7 @@ public class TrimRegionCommand extends EditCommand int[] region; for (int i = 0; i < deletedHiddenColumns.size(); i++) { - region = (int[]) deletedHiddenColumns.elementAt(i); + region = deletedHiddenColumns.get(i); colSel.hideColumns(region[0], region[1]); } } diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 0731991..e137225 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -75,9 +75,10 @@ public class AlignmentAnnotation public SequenceFeature[] _rnasecstr = null; /** - * position of annotation resulting in invalid WUSS parsing or -1 + * position of annotation resulting in invalid WUSS parsing or -1. -2 means + * there was no RNA structure in this annotation */ - private long invalidrnastruc = -1; + private long invalidrnastruc = -2; /** * Updates the _rnasecstr field Determines the positions that base pair and @@ -110,10 +111,47 @@ public class AlignmentAnnotation isrna = true; showAllColLabels = true; scaleColLabel = true; + _markRnaHelices(); } // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup()); + } + private void _markRnaHelices() + { + int mxval = 0; + // Figure out number of helices + // Length of rnasecstr is the number of pairs of positions that base pair + // with each other in the secondary structure + for (int x = 0; x < _rnasecstr.length; x++) + { + + /* + * System.out.println(this.annotation._rnasecstr[x] + " Begin" + + * this.annotation._rnasecstr[x].getBegin()); + */ + // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup()); + int val = 0; + try + { + val = Integer.valueOf(_rnasecstr[x].getFeatureGroup()); + if (mxval < val) + { + mxval = val; + } + } catch (NumberFormatException q) + { + } + ; + + annotations[_rnasecstr[x].getBegin()].value = val; + annotations[_rnasecstr[x].getEnd()].value = val; + + // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val; + // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val; + } + setScore(mxval); + } /** * map of positions in the associated annotation */ @@ -455,11 +493,10 @@ public class AlignmentAnnotation @Override public char charAt(int index) { - String dc; return ((index + offset < 0) || (index + offset) >= max - || annotations[index + offset] == null || (dc = annotations[index - + offset].displayCharacter.trim()).length() < 1) ? '.' : dc - .charAt(0); + || annotations[index + offset] == null || (annotations[index + + offset].secondaryStructure < ' ') ? ' ' + : annotations[index + offset].secondaryStructure); } public String toString() @@ -469,9 +506,8 @@ public class AlignmentAnnotation for (int i = offset; i < mx; i++) { - String dc; - string[i] = (annotations[i] == null || (dc = annotations[i].displayCharacter - .trim()).length() < 1) ? '.' : dc.charAt(0); + string[i] = (annotations[i] == null || (annotations[i].secondaryStructure < 32)) ? ' ' + : annotations[i].secondaryStructure; } return new String(string); } diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 35d467a..f414d13 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -20,9 +20,12 @@ */ package jalview.datamodel; -import java.util.*; +import jalview.util.ShiftList; -import jalview.util.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; /** * NOTE: Columns are zero based. @@ -186,9 +189,9 @@ public class ColumnSelection * @param left * shift in edit (+ve for removal, or -ve for inserts) */ - public Vector compensateForEdit(int start, int change) + public List compensateForEdit(int start, int change) { - Vector deletedHiddenColumns = null; + List deletedHiddenColumns = null; for (int i = 0; i < size(); i++) { int temp = columnAt(i); @@ -201,14 +204,14 @@ public class ColumnSelection if (hiddenColumns != null) { - deletedHiddenColumns = new Vector(); + deletedHiddenColumns = new ArrayList(); int hSize = hiddenColumns.size(); for (int i = 0; i < hSize; i++) { int[] region = (int[]) hiddenColumns.elementAt(i); if (region[0] > start && start + change > region[1]) { - deletedHiddenColumns.addElement(hiddenColumns.elementAt(i)); + deletedHiddenColumns.add(region); hiddenColumns.removeElementAt(i); i--; @@ -752,6 +755,7 @@ public class ColumnSelection public boolean isVisible(int column) { if (hiddenColumns != null) + { for (int i = 0; i < hiddenColumns.size(); i++) { int[] region = (int[]) hiddenColumns.elementAt(i); @@ -760,6 +764,7 @@ public class ColumnSelection return false; } } + } return true; } @@ -1018,7 +1023,9 @@ public class ColumnSelection w += els.length; } if (w == 0) + { return; + } Enumeration e = annels.elements(); alignmentAnnotation.annotations = new Annotation[w]; w = 0; diff --git a/src/jalview/exceptions/JalviewException.java b/src/jalview/exceptions/JalviewException.java new file mode 100644 index 0000000..80e0b08 --- /dev/null +++ b/src/jalview/exceptions/JalviewException.java @@ -0,0 +1,25 @@ +package jalview.exceptions; + +@SuppressWarnings("serial") +public class JalviewException extends Exception +{ + public JalviewException(String exceptionMessage) + { + super(exceptionMessage); + } + + public JalviewException() + { + super(); + } + + public JalviewException(String exceptionMessage, Throwable cause) + { + super(exceptionMessage, cause); + } + + public JalviewException(Throwable cause) + { + super(cause); + } +} diff --git a/src/jalview/exceptions/NoFileSelectedException.java b/src/jalview/exceptions/NoFileSelectedException.java new file mode 100644 index 0000000..5c56f47 --- /dev/null +++ b/src/jalview/exceptions/NoFileSelectedException.java @@ -0,0 +1,10 @@ +package jalview.exceptions; + +@SuppressWarnings("serial") +public class NoFileSelectedException extends JalviewException +{ + public NoFileSelectedException(String msg) + { + super(msg); + } +} diff --git a/src/jalview/ext/jmol/PDBFileWithJmol.java b/src/jalview/ext/jmol/PDBFileWithJmol.java index 9fa6bf4..f5710d3 100644 --- a/src/jalview/ext/jmol/PDBFileWithJmol.java +++ b/src/jalview/ext/jmol/PDBFileWithJmol.java @@ -186,9 +186,12 @@ public class PDBFileWithJmol extends AlignFile implements seqs.add(sq); if (!isNa) { + String mt = model.getModelTitle() == null ? getDataName() + : model.getModelTitle(); + mt += _lastChainId; AlignmentAnnotation ann = new AlignmentAnnotation( "Secondary Structure", - "Secondary Structure from PDB File", asecstr); + "Secondary Structure for " + mt, asecstr); ann.belowAlignment=true; ann.visible=true; ann.autoCalculated=false; diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 090b61d..fb03f04 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -343,8 +343,7 @@ public abstract class JalviewChimeraBinding extends public void colourByChain() { colourBySequence = false; - // this is not a valid Chimera command; is there one? Menu option hidden - evalStateCommand("select *;color chain",false); + evalStateCommand("rainbow chain", false); } public void colourByCharge() diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 684e7ac..04df3d6 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -34,6 +34,7 @@ import jalview.api.analysis.ScoreModelI; import jalview.bin.Cache; import jalview.commands.CommandI; import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; import jalview.commands.OrderCommand; import jalview.commands.RemoveGapColCommand; import jalview.commands.RemoveGapsCommand; @@ -53,6 +54,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AlignmentProperties; import jalview.io.AnnotationFile; +import jalview.io.BioJsHTMLOutput; import jalview.io.FeaturesFile; import jalview.io.FileLoader; import jalview.io.FormatAdapter; @@ -1231,6 +1233,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); } + @Override + public void bioJSMenuItem_actionPerformed(ActionEvent e) + { + new BioJsHTMLOutput(alignPanel, + alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); + } public void createImageMap(File file, String image) { alignPanel.makePNGImageMap(file, image); @@ -1410,7 +1418,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (viewport.historyList.size() > 0) { undoMenuItem.setEnabled(true); - CommandI command = (CommandI) viewport.historyList.peek(); + CommandI command = viewport.historyList.peek(); undoMenuItem.setText(MessageManager.formatMessage( "label.undo_command", new String[] { command.getDescription() })); @@ -1425,7 +1433,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { redoMenuItem.setEnabled(true); - CommandI command = (CommandI) viewport.redoList.peek(); + CommandI command = viewport.redoList.peek(); redoMenuItem.setText(MessageManager.formatMessage( "label.redo_command", new String[] { command.getDescription() })); @@ -1489,7 +1497,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { return; } - CommandI command = (CommandI) viewport.historyList.pop(); + CommandI command = viewport.historyList.pop(); viewport.redoList.push(command); command.undoCommand(getViewAlignments()); @@ -1528,7 +1536,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - CommandI command = (CommandI) viewport.redoList.pop(); + CommandI command = viewport.redoList.pop(); viewport.historyList.push(command); command.doCommand(getViewAlignments()); @@ -1990,7 +1998,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // ///// // ADD HISTORY ITEM // - addHistoryItem(new EditCommand(MessageManager.getString("label.add_sequences"), EditCommand.PASTE, + addHistoryItem(new EditCommand( + MessageManager.getString("label.add_sequences"), + Action.PASTE, sequences, 0, alignment.getWidth(), alignment)); } // Add any annotations attached to sequences @@ -2261,8 +2271,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* * //ADD HISTORY ITEM */ - addHistoryItem(new EditCommand(MessageManager.getString("label.cut_sequences"), EditCommand.CUT, cut, - sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, + addHistoryItem(new EditCommand( + MessageManager.getString("label.cut_sequences"), Action.CUT, + cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, viewport.getAlignment())); viewport.setSelectionGroup(null); @@ -5797,7 +5808,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, aa.visible = visible; } } - this.alignPanel.paintAlignment(true); + alignPanel.validateAnnotationDimensions(false); + alignPanel.alignmentChanged(); } /** diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 5c383d8..632d2b2 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -42,9 +42,8 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.NJTree; import jalview.api.AlignViewportI; import jalview.bin.Cache; -import jalview.datamodel.AlignmentAnnotation; +import jalview.commands.CommandI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; @@ -130,7 +129,7 @@ public class AlignViewport extends AlignmentViewport implements * Keys are the feature types which are currently visible. Note: Values are * not used! */ - Hashtable featuresDisplayed = null; + private Hashtable featuresDisplayed = null; boolean antiAlias = false; @@ -140,9 +139,9 @@ public class AlignViewport extends AlignmentViewport implements boolean gatherViewsHere = false; - Stack historyList = new Stack(); + Stack historyList = new Stack(); - Stack redoList = new Stack(); + Stack redoList = new Stack(); int thresholdTextColour = 0; @@ -337,10 +336,6 @@ public class AlignViewport extends AlignmentViewport implements false); showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false); showConsensus = Cache.getDefault("SHOW_IDENTITY", true); - consensus = new AlignmentAnnotation("Consensus", "PID", - new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); - consensus.hasText = true; - consensus.autoCalculated = true; } initAutoAnnotation(); if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null) @@ -1279,6 +1274,16 @@ public class AlignViewport extends AlignmentViewport implements } } + + public Hashtable getFeaturesDisplayed() + { + return featuresDisplayed; + } + + public void setFeaturesDisplayed(Hashtable featuresDisplayed) + { + this.featuresDisplayed = featuresDisplayed; + } protected SequenceAnnotationOrder getSortAnnotationsBy() { return sortAnnotationsBy; diff --git a/src/jalview/gui/AnnotationExporter.java b/src/jalview/gui/AnnotationExporter.java index 315c3e2..ecf4b8e 100644 --- a/src/jalview/gui/AnnotationExporter.java +++ b/src/jalview/gui/AnnotationExporter.java @@ -210,11 +210,11 @@ public class AnnotationExporter extends JPanel private Hashtable getDisplayedFeatureCols() { Hashtable fcols = new Hashtable(); - if (ap.av.featuresDisplayed == null) + if (ap.av.getFeaturesDisplayed() == null) { return fcols; } - Enumeration en = ap.av.featuresDisplayed.keys(); + Enumeration en = ap.av.getFeaturesDisplayed().keys(); FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider // higher // level diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index ad6f9e5..6e8417f 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -478,20 +478,29 @@ public class AnnotationLabels extends JPanel implements MouseListener, { desc.append("
    "); } - + // if (aa.hasProperties()) + // { + // desc.append(""); + // for (String prop : aa.getProperties()) + // { + // desc.append(""); + // } + // desc.append("
    " + prop + "" + // + aa.getProperty(prop) + "
    "); + // } } else { // begin the tooltip's html fragment desc.append(""); + if (aa.hasScore()) + { + // TODO: limit precision of score to avoid noise from imprecise + // doubles + // (64.7 becomes 64.7+/some tiny value). + desc.append(" Score: " + aa.score); + } } - if (aa.hasScore()) - { - // TODO: limit precision of score to avoid noise from imprecise doubles - // (64.7 becomes 64.7+/some tiny value). - desc.append(" Score: " + aa.score); - } - if (desc.length() > 6) { desc.append(""); @@ -502,7 +511,6 @@ public class AnnotationLabels extends JPanel implements MouseListener, this.setToolTipText(null); } } - } /** diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 4adeb83..9f56206 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -20,17 +20,43 @@ */ package jalview.gui; -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; - -import javax.swing.*; - -import jalview.datamodel.*; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Annotation; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SequenceI; import jalview.renderer.AnnotationRenderer; import jalview.renderer.AwtRenderPanelI; import jalview.util.MessageManager; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.awt.image.BufferedImage; + +import javax.swing.JColorChooser; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.Scrollable; +import javax.swing.SwingUtilities; +import javax.swing.ToolTipManager; + /** * AnnotationPanel displays visible portion of annotation rows below unwrapped * alignment @@ -289,7 +315,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int index = av.getColumnSelection().columnAt(i); if (!av.getColumnSelection().isVisible(index)) + { continue; + } if (anot[index] == null) { @@ -314,7 +342,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int index = av.getColumnSelection().columnAt(i); if (!av.getColumnSelection().isVisible(index)) + { continue; + } if (anot[index] == null) { @@ -373,14 +403,18 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int index = av.getColumnSelection().columnAt(i); if (!av.getColumnSelection().isVisible(index)) + { continue; + } if (anot[index] == null) { anot[index] = new Annotation(label, "", type, 0); } - anot[index].secondaryStructure = type; + + anot[index].secondaryStructure = type != 'S' ? type : label + .length() == 0 ? ' ' : label.charAt(0); anot[index].displayCharacter = label; } @@ -406,7 +440,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int index = columnSelection.columnAt(i); // always check for current display state - just in case if (!viscols.isVisible(index)) + { continue; + } String tlabel = null; if (anot[index] != null) { // LML added stem code @@ -765,7 +801,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; if (imgWidth < 1) + { return; + } if (image == null || imgWidth != image.getWidth(this) || image.getHeight(this) != getHeight()) { @@ -984,6 +1022,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return bounds; } else + { return null; + } } } diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index cfac4ef..02865e1 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -144,9 +144,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, _alignwith = new Vector(); } - // no colour by chain command in Chimera? - chainColour.setVisible(false); - // save As not yet implemented savemenu.setVisible(false); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 19dbcdb..007fefd 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -2605,7 +2605,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements + ermsg + "" + "

    It may be that you have invalid JABA URLs
    in your web service preferences," - + " or mis-configured HTTP proxy settings.

    " + + "
    or as a command-line argument, or mis-configured HTTP proxy settings.

    " + "

    Check the Connections and Web services tab
    of the" + " Tools->Preferences dialog box to change them.

    "), "Web Service Configuration Problem", diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index d2d9c9c..fe083b0 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -192,20 +192,20 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer // copy over the displayed feature settings if (fr.av != null) { - if (fr.av.featuresDisplayed != null) + if (fr.av.getFeaturesDisplayed() != null) { // update display settings - if (av.featuresDisplayed == null) + if (av.getFeaturesDisplayed() == null) { - av.featuresDisplayed = new Hashtable(fr.av.featuresDisplayed); + av.setFeaturesDisplayed(new Hashtable(fr.av.getFeaturesDisplayed())); } else { - av.featuresDisplayed.clear(); - Enumeration en = fr.av.featuresDisplayed.keys(); + av.getFeaturesDisplayed().clear(); + Enumeration en = fr.av.getFeaturesDisplayed().keys(); while (en.hasMoreElements()) { - av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE); + av.getFeaturesDisplayed().put(en.nextElement(), Boolean.TRUE); } } @@ -349,11 +349,11 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer fm = g.getFontMetrics(); } - if (av.featuresDisplayed == null || renderOrder == null + if (av.getFeaturesDisplayed() == null || renderOrder == null || newFeatureAdded) { findAllFeatures(); - if (av.featuresDisplayed.size() < 1) + if (av.getFeaturesDisplayed().size() < 1) { return; } @@ -388,7 +388,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { type = renderOrder[renderIndex]; - if (type == null || !av.featuresDisplayed.containsKey(type)) + if (type == null || !av.getFeaturesDisplayed().containsKey(type)) { continue; } @@ -682,9 +682,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer findingFeatures = true; - if (av.featuresDisplayed == null) + if (av.getFeaturesDisplayed() == null) { - av.featuresDisplayed = new Hashtable(); + av.setFeaturesDisplayed(new Hashtable()); } allfeatures = new Vector(); @@ -717,7 +717,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer int index = 0; while (index < features.length) { - if (!av.featuresDisplayed.containsKey(features[index].getType())) + if (!av.getFeaturesDisplayed().containsKey(features[index].getType())) { if (featureGroups.containsKey(features[index].getType())) @@ -742,7 +742,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { // this is a new feature type on the alignment. Mark it for // display. - av.featuresDisplayed.put(features[index].getType(), + av.getFeaturesDisplayed().put(features[index].getType(), new Integer(getColour(features[index].getType()) .getRGB())); setOrder(features[index].getType(), 0); @@ -1253,7 +1253,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer sf.description = lastDescriptionAdded; setColour(sf.type, fcol); - av.featuresDisplayed.put(sf.type, getColour(sf.type)); + av.getFeaturesDisplayed().put(sf.type, getColour(sf.type)); try { @@ -1281,9 +1281,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer ffile.parseDescriptionHTML(features[i], false); } - if (av.featuresDisplayed == null) + if (av.getFeaturesDisplayed() == null) { - av.featuresDisplayed = new Hashtable(); + av.setFeaturesDisplayed(new Hashtable()); } if (lastFeatureGroupAdded != null) @@ -1293,7 +1293,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer featureGroups.put(lastFeatureGroupAdded, new Boolean(true)); } setColour(lastFeatureAdded, fcol); - av.featuresDisplayed.put(lastFeatureAdded, + av.getFeaturesDisplayed().put(lastFeatureAdded, getColour(lastFeatureAdded)); findAllFeatures(false); @@ -1386,13 +1386,13 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { if (visibleNew) { - if (av.featuresDisplayed != null) + if (av.getFeaturesDisplayed() != null) { - av.featuresDisplayed.clear(); + av.getFeaturesDisplayed().clear(); } else { - av.featuresDisplayed = new Hashtable(); + av.setFeaturesDisplayed(new Hashtable()); } } if (data == null) @@ -1414,7 +1414,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer // interface object if (((Boolean) data[i][2]).booleanValue()) { - av.featuresDisplayed.put(type, new Integer(getColour(type) + av.getFeaturesDisplayed().put(type, new Integer(getColour(type) .getRGB())); } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 2210148..8f841d1 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -222,7 +222,7 @@ public class FeatureSettings extends JPanel dassourceBrowser = new DasSourceBrowser(this); dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER); - if (af.getViewport().featuresDisplayed == null + if (af.getViewport().getFeaturesDisplayed() == null || fr.renderOrder == null) { fr.findAllFeatures(true); // display everything! @@ -645,7 +645,7 @@ public class FeatureSettings extends JPanel data[dataIndex][0] = type; data[dataIndex][1] = fr.getFeatureStyle(type); data[dataIndex][2] = new Boolean( - af.getViewport().featuresDisplayed.containsKey(type)); + af.getViewport().getFeaturesDisplayed().containsKey(type)); dataIndex++; visibleChecks.removeElement(type); } @@ -1277,7 +1277,7 @@ public class FeatureSettings extends JPanel System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length); for (int i = 0; i < typ.length; i++) { - if (af.viewport.featuresDisplayed.get(typ[i]) == null) + if (af.viewport.getFeaturesDisplayed().get(typ[i]) == null) { typ[i] = null; } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index b608b95..158ae50 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1145,7 +1145,7 @@ public class Jalview2XML view.setFollowHighlight(av.followHighlight); view.setFollowSelection(av.followSelection); view.setIgnoreGapsinConsensus(av.getIgnoreGapsConsensus()); - if (av.featuresDisplayed != null) + if (av.getFeaturesDisplayed() != null) { jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings(); @@ -1180,7 +1180,7 @@ public class Jalview2XML .getColour(renderOrder[ro]).getRGB()); } - setting.setDisplay(av.featuresDisplayed + setting.setDisplay(av.getFeaturesDisplayed() .containsKey(renderOrder[ro])); float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer() .getOrder(renderOrder[ro]); @@ -3604,7 +3604,7 @@ public class Jalview2XML // recover featre settings if (jms.getFeatureSettings() != null) { - af.viewport.featuresDisplayed = new Hashtable(); + af.viewport.setFeaturesDisplayed(new Hashtable()); String[] renderOrder = new String[jms.getFeatureSettings() .getSettingCount()]; for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++) @@ -3656,7 +3656,7 @@ public class Jalview2XML } if (setting.getDisplay()) { - af.viewport.featuresDisplayed.put(setting.getType(), new Integer( + af.viewport.getFeaturesDisplayed().put(setting.getType(), new Integer( setting.getColour())); } } diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 9263cd9..3773a64 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -415,7 +415,7 @@ public class Jalview2XML_V1 if (jms.getFeatureSettings() != null) { - af.viewport.featuresDisplayed = new Hashtable(); + af.viewport.setFeaturesDisplayed(new Hashtable()); String[] renderOrder = new String[jms.getFeatureSettings() .getSettingCount()]; for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++) @@ -429,7 +429,7 @@ public class Jalview2XML_V1 if (setting.getDisplay()) { - af.viewport.featuresDisplayed.put(setting.getType(), new Integer( + af.viewport.getFeaturesDisplayed().put(setting.getType(), new Integer( setting.getColour())); } } diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index d546584..e433243 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -53,14 +53,14 @@ public final class JvSwingUtils */ public static String wrapTooltip(boolean enclose, String ttext) { - if (ttext.length() < 60) { - return enclose ? ""+ttext+"" : ttext; + return enclose ? "" + ttext + "" : ttext; } else { - return (enclose ? "" : "") + "
    " + ttext + return (enclose ? "" : "") + + "
    " + ttext + "
    " + ((enclose ? "" : "")); } } diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index dcddf88..69b6ba6 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -20,14 +20,16 @@ */ package jalview.gui; -import java.util.*; -import java.awt.event.*; - -import jalview.analysis.*; -import jalview.datamodel.*; -import jalview.jbgui.*; +import jalview.analysis.AlignSeq; +import jalview.datamodel.Alignment; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; +import jalview.jbgui.GPairwiseAlignPanel; import jalview.util.MessageManager; +import java.awt.event.ActionEvent; +import java.util.Vector; + /** * DOCUMENT ME! * @@ -97,13 +99,8 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel totscore = totscore + scores[i][j]; textarea.append(as.getOutput()); - seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1() - .getStart(), as.getS1().getEnd()); - sequences.add(seq); - - seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2() - .getStart(), as.getS2().getEnd()); - sequences.add(seq); + sequences.add(as.getAlignedSeq1()); + sequences.add(as.getAlignedSeq1()); } } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 1c7be46..9976471 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -25,6 +25,7 @@ import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.Conservation; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.DBRefEntry; @@ -372,12 +373,12 @@ public class PopupMenu extends JPopupMenu { AlignmentAnnotation[] aa = ap.av.getAlignment() .getAlignmentAnnotation(); - for (int i = 0; i < aa.length; i++) + for (int i = 0; aa != null && i < aa.length; i++) { - if (aa[i].getRNAStruc() != null) + if (aa[i].isValidStruc() && aa[i].sequenceRef == null) { final String rnastruc = aa[i].getRNAStruc(); - final String structureLine = aa[i].label; + final String structureLine = aa[i].label + " (alignment)"; menuItem = new JMenuItem(); menuItem.setText(MessageManager.formatMessage( "label.2d_rna_structure_line", new String[] @@ -387,15 +388,15 @@ public class PopupMenu extends JPopupMenu @Override public void actionPerformed(ActionEvent e) { - // System.out.println("1:"+structureLine); - System.out.println("1:sname" + seq.getName()); - System.out.println("2:seq" + seq); - - // System.out.println("3:"+seq.getSequenceAsString()); - System.out.println("3:strucseq" + rnastruc); - // System.out.println("4:struc"+seq.getRNA()); - System.out.println("5:name" + seq.getName()); - System.out.println("6:ap" + ap); + // // System.out.println("1:"+structureLine); + // System.out.println("1:sname" + seq.getName()); + // System.out.println("2:seq" + seq); + // + // // System.out.println("3:"+seq.getSequenceAsString()); + // System.out.println("3:strucseq" + rnastruc); + // // System.out.println("4:struc"+seq.getRNA()); + // System.out.println("5:name" + seq.getName()); + // System.out.println("6:ap" + ap); new AppVarna(structureLine, seq, seq.getSequenceAsString(), rnastruc, seq.getName(), ap); // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(), @@ -414,7 +415,7 @@ public class PopupMenu extends JPopupMenu AlignmentAnnotation seqAnno[] = seq.getAnnotation(); for (int i = 0; i < seqAnno.length; i++) { - if (seqAnno[i].getRNAStruc() != null) + if (seqAnno[i].isValidStruc()) { final String rnastruc = seqAnno[i].getRNAStruc(); @@ -2707,7 +2708,7 @@ public class PopupMenu extends JPopupMenu { EditCommand editCommand = new EditCommand( MessageManager.getString("label.edit_sequences"), - EditCommand.REPLACE, dialog.getName().replace(' ', + Action.REPLACE, dialog.getName().replace(' ', ap.av.getGapCharacter()), sg.getSequencesAsArray(ap.av.getHiddenRepSequences()), sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment()); diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 0e55cf8..ab0a0b8 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -20,18 +20,28 @@ */ package jalview.gui; -import java.util.*; - -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; - import jalview.analysis.AlignSeq; -import jalview.commands.*; -import jalview.datamodel.*; -import jalview.jbgui.*; +import jalview.commands.CommandI; +import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.jbgui.GSliderPanel; import jalview.util.MessageManager; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import java.util.Vector; + +import javax.swing.JInternalFrame; +import javax.swing.JProgressBar; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; + /** * DOCUMENT ME! * @@ -44,7 +54,9 @@ public class RedundancyPanel extends GSliderPanel implements Runnable AlignmentPanel ap; - Stack historyList = new Stack(); // simpler than synching with alignFrame. + Stack historyList = new Stack(); + + // simpler than synching with alignFrame. float[] redundancy; @@ -229,7 +241,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable } EditCommand cut = new EditCommand(MessageManager.getString("action.remove_redundancy"), - EditCommand.CUT, deleted, 0, width, ap.av.getAlignment()); + Action.CUT, deleted, 0, width, ap.av.getAlignment()); for (int i = 0; i < del.size(); i++) { @@ -263,7 +275,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable return; } - CommandI command = (CommandI) historyList.pop(); + CommandI command = historyList.pop(); if (ap.av.historyList.contains(command)) { command.undoCommand(af.getViewAlignments()); diff --git a/src/jalview/gui/SVGOptions.java b/src/jalview/gui/SVGOptions.java new file mode 100644 index 0000000..b5e194b --- /dev/null +++ b/src/jalview/gui/SVGOptions.java @@ -0,0 +1,163 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview 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 3 + * of the License, or (at your option) any later version. + * + * Jalview 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 Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.gui; + +import jalview.util.MessageManager; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +public class SVGOptions extends JPanel +{ + JDialog dialog; + + public boolean cancelled = false; + + String value; + + public SVGOptions() + { + try + { + jbInit(); + } catch (Exception ex) + { + ex.printStackTrace(); + } + + ButtonGroup bg = new ButtonGroup(); + bg.add(lineart); + bg.add(text); + + JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION, + JOptionPane.DEFAULT_OPTION, null, new Object[] + { this }); + + dialog = pane.createDialog(Desktop.desktop, "SVG Rendering options"); + dialog.setVisible(true); + + } + + private void jbInit() throws Exception + { + lineart.setFont(JvSwingUtils.getLabelFont()); + lineart.setText(MessageManager.getString("label.lineart")); + text.setFont(JvSwingUtils.getLabelFont()); + text.setText(MessageManager.getString("action.text")); + text.setSelected(true); + askAgain.setFont(JvSwingUtils.getLabelFont()); + askAgain.setText(MessageManager.getString("label.dont_ask_me_again")); + ok.setText(MessageManager.getString("action.ok")); + ok.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setText(MessageManager.getString("action.cancel")); + cancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + jLabel1.setFont(JvSwingUtils.getLabelFont()); + jLabel1.setText("Select SVG character rendering style"); + this.setLayout(borderLayout1); + jPanel3.setBorder(BorderFactory.createEtchedBorder()); + jPanel2.add(text); + jPanel2.add(lineart); + jPanel2.add(askAgain); + jPanel1.add(ok); + jPanel1.add(cancel); + jPanel3.add(jLabel1); + jPanel3.add(jPanel2); + this.add(jPanel3, java.awt.BorderLayout.CENTER); + this.add(jPanel1, java.awt.BorderLayout.SOUTH); + } + + JRadioButton lineart = new JRadioButton(); + + JRadioButton text = new JRadioButton(); + + JCheckBox askAgain = new JCheckBox(); + + JButton ok = new JButton(); + + JButton cancel = new JButton(); + + JPanel jPanel1 = new JPanel(); + + JLabel jLabel1 = new JLabel(); + + JPanel jPanel2 = new JPanel(); + + JPanel jPanel3 = new JPanel(); + + BorderLayout borderLayout1 = new BorderLayout(); + + public void ok_actionPerformed(ActionEvent e) + { + if (lineart.isSelected()) + { + value = "Lineart"; + } + else + { + value = "Text"; + } + + if (!askAgain.isSelected()) + { + jalview.bin.Cache.applicationProperties.remove("SVG_RENDERING"); + } + else + { + jalview.bin.Cache.setProperty("SVG_RENDERING", value); + } + + dialog.setVisible(false); + } + + public void cancel_actionPerformed(ActionEvent e) + { + cancelled = true; + dialog.setVisible(false); + } + + public String getValue() + { + return value; + } +} diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index d5b81f1..d73ee70 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -20,11 +20,22 @@ */ package jalview.gui; -import java.awt.*; -import java.awt.image.*; -import javax.swing.*; - -import jalview.datamodel.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; + +import java.awt.BasicStroke; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.image.BufferedImage; + +import javax.swing.JComponent; /** * DOCUMENT ME! @@ -247,16 +258,11 @@ public class SeqCanvas extends JComponent */ public void fastPaint(int horizontal, int vertical) { - if (fastpainting) + if (fastpainting || gg == null) { return; } fastpainting = true; - if (gg == null) - { - return; - } - fastPaint = true; gg.copyArea(horizontal * av.charWidth, vertical * av.charHeight, @@ -575,7 +581,7 @@ public class SeqCanvas extends JComponent annotations = new AnnotationPanel(av); } - annotations.renderer.drawComponent(annotations, av, (Graphics2D) g, + annotations.renderer.drawComponent(annotations, av, g, -1, startRes, endx + 1); g.translate(0, -cHeight - ypos - 3); } @@ -763,7 +769,7 @@ public class SeqCanvas extends JComponent if ((group == null) && (av.getAlignment().getGroups().size() > 0)) { - group = (SequenceGroup) av.getAlignment().getGroups().get(0); + group = av.getAlignment().getGroups().get(0); groupIndex = 0; } @@ -924,7 +930,7 @@ public class SeqCanvas extends JComponent break; } - group = (SequenceGroup) av.getAlignment().getGroups() + group = av.getAlignment().getGroups() .get(groupIndex); } while (groupIndex < av.getAlignment().getGroups().size()); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 61782b4..5d3df1a 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SearchResults; import jalview.datamodel.Sequence; @@ -112,7 +113,7 @@ public class SeqPanel extends JPanel implements MouseListener, private final SequenceAnnotationReport seqARep; - StringBuffer tooltipText = new StringBuffer(""); + StringBuffer tooltipText = new StringBuffer(); String tmpString; @@ -250,8 +251,9 @@ public class SeqPanel extends JPanel implements MouseListener, { for (int i = 0; i < features.length; i++) { - if (av.featuresDisplayed == null - || !av.featuresDisplayed.containsKey(features[i].getType())) + if (av.getFeaturesDisplayed() == null + || !av.getFeaturesDisplayed().containsKey( + features[i].getType())) { continue; } @@ -727,11 +729,6 @@ public class SeqPanel extends JPanel implements MouseListener, { if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res) { - if (tooltipText.length() > 6) - { - tooltipText.append("
    "); - } - if (!groups[g].getName().startsWith("JTreeGroup") && !groups[g].getName().startsWith("JGroup")) { @@ -763,12 +760,13 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - tooltipText.append(""); if (lastTooltip == null || !lastTooltip.equals(tooltipText.toString())) { - setToolTipText(JvSwingUtils.wrapTooltip(true, - tooltipText.toString())); + String formatedTooltipText = JvSwingUtils.wrapTooltip(true, + tooltipText.toString()); + // String formatedTooltipText = tooltipText.toString(); + setToolTipText(formatedTooltipText); lastTooltip = tooltipText.toString(); } @@ -1190,7 +1188,7 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - editCommand.appendEdit(EditCommand.INSERT_GAP, groupSeqs, + editCommand.appendEdit(Action.INSERT_GAP, groupSeqs, startres, startres - lastres, av.getAlignment(), true); } } @@ -1206,7 +1204,7 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - editCommand.appendEdit(EditCommand.DELETE_GAP, groupSeqs, + editCommand.appendEdit(Action.DELETE_GAP, groupSeqs, startres, lastres - startres, av.getAlignment(), true); } @@ -1228,7 +1226,7 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[] + editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres, startres - lastres, av.getAlignment(), true); } } @@ -1265,7 +1263,7 @@ public class SeqPanel extends JPanel implements MouseListener, if (max > 0) { - editCommand.appendEdit(EditCommand.DELETE_GAP, + editCommand.appendEdit(Action.DELETE_GAP, new SequenceI[] { seq }, startres, max, av.getAlignment(), true); } @@ -1283,7 +1281,7 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - editCommand.appendEdit(EditCommand.INSERT_NUC, new SequenceI[] + editCommand.appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres, startres - lastres, av.getAlignment(), true); } } @@ -1319,10 +1317,10 @@ public class SeqPanel extends JPanel implements MouseListener, } } - editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1, + editCommand.appendEdit(Action.DELETE_GAP, seq, blankColumn, 1, av.getAlignment(), true); - editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1, + editCommand.appendEdit(Action.INSERT_GAP, seq, j, 1, av.getAlignment(), true); } @@ -1330,10 +1328,10 @@ public class SeqPanel extends JPanel implements MouseListener, void deleteChar(int j, SequenceI[] seq, int fixedColumn) { - editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1, + editCommand.appendEdit(Action.DELETE_GAP, seq, j, 1, av.getAlignment(), true); - editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1, + editCommand.appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1, av.getAlignment(), true); } diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 00d9c79..4a74c9c 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -956,7 +956,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { Vector services = new Vector(); services.addElement(args[p++]); - Jws2Discoverer.setServiceUrls(services); + Jws2Discoverer.getDiscoverer().setServiceUrls(services); } try { diff --git a/src/jalview/gui/WsPreferences.java b/src/jalview/gui/WsPreferences.java index 0674352..527750c 100644 --- a/src/jalview/gui/WsPreferences.java +++ b/src/jalview/gui/WsPreferences.java @@ -33,6 +33,7 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URL; +import java.util.List; import java.util.Vector; import javax.swing.JLabel; @@ -52,7 +53,9 @@ public class WsPreferences extends GWsPreferences initFromPreferences(); } - Vector wsUrls, oldUrls, rsbsUrls, oldRsbsUrls; + List wsUrls; + + Vector oldUrls, rsbsUrls, oldRsbsUrls; private boolean needWsMenuUpdate; @@ -62,8 +65,8 @@ public class WsPreferences extends GWsPreferences private void initFromPreferences() { - wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls(); - if (wsUrls != null) + wsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls(); + if (!wsUrls.isEmpty()) { oldUrls = new Vector(wsUrls); } @@ -235,7 +238,7 @@ public class WsPreferences extends GWsPreferences private void updateServiceList() { - jalview.ws.jws2.Jws2Discoverer.setServiceUrls(wsUrls); + Jws2Discoverer.getDiscoverer().setServiceUrls(wsUrls); } private void updateRsbsServiceList() @@ -256,7 +259,7 @@ public class WsPreferences extends GWsPreferences int sel = wsList.getSelectedRow(); if (sel > -1) { - wsUrls.removeElementAt(sel); + wsUrls.remove(sel); update++; updateList(); } @@ -274,21 +277,22 @@ public class WsPreferences extends GWsPreferences int sel = wsList.getSelectedRow(); if (sel > -1) { - String url = editUrl(wsUrls.elementAt(sel), MessageManager.getString("label.edit_jabaws_url")); + String url = editUrl(wsUrls.get(sel), + MessageManager.getString("label.edit_jabaws_url")); if (url != null) { int present = wsUrls.indexOf(url); if (present == -1) { update++; - wsUrls.setElementAt(url, sel); + wsUrls.set(sel, url); updateList(); } else { if (present != sel) { - wsUrls.removeElementAt(sel); + wsUrls.remove(sel); updateList(); } } @@ -406,8 +410,8 @@ public class WsPreferences extends GWsPreferences if (p > -1 && p < wsUrls.size() - 1) { String t = wsUrls.get(p + 1); - wsUrls.setElementAt(wsUrls.elementAt(p), p + 1); - wsUrls.setElementAt(t, p); + wsUrls.set(p + 1, wsUrls.get(p)); + wsUrls.set(p, t); updateList(); wsList.getSelectionModel().setSelectionInterval(p + 1, p + 1); update++; @@ -428,8 +432,8 @@ public class WsPreferences extends GWsPreferences if (p > 0) { String t = wsUrls.get(p - 1); - wsUrls.setElementAt(wsUrls.elementAt(p), p - 1); - wsUrls.setElementAt(t, p); + wsUrls.set(p - 1, wsUrls.get(p)); + wsUrls.set(p, t); updateList(); wsList.getSelectionModel().setSelectionInterval(p - 1, p - 1); update++; @@ -487,7 +491,7 @@ public class WsPreferences extends GWsPreferences if (validate == JOptionPane.OK_OPTION) { - if (jalview.ws.jws2.Jws2Discoverer.testServiceUrl(foo)) + if (Jws2Discoverer.testServiceUrl(foo)) { return foo.toString(); } @@ -544,11 +548,11 @@ public class WsPreferences extends GWsPreferences int selind = wsList.getSelectedRow(); if (selind > -1) { - wsUrls.insertElementAt(url, selind); + wsUrls.add(selind, url); } else { - wsUrls.addElement(url); + wsUrls.add(url); } update++; updateList(); @@ -651,8 +655,8 @@ public class WsPreferences extends GWsPreferences @Override protected void resetWs_actionPerformed(ActionEvent e) { - jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null); - Vector nwsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls(); + Jws2Discoverer.getDiscoverer().setServiceUrls(null); + List nwsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls(); if (!wsUrls.equals(nwsUrls)) { update++; diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index d3b19fa..505f609 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -47,7 +47,9 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", - "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC }; // , "SimpleBLAST" }; + "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, "HTML" }; // , + // "SimpleBLAST" + // }; /** * List of valid format strings for use by callers of the formatSequences @@ -79,7 +81,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "jar,jvp", "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT }; // ".blast" + "jar,jvp", "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, + "html" }; // ".blast" /** * List of readable formats by application in order corresponding to @@ -87,7 +90,7 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Jalview", - "Stockholm", "RNAML", PhylipFile.FILE_DESC };// , + "Stockholm", "RNAML", PhylipFile.FILE_DESC, "HTML" };// , // "SimpleBLAST" // }; @@ -109,7 +112,7 @@ public class AppletFormatAdapter for (int i = 0, iSize = els.length - 1; i < iSize; i++) { list.append(els[i]); - list.append(","); + list.append(", "); } list.append(" and " + els[els.length - 1] + "."); return list.toString(); @@ -268,6 +271,10 @@ public class AppletFormatAdapter { afile = new PhylipFile(inFile, type); } + // else if (format.equals(HtmlFile.FILE_DESC)) + // { + // afile = new HtmlFile(inFile, type); + // } else if (format.equals("RNAML")) { afile = new RnamlFile(inFile, type); @@ -392,6 +399,10 @@ public class AppletFormatAdapter { afile = new PhylipFile(source); } + // else if (format.equals(HtmlFile.FILE_DESC)) + // { + // afile = new HtmlFile(source); + // } Alignment al = new Alignment(afile.getSeqsAsArray()); afile.addAnnotations(al); @@ -527,6 +538,10 @@ public class AppletFormatAdapter { afile = new PhylipFile(); } + // else if (format.equalsIgnoreCase(HtmlFile.FILE_DESC)) + // { + // afile = new HtmlFile(); + // } else if (format.equalsIgnoreCase("RNAML")) { afile = new RnamlFile(); diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java new file mode 100644 index 0000000..772337a --- /dev/null +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -0,0 +1,221 @@ +package jalview.io; + +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.exceptions.NoFileSelectedException; +import jalview.gui.AlignViewport; +import jalview.gui.AlignmentPanel; +import jalview.gui.FeatureRenderer; +import jalview.json.binding.v1.BioJsAlignmentPojo; +import jalview.json.binding.v1.BioJsFeaturePojo; +import jalview.json.binding.v1.BioJsSeqPojo; +import jalview.schemes.ColourSchemeProperty; +import jalview.util.MessageManager; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.Hashtable; + +import com.json.JSONException; + +public class BioJsHTMLOutput +{ + private AlignViewport av; + + private FeatureRenderer fr; + + private String globalColorScheme; + + private Hashtable displayedFeatures; + + private String jalviewVersion; + + private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp"; + + public BioJsHTMLOutput(AlignmentPanel ap, + FeatureRenderer fr1) + { + + jalviewVersion = jalview.bin.Cache.getProperty("VERSION"); + webStartLaunchServletUrl = jalview.bin.Cache.getDefault( + "www.jalview.org", "http://www.jalview.org") + + "/services/launchApp"; + if (ap != null) + { + this.av = ap.av; + this.globalColorScheme = ColourSchemeProperty.getColourName(av + .getGlobalColourScheme()); + this.fr = new FeatureRenderer(ap); + fr.transferSettings(fr1); + displayedFeatures = av.getFeaturesDisplayed(); + + exportJalviewAlignmentAsBioJsHtmlFile(); + } + } + + private void exportJalviewAlignmentAsBioJsHtmlFile() + { + try + { + String outputFile = getOutputFile(); + String jalviewAlignmentJson = getJalviewAlignmentAsJsonString(av + .getAlignment()); + String bioJSTemplateString = getBioJsTemplateAsString(this); + String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString + .replaceAll( +"#sequenceData#", jalviewAlignmentJson) + .toString(); + + PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter( + outputFile)); + out.print(generatedBioJsWithJalviewAlignmentAsJson); + out.flush(); + out.close(); + jalview.util.BrowserLauncher.openURL("file:///" + outputFile); + } catch (NoFileSelectedException ex) + { + // do noting if no file was selected + } catch (Exception e) + { + e.printStackTrace(); + } + } + + public String getOutputFile() throws NoFileSelectedException + { + String selectedFile = null; + JalviewFileChooser jvFileChooser = new JalviewFileChooser( + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] + { "html" }, new String[] + { "HTML files" }, "HTML files"); + jvFileChooser.setFileView(new JalviewFileView()); + + // TODO uncomment when supported by MassageManager + jvFileChooser.setDialogTitle(MessageManager + .getString("label.save_as_biojs_html")); + jvFileChooser.setDialogTitle("save as BioJs HTML"); + jvFileChooser.setToolTipText(MessageManager.getString("action.save")); + + int fileChooserOpt = jvFileChooser.showSaveDialog(null); + if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION) + { + jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser + .getSelectedFile().getParent()); + selectedFile = jvFileChooser.getSelectedFile().getPath(); + } + else + { + throw new NoFileSelectedException("No file was selected."); + } + + return selectedFile; + } + + public String getJalviewAlignmentAsJsonString(AlignmentI alignment) + throws IOException, JSONException + { + BioJsAlignmentPojo bjsAlignment = new BioJsAlignmentPojo(); + + bjsAlignment.setGlobalColorScheme(getGlobalColorScheme()); + bjsAlignment.setJalviewVersion(jalviewVersion); + bjsAlignment.setWebStartUrl(webStartLaunchServletUrl); + + int count = 0; + for (SequenceI seq : alignment.getSequences()) + { + StringBuilder name = new StringBuilder(); + name.append(seq.getName()).append("/").append(seq.getStart()) + .append("-").append(seq.getEnd()); + + BioJsSeqPojo seqPojo = new BioJsSeqPojo(); + seqPojo.setId(String.valueOf(++count)); + seqPojo.setEnd(seq.getEnd()); + seqPojo.setStart(seq.getStart()); + seqPojo.setName(name.toString()); + seqPojo.setSeq(seq.getSequenceAsString()); + + SequenceFeature[] seqFeatures = seq.getDatasetSequence() + .getSequenceFeatures(); + if (seqFeatures != null) + { + ArrayList bjsSeqFeatures = new ArrayList(); + for (SequenceFeature sf : seqFeatures) + { + if (displayedFeatures != null + && displayedFeatures.get(sf.getType()) != null) + { + String featureColour = jalview.util.Format.getHexString(fr + .getColour(sf)); + BioJsFeaturePojo bjsFeature = new BioJsFeaturePojo(); + bjsFeature.setFillColor(featureColour); + bjsFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); + bjsFeature.setXend(seq.findIndex(sf.getEnd())); + bjsFeature.setText(sf.getType()); + bjsSeqFeatures.add(bjsFeature); + } + } + seqPojo.setFeatures(bjsSeqFeatures); + } + bjsAlignment.getSeqs().add(seqPojo); + } + + return new com.json.JSONObject(bjsAlignment).toString() + .replaceAll("xstart", "xStart").replaceAll("xend", "xEnd"); + } + + public static String getBioJsTemplateAsString(Object currentObj) + throws IOException + { + InputStreamReader isReader = null; + BufferedReader buffReader = null; + StringBuilder sb = new StringBuilder(); + URL url = currentObj.getClass().getResource( + "/templates/BioJSTemplate.txt"); + if (url != null) + { + try + { + isReader = new InputStreamReader(url.openStream()); + buffReader = new BufferedReader(isReader); + String line; + String lineSeparator = System.getProperty("line.separator"); + while ((line = buffReader.readLine()) != null) + { + sb.append(line).append(lineSeparator); + } + + } catch (Exception ex) + { + ex.printStackTrace(); + } finally + { + if (isReader != null) + { + isReader.close(); + } + + if (buffReader != null) + { + buffReader.close(); + } + } + } + return sb.toString(); + } + + public String getGlobalColorScheme() + { + return globalColorScheme; + } + + public void setGlobalColorScheme(String globalColorScheme) + { + this.globalColorScheme = globalColorScheme; + } + +} diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 82b94c3..833f590 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -152,6 +152,7 @@ public class FileLoader implements Runnable public AlignFrame LoadFileWaitTillLoaded(FileParse source, String format) { this.source = source; + file = source.getInFile(); protocol = source.type; this.format = format; @@ -352,6 +353,11 @@ public class FileLoader implements Runnable { alignFrame.setFileName(file, format); } + if (source instanceof HtmlFile) + { + ((HtmlFile) source).LoadAlignmentFeatures(alignFrame); + + } if (raiseGUI) { // add the window to the GUI diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 8ca0c35..df5353c 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -255,6 +255,41 @@ public class FormatAdapter extends AppletFormatAdapter return this.formatSequences(format, alignment, suffix); } + public Alignment readFile(String inFile, String type, String format) + throws java.io.IOException + { + Alignment al; + if (format.equals("HTML")) + { + afile = new HtmlFile(inFile, type); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + } + else + { + al = super.readFile(inFile, type, format); + } + + return al; + } + + public AlignmentI readFromFile(FileParse source, String format) + throws java.io.IOException + { + Alignment al; + if (format.equals("HTML")) + { + afile = new HtmlFile(source); + al = new Alignment(afile.getSeqsAsArray()); + afile.addAnnotations(al); + } + else + { + al = (Alignment) super.readFromFile(source, format); + } + return al; + } + /** * validate format is valid for IO in Application. This is basically the * AppletFormatAdapter.isValidFormat call with additional checks for diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java new file mode 100644 index 0000000..3cb7c3f --- /dev/null +++ b/src/jalview/io/HtmlFile.java @@ -0,0 +1,152 @@ +package jalview.io; + +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; +import jalview.gui.AlignFrame; +import jalview.json.binding.v1.BioJsAlignmentPojo.JalviewBioJsColorSchemeMapper; +import jalview.schemes.ColourSchemeI; + +import java.io.IOException; +import java.util.Iterator; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +public class HtmlFile extends AlignFile +{ + // public static final String FILE_EXT = "html"; + // + // public static final String FILE_DESC = "HTML"; + + private ColourSchemeI cs; + + public HtmlFile() + { + super(); + } + + public HtmlFile(FileParse source) throws IOException + { + super(source); + } + + public HtmlFile(String inFile, String type) throws IOException + { + super(inFile, type); + } + + @SuppressWarnings("unchecked") + @Override + public void parse() throws IOException + { + try + { + StringBuilder htmlData = new StringBuilder(); + String currentLine; + while ((currentLine = nextLine()) != null) + { + htmlData.append(currentLine); + } + + Document doc = Jsoup.parse(htmlData.toString()); + Element content = doc.getElementById("seqData"); + + String alignmentJsonString = content.val(); + JSONParser jsonParser = new JSONParser(); + JSONObject alignmentJsonObj = (JSONObject) jsonParser + .parse(alignmentJsonString); + JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs"); + String bioJsColourScheme = (String) alignmentJsonObj + .get("globalColorScheme"); + cs = getJalviewColorScheme(bioJsColourScheme); + + for (Iterator sequenceIter = seqJsonArray.iterator(); sequenceIter + .hasNext();) + { + JSONObject sequence = sequenceIter.next(); + String sequcenceString = sequence.get("seq").toString(); + Sequence seq = new Sequence(sequence.get("name").toString(), + sequcenceString, Integer.valueOf(sequence.get("start") + .toString()), Integer.valueOf(sequence.get("end") + .toString())); + + JSONArray jsonSeqArray = (JSONArray) sequence.get("features"); + SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures( + jsonSeqArray, seq); + if (retrievedSeqFeatures != null) + { + seq.setSequenceFeatures(retrievedSeqFeatures); + } + seqs.add(seq); + + } + } catch (Exception e) + { + e.printStackTrace(); + } + } + + public SequenceFeature[] getJalviewSequenceFeatures( + JSONArray jsonSeqFeatures, Sequence seq) + { + SequenceFeature[] seqFeatures = null; + int count = 0; + if (jsonSeqFeatures != null) + { + seqFeatures = new SequenceFeature[jsonSeqFeatures.size()]; + for (@SuppressWarnings("unchecked") + Iterator seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr + .hasNext();) + { + + SequenceFeature sequenceFeature = new SequenceFeature(); + JSONObject jsonFeature = seqFeatureItr.next(); + Long begin = (Long) jsonFeature.get("xStart"); + Long end = (Long) jsonFeature.get("xEnd"); + String type = (String) jsonFeature.get("text"); + // String color = (String) jsonFeature.get("fillColor"); + + sequenceFeature.setBegin(seq.findPosition(begin.intValue())); + sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1); + sequenceFeature.setType(type); + seqFeatures[count++] = sequenceFeature; + } + } + return seqFeatures; + } + + public void LoadAlignmentFeatures(AlignFrame af) + { + + af.setShowSeqFeatures(true); + af.changeColour(cs); + af.setMenusForViewport(); + } + + private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName) + { + ColourSchemeI jalviewColor = null; + for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + .values()) + { + if (cs.getBioJsName().equals(bioJsColourSchemeName)) + { + jalviewColor = cs.getJvColourScheme(); + break; + } + } + return jalviewColor; + } + + @Override + public String print() + { + throw new UnsupportedOperationException( + "Print method of HtmlFile not yet supported!"); + } + +} diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 9c7478b..4fb2516 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -136,8 +136,14 @@ public class IdentifyFile break; } + // if (data.matches("<(\"[^\"]*\"|'[^']*'|[^'\">])*>")) + if (data.matches("<(?i)html(\"[^\"]*\"|'[^']*'|[^'\">])*>")) + { + reply = "HTML"; + break; + } - if ((data.indexOf("<") > -1)) + if (data.matches("<(?i)rnaml (\"[^\"]*\"|'[^']*'|[^'\">])*>")) { reply = "RNAML"; @@ -275,6 +281,7 @@ public class IdentifyFile break; } + /* * // TODO comment out SimpleBLAST identification for Jalview 2.4.1 else * if (!lineswereskipped && data.indexOf("BLAST")<4) { reply = @@ -320,6 +327,7 @@ public class IdentifyFile public static void main(String[] args) { + for (int i = 0; args != null && i < args.length; i++) { IdentifyFile ider = new IdentifyFile(); diff --git a/src/jalview/io/RnamlFile.java b/src/jalview/io/RnamlFile.java index d366edc..c075fda 100644 --- a/src/jalview/io/RnamlFile.java +++ b/src/jalview/io/RnamlFile.java @@ -20,12 +20,6 @@ */ package jalview.io; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; - import jalview.analysis.SecStrConsensus.SimpleBP; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -33,6 +27,14 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +import com.stevesoft.pat.Regex; + import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax; import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed; import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied; @@ -139,6 +141,14 @@ public class RnamlFile extends AlignFile int end = seq.length(); id = current.getName(); + if (id == null || id.trim().length() == 0) + { + id = safeName(getDataName()); + if (result.size() > 1) + { + id += "." + i; + } + } seqs[i] = new Sequence(id, seq, begin, end); seqs[i].setEnd(seqs[i].findPosition(seqs[i].getLength())); @@ -157,8 +167,11 @@ public class RnamlFile extends AlignFile annot[k]).charAt(0), 0f); } - AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.", - current.getID(), ann); + AlignmentAnnotation align = new AlignmentAnnotation( + "Secondary Structure", + current.getID().trim().length() > 0 ? "Secondary Structure for " + + current.getID() + : "", ann); seqs[i].addAlignmentAnnotation(align); seqs[i].setRNA(result.get(i)); @@ -204,13 +217,18 @@ public class RnamlFile extends AlignFile private String safeName(String dataName) { int b = 0; - while ((b = dataName.indexOf("/")) > -1 && b < dataName.length()) + if ((b = dataName.lastIndexOf(".")) > 0) { - dataName = dataName.substring(b + 1).trim(); - + dataName = dataName.substring(0, b - 1); + } + b = 0; + Regex m = new Regex("[\\/]?([-A-Za-z0-9]+)\\.?"); + String mm = dataName; + while (m.searchFrom(dataName, b)) + { + mm = m.stringMatched(); + b = m.matchedTo(); } - int e = (dataName.length() - dataName.indexOf(".")) + 1; - dataName = dataName.substring(1, e).trim(); - return dataName; + return mm; } } diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index 0a18be0..96c462c 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -23,7 +23,6 @@ */ package jalview.io; -import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; @@ -41,7 +40,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; @@ -186,7 +187,7 @@ public class StockholmFile extends AlignFile String version; // String id; Hashtable seqAnn = new Hashtable(); // Sequence related annotations - Hashtable seqs = new Hashtable(); + LinkedHashMap seqs = new LinkedHashMap(); Regex p, r, rend, s, x; // Temporary line for processing RNA annotation // String RNAannot = ""; @@ -198,7 +199,9 @@ public class StockholmFile extends AlignFile r = new Regex("# STOCKHOLM ([\\d\\.]+)"); if (!r.search(nextLine())) { - throw new IOException(MessageManager.getString("exception.stockholm_invalid_format")); + throw new IOException( + MessageManager + .getString("exception.stockholm_invalid_format")); } else { @@ -258,12 +261,11 @@ public class StockholmFile extends AlignFile } } // logger.debug("Number of sequences: " + this.noSeqs); - Enumeration accs = seqs.keys(); - while (accs.hasMoreElements()) + for (Map.Entry skey : seqs.entrySet()) { - String acc = (String) accs.nextElement(); // logger.debug("Processing sequence " + acc); - String seq = (String) seqs.remove(acc); + String acc = skey.getKey(); + String seq = skey.getValue(); if (maxLength < seq.length()) { maxLength = seq.length(); @@ -367,6 +369,7 @@ public class StockholmFile extends AlignFile AlignmentAnnotation an = (AlignmentAnnotation) vv .elementAt(ii); seqO.addAlignmentAnnotation(an); + annotations.add(an); } } } @@ -416,9 +419,11 @@ public class StockholmFile extends AlignFile if (!x.search(line)) { // logger.error("Could not parse sequence line: " + line); - throw new IOException(MessageManager.formatMessage("exception.couldnt_parse_sequence_line", new String[]{line})); + throw new IOException(MessageManager.formatMessage( + "exception.couldnt_parse_sequence_line", new String[] + { line })); } - String ns = (String) seqs.get(x.stringMatched(1)); + String ns = seqs.get(x.stringMatched(1)); if (ns == null) { ns = ""; @@ -528,7 +533,9 @@ public class StockholmFile extends AlignFile } else { - throw new IOException(MessageManager.formatMessage("exception.error_parsing_line", new String[]{line})); + throw new IOException(MessageManager.formatMessage( + "exception.error_parsing_line", new String[] + { line })); } } else if (annType.equals("GC")) @@ -636,9 +643,13 @@ public class StockholmFile extends AlignFile strucAnn = new Hashtable(); } - Vector newStruc = new Vector(); + Vector newStruc = new Vector(); parseAnnotationRow(newStruc, type, ns); - + for (AlignmentAnnotation alan : newStruc) + { + alan.visible = false; + } + // annotations.addAll(newStruc); strucAnn.put(type, newStruc); seqAnn.put(acc, strucAnn); } @@ -653,7 +664,9 @@ public class StockholmFile extends AlignFile } else { - throw new IOException(MessageManager.formatMessage("exception.unknown_annotation_detected", new String[]{annType,annContent})); + throw new IOException(MessageManager.formatMessage( + "exception.unknown_annotation_detected", new String[] + { annType, annContent })); } } } @@ -813,25 +826,29 @@ public class StockholmFile extends AlignFile // be written out if (ss) { - if (detectbrackets.search(pos)) - { - ann.secondaryStructure = jalview.schemes.ResidueProperties - .getRNASecStrucState(pos).charAt(0); - } - else + //if (" .-_".indexOf(pos) == -1) { - ann.secondaryStructure = jalview.schemes.ResidueProperties - .getDssp3state(pos).charAt(0); - } + if (detectbrackets.search(pos)) + { + ann.secondaryStructure = jalview.schemes.ResidueProperties + .getRNASecStrucState(pos).charAt(0); + } + else + { + ann.secondaryStructure = jalview.schemes.ResidueProperties + .getDssp3state(pos).charAt(0); + } - if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0) == 'C') - { - ann.displayCharacter = ""; // null; // " "; - } - else - { - ann.displayCharacter = " " + ann.displayCharacter; + if (ann.secondaryStructure == pos.charAt(0)) + { + ann.displayCharacter = ""; // null; // " "; + } + else + { + ann.displayCharacter = " " + ann.displayCharacter; + } } + } els[i] = ann; @@ -842,7 +859,9 @@ public class StockholmFile extends AlignFile { annot = (AlignmentAnnotation) e.nextElement(); if (annot.label.equals(type)) + { break; + } annot = null; } if (annot == null) @@ -887,7 +906,9 @@ public class StockholmFile extends AlignFile for (int idb = 0; idb < s[in].getDBRef().length; idb++) { if (dataRef == null) + { dataRef = new Hashtable(); + } String datAs1 = s[in].getDBRef()[idb].getSource().toString() + " ; " @@ -960,39 +981,19 @@ public class StockholmFile extends AlignFile String key = type2id(feature); if (key == null) + { continue; + } // out.append("#=GR "); out.append(new Format("%-" + maxid + "s").form("#=GR " + printId(s[i]) + " " + key + " ")); ann = alAnot[j].annotations; + boolean isrna = alAnot[j].isValidStruc(); String seq = ""; for (int k = 0; k < ann.length; k++) { - annot = ann[k]; - String ch = (annot == null) ? Character.toString(s[i] - .getCharAt(k)) : annot.displayCharacter; - if (ch.length() == 0) - { - if (key.equals("SS")) - { - char ll = annot.secondaryStructure; - seq = (Character.toString(ll).equals(" ")) ? seq + "C" - : seq + ll; - } - else - { - seq += "."; - } - } - else if (ch.length() == 1) - { - seq += ch; - } - else if (ch.length() > 1) - { - seq += ch.charAt(1); - } + seq += outputCharacter(key, k, isrna, ann, s[i]); } out.append(seq); out.append(newline); @@ -1013,43 +1014,33 @@ public class StockholmFile extends AlignFile for (int ia = 0; ia < al.getAlignmentAnnotation().length; ia++) { aa = al.getAlignmentAnnotation()[ia]; - if (aa.autoCalculated || !aa.visible) + if (aa.autoCalculated || !aa.visible || aa.sequenceRef != null) { continue; } String seq = ""; String label; - + String key = ""; if (aa.label.equals("seq")) + { label = "seq_cons"; + } else - label = type2id(aa.label.toLowerCase()) + "_cons"; + { + label = (key = type2id(aa.label.toLowerCase())) + "_cons"; + } if (label == null) + { label = aa.label; + } out.append(new Format("%-" + maxid + "s").form("#=GC " + label + " ")); + boolean isrna = aa.isValidStruc(); for (int j = 0; j < aa.annotations.length; j++) { - String ch = (aa.annotations[j] == null) ? "-" - : aa.annotations[j].displayCharacter; - if (ch.length() == 0) - { - char ll = aa.annotations[j].secondaryStructure; - if (Character.toString(ll).equals(" ")) - seq += "C"; - else - seq += ll; - } - else if (ch.length() == 1) - { - seq += ch; - } - else if (ch.length() > 1) - { - seq += ch.charAt(1); - } + seq += outputCharacter(key, j, isrna, aa.annotations, null); } out.append(seq); out.append(newline); @@ -1058,6 +1049,57 @@ public class StockholmFile extends AlignFile return out.toString(); } + /** + * add an annotation character to the output row + * + * @param seq + * @param key + * @param k + * @param isrna + * @param ann + * @param sequenceI + */ + private char outputCharacter(String key, int k, + boolean isrna, Annotation[] ann, SequenceI sequenceI) + { + char seq = ' '; + Annotation annot = ann[k]; + String ch = (annot == null) ? ((sequenceI == null) ? "-" : Character + .toString(sequenceI.getCharAt(k))) + : annot.displayCharacter; + if (key.equals("SS")) + { + if (annot == null) + { + // sensible gap character if one is available or make one up + return sequenceI == null ? '-' : sequenceI + .getCharAt(k); + } + else + { + // valid secondary structure AND no alternative label (e.g. ' B') + if (annot.secondaryStructure > ' ' && ch.length() < 2) + { + return annot.secondaryStructure; + } + } + } + + if (ch.length() == 0) + { + seq = '.'; + } + else if (ch.length() == 1) + { + seq = ch.charAt(0); + } + else if (ch.length() > 1) + { + seq = ch.charAt(1); + } + return seq; + } + public String print() { out = new StringBuffer(); @@ -1121,7 +1163,7 @@ public class StockholmFile extends AlignFile } if (key != null) { - return (String) key; + return key; } System.err.println("Warning : Unknown Stockholm annotation type: " + type); diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 77af496..4bf8176 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -214,6 +214,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem createPNG = new JMenuItem(); + JMenuItem createBioJS = new JMenuItem(); + JMenuItem createSVG = new JMenuItem(); protected JMenuItem font = new JMenuItem(); @@ -1197,6 +1199,19 @@ public class GAlignFrame extends JInternalFrame htmlMenuItem_actionPerformed(e); } }); + + // TODO uncomment when supported by MassageManager + // createBioJS.setText(MessageManager.getString("label.biojs_html_export")); + createBioJS.setText("BioJS"); + createBioJS.addActionListener(new java.awt.event.ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + bioJSMenuItem_actionPerformed(e); + } + }); + overviewMenuItem.setText(MessageManager .getString("label.overview_window")); overviewMenuItem.addActionListener(new java.awt.event.ActionListener() @@ -1603,7 +1618,6 @@ public class GAlignFrame extends JInternalFrame font_actionPerformed(e); } }); - seqLimits.setText(MessageManager .getString("label.show_sequence_limits")); seqLimits.setState(jalview.bin.Cache.getDefault("SHOW_JVSUFFIX", true)); @@ -1753,7 +1767,7 @@ public class GAlignFrame extends JInternalFrame sortByAnnotScore.setText(MessageManager .getString("label.sort_by_score")); sort.add(sortByAnnotScore); - sortByAnnotScore.addMenuListener(new javax.swing.event.MenuListener() + sort.addMenuListener(new javax.swing.event.MenuListener() { @Override @@ -2353,6 +2367,7 @@ public class GAlignFrame extends JInternalFrame jMenu2.add(htmlMenuItem); jMenu2.add(epsFile); jMenu2.add(createPNG); + jMenu2.add(createBioJS); jMenu2.add(createSVG); addSequenceMenu.add(addFromFile); addSequenceMenu.add(addFromText); @@ -2611,6 +2626,11 @@ public class GAlignFrame extends JInternalFrame { } + protected void bioJSMenuItem_actionPerformed(ActionEvent e) + { + + } + protected void closeMenuItem_actionPerformed(boolean b) { } diff --git a/src/jalview/json/binding/v1/BioJsAlignmentPojo.java b/src/jalview/json/binding/v1/BioJsAlignmentPojo.java new file mode 100644 index 0000000..8e8747f --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsAlignmentPojo.java @@ -0,0 +1,151 @@ +package jalview.json.binding.v1; + +import jalview.schemes.Blosum62ColourScheme; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.NucleotideColourScheme; +import jalview.schemes.PIDColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.RNAInteractionColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.ZappoColourScheme; + +import java.util.ArrayList; + +public class BioJsAlignmentPojo +{ + private String globalColorScheme = "none"; + + private String jalviewVersion; + + private String webStartUrl; + private ArrayList seqs = new ArrayList(); + + public BioJsAlignmentPojo() + { + + } + public ArrayList getSeqs() + { + return seqs; + } + + public void setSeqs(ArrayList seqs) + { + this.seqs = seqs; + } + public String getGlobalColorScheme() + { + return globalColorScheme; + } + public void setGlobalColorScheme(String globalColorScheme) + { + for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper + .values()) + { + if (cs.getJalviewName().equals(globalColorScheme)) + { + this.globalColorScheme = cs.getBioJsName(); + break; + } + } + + // JALVIEW colors not in biojs + // Blosum62 + // T-Coffee Scores (almost same with Blosom62 + // RNA Interaction type - no color applied + // RNA Helices - missing + + // BIOJS Colour not in jalview + // schemes.push name: "Lesk", id: "lesk" + // schemes.push name: "Cinema", id: "cinema" + // schemes.push name: "MAE", id: "mae" + // schemes.push name: "Clustal2", id: "clustal2" + + } + + + public String getJalviewVersion() + { + return jalviewVersion; + } + + public void setJalviewVersion(String jalviewVersion) + { + this.jalviewVersion = jalviewVersion; + } + + public String getWebStartUrl() + { + return webStartUrl; + } + + public void setWebStartUrl(String webStartUrl) + { + this.webStartUrl = webStartUrl; + } + + public enum JalviewBioJsColorSchemeMapper + { + USER_DEFINED("User Defined", "user defined", null), NONE("None", "foo", + null), CLUSTAL("Clustal", "clustal", null), ZAPPO("Zappo", + "zappo", new ZappoColourScheme()), TAYLOR( + "Taylor", "taylor", new TaylorColourScheme()), NUCLEOTIDE( + "Nucleotide", "nucleotide", new NucleotideColourScheme()), PURINE_PYRIMIDINE( + "Purine/Pyrimidine", "purine", + new PurinePyrimidineColourScheme()), HELIX_PROPENCITY( + "Helix Propensity", "helix", new HelixColourScheme()), TURN_PROPENSITY( + "Turn Propensity", "turn", new TurnColourScheme()), STRAND_PROPENSITY( + "Strand Propensity", "strand", new StrandColourScheme()), BURIED_INDEX( + "Buried Index", "buried", new BuriedColourScheme()), HYDROPHOBIC( + "Hydrophobic", "hydro", new HydrophobicColourScheme()), + + // The color types below are not yet supported by BioJs MSA viewer + T_COFFE_SCORES("T-Coffee Scores", "T-Coffee Scores", + null), RNA_INT_TYPE( + "RNA Interaction type", "RNA Interaction type", + new RNAInteractionColourScheme()), BLOSUM62("Blosum62", + "Blosum62", new Blosum62ColourScheme()), RNA_HELICES( + "RNA Helices", "RNA Helices", null), PERCENTAGE_IDENTITY( + "% Identity", "pid", + new PIDColourScheme()); + + private String jalviewName; + private String bioJsName; + + private ColourSchemeI jvColourScheme; + + private JalviewBioJsColorSchemeMapper(String jalviewName, + String bioJsName, ColourSchemeI jvColourScheme) + { + this.jalviewName = jalviewName; + this.bioJsName = bioJsName; + this.setJvColourScheme(jvColourScheme); + } + + public String getJalviewName() + { + return jalviewName; + } + + public String getBioJsName() + { + return bioJsName; + } + + public ColourSchemeI getJvColourScheme() + { + return jvColourScheme; + } + + public void setJvColourScheme(ColourSchemeI jvColourScheme) + { + this.jvColourScheme = jvColourScheme; + } + + } +} diff --git a/src/jalview/json/binding/v1/BioJsFeaturePojo.java b/src/jalview/json/binding/v1/BioJsFeaturePojo.java new file mode 100644 index 0000000..3c2fdda --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsFeaturePojo.java @@ -0,0 +1,60 @@ +package jalview.json.binding.v1; + +public class BioJsFeaturePojo +{ + + private int xstart; + + private int xend; + + private String text; + + private String fillColor; + + public BioJsFeaturePojo() + { + } + + + public String getText() + { + return text; + } + + public void setText(String text) + { + this.text = text; + } + + public String getFillColor() + { + return "#" + fillColor; + } + + public void setFillColor(String fillColor) + { + this.fillColor = fillColor; + } + + public int getXstart() + { + return xstart; + } + + public void setXstart(int xstart) + { + this.xstart = xstart; + } + + public int getXend() + { + return xend; + } + + public void setXend(int xend) + { + this.xend = xend; + } + + +} diff --git a/src/jalview/json/binding/v1/BioJsSeqPojo.java b/src/jalview/json/binding/v1/BioJsSeqPojo.java new file mode 100644 index 0000000..bac8601 --- /dev/null +++ b/src/jalview/json/binding/v1/BioJsSeqPojo.java @@ -0,0 +1,90 @@ +package jalview.json.binding.v1; + +import java.util.ArrayList; + + +public class BioJsSeqPojo +{ + private String seq; + + private String name; + + private String id; + + private int start; + + private int end; + + private ArrayList features = new ArrayList(); + + public BioJsSeqPojo() + { + } + + public BioJsSeqPojo(int start, int end, String id, String name, String seq) + { + this.id = id; + this.name = name; + this.seq = seq; + } + public String getSeq() + { + return seq; + } + + public void setSeq(String seq) + { + this.seq = seq; + } + + public String getName() + { + + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public int getStart() + { + return start; + } + + public void setStart(int start) + { + this.start = start; + } + + public int getEnd() + { + return end; + } + + public void setEnd(int end) + { + this.end = end; + } + + public ArrayList getFeatures() + { + return features; + } + + public void setFeatures(ArrayList features) + { + this.features = features; + } +} diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index e731910..d5b2f49 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -27,6 +27,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.schemes.ColourSchemeI; +import jalview.schemes.ResidueProperties; import java.awt.BasicStroke; import java.awt.Color; @@ -77,17 +78,17 @@ public class AnnotationRenderer int x2 = (x * charWidth); Regex closeparen = new Regex("(\\))"); - String dc = (column == 0 || row_annotations[column - 1] == null) ? "" - : row_annotations[column - 1].displayCharacter; + char dc = (column == 0 || row_annotations[column - 1] == null) ? ' ' + : row_annotations[column - 1].secondaryStructure; boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null - || !dc.equals(row_annotations[sCol - 1].displayCharacter); + || dc != row_annotations[sCol - 1].secondaryStructure; boolean diffdownstream = !validRes || !validEnd || row_annotations[column] == null - || !dc.equals(row_annotations[column].displayCharacter); + || dc != row_annotations[column].secondaryStructure; // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream); // If a closing base pair half of the stem, display a backward arrow - if (column > 0 && closeparen.search(dc)) + if (column > 0 && ResidueProperties.isCloseParenRNA(dc)) { if (diffupstream) @@ -574,11 +575,15 @@ public class AnnotationRenderer } } } - if (!row.isValidStruc()) + if (row.getInvalidStrucPos() > x) { g.setColor(Color.orange); - g.fillRect((int) row.getInvalidStrucPos() * charWidth, y, - charWidth, charHeight); + g.fillRect(x * charWidth, y, charWidth, charHeight); + } + else if (row.getInvalidStrucPos() == x) + { + g.setColor(Color.orange.darker()); + g.fillRect(x * charWidth, y, charWidth, charHeight); } if (validCharWidth && validRes @@ -617,9 +622,13 @@ public class AnnotationRenderer charOffset = (int) ((charWidth - fmWidth) / 2f); if (row_annotations[column].colour == null) + { g.setColor(Color.black); + } else + { g.setColor(row_annotations[column].colour); + } if (column == 0 || row.graph > 0) { @@ -1190,9 +1199,13 @@ public class AnnotationRenderer } if (aa_annotations[column].colour == null) + { g.setColor(Color.black); + } else + { g.setColor(aa_annotations[column].colour); + } y1 = y - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight); @@ -1264,9 +1277,13 @@ public class AnnotationRenderer continue; } if (aa_annotations[column].colour == null) + { g.setColor(Color.black); + } else + { g.setColor(aa_annotations[column].colour); + } y1 = y - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight); @@ -1384,9 +1401,13 @@ public class AnnotationRenderer if (aa_annotations[j] != null) { if (aa_annotations[j].colour == null) + { g.setColor(Color.black); + } else + { g.setColor(aa_annotations[j].colour); + } height = (int) ((aa_annotations[j].value / _aa.graphMax) * y); if (height > y) diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 713e55d..3cada8b 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -53,7 +53,6 @@ public class AnnotationColourGradient extends FollowerColourScheme private boolean predefinedColours = false; private boolean seqAssociated = false; - /** * false if the scheme was constructed without a minColour and maxColour used * to decide if existing colours should be taken from annotation elements when @@ -141,6 +140,12 @@ public class AnnotationColourGradient extends FollowerColourScheme bb = maxColour.getBlue() - b1; noGradient = false; + aamax = annotation.graphMax; + aamin = annotation.graphMin; + if (annotation.isRNA()) + { + ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); + } } @Override @@ -162,6 +167,7 @@ public class AnnotationColourGradient extends FollowerColourScheme // resolve the context containing all the annotation for the sequence AnnotatedCollectionI alcontext = alignment instanceof AlignmentI ? alignment : alignment.getContext(); + boolean f = true,rna=false; for (AlignmentAnnotation alan : alcontext.findAnnotation(annotation .getCalcId())) { @@ -169,12 +175,30 @@ public class AnnotationColourGradient extends FollowerColourScheme && (alan.label != null && annotation != null && alan.label .equals(annotation.label))) { + if (!rna && alan.isRNA()) + { + rna = true; + } seqannot.put(alan.sequenceRef, alan); + if (f || alan.graphMax > aamax) + { + aamax = alan.graphMax; + } + if (f || alan.graphMin < aamin) + { + aamin = alan.graphMin; + } + f = false; } } + if (rna) + { + ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); + } } } + float aamin = 0f, aamax = 0f; public String getAnnotation() { return annotation.label; @@ -278,9 +302,16 @@ public class AnnotationColourGradient extends FollowerColourScheme } else { - currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR - : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR - : jalview.renderer.AnnotationRenderer.STEM_COLOUR; + if (annotation.isRNA()) + { + currentColour = ColourSchemeProperty.rnaHelices[(int) aj.value]; + } + else + { + currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR + : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR + : jalview.renderer.AnnotationRenderer.STEM_COLOUR; + } } } else @@ -305,35 +336,7 @@ public class AnnotationColourGradient extends FollowerColourScheme } else { - // calculate a shade - float range = 1f; - if (thresholdIsMinMax - && annotation.threshold != null - && aboveAnnotationThreshold == ABOVE_THRESHOLD - && annotation.annotations[j].value >= annotation.threshold.value) - { - range = (annotation.annotations[j].value - annotation.threshold.value) - / (annotation.graphMax - annotation.threshold.value); - } - else if (thresholdIsMinMax - && annotation.threshold != null - && aboveAnnotationThreshold == BELOW_THRESHOLD - && annotation.annotations[j].value >= annotation.graphMin) - { - range = (annotation.annotations[j].value - annotation.graphMin) - / (annotation.threshold.value - annotation.graphMin); - } - else - { - range = (annotation.annotations[j].value - annotation.graphMin) - / (annotation.graphMax - annotation.graphMin); - } - - int dr = (int) (rr * range + r1), dg = (int) (gg * range + g1), db = (int) (bb - * range + b1); - - currentColour = new Color(dr, dg, db); - + currentColour = shadeCalculation(annotation, j); } } if (conservationColouring) @@ -345,6 +348,45 @@ public class AnnotationColourGradient extends FollowerColourScheme return currentColour; } + private Color shadeCalculation(AlignmentAnnotation annotation, int j) + { + + // calculate a shade + float range = 1f; + if (thresholdIsMinMax + && annotation.threshold != null + && aboveAnnotationThreshold == ABOVE_THRESHOLD + && annotation.annotations[j].value >= annotation.threshold.value) + { + range = (annotation.annotations[j].value - annotation.threshold.value) + / (annotation.graphMax - annotation.threshold.value); + } + else if (thresholdIsMinMax && annotation.threshold != null + && aboveAnnotationThreshold == BELOW_THRESHOLD + && annotation.annotations[j].value >= annotation.graphMin) + { + range = (annotation.annotations[j].value - annotation.graphMin) + / (annotation.threshold.value - annotation.graphMin); + } + else + { + if (annotation.graphMax != annotation.graphMin) + { + range = (annotation.annotations[j].value - annotation.graphMin) + / (annotation.graphMax - annotation.graphMin); + } + else + { + range = 0f; + } + } + + int dr = (int) (rr * range + r1), dg = (int) (gg * range + g1), db = (int) (bb + * range + b1); + + return new Color(dr, dg, db); + + } public boolean isPredefinedColours() { return predefinedColours; diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index cc303d6..57a2dd9 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -597,4 +597,33 @@ public class ColourSchemeProperty return col; } + + public static Color rnaHelices[] = null; + + public static void initRnaHelicesShading(int n) + { + int j = 0; + if (rnaHelices == null) + { + rnaHelices = new Color[n + 1]; + } + else if (rnaHelices != null && rnaHelices.length <= n) + { + Color[] t = new Color[n + 1]; + System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length); + j = rnaHelices.length; + rnaHelices = t; + } + else + { + return; + } + // Generate random colors and store + for (; j <= n; j++) + { + rnaHelices[j] = jalview.util.ColorUtils + .generateRandomColor(Color.white); + } + } + } diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 7ec9e1c..8acf1f2 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -23,9 +23,13 @@ package jalview.schemes; import jalview.analysis.scoremodels.PIDScoreModel; import jalview.api.analysis.ScoreModelI; -import java.util.*; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; import java.util.List; -import java.awt.*; +import java.util.Map; +import java.util.Vector; public class ResidueProperties { @@ -1451,7 +1455,7 @@ public class ResidueProperties propMatrixF[i][j] = 0; propMatrixPos[i][j] = 0; propMatrixEpos[i][j] = 0; - for (Enumeration en = (Enumeration) propHash.keys(); en + for (Enumeration en = propHash.keys(); en .hasMoreElements();) { String ph = en.nextElement(); @@ -1695,7 +1699,9 @@ public class ResidueProperties * Used by getRNASecStrucState * */ - public static Hashtable toRNAssState; + public static Hashtable toRNAssState; + + public static boolean RNAcloseParen[] = new boolean[255]; static { toRNAssState = new Hashtable(); @@ -1759,7 +1765,15 @@ public class ResidueProperties toRNAssState.put("y", "Y"); toRNAssState.put("Z", "Z"); toRNAssState.put("z", "Z"); - + for (int p = 0; p < RNAcloseParen.length; p++) + { + RNAcloseParen[p] = false; + } + for (String k : toRNAssState.keySet()) + { + RNAcloseParen[k.charAt(0)] = k.charAt(0) != toRNAssState.get(k) + .charAt(0); + } } /** @@ -1780,7 +1794,8 @@ public class ResidueProperties String ssc = ssstring.substring(i, i + 1); if (toRNAssState.containsKey(ssc)) { - ss.append((String) toRNAssState.get(ssc)); + // valid ss character - so return it + ss.append(ssc); // (String) toRNAssState.get(ssc)); } else { @@ -1790,6 +1805,11 @@ public class ResidueProperties return ss.toString(); } + public static boolean isCloseParenRNA(char dc) + { + return RNAcloseParen[dc]; + } + // main method generates perl representation of residue property hash // / cut here public static void main(String[] args) @@ -1839,4 +1859,5 @@ public class ResidueProperties System.out.println("};"); } // to here + } diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 61ef34f..b410be6 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -21,6 +21,7 @@ package jalview.util; import jalview.gui.EPSOptions; +import jalview.gui.SVGOptions; import jalview.io.JalviewFileChooser; import java.awt.Component; @@ -34,6 +35,7 @@ import java.io.FileOutputStream; import javax.imageio.ImageIO; import org.jfree.graphics2d.svg.SVGGraphics2D; +import org.jfree.graphics2d.svg.SVGHints; import org.jibble.epsgraphics.EpsGraphics2D; public class ImageMaker @@ -219,11 +221,39 @@ public class ImageMaker Graphics2D ig2 = (Graphics2D) graphics; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + } void setupSVG(int width, int height, String title) { + g2 = new SVGGraphics2D(width, height); + Graphics2D ig2 = g2; + + String renderStyle = jalview.bin.Cache.getDefault("SVG_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for EPS rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && !(System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true"))) + { + SVGOptions svgOption = new SVGOptions(); + renderStyle = svgOption.getValue(); + + if (renderStyle == null || svgOption.cancelled) + { + return; + } + } + + if (renderStyle.equalsIgnoreCase("lineart")) + { + ig2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + } + graphics = g2; } diff --git a/src/jalview/ws/jws2/JabaWsServerQuery.java b/src/jalview/ws/jws2/JabaWsServerQuery.java index a08a233..74dce4d 100644 --- a/src/jalview/ws/jws2/JabaWsServerQuery.java +++ b/src/jalview/ws/jws2/JabaWsServerQuery.java @@ -27,6 +27,9 @@ import jalview.bin.Cache; import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.jws2.jabaws2.Jws2InstanceFactory; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashSet; import java.util.Set; @@ -44,7 +47,7 @@ public class JabaWsServerQuery implements Runnable Jws2Discoverer jws2Discoverer = null; - String jwsservers = null; + String jwsserver = null; boolean quit = false, running = false; @@ -65,10 +68,10 @@ public class JabaWsServerQuery implements Runnable this.quit = quit; } - public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers) + public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String server) { this.jws2Discoverer = jws2Discoverer; - this.jwsservers = jwsservers; + this.jwsserver = server; } Services[] JABAWS1SERVERS = new Services[] @@ -92,7 +95,9 @@ public class JabaWsServerQuery implements Runnable running = true; try { - if (Jws2Client.validURL(jwsservers)) + // TODO this test doesn't seem to attempt a connection - should it? + // would save a lot of failed tries with UnknownHostException + if (isValidUrl(jwsserver)) { compbio.data.msa.RegistryWS registry = null; Set svccategories = null; @@ -109,7 +114,7 @@ public class JabaWsServerQuery implements Runnable try { // JBPNote: why is RegistryWS in compbio.data.msa ? - registry = Jws2Client.connectToRegistry(jwsservers); + registry = Jws2Client.connectToRegistry(jwsserver); if (registry != null) { // System.err.println("Test Services Output\n" @@ -137,7 +142,7 @@ public class JabaWsServerQuery implements Runnable ex.printStackTrace(); // if that failed, then we are probably working with a JABAWS1 server. // in that case, look for each service endpoint - System.err.println("JWS2 Discoverer: " + jwsservers + System.err.println("JWS2 Discoverer: " + jwsserver + " is a JABAWS1 server. Using hardwired list."); for (Services srv : JABAWS1SERVERS) { @@ -161,18 +166,18 @@ public class JabaWsServerQuery implements Runnable JABAService service = null; try { - service = Jws2Client.connect(jwsservers, srv); + service = Jws2Client.connect(jwsserver, srv); } catch (Exception e) { System.err.println("Jws2 Discoverer: Problem on " - + jwsservers + " with service " + srv + ":\n" + + jwsserver + " with service " + srv + ":\n" + e.getMessage()); if (!(e instanceof javax.xml.ws.WebServiceException)) { e.printStackTrace(); } // For moment, report service as a problem. - jws2Discoverer.addInvalidServiceUrl(jwsservers); + jws2Discoverer.addInvalidServiceUrl(jwsserver); } ; if (service != null) @@ -184,16 +189,16 @@ public class JabaWsServerQuery implements Runnable String description = registry.getServiceDescription(srv); - svc = Jws2InstanceFactory.newJws2Instance(jwsservers, + svc = Jws2InstanceFactory.newJws2Instance(jwsserver, srv.toString(), cat.name, description, service); } if (svc == null) { - svc = Jws2InstanceFactory.newJws2Instance(jwsservers, + svc = Jws2InstanceFactory.newJws2Instance(jwsserver, srv.toString(), cat.name, "JABAWS 1 Alignment Service", service); } - jws2Discoverer.addService(jwsservers, svc); + jws2Discoverer.addService(jwsserver, svc); } } @@ -201,25 +206,53 @@ public class JabaWsServerQuery implements Runnable if (noservices) { - jws2Discoverer.addUrlwithnoservices(jwsservers); + jws2Discoverer.addUrlwithnoservices(jwsserver); } } else { - jws2Discoverer.addInvalidServiceUrl(jwsservers); - Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers); + jws2Discoverer.addInvalidServiceUrl(jwsserver); + Cache.log.info("Ignoring invalid Jws2 service url " + jwsserver); } } catch (Exception e) { e.printStackTrace(); Cache.log.warn("Exception when discovering Jws2 services.", e); - jws2Discoverer.addInvalidServiceUrl(jwsservers); + jws2Discoverer.addInvalidServiceUrl(jwsserver); } catch (Error e) { Cache.log.error("Exception when discovering Jws2 services.", e); - jws2Discoverer.addInvalidServiceUrl(jwsservers); + jws2Discoverer.addInvalidServiceUrl(jwsserver); } running = false; } + /** + * Check if the URL is valid and responding. + * + * @return + */ + private boolean isValidUrl(String server) + { + // return Jws2Client.validURL(jwsserver); // checks syntax only + boolean result = false; + if (server != null) { + try { + URL url = new URL(server); + url.openStream().close(); + result = true; + } catch (MalformedURLException e) + { + System.err.println("Invalid server URL: " + server); + result = false; + } catch (IOException e) + { + System.err.println("Error connecting to server: " + server + ": " + + e.toString()); + result = false; + } + } + return result; + } + } diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 910b749..a111d68 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -34,6 +34,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -60,9 +62,48 @@ import compbio.ws.client.Services; */ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { - private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport( + public static final String COMPBIO_JABAWS = "http://www.compbio.dundee.ac.uk/jabaws"; + + /* + * the .jalview_properties entry for JWS2 URLS + */ + final static String JWS2HOSTURLS = "JWS2HOSTURLS"; + + /* + * Singleton instance + */ + private static Jws2Discoverer discoverer; + + /* + * Override for testing only + */ + private static List testUrls = null; + + // preferred url has precedence over others + private String preferredUrl; + + private PropertyChangeSupport changeSupport = new PropertyChangeSupport( this); + Vector invalidServiceUrls = null, urlsWithoutServices = null, + validServiceUrls = null; + + boolean running = false, aborted = false; + + Thread oldthread = null; + + /** + * holds list of services. + */ + protected Vector services; + + /** + * Private constructor enforces use of singleton via getDiscoverer() + */ + private Jws2Discoverer() + { + } + /** * change listeners are notified of "services" property changes * @@ -87,8 +128,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI changeSupport.removePropertyChangeListener(listener); } - boolean running = false, aborted = false; - /** * @return the aborted */ @@ -104,10 +143,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI public void setAborted(boolean aborted) { this.aborted = aborted; - } - - Thread oldthread = null; + } public void run() { @@ -135,7 +172,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI // first set up exclusion list if needed final Set ignoredServices = new HashSet(); - for (String ignored : jalview.bin.Cache.getDefault( + for (String ignored : Cache.getDefault( "IGNORED_JABAWS_SERVICETYPES", "") .split("\\|")) { @@ -176,9 +213,9 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI ArrayList svctypes = new ArrayList(); List qrys = new ArrayList(); - for (final String jwsservers : getServiceUrls()) + for (final String jwsserver : getServiceUrls()) { - JabaWsServerQuery squery = new JabaWsServerQuery(this, jwsservers); + JabaWsServerQuery squery = new JabaWsServerQuery(this, jwsserver); if (svctypes.size() == 0) { // TODO: remove this ugly hack to get Canonical JABA service ordering @@ -233,7 +270,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI Jws2Instance[] svcs = new Jws2Instance[services.size()]; int[] spos = new int[services.size()]; int ipos = 0; - Vector svcUrls = getServiceUrls(); + List svcUrls = getServiceUrls(); for (Jws2Instance svc : services) { svcs[ipos] = svc; @@ -290,11 +327,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } /** - * holds list of services. - */ - protected Vector services; - - /** * attach all available web services to the appropriate submenu in the given * JMenu */ @@ -545,7 +577,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { if (args.length > 0) { - testUrls = new Vector(); + testUrls = new ArrayList(); for (String url : args) { testUrls.add(url); @@ -592,8 +624,11 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } - private static Jws2Discoverer discoverer; - + /** + * Returns the singleton instance of this class. + * + * @return + */ public static Jws2Discoverer getDiscoverer() { if (discoverer == null) @@ -605,7 +640,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI public boolean hasServices() { - // TODO Auto-generated method stub return !running && services != null && services.size() > 0; } @@ -614,24 +648,19 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI return running; } - /** - * the jalview .properties entry for JWS2 URLS - */ - final static String JWS2HOSTURLS = "JWS2HOSTURLS"; - - public static void setServiceUrls(Vector urls) + public void setServiceUrls(List wsUrls) { - if (urls != null) + if (wsUrls != null && !wsUrls.isEmpty()) { - StringBuffer urlbuffer = new StringBuffer(); + StringBuilder urls = new StringBuilder(128); String sep = ""; - for (String url : urls) + for (String url : wsUrls) { - urlbuffer.append(sep); - urlbuffer.append(url); + urls.append(sep); + urls.append(url); sep = ","; } - Cache.setProperty(JWS2HOSTURLS, urlbuffer.toString()); + Cache.setProperty(JWS2HOSTURLS, urls.toString()); } else { @@ -639,18 +668,27 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } - private static Vector testUrls = null; - - public static Vector getServiceUrls() + /** + * Returns web service URLs, in the order in which they should be tried (or an + * empty list). + * + * @return + */ + public List getServiceUrls() { if (testUrls != null) { // return test urls, if there are any, instead of touching cache return testUrls; } - String surls = Cache.getDefault(JWS2HOSTURLS, - "http://www.compbio.dundee.ac.uk/jabaws"); - Vector urls = new Vector(); + List urls = new ArrayList(); + + if (this.preferredUrl != null) + { + urls.add(preferredUrl); + } + + String surls = Cache.getDefault(JWS2HOSTURLS, COMPBIO_JABAWS); try { StringTokenizer st = new StringTokenizer(surls, ","); @@ -659,40 +697,37 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI String url = null; try { - java.net.URL u = new java.net.URL(url = st.nextToken()); + url = st.nextToken(); + new URL(url); if (!urls.contains(url)) { urls.add(url); } else { - jalview.bin.Cache.log.info("Ignoring duplicate url in " + Cache.log.info("Ignoring duplicate url " + url + " in " + JWS2HOSTURLS + " list"); } - } catch (Exception ex) + } catch (MalformedURLException ex) { - jalview.bin.Cache.log + Cache.log .warn("Problem whilst trying to make a URL from '" + ((url != null) ? url : "") + "'"); - jalview.bin.Cache.log + Cache.log .warn("This was probably due to a malformed comma separated list" + " in the " + JWS2HOSTURLS + " entry of $(HOME)/.jalview_properties)"); - jalview.bin.Cache.log.debug("Exception was ", ex); + Cache.log.debug("Exception was ", ex); } } } catch (Exception ex) { - jalview.bin.Cache.log.warn( + Cache.log.warn( "Error parsing comma separated list of urls in " + JWS2HOSTURLS + " preference.", ex); } - if (urls.size() >= 0) - { - return urls; - } - return null; + return urls; } public Vector getServices() @@ -750,9 +785,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI return thr; } - Vector invalidServiceUrls = null, urlsWithoutServices = null, - validServiceUrls = null; - /** * @return the invalidServiceUrls */ @@ -865,7 +897,9 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI return 1; } if (urlsWithoutServices != null && urlsWithoutServices.contains(url)) + { return 0; + } if (invalidServiceUrls != null && invalidServiceUrls.contains(url)) { return -1; @@ -979,4 +1013,21 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { setPreferredServiceFor(null, serviceType, serviceAction, selectedServer); } + + /** + * Set a URL to try before any others. For use with command-line parameter to + * configure a local Jabaws installation without the need to add to property + * files. + * + * @param value + * @throws MalformedURLException + */ + public void setPreferredUrl(String value) throws MalformedURLException + { + if (value != null && value.trim().length() > 0) + { + new URL(value); + preferredUrl = value; + } + } } diff --git a/test/jalview/commands/EditCommandTest.java b/test/jalview/commands/EditCommandTest.java new file mode 100644 index 0000000..fc821b9 --- /dev/null +++ b/test/jalview/commands/EditCommandTest.java @@ -0,0 +1,232 @@ +package jalview.commands; + +import static org.junit.Assert.assertEquals; +import jalview.commands.EditCommand.Action; +import jalview.commands.EditCommand.Edit; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Unit tests for EditCommand + * + * @author gmcarstairs + * + */ +public class EditCommandTest +{ + + private EditCommand testee; + + private SequenceI[] seqs; + + private Alignment al; + + @Before + public void setUp() + { + testee = new EditCommand(); + seqs = new SequenceI[4]; + seqs[0] = new Sequence("seq0", "abcdefghjk"); + seqs[1] = new Sequence("seq1", "fghjklmnopq"); + seqs[2] = new Sequence("seq2", "qrstuvwxyz"); + seqs[3] = new Sequence("seq3", "1234567890"); + al = new Alignment(seqs); + al.setGapCharacter('?'); + } + + /** + * Test inserting gap characters + */ + @Test + public void testAppendEdit_insertGap() + { + // set a non-standard gap character to prove it is actually used + testee.appendEdit(Action.INSERT_GAP, seqs, 4, 3, al, true); + assertEquals("abcd???efghjk", seqs[0].getSequenceAsString()); + assertEquals("fghj???klmnopq", seqs[1].getSequenceAsString()); + assertEquals("qrst???uvwxyz", seqs[2].getSequenceAsString()); + assertEquals("1234???567890", seqs[3].getSequenceAsString()); + + // todo: test for handling out of range positions? + } + + /** + * Test deleting characters from sequences. Note the deleteGap() action does + * not check that only gap characters are being removed. + */ + @Test + public void testAppendEdit_deleteGap() + { + testee.appendEdit(Action.DELETE_GAP, seqs, 4, 3, al, true); + assertEquals("abcdhjk", seqs[0].getSequenceAsString()); + assertEquals("fghjnopq", seqs[1].getSequenceAsString()); + assertEquals("qrstxyz", seqs[2].getSequenceAsString()); + assertEquals("1234890", seqs[3].getSequenceAsString()); + } + + /** + * Test a cut action. The command should store the cut characters to support + * undo. + */ + @Test + public void testCut() + { + Edit ec = testee.new Edit(Action.CUT, seqs, 4, 3, al); + testee.cut(ec, new AlignmentI[] + { al }); + assertEquals("abcdhjk", seqs[0].getSequenceAsString()); + assertEquals("fghjnopq", seqs[1].getSequenceAsString()); + assertEquals("qrstxyz", seqs[2].getSequenceAsString()); + assertEquals("1234890", seqs[3].getSequenceAsString()); + + assertEquals("efg", new String(ec.string[0])); + assertEquals("klm", new String(ec.string[1])); + assertEquals("uvw", new String(ec.string[2])); + assertEquals("567", new String(ec.string[3])); + // TODO: case where whole sequence is deleted as nothing left; etc + } + + /** + * Test a Paste action, where this adds sequences to an alignment. + */ + @Test + @Ignore + // TODO fix so it works + public void testPaste_addToAlignment() + { + SequenceI[] newSeqs = new SequenceI[2]; + newSeqs[0] = new Sequence("newseq0", "ACEFKL"); + newSeqs[1] = new Sequence("newseq1", "JWMPDH"); + + Edit ec = testee.new Edit(Action.PASTE, newSeqs, 0, al.getWidth(), al); + testee.paste(ec, new AlignmentI[] + { al }); + assertEquals(6, al.getSequences().size()); + assertEquals("1234567890", seqs[3].getSequenceAsString()); + assertEquals("ACEFKL", seqs[4].getSequenceAsString()); + assertEquals("JWMPDH", seqs[5].getSequenceAsString()); + } + + /** + * Test insertGap followed by undo command + */ + @Test + public void testUndo_insertGap() + { + // Edit ec = testee.new Edit(Action.INSERT_GAP, seqs, 4, 3, '?'); + testee.appendEdit(Action.INSERT_GAP, seqs, 4, 3, al, true); + // check something changed + assertEquals("abcd???efghjk", seqs[0].getSequenceAsString()); + testee.undoCommand(new AlignmentI[] + { al }); + assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); + assertEquals("fghjklmnopq", seqs[1].getSequenceAsString()); + assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString()); + assertEquals("1234567890", seqs[3].getSequenceAsString()); + } + + /** + * Test deleteGap followed by undo command + */ + @Test + public void testUndo_deleteGap() + { + testee.appendEdit(Action.DELETE_GAP, seqs, 4, 3, al, true); + // check something changed + assertEquals("abcdhjk", seqs[0].getSequenceAsString()); + testee.undoCommand(new AlignmentI[] + { al }); + // deleteGap doesn't 'remember' deleted characters, only gaps get put back + assertEquals("abcd???hjk", seqs[0].getSequenceAsString()); + assertEquals("fghj???nopq", seqs[1].getSequenceAsString()); + assertEquals("qrst???xyz", seqs[2].getSequenceAsString()); + assertEquals("1234???890", seqs[3].getSequenceAsString()); + } + + /** + * Test several commands followed by an undo command + */ + @Test + public void testUndo_multipleCommands() + { + // delete positions 3/4/5 (counting from 1) + testee.appendEdit(Action.DELETE_GAP, seqs, 2, 3, al, true); + assertEquals("abfghjk", seqs[0].getSequenceAsString()); + assertEquals("1267890", seqs[3].getSequenceAsString()); + + // insert 2 gaps after the second residue + testee.appendEdit(Action.INSERT_GAP, seqs, 2, 2, al, true); + assertEquals("ab??fghjk", seqs[0].getSequenceAsString()); + assertEquals("12??67890", seqs[3].getSequenceAsString()); + + // delete positions 4/5/6 + testee.appendEdit(Action.DELETE_GAP, seqs, 3, 3, al, true); + assertEquals("ab?hjk", seqs[0].getSequenceAsString()); + assertEquals("12?890", seqs[3].getSequenceAsString()); + + // undo edit commands + testee.undoCommand(new AlignmentI[] + { al }); + assertEquals("ab?????hjk", seqs[0].getSequenceAsString()); + assertEquals("12?????890", seqs[3].getSequenceAsString()); + } + + /** + * Unit test for JAL-1594 bug: click and drag sequence right to insert gaps - + * undo did not remove them all. + */ + @Test + public void testUndo_multipleInsertGaps() + { + testee.appendEdit(Action.INSERT_GAP, seqs, 4, 1, al, true); + testee.appendEdit(Action.INSERT_GAP, seqs, 5, 1, al, true); + testee.appendEdit(Action.INSERT_GAP, seqs, 6, 1, al, true); + + // undo edit commands + testee.undoCommand(new AlignmentI[] + { al }); + assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); + assertEquals("1234567890", seqs[3].getSequenceAsString()); + + } + + /** + * Test cut followed by undo command + */ + @Test + public void testUndo_cut() + { + testee.appendEdit(Action.CUT, seqs, 4, 3, al, true); + // check something changed + assertEquals("abcdhjk", seqs[0].getSequenceAsString()); + testee.undoCommand(new AlignmentI[] + { al }); + assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); + assertEquals("fghjklmnopq", seqs[1].getSequenceAsString()); + assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString()); + assertEquals("1234567890", seqs[3].getSequenceAsString()); + } + + /** + * Test the replace command (used to manually edit a sequence) + */ + @Test + public void testReplace() + { + // seem to need a dataset sequence on the edited sequence here + seqs[1].setDatasetSequence(seqs[1]); + new EditCommand("", Action.REPLACE, "ZXY", new SequenceI[] + { seqs[1] }, 4, 8, al); + assertEquals("abcdefghjk", seqs[0].getSequenceAsString()); + assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString()); + assertEquals("1234567890", seqs[3].getSequenceAsString()); + seqs[1] = new Sequence("seq1", "fghjZXYnopq"); + + } +} diff --git a/test/jalview/io/BioJsHTMLOutputTest.java b/test/jalview/io/BioJsHTMLOutputTest.java new file mode 100644 index 0000000..cbda794 --- /dev/null +++ b/test/jalview/io/BioJsHTMLOutputTest.java @@ -0,0 +1,47 @@ +package jalview.io; + +import jalview.datamodel.Alignment; +import jalview.datamodel.Sequence; + +import java.io.IOException; + +import org.junit.Test; + +import com.json.JSONException; + +public class BioJsHTMLOutputTest +{ + + + @Test + public void getJalviewAlignmentAsJsonString() + { + BioJsHTMLOutput bioJsHtmlOuput = new BioJsHTMLOutput(null, null); + bioJsHtmlOuput.setGlobalColorScheme("Zappo"); + + Sequence[] seqs = new Sequence[1]; + Sequence seq = new Sequence("name", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26); + // SequenceFeature seqFeature = new SequenceFeature("type", "desc", + // "status", 1, 5, "jalview"); + // seq.addSequenceFeature(seqFeature); + seq.setDatasetSequence(seq); + seqs[0] = seq; + + Alignment al = new Alignment(seqs); + try + { + String generatedJson = bioJsHtmlOuput + .getJalviewAlignmentAsJsonString(al); + assert (generatedJson + .equalsIgnoreCase("{\"globalColorScheme\":\"zappo\",\"seqs\":[{\"id\":\"1\",\"start\":1,\"name\":\"name/1-26\",\"features\":[],\"seq\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"end\":26}]}")); + System.out.println("Output : " + generatedJson); + } catch (IOException e) + { + e.printStackTrace(); + } catch (JSONException e) + { + e.printStackTrace(); + } + } + +} diff --git a/test/jalview/io/HtmlFileTest.java b/test/jalview/io/HtmlFileTest.java new file mode 100644 index 0000000..be228b8 --- /dev/null +++ b/test/jalview/io/HtmlFileTest.java @@ -0,0 +1,16 @@ +package jalview.io; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class HtmlFileTest +{ + + @Test + public void test() + { + fail("Not yet implemented"); + } + +} diff --git a/test/jalview/io/RNAMLfileTest.java b/test/jalview/io/RNAMLfileTest.java index 5839761..f5b0258 100644 --- a/test/jalview/io/RNAMLfileTest.java +++ b/test/jalview/io/RNAMLfileTest.java @@ -20,8 +20,6 @@ */ package jalview.io; -import static org.junit.Assert.*; - import java.io.File; import org.junit.AfterClass; @@ -45,7 +43,7 @@ public class RNAMLfileTest public void testRnamlToStockholmIO() { StockholmFileTest.testFileIOwithFormat(new File( - "examples/rna-alignment.xml"), "STH"); + "examples/rna-alignment.xml"), "STH", -1, -1); } diff --git a/test/jalview/io/StockholmFileTest.java b/test/jalview/io/StockholmFileTest.java index 8fece9d..cf61e6e 100644 --- a/test/jalview/io/StockholmFileTest.java +++ b/test/jalview/io/StockholmFileTest.java @@ -20,6 +20,7 @@ */ package jalview.io; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import jalview.datamodel.Alignment; @@ -45,7 +46,7 @@ public class StockholmFileTest @Test public void pfamFileIO() throws Exception { - testFileIOwithFormat(new File(PfamFile), "STH"); + testFileIOwithFormat(new File(PfamFile), "STH", -1, 0); } @Test @@ -70,7 +71,7 @@ public class StockholmFileTest @Test public void rfamFileIO() throws Exception { - testFileIOwithFormat(new File(RfamFile), "STH"); + testFileIOwithFormat(new File(RfamFile), "STH", 2, 1); } /** @@ -83,7 +84,8 @@ public class StockholmFileTest * - label for IO class used to write and read back in the data from * f */ - public static void testFileIOwithFormat(File f, String ioformat) + public static void testFileIOwithFormat(File f, String ioformat, + int naliannot, int nminseqann) { System.out.println("Reading file: " + f); String ff = f.getPath(); @@ -118,6 +120,28 @@ public class StockholmFileTest + ioformat + "' writer", ioformat.equals(identifyoutput)); testAlignmentEquivalence(al, al_input); + int numaliannot = 0, numsqswithali = 0; + for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation()) + { + if (ala.sequenceRef == null) + { + numaliannot++; + } + else + { + numsqswithali++; + } + } + if (naliannot > -1) + { + assertEquals("Number of alignment annotations", naliannot, + numaliannot); + } + + assertTrue( + "Number of sequence associated annotations wasn't at least " + + nminseqann, numsqswithali >= nminseqann); + } catch (Exception e) { e.printStackTrace(); diff --git a/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java b/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java index 295c3bf..c206323 100644 --- a/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java +++ b/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java @@ -20,7 +20,8 @@ */ package jalview.ws.jabaws; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import jalview.ws.jws2.Jws2Discoverer; import java.util.Vector; @@ -73,7 +74,7 @@ public class JalviewJabawsTestUtils services.add(url); } ; - Jws2Discoverer.setServiceUrls(services); + Jws2Discoverer.getDiscoverer().setServiceUrls(services); } try { diff --git a/utils/InstallAnywhere/Jalview.iap_xml b/utils/InstallAnywhere/Jalview.iap_xml index c938a0b..41ca030 100755 --- a/utils/InstallAnywhere/Jalview.iap_xml +++ b/utils/InstallAnywhere/Jalview.iap_xml @@ -1040,6 +1040,58 @@ and any path to a file to save to the file]]> + + + + + + false + + + true + + + true + + + + + + + + + + + + false + + + + + + true + + + true + + + true + + + + + + 348699 + + + false + + + 0 + + + + @@ -6185,6 +6237,7 @@ and any path to a file to read from that file]]> + @@ -6922,6 +6975,7 @@ and any path to a file to read from that file]]> +