use of uk.ac.babraham.SeqMonk.Analysis.Statistics.BoxWhisker in project SeqMonk by s-andrews.
the class BoxWhiskerFilter method generateProbeList.
/* (non-Javadoc)
* @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
*/
protected void generateProbeList() {
ProbeList newList = new ProbeList(startingList, "Filtered Probes", "", null);
Hashtable<Probe, Integer> hitCounts = new Hashtable<Probe, Integer>();
for (int s = 0; s < stores.length; s++) {
progressUpdated("Processing " + stores[s].name(), s, stores.length);
if (cancel) {
cancel = false;
progressCancelled();
return;
}
BoxWhisker bw;
try {
bw = new BoxWhisker(stores[s], startingList, stringency);
} catch (SeqMonkException e) {
System.err.println("Ignoring unquantitated dataset");
e.printStackTrace();
continue;
}
if (useUpper) {
Probe[] p = bw.upperProbeOutliers();
if (cancel) {
cancel = false;
progressCancelled();
return;
}
for (int i = 0; i < p.length; i++) {
if (hitCounts.containsKey(p[i])) {
hitCounts.put(p[i], hitCounts.get(p[i]).intValue() + 1);
} else {
hitCounts.put(p[i], 1);
}
}
}
if (useLower) {
Probe[] p = bw.lowerProbeOutliers();
for (int i = 0; i < p.length; i++) {
if (cancel) {
cancel = false;
progressCancelled();
return;
}
if (hitCounts.containsKey(p[i])) {
hitCounts.put(p[i], hitCounts.get(p[i]).intValue() + 1);
} else {
hitCounts.put(p[i], 1);
}
}
}
}
// Now we can go through the probes which hit and see if
// we had enough hits to put them into our final list.
Enumeration<Probe> candidates = hitCounts.keys();
while (candidates.hasMoreElements()) {
if (cancel) {
cancel = false;
progressCancelled();
return;
}
Probe candidate = candidates.nextElement();
int count = hitCounts.get(candidate).intValue();
// probe to the probe set.
switch(filterType) {
case EXACTLY:
if (count == storeCutoff)
newList.addProbe(candidate, null);
break;
case AT_LEAST:
if (count >= storeCutoff)
newList.addProbe(candidate, null);
break;
case NO_MORE_THAN:
if (count <= storeCutoff)
newList.addProbe(candidate, null);
break;
}
}
filterFinished(newList);
}
use of uk.ac.babraham.SeqMonk.Analysis.Statistics.BoxWhisker in project SeqMonk by s-andrews.
the class MultiBoxWhiskerDialog method actionPerformed.
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("close")) {
setVisible(false);
dispose();
} else if (ae.getActionCommand().equals("save")) {
ImageSaver.saveImage(graphPanel);
} else if (ae.getActionCommand().equals("save_data")) {
JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new FileFilter() {
public String getDescription() {
return "Text Files";
}
public boolean accept(File f) {
if (f.isDirectory() || f.getName().toLowerCase().endsWith(".txt")) {
return true;
}
return false;
}
});
int result = chooser.showSaveDialog(MultiBoxWhiskerDialog.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(MultiBoxWhiskerDialog.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;
}
}
// Now write out the results
try {
PrintWriter pr = new PrintWriter(file);
pr.println("ProbeList\tDataStore\tMedian\tLowerQuartile\tUpperQuartile\tLowerWhisker\tUpperWhisker\tOutliers");
StringBuffer br;
// Now do all of the data stores
for (int s = 0; s < stores.length; s++) {
for (int p = 0; p < probes.length; p++) {
br = new StringBuffer();
BoxWhisker bw = whiskers[p][s];
br.append(probes[p].name());
br.append("\t");
br.append(stores[s].name());
br.append("\t");
br.append(bw.median());
br.append("\t");
br.append(bw.lowerQuartile());
br.append("\t");
br.append(bw.upperQuartile());
br.append("\t");
br.append(bw.lowerWhisker());
br.append("\t");
br.append(bw.upperWhisker());
float[] outliers = bw.lowerOutliers();
for (int f = 0; f < outliers.length; f++) {
br.append("\t");
br.append(outliers[f]);
}
outliers = bw.upperOutliers();
for (int f = 0; f < outliers.length; f++) {
br.append("\t");
br.append(outliers[f]);
}
pr.println(br.toString());
}
}
pr.close();
} catch (IOException ioe) {
throw new IllegalStateException(ioe);
}
} else if (ae.getActionCommand().equals("xaxis")) {
if (!xAxisChoice.getSelectedItem().equals(currentChoice)) {
currentChoice = (String) xAxisChoice.getSelectedItem();
updateGraphs();
}
} else {
throw new IllegalStateException("Unknown command " + ae.getActionCommand());
}
}
use of uk.ac.babraham.SeqMonk.Analysis.Statistics.BoxWhisker in project SeqMonk by s-andrews.
the class MultiBoxWhiskerDialog method run.
public void run() {
whiskers = new BoxWhisker[probes.length][stores.length];
try {
for (int p = 0; p < probes.length; p++) {
for (int s = 0; s < stores.length; s++) {
whiskers[p][s] = new BoxWhisker(stores[s], probes[p]);
if (p == 0 && s == 0) {
min = (float) whiskers[p][s].minValue();
max = (float) whiskers[p][s].maxValue();
}
if (whiskers[p][s].minValue() < min) {
min = (float) whiskers[p][s].minValue();
}
if (whiskers[p][s].maxValue() > max) {
max = (float) whiskers[p][s].maxValue();
}
}
}
updateGraphs();
setVisible(true);
} catch (SeqMonkException sme) {
throw new IllegalStateException(sme);
}
}
use of uk.ac.babraham.SeqMonk.Analysis.Statistics.BoxWhisker in project SeqMonk by s-andrews.
the class MultiBoxWhiskerDialog method updateGraphs.
private void updateGraphs() {
boolean useProbesOnXAxis = true;
if (xAxisChoice.getSelectedItem().equals("Data Stores")) {
useProbesOnXAxis = false;
}
int rows;
int cols;
if (useProbesOnXAxis) {
rows = (int) Math.sqrt(stores.length);
cols = stores.length / rows;
if (stores.length % rows > 0) {
cols++;
}
} else {
rows = (int) Math.sqrt(probes.length);
cols = probes.length / rows;
if (probes.length % rows > 0) {
cols++;
}
}
graphPanel.removeAll();
graphPanel.setLayout(new GridLayout(rows, cols));
if (useProbesOnXAxis) {
String[] panelNames = new String[probes.length];
for (int p = 0; p < probes.length; p++) {
panelNames[p] = probes[p].name();
}
for (int g = 0; g < stores.length; g++) {
String groupName = stores[g].name();
BoxWhisker[] theseWhiskers = new BoxWhisker[probes.length];
for (int p = 0; p < probes.length; p++) {
theseWhiskers[p] = whiskers[p][g];
}
MultiBoxWhiskerPanel graph = new MultiBoxWhiskerPanel(theseWhiskers, panelNames, groupName, min, max);
graph.setBorder(BorderFactory.createLineBorder(Color.BLACK));
graphPanel.add(graph);
}
} else {
String[] panelNames = new String[stores.length];
for (int s = 0; s < stores.length; s++) {
panelNames[s] = stores[s].name();
}
for (int p = 0; p < probes.length; p++) {
String groupName = probes[p].name();
BoxWhisker[] theseWhiskers = new BoxWhisker[stores.length];
for (int s = 0; s < stores.length; s++) {
theseWhiskers[s] = whiskers[p][s];
}
MultiBoxWhiskerPanel graph = new MultiBoxWhiskerPanel(theseWhiskers, panelNames, groupName, min, max);
graph.setBorder(BorderFactory.createLineBorder(Color.BLACK));
graphPanel.add(graph);
}
}
graphPanel.revalidate();
graphPanel.repaint();
}
Aggregations