use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class MAPlotDialog 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
OrderedListSelector selector = new OrderedListSelector(this, probeList, subLists);
// It's modal so by the time we get here the selection has been made
subLists = selector.getOrderedLists();
// try to highlight anything.
if (subLists != null && subLists.length == 0) {
subLists = null;
}
selector.dispose();
actionPerformed(new ActionEvent(this, 1, "plot"));
} else if (ae.getActionCommand().equals("plot")) {
DataStore xStore = (DataStore) xStores.getSelectedItem();
DataStore yStore = (DataStore) yStores.getSelectedItem();
getContentPane().remove(maPlotPanel);
// Check if these stores are quantitated
if (!xStore.isQuantitated()) {
JOptionPane.showMessageDialog(this, xStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
} else if (!yStore.isQuantitated()) {
JOptionPane.showMessageDialog(this, yStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
} else {
maPlotPanel = new MAPlotPanel(xStore, yStore, probeList, subLists, commonScaleBox.isSelected(), dotSizeSlider.getValue());
getContentPane().add(maPlotPanel, BorderLayout.CENTER);
}
validate();
} else if (ae.getActionCommand().equals("save_probe_list")) {
if (maPlotPanel instanceof MAPlotPanel) {
ProbeList list = ((MAPlotPanel) maPlotPanel).getFilteredProbes(collection.probeSet());
if (list.getAllProbes().length == 0) {
JOptionPane.showMessageDialog(this, "No probes were selected", "No probes", JOptionPane.INFORMATION_MESSAGE);
return;
}
// Ask for a name for the list
String groupName = null;
while (true) {
groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + list.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, list.name());
if (groupName == null) {
// Remove the list which will have been created by this stage
list.delete();
// They cancelled
return;
}
if (groupName.length() == 0)
// Try again
continue;
break;
}
list.setName(groupName);
}
} else if (ae.getActionCommand().equals("save_image")) {
ImageSaver.saveImage(maPlotPanel);
} else {
throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class ScatterPlotDialog 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
OrderedListSelector selector = new OrderedListSelector(this, probeList, subLists);
// It's modal so by the time we get here the selection has been made
subLists = selector.getOrderedLists();
// try to highlight anything.
if (subLists != null && subLists.length == 0) {
subLists = null;
}
selector.dispose();
actionPerformed(new ActionEvent(this, 1, "plot"));
} else if (ae.getActionCommand().equals("plot")) {
DataStore xStore = (DataStore) xStores.getSelectedItem();
DataStore yStore = (DataStore) yStores.getSelectedItem();
getContentPane().remove(scatterPlotPanel);
// Check if these stores are quantitated
if (!xStore.isQuantitated()) {
JOptionPane.showMessageDialog(this, xStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
} else if (!yStore.isQuantitated()) {
JOptionPane.showMessageDialog(this, yStore.name() + " is not quantiated", "Can't make plot", JOptionPane.INFORMATION_MESSAGE);
} else {
scatterPlotPanel = new ScatterPlotPanel(xStore, yStore, probeList, subLists, commonScaleBox.isSelected(), dotSizeSlider.getValue());
getContentPane().add(scatterPlotPanel, BorderLayout.CENTER);
}
validate();
} else if (ae.getActionCommand().equals("save_probe_list")) {
if (scatterPlotPanel instanceof ScatterPlotPanel) {
ProbeList list = ((ScatterPlotPanel) scatterPlotPanel).getFilteredProbes(collection.probeSet());
if (list.getAllProbes().length == 0) {
JOptionPane.showMessageDialog(this, "No probes were selected", "No probes", JOptionPane.INFORMATION_MESSAGE);
return;
}
// Ask for a name for the list
String groupName = null;
while (true) {
groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + list.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, list.name());
if (groupName == null) {
// Remove the list which will have been created by this stage
list.delete();
// They cancelled
return;
}
if (groupName.length() == 0)
// Try again
continue;
break;
}
list.setName(groupName);
}
} else if (ae.getActionCommand().equals("save_image")) {
ImageSaver.saveImage(scatterPlotPanel);
} else {
throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class MAPlotPanel method getFilteredProbes.
/**
* Gets the filtered probes.
*
* @param probeset the probeset
* @return the filtered probes
*/
public ProbeList getFilteredProbes(ProbeSet probeset) {
double minY = Math.min(ySelectionStart, ySelectionEnd);
double maxY = Math.max(ySelectionStart, ySelectionEnd);
ProbeList list = new ProbeList(probeList, "Difference between " + df.format(minY) + " and " + df.format(maxY), "Difference between " + xStore.name() + " and " + yStore.name() + " was between " + df.format(minY) + " and " + df.format(maxY), null);
if (madeSelection) {
Probe[] probes = probeList.getAllProbes();
for (int p = 0; p < probes.length; p++) {
try {
double diff = xStore.getValueForProbe(probes[p]) - yStore.getValueForProbe(probes[p]);
if (diff < minY)
continue;
if (diff > maxY)
continue;
list.addProbe(probes[p], null);
} catch (SeqMonkException e) {
e.printStackTrace();
}
}
}
return list;
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class HierarchicalClusterPanel method saveClusters.
public ProbeList saveClusters(int minClusterSize) {
ProbeList allClusterList = new ProbeList(probeList, "Hierarchical Clusters", "Hierarchical Clusters with R > " + rValue, null);
// Now we need to work our way through the connected clusters
// to make the appropriate sub-lists
ClusterPair[] connectedClusters = clusters.getConnectedClusters((float) rValue);
int runningCount = 0;
for (int subListIndex = 0; subListIndex < connectedClusters.length; subListIndex++) {
Integer[] indices = connectedClusters[subListIndex].getAllIndices();
// System.err.println("Looking at index "+subListIndex+" which has "+indices.length+" probes");
runningCount += indices.length;
// If we're starting before the currently visible set then we can skip
if (runningCount - indices.length < currentYStartIndex) {
// System.err.println("Skipping index "+(runningCount-indices.length)+" which is less than "+currentYStartIndex);
continue;
}
// If we're after the end of the current visible set we can stop all together
if (runningCount > (currentYEndIndex + 1)) {
// System.err.println("Stopping because "+runningCount+" is bigger than "+currentYEndIndex);
break;
}
// We may get rid of the list later if there are duplicates in it.
if (indices.length < minClusterSize)
continue;
Probe[] theseProbes = new Probe[indices.length];
for (int i = 0; i < theseProbes.length; i++) {
theseProbes[i] = probes[indices[i]];
}
// We used to sort and deduplicate these clusters so that we could be sure
// the number of probes is correct. We're now going to leave this alone
// (probe lists deduplicate internally) and annotate on the index rather
// than the r-value of the specific cluster.
ProbeList thisList = new ProbeList(allClusterList, "Cluster " + (subListIndex + 1), "HiC cluster list number " + (subListIndex + 1), "Index");
thisList.addProbe(theseProbes[0], (float) 0);
allClusterList.addProbe(theseProbes[0], null);
for (int i = 1; i < theseProbes.length; i++) {
if (theseProbes[i] == theseProbes[i - 1])
continue;
thisList.addProbe(theseProbes[i], (float) i);
allClusterList.addProbe(theseProbes[i], null);
}
}
return allClusterList;
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class SeqMonkParser method parseLists.
/**
* Parses the set of probe lists.
*
* @param sections The tab split initial line from the probe lists section
* @throws SeqMonkException
* @throws IOException Signals that an I/O exception has occurred.
*/
private void parseLists(String[] sections) throws SeqMonkException, IOException {
if (sections.length != 2) {
throw new SeqMonkException("Probe Lists line didn't contain 2 sections");
}
int n = Integer.parseInt(sections[1]);
ProbeList[] lists = new ProbeList[n];
// We also store the probe lists in their appropriate linkage position
// to recreate the links between probe lists. The worst case scenario
// is that we have one big chain of linked lists so we make a linkage
// list which is the same size as the number of probe lists.
ProbeList[] linkage = new ProbeList[n + 1];
// The 0 linkage list will always be the full ProbeSet
linkage[0] = application.dataCollection().probeSet();
for (int i = 0; i < n; i++) {
String line = br.readLine();
if (line == null) {
throw new SeqMonkException("Ran out of probe data at line " + i + " (expected " + n + " probes)");
}
String[] listSections = line.split("\\t", -1);
// we allow for that not being present.
if (thisDataVersion < 5) {
lists[i] = new ProbeList(application.dataCollection().probeSet(), listSections[0], "", listSections[1]);
if (listSections.length > 2) {
lists[i].setDescription(listSections[2]);
} else {
lists[i].setDescription("No description");
}
} else {
lists[i] = new ProbeList(linkage[Integer.parseInt(listSections[0]) - 1], listSections[1], listSections[3], listSections[2]);
if (listSections.length > 4) {
lists[i].setComments(listSections[4].replaceAll("`", "\n"));
}
linkage[Integer.parseInt(listSections[0])] = lists[i];
}
}
// Next we reach the probe list data. These comes as a long list of values
// the first of which is the probe name, then either a numerical value if
// the probe is contained in that list, or a blank if it isn't.
String line = br.readLine();
if (line == null) {
throw new SeqMonkException("Couldn't find probe line for list data");
}
sections = line.split("\\t");
if (sections.length != 2) {
throw new SeqMonkException("Probe line didn't contain 2 sections");
}
if (!sections[0].equals("Probes")) {
throw new SeqMonkException("Couldn't find expected probe lists probe line");
}
n = Integer.parseInt(sections[1]);
for (int i = 0; i < n; i++) {
sections = br.readLine().split("\\t", -1);
if (sections.length != lists.length + 1) {
throw new SeqMonkException("Expected " + (lists.length + 1) + " sections in probe list section of data file for " + sections[0] + " but got " + sections.length);
}
if (i % 1000 == 0) {
Enumeration<ProgressListener> e = listeners.elements();
while (e.hasMoreElements()) {
e.nextElement().progressUpdated("Processed list data for " + i + " probes", i, n);
}
}
Probe p = probes[i];
if (p == null) {
continue;
}
for (int j = 0; j < lists.length; j++) {
if (sections[j + 1].length() > 0) {
if (sections[j + 1].equals("NaN")) {
lists[j].addProbe(p, null);
} else {
lists[j].addProbe(p, new Float(Float.parseFloat(sections[j + 1])));
}
}
}
}
}
Aggregations