X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=9d63cde5867d0e4abe881d47f7777e9260d9bf18;hb=24efbd38f2c3dceaf6d3e305eef41ba0b0c9ebdc;hp=03e0c5a95b65a9cd1639b43fb187bb00e1180332;hpb=d6d520d7e8f262d0570ebb8ffc729cab87bb280a;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 03e0c5a..9d63cde 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,9 +1,10 @@ package jalview.gui; import java.awt.*; -import jalview.io.*; +import jalview.analysis.*; import jalview.analysis.NJTree; import jalview.datamodel.*; +import jalview.schemes.*; import java.util.*; public class AlignViewport @@ -14,118 +15,199 @@ public class AlignViewport int startSeq; int endSeq; - boolean showScores=false; + boolean showFullId = false; boolean showText=true; boolean showColourText=false; boolean showBoxes=true; boolean wrapAlignment=false; - boolean renderGaps = false; + boolean renderGaps = true; + boolean showSequenceFeatures = false; + boolean showAnnotation = true; - boolean groupEdit = false; + boolean colourAppliesToAllGroups = true; + ColourSchemeI globalColourScheme = null; + boolean conservationColourSelected = false; + boolean abovePIDThreshold = false; - RendererI renderer = new SequenceRenderer(); + SequenceGroup selectionGroup = new SequenceGroup(); + + RendererI renderer = new SequenceRenderer(this); int charHeight; - double charWidth; + int charWidth; int chunkWidth; int chunkHeight; - Color backgroundColour; - Font font = new Font("SansSerif",Font.PLAIN,10); AlignmentI alignment; - Selection sel = new Selection(); ColumnSelection colSel = new ColumnSelection(); - OutputGenerator og; - - String visibleConsensus; - int threshold; int increment; NJTree currentTree = null; - int window = 50; - int baseline = 30; - - Vector kmers; - public AlignViewport(AlignmentI da, - boolean showScores, + public AlignViewport(AlignmentI al, boolean showText, boolean showBoxes, boolean wrapAlignment) { - this(0,da.getWidth()-1,0,da.getHeight()-1,showScores, - showText, - showBoxes, - wrapAlignment); - setAlignment(da); - } + this.startRes = 0; + this.endRes = al.getWidth()-1; + this.startSeq = 0; + this.endSeq = al.getHeight()-1; + this.showText = showText; + this.showBoxes = showBoxes; + this.wrapAlignment = wrapAlignment; - public AlignViewport(int startRes, int endRes, - int startSeq, int endSeq, - boolean showScores, - boolean showText, - boolean showBoxes, - boolean wrapAlignment) { + setAlignment(al); + setFont( font ); + } - this.startRes = startRes; - this.endRes = endRes; - this.startSeq = startSeq; - this.endSeq = endSeq; + public void showSequenceFeatures(boolean b) + { + showSequenceFeatures = b; + } - this.showScores = showScores; - this.showText = showText; - this.showBoxes = showBoxes; - this.wrapAlignment = wrapAlignment; + AlignmentAnnotation consensus; + AlignmentAnnotation conservation; + public void updateConservation() + { + Annotation [] annotations = new Annotation[alignment.getWidth()]; - // og = new AlignmentOutputGenerator(this); + Conservation cons = new jalview.analysis.Conservation("All", + jalview.schemes.ResidueProperties.propHash, 3, + alignment.getSequences(), 0, + alignment.getWidth()); + cons.calculate(); + cons.verdict(false, 100); - setFont( font ); - } + String sequence = cons.getConsSequence().getSequence(); + for (int i = 0; i < alignment.getWidth(); i++) + { + int value = 0; + try + { + value = Integer.parseInt(sequence.charAt(i) + ""); + } + catch (Exception ex) + { + if (sequence.charAt(i) == '*') value = 10; + } - public AlignViewport(int startRes, int endRes, - int startSeq, int endSeq, - boolean showScores, - boolean showText, - boolean showBoxes, - boolean wrapAlignment, - Color backgroundColour) { - this(startRes,endRes,startSeq,endSeq,showScores,showText,showBoxes,wrapAlignment); + annotations[i] = new Annotation(sequence.charAt(i) + "", + "Conservation graph", ' ', value); + } + + if(conservation==null) + { + conservation = new AlignmentAnnotation("Conservation", + "Conservation of total alignment", + annotations, 0, 10, 1); + alignment.addAnnotation(conservation); + } + else + conservation.annotations = annotations; - this.backgroundColour = backgroundColour; } + public void updateConsensus() + { + Annotation [] annotations = new Annotation[alignment.getWidth()]; + + Vector cons = alignment.getAAFrequency(); + Hashtable hash = null; + for (int i = 0; i < alignment.getWidth(); i++) + { + hash = (Hashtable) cons.elementAt(i); + float value = Float.parseFloat(hash.get("maxCount").toString()); + value /= Float.parseFloat(hash.get("size").toString()); + + value *= 100; + String maxRes = hash.get("maxResidue")+" "; + String mouseOver = hash.get("maxResidue")+" "; + if(maxRes.length()>2) + { + mouseOver = "["+maxRes+"] "; + maxRes = "+ "; + } + + mouseOver += (int)value+"%"; + annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); + + } + + if(consensus==null) + { + consensus = new AlignmentAnnotation("% Identity", + "PID", annotations, 0f, 100f, 1); + alignment.addAnnotation(consensus); + } + else + consensus.annotations = annotations; + + } public String getVisibleConsensus() { return visibleConsensus; } - Vector consensus = new Vector(); + String visibleConsensus; + Vector consensusV = new Vector(); public Vector getConsensus(boolean recalculate) { - if(recalculate || consensus.size()<1) + if(recalculate || consensusV.size()<1) { - consensus = alignment.getAAFrequency(); + consensusV = alignment.getAAFrequency(); StringBuffer sb = new StringBuffer(); Hashtable hash = null; - for (int i = 0; i < consensus.size(); i++) + for (int i = 0; i < consensusV.size(); i++) { - hash = (Hashtable) consensus.elementAt(i); + hash = (Hashtable) consensusV.elementAt(i); sb.append(hash.get("maxResidue").toString().charAt(0)); } visibleConsensus = sb.toString(); } - return consensus; + return consensusV; + } + + + public SequenceGroup getSelectionGroup() + { + return selectionGroup; + } + + public void setSelectionGroup(SequenceGroup sg) + { + selectionGroup = sg; } + public boolean getConservationSelected() + { + return conservationColourSelected; + } + + public void setConservationSelected(boolean b) + { + conservationColourSelected = b; + } + + public boolean getAbovePIDThreshold() + { + return abovePIDThreshold; + } + + public void setAbovePIDThreshold(boolean b) + { + abovePIDThreshold = b; + } + public int getStartRes() { return startRes; } @@ -138,6 +220,16 @@ public class AlignViewport return startSeq; } + public void setGlobalColourScheme(ColourSchemeI cs) + { + globalColourScheme = cs; + } + + public ColourSchemeI getGlobalColourScheme() + { + return globalColourScheme; + } + public void setStartRes(int res) { this.startRes = res; @@ -180,10 +272,10 @@ public class AlignViewport public Font getFont() { return font; } - public void setCharWidth(double w) { + public void setCharWidth(int w) { this.charWidth = w; } - public double getCharWidth() { + public int getCharWidth() { return charWidth; } public void setCharHeight(int h) { @@ -210,9 +302,7 @@ public class AlignViewport public void setAlignment(AlignmentI align) { this.alignment = align; } - public void setShowScores(boolean state) { - showScores = state; - } + public void setWrapAlignment(boolean state) { wrapAlignment = state; } @@ -243,9 +333,7 @@ public class AlignViewport public void setShowBoxes(boolean state) { showBoxes = state; } - public boolean getShowScores() { - return showScores; - } + public boolean getWrapAlignment() { return wrapAlignment; } @@ -255,15 +343,7 @@ public class AlignViewport public boolean getShowBoxes() { return showBoxes; } - // public CommandParser getCommandLog() { - /// return log; - // } - public boolean getGroupEdit() { - return groupEdit; - } - public void setGroupEdit(boolean state) { - groupEdit = state; - } + public char getGapCharacter() { return getAlignment().getGapCharacter(); } @@ -303,17 +383,12 @@ public class AlignViewport } return -1; } - public Selection getSelection() { - return sel; - } + public ColumnSelection getColumnSelection() { return colSel; } - public OutputGenerator getOutputGenerator() { - return og; - } + public void resetSeqLimits(int height) { - setStartSeq(0); setEndSeq(height/getCharHeight()); } public void setCurrentTree(NJTree tree) { @@ -330,27 +405,31 @@ public class AlignViewport public RendererI getRenderer() { return renderer; } - public int getPIDWindow() { - return window; - } - public void setPIDWindow(int window) { - this.window = window; - } - public int getPIDBaseline() { - return baseline; - } - public void setPIDBaseline(int baseline) { - this.baseline = baseline; - } + public void setColourAppliesToAllGroups(boolean b) + { colourAppliesToAllGroups = b; } - public void setKmers(Vector kmers) { - this.kmers = kmers; - } + public boolean getColourAppliesToAllGroups() + {return colourAppliesToAllGroups; } - public Vector getKmers() { - return this.kmers; - } + public boolean getShowFullId() + { + return showFullId; + } + + public void setShowFullId(boolean b) + { + showFullId = b; + } + public boolean getShowAnnotation() + { + return showAnnotation; + } + + public void setShowAnnotation(boolean b) + { + showAnnotation = b; + } }