use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class HiCReadCountQuantitation method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
Probe[] probes = application.dataCollection().probeSet().getAllProbes();
float[] corrections = new float[data.length];
if (correctTotal) {
float largest = 0;
if (correctPerMillion) {
largest = 1000000;
}
for (int d = 0; d < data.length; d++) {
// if (correctOnlyInProbes) {
// corrections[d] = getTotalCountInProbes(data[d],probes);
// }
// else {
corrections[d] = ((DataStore) data[d]).getTotalReadCount();
// }
if (d == 0 && !correctPerMillion) {
largest = corrections[d];
} else {
if (!correctPerMillion && corrections[d] > largest) {
largest = corrections[d];
}
}
}
// We correct everything by the largest count
for (int d = 0; d < corrections.length; d++) {
corrections[d] = largest / corrections[d];
}
}
for (int p = 0; p < probes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
double lengthCorrection = 1;
if (correctLength) {
// We assume a 'normal' probe length of 1kb
lengthCorrection = (double) 1000 / probes[p].length();
}
progressUpdated(p, probes.length);
for (int d = 0; d < data.length; d++) {
double count = 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 (SequenceRead.overlaps(hitReads[r], probes[p].packedPosition()) && SequenceRead.compare(hitReads[r], sourceReads[r]) > 0) {
continue;
}
++count;
}
}
if (logTransform && count == 0) {
count = 0.9;
}
if (correctTotal) {
count *= corrections[d];
}
if (correctLength) {
count *= lengthCorrection;
}
if (logTransform) {
count = (float) Math.log(count) / log2;
}
// TODO: This is icky since the inheritance between HiCDataStore and DataStore
// isn't properly sorted out.
((DataStore) data[d]).setValueForProbe(probes[p], (float) count);
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class AnnotatedListReport method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
String annotationTypeValue = (String) annotationType.getSelectedItem();
int distanceLimit = 0;
// Check what to do with unannotated probes
boolean includeAll = true;
if (((String) excludes.getSelectedItem()).equals("Exclude")) {
includeAll = false;
}
String annotationPositionValue = (String) annotationPosition.getSelectedItem();
// We're going to set up a set of booleans which tell us which kinds
// of relationships we're allowed to look for later.
boolean surrounding = true;
boolean upstream = true;
boolean downstream = true;
boolean matchname = false;
boolean exactmatch = false;
boolean skipAnnotation = false;
if (annotationPositionValue.equals("[Don't annotate]")) {
upstream = false;
downstream = false;
surrounding = false;
skipAnnotation = true;
} else if (annotationPositionValue.equals("overlapping")) {
upstream = false;
downstream = false;
} else if (annotationPositionValue.equals("exactly overlapping")) {
upstream = false;
downstream = false;
exactmatch = true;
} else if (annotationPositionValue.equals("surrounding or upstream")) {
downstream = false;
} else if (annotationPositionValue.equals("surrounding or downstream")) {
upstream = false;
} else if (annotationPositionValue.equals("upstream")) {
surrounding = false;
downstream = false;
} else if (annotationPositionValue.equals("downstream")) {
surrounding = false;
upstream = false;
} else if (annotationPositionValue.equals("closest")) {
// Leave things as they are!
} else if (annotationPositionValue.equals("name matched")) {
matchname = true;
upstream = false;
surrounding = false;
downstream = false;
} else {
System.err.println("Didn't recognise position value '" + annotationPositionValue + "'");
}
// surrounding.
if (!annotationPositionValue.equals("surrounding")) {
if (annotationLimit.getText().length() > 0) {
distanceLimit = Integer.parseInt(annotationLimit.getText());
}
}
Vector<ProbeAnnotation> annotations = new Vector<ProbeAnnotation>();
// Since we're going to be making the annotations on the
// basis of position we should go through all probes one
// chromosome at a time.
Chromosome[] chrs = collection.genome().getAllChromosomes();
for (int c = 0; c < chrs.length; c++) {
progressUpdated("Processing Chr" + chrs[c].name(), c, chrs.length);
Probe[] probes = collection.probeSet().getActiveList().getProbesForChromosome(chrs[c]);
Feature[] features = new Feature[0];
if (!skipAnnotation) {
features = collection.genome().annotationCollection().getFeaturesForType(chrs[c], annotationTypeValue);
}
// We can now step through the probes looking for the best feature match
for (int p = 0; p < probes.length; p++) {
if (cancel) {
progressCancelled();
return;
}
String nameWithoutExtensions = "";
String nameWithoutTranscript = "";
if (matchname) {
nameWithoutExtensions = probes[p].name().replaceFirst("_upstream$", "").replaceAll("_downstream$", "").replaceAll("_gene$", "");
nameWithoutTranscript = nameWithoutExtensions.replaceAll("-\\d\\d\\d$", "");
}
Feature bestFeature = null;
int closestDistance = 0;
String relationshipType = "Not found";
for (int f = 0; f < features.length; f++) {
if (matchname) {
// Simplest check is if the name matches exactly
if (features[f].name().equals(probes[p].name()) || features[f].name().equals(nameWithoutExtensions) || features[f].name().equals(nameWithoutTranscript)) {
bestFeature = features[f];
closestDistance = 0;
relationshipType = "Name match";
break;
}
}
if (surrounding) {
if (probes[p].start() <= features[f].location().end() && probes[p].end() >= features[f].location().start()) {
// If this is an exact overlap then we check to see that the positions exactly align.
if ((!exactmatch) || (probes[p].start() == features[f].location().start() && probes[p].end() == features[f].location().end())) {
bestFeature = features[f];
closestDistance = 0;
relationshipType = "overlapping";
// Once we've found an overlapping feature we quit.
break;
}
}
}
if (downstream) {
// Check if the feature is downstream
// Get the distance to the start
int d = 0;
if (features[f].location().strand() == Location.FORWARD) {
d = features[f].location().start() - probes[p].end();
} else {
d = probes[p].start() - features[f].location().end();
}
if (d >= 0) {
if (d > distanceLimit || (bestFeature != null && d > closestDistance)) {
continue;
}
// See if this is the closest feature we have so far...
if (bestFeature == null || d < closestDistance) {
bestFeature = features[f];
relationshipType = "downstream";
closestDistance = d;
}
continue;
}
}
if (upstream) {
// Check if the feature is upstream
// Get the distance to the start
int d = 0;
if (features[f].location().strand() == Location.FORWARD) {
d = probes[p].start() - features[f].location().end();
} else {
d = features[f].location().start() - probes[p].end();
}
if (d >= 0) {
if (d > distanceLimit || (bestFeature != null && d > closestDistance)) {
continue;
}
// See if this is the closest feature we have so far...
if (bestFeature == null || d < closestDistance) {
bestFeature = features[f];
relationshipType = "upstream";
closestDistance = d;
}
continue;
}
}
}
if (bestFeature == null && (!includeAll)) {
continue;
}
annotations.add(new ProbeAnnotation(probes[p], bestFeature, closestDistance, relationshipType));
}
}
if (includeAll) {
Probe[] probes = collection.probeSet().getActiveList().getProbesForChromosome(null);
for (int p = 0; p < probes.length; p++) {
annotations.add(new ProbeAnnotation(probes[p], null, 0, "Not found"));
}
}
DataStore[] stores = new DataStore[0];
if (((String) data.getSelectedItem()).equals("Include")) {
stores = storesToAnnotate;
}
TableModel model = new AnnotationTableModel(annotations.toArray(new ProbeAnnotation[0]), collection.probeSet().getActiveList(), stores);
reportComplete(model);
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class ProbeGroupReport method run.
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
String annotationTypeValue = (String) annotationType.getSelectedItem();
int distanceLimit = 0;
// Check what to do with unannotated probes
boolean includeAll = true;
if (((String) excludes.getSelectedItem()).equals("Exclude")) {
includeAll = false;
}
String annotationPositionValue = (String) annotationPosition.getSelectedItem();
// We're going to set up a set of booleans which tell us which kinds
// of relationships we're allowed to look for later.
boolean annotateIndividualProbes = true;
boolean justEnclosed = false;
boolean surrounding = true;
boolean upstream = true;
boolean downstream = true;
if (annotationPositionValue.equals("[Don't annotate]")) {
// It's easier to leave this true as we can bail out the annotation more quickly
annotateIndividualProbes = true;
justEnclosed = false;
surrounding = false;
upstream = false;
downstream = false;
} else if (annotationPositionValue.equals("all overlapping")) {
annotateIndividualProbes = false;
justEnclosed = false;
} else if (annotationPositionValue.equals("all enclosed")) {
annotateIndividualProbes = false;
justEnclosed = true;
} else if (annotationPositionValue.equals("surrounding")) {
upstream = false;
downstream = false;
} else if (annotationPositionValue.equals("surrounding or upstream")) {
downstream = false;
} else if (annotationPositionValue.equals("surrounding or downstream")) {
upstream = false;
} else if (annotationPositionValue.equals("upstream")) {
surrounding = false;
downstream = false;
} else if (annotationPositionValue.equals("downstream")) {
surrounding = false;
upstream = false;
} else if (annotationPositionValue.equals("closest")) {
// Leave things as they are!
} else {
System.err.println("Didn't recognise position value '" + annotationPositionValue + "'");
}
// surrounding.
if (!annotationPositionValue.equals("surrounding")) {
if (annotationLimit.getText().length() > 0) {
distanceLimit = Integer.parseInt(annotationLimit.getText());
}
}
// Find out how closely to group probes
int groupDistance = Integer.parseInt(probeDistanceLimit.getText());
Vector<ProbeGroupAnnotation> annotations = new Vector<ProbeGroupAnnotation>();
// Since we're going to be making the annotations on the
// basis of position we should go through all probes one
// chromosome at a time.
Chromosome[] chrs = collection.genome().getAllChromosomes();
for (int c = 0; c < chrs.length; c++) {
progressUpdated("Processing Chr" + chrs[c].name(), c, chrs.length);
Probe[] probes = collection.probeSet().getActiveList().getProbesForChromosome(chrs[c]);
Feature[] features = collection.genome().annotationCollection().getFeaturesForType(chrs[c], annotationTypeValue);
ProbeGroupAnnotation group = new ProbeGroupAnnotation();
int lastPosition = -1;
// We can now step through the probes looking for the best feature match
for (int p = 0; p < probes.length; p++) {
if (cancel) {
progressCancelled();
return;
}
if (lastPosition == -1 || probes[p].start() - groupDistance <= lastPosition) {
// We're in the same group
group.addProbe(probes[p]);
if (probes[p].end() > lastPosition)
lastPosition = probes[p].end();
// System.err.println("Adding to existing group");
} else {
// group annotations
if (!annotateIndividualProbes) {
annotateGroup(group, justEnclosed, annotationTypeValue);
}
if (includeAll || group.featureNames().length() > 0) {
// System.err.println("Adding group to keepers");
annotations.add(group);
} else {
// System.err.println("Not adding this group");
}
// Create a new group and add the current probe to start it off.
group = new ProbeGroupAnnotation();
group.addProbe(probes[p]);
lastPosition = probes[p].end();
}
if (!annotateIndividualProbes)
continue;
Feature bestFeature = null;
int closestDistance = 0;
for (int f = 0; f < features.length; f++) {
if (surrounding) {
if (probes[p].start() <= features[f].location().end() && probes[p].end() >= features[f].location().start()) {
bestFeature = features[f];
closestDistance = 0;
// Once we've found an overlapping feature we quit.
break;
}
}
if (downstream) {
// Check if the feature is downstream
// Get the distance to the start
int d = 0;
if (features[f].location().strand() == Location.FORWARD) {
d = features[f].location().start() - probes[p].end();
} else {
d = probes[p].start() - features[f].location().end();
}
if (d >= 0) {
if (d > distanceLimit || (bestFeature != null && d > closestDistance)) {
continue;
}
// See if this is the closest feature we have so far...
if (bestFeature == null || d < closestDistance) {
bestFeature = features[f];
closestDistance = d;
}
continue;
}
}
if (upstream) {
// Check if the feature is upstream
// Get the distance to the start
int d = 0;
if (features[f].location().strand() == Location.FORWARD) {
d = probes[p].start() - features[f].location().end();
} else {
d = features[f].location().start() - probes[p].end();
}
if (d >= 0) {
if (d > distanceLimit || (bestFeature != null && d > closestDistance)) {
continue;
}
// See if this is the closest feature we have so far...
if (bestFeature == null || d < closestDistance) {
bestFeature = features[f];
closestDistance = d;
}
continue;
}
}
}
if (bestFeature != null) {
group.addFeature(bestFeature);
}
}
// and do any necessary annotation.
if (group.numberOfProbes() > 0) {
// We need to do the annotation for this last group (if we have to)
if (!annotateIndividualProbes) {
annotateGroup(group, justEnclosed, annotationTypeValue);
}
if (includeAll || group.featureNames().length() > 0) {
// System.err.println("Adding group to keepers");
annotations.add(group);
}
}
}
DataStore[] stores = new DataStore[0];
if (((String) data.getSelectedItem()).equals("Include")) {
stores = storesToAnnotate;
}
TableModel model = new AnnotationTableModel(annotations.toArray(new ProbeGroupAnnotation[0]), stores);
reportComplete(model);
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class ContigProbeGenerator 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;
}
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.BOTH;
optionPanel.add(new JLabel("Stores to use"), gbc);
gbc.gridy++;
gbc.weighty = 0.9;
DataStore[] stores = collection.getAllDataStores();
storesList = new JList(stores);
storesList.getSelectionModel().addListSelectionListener(this);
storesList.setCellRenderer(new TypeColourRenderer());
optionPanel.add(new JScrollPane(storesList), gbc);
gbc.gridy++;
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new GridBagLayout());
GridBagConstraints bgbc = new GridBagConstraints();
bgbc.gridx = 0;
bgbc.gridy = 0;
bgbc.weightx = 0.5;
bgbc.weighty = 0.5;
bgbc.fill = GridBagConstraints.HORIZONTAL;
bottomPanel.add(new JLabel("Use reads on strand "), bgbc);
readStrandTypeBox = new JComboBox(ReadStrandType.getTypeOptions());
bgbc.gridx = 1;
bottomPanel.add(readStrandTypeBox, bgbc);
bgbc.gridy++;
bgbc.gridx = 0;
bottomPanel.add(new JLabel("Build peaks for strands seprately "), bgbc);
bgbc.gridx = 1;
separateStrands = new JCheckBox();
bottomPanel.add(separateStrands, bgbc);
bgbc.gridy++;
bgbc.gridx = 0;
bottomPanel.add(new JLabel("Ignore duplicate reads "), bgbc);
bgbc.gridx = 1;
ignoreDuplicates = new JCheckBox();
bottomPanel.add(ignoreDuplicates, bgbc);
bgbc.gridx = 0;
bgbc.gridy++;
bottomPanel.add(new JLabel("Merge contigs closer than (bp)"), bgbc);
bgbc.gridx = 1;
distField = new JTextField("0", 4);
distField.addKeyListener(this);
bottomPanel.add(distField, bgbc);
optionPanel.add(bottomPanel, gbc);
bgbc.gridx = 0;
bgbc.gridy++;
bottomPanel.add(new JLabel("Min Contig Size (bp) "), bgbc);
bgbc.gridx = 1;
minSizeField = new JTextField("0", 4);
minSizeField.addKeyListener(this);
bottomPanel.add(minSizeField, bgbc);
bgbc.gridx = 0;
bgbc.gridy++;
bottomPanel.add(new JLabel("Depth Cutoff "), bgbc);
bgbc.gridx = 1;
// TODO: Work out the effective fold change for the current cutoff
JPanel depthPanel = new JPanel();
minDepthField = new JTextField("0", 4);
minDepthField.addKeyListener(this);
depthPanel.add(minDepthField);
depthPanel.add(new JLabel("fold "));
depthIntLabel = new JLabel("(" + depthCutoff);
depthPanel.add(depthIntLabel);
depthPanel.add(new JLabel(" reads)"));
bottomPanel.add(depthPanel, bgbc);
optionPanel.add(bottomPanel, gbc);
return optionPanel;
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class EvenCoverageProbeGenerator 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;
}
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.BOTH;
optionPanel.add(new JLabel("Stores to use"), gbc);
gbc.gridy++;
gbc.weighty = 0.9;
DataStore[] stores = collection.getAllDataStores();
storesList = new JList(stores);
storesList.getSelectionModel().addListSelectionListener(this);
storesList.setCellRenderer(new TypeColourRenderer());
optionPanel.add(new JScrollPane(storesList), gbc);
gbc.gridy++;
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new GridBagLayout());
GridBagConstraints bgbc = new GridBagConstraints();
bgbc.gridx = 0;
bgbc.gridy = 0;
bgbc.weightx = 0.5;
bgbc.weighty = 0.5;
bgbc.fill = GridBagConstraints.HORIZONTAL;
bottomPanel.add(new JLabel("Use reads on strand "), bgbc);
readStrandTypeBox = new JComboBox(ReadStrandType.getTypeOptions());
bgbc.gridx = 1;
bottomPanel.add(readStrandTypeBox, bgbc);
bgbc.gridy++;
bgbc.gridx = 0;
bottomPanel.add(new JLabel("Ignore duplicate reads "), bgbc);
bgbc.gridx = 1;
ignoreDuplicates = new JCheckBox();
bottomPanel.add(ignoreDuplicates, bgbc);
bgbc.gridx = 0;
bgbc.gridy++;
bottomPanel.add(new JLabel("Target read count"), bgbc);
bgbc.gridx = 1;
targetReadCountField = new JTextField("10000", 5);
targetReadCountField.addKeyListener(this);
bottomPanel.add(targetReadCountField, bgbc);
optionPanel.add(bottomPanel, gbc);
bgbc.gridx = 0;
bgbc.gridy++;
bottomPanel.add(new JLabel("Max Probe Size (bp) "), bgbc);
bgbc.gridx = 1;
maxSizeField = new JTextField("0", 5);
maxSizeField.addKeyListener(this);
bottomPanel.add(maxSizeField, bgbc);
optionPanel.add(bottomPanel, gbc);
return optionPanel;
}
Aggregations