diff --git a/uk/ac/sanger/artemis/plot/BaseAlgorithm.java b/uk/ac/sanger/artemis/plot/BaseAlgorithm.java index 20cd71a29e55bae851b7414dc8b3772855a89f27..36136f881ee296b1b5a16068a5ab393ebc60a11a 100644 --- a/uk/ac/sanger/artemis/plot/BaseAlgorithm.java +++ b/uk/ac/sanger/artemis/plot/BaseAlgorithm.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/BaseAlgorithm.java,v 1.6 2004-12-02 16:52:54 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/BaseAlgorithm.java,v 1.7 2006-06-23 10:40:14 tjc Exp $ */ package uk.ac.sanger.artemis.plot; @@ -38,7 +38,7 @@ import java.awt.BasicStroke; * Strand of DNA, meaning the algorithm can't change strand part way along. * * @author Kim Rutherford - * @version $Id: BaseAlgorithm.java,v 1.6 2004-12-02 16:52:54 tjc Exp $ + * @version $Id: BaseAlgorithm.java,v 1.7 2006-06-23 10:40:14 tjc Exp $ **/ public abstract class BaseAlgorithm extends Algorithm @@ -117,7 +117,8 @@ public abstract class BaseAlgorithm extends Algorithm FontMetrics fm = g2d.getFontMetrics(); int lineHgt = 3 * font_height/4; - if(strand.isForwardStrand()) + if( (strand.isForwardStrand() && !isRevCompDisplay()) || + (!strand.isForwardStrand() && isRevCompDisplay())) { g2d.setColor(Color.black); g2d.drawString("1",0,font_height); @@ -138,13 +139,19 @@ public abstract class BaseAlgorithm extends Algorithm } else { + + /* + int frame = strand.getSequenceLength() % 3; g2d.setColor(Color.black); + g2d.drawString("4",0,font_height); g2d.drawString("5",font_width*5,font_height); g2d.drawString("6",font_width*10,font_height); BasicStroke stroke = (BasicStroke)g2d.getStroke(); g2d.setStroke(new BasicStroke(3.f)); + + g2d.setColor(frameColour[0]); g2d.drawLine(font_width*2, lineHgt, font_width*4, lineHgt); @@ -154,6 +161,50 @@ public abstract class BaseAlgorithm extends Algorithm g2d.setColor(frameColour[1]); g2d.drawLine(font_width*12, lineHgt, font_width*14, lineHgt); g2d.setStroke(stroke); + */ + + g2d.setColor(Color.black); + g2d.drawString("4",0,font_height); + g2d.drawString("5",font_width*5,font_height); + g2d.drawString("6",font_width*10,font_height); + + BasicStroke stroke = (BasicStroke)g2d.getStroke(); + g2d.setStroke(new BasicStroke(3.f)); + int frame = strand.getSequenceLength() % 3; + + //System.out.println("FRAME "+frame+" length="+strand.getSequenceLength()); + Color col4 = null; + Color col5 = null; + Color col6 = null; + + switch(frame) + { + case 0: + col4 = frameColour[1]; + col5 = frameColour[2]; + col6 = frameColour[0]; + break; + case 1: + col4 = frameColour[2]; + col5 = frameColour[0]; + col6 = frameColour[1]; + break; + case 2: + col4 = frameColour[0]; + col5 = frameColour[1]; + col6 = frameColour[2]; + break; + } + + g2d.setColor(col4); + g2d.drawLine(font_width*2, lineHgt, font_width*4, lineHgt); + + g2d.setColor(col5); + g2d.drawLine(font_width*7, lineHgt, font_width*9, lineHgt); + + g2d.setColor(col6); + g2d.drawLine(font_width*12, lineHgt, font_width*14, lineHgt); + g2d.setStroke(stroke); } } diff --git a/uk/ac/sanger/artemis/plot/Codon12CorrelationAlgorithm.java b/uk/ac/sanger/artemis/plot/Codon12CorrelationAlgorithm.java index d0359ea34e9ce545e35e4188c2a687e975c049d1..d88e8202043544e727e0a128a3d068a4843ab048 100644 --- a/uk/ac/sanger/artemis/plot/Codon12CorrelationAlgorithm.java +++ b/uk/ac/sanger/artemis/plot/Codon12CorrelationAlgorithm.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/Codon12CorrelationAlgorithm.java,v 1.3 2004-12-02 16:52:55 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/Codon12CorrelationAlgorithm.java,v 1.4 2006-06-23 10:40:14 tjc Exp $ */ package uk.ac.sanger.artemis.plot; @@ -38,7 +38,7 @@ import java.awt.*; * the given strand. The Strand to use is set in the constructor. * * @author Kim Rutherford - * @version $Id: Codon12CorrelationAlgorithm.java,v 1.3 2004-12-02 16:52:55 tjc Exp $ + * @version $Id: Codon12CorrelationAlgorithm.java,v 1.4 2006-06-23 10:40:14 tjc Exp $ **/ public class Codon12CorrelationAlgorithm extends BaseAlgorithm { @@ -101,24 +101,21 @@ public class Codon12CorrelationAlgorithm extends BaseAlgorithm else start += (end - start + 1) % 3; - final String sub_sequence; + final char[] sub_sequence_raw; try { - sub_sequence = getStrand().getRawSubSequence(new Range(start, end)); + sub_sequence_raw = getStrand().getRawSubSequenceC(new Range(start, end)); } catch(OutOfRangeException e) { throw new Error("internal error - unexpected exception: " + e); } - final char[] sub_sequence_raw = sub_sequence.toCharArray(); - final float gc_counts[] = new float[3]; // the first index is the position the second is the base (t,c,a,g) final int[][] positional_base_counts = new int[4][3]; - final int sub_sequence_length = sub_sequence_raw.length; if(getStrand().isForwardStrand()) @@ -132,10 +129,7 @@ public class Codon12CorrelationAlgorithm extends BaseAlgorithm } else { - final String complement_string = Bases.complement(sub_sequence); - - final char [] complement_sub_sequence_raw = - complement_string.toCharArray(); + final char[] complement_sub_sequence_raw = Bases.complement(sub_sequence_raw); for(int i = 0 ; i < sub_sequence_length ; ++i) { @@ -149,6 +143,9 @@ public class Codon12CorrelationAlgorithm extends BaseAlgorithm } } + final int whole_sequence_length = getStrand().getSequenceLength(); + final int whole_sequence_length_mod3 = whole_sequence_length % 3; + for(int frame = 0 ; frame < 3 ; ++frame) { final double cor1_2_score = @@ -181,10 +178,26 @@ public class Codon12CorrelationAlgorithm extends BaseAlgorithm correlation_score_factors_2[3]) + 0.5; // add 0.5 because that is what the old uk.ac.sanger.artemis did - values [(start + frame) % 3] = (float)cor1_2_score; + // add 2 brings the frame colouring in-line with codon usage + if(getStrand().isForwardStrand()) + values [(start + frame + 2) % 3] = (float)cor1_2_score; + else + values [(start + frame + whole_sequence_length_mod3 + 2) % 3] = (float)cor1_2_score; + } + + /* + for(int frame = 0 ; frame < 3 ; ++frame) + { + if(getStrand().isForwardStrand()) + System.out.println("FWD "+frame+" "+((start + frame + 2) % 3)); + else + System.out.println("BWD "+frame+" "+((start + frame + whole_sequence_length_mod3 -1) % 3)+ + " "+whole_sequence_length_mod3); } + */ } + /** * Return the number of values a call to getValues () will return - three * in this case. diff --git a/uk/ac/sanger/artemis/plot/CodonUsageAlgorithm.java b/uk/ac/sanger/artemis/plot/CodonUsageAlgorithm.java index cda00e027eb870c9ff48e1f1fc029be1fb97fc79..c5016fd6e89a90a58063e11be10868d3ec8f3284 100644 --- a/uk/ac/sanger/artemis/plot/CodonUsageAlgorithm.java +++ b/uk/ac/sanger/artemis/plot/CodonUsageAlgorithm.java @@ -20,11 +20,17 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/CodonUsageAlgorithm.java,v 1.1 2004-06-09 09:51:19 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/CodonUsageAlgorithm.java,v 1.2 2006-06-23 10:40:14 tjc Exp $ */ package uk.ac.sanger.artemis.plot; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; + import uk.ac.sanger.artemis.*; import uk.ac.sanger.artemis.sequence.*; @@ -39,7 +45,7 @@ import uk.ac.sanger.artemis.io.Range; * See Gribskov et al. (Nucl. Acids Res. 12(1); 539-549 (1984)). * * @author Kim Rutherford - * @version $Id: CodonUsageAlgorithm.java,v 1.1 2004-06-09 09:51:19 tjc Exp $ + * @version $Id: CodonUsageAlgorithm.java,v 1.2 2006-06-23 10:40:14 tjc Exp $ **/ public class CodonUsageAlgorithm extends BaseAlgorithm { @@ -68,8 +74,10 @@ public class CodonUsageAlgorithm extends BaseAlgorithm { * this array. There is one value for each frame and the value is the * the average of the weightings for the codons in the range. **/ - public void getValues (int start, int end, final float [] values) { - if (isRevCompDisplay ()) { + public void getValues(int start, int end, final float[] values) + { + if (isRevCompDisplay ()) + { final int new_end = getStrand ().getBases ().getComplementPosition (start); final int new_start = @@ -80,74 +88,78 @@ public class CodonUsageAlgorithm extends BaseAlgorithm { } // add 1 or 2 if necessary to make the range a multiple of 3 - if (getStrand ().isForwardStrand ()) { + if(getStrand ().isForwardStrand ()) end -= (end - start + 1) % 3; - } else { + else start += (end - start + 1) % 3; - } - final String sequence; + final char[] sequence; - try { - sequence = getStrand ().getRawSubSequence (new Range (start, end)); - } catch (OutOfRangeException e) { + try + { + sequence = getStrand ().getRawSubSequenceC(new Range (start, end)); + } + catch (OutOfRangeException e) + { throw new Error ("internal error - unexpected exception: " + e); } - float [] totals = { 0, 0, 0 }; + float[] totals = { 0, 0, 0 }; // a count of the number of codons we have seen int codon_count = 0; - final int sub_sequence_length = sequence.length (); + final int sub_sequence_length = sequence.length; - if (getStrand ().isForwardStrand ()) { - - for (int frame = 0 ; frame < 3 ; ++frame) { - for (int i = frame ; i < sub_sequence_length - 3 ; i += 3) { - - final char base1 = sequence.charAt (i); - final char base2 = sequence.charAt (i + 1); - final char base3 = sequence.charAt (i + 2); + if(getStrand ().isForwardStrand ()) + { + for (int frame = 0 ; frame < 3 ; ++frame) + { + final int real_frame = (frame + start + 2) % 3; + for (int i = frame ; i < sub_sequence_length - 3 ; i += 3) + { + final char base1 = sequence[i]; + final char base2 = sequence[i + 1]; + final char base3 = sequence[i + 2]; final float this_weight = - usage_data.getCodonValue (base1, base2, base3); - - final int real_frame = (frame + start + 2) % 3; + usage_data.getCodonValue(base1, base2, base3); ++codon_count; - totals[real_frame] += Math.log (this_weight); + totals[real_frame] += Math.log(this_weight); } } - } else { - for (int frame = 2 ; frame >= 0 ; --frame) { - for (int i = frame ; i < sub_sequence_length - 3 ; i += 3) { - - final char base1 = Bases.complement (sequence.charAt (i + 2)); - final char base2 = Bases.complement (sequence.charAt (i + 1)); - final char base3 = Bases.complement (sequence.charAt (i)); + } + else + { + for(int frame = 2; frame >= 0 ; --frame) + { + final int real_frame = (frame + start + 2) % 3; + for (int i = frame ; i < sub_sequence_length - 3 ; i += 3) + { + final char base1 = Bases.complement(sequence[i + 2]); + final char base2 = Bases.complement(sequence[i + 1]); + final char base3 = Bases.complement(sequence[i]); final float this_weight = - usage_data.getCodonValue (base1, base2, base3); - - final int real_frame = (frame + start + 2) % 3; + usage_data.getCodonValue(base1, base2, base3); ++codon_count; - totals[real_frame] += Math.log (this_weight); - + totals[real_frame] += Math.log(this_weight); } } } - for (int frame = 0 ; frame < 3 ; ++frame) { - if (codon_count == 0) { + for (int frame = 0 ; frame < 3 ; ++frame) + { + if (codon_count == 0) values[frame] = 0; - } else { - values[frame] = (float) Math.exp (totals[frame] / codon_count); - } + else + values[frame] = (float)Math.exp(totals[frame] / codon_count); } } + /** * Return the number of values a call to getValues () will return - three * in this case. diff --git a/uk/ac/sanger/artemis/plot/GCFrameAlgorithm.java b/uk/ac/sanger/artemis/plot/GCFrameAlgorithm.java index ff965f5f8a4d668057842154ab7e58ef930c844e..74db76dd1ef99a56b6a424f1a29666dea919d133 100644 --- a/uk/ac/sanger/artemis/plot/GCFrameAlgorithm.java +++ b/uk/ac/sanger/artemis/plot/GCFrameAlgorithm.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/GCFrameAlgorithm.java,v 1.5 2006-06-21 10:06:08 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/GCFrameAlgorithm.java,v 1.6 2006-06-23 10:40:14 tjc Exp $ */ package uk.ac.sanger.artemis.plot; @@ -38,7 +38,7 @@ import java.awt.*; * constructor. * * @author Kim Rutherford - * @version $Id: GCFrameAlgorithm.java,v 1.5 2006-06-21 10:06:08 tjc Exp $ + * @version $Id: GCFrameAlgorithm.java,v 1.6 2006-06-23 10:40:14 tjc Exp $ **/ public class GCFrameAlgorithm extends BaseAlgorithm { @@ -149,6 +149,8 @@ public class GCFrameAlgorithm extends BaseAlgorithm public void drawLegend(Graphics g, int font_height, int font_width, Color[] frameColour) { + return; + /* final Strand strand = getStrand(); if(strand.isForwardStrand()) super.drawLegend(g,font_height,font_width,frameColour); @@ -182,7 +184,7 @@ public class GCFrameAlgorithm extends BaseAlgorithm g2d.drawLine(font_width*12, lineHgt, font_width*14, lineHgt); g2d.setStroke(stroke); return; - /* case 1: + case 1: g2d.setColor(frameColour[2]); g2d.drawLine(font_width*2, lineHgt, font_width*4, lineHgt); @@ -204,8 +206,8 @@ public class GCFrameAlgorithm extends BaseAlgorithm g2d.drawLine(font_width*12, lineHgt, font_width*14, lineHgt); g2d.setStroke(stroke); return; - } */ - } + } + } */ } diff --git a/uk/ac/sanger/artemis/plot/KarlinSigAlgorithm.java b/uk/ac/sanger/artemis/plot/KarlinSigAlgorithm.java index 792be5c0426a17d65333011a4d919fc6d582ca25..9dee5bf5cf2c37f94a821e07f07761f8b335343b 100644 --- a/uk/ac/sanger/artemis/plot/KarlinSigAlgorithm.java +++ b/uk/ac/sanger/artemis/plot/KarlinSigAlgorithm.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/KarlinSigAlgorithm.java,v 1.1 2004-06-09 09:51:36 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/KarlinSigAlgorithm.java,v 1.2 2006-06-23 10:40:14 tjc Exp $ */ package uk.ac.sanger.artemis.plot; @@ -42,7 +42,7 @@ import uk.ac.sanger.artemis.sequence.*; * constructor. * * @author Kim Rutherford - * @version $Id: KarlinSigAlgorithm.java,v 1.1 2004-06-09 09:51:36 tjc Exp $ + * @version $Id: KarlinSigAlgorithm.java,v 1.2 2006-06-23 10:40:14 tjc Exp $ **/ public class KarlinSigAlgorithm extends BaseAlgorithm { @@ -69,10 +69,10 @@ public class KarlinSigAlgorithm extends BaseAlgorithm { // add 1 or 2 if necessary to make the range a multiple of 3 end -= (end - start + 1) % 3; - final String sub_sequence; + final char[] sub_sequence; try { - sub_sequence = getStrand ().getSubSequence (new Range (start, end)); + sub_sequence = getStrand().getRawSubSequenceC(new Range (start, end)); } catch (OutOfRangeException e) { throw new Error ("internal error - unexpected exception: " + e); } @@ -194,12 +194,11 @@ public class KarlinSigAlgorithm extends BaseAlgorithm { * dinucleotide "TT" is stored in global_signature[0][0], "TC" is stored in * [0][1], etc. **/ - private float [][] getRelativeAbundance (final String sequence) { + private float [][] getRelativeAbundance (final char [] sequence_forward_raw) { final float [][] return_value = new float [4][4]; - final char [] sequence_forward_raw = sequence.toCharArray (); final char [] sequence_reverse_raw = - Bases.reverseComplement (sequence).toCharArray (); + Bases.reverseComplement (sequence_forward_raw); final int [] base_counts = new int [4]; final int [][] dinucleotide_base_counts = new int [4][4]; @@ -287,8 +286,8 @@ public class KarlinSigAlgorithm extends BaseAlgorithm { try { final Range whole_range = new Range (1, getStrand ().getSequenceLength ()); - final String sequence = - getStrand ().getSubSequence (whole_range); + final char[] sequence = + getStrand().getRawSubSequenceC(whole_range); global_relative_abundance_values = getRelativeAbundance (sequence); } catch (OutOfRangeException e) { throw new Error ("internal error - unexpected exception: " + e);