Skip to content
Snippets Groups Projects
Commit 7b61ceea authored by tjc's avatar tjc
Browse files

create features based on plot peaks

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@7200 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent b92ee647
Branches
Tags
No related merge requests found
......@@ -20,32 +20,48 @@
* 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.8 2007-06-20 15:49:32 tjc Exp $
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/BasePlot.java,v 1.9 2008-03-06 14:34:05 tjc Exp $
**/
package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.*;
import uk.ac.sanger.artemis.sequence.*;
import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
import uk.ac.sanger.artemis.io.EntryInformationException;
import uk.ac.sanger.artemis.io.Key;
import uk.ac.sanger.artemis.io.Location;
import uk.ac.sanger.artemis.io.Qualifier;
import uk.ac.sanger.artemis.io.QualifierVector;
import uk.ac.sanger.artemis.io.RangeVector;
import uk.ac.sanger.artemis.plot.*;
import uk.ac.sanger.artemis.util.OutOfRangeException;
import uk.ac.sanger.artemis.util.ReadOnlyException;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* A component for plotting functions over the base sequence. Scrolling and
* scale is tied to a FeatureDisplay component.
*
* @author Kim Rutherford
* @version $Id: BasePlot.java,v 1.8 2007-06-20 15:49:32 tjc Exp $
* @version $Id: BasePlot.java,v 1.9 2008-03-06 14:34:05 tjc Exp $
**/
public class BasePlot extends Plot
implements DisplayAdjustmentListener, SelectionChangeListener
{
private static final long serialVersionUID = 1L;
/**
* The start base to plot, as obtained from the DisplayAdjustmentEvent.
**/
......@@ -117,6 +133,8 @@ public class BasePlot extends Plot
**/
private float max_value = Float.MIN_VALUE;
private EntryGroup entryGroup;
/**
* Used by getPreferredSize() and getMinimumSize();
**/
......@@ -152,13 +170,15 @@ public class BasePlot extends Plot
**/
public BasePlot(final BaseAlgorithm algorithm,
final Selection selection,
final GotoEventSource goto_event_source)
final GotoEventSource goto_event_source,
final EntryGroup entryGroup)
{
super(algorithm, false); // false means don't draw the scale line
this.selection = selection;
this.goto_event_source = goto_event_source;
this.bases = getBaseAlgorithm().getBases();
this.entryGroup = entryGroup;
getSelection().addSelectionChangeListener(this);
......@@ -317,6 +337,155 @@ public class BasePlot extends Plot
return width_in_bases;
}
/**
* Recalculate the values in value_array_array, step_size, min_value and
* max_value.
* @throws OutOfRangeException
* @throws EntryInformationException
* @throws ReadOnlyException
* @throws OutOfRangeException
* @throws EntryInformationException
* @throws ReadOnlyException
**/
protected void calculateFeatures()
throws ReadOnlyException, EntryInformationException, OutOfRangeException
{
GridBagLayout gridbag = new GridBagLayout();
JPanel pane = new JPanel(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.EAST;
c.gridx = 0;
c.gridy = 0;
pane.add(new JLabel("Minimum feature size:"), c);
c.gridx = 0;
c.gridy = 1;
pane.add(new JLabel("Cut-off value:"), c);
c.gridx = 0;
c.gridy = 2;
pane.add(new JLabel("Key:"), c);
JTextField minSize = new JTextField(String.valueOf (100), 15);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 0;
pane.add(minSize, c);
JTextField cutoffField = new JTextField(getAlgorithm().getAverage().toString(),15);
c.gridx = 1;
c.gridy = 1;
pane.add(cutoffField,c);
final Key defaultKey;
if(GeneUtils.isDatabaseEntry(entryGroup))
defaultKey = new Key("region");
else
defaultKey = Key.CDS;
KeyChoice keyChoice = new KeyChoice(
entryGroup.getDefaultEntry().getEntryInformation(), defaultKey);
c.gridx = 1;
c.gridy = 2;
pane.add(keyChoice, c);
int select = JOptionPane.showConfirmDialog(null,
pane, "Options",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(select == JOptionPane.CANCEL_OPTION)
return;
int minFeatureSize = Integer.parseInt(minSize.getText());
float cutoff = Float.parseFloat(cutoffField.getText());
Key key = keyChoice.getSelectedItem();
final int end = getBaseAlgorithm().getBases().getLength();
final int window_size = getWindowSize();
final Integer default_step_size =
getAlgorithm().getDefaultStepSize(window_size);
if(default_step_size == null)
step_size = 1;
else
{
if(default_step_size.intValue() < window_size)
step_size = default_step_size.intValue();
else
step_size = window_size;
}
// the number of plot points in the graph
final int number_of_values =
(end - (getWindowSize() - step_size)) / step_size;
getBaseAlgorithm().setRevCompDisplay(rev_comp_display);
// just one graph calculated
float [] temp_values = new float [1];
int featureStart = -1;
final Entry new_entry =
entryGroup.createEntry ("CDS_" + minFeatureSize + "_" +
getBaseAlgorithm().getAlgorithmShortName());
float average = 0.f;
int averageCount = 0;
final String noteField = "Auto-generated from "+getAlgorithm().getAlgorithmName()+
" plot;"+" window size="+getWindowSize()+
"; score cut-off="+cutoffField.getText();
for(int i = 0 ; i < number_of_values ; ++i)
{
getBaseAlgorithm().getValues(i * step_size,
i * step_size +
getWindowSize() - 1,
temp_values);
final float current_value = temp_values[0];
int pos = getWindowSize()/2 + (i * step_size) + 1;
if(current_value > cutoff)
{
average+=current_value;
averageCount++;
}
if(current_value > cutoff && featureStart == -1)
{
featureStart = pos;
}
else if(current_value <= cutoff && featureStart > -1)
{
if(pos-featureStart < minFeatureSize)
{
average = 0.f;
averageCount = 0;
featureStart = -1;
continue;
}
// create feature
MarkerRange range = new MarkerRange(getBaseAlgorithm().getStrand(),
featureStart, pos);
final Location new_location = range.createLocation();
average = average/averageCount;
QualifierVector qualifiers = new QualifierVector();
qualifiers.add(new Qualifier("score", Float.toString(average)));
qualifiers.add(new Qualifier("note", noteField));
new_entry.createFeature(key, new_location, qualifiers);
featureStart = -1;
average = 0.f;
averageCount = 0;
}
}
return;
}
/**
* Recalculate the values in value_array_array, step_size, min_value and
......
......@@ -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/BasePlotGroup.java,v 1.6 2004-11-30 16:16:17 tjc Exp $
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/BasePlotGroup.java,v 1.7 2008-03-06 14:34:05 tjc Exp $
*/
package uk.ac.sanger.artemis.components;
......@@ -42,7 +42,7 @@ import javax.swing.*;
* which can toggled off and on.
*
* @author Kim Rutherford
* @version $Id: BasePlotGroup.java,v 1.6 2004-11-30 16:16:17 tjc Exp $
* @version $Id: BasePlotGroup.java,v 1.7 2008-03-06 14:34:05 tjc Exp $
**/
public class BasePlotGroup extends JPanel
......@@ -355,7 +355,7 @@ public class BasePlotGroup extends JPanel
GridBagConstraints constraints)
{
final BasePlot new_base_plot =
new BasePlot(algorithm, getSelection(), getGotoEventSource());
new BasePlot(algorithm, getSelection(), getGotoEventSource(), entry_group);
gridbag.setConstraints(new_base_plot, constraints);
add(new_base_plot);
......
......@@ -20,17 +20,21 @@
* 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.12 2006-10-09 12:21:52 tjc Exp $
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/Plot.java,v 1.13 2008-03-06 14:34:05 tjc Exp $
**/
package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.io.EntryInformationException;
import uk.ac.sanger.artemis.plot.*;
import uk.ac.sanger.artemis.util.OutOfRangeException;
import uk.ac.sanger.artemis.util.ReadOnlyException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.JLabel;
......@@ -48,7 +52,7 @@ import javax.swing.JPopupMenu;
* This class implements a simple plot component.
*
* @author Kim Rutherford
* @version $Id: Plot.java,v 1.12 2006-10-09 12:21:52 tjc Exp $
* @version $Id: Plot.java,v 1.13 2008-03-06 14:34:05 tjc Exp $
**/
public abstract class Plot extends JPanel
......@@ -109,6 +113,9 @@ public abstract class Plot extends JPanel
**/
protected abstract int getPointPosition(final int canvas_x_position);
protected abstract void calculateFeatures()
throws ReadOnlyException, EntryInformationException, OutOfRangeException;
/** number of graph lines to be drawn */
private int numPlots;
......@@ -347,8 +354,8 @@ public abstract class Plot extends JPanel
popup.add(scaling_toggle);
popup.addSeparator();
final JMenuItem max_window_size =
new JMenuItem("Maximum Window Size:");
final JMenu max_window_size =
new JMenu("Maximum Window Size");
popup.add(max_window_size);
......@@ -380,7 +387,41 @@ public abstract class Plot extends JPanel
}
});
popup.add(window_size_item);
max_window_size.add(window_size_item);
}
if(numPlots == 1 && getAlgorithm() instanceof BaseAlgorithm)
{
popup.addSeparator();
final JMenuItem createFeatures =
new JMenuItem("Create features from graph peaks...");
popup.add(createFeatures);
createFeatures.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
calculateFeatures();
}
catch(ReadOnlyException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch(EntryInformationException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch(OutOfRangeException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
parent.add(popup);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment