From 70654ad85b5ca344793b0a199107fec66facbda6 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 16 Nov 2004 15:22:09 +0000 Subject: [PATCH] Make sure we're talking about the same alignment! --- src/jalview/gui/SeqPanel.java | 203 ++++++++++++++++++++++++++++++++--------- 1 file changed, 161 insertions(+), 42 deletions(-) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 5895fe3..b650c9a 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -5,12 +5,12 @@ import java.awt.event.*; import jalview.datamodel.*; import javax.swing.*; import jalview.schemes.*; +import jalview.analysis.*; public class SeqPanel extends JPanel { - public AlignmentI align; public SeqCanvas seqCanvas; public AlignmentPanel parent; @@ -26,7 +26,6 @@ public class SeqPanel extends JPanel public SeqPanel(AlignViewport av, AlignmentPanel p) { this.av = av; - this.align = av.getAlignment(); seqCanvas = new SeqCanvas(av); setLayout(new BorderLayout()); @@ -39,15 +38,15 @@ public class SeqPanel extends JPanel public void mouseMoved(MouseEvent evt) { doMouseMoved(evt); } public void mouseDragged(MouseEvent evt) - { doMouseDragged(evt); } + { doMouseDragged(evt); } }); addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent evt) - { doMouseReleased(evt); } + { doMouseReleased(evt); } public void mousePressed(MouseEvent evt) - { doMousePressed(evt); } + { doMousePressed(evt); } }); repaint(); @@ -73,6 +72,7 @@ public class SeqPanel extends JPanel } public void doMousePressed(MouseEvent evt) { + parent.alignFrame.addHistoryItem("sequence edit"); int seq; int res; @@ -82,7 +82,7 @@ public class SeqPanel extends JPanel res = (int)(x/av.getCharWidth()) + av.getStartRes(); seq = (y)/av.getCharHeight() + av.getStartSeq(); - if (seq < align.getHeight() && res < align.getSequenceAt(seq).getLength()) + if (seq < av.getAlignment().getHeight() && res < av.getAlignment().getSequenceAt(seq).getLength()) { //char resstr = align.getSequenceAt(seq).getSequence().charAt(res); // Find the residue's position in the sequence (res is the position @@ -90,7 +90,7 @@ public class SeqPanel extends JPanel startseq = seq; - if (startseq == (align.getHeight()-1)) { + if (startseq == (av.getAlignment().getHeight()-1)) { padseq = 1; } else { padseq = 1; @@ -110,9 +110,31 @@ public class SeqPanel extends JPanel public void doMouseMoved(MouseEvent evt) { + int res=0, seq=0; + int x = evt.getX(); + int y = evt.getY(); + if(av.wrapAlignment) + { + y -= 2*av.charHeight; + int chunkHeight = (av.getAlignment().getHeight()+2)*av.charHeight; + + + res = (int)((y/chunkHeight)*(getWidth()/av.charWidth)) + (int)(x/av.getCharWidth()) + av.getStartRes(); + + System.out.println( ((y/chunkHeight)*(getWidth()/av.charWidth)) +" "+((x / av.getCharWidth()) + av.getStartRes()) ); + y %= chunkHeight; + seq = y / av.getCharHeight() + av.getStartSeq(); + + // chunkHeight = (da.getHeight() + 2)*charHeight; + // startx += chunkWidth; + } + else + { + res = (int) (x / av.getCharWidth()) + av.getStartRes(); + seq = y / av.getCharHeight() + av.getStartSeq(); + } + - int res = (int)(evt.getX()/av.getCharWidth()) + av.getStartRes(); - int seq = (evt.getY())/av.getCharHeight() + av.getStartSeq(); if(seq>=av.getAlignment().getHeight()) return; @@ -121,7 +143,7 @@ public class SeqPanel extends JPanel if(obj!=null) aa = obj.toString(); - StringBuffer text = new StringBuffer("Sequence " +seq+" ID: "+av.getAlignment().getSequenceAt(seq).getName()); + StringBuffer text = new StringBuffer("Sequence " +(seq+1)+" ID: "+av.getAlignment().getSequenceAt(seq).getName()); if(aa!="") text.append(" Residue: "+aa+" ("+ av.getAlignment().getSequenceAt(seq).findPosition(res)+")"); @@ -132,7 +154,6 @@ public class SeqPanel extends JPanel public void doMouseDragged(MouseEvent evt) { // If we're dragging we're editing editFlag = true; - int x = evt.getX(); int res = (int)(x/av.getCharWidth()) + av.getStartRes(); @@ -143,19 +164,23 @@ public class SeqPanel extends JPanel // Group editing if (av.getGroupEdit()) { - SequenceGroup sg = align.findGroup(startseq); + SequenceGroup sg = av.getAlignment().findGroup(startseq); - if (res < align.getWidth() && res < lastres) { + if(sg!=null) + if (res < av.getAlignment().getWidth() && res < lastres) + { boolean flag = false; - for (int i= 0 ; i < sg.getSize(); i++) { + for (int i= 0 ; i < sg.getSize(); i++) + { SequenceI s = (SequenceI)sg.getSequenceAt(i); - for (int j=lastres-1; j >= res; j--) { - if (!flag) { - if (!s.getSequence().substring(j,j+1).equals(align.getGapCharacter()) && - !s.getSequence().substring(j,j+1).equals(" ")) { + for (int j=lastres-1; j >= res; j--) + { + if (!flag) + { + if (!s.getSequence().substring(j,j+1).equals(av.getAlignment().getGapCharacter()) && + !s.getSequence().substring(j,j+1).equals(" ")) + { res = j+1; - System.out.print("\07"); - System.out.flush(); flag = true; } } @@ -163,14 +188,15 @@ public class SeqPanel extends JPanel } } + if(sg!=null) for (int i= 0 ; i < sg.getSize(); i++) { SequenceI s = (SequenceI)sg.getSequenceAt(i); boolean found = false; int sno = -1; - for (int k = 0; k < align.getHeight(); k++) + for (int k = 0; k < av.getAlignment().getHeight(); k++) { - if (align.getSequenceAt(k) == s) + if (av.getAlignment().getSequenceAt(k) == s) { found = true; sno = k; @@ -178,24 +204,24 @@ public class SeqPanel extends JPanel } } if (found && sno != -1) { - if (res < align.getWidth() && res > lastres) + if (res < av.getAlignment().getWidth() && res > lastres) { for (int j = lastres; j < res; j++) insertChar(j,sno); - int index = align.findIndex(s); + int index = av.getAlignment().findIndex(s); if (index != -1) drawChars(index,index+1,lastres); - } else if (res < align.getWidth() && res < lastres) + } else if (res < av.getAlignment().getWidth() && res < lastres) { for (int j = res; j < lastres; j++) { deleteChar(j,res,sno); startres = res; } - int index = align.findIndex(s); + int index = av.getAlignment().findIndex(s); if (index != -1) drawChars(index,index+1,res); @@ -207,15 +233,15 @@ public class SeqPanel extends JPanel } else { - if (res < align.getWidth() && res > lastres) { + if (res < av.getAlignment().getWidth() && res > lastres) { // dragging to the right for (int j = lastres; j < res; j++) - { insertChar(j,startseq); - } + drawChars(startseq,startseq+1,lastres); - } else if (res < align.getWidth() && res < lastres) { + } else if (res < av.getAlignment().getWidth() && res < lastres) + { // dragging to the left for (int j = res; j < lastres; j++) { @@ -240,36 +266,129 @@ public class SeqPanel extends JPanel public void insertChar(int j, int seq) { - align.getSequenceAt(seq).insertCharAt(j, av.getGapCharacter().charAt(0)); + av.getAlignment().getSequenceAt(seq).insertCharAt(j, av.getGapCharacter().charAt(0)); + updateConservation(seq); } public void deleteChar(int j, int res, int sno) { - if (align.getSequenceAt(sno).getSequence().substring(j,j+1).equals(".") || - align.getSequenceAt(sno).getSequence().substring(j,j+1).equals("-") || - align.getSequenceAt(sno).getSequence().substring(j,j+1).equals(" ") ) + if (av.getAlignment().getSequenceAt(sno).getSequence().substring(j,j+1).equals(".") || + av.getAlignment().getSequenceAt(sno).getSequence().substring(j,j+1).equals("-") || + av.getAlignment().getSequenceAt(sno).getSequence().substring(j,j+1).equals(" ") ) { - align.getSequenceAt(sno).deleteCharAt(j); + av.getAlignment().getSequenceAt(sno).deleteCharAt(j); } - - align.getWidth(); + updateConservation(sno); + av.getAlignment().getWidth(); repaint(); } - public void setColourScheme(ColourSchemeI cs) + + void updateConservation(int i) { - seqCanvas.cs = cs; + + Alignment al = (Alignment) av.getAlignment(); + SequenceGroup sg = av.alignment.findGroup( al.getSequenceAt(i)); + if(sg==null || !(sg.cs instanceof ConservationColourScheme)) + return; + + Conservation c = sg.getConservation(); + + c = new Conservation("All", al.cons, + ResidueProperties.propHash, 3, sg.sequences, 0, + al.getWidth()); + c.calculate(); + c.verdict(false, 100); + sg.setConservation(c); + ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; + ccs.conserve = c; + // sg.cs = new ConservationColourScheme(sg); + } + + public void setColourScheme(ColourSchemeI cs, boolean showConservation) + { + if (av.getSelection().size() == 0) + { + seqCanvas.cs = cs; + for (int i = 0; i < av.alignment.getGroups().size();i++) + { + SequenceGroup sg = (SequenceGroup)av.alignment.getGroups().elementAt(i); + sg.cs = cs; + if(!showConservation + && !(sg.cs instanceof Blosum62ColourScheme) + && sg.cs instanceof ConservationColourScheme) + { + // remove ConservationColouring from existing Conservation group + ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; + sg.cs = ccs.cs; + } + else if(showConservation && !(sg.cs instanceof ConservationColourScheme)) + { + // add ConservationColouring to new group + Conservation c = sg.getConservation(); + Alignment al = (Alignment) av.getAlignment(); + c = new Conservation("All", al.cons, + ResidueProperties.propHash, 3, sg.sequences, 0, + al.getWidth() ); + c.calculate(); + c.verdict(false, 100); + sg.setConservation(c); + sg.cs = new ConservationColourScheme(sg); + } + + + } + } + else + { + SequenceGroup sg = av.alignment.addGroup(); + sg.cs = cs; + + for (int i=0; i < av.getSelection().size(); i++) + { + av.alignment.removeFromGroup(av.alignment.findGroup((Sequence)av.sel.sequenceAt(i)), + (Sequence)av.sel.sequenceAt(i)); + av.alignment.addToGroup(sg,(Sequence)av.sel.sequenceAt(i)); + } + + // Selection is made, we only want to change the conservationColour for selected group + if( showConservation + && !(sg.cs instanceof ConservationColourScheme) + && !(sg.cs instanceof Blosum62ColourScheme)) + { + Conservation c = sg.getConservation(); + Alignment al = (Alignment) av.getAlignment(); + + c = new Conservation("All", al.cons, + ResidueProperties.propHash, 3, sg.sequences, 0, + al.getWidth() ); + c.calculate(); + c.verdict(false, 100); + sg.setConservation(c); + sg.cs = new ConservationColourScheme(sg); + } + else if( !showConservation && sg.cs instanceof ConservationColourScheme) + { + ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; + sg.cs = ccs.cs; + } + + + + } seqCanvas.paintFlag = true; repaint(); } + public ColourSchemeI getColourScheme() { - return seqCanvas.cs; + if(av.getSelection().size()>0) + return av.alignment.findGroup((Sequence)av.sel.sequenceAt(0)).cs; + else + return seqCanvas.cs; } - - } -- 1.7.10.2