use of uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix in project SeqMonk by s-andrews.
the class HeatmapProbeListWindow method progressComplete.
public void progressComplete(String command, Object result) {
if (command.equals("heatmap")) {
if (matrix.interactions().length == 0) {
JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No interactions were found", "Interaction Result", JOptionPane.INFORMATION_MESSAGE);
dispose();
return;
}
heatmapPanel = new HeatmapProbeListPanelCollection(data, probeLists, matrix, genome);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(heatmapPanel, BorderLayout.CENTER);
filterOptions = new HeatmapFilterOptions(matrix);
getContentPane().add(filterOptions, BorderLayout.WEST);
JPanel buttonPanel = new JPanel();
JButton closeButton = new JButton("Close");
closeButton.setActionCommand("close");
closeButton.addActionListener(this);
buttonPanel.add(closeButton);
JButton saveImageButton = new JButton("Save Image");
saveImageButton.setActionCommand("save_image");
saveImageButton.addActionListener(this);
buttonPanel.add(saveImageButton);
JButton saveProbesButton = new JButton("Save Probe List");
saveProbesButton.setActionCommand("save_probes");
saveProbesButton.addActionListener(this);
buttonPanel.add(saveProbesButton);
JButton makeReportButton = new JButton("Make Report");
makeReportButton.setActionCommand("make_report");
makeReportButton.addActionListener(this);
buttonPanel.add(makeReportButton);
clusterButton = new JButton("Cluster Interactions");
clusterButton.setActionCommand("cluster");
clusterButton.addActionListener(this);
buttonPanel.add(clusterButton);
saveClustersButton = new JButton("Save current clusters");
saveClustersButton.setActionCommand("save_clusters");
saveClustersButton.addActionListener(this);
saveClustersButton.setEnabled(false);
buttonPanel.add(saveClustersButton);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setSize(800, 500);
setLocationRelativeTo(SeqMonkApplication.getInstance());
setVisible(true);
} else if (command.equals("interaction_cluster_matrix")) {
// We can start the actual clustering
HierarchicalClusterSet clusterSet = new HierarchicalClusterSet((InteractionClusterMatrix) result);
clusterSet.addListener(new ProgressDialog(this, "HiC Interaction Clustering", clusterSet));
clusterSet.addListener(this);
clusterSet.startClustering();
} else if (command.equals("interaction_cluster")) {
matrix.setCluster((ClusterPair) result);
clusterButton.setText("Remove clustering");
clusterButton.setEnabled(true);
saveClustersButton.setEnabled(true);
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix in project SeqMonk by s-andrews.
the class HiCPCADomainQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
// We're going to go through the probes one chromosome at a time so we
// can reduce the complexity we have to deal with
Chromosome[] chromosomes = application.dataCollection().genome().getAllChromosomes();
for (int c = 0; c < chromosomes.length; c++) {
if (cancel) {
progressCancelled();
return;
}
currentChromosome = chromosomes[c];
Probe[] probes = application.dataCollection().probeSet().getProbesForChromosome(chromosomes[c]);
if (probes.length < 5) {
progressWarningReceived(new SeqMonkException("Too few probes on chromosome " + currentChromosome.name() + " - assigning zero to everything"));
// It's not worth trying to find domains
for (int d = 0; d < data.length; d++) {
for (int p = 0; p < probes.length; p++) {
((DataStore) data[d]).setValueForProbe(probes[p], 0f);
}
}
continue;
}
ProbeList thisChrProbes = new ProbeList(application.dataCollection().probeSet(), chromosomes[c].name(), "", null);
for (int p = 0; p < probes.length; p++) {
thisChrProbes.addProbe(probes[p], 0f);
}
for (int d = 0; d < data.length; d++) {
if (cancel) {
progressCancelled();
return;
}
currentStore = data[d];
current = (d * chromosomes.length) + c;
total = chromosomes.length * data.length;
progressUpdated("Processing chromosome " + chromosomes[c].name() + " for " + data[d].name(), current, total);
HeatmapMatrix matrix = new HeatmapMatrix(data[d], new ProbeList[] { thisChrProbes }, application.dataCollection().genome(), optionsPanel.minDistance(), optionsPanel.maxDistance(), optionsPanel.minStrength(), optionsPanel.maxSignificance(), optionsPanel.minAbsolute(), optionsPanel.correctLinkage());
matrix.addProgressListener(this);
wait = true;
matrix.startCalculating();
while (wait) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
if (cancel) {
progressCancelled();
return;
}
if (matrix.filteredInteractions().length < 10) {
progressWarningReceived(new SeqMonkException("Too few interactions on chromosome " + currentChromosome.name() + " for " + data[d].name() + " - assigning zero to everything"));
// not going to get a sensible answer anyway.
for (int p = 0; p < probes.length; p++) {
((DataStore) data[d]).setValueForProbe(probes[p], 0f);
}
continue;
}
InteractionClusterMatrix clusterMatrix = new InteractionClusterMatrix(matrix.filteredInteractions(), probes.length);
clusterMatrix.addListener(this);
wait = true;
clusterMatrix.startCorrelating();
while (wait) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
float[][] correlationMatrix = clusterMatrix.correlationMatix();
// Annoyingly the PCA needs a double [][]
double[][] correlationMatrixDouble = new double[correlationMatrix.length][];
for (int i = 0; i < correlationMatrix.length; i++) {
double[] db = new double[correlationMatrix[i].length];
for (int j = 0; j < db.length; j++) {
db[j] = correlationMatrix[i][j];
}
correlationMatrixDouble[i] = db;
}
// Now we can calculate the PCA values from the correlation matrix
PCA pca = new PCA(correlationMatrixDouble);
pca.addProgressListener(this);
wait = true;
pca.startCalculating();
while (wait) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
double[] extractedEigenValues = pca.extractedEigenValues();
// for these probes
for (int p = 0; p < probes.length; p++) {
((DataStore) data[d]).setValueForProbe(probes[p], (float) extractedEigenValues[p]);
}
}
thisChrProbes.delete();
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix in project SeqMonk by s-andrews.
the class HeatmapProbeListWindow 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_image")) {
ImageSaver.saveImage(heatmapPanel);
} else if (ae.getActionCommand().equals("cluster")) {
if (clusterButton.getText().equals("Cluster Interactions")) {
// First we need to make up an interaction cluster matrix which we
// can then feed to the generic hierarchical clustering program
InteractionClusterMatrix clusterMatrix = new InteractionClusterMatrix(matrix.filteredInteractions(), matrix.probeCount());
clusterMatrix.addListener(new ProgressDialog(this, "HiC Interaction Clustering", clusterMatrix));
clusterMatrix.addListener(this);
clusterMatrix.startCorrelating();
clusterButton.setEnabled(false);
} else {
matrix.setCluster(null);
saveClustersButton.setEnabled(false);
clusterButton.setText("Cluster Interactions");
}
} else if (ae.getActionCommand().equals("save_probes")) {
ProbeList newList = matrix.createProbeListFromCurrentInteractions();
// Ask for a name for the list
String groupName = null;
while (true) {
groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + newList.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, newList.name());
if (groupName == null) {
// Since the list will automatically have been added to
// the ProbeList tree we actively need to delete it if
// they choose to cancel at this point.
newList.delete();
// They cancelled
return;
}
if (groupName.length() == 0)
// Try again
continue;
break;
}
newList.setName(groupName);
} else if (ae.getActionCommand().equals("save_clusters")) {
if (matrix.cluster() == null)
return;
// Get a limit for how many probes per cluster
String howManyProbes = JOptionPane.showInputDialog(this, "Minimum number of probes per cluster", "10");
if (howManyProbes == null)
return;
int minProbes;
try {
minProbes = Integer.parseInt(howManyProbes);
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(this, howManyProbes + " was not an integer", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
ProbeList newList = matrix.createProbeListsFromClusters(minProbes, heatmapPanel.probeListPanel().currentYStartIndex(), heatmapPanel.probeListPanel().currentYEndIndex());
// This was called before clustering had completed.
if (newList == null)
return;
// Ask for a name for the list
String groupName = null;
while (true) {
groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + newList.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, newList.name());
if (groupName == null) {
// Since the list will automatically have been added to
// the ProbeList tree we actively need to delete it if
// they choose to cancel at this point.
newList.delete();
// They cancelled
return;
}
if (groupName.length() == 0)
// Try again
continue;
break;
}
newList.setName(groupName);
} else if (ae.getActionCommand().equals("make_report")) {
new InteractionReportOptions(SeqMonkApplication.getInstance(), new AnnotatedInteractionReport(SeqMonkApplication.getInstance().dataCollection(), matrix));
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix in project SeqMonk by s-andrews.
the class HeatmapGenomeWindow method progressComplete.
public void progressComplete(String command, Object result) {
if (command.equals("heatmap")) {
if (matrix.interactions().length == 0) {
JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No interactions were found", "Interaction Result", JOptionPane.INFORMATION_MESSAGE);
dispose();
return;
}
heatmapPanel = new HeatmapGenomePanelCollection(data, probes, matrix, genome);
heatmapPanel.genomePanel().addPositionListener(this);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(heatmapPanel, BorderLayout.CENTER);
filterOptions = new HeatmapFilterOptions(matrix);
getContentPane().add(filterOptions, BorderLayout.WEST);
JPanel buttonPanel = new JPanel();
JButton closeButton = new JButton("Close");
closeButton.setActionCommand("close");
closeButton.addActionListener(this);
buttonPanel.add(closeButton);
JButton matchButton = new JButton("Match Chr View");
matchButton.setActionCommand("match");
matchButton.addActionListener(this);
buttonPanel.add(matchButton);
sendXButton = new JButton("Send X");
sendXButton.setActionCommand("send_x");
sendXButton.addActionListener(this);
sendXButton.setEnabled(false);
buttonPanel.add(sendXButton);
sendYButton = new JButton("Send Y");
sendYButton.setActionCommand("send_y");
sendYButton.addActionListener(this);
sendYButton.setEnabled(false);
buttonPanel.add(sendYButton);
JButton saveImageButton = new JButton("Save Image");
saveImageButton.setActionCommand("save_image");
saveImageButton.addActionListener(this);
buttonPanel.add(saveImageButton);
JButton saveProbesButton = new JButton("Save Probe List");
saveProbesButton.setActionCommand("save_probes");
saveProbesButton.addActionListener(this);
buttonPanel.add(saveProbesButton);
JButton makeReportButton = new JButton("Make Report");
makeReportButton.setActionCommand("make_report");
makeReportButton.addActionListener(this);
buttonPanel.add(makeReportButton);
clusterButton = new JButton("Cluster Interactions");
clusterButton.setActionCommand("cluster");
clusterButton.addActionListener(this);
buttonPanel.add(clusterButton);
saveClustersButton = new JButton("Save current clusters");
saveClustersButton.setActionCommand("save_clusters");
saveClustersButton.addActionListener(this);
saveClustersButton.setEnabled(false);
buttonPanel.add(saveClustersButton);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setSize(800, 500);
setLocationRelativeTo(SeqMonkApplication.getInstance());
setVisible(true);
} else if (command.equals("interaction_cluster_matrix")) {
// We can start the actual clustering
HierarchicalClusterSet clusterSet = new HierarchicalClusterSet((InteractionClusterMatrix) result);
clusterSet.addListener(new ProgressDialog(this, "HiC Interaction Clustering", clusterSet));
clusterSet.addListener(this);
clusterSet.startClustering();
} else if (command.equals("interaction_cluster")) {
matrix.setCluster((ClusterPair) result);
clusterButton.setText("Remove clustering");
clusterButton.setEnabled(true);
saveClustersButton.setEnabled(true);
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.Interaction.InteractionClusterMatrix in project SeqMonk by s-andrews.
the class HeatmapGenomeWindow 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_image")) {
ImageSaver.saveImage(heatmapPanel);
} else if (ae.getActionCommand().equals("cluster")) {
if (clusterButton.getText().equals("Cluster Interactions")) {
// First we need to make up an interaction cluster matrix which we
// can then feed to the generic hierarchical clustering program
InteractionClusterMatrix clusterMatrix = new InteractionClusterMatrix(matrix.filteredInteractions(), matrix.probeCount());
clusterMatrix.addListener(new ProgressDialog(this, "HiC Interaction Clustering", clusterMatrix));
clusterMatrix.addListener(this);
clusterMatrix.startCorrelating();
clusterButton.setEnabled(false);
} else {
matrix.setCluster(null);
saveClustersButton.setEnabled(false);
clusterButton.setText("Cluster Interactions");
}
} else if (ae.getActionCommand().equals("save_probes")) {
ProbeList newList = matrix.createProbeListFromCurrentInteractions();
// Ask for a name for the list
String groupName = null;
while (true) {
groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + newList.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, newList.name());
if (groupName == null) {
// Since the list will automatically have been added to
// the ProbeList tree we actively need to delete it if
// they choose to cancel at this point.
newList.delete();
// They cancelled
return;
}
if (groupName.length() == 0)
// Try again
continue;
break;
}
newList.setName(groupName);
} else if (ae.getActionCommand().equals("save_clusters")) {
if (matrix.cluster() == null)
return;
// Get a limit for how many probes per cluster
String howManyProbes = JOptionPane.showInputDialog(this, "Minimum number of probes per cluster", "10");
if (howManyProbes == null)
return;
int minProbes;
try {
minProbes = Integer.parseInt(howManyProbes);
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(this, howManyProbes + " was not an integer", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
ProbeList newList = matrix.createProbeListsFromClusters(minProbes, heatmapPanel.genomePanel().currentYStartIndex(), heatmapPanel.genomePanel().currentYEndIndex());
// This was called before clustering had completed.
if (newList == null)
return;
// Ask for a name for the list
String groupName = null;
while (true) {
groupName = (String) JOptionPane.showInputDialog(this, "Enter list name", "Found " + newList.getAllProbes().length + " probes", JOptionPane.QUESTION_MESSAGE, null, null, newList.name());
if (groupName == null) {
// Since the list will automatically have been added to
// the ProbeList tree we actively need to delete it if
// they choose to cancel at this point.
newList.delete();
// They cancelled
return;
}
if (groupName.length() == 0)
// Try again
continue;
break;
}
newList.setName(groupName);
} else if (ae.getActionCommand().equals("send_x")) {
DisplayPreferences.getInstance().setLocation(xChr, SequenceRead.packPosition(xStart, xEnd, Location.UNKNOWN));
} else if (ae.getActionCommand().equals("send_y")) {
DisplayPreferences.getInstance().setLocation(yChr, SequenceRead.packPosition(yStart, yEnd, Location.UNKNOWN));
} else if (ae.getActionCommand().equals("match")) {
Chromosome chr = DisplayPreferences.getInstance().getCurrentChromosome();
int start = SequenceRead.start(DisplayPreferences.getInstance().getCurrentLocation());
int end = SequenceRead.end(DisplayPreferences.getInstance().getCurrentLocation());
heatmapPanel.genomePanel().setCurrentPosition(chr, start, end);
} else if (ae.getActionCommand().equals("make_report")) {
new InteractionReportOptions(SeqMonkApplication.getInstance(), new AnnotatedInteractionReport(SeqMonkApplication.getInstance().dataCollection(), matrix));
}
}
Aggregations