use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class RelativeQuantitation 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.01;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(2, 2, 2, 2);
optionPanel.add(new JLabel("Reference"), gbc);
gbc.gridx = 2;
optionPanel.add(new JLabel("Data Stores"), gbc);
gbc.gridy++;
gbc.gridx = 1;
gbc.weighty = 0.99;
gbc.fill = GridBagConstraints.BOTH;
DefaultListModel dataModel = new DefaultListModel();
DataStore[] stores = application.dataCollection().getAllDataStores();
Vector<DataStore> quantitatedStores = new Vector<DataStore>();
for (int i = 0; i < stores.length; i++) {
if (stores[i].isQuantitated()) {
dataModel.addElement(stores[i]);
if (!(stores[i] instanceof ReplicateSet)) {
quantitatedStores.add(stores[i]);
}
}
}
data = quantitatedStores.toArray(new DataStore[0]);
referenceList = new JList(dataModel);
// only allow one to be selected
referenceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
referenceList.setCellRenderer(new TypeColourRenderer());
referenceList.addListSelectionListener(this);
optionPanel.add(new JScrollPane(referenceList), gbc);
gbc.gridx = 2;
tableModel = new ReferencePairingTableModel();
JTable refTable = new JTable(tableModel);
optionPanel.add(new JScrollPane(refTable), gbc);
gbc.gridx = 1;
gbc.gridy++;
gbc.weighty = 0.01;
gbc.fill = GridBagConstraints.NONE;
JButton applyToSelectionButton = new JButton("Apply to Selected");
applyToSelectionButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object value = referenceList.getSelectedValue();
// if (value == null) return;
tableModel.setReference((DataStore) value);
}
});
optionPanel.add(applyToSelectionButton, gbc);
gbc.gridx = 2;
JButton selectAllButton = new JButton("Apply to All");
selectAllButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tableModel.selectAll();
Object value = referenceList.getSelectedValue();
tableModel.setReference((DataStore) value);
}
});
// applyToSelectionButton.addActionListener(this);
optionPanel.add(selectAllButton, gbc);
// define relative quantitation method
gbc.gridx = 1;
gbc.gridy++;
gbc.fill = GridBagConstraints.HORIZONTAL;
optionPanel.add(new JLabel("Reference method"), gbc);
gbc.gridx = 2;
diffTypeBox = new JComboBox(new String[] { "Minus", "Log Divide", "Divide" });
// default : divide
diffTypeBox.setSelectedIndex(2);
optionPanel.add(diffTypeBox, gbc);
return optionPanel;
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class SmoothingSubtractionQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
if (!isReady()) {
progressExceptionReceived(new SeqMonkException("Options weren't set correctly"));
}
Chromosome[] chromosomes = application.dataCollection().genome().getAllChromosomes();
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]);
}
}
DataStore[] data = quantitatedStores.toArray(new DataStore[0]);
for (int c = 0; c < chromosomes.length; c++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
progressUpdated(c, chromosomes.length);
Probe[] allProbes = application.dataCollection().probeSet().getProbesForChromosome(chromosomes[c]);
float[][] newValues = new float[data.length][allProbes.length];
try {
for (int p = 0; p < allProbes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
// Find the min and max indices we're going to use.
int minIndex = p;
int maxIndex = p;
if (correctionAction == ADJACENT) {
minIndex = p - (distance / 2);
maxIndex = minIndex + (distance - 1);
if (minIndex < 0)
minIndex = 0;
if (maxIndex > allProbes.length - 1)
maxIndex = allProbes.length - 1;
} else if (correctionAction == WINDOW) {
for (int i = p; i >= 0; i--) {
if (allProbes[i].end() < allProbes[p].start() - (distance / 2)) {
break;
}
minIndex = i;
}
for (int i = p; i < allProbes.length; i++) {
if (allProbes[i].start() > allProbes[p].end() + (distance / 2)) {
break;
}
maxIndex = i;
}
}
// Now go through all of the datasets working out the new value for this range
float[] tempValues = new float[(maxIndex - minIndex) + 1];
for (int d = 0; d < data.length; d++) {
for (int i = minIndex; i <= maxIndex; i++) {
tempValues[i - minIndex] = data[d].getValueForProbe(allProbes[i]);
}
newValues[d][p] = SimpleStats.mean(tempValues);
}
}
// Now assign the values for the probes on this chromosome
for (int d = 0; d < data.length; d++) {
for (int p = 0; p < allProbes.length; p++) {
data[d].setValueForProbe(allProbes[p], data[d].getValueForProbe(allProbes[p]) - newValues[d][p]);
}
}
} catch (SeqMonkException e) {
progressExceptionReceived(e);
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore 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();
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class HiCPrevNextQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
Probe[] probes = application.dataCollection().probeSet().getAllProbes();
Arrays.sort(probes);
for (int p = 0; p < probes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
if (probes[p].start() - distance < 0 || probes[p].end() + distance > probes[p].chromosome().length()) {
for (int d = 0; d < data.length; d++) {
((DataStore) data[d]).setValueForProbe(probes[p], 0);
}
continue;
}
// Make up a pseudo probe for the previous and next regions
Probe previousProbe = new Probe(probes[p].chromosome(), probes[p].start() - distance, probes[p].start());
Probe nextProbe = new Probe(probes[p].chromosome(), probes[p].end(), probes[p].end() + distance);
progressUpdated(p, probes.length);
for (int d = 0; d < data.length; d++) {
// Get the counts for the previous and next probes
int previousTotalCount = data[d].getHiCReadCountForProbe(previousProbe);
HiCHitCollection hiCHits = data[d].getHiCReadsForProbe(probes[p]);
int nextTotalCount = data[d].getHiCReadCountForProbe(nextProbe);
// any reads then give up on this one.
if (previousTotalCount == 0 || nextTotalCount == 0) {
((DataStore) data[d]).setValueForProbe(probes[p], 0);
continue;
}
int previousCount = 0;
int nextCount = 0;
long[] hitPositions = hiCHits.getHitPositionsForChromosome(hiCHits.getSourceChromosomeName());
SequenceRead.sort(hitPositions);
for (int r = 0; r < hitPositions.length; r++) {
// Check if we can ignore this one
if (removeDuplicates) {
if (r > 0 && hitPositions[r] == hitPositions[r - 1])
continue;
}
// Check if the other end maps to either the prev or next probe
if (SequenceRead.overlaps(hitPositions[r], previousProbe.packedPosition())) {
++previousCount;
}
if (SequenceRead.overlaps(hitPositions[r], nextProbe.packedPosition())) {
++nextCount;
}
}
// If both of the actual counts are zero then don't try to calculate a real value
if (previousCount == 0 && nextCount == 0) {
((DataStore) data[d]).setValueForProbe(probes[p], 0);
continue;
}
// Basically what happens here is that we calculate a normal X^2 value and then
// turn it into a negative depending on the direction of the deviation from the
// expected proportion.
// We need to calculate expected values for the two directions based on the proportion
// of reads falling into those two regions in total.
// Correct the counts based on the proportions of the two totals
double expectedProportion = (previousTotalCount / (double) (nextTotalCount + previousTotalCount));
int totalObservedCount = previousCount + nextCount;
double expectedPreviousCount = totalObservedCount * expectedProportion;
double expectedNextCount = totalObservedCount - expectedPreviousCount;
// Now we can calculate the X^2 values to compare the expected and observed values
double chisquare = (Math.pow(previousCount - expectedPreviousCount, 2) / expectedPreviousCount) + (Math.pow(nextCount - expectedNextCount, 2) / expectedNextCount);
// We now negate this count if the proportions bias towards the next count
double observedProportion = (previousCount / (double) totalObservedCount);
if (observedProportion > expectedProportion) {
chisquare = 0 - chisquare;
}
// System.err.println("Raw counts "+previousCount+","+nextCount+" Totals "+previousTotalCount+","+nextTotalCount+" Expected "+expectedPreviousCount+","+expectedNextCount+" Chi "+chisquare);
// TODO: This is icky since the inheritance between HiCDataStore and DataStore
// isn't properly sorted out.
((DataStore) data[d]).setValueForProbe(probes[p], (float) chisquare);
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class PerProbeNormalisationQuantitation 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[] { "Subtract", "Log Divide", "Scale" });
optionPanel.add(correctionActions, gbc);
gbc.gridy++;
gbc.gridx = 1;
optionPanel.add(new JLabel("Averaging Method"), gbc);
gbc.gridx = 2;
averageMethod = new JComboBox(new String[] { "Median", "Mean" });
optionPanel.add(averageMethod, 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]);
return optionPanel;
}
Aggregations