use of uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore in project SeqMonk by s-andrews.
the class CisTransScatterPlotDialog 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("plot")) {
HiCDataStore store = (HiCDataStore) hiCStores.getSelectedItem();
getContentPane().remove(scatterPlotPanel);
scatterPlotPanel = new CisTransScatterPlotPanel(store, collection.probeSet().getActiveList(), commonScaleBox.isSelected(), dotSizeSlider.getValue());
getContentPane().add(scatterPlotPanel, BorderLayout.CENTER);
validate();
} else if (ae.getActionCommand().equals("filter_chromosome")) {
Chromosome c;
if (chromosomes.getSelectedItem() instanceof Chromosome) {
c = (Chromosome) chromosomes.getSelectedItem();
} else {
c = null;
}
if (scatterPlotPanel instanceof CisTransScatterPlotPanel) {
((CisTransScatterPlotPanel) scatterPlotPanel).setChromosome(c);
}
} else if (ae.getActionCommand().equals("save_probe_list")) {
if (scatterPlotPanel instanceof CisTransScatterPlotPanel) {
ProbeList list = ((CisTransScatterPlotPanel) 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);
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore in project SeqMonk by s-andrews.
the class DataTreeRenderer method getTreeCellRendererComponent.
/* (non-Javadoc)
* @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
*/
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DataSet) {
JLabel label = new JLabel(value.toString(), dataSetIcon, JLabel.LEFT);
if (value instanceof HiCDataStore && ((HiCDataStore) value).isValidHiC()) {
label.setText("[HiC] " + label.getText());
}
if (selected) {
label.setOpaque(true);
label.setBackground(Color.LIGHT_GRAY);
}
return label;
} else if (value instanceof DataGroup) {
JLabel label = new JLabel(value.toString(), dataGroupIcon, JLabel.LEFT);
if (value instanceof HiCDataStore && ((HiCDataStore) value).isValidHiC()) {
label.setText("[HiC] " + label.getText());
}
if (selected) {
label.setOpaque(true);
label.setBackground(Color.LIGHT_GRAY);
}
return label;
} else if (value instanceof ReplicateSet) {
JLabel label = new JLabel(value.toString(), replicateSetIcon, JLabel.LEFT);
if (value instanceof HiCDataStore && ((HiCDataStore) value).isValidHiC()) {
label.setText("[HiC] " + label.getText());
}
if (selected) {
label.setOpaque(true);
label.setBackground(Color.LIGHT_GRAY);
}
return label;
} else if (value instanceof ProbeList) {
JLabel label = new JLabel(value.toString(), probeListIcon, JLabel.LEFT);
if (selected) {
label.setOpaque(true);
label.setBackground(Color.LIGHT_GRAY);
}
return label;
} else if (value instanceof AnnotationSet) {
JLabel label = new JLabel(value.toString(), annotationSetIcon, JLabel.LEFT);
if (selected) {
label.setOpaque(true);
label.setBackground(Color.LIGHT_GRAY);
}
return label;
} else {
return super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore in project SeqMonk by s-andrews.
the class TypeColourRenderer method getListCellRendererComponent.
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus) {
// will make it do something more sensible
if (value == null) {
return new JLabel("null");
}
JLabel l = new JLabel(value.toString());
if (value instanceof HiCDataStore) {
if (((HiCDataStore) value).isValidHiC()) {
l.setText("[HiC] " + l.getText());
}
}
if (value instanceof DataSet) {
l.setForeground(ColourScheme.DATASET_LIST);
l.setBackground(ColourScheme.DATASET_LIST);
} else if (value instanceof DataGroup) {
l.setForeground(ColourScheme.DATAGROUP_LIST);
l.setBackground(ColourScheme.DATAGROUP_LIST);
} else {
// Should only be replicate sets
l.setForeground(ColourScheme.REPLICATE_SET_LIST);
l.setBackground(ColourScheme.REPLICATE_SET_LIST);
}
if (selected) {
l.setForeground(Color.WHITE);
l.setOpaque(true);
}
return l;
}
use of uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore in project SeqMonk by s-andrews.
the class FourCEnrichmentQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
// Start off by finding the right HiC data for each 4C dataset
HiCDataStore[] parentHiC = new HiCDataStore[data.length];
Probe[] parentProbes = new Probe[data.length];
ProbeList[] significantLists = new ProbeList[data.length];
for (int d = 0; d < data.length; d++) {
String filename = data[d].fileName();
filename = filename.replaceAll("HiC other end of ", "");
filename = filename.replaceAll(" for region.*", "");
System.err.println("Looking for HiC match to " + filename);
for (int h = 0; h < hiCData.length; h++) {
if (((DataStore) hiCData[h]).name().equals(filename)) {
parentHiC[d] = hiCData[h];
}
}
if (parentHiC[d] == null) {
progressWarningReceived(new SeqMonkException("Failed to find HiC dataset '" + filename + "' for 4C dataset " + data[d].name()));
continue;
}
significantLists[d] = new ProbeList(application.dataCollection().probeSet(), "4C p<0.05 " + data[d].name(), "4C pipeline significance < 0.05", "P-value");
// Also make up a probe to represent the region from which
// the dataset was made
filename = data[d].fileName();
filename = filename.replaceAll("^.*for region ", "");
String[] locationSections = filename.split("[-:]");
if (locationSections.length != 3) {
progressWarningReceived(new SeqMonkException("Couldn't extract location from " + filename));
continue;
}
try {
parentProbes[d] = new Probe(application.dataCollection().genome().getChromosome(locationSections[0]).chromosome(), Integer.parseInt(locationSections[1]), Integer.parseInt(locationSections[2]));
} catch (Exception e) {
progressExceptionReceived(e);
return;
}
}
// Make strength calculators for each HiC set
HiCInteractionStrengthCalculator[] strengthCalculators = new HiCInteractionStrengthCalculator[parentHiC.length];
for (int i = 0; i < parentHiC.length; i++) {
strengthCalculators[i] = new HiCInteractionStrengthCalculator(parentHiC[i], true);
}
// Get the cis/trans counts for the parent probes
int[] parentProbeCisCounts = new int[parentHiC.length];
int[] parentProbeTransCounts = new int[parentHiC.length];
for (int p = 0; p < parentHiC.length; p++) {
if (parentHiC[p] == null)
continue;
HiCHitCollection hits = parentHiC[p].getHiCReadsForProbe(parentProbes[p]);
String[] chrNames = hits.getChromosomeNamesWithHits();
for (int c = 0; c < chrNames.length; c++) {
if (chrNames[c].equals(hits.getSourceChromosomeName())) {
parentProbeCisCounts[p] = hits.getSourcePositionsForChromosome(chrNames[c]).length;
} else {
parentProbeTransCounts[p] += hits.getSourcePositionsForChromosome(chrNames[c]).length;
}
}
}
Probe[] probes = application.dataCollection().probeSet().getAllProbes();
for (int p = 0; p < probes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
progressUpdated(p, probes.length);
for (int d = 0; d < data.length; d++) {
if (parentHiC[d] == null)
continue;
int thisProbeCisCount = 0;
int thisProbeTransCount = 0;
HiCHitCollection hiCHits = parentHiC[d].getHiCReadsForProbe(probes[p]);
String[] chrNames = hiCHits.getChromosomeNamesWithHits();
for (int c = 0; c < chrNames.length; c++) {
if (chrNames[c].equals(hiCHits.getSourceChromosomeName())) {
thisProbeCisCount = hiCHits.getSourcePositionsForChromosome(chrNames[c]).length;
} else {
thisProbeTransCount += hiCHits.getSourcePositionsForChromosome(chrNames[c]).length;
}
}
strengthCalculators[d].calculateInteraction(data[d].getReadsForProbe(probes[p]).length, thisProbeCisCount, thisProbeTransCount, parentProbeCisCounts[d], parentProbeTransCounts[d], probes[p], parentProbes[d]);
float obsExp = (float) strengthCalculators[d].obsExp();
data[d].setValueForProbe(probes[p], obsExp);
float pValue = (float) strengthCalculators[d].rawPValue() * probes.length;
if (pValue < 0.05) {
significantLists[d].addProbe(probes[p], pValue);
}
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore in project SeqMonk by s-andrews.
the class HiCCisTransQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
Probe[] probes = application.dataCollection().probeSet().getAllProbes();
for (int p = 0; p < probes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
progressUpdated(p, probes.length);
for (int d = 0; d < data.length; d++) {
int cisCount = 0;
int transCount = 0;
HiCHitCollection hiCHits = data[d].getHiCReadsForProbe(probes[p]);
String[] chromosomeNames = hiCHits.getChromosomeNamesWithHits();
for (int c = 0; c < chromosomeNames.length; c++) {
long[] sourceReads = hiCHits.getSourcePositionsForChromosome(chromosomeNames[c]);
long[] hitReads = hiCHits.getHitPositionsForChromosome(chromosomeNames[c]);
for (int r = 0; r < sourceReads.length; r++) {
// Check if we can ignore this one
if (removeDuplicates) {
if (r > 0 && sourceReads[r] == sourceReads[r - 1] && hitReads[r] == hitReads[r - 1])
continue;
}
if (!chromosomeNames[c].equals(probes[p].chromosome().name())) {
++transCount;
} else {
if (includeFarCis) {
int distance = SequenceRead.fragmentLength(sourceReads[r], hitReads[r]);
if (distance > farCisDistance) {
++transCount;
} else {
// System.err.println("Distance was "+distance);
++cisCount;
}
} else {
++cisCount;
}
}
}
}
float percentage = ((transCount * 100f) / (cisCount + transCount));
if (cisCount + transCount == 0) {
percentage = 0;
}
// TODO: This is icky since the inheritance between HiCDataStore and DataStore
// isn't properly sorted out.
((DataStore) data[d]).setValueForProbe(probes[p], percentage);
}
}
if (correctPerChromosome) {
Chromosome[] chrs = application.dataCollection().genome().getAllChromosomes();
for (int c = 0; c < chrs.length; c++) {
Probe[] thisChrProbes = application.dataCollection().probeSet().getProbesForChromosome(chrs[c]);
float[] thisChrValues = new float[thisChrProbes.length];
for (int d = 0; d < data.length; d++) {
DataStore ds = (DataStore) data[d];
for (int p = 0; p < thisChrProbes.length; p++) {
try {
thisChrValues[p] = ds.getValueForProbe(thisChrProbes[p]);
} catch (SeqMonkException e) {
}
}
float median = SimpleStats.median(thisChrValues);
for (int p = 0; p < thisChrProbes.length; p++) {
try {
ds.setValueForProbe(thisChrProbes[p], ds.getValueForProbe(thisChrProbes[p]) - median);
} catch (SeqMonkException e) {
}
}
}
}
}
quantitatonComplete();
}
Aggregations