use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class SmoothingQuantitation 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], 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 SeqMonkParser method parseReplicates.
/**
* Parses the list of replicate sets.
*
* @param sections The tab split values from the initial replicates line
* @throws SeqMonkException
* @throws IOException Signals that an I/O exception has occurred.
*/
private void parseReplicates(String[] sections) throws SeqMonkException, IOException {
if (sections.length != 2) {
throw new SeqMonkException("Data Groups line didn't contain 2 sections");
}
if (!sections[0].equals("Replicate Sets")) {
throw new SeqMonkException("Couldn't find expected replicates line");
}
int n = Integer.parseInt(sections[1]);
for (int i = 0; i < n; i++) {
String[] replicateLine = br.readLine().split("\\t");
DataStore[] groupMembers = new DataStore[replicateLine.length - 1];
for (int j = 1; j < replicateLine.length; j++) {
if (replicateLine[j].startsWith("g")) {
replicateLine[j] = replicateLine[j].substring(1);
groupMembers[j - 1] = application.dataCollection().getDataGroup(Integer.parseInt(replicateLine[j]));
} else if (replicateLine[j].startsWith("s")) {
replicateLine[j] = replicateLine[j].substring(1);
groupMembers[j - 1] = application.dataCollection().getDataSet(Integer.parseInt(replicateLine[j]));
} else {
throw new SeqMonkException("Replicate member id " + replicateLine[j] + " didn't start with g or s");
}
if (groupMembers[j - 1] == null) {
throw new SeqMonkException("Couldn't find replicate member from position " + replicateLine[j]);
}
}
ReplicateSet r = new ReplicateSet(replicateLine[0], groupMembers);
application.dataCollection().addReplicateSet(r);
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class SeqMonkParser method parseVisibleStores.
/**
* Parses the list of dataStores which should initially be visible
*
* @param sections The tab split initial line from the visible stores section
* @throws SeqMonkException
* @throws IOException Signals that an I/O exception has occurred.
*/
private void parseVisibleStores(String[] sections) throws SeqMonkException, IOException {
if (sections.length != 2) {
throw new SeqMonkException("Visible stores line didn't contain 2 sections");
}
int n = Integer.parseInt(sections[1]);
/*
* Collect the drawn stores in an array. We used to add them as we found
* them but this was inefficient since we had to redo a calculation for
* every one we added. This way we only need to calculate once.
*/
DataStore[] drawnStores = new DataStore[n];
if (thisDataVersion < 4) {
// In the bad old days we used to refer to datasets and stores by name
// which caused problems when names were duplicated. We do our best
// with these cases.
DataSet[] sets = application.dataCollection().getAllDataSets();
DataGroup[] groups = application.dataCollection().getAllDataGroups();
for (int i = 0; i < n; i++) {
String line = br.readLine();
if (line == null) {
throw new SeqMonkException("Ran out of visible store data at line " + i + " (expected " + n + " stores)");
}
String[] storeSections = line.split("\\t");
if (storeSections.length != 2) {
throw new SeqMonkException("Expected 2 sections in visible store line but got " + storeSections.length);
}
if (storeSections[1].equals("set")) {
for (int s = 0; s < sets.length; s++) {
if (sets[s].name().equals(storeSections[0])) {
drawnStores[i] = sets[s];
break;
}
}
} else if (storeSections[1].equals("group")) {
for (int g = 0; g < groups.length; g++) {
if (groups[g].name().equals(storeSections[0])) {
drawnStores[i] = groups[g];
break;
}
}
} else {
throw new SeqMonkException("Didn't recognise data type '" + storeSections[1] + "' when adding visible stores from line '" + line + "'");
}
}
} else {
for (int i = 0; i < n; i++) {
String line = br.readLine();
if (line == null) {
throw new SeqMonkException("Ran out of visible store data at line " + i + " (expected " + n + " stores)");
}
String[] storeSections = line.split("\\t");
if (storeSections.length != 2) {
throw new SeqMonkException("Expected 2 sections in visible store line but got " + storeSections.length);
}
if (storeSections[1].equals("set")) {
drawnStores[i] = application.dataCollection().getDataSet(Integer.parseInt(storeSections[0]));
} else if (storeSections[1].equals("group")) {
drawnStores[i] = application.dataCollection().getDataGroup(Integer.parseInt(storeSections[0]));
} else if (storeSections[1].equals("replicate")) {
drawnStores[i] = application.dataCollection().getReplicateSet(Integer.parseInt(storeSections[0]));
} else {
throw new SeqMonkException("Didn't recognise data type '" + storeSections[1] + "' when adding visible stores from line '" + line + "'");
}
}
}
application.addToDrawnDataStores(drawnStores);
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class ReplicateSetEditor method valueChanged.
/* (non-Javadoc)
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
*/
public void valueChanged(ListSelectionEvent ae) {
// Check for a new set being selected
if (ae.getSource() == replicateSetList) {
// Move all samples back to the available list
DataStore[] o = usedModel.getStores();
availableModel.addElements(o);
usedList.setSelectedIndices(new int[0]);
availableList.setSelectedIndices(new int[0]);
usedModel.removeAllElements();
if (replicateSetList.getSelectedValues().length == 1) {
renameButton.setEnabled(true);
deleteButton.setEnabled(true);
ReplicateSet s = (ReplicateSet) replicateSetList.getSelectedValue();
DataStore[] st = s.dataStores();
usedModel.addElements(st);
availableModel.removeElements(st);
usedList.setSelectedIndices(new int[0]);
availableList.setSelectedIndices(new int[0]);
} else if (replicateSetList.getSelectedValues().length > 1) {
deleteButton.setEnabled(true);
} else {
deleteButton.setEnabled(false);
}
}
// Check to see if we can add anything...
if (availableList.getSelectedIndices().length > 0 && replicateSetList.getSelectedIndices().length == 1) {
addButton.setEnabled(true);
} else {
addButton.setEnabled(false);
}
// Or remove anything
if (usedList.getSelectedIndices().length > 0 && replicateSetList.getSelectedIndices().length == 1) {
removeButton.setEnabled(true);
} else {
removeButton.setEnabled(false);
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class ChromosomeViewer method tracksUpdated.
/**
* This is quite a heavyweight call to make. It forces the recalculation
* of the layout of all tracks. In many cases it is sufficient to call
* repaint on the chromosome viewer which will update existing information
* (name changes, selection changes etc). Only use this when the actual
* data has changed.
*/
public void tracksUpdated() {
if (featurePanel == null)
return;
String[] featureTypes = application.drawnFeatureTypes();
featureTracks.removeAllElements();
for (int i = 0; i < featureTypes.length; i++) {
ChromosomeFeatureTrack t = new ChromosomeFeatureTrack(this, featureTypes[i], application.dataCollection().genome().annotationCollection().getFeaturesForType(chromosome, featureTypes[i]));
featureTracks.add(t);
}
DataStore[] dataStores = application.drawnDataStores();
dataTracks.removeAllElements();
for (int i = 0; i < dataStores.length; i++) {
if (dataStores[i] instanceof ReplicateSet && DisplayPreferences.getInstance().getReplicateSetExpansion() == DisplayPreferences.REPLICATE_SETS_EXPANDED) {
DataStore[] localStores = ((ReplicateSet) dataStores[i]).dataStores();
for (int j = 0; j < localStores.length; j++) {
ChromosomeDataTrack t = new ChromosomeDataTrack(this, application.dataCollection(), localStores[j]);
t.setEnclosingReplicateSet((ReplicateSet) dataStores[i]);
dataTracks.add(t);
}
} else {
if (dataStores[i] == application.dataCollection().getActiveDataStore()) {
ChromosomeDataTrack t = new MinSizeDataTrack(this, application.dataCollection(), dataStores[i]);
dataTracks.add(t);
} else {
ChromosomeDataTrack t = new ChromosomeDataTrack(this, application.dataCollection(), dataStores[i]);
dataTracks.add(t);
}
}
}
featurePanel.removeAll();
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 0.001;
Enumeration<ChromosomeFeatureTrack> e = featureTracks.elements();
while (e.hasMoreElements()) {
featurePanel.add(e.nextElement(), c);
c.gridy++;
}
// We weight the data tracks way more heavily than the feature tracks since the feature tracks
// have a preferred size which we don't need to exceed but the data tracks should take up whatever
// is left.
c.weighty = 0.6;
Enumeration<ChromosomeDataTrack> e2 = dataTracks.elements();
while (e2.hasMoreElements()) {
featurePanel.add(e2.nextElement(), c);
c.gridy++;
}
// Finally add a scale track, which we weigh very lightly
c.weighty = 0.00001;
featurePanel.add(new ChromosomeScaleTrack(this), c);
c.gridy++;
featurePanel.validate();
featurePanel.repaint();
}
Aggregations