use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.
the class HiCLengthHistogramPlot method actionPerformed.
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("close")) {
setVisible(false);
dispose();
} else if (ae.getActionCommand().equals("save")) {
ImageSaver.saveImage(plotPanel.mainHistogramPanel());
} else if (ae.getActionCommand().equals("export")) {
JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new TxtFileFilter());
int result = chooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = chooser.getSelectedFile();
SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
if (file.isDirectory())
return;
if (!file.getPath().toLowerCase().endsWith(".txt")) {
file = new File(file.getPath() + ".txt");
}
// Check if we're stepping on anyone's toes...
if (file.exists()) {
int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists. Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
if (answer > 0) {
return;
}
}
try {
plotPanel.exportData(file);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.
the class ProbeLengthHistogramPlot method actionPerformed.
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("close")) {
setVisible(false);
dispose();
} else if (ae.getActionCommand().equals("save")) {
ImageSaver.saveImage(plotPanel.mainHistogramPanel());
} else if (ae.getActionCommand().equals("export")) {
JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new TxtFileFilter());
int result = chooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = chooser.getSelectedFile();
SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
if (file.isDirectory())
return;
if (!file.getPath().toLowerCase().endsWith(".txt")) {
file = new File(file.getPath() + ".txt");
}
// Check if we're stepping on anyone's toes...
if (file.exists()) {
int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists. Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
if (answer > 0) {
return;
}
}
try {
plotPanel.exportData(file);
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else if (ae.getActionCommand().equals("scale")) {
int min = (int) plotPanel.currentMinValue();
int max = (int) plotPanel.currentMaxValue();
int interval = max - min;
if (interval > 200) {
// There are too many bins to draw 1 bin per base
int multiplier = interval / 200;
// System.err.println("Initial multiplier is "+multiplier);
if (multiplier != interval / 200d) {
multiplier++;
// System.err.println("Not an exact interval, multiplier is now "+multiplier);
}
// have it finish on a boundary
if (interval % multiplier != 0) {
// System.err.println("Interval "+interval+" is not divisible by "+multiplier+" adjusting min="+min+" max="+max);
max = min + interval + (multiplier - (interval % multiplier));
// System.err.println("New max="+max);
}
plotPanel.setScale(min, max, ((max - min) / multiplier));
} else {
plotPanel.setScale(min, max, (max - min));
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.
the class ManualCorrectionQuantitation method getOptionsPanel.
/* (non-Javadoc)
* @see uk.ac.babraham.SeqMonk.Quantitation.Quantitation#getOptionsPanel(uk.ac.babraham.SeqMonk.SeqMonkApplication)
*/
public JPanel getOptionsPanel() {
if (optionPanel != null) {
// We've done this already
return optionPanel;
}
optionPanel = new JPanel();
optionPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 0.5;
gbc.weighty = 0.1;
gbc.fill = GridBagConstraints.HORIZONTAL;
optionPanel.add(new JLabel("Method of correction"), gbc);
gbc.gridx = 2;
correctionActions = new JComboBox(new String[] { "Add", "Subtract", "Multiply", "Divide" });
optionPanel.add(correctionActions, gbc);
Vector<DataStore> quantitatedStores = new Vector<DataStore>();
DataSet[] sets = application.dataCollection().getAllDataSets();
for (int s = 0; s < sets.length; s++) {
if (sets[s].isQuantitated()) {
quantitatedStores.add(sets[s]);
}
}
DataGroup[] groups = application.dataCollection().getAllDataGroups();
for (int g = 0; g < groups.length; g++) {
if (groups[g].isQuantitated()) {
quantitatedStores.add(groups[g]);
}
}
data = quantitatedStores.toArray(new DataStore[0]);
correctionFactors = new JTextField[data.length];
// Now we work our way through the sets
JPanel correctionPanel = new JPanel();
correctionPanel.setLayout(new GridBagLayout());
GridBagConstraints cbc = new GridBagConstraints();
cbc.gridx = 1;
cbc.gridy = 1;
cbc.weightx = 0.5;
cbc.weighty = 0.5;
cbc.insets = new Insets(1, 3, 1, 3);
cbc.fill = GridBagConstraints.HORIZONTAL;
for (int d = 0; d < data.length; d++) {
cbc.gridx = 1;
cbc.gridy++;
correctionPanel.add(new JLabel(data[d].name()), cbc);
cbc.gridx = 2;
correctionFactors[d] = new JTextField();
if (storedCorrections.containsKey(data[d].name())) {
correctionFactors[d].setText("" + storedCorrections.get(data[d].name()));
}
correctionFactors[d].addKeyListener(new NumberKeyListener(true, true));
correctionPanel.add(correctionFactors[d], cbc);
}
gbc.gridx = 1;
gbc.gridy++;
gbc.gridwidth = 2;
optionPanel.add(new JLabel("Correction factors", JLabel.CENTER), gbc);
gbc.gridy++;
gbc.weighty = 0.9;
gbc.fill = GridBagConstraints.BOTH;
optionPanel.add(new JScrollPane(correctionPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), gbc);
gbc.gridx = 1;
gbc.gridy++;
gbc.gridwidth = 2;
gbc.weighty = 0.001;
gbc.fill = GridBagConstraints.NONE;
JButton loadFromFileButton = new JButton("Load from file");
loadFromFileButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getDataLocation());
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new TxtFileFilter());
int result = chooser.showOpenDialog(optionPanel);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = chooser.getSelectedFile();
SeqMonkPreferences.getInstance().setLastUsedDataLocation(file);
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
line.trim();
if (line.startsWith("#"))
continue;
String[] sections = line.split("\t");
if (sections.length < 2)
continue;
if (sections[1].length() == 0)
continue;
// See if we can find a dataset with the name of this section
for (int d = 0; d < data.length; d++) {
if (data[d].name().equals(sections[0])) {
// We try setting the value to whatever is stored for this
try {
Double.parseDouble(sections[1]);
correctionFactors[d].setText(sections[1]);
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(optionPanel, "Skipping " + sections[0] + " as " + sections[1] + " isn't a number", "Correction import error", JOptionPane.WARNING_MESSAGE);
}
}
}
}
br.close();
} catch (IOException ioe) {
JOptionPane.showMessageDialog(optionPanel, "Failed to read input file:" + ioe.getMessage(), "Correction import error", JOptionPane.ERROR_MESSAGE);
return;
}
}
});
optionPanel.add(loadFromFileButton, gbc);
return optionPanel;
}
use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.
the class ReadLengthHistogramPlot method actionPerformed.
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("close")) {
setVisible(false);
dispose();
} else if (ae.getActionCommand().equals("save")) {
ImageSaver.saveImage(plotPanel.mainHistogramPanel());
} else if (ae.getActionCommand().equals("export")) {
JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new TxtFileFilter());
int result = chooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = chooser.getSelectedFile();
SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
if (file.isDirectory())
return;
if (!file.getPath().toLowerCase().endsWith(".txt")) {
file = new File(file.getPath() + ".txt");
}
// Check if we're stepping on anyone's toes...
if (file.exists()) {
int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists. Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
if (answer > 0) {
return;
}
}
try {
plotPanel.exportData(file);
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else if (ae.getActionCommand().equals("scale")) {
int min = (int) plotPanel.currentMinValue();
int max = (int) plotPanel.currentMaxValue();
int interval = max - min;
if (interval > 200) {
// There are too many bins to draw 1 bin per base
int multiplier = interval / 200;
// System.err.println("Initial multiplier is "+multiplier);
if (multiplier != interval / 200d) {
multiplier++;
// System.err.println("Not an exact interval, multiplier is now "+multiplier);
}
// have it finish on a boundary
if (interval % multiplier != 0) {
// System.err.println("Interval "+interval+" is not divisible by "+multiplier+" adjusting min="+min+" max="+max);
max = min + interval + (multiplier - (interval % multiplier));
// System.err.println("New max="+max);
}
plotPanel.setScale(min, max, ((max - min) / multiplier));
} else {
plotPanel.setScale(min, max, (max - min));
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.
the class PCAScatterPlotDialog method actionPerformed.
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("close")) {
setVisible(false);
dispose();
} else if (ae.getActionCommand().equals("sublists")) {
// Select a set of sublists from the current probe list to highlight
// in the plot
OrderedReplicateSetSelector selector = new OrderedReplicateSetSelector(this, SeqMonkApplication.getInstance().dataCollection().getAllReplicateSets(), highlightedSets);
// It's modal so by the time we get here the selection has been made
highlightedSets = selector.getOrderedSets();
// try to highlight anything.
if (highlightedSets != null && highlightedSets.length == 0) {
highlightedSets = null;
}
selector.dispose();
actionPerformed(new ActionEvent(this, 1, "plot"));
} else if (ae.getActionCommand().equals("plot")) {
int xIndex = xStores.getSelectedIndex();
int yIndex = yStores.getSelectedIndex();
getContentPane().remove(scatterPlotPanel);
scatterPlotPanel = new PCAScatterPlotPanel(data, xIndex, yIndex, highlightedSets, showLabelsBox.isSelected(), dotSizeSlider.getValue());
getContentPane().add(scatterPlotPanel, BorderLayout.CENTER);
validate();
} else if (ae.getActionCommand().equals("save_image")) {
ImageSaver.saveImage(scatterPlotPanel);
} else if (ae.getActionCommand().equals("export")) {
JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new TxtFileFilter());
int result = chooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = chooser.getSelectedFile();
SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
if (file.isDirectory())
return;
if (!file.getPath().toLowerCase().endsWith(".txt")) {
file = new File(file.getPath() + ".txt");
}
// Check if we're stepping on anyone's toes...
if (file.exists()) {
int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists. Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
if (answer > 0) {
return;
}
}
try {
data.writeExportData(file);
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else {
throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
}
}
Aggregations