diff --git a/uk/ac/sanger/artemis/components/BasePlot.java b/uk/ac/sanger/artemis/components/BasePlot.java index 362c9efdd88aebc63853edf5cd46a2d061d3653f..5f0d00c21924ad1e75734e0c0f1f20d4f53975fc 100644 --- a/uk/ac/sanger/artemis/components/BasePlot.java +++ b/uk/ac/sanger/artemis/components/BasePlot.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/components/BasePlot.java,v 1.19 2009-07-16 14:17:11 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/BasePlot.java,v 1.20 2009-07-20 15:11:17 tjc Exp $ **/ package uk.ac.sanger.artemis.components; @@ -54,7 +54,7 @@ import org.apache.log4j.Level; * scale is tied to a FeatureDisplay component. * * @author Kim Rutherford - * @version $Id: BasePlot.java,v 1.19 2009-07-16 14:17:11 tjc Exp $ + * @version $Id: BasePlot.java,v 1.20 2009-07-20 15:11:17 tjc Exp $ **/ public class BasePlot extends Plot @@ -739,10 +739,16 @@ public class BasePlot extends Plot final int number_of_values = value_array_array[0].length; boolean isWiggle = false; + boolean isBlast = false; if(getAlgorithm() instanceof UserDataAlgorithm) { - if( ((UserDataAlgorithm)getAlgorithm()).wiggle != null ) + int format = ((UserDataAlgorithm)getAlgorithm()).FORMAT; + if(format == UserDataAlgorithm.WIGGLE_FIXED_STEP_FORMAT || + format == UserDataAlgorithm.WIGGLE_VARIABLE_STEP_FORMAT) isWiggle = true; + + if(format == UserDataAlgorithm.BLAST_FORMAT) + isBlast = true; } if(number_of_values > 1 && !isWiggle) @@ -771,7 +777,7 @@ public class BasePlot extends Plot getWidthInBases(), offset, value_array_array[value_index], value_index, - get_values_return_count, isWiggle); + get_values_return_count, isWiggle, isBlast); } ((Graphics2D)g).setStroke(stroke); diff --git a/uk/ac/sanger/artemis/components/FeaturePlot.java b/uk/ac/sanger/artemis/components/FeaturePlot.java index 112c90ee38d0742efe21d4e8349a23d697940abf..646f45c368a9789ed1a739fe710bb5d12dd82a7e 100644 --- a/uk/ac/sanger/artemis/components/FeaturePlot.java +++ b/uk/ac/sanger/artemis/components/FeaturePlot.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/components/FeaturePlot.java,v 1.10 2009-07-16 14:17:11 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeaturePlot.java,v 1.11 2009-07-20 15:11:17 tjc Exp $ */ package uk.ac.sanger.artemis.components; @@ -38,7 +38,7 @@ import java.awt.*; * particular feature. * * @author Kim Rutherford - * @version $Id: FeaturePlot.java,v 1.10 2009-07-16 14:17:11 tjc Exp $ + * @version $Id: FeaturePlot.java,v 1.11 2009-07-20 15:11:17 tjc Exp $ **/ public class FeaturePlot extends Plot @@ -330,7 +330,7 @@ public class FeaturePlot extends Plot getSize ().width, 0, // no offset. value_array_array[value_index], value_index, - get_values_return_count, false); + get_values_return_count, false, false); } drawMinMax (g, min_value, max_value); diff --git a/uk/ac/sanger/artemis/components/Plot.java b/uk/ac/sanger/artemis/components/Plot.java index 3f1e4333e47c990854ed88be0ec161f3ca1c6bf8..fd897a3a633eb7e263653499aa95561050c7bf71 100644 --- a/uk/ac/sanger/artemis/components/Plot.java +++ b/uk/ac/sanger/artemis/components/Plot.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/components/Plot.java,v 1.24 2009-07-16 14:17:11 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/Plot.java,v 1.25 2009-07-20 15:11:17 tjc Exp $ **/ package uk.ac.sanger.artemis.components; @@ -48,7 +48,7 @@ import javax.swing.JPopupMenu; * This class implements a simple plot component. * * @author Kim Rutherford - * @version $Id: Plot.java,v 1.24 2009-07-16 14:17:11 tjc Exp $ + * @version $Id: Plot.java,v 1.25 2009-07-20 15:11:17 tjc Exp $ **/ public abstract class Plot extends JPanel @@ -810,7 +810,8 @@ public abstract class Plot extends JPanel final float [] plot_values, final int value_index, final int numberPlots, - final boolean isWiggle) + final boolean isWiggle, + final boolean isBlast) { final float residues_per_pixel = (float) total_unit_count / getSize().width; @@ -848,8 +849,11 @@ public abstract class Plot extends JPanel for(int i = 0; i<number_of_values - 1; ++i) { - if(isWiggle && plot_values[i] == 0) - continue; + if( (isBlast || isWiggle) && plot_values[i] == 0) + { + if( !(isBlast && plotType.equals(LineAttributes.PLOT_TYPES[0])) ) + continue; + } start_residue = window_size / 2 + i * step_size + start_position; start_x = (int)(start_residue / residues_per_pixel); @@ -937,18 +941,18 @@ public abstract class Plot extends JPanel float scale = ((float)(NUMBER_OF_SHADES-i) * (float)(255 / NUMBER_OF_SHADES )) ; - if((R+scale) < 253) + if((R+scale) < 254) R += scale; else - R = 253; - if((G+scale) < 253) + R = 254; + if((G+scale) < 254) G += scale; else - G = 253; - if((B+scale) < 253) + G = 254; + if((B+scale) < 254) B += scale; else - B = 253; + B = 254; definedColour[i] = new Color(R,G,B); } diff --git a/uk/ac/sanger/artemis/plot/UserDataAlgorithm.java b/uk/ac/sanger/artemis/plot/UserDataAlgorithm.java index dd9d71618e57387172fa36e3600bbe530cef5fa6..a501743c6b79a1f9e75b5f0d5b8044a193d9c683 100644 --- a/uk/ac/sanger/artemis/plot/UserDataAlgorithm.java +++ b/uk/ac/sanger/artemis/plot/UserDataAlgorithm.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/UserDataAlgorithm.java,v 1.11 2009-07-16 14:14:32 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/UserDataAlgorithm.java,v 1.12 2009-07-20 15:11:18 tjc Exp $ */ package uk.ac.sanger.artemis.plot; @@ -31,10 +31,16 @@ import uk.ac.sanger.artemis.util.*; import uk.ac.sanger.artemis.io.ReadFormatException; import java.awt.Color; +import java.awt.GridLayout; import java.io.*; import java.util.HashMap; import java.util.regex.Pattern; +import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + /** * Objects of this class have one useful method - getValues (), which takes a * range of bases and returns a single floating point number. The number is @@ -42,20 +48,22 @@ import java.util.regex.Pattern; * set in the constructor. * * @author Kim Rutherford <kmr@sanger.ac.uk> - * @version $Id: UserDataAlgorithm.java,v 1.11 2009-07-16 14:14:32 tjc Exp $ + * @version $Id: UserDataAlgorithm.java,v 1.12 2009-07-20 15:11:18 tjc Exp $ **/ public class UserDataAlgorithm extends BaseAlgorithm { /** A base per line file format */ - private static int BASE_PER_LINE_FORMAT = 1; + public static int BASE_PER_LINE_FORMAT = 1; /** Base position is specified in the first column file format */ - private static int BASE_SPECIFIED_FORMAT = 2; + public static int BASE_SPECIFIED_FORMAT = 2; /** Wiggle format */ - private static int WIGGLE_VARIABLE_STEP_FORMAT = 3; - private static int WIGGLE_FIXED_STEP_FORMAT = 4; + public static int WIGGLE_VARIABLE_STEP_FORMAT = 3; + public static int WIGGLE_FIXED_STEP_FORMAT = 4; + + public static int BLAST_FORMAT = 5; /** The data read by the constructor - for BASE_PER_LINE_FORMAT */ private float data[][] = null; @@ -83,7 +91,7 @@ public class UserDataAlgorithm extends BaseAlgorithm private boolean logTransform; /** Format type for this instance */ - private int FORMAT = BASE_PER_LINE_FORMAT; + public int FORMAT = BASE_PER_LINE_FORMAT; private LineAttributes lines[]; @@ -113,10 +121,16 @@ public class UserDataAlgorithm extends BaseAlgorithm String first_line = pushback_reader.readLine (); Pattern dataPattern = Pattern.compile("^\\s*([\\d\\.]+\\s*)+$"); + Pattern blastPattern = Pattern.compile( + "^(\\S+\\t+){2}[\\d\\.]+\\t+(\\d+\\t+){7}\\S+\\t+(\\d+)$"); if(dataPattern.matcher(first_line).matches()) FORMAT = BASE_PER_LINE_FORMAT; - else + else if(blastPattern.matcher(first_line).matches()) { + FORMAT = BLAST_FORMAT; + } + else + { StringBuffer header = new StringBuffer(first_line+"\n"); while(!dataPattern.matcher(first_line).matches()) @@ -143,6 +157,8 @@ public class UserDataAlgorithm extends BaseAlgorithm if(FORMAT == BASE_SPECIFIED_FORMAT || FORMAT == BASE_PER_LINE_FORMAT) readData(pushback_reader); + else if(FORMAT == BLAST_FORMAT) + readBlast(pushback_reader); else readWiggle(pushback_reader); pushback_reader.close(); @@ -322,6 +338,105 @@ public class UserDataAlgorithm extends BaseAlgorithm default_window_size = 1; } + + /** + * Read all from buffered_reader into data. + **/ + private void readBlast (final LinePushBackReader pushback_reader) + throws IOException + { + String line = null; + int count = 0; + int lineNum = 0; + final int seqLength = getStrand ().getSequenceLength (); + final Pattern patt = Pattern.compile("\\t+"); + + dataMap = new HashMap<Integer, Float[]>(); + this.number_of_values = 1; + int coordIndexStart = 6; + int coordIndexEnd = 7; + + while ((line = pushback_reader.readLine ()) != null) + { + String tokens[] = patt.split(line.trim()); + + if(lineNum == 0) + { + final JPanel message = new JPanel(new GridLayout(2,1)); + + JCheckBox query = new JCheckBox("Query "+tokens[0], true); + message.add(query); + JCheckBox subj = new JCheckBox("Subject "+tokens[1], false); + message.add(subj); + ButtonGroup group = new ButtonGroup(); + group.add(query); + group.add(subj); + + JOptionPane.showConfirmDialog(null, message, + "Use Coordinates From", JOptionPane.OK_OPTION); + if(subj.isSelected()) + { + coordIndexStart = 8; + coordIndexEnd = 9; + } + } + lineNum++; + + int startBase = Integer.parseInt(tokens[coordIndexStart]); + int endBase = Integer.parseInt(tokens[coordIndexEnd]); + float value = Float.parseFloat(tokens[11]); + + int valueIndex = 0; + try + { + if(startBase > seqLength || endBase > seqLength) + throw new ReadFormatException ( + "the location ("+startBase+".."+endBase+ + ") is outside than the sequence length:\n"+line); + + if(logTransform) + value = (float) Math.log(value+1); + + if (value > data_max) + data_max = value; + if (value < data_min) + data_min = value; + + if(startBase > endBase) + { + int tmpStart = startBase; + startBase = endBase; + endBase = tmpStart; + } + + final Float valueArray[] = new Float[number_of_values]; + for (int base = startBase; base <= endBase; base++) + { + if (dataMap.containsKey(base)) + { + Float oldValues[] = dataMap.get(base); + if(oldValues[0] > value) + value = oldValues[0]; + } + + valueArray[number_of_values - 1] = value; + dataMap.put(base, valueArray); + count++; + } + + average_value += value; + } + catch (NumberFormatException e) + { + throw new ReadFormatException ("cannot understand this number: " + + tokens[valueIndex] + " - " +e.getMessage ()); + } + } + + average_value = average_value/count; + default_window_size = 1; + } + /** * Return the value of the function between a pair of bases. * @param start The start base (included in the range). @@ -343,7 +458,8 @@ public class UserDataAlgorithm extends BaseAlgorithm if(FORMAT == BASE_SPECIFIED_FORMAT || FORMAT == WIGGLE_VARIABLE_STEP_FORMAT || - FORMAT == WIGGLE_FIXED_STEP_FORMAT) + FORMAT == WIGGLE_FIXED_STEP_FORMAT || + FORMAT == BLAST_FORMAT) { for (int i = 0 ; i < value_count ; ++i) {