use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class LogTransformQuantitation 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]);
try {
for (int p = 0; p < allProbes.length; p++) {
// See if we need to quit
if (cancel) {
progressCancelled();
return;
}
for (int d = 0; d < data.length; d++) {
data[d].setValueForProbe(allProbes[p], (float) (Math.log(Math.max(data[d].getValueForProbe(allProbes[p]), threshold)) / Math.log(logBase)));
}
}
} catch (SeqMonkException e) {
progressExceptionReceived(e);
}
}
quantitatonComplete();
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class MatchDistributionsQuantitation method getOptionsPanel.
/* (non-Javadoc)
* @see uk.ac.babraham.SeqMonk.Quantitation.Quantitation#getOptionsPanel(uk.ac.babraham.SeqMonk.SeqMonkApplication)
*/
public JPanel getOptionsPanel() {
if (optionsPanel == null) {
optionsPanel = new JPanel();
optionsPanel.setLayout(new BorderLayout());
optionsPanel.add(new JLabel("Data Stores to Normalise", JLabel.CENTER), BorderLayout.NORTH);
DataStore[] stores = application.dataCollection().getAllDataStores();
Vector<DataStore> usableStores = new Vector<DataStore>();
for (int i = 0; i < stores.length; i++) {
if (stores[i] instanceof ReplicateSet)
continue;
if (!stores[i].isQuantitated())
continue;
usableStores.add(stores[i]);
}
usedStoresList = new JList(usableStores.toArray(new DataStore[0]));
usedStoresList.getSelectionModel().addListSelectionListener(this);
usedStoresList.setCellRenderer(new TypeColourRenderer());
int[] selectedIndices = new int[usableStores.size()];
for (int i = 0; i < selectedIndices.length; i++) selectedIndices[i] = i;
usedStoresList.setSelectedIndices(selectedIndices);
optionsPanel.add(new JScrollPane(usedStoresList), BorderLayout.CENTER);
}
return optionsPanel;
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class SeqMonkMenu method actionPerformed.
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
String action = ae.getActionCommand();
if (action.equals("exit")) {
application.dispose();
} else if (action.equals("new")) {
application.startNewProject();
} else if (action.equals("import_other")) {
JOptionPane.showMessageDialog(application, "SeqMonk can be extended to support other file formats.\n\nIf you'd like support for the format you use then please contact the program authors\nand provide them with example data files so they can write the appropriate import filters.", "Import other formats", JOptionPane.INFORMATION_MESSAGE);
} else if (action.equals("import_generic")) {
application.importData(new GenericSeqReadParser(application.dataCollection()));
} else if (action.equals("import_bed")) {
application.importData(new BedFileParser(application.dataCollection()));
} else if (action.equals("import_bedpe")) {
application.importData(new BedPEFileParser(application.dataCollection()));
} else if (action.equals("import_bowtie")) {
application.importData(new BowtieFileParser(application.dataCollection()));
} else if (action.equals("import_bismark_cov")) {
application.importData(new BismarkCovFileParser(application.dataCollection()));
} else if (action.equals("import_quasr")) {
application.importData(new QuasRFileParser(application.dataCollection()));
} else if (action.equals("import_methylkit")) {
application.importData(new MethylKitFileParser(application.dataCollection()));
} else if (action.equals("import_gff")) {
application.importData(new GffFileParser(application.dataCollection()));
} else if (action.equals("import_seqmonk")) {
application.importData(new SeqMonkReimportParser(application.dataCollection()));
} else if (action.equals("import_bam")) {
application.importData(new BAMFileParser(application.dataCollection()));
} else if (action.equals("import_visible_stores")) {
if (application.drawnDataStores() == null || application.drawnDataStores().length == 0) {
JOptionPane.showMessageDialog(application, "You need to have some data stores visible before you can use this option", "Can't reimport data", JOptionPane.ERROR_MESSAGE);
return;
}
application.importData(new VisibleStoresParser(application));
} else if (action.equals("import_active_probes")) {
if (application.dataCollection().probeSet() == null) {
JOptionPane.showMessageDialog(application, "You don't have any active probes to import at the moment", "Can't import data", JOptionPane.ERROR_MESSAGE);
return;
}
application.importData(new ActiveProbeListParser(application));
} else if (action.equals("import_hic")) {
DataStore[] drawnStores = application.drawnDataStores();
boolean foundHic = false;
for (int i = 0; i < drawnStores.length; i++) {
if (drawnStores[i] instanceof HiCDataStore && ((HiCDataStore) drawnStores[i]).isValidHiC()) {
foundHic = true;
}
}
if (!foundHic) {
JOptionPane.showMessageDialog(application, "You need to have at least one visible HiC data set to use this option", "Can't import HiC data", JOptionPane.ERROR_MESSAGE);
return;
}
application.importData(new HiCOtherEndExtractor(application.dataCollection(), application.drawnDataStores()));
} else if (action.equals("annot_gff")) {
AnnotationParserRunner.RunAnnotationParser(application, new GFF3AnnotationParser(application.dataCollection().genome()));
} else if (action.equals("annot_generic")) {
AnnotationParserRunner.RunAnnotationParser(application, new GenericAnnotationParser(application.dataCollection().genome()));
} else if (action.equals("annot_probe")) {
if (application.dataCollection().probeSet() == null) {
JOptionPane.showMessageDialog(application, "You haven't made a probeset yet (Do Data > Quantitation > Define Probes)", "Can't make new annotation", JOptionPane.ERROR_MESSAGE);
return;
}
String featureType = null;
while (true) {
featureType = (String) JOptionPane.showInputDialog(application, "Enter new feature type", "Set feature type", JOptionPane.QUESTION_MESSAGE, null, null, application.dataCollection().probeSet().getActiveList().name());
if (featureType == null)
// They cancelled
return;
if (featureType.length() == 0)
// Try again
continue;
break;
}
AnnotationParserRunner.RunAnnotationParser(application, new ProbeListAnnotationParser(application.dataCollection().genome(), application.dataCollection().probeSet().getActiveList(), featureType));
} else if (action.equals("about")) {
new AboutDialog();
} else if (action.equals("help_license")) {
try {
new LicenseDialog(application);
} catch (IOException e) {
e.printStackTrace();
}
} else if (action.equals("help_contents")) {
try {
// Java has a bug in it which affects the creation of valid URIs from
// URLs relating to an windows UNC path. We therefore have to mung
// URLs starting file file:// to add 5 forward slashes so that we
// end up with a valid URI.
URL url = ClassLoader.getSystemResource("Help");
if (url.toString().startsWith("file://")) {
try {
url = new URL(url.toString().replace("file://", "file://///"));
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
}
new HelpDialog(new File(url.toURI()));
} catch (URISyntaxException ux) {
System.err.println("Couldn't parse URL falling back to path");
new HelpDialog(new File(ClassLoader.getSystemResource("Help").getPath()));
}
} else if (action.equals("zoom_in")) {
application.chromosomeViewer().zoomIn();
} else if (action.equals("zoom_out")) {
application.chromosomeViewer().zoomOut();
} else if (action.equals("move_left")) {
application.chromosomeViewer().moveLeft();
} else if (action.equals("move_right")) {
application.chromosomeViewer().moveRight();
} else if (action.equals("page_left")) {
application.chromosomeViewer().pageLeft();
} else if (action.equals("page_right")) {
application.chromosomeViewer().pageRight();
} else if (action.equals("view_display_options")) {
new DisplayPreferencesEditorDialog();
} else if (action.equals("data_reads_probes")) {
DisplayPreferences.getInstance().setDisplayMode(DisplayPreferences.DISPLAY_MODE_READS_AND_QUANTITATION);
} else if (action.equals("data_reads")) {
DisplayPreferences.getInstance().setDisplayMode(DisplayPreferences.DISPLAY_MODE_READS_ONLY);
} else if (action.equals("data_probes")) {
DisplayPreferences.getInstance().setDisplayMode(DisplayPreferences.DISPLAY_MODE_QUANTITATION_ONLY);
} else if (action.equals("read_density_low")) {
DisplayPreferences.getInstance().setReadDensity(DisplayPreferences.READ_DENSITY_LOW);
} else if (action.equals("read_density_medium")) {
DisplayPreferences.getInstance().setReadDensity(DisplayPreferences.READ_DENSITY_MEDIUM);
} else if (action.equals("read_density_high")) {
DisplayPreferences.getInstance().setReadDensity(DisplayPreferences.READ_DENSITY_HIGH);
} else if (action.equals("read_pack_combine")) {
DisplayPreferences.getInstance().setReadDisplay(DisplayPreferences.READ_DISPLAY_COMBINED);
} else if (action.equals("read_pack_separate")) {
DisplayPreferences.getInstance().setReadDisplay(DisplayPreferences.READ_DISPLAY_SEPARATED);
} else if (action.equals("data_colour_dynamic")) {
DisplayPreferences.getInstance().setColourType(DisplayPreferences.COLOUR_TYPE_GRADIENT);
} else if (action.equals("data_colour_fixed")) {
DisplayPreferences.getInstance().setColourType(DisplayPreferences.COLOUR_TYPE_INDEXED);
} else if (action.equals("scale_positive")) {
DisplayPreferences.getInstance().setScaleType(DisplayPreferences.SCALE_TYPE_POSITIVE);
} else if (action.equals("scale_negative")) {
DisplayPreferences.getInstance().setScaleType(DisplayPreferences.SCALE_TYPE_POSITIVE_AND_NEGATIVE);
} else if (action.equals("view_annotation_tracks")) {
new AnnotationTrackSelector(application);
} else if (action.equals("view_data_tracks")) {
new DataTrackSelector(application);
} else if (action.equals("view_boxwhisker")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new MultiBoxWhiskerDialog(application.drawnDataSets(), new ProbeList[] { application.dataCollection().probeSet().getActiveList() });
}
} else if (action.equals("view_starwars")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new MultiStarWarsDialog(application.drawnDataSets(), new ProbeList[] { application.dataCollection().probeSet().getActiveList() });
}
} else if (action.equals("view_beanplot")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new MultiBeanPlotDialog(application.drawnDataSets(), new ProbeList[] { application.dataCollection().probeSet().getActiveList() });
}
} else if (action.equals("view_cumdist")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
try {
new CumulativeDistributionDialog(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
} catch (SeqMonkException e) {
throw new IllegalStateException(e);
}
}
} else if (action.equals("view_qqdist")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
try {
new QQDistributionDialog(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
} catch (SeqMonkException e) {
throw new IllegalStateException(e);
}
}
} else if (action.equals("plot_rna_qc")) {
new RNAQCPreferencesDialog(application.dataCollection(), application.drawnDataSets());
} else if (action.equals("plot_small_rna_qc")) {
new SmallRNAQCPreferencesDialog(application.dataCollection());
} else if (action.startsWith("toolbar_")) {
// We're toggling the visibility of one of the toolbars;
int index = Integer.parseInt(action.replaceAll("toolbar_", ""));
toolbars[index].setShown(!toolbars[index].shown());
updateVisibleToolBars();
} else if (action.startsWith("multiprobe")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
return;
}
ProbeList[] probeLists = ProbeListSelectorDialog.selectProbeLists();
if (probeLists == null || probeLists.length == 0)
return;
else if (action.equals("multiprobe_view_boxwhisker")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store from the data panel to use this view", "No active data store", JOptionPane.INFORMATION_MESSAGE);
return;
}
new MultiBoxWhiskerDialog(new DataStore[] { application.dataCollection().getActiveDataStore() }, probeLists);
} else if (action.equals("multiprobe_view_beanplot")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store from the data panel to use this view", "No active data store", JOptionPane.INFORMATION_MESSAGE);
return;
}
new MultiBeanPlotDialog(new DataStore[] { application.dataCollection().getActiveDataStore() }, probeLists);
} else if (action.equals("multiprobe_view_starwars")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store from the data panel to use this view", "No active data store", JOptionPane.INFORMATION_MESSAGE);
return;
}
new MultiStarWarsDialog(new DataStore[] { application.dataCollection().getActiveDataStore() }, probeLists);
} else if (action.equals("multiprobe_view_multistore_boxwhisker")) {
new MultiBoxWhiskerDialog(application.drawnDataSets(), probeLists);
} else if (action.equals("multiprobe_view_multistore_beanplot")) {
new MultiBeanPlotDialog(application.drawnDataSets(), probeLists);
} else if (action.equals("multiprobe_view_multistore_starwars")) {
new MultiStarWarsDialog(application.drawnDataSets(), probeLists);
} else if (action.equals("multiprobe_view_probetrend")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new TrendOverProbePreferencesDialog(probeLists, application.drawnDataSets());
}
} else if (action.equals("multiprobe_view_cumdist")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store from the data panel to use this view", "No active data store", JOptionPane.INFORMATION_MESSAGE);
return;
}
try {
new CumulativeDistributionDialog(application.dataCollection().getActiveDataStore(), probeLists);
} catch (SeqMonkException e) {
throw new IllegalStateException(e);
}
} else if (action.equals("multiprobe_view_qqdist")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store from the data panel to use this view", "No active data store", JOptionPane.INFORMATION_MESSAGE);
return;
}
try {
new QQDistributionDialog(application.dataCollection().getActiveDataStore(), probeLists);
} catch (SeqMonkException e) {
throw new IllegalStateException(e);
}
} else if (action.equals("multiprobe_view_line_graph")) {
try {
new LineGraphDialog(application.drawnDataSets(), probeLists);
} catch (SeqMonkException sme) {
JOptionPane.showMessageDialog(application, sme.getLocalizedMessage(), "Can't draw graph", JOptionPane.ERROR_MESSAGE);
}
} else if (action.equals("multiprobe_view_heatmap_active")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select an active data store to view this plot", "No data selected...", JOptionPane.INFORMATION_MESSAGE);
} else if (!(application.dataCollection().getActiveDataStore() instanceof HiCDataStore && ((HiCDataStore) application.dataCollection().getActiveDataStore()).isValidHiC())) {
JOptionPane.showMessageDialog(application, "Your active data store needs to be a HiC dataset to view this plot", "Wrong data selected...", JOptionPane.INFORMATION_MESSAGE);
} else {
new HeatmapProbeListWindow((HiCDataStore) application.dataCollection().getActiveDataStore(), probeLists, application.dataCollection().genome());
}
} else if (action.equals("multiprobe_plot_list_overlap")) {
new ListOverlapsDialog(probeLists);
} else if (action.equals("multiprobe_list_giraph_plot")) {
if (probeLists.length > 50) {
JOptionPane.showMessageDialog(application, "Please select fewer than 50 probe lists to display", "Too many probe lists...", JOptionPane.INFORMATION_MESSAGE);
} else {
new GiraphPlot(probeLists);
}
}
} else if (action.equals("view_value_histogram")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store in the Data panel before viewing this plot", "No data selected...", JOptionPane.INFORMATION_MESSAGE);
} else {
if (!application.dataCollection().getActiveDataStore().isQuantitated()) {
JOptionPane.showMessageDialog(application, "Your active data store hasn't been quantitated yet", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
try {
new ProbeValueHistogramPlot(application.dataCollection().getActiveDataStore(), application.dataCollection().probeSet().getActiveList());
} catch (SeqMonkException e) {
throw new IllegalStateException(e);
}
}
}
} else if (action.equals("plot_duplication")) {
if (application.dataCollection().probeSet() == null) {
JOptionPane.showMessageDialog(application, "You need to make some probes before running this plot", "No probes...", JOptionPane.INFORMATION_MESSAGE);
} else {
new DuplicationPlotDialog(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
}
} else if (action.equals("view_read_length_histogram")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store in the Data panel before viewing this plot", "No data selected...", JOptionPane.INFORMATION_MESSAGE);
} else {
new ReadLengthHistogramPlot(application.dataCollection().getActiveDataStore());
}
} else if (action.startsWith("view_hic_length_")) {
if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select a data store in the Data panel before viewing this plot", "No data selected...", JOptionPane.INFORMATION_MESSAGE);
} else if (!(application.dataCollection().getActiveDataStore() instanceof HiCDataStore && ((HiCDataStore) application.dataCollection().getActiveDataStore()).isValidHiC())) {
JOptionPane.showMessageDialog(application, "This plot can only be used on HiC data stores", "Not HiC data...", JOptionPane.INFORMATION_MESSAGE);
} else {
if (action.equals("view_hic_length_histogram")) {
new HiCLengthHistogramPlot((HiCDataStore) application.dataCollection().getActiveDataStore(), null);
} else if (action.equals("view_hic_length_probes")) {
if (application.dataCollection().probeSet() != null) {
new HiCLengthHistogramPlot((HiCDataStore) application.dataCollection().getActiveDataStore(), application.dataCollection().probeSet().getActiveList());
} else {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data before selecting this option", "No data selected...", JOptionPane.INFORMATION_MESSAGE);
}
}
}
} else if (action.equals("cis_trans_scatterplot")) {
// Check to see if we have any HiC datasets
DataStore[] stores = application.dataCollection().getAllDataStores();
boolean foundHiC = false;
for (int s = 0; s < stores.length; s++) {
if (stores[s] instanceof HiCDataStore && ((HiCDataStore) stores[s]).isValidHiC()) {
foundHiC = true;
break;
}
}
if (!foundHiC) {
JOptionPane.showMessageDialog(application, "You don't appear to have any HiC data to plot", "No data available...", JOptionPane.INFORMATION_MESSAGE);
return;
}
new CisTransScatterPlotDialog(application.dataCollection());
} else if (action.equals("view_probe_length_histogram")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new ProbeLengthHistogramPlot(application.dataCollection().probeSet().getActiveList());
}
} else if (action.equals("view_probetrend")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new TrendOverProbePreferencesDialog(new ProbeList[] { application.dataCollection().probeSet().getActiveList() }, application.drawnDataSets());
}
} else if (action.equals("view_quanttrend")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new QuantiationTrendPlotPreferencesDialog(application.dataCollection(), application.dataCollection().probeSet().getActiveList(), application.drawnDataSets());
}
} else // }
if (action.equals("view_aligned_probes")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new AlignedSummaryPreferencesDialog(new ProbeList[] { application.dataCollection().probeSet().getActiveList() }, application.drawnDataSets());
}
} else if (action.equals("view_aligned_probes_multi")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
ProbeList[] probeLists = ProbeListSelectorDialog.selectProbeLists();
if (probeLists == null || probeLists.length == 0)
return;
new AlignedSummaryPreferencesDialog(probeLists, application.drawnDataSets());
}
} else if (action.equals("view_heatmap_active")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else if (application.dataCollection().getActiveDataStore() == null) {
JOptionPane.showMessageDialog(application, "You need to select an active data store to view this plot", "No data selected...", JOptionPane.INFORMATION_MESSAGE);
} else if (!(application.dataCollection().getActiveDataStore() instanceof HiCDataStore && ((HiCDataStore) application.dataCollection().getActiveDataStore()).isValidHiC())) {
JOptionPane.showMessageDialog(application, "Your active data store needs to be a HiC dataset to view this plot", "Wrong data selected...", JOptionPane.INFORMATION_MESSAGE);
} else {
new HeatmapGenomeWindow((HiCDataStore) application.dataCollection().getActiveDataStore(), application.dataCollection().probeSet().getActiveList(), application.dataCollection().genome());
}
} else if (action.equals("plot_domainogram")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new DomainogramPreferencesDialog(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
}
} else if (action.equals("view_variance_plot")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else if (application.dataCollection().getAllReplicateSets().length == 0) {
JOptionPane.showMessageDialog(application, "This plot only works on Replicate Sets and you don't have any", "No replicate sets...", JOptionPane.INFORMATION_MESSAGE);
} else {
new VariancePlotDialog(application.dataCollection());
}
} else if (action.equals("view_strand_bias_plot")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new StrandBiasPlotDialog(application.dataCollection());
}
} else if (action.equals("view_scatterplot")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new ScatterPlotDialog(application.dataCollection());
}
} else if (action.equals("view_ma_plot")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new MAPlotDialog(application.dataCollection());
}
} else if (action.equals("view_line_graph")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
try {
new LineGraphDialog(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
} catch (SeqMonkException sme) {
JOptionPane.showMessageDialog(application, sme.getLocalizedMessage(), "Can't draw graph", JOptionPane.ERROR_MESSAGE);
}
}
} else if (action.equals("view_datastore_tree")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new DataStoreTreeDialog(application.dataCollection().probeSet().getActiveList(), application.drawnDataSets());
}
} else if (action.equals("view_pca")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new PCADataCalculator(application.dataCollection().probeSet().getActiveList(), application.drawnDataSets());
}
} else if (action.equals("view_tsne")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new TsneOptionsDialog(application.dataCollection().probeSet().getActiveList(), application.drawnDataSets());
}
} else if (action.equals("view_correlation_matrix")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
new CorrelationMatrix(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
}
} else if (action.startsWith("view_hierarchical_cluster")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data to view this plot", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
} else {
boolean normalise = false;
if (action.endsWith("normalised")) {
normalise = true;
}
new HierarchicalClusterDialog(application.dataCollection().probeSet().getActiveList(), application.drawnDataSets(), normalise);
}
} else if (action.equals("view_all_labels")) {
application.chromosomeViewer().toggleLabels();
} else if (action.equals("view_set_zoom")) {
new DataZoomSelector(application);
} else if (action.equals("define_probes")) {
new DefineProbeOptions(application);
} else if (action.equals("quantitation")) {
if (application.dataCollection().probeSet() == null) {
JOptionPane.showMessageDialog(application, "You need to define some probes before quantitating", "No probes...", JOptionPane.INFORMATION_MESSAGE);
new DefineProbeOptions(application);
} else {
new DefineQuantitationOptions(application);
}
} else if (action.equals("pipeline_quantitation")) {
new DefinePipelineOptions(application);
} else if (action.equals("edit_groups")) {
new GroupEditor(application);
} else if (action.equals("edit_replicates")) {
new ReplicateSetEditor(application);
} else if (action.equals("auto_create_groups")) {
new AutoSplitDataDialog(application);
} else if (action.equals("edit_samples")) {
new DataSetEditor(application.dataCollection());
} else if (action.equals("save")) {
application.saveProject();
} else if (action.equals("save_as")) {
application.saveProjectAs();
} else if (action.equals("file_export_chromosome_view")) {
// We don't want the scroll bars to appear in the drawn image
// so we temporarily remove them.
// application.chromosomeViewer().scrollPane().setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// application.chromosomeViewer().scrollPane().validate();
ImageSaver.saveImage(application.chromosomeViewer());
// application.chromosomeViewer().scrollPane().setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// application.chromosomeViewer().scrollPane().validate();
} else if (action.equals("file_export_genome_view")) {
ImageSaver.saveImage(application.genomeViewer());
} else if (action.equals("file_export_bedgraph")) {
if (!application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You need to have quantitated your data", "No quantitation...", JOptionPane.INFORMATION_MESSAGE);
return;
}
BedGraphDataWriter bgw = new BedGraphDataWriter(application.drawnDataSets(), application.dataCollection().probeSet().getActiveList());
bgw.startProcessing();
} else if (action.equals("open")) {
application.loadProject();
} else if (action.equals("open_switch")) {
application.loadProjectAndSwitchAssembly();
} else if (action.startsWith("filter")) {
try {
if (action.startsWith("filter_r_")) {
try {
RVersionTest.testRVersion(SeqMonkPreferences.getInstance().RLocation());
} catch (IOException ioe) {
JOptionPane.showMessageDialog(application, "<html>Can't find R at '" + SeqMonkPreferences.getInstance().RLocation() + "'<br><br>Please set the path to R under Edit > Preferences > Programs", "Can't find R", JOptionPane.ERROR_MESSAGE);
return;
}
if (action.equals("filter_r_deseq2")) {
new FilterOptionsDialog(application.dataCollection(), new DESeqFilter(application.dataCollection()));
} else if (action.equals("filter_r_limma")) {
new FilterOptionsDialog(application.dataCollection(), new LimmaFilter(application.dataCollection()));
} else if (action.equals("filter_r_edger")) {
new FilterOptionsDialog(application.dataCollection(), new EdgeRFilter(application.dataCollection()));
} else if (action.equals("filter_r_edger_forrev")) {
new FilterOptionsDialog(application.dataCollection(), new EdgeRForRevFilter(application.dataCollection()));
} else if (action.equals("filter_r_logistic_regression")) {
new FilterOptionsDialog(application.dataCollection(), new LogisticRegressionFilter(application.dataCollection()));
} else if (action.equals("filter_r_logistic_regression_splicing")) {
new FilterOptionsDialog(application.dataCollection(), new LogisticRegressionSplicingFilter(application.dataCollection()));
} else {
throw new IllegalArgumentException("Didn't understand command '" + action + "'");
}
} else if (action.equals("filter_values_individual")) {
new FilterOptionsDialog(application.dataCollection(), new ValuesFilter(application.dataCollection()));
} else if (action.equals("filter_values_windowed")) {
new FilterOptionsDialog(application.dataCollection(), new WindowedValuesFilter(application.dataCollection()));
} else if (action.equals("filter_values_distribution")) {
new FilterOptionsDialog(application.dataCollection(), new DistributionPositionFilter(application.dataCollection()));
} else if (action.equals("filter_diffs_individual")) {
new FilterOptionsDialog(application.dataCollection(), new DifferencesFilter(application.dataCollection()));
} else if (action.equals("filter_diffs_windowed")) {
new FilterOptionsDialog(application.dataCollection(), new WindowedDifferencesFilter(application.dataCollection()));
} else if (action.equals("filter_var_individual")) {
new FilterOptionsDialog(application.dataCollection(), new VarianceValuesFilter(application.dataCollection()));
} else if (action.equals("filter_intensity_stats")) {
new FilterOptionsDialog(application.dataCollection(), new IntensityDifferenceFilter(application.dataCollection()));
} else if (action.equals("filter_intensity_var_stats")) {
new FilterOptionsDialog(application.dataCollection(), new VarianceIntensityDifferenceFilter(application.dataCollection()));
} else if (action.equals("filter_proportion_library")) {
new FilterOptionsDialog(application.dataCollection(), new ProportionOfLibraryStatisticsFilter(application.dataCollection()));
} else if (action.equals("filter_intensity_replicate_stats")) {
new FilterOptionsDialog(application.dataCollection(), new IntensityReplicateFilter(application.dataCollection()));
} else if (action.equals("filter_statsr")) {
new FilterOptionsDialog(application.dataCollection(), new WindowedReplicateStatsFilter(application.dataCollection()));
} else if (action.equals("filter_stats")) {
new FilterOptionsDialog(application.dataCollection(), new ReplicateSetStatsFilter(application.dataCollection()));
} else if (action.equals("filter_monte_carlo")) {
new FilterOptionsDialog(application.dataCollection(), new MonteCarloFilter(application.dataCollection()));
} else // Laura
if (action.equals("filter_genesets")) {
new FilterOptionsDialog(application.dataCollection(), new GeneSetIntensityDifferenceFilter(application.dataCollection()));
} else if (action.equals("filter_boxwhisker")) {
BoxWhiskerFilter filter = new BoxWhiskerFilter(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_chisquare_stores")) {
ChiSquareFilter filter = new ChiSquareFilter(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_chisquare_forrev")) {
ChiSquareFilterForRev filter = new ChiSquareFilterForRev(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_chisquare_frontback")) {
ChiSquareFilterFrontBack filter = new ChiSquareFilterFrontBack(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_binomial_forrev")) {
BinomialFilterForRev filter = new BinomialFilterForRev(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_correlation_cluster")) {
CorrelationClusterFilter filter = new CorrelationClusterFilter(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_correlation_probes")) {
CorrelationFilter filter = new CorrelationFilter(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_correlation_manual")) {
ManualCorrelationFilter filter = new ManualCorrelationFilter(application.dataCollection());
new FilterOptionsDialog(application.dataCollection(), filter);
} else if (action.equals("filter_position")) {
new FilterOptionsDialog(application.dataCollection(), new PositionFilter(application.dataCollection(), DisplayPreferences.getInstance().getCurrentChromosome(), SequenceRead.start(DisplayPreferences.getInstance().getCurrentLocation()), SequenceRead.end(DisplayPreferences.getInstance().getCurrentLocation())));
} else // }
if (action.equals("filter_length")) {
new FilterOptionsDialog(application.dataCollection(), new ProbeLengthFilter(application.dataCollection()));
} else if (action.equals("filter_features")) {
new FilterOptionsDialog(application.dataCollection(), new FeatureFilter(application.dataCollection()));
} else if (action.equals("filter_feature_names")) {
new FilterOptionsDialog(application.dataCollection(), new FeatureNameFilter(application.dataCollection()));
} else if (action.equals("filter_probe_names")) {
new FilterOptionsDialog(application.dataCollection(), new ProbeNameFilter(application.dataCollection()));
} else if (action.equals("filter_deduplication")) {
new FilterOptionsDialog(application.dataCollection(), new DeduplicationFilter(application.dataCollection()));
} else if (action.equals("filter_random")) {
new FilterOptionsDialog(application.dataCollection(), new RandomFilter(application.dataCollection()));
} else if (action.equals("filter_combine")) {
new FilterOptionsDialog(application.dataCollection(), new CombineFilter(application.dataCollection()));
} else if (action.equals("filter_collate")) {
new FilterOptionsDialog(application.dataCollection(), new CollateListsFilter(application.dataCollection()));
}
} catch (SeqMonkException e) {
JOptionPane.showMessageDialog(application, e.getMessage(), "Can't run filter", JOptionPane.ERROR_MESSAGE);
}
} else if (action.startsWith("report")) {
if (action != "report_summary" && !application.dataCollection().isQuantitated()) {
JOptionPane.showMessageDialog(application, "You must quantiate your data before creating reports", "Can't generate report", JOptionPane.ERROR_MESSAGE);
return;
}
if (action.equals("report_annotated")) {
new ReportOptions(application, new AnnotatedListReport(application.dataCollection(), application.drawnDataSets()));
} else if (action.equals("report_description")) {
new ProbeListReportCreator(application.dataCollection().probeSet().getActiveList());
} else if (action.equals("report_group")) {
new ReportOptions(application, new ProbeGroupReport(application.dataCollection(), application.drawnDataSets()));
} else if (action.equals("report_feature")) {
new ReportOptions(application, new FeatureReport(application.dataCollection(), application.drawnDataSets()));
} else if (action.equals("report_summary")) {
new ReportOptions(application, new DataStoreSummaryReport(application.dataCollection(), application.drawnDataSets()));
} else if (action.equals("report_chromosome")) {
new ReportOptions(application, new ChromosomeViewReport(application.dataCollection(), application.drawnDataSets()));
}
} else if (action.equals("edit_preferences")) {
new EditPreferencesDialog(application.dataCollection());
} else if (action.equals("find_feature")) {
new FindFeatureDialog(application.dataCollection());
} else if (action.equals("find_feature_names")) {
new FindFeaturesByNameDialog(application.dataCollection());
} else if (action.equals("goto_position")) {
new GotoDialog(application);
} else if (action.equals("goto_window")) {
new GotoWindowDialog(application);
} else if (action.equals("copy_position")) {
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable t = new StringSelection("chr" + DisplayPreferences.getInstance().getCurrentChromosome().name() + ":" + SequenceRead.start(DisplayPreferences.getInstance().getCurrentLocation()) + "-" + SequenceRead.end(DisplayPreferences.getInstance().getCurrentLocation()));
c.setContents(t, null);
} else {
throw new IllegalStateException("Unknown command '" + action + "' from main menu");
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class LimmaFilter method generateProbeList.
/* (non-Javadoc)
* @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
*/
@Override
protected void generateProbeList() {
// We need to make a temporary directory, save the data into it, write out the R script
// and then run it an collect the list of results, then clean up.
// Make up the list of DataStores in each replicate set
DataStore[] fromStores = replicateSets[0].dataStores();
DataStore[] toStores = replicateSets[1].dataStores();
File tempDir;
try {
progressUpdated("Creating temp directory", 0, 1);
tempDir = TempDirectory.createTempDirectory();
// System.err.println("Temp dir is "+tempDir.getAbsolutePath());
progressUpdated("Writing R script", 0, 1);
// Get the template script
Template template = new Template(ClassLoader.getSystemResource("uk/ac/babraham/SeqMonk/Filters/LimmaFilter/limma_template.r"));
// Substitute in the variables we need to change
template.setValue("WORKING", tempDir.getAbsolutePath().replace("\\", "/"));
// Say which p value column we're filtering on
if (multiTest) {
template.setValue("CORRECTED", "adj.P.Val");
} else {
template.setValue("CORRECTED", "P.Value");
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < fromStores.length; i++) {
if (i > 0)
sb.append(",");
sb.append("\"from\"");
}
for (int i = 0; i < toStores.length; i++) {
sb.append(",");
sb.append("\"to\"");
}
template.setValue("CONDITIONS", sb.toString());
template.setValue("PVALUE", "" + cutoff);
// Write the script file
File scriptFile = new File(tempDir.getAbsoluteFile() + "/script.r");
PrintWriter pr = new PrintWriter(scriptFile);
pr.print(template.toString());
pr.close();
// Write the count data
File countFile = new File(tempDir.getAbsoluteFile() + "/counts.txt");
pr = new PrintWriter(countFile);
sb = new StringBuffer();
sb.append("probe");
for (int i = 0; i < fromStores.length; i++) {
sb.append("\t");
sb.append("from");
sb.append(i);
}
for (int i = 0; i < toStores.length; i++) {
sb.append("\t");
sb.append("to");
sb.append(i);
}
pr.println(sb.toString());
progressUpdated("Writing count data", 0, 1);
Probe[] probes = startingList.getAllProbes();
float value;
for (int p = 0; p < probes.length; p++) {
if (p % 1000 == 0) {
progressUpdated("Writing count data", p, probes.length);
}
sb = new StringBuffer();
sb.append(p);
for (int i = 0; i < fromStores.length; i++) {
sb.append("\t");
value = fromStores[i].getValueForProbe(probes[p]);
sb.append(value);
}
for (int i = 0; i < toStores.length; i++) {
sb.append("\t");
value = toStores[i].getValueForProbe(probes[p]);
sb.append(value);
}
pr.println(sb.toString());
}
pr.close();
progressUpdated("Running R Script", 0, 1);
RScriptRunner runner = new RScriptRunner(tempDir);
RProgressListener listener = new RProgressListener(runner);
runner.addProgressListener(new ProgressRecordDialog("R Session", runner));
runner.runScript();
while (true) {
if (listener.cancelled()) {
progressCancelled();
return;
}
if (listener.exceptionReceived()) {
progressExceptionReceived(listener.exception());
return;
}
if (listener.complete())
break;
Thread.sleep(500);
}
// We can now parse the results and put the hits into a new probe list
ProbeList newList;
newList = new ProbeList(startingList, "", "", "FDR");
File hitsFile = new File(tempDir.getAbsolutePath() + "/hits.txt");
BufferedReader br = new BufferedReader(new FileReader(hitsFile));
String line = br.readLine();
while ((line = br.readLine()) != null) {
String[] sections = line.split("\t");
int probeIndex = Integer.parseInt(sections[0]);
float pValue;
if (multiTest) {
pValue = Float.parseFloat(sections[sections.length - 2]);
} else {
pValue = Float.parseFloat(sections[sections.length - 3]);
}
newList.addProbe(probes[probeIndex], pValue);
}
br.close();
runner.cleanUp();
// TODO: Show log of R session?
filterFinished(newList);
} catch (Exception ioe) {
progressExceptionReceived(ioe);
return;
}
// filterFinished(newList);
}
use of uk.ac.babraham.SeqMonk.DataTypes.DataStore in project SeqMonk by s-andrews.
the class LogisticRegressionFilter method generateProbeList.
/* (non-Javadoc)
* @see uk.ac.babraham.SeqMonk.Filters.ProbeFilter#generateProbeList()
*/
@Override
protected void generateProbeList() {
// We need to make a temporary directory, save the data into it, write out the R script
// and then run it an collect the list of results, then clean up.
// Make up the list of DataStores in each replicate set
DataStore[] fromStores = replicateSets[0].dataStores();
DataStore[] toStores = replicateSets[1].dataStores();
if (minObservations < 3)
minObservations = 3;
File tempDir;
try {
Probe[] probes = startingList.getAllProbes();
if (resample) {
// We need to check that the data stores are quantitated
for (int i = 0; i < fromStores.length; i++) {
if (!fromStores[i].isQuantitated()) {
progressExceptionReceived(new SeqMonkException("Data Store " + fromStores[i].name() + " wasn't quantitated"));
return;
}
for (int p = 0; p < probes.length; p++) {
float value = fromStores[i].getValueForProbe(probes[p]);
if ((!Float.isNaN(value)) && (value < 0 || value > 100)) {
progressExceptionReceived(new SeqMonkException("Data Store " + fromStores[i].name() + " had a value outside the range 0-100 (" + value + ")"));
return;
}
}
}
for (int i = 0; i < toStores.length; i++) {
if (!toStores[i].isQuantitated()) {
progressExceptionReceived(new SeqMonkException("Data Store " + toStores[i].name() + " wasn't quantitated"));
return;
}
for (int p = 0; p < probes.length; p++) {
float value = toStores[i].getValueForProbe(probes[p]);
if ((!Float.isNaN(value)) && (value < 0 || value > 100)) {
progressExceptionReceived(new SeqMonkException("Data Store " + toStores[i].name() + " had a value outside the range 0-100 (" + value + ")"));
return;
}
}
}
}
progressUpdated("Creating temp directory", 0, 1);
tempDir = TempDirectory.createTempDirectory();
System.err.println("Temp dir is " + tempDir.getAbsolutePath());
progressUpdated("Writing R script", 0, 1);
// Get the template script
Template template = new Template(ClassLoader.getSystemResource("uk/ac/babraham/SeqMonk/Filters/LogisticRegressionFilter/logistic_regression_template.r"));
// Write the count data
// Sort these so we can get probes from the same chromosome together
Arrays.sort(probes);
PrintWriter pr = null;
String lastChr = "";
// Rather than not testing probes based on their absolute difference
// we should just post-filter them. The easiest way to do this will
// be to not test (as we do now) but explicity pass in the number of
// tests we should have performed to the multiple testing correction.
int numberOfTestsToCorrectBy = 0;
PROBE: for (int p = 0; p < probes.length; p++) {
if (!probes[p].chromosome().name().equals(lastChr)) {
if (pr != null)
pr.close();
File outFile = new File(tempDir.getAbsoluteFile() + "/data_chr" + probes[p].chromosome().name() + ".txt");
pr = new PrintWriter(outFile);
lastChr = probes[p].chromosome().name();
pr.println("id\tgroup\treplicate\tstate\tcount");
}
if (p % 1000 == 0) {
progressUpdated("Writing data for chr" + lastChr, p, probes.length);
}
int[] fromMethCounts = new int[fromStores.length];
int[] fromUnmethCounts = new int[fromStores.length];
int[] toMethCounts = new int[toStores.length];
int[] toUnmethCounts = new int[toStores.length];
for (int i = 0; i < fromStores.length; i++) {
long[] reads = fromStores[i].getReadsForProbe(probes[p]);
int totalCount = 0;
int methCount = 0;
if (resample) {
float value = fromStores[i].getValueForProbe(probes[p]);
if (Float.isNaN(value)) {
continue PROBE;
}
totalCount = reads.length;
methCount = Math.round((totalCount * value) / 100f);
} else {
for (int r = 0; r < reads.length; r++) {
totalCount++;
if (SequenceRead.strand(reads[r]) == Location.FORWARD) {
++methCount;
}
}
}
fromMethCounts[i] = methCount;
fromUnmethCounts[i] = totalCount - methCount;
}
for (int i = 0; i < toStores.length; i++) {
long[] reads = toStores[i].getReadsForProbe(probes[p]);
int totalCount = 0;
int methCount = 0;
if (resample) {
float value = toStores[i].getValueForProbe(probes[p]);
if (Float.isNaN(value)) {
continue PROBE;
}
totalCount = reads.length;
methCount = Math.round((totalCount * value) / 100f);
} else {
for (int r = 0; r < reads.length; r++) {
totalCount++;
if (SequenceRead.strand(reads[r]) == Location.FORWARD) {
++methCount;
}
}
}
toMethCounts[i] = methCount;
toUnmethCounts[i] = totalCount - methCount;
}
// Check to see we meet the requirements for the min amount of information
// and the min diff.
int totalFromMeth = 0;
int totalFrom = 0;
int totalToMeth = 0;
int totalTo = 0;
int validFrom = 0;
for (int i = 0; i < fromStores.length; i++) {
totalFromMeth += fromMethCounts[i];
totalFrom += fromMethCounts[i];
totalFrom += fromUnmethCounts[i];
if (fromMethCounts[i] + fromUnmethCounts[i] >= minObservations) {
++validFrom;
}
}
int validTo = 0;
for (int i = 0; i < toStores.length; i++) {
totalToMeth += toMethCounts[i];
totalTo += toMethCounts[i];
totalTo += toUnmethCounts[i];
if (toMethCounts[i] + toUnmethCounts[i] >= minObservations) {
++validTo;
}
}
// have enough data in all stores to go ahead and do the test.
if (validFrom < fromStores.length || validTo < toStores.length) {
// We don't have enough data to measure this one
continue;
}
// At this point we have to count this probe as valid for the
// purposes of multiple testing correction
++numberOfTestsToCorrectBy;
float[] fromPercentages = new float[validFrom];
float[] toPercentages = new float[validTo];
int lastFromIndex = 0;
int lastToIndex = 0;
for (int i = 0; i < fromMethCounts.length; i++) {
if (fromMethCounts[i] + fromUnmethCounts[i] == 0)
continue;
fromPercentages[lastFromIndex] = fromMethCounts[i] * 100f / (fromMethCounts[i] + fromUnmethCounts[i]);
++lastFromIndex;
}
for (int i = 0; i < toMethCounts.length; i++) {
if (toMethCounts[i] + toUnmethCounts[i] == 0)
continue;
toPercentages[lastToIndex] = toMethCounts[i] * 100f / (toMethCounts[i] + toUnmethCounts[i]);
++lastToIndex;
}
for (int i = 0; i < fromMethCounts.length; i++) {
pr.println(p + "\tfrom\tfrom" + i + "\tmeth\t" + fromMethCounts[i]);
pr.println(p + "\tfrom\tfrom" + i + "\tunmeth\t" + fromUnmethCounts[i]);
}
for (int i = 0; i < toMethCounts.length; i++) {
pr.println(p + "\tto\tto" + i + "\tmeth\t" + toMethCounts[i]);
pr.println(p + "\tto\tto" + i + "\tunmeth\t" + toUnmethCounts[i]);
}
}
pr.close();
// Sanity check to make sure we have something to work with.
if (numberOfTestsToCorrectBy == 0) {
progressExceptionReceived(new IllegalStateException("No probes had enough data to test."));
}
// Now we can complete the template
// Substitute in the variables we need to change
template.setValue("WORKING", tempDir.getAbsolutePath().replace("\\", "/"));
template.setValue("CORRECTCOUNT", "" + numberOfTestsToCorrectBy);
template.setValue("PVALUE", "" + pValueCutoff);
if (multiTest) {
template.setValue("MULTITEST", "TRUE");
} else {
template.setValue("MULTITEST", "FALSE");
}
// Write the script file
File scriptFile = new File(tempDir.getAbsoluteFile() + "/script.r");
pr = new PrintWriter(scriptFile);
pr.print(template.toString());
pr.close();
progressUpdated("Running R Script", 0, 1);
RScriptRunner runner = new RScriptRunner(tempDir);
RProgressListener listener = new RProgressListener(runner);
runner.addProgressListener(new ProgressRecordDialog("R Session", runner));
runner.runScript();
while (true) {
if (listener.cancelled()) {
progressCancelled();
pr.close();
return;
}
if (listener.exceptionReceived()) {
progressExceptionReceived(new SeqMonkException("R Script failed"));
pr.close();
return;
}
if (listener.complete())
break;
Thread.sleep(500);
}
// We can now parse the results and put the hits into a new probe list
ProbeList newList;
if (multiTest) {
newList = new ProbeList(startingList, "", "", "FDR");
} else {
newList = new ProbeList(startingList, "", "", "p-value");
}
File hitsFile = new File(tempDir.getAbsolutePath() + "/hits.txt");
BufferedReader br = new BufferedReader(new FileReader(hitsFile));
String line = br.readLine();
while ((line = br.readLine()) != null) {
String[] sections = line.split("\t");
String[] indexSections = sections[0].split("\\.");
int probeIndex = Integer.parseInt(indexSections[indexSections.length - 1]);
float pValue = Float.parseFloat(sections[sections.length - 1]);
newList.addProbe(probes[probeIndex], pValue);
}
br.close();
runner.cleanUp();
filterFinished(newList);
} catch (Exception ioe) {
progressExceptionReceived(ioe);
return;
}
}
Aggregations