use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class ReplicateSetEditor method actionPerformed.
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
String c = ae.getActionCommand();
if (c.equals("add")) {
Object[] addObjs = availableList.getSelectedValues();
DataStore[] adds = new DataStore[addObjs.length];
for (int i = 0; i < adds.length; i++) {
adds[i] = (DataStore) addObjs[i];
}
usedModel.addElements(adds);
availableModel.removeElements(adds);
usedList.setSelectedIndices(new int[0]);
availableList.setSelectedIndices(new int[0]);
DataStore[] s = usedModel.getStores();
ReplicateSet r = (ReplicateSet) replicateSetList.getSelectedValue();
r.setDataStores(s);
} else if (c.equals("select_named")) {
new NameGatherer();
} else if (c.equals("remove")) {
Object[] addObjs = usedList.getSelectedValues();
DataStore[] adds = new DataStore[addObjs.length];
for (int i = 0; i < adds.length; i++) {
adds[i] = (DataStore) addObjs[i];
}
usedModel.removeElements(adds);
availableModel.addElements(adds);
usedList.setSelectedIndices(new int[0]);
availableList.setSelectedIndices(new int[0]);
DataStore[] s = usedModel.getStores();
ReplicateSet r = (ReplicateSet) replicateSetList.getSelectedValue();
r.setDataStores(s);
} else if (c.equals("new_set")) {
String setName = null;
while (true) {
setName = (String) JOptionPane.showInputDialog(this, "Enter set name", "Group Name", JOptionPane.QUESTION_MESSAGE, null, null, "New replicate set");
if (setName == null)
// They cancelled
return;
if (setName.length() == 0)
// Try again
continue;
break;
}
ReplicateSet s = new ReplicateSet(setName, new DataStore[0]);
application.dataCollection().addReplicateSet(s);
replicateSetModel.addElements(new DataStore[] { s });
} else if (c.equals("rename_set")) {
ReplicateSet s = (ReplicateSet) replicateSetList.getSelectedValue();
String setName = null;
while (true) {
setName = (String) JOptionPane.showInputDialog(this, "Enter set name", "Set Name", JOptionPane.QUESTION_MESSAGE, null, null, s.name());
// They cancelled
if (setName == null)
return;
if (setName.length() > 0)
break;
}
s.setName(setName);
replicateSetModel.setElementAt(s, replicateSetList.getSelectedIndex());
} else if (c.equals("delete_set")) {
Object[] o = replicateSetList.getSelectedValues();
ReplicateSet[] repSets = new ReplicateSet[o.length];
for (int i = 0; i < o.length; i++) {
repSets[i] = (ReplicateSet) o[i];
}
replicateSetModel.removeElements(repSets);
application.dataCollection().removeReplicateSets(repSets);
} else if (c.equals("close")) {
setVisible(false);
dispose();
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class DataStoreTreeDialog method progressComplete.
public void progressComplete(String command, Object result) {
getContentPane().setLayout(new BorderLayout());
clusterPanel = new DataStoreClusterPanel((ClusterPair) result, stores, listName);
getContentPane().add(clusterPanel, BorderLayout.CENTER);
rValueSlider = new JSlider(JSlider.HORIZONTAL, 0, 1000, 0);
rValueSlider.setPaintTicks(true);
getContentPane().add(rValueSlider, BorderLayout.NORTH);
rValueSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
clusterPanel.setRProportion(rValueSlider.getValue() / 1000f);
}
});
JPanel buttonPanel = new JPanel();
JButton closeButton = new JButton("Close");
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
});
buttonPanel.add(closeButton);
JButton saveImageButton = new JButton("Save Image");
saveImageButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ImageSaver.saveImage(clusterPanel);
}
});
buttonPanel.add(saveImageButton);
JButton createRepSetsButton = new JButton("Split data stores");
createRepSetsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int s = 0; s < stores.length; s++) {
if (stores[s] instanceof ReplicateSet) {
JOptionPane.showMessageDialog(DataStoreTreeDialog.this, "One of the stores you plotted is already a replicate set so you can't make a new set with it in.", "Can't split stores", JOptionPane.ERROR_MESSAGE);
return;
}
}
// TODO: Ask for min count per store
DataStore[][] splitStores = clusterPanel.getSplitStores(2);
for (int s = 0; s < splitStores.length; s++) {
SeqMonkApplication.getInstance().dataCollection().addReplicateSet(new ReplicateSet("Cluster Group " + (s + 1), splitStores[s]));
}
JOptionPane.showMessageDialog(DataStoreTreeDialog.this, "Created " + splitStores.length + " new replicate sets", "Splitting Complete", JOptionPane.INFORMATION_MESSAGE);
}
});
buttonPanel.add(createRepSetsButton);
JButton reorderStoresButton = new JButton("Reorder stores");
reorderStoresButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DataStore[] orderedStores = clusterPanel.getOrderedStores();
SeqMonkApplication.getInstance().setDrawnDataStores(orderedStores);
}
});
buttonPanel.add(reorderStoresButton);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setSize(800, 800);
setLocationRelativeTo(SeqMonkApplication.getInstance());
setVisible(true);
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class AutoSplitDataDialog method createGroups.
private void createGroups() {
String[] names = groupNamesArea.getText().split("\\n");
int[] counts = new int[names.length];
DataSet[] dataSets = application.dataCollection().getAllDataSets();
DataGroup[] dataGroups = application.dataCollection().getAllDataGroups();
boolean makeReplicateSets = groupsOrSetsBox.getSelectedItem().equals("Replicate Sets");
boolean caseInsensitive = caseInsensitiveBox.isSelected();
if (!includeGroupsBox.isSelected()) {
dataGroups = new DataGroup[0];
}
boolean[] setsFound = new boolean[dataSets.length];
boolean[] groupsFound = new boolean[dataGroups.length];
for (int n = 0; n < names.length; n++) {
if (names[n].trim().length() == 0)
continue;
names[n] = names[n].trim();
String[] patterns = names[n].split("\\|");
if (makeReplicateSets) {
Vector<DataStore> stores = new Vector<DataStore>();
DATASET: for (int i = 0; i < dataSets.length; i++) {
// Only add to the first match we make
if (setsFound[i])
continue;
for (int p = 0; p < patterns.length; p++) {
if (caseInsensitive) {
if (!dataSets[i].name().toLowerCase().contains(patterns[p].toLowerCase())) {
continue DATASET;
}
} else {
if (!dataSets[i].name().contains(patterns[p])) {
continue DATASET;
}
}
}
stores.add(dataSets[i]);
setsFound[i] = true;
}
DATAGROUP: for (int i = 0; i < dataGroups.length; i++) {
// Only add to the first match we make
if (groupsFound[i])
continue;
for (int p = 0; p < patterns.length; p++) {
if (!dataGroups[i].name().contains(patterns[p])) {
continue DATAGROUP;
}
}
stores.add(dataGroups[i]);
groupsFound[i] = true;
}
counts[n] = stores.size();
if (stores.size() > 0) {
application.dataCollection().addReplicateSet(new ReplicateSet(names[n], stores.toArray(new DataStore[0])));
}
} else {
Vector<DataSet> sets = new Vector<DataSet>();
DATASET: for (int i = 0; i < dataSets.length; i++) {
for (int p = 0; p < patterns.length; p++) {
if (!dataSets[i].name().contains(patterns[p])) {
continue DATASET;
}
}
sets.add(dataSets[i]);
}
counts[n] = sets.size();
if (sets.size() > 0) {
application.dataCollection().addDataGroup(new DataGroup(names[n], sets.toArray(new DataSet[0])));
}
}
}
StringBuffer sb = new StringBuffer();
sb.append("<html>");
for (int i = 0; i < names.length; i++) {
sb.append("For name ");
sb.append(names[i]);
sb.append(" found ");
sb.append(counts[i]);
sb.append(" hits<br>");
}
sb.append("</html>");
JOptionPane.showMessageDialog(this, sb.toString(), "Group creation complete", JOptionPane.INFORMATION_MESSAGE);
// It's actually better not to close after this but let them close it themselves.
// setVisible(false);
// dispose();
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class SubsetNormalisationQuantitation 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", "Multiply" });
optionPanel.add(correctionActions, gbc);
gbc.gridx = 1;
gbc.gridy++;
optionPanel.add(new JLabel("Summation Method"), gbc);
gbc.gridx = 2;
summationActions = new JComboBox(new String[] { "Mean", "Sum" });
optionPanel.add(summationActions, gbc);
gbc.gridx = 1;
gbc.gridy++;
optionPanel.add(new JLabel("Target Value"), gbc);
gbc.gridx = 2;
targetActions = new JComboBox(new String[] { "Largest", "1" });
optionPanel.add(targetActions, 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]);
gbc.gridx = 1;
gbc.gridy++;
optionPanel.add(new JLabel("Calculate from probe list"), gbc);
ProbeList[] currentLists = application.dataCollection().probeSet().getAllProbeLists();
calculateFromProbeList = new JComboBox(currentLists);
calculateFromProbeList.setPrototypeDisplayValue("No longer than this please");
for (int i = 0; i < currentLists.length; i++) {
if (currentLists[i] == application.dataCollection().probeSet().getActiveList()) {
calculateFromProbeList.setSelectedIndex(i);
}
}
gbc.gridx++;
optionPanel.add(calculateFromProbeList, gbc);
return optionPanel;
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore 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;
}
Aggregations