use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class SubsetNormalisationQuantitation 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[] { "Add", "Multiply" });
optionPanel.add(correctionActions, gbc);
gbc.gridx = 1;
gbc.gridy++;
optionPanel.add(new JLabel("Summation Method"), gbc);
gbc.gridx = 2;
summationActions = new JComboBox(new String[] { "Mean", "Sum" });
optionPanel.add(summationActions, gbc);
gbc.gridx = 1;
gbc.gridy++;
optionPanel.add(new JLabel("Target Value"), gbc);
gbc.gridx = 2;
targetActions = new JComboBox(new String[] { "Largest", "1" });
optionPanel.add(targetActions, 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]);
gbc.gridx = 1;
gbc.gridy++;
optionPanel.add(new JLabel("Calculate from probe list"), gbc);
ProbeList[] currentLists = application.dataCollection().probeSet().getAllProbeLists();
calculateFromProbeList = new JComboBox(currentLists);
calculateFromProbeList.setPrototypeDisplayValue("No longer than this please");
for (int i = 0; i < currentLists.length; i++) {
if (currentLists[i] == application.dataCollection().probeSet().getActiveList()) {
calculateFromProbeList.setSelectedIndex(i);
}
}
gbc.gridx++;
optionPanel.add(calculateFromProbeList, gbc);
return optionPanel;
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class SubsetNormalisationQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
if (!isReady()) {
progressExceptionReceived(new SeqMonkException("Options weren't set correctly"));
}
Probe[] allProbes = application.dataCollection().probeSet().getAllProbes();
Probe[] calculateProbes = ((ProbeList) calculateFromProbeList.getSelectedItem()).getAllProbes();
float[] summedValues = new float[data.length];
// since we need that whether or not they're taking the mean.
for (int d = 0; d < data.length; d++) {
progressUpdated("Calculating correction for " + data[d].name(), d, data.length);
for (int p = 0; p < calculateProbes.length; p++) {
try {
summedValues[d] += data[d].getValueForProbe(calculateProbes[p]);
} catch (SeqMonkException e) {
progressExceptionReceived(e);
}
}
}
if (summationAction == VALUE_MEAN) {
for (int i = 0; i < summedValues.length; i++) {
summedValues[i] /= calculateProbes.length;
}
}
float targetValue = 1;
if (targetAction == TARGET_LARGEST) {
targetValue = summedValues[0];
for (int i = 1; i < summedValues.length; i++) {
if (summedValues[i] > targetValue)
targetValue = summedValues[i];
}
}
for (int d = 0; d < data.length; d++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
progressUpdated(d, data.length);
// Get the correction value
float correctionFactor = 1;
if (correctionAction == ADD) {
correctionFactor = targetValue - summedValues[d];
} else if (correctionAction == MULTIPLY) {
correctionFactor = targetValue / summedValues[d];
}
System.err.println("For " + data[d].name() + " correction factor is " + correctionFactor);
try {
for (int p = 0; p < allProbes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
if (correctionAction == ADD) {
data[d].setValueForProbe(allProbes[p], data[d].getValueForProbe(allProbes[p]) + correctionFactor);
} else if (correctionAction == MULTIPLY) {
data[d].setValueForProbe(allProbes[p], data[d].getValueForProbe(allProbes[p]) * correctionFactor);
}
}
} catch (SeqMonkException e) {
progressExceptionReceived(e);
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList in project SeqMonk by s-andrews.
the class EnrichmentNormalisationQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
if (!isReady()) {
progressExceptionReceived(new SeqMonkException("Options weren't set correctly"));
}
Probe[] allProbes = application.dataCollection().probeSet().getAllProbes();
Probe[] calculateProbes = ((ProbeList) calculateFromProbeList.getSelectedItem()).getAllProbes();
float[] lowerPercentileValues = new float[data.length];
float[] upperPercentileValues = new float[data.length];
// Work out the value at the appropriate percentile
for (int d = 0; d < data.length; d++) {
progressUpdated("Calculating correction for " + data[d].name(), d, data.length);
float[] theseValues = new float[calculateProbes.length];
for (int p = 0; p < calculateProbes.length; p++) {
try {
theseValues[p] = data[d].getValueForProbe(calculateProbes[p]);
} catch (SeqMonkException e) {
progressExceptionReceived(e);
}
}
Arrays.sort(theseValues);
lowerPercentileValues[d] = getPercentileValue(theseValues, lowerPercentile);
upperPercentileValues[d] = getPercentileValue(theseValues, upperPercentile);
System.err.println("Lower percentile for " + data[d].name() + " is " + lowerPercentileValues[d] + " from " + theseValues.length + " values");
}
float lowerMedian = SimpleStats.median(Arrays.copyOf(lowerPercentileValues, lowerPercentileValues.length));
float upperMedian = SimpleStats.median(Arrays.copyOf(upperPercentileValues, upperPercentileValues.length));
for (int d = 0; d < data.length; d++) {
System.err.println("Looking at " + data[d].name());
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
progressUpdated(d, data.length);
// Now we work out the correction factor we're actually going to use
float lowerCorrectionFactor = lowerMedian - lowerPercentileValues[d];
float upperCorrectionFactor = ((upperPercentileValues[d] + lowerCorrectionFactor) - lowerMedian) / (upperMedian - lowerMedian);
System.err.println("Lower percentile = " + lowerPercentileValues[d]);
System.err.println("Upper percentile = " + upperPercentileValues[d]);
System.err.println("Lower median = " + lowerMedian);
System.err.println("Upper median = " + upperMedian);
System.err.println("Lower correction = " + lowerCorrectionFactor);
System.err.println("Upper correction = " + upperCorrectionFactor);
System.err.println("\n\n");
// Apply the correction to all probes
try {
for (int p = 0; p < allProbes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
float probeValue = data[d].getValueForProbe(allProbes[p]);
probeValue += lowerCorrectionFactor;
probeValue -= lowerMedian;
probeValue /= upperCorrectionFactor;
probeValue += lowerMedian;
data[d].setValueForProbe(allProbes[p], probeValue);
}
} catch (SeqMonkException e) {
progressExceptionReceived(e);
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList 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.Probes.ProbeList in project SeqMonk by s-andrews.
the class ShuffleListProbeGenerator method getOptionsPanel.
/* (non-Javadoc)
* @see uk.ac.babraham.SeqMonk.ProbeGenerators.ProbeGenerator#getOptionsPanel(uk.ac.babraham.SeqMonk.SeqMonkApplication)
*/
public JPanel getOptionsPanel() {
if (optionPanel != null) {
// We've done this already
return optionPanel;
}
ProbeList currentActiveList = null;
if (collection.probeSet() != null) {
currentLists = collection.probeSet().getAllProbeLists();
currentActiveList = collection.probeSet().getActiveList();
} else {
currentLists = new ProbeList[0];
}
optionPanel = new JPanel();
optionPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 0.1;
gbc.weighty = 0.5;
gbc.fill = GridBagConstraints.HORIZONTAL;
optionPanel.add(new JLabel("Select List"), gbc);
gbc.gridx++;
gbc.weightx = 0.9;
selectedListBox = new JComboBox(currentLists);
selectedListBox.setPrototypeDisplayValue("No longer than this please");
for (int i = 0; i < currentLists.length; i++) {
if (currentLists[i] == currentActiveList) {
selectedListBox.setSelectedIndex(i);
}
}
selectedListBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
isReady();
}
});
optionPanel.add(selectedListBox, gbc);
gbc.gridx = 1;
gbc.gridy++;
gbc.weightx = 0.1;
optionPanel.add(new JLabel("Maintain Chromosomal Distribution"), gbc);
gbc.gridx++;
gbc.weightx = 0.9;
keepChromosomalDistributionBox = new JCheckBox("", true);
optionPanel.add(keepChromosomalDistributionBox, gbc);
gbc.gridx = 1;
gbc.gridy++;
gbc.weightx = 0.1;
optionPanel.add(new JLabel("Constrain within the probeset positions"), gbc);
gbc.gridx++;
gbc.weightx = 0.9;
limitEndsBox = new JCheckBox("", true);
optionPanel.add(limitEndsBox, gbc);
return optionPanel;
}
Aggregations