Skip to content

Commit

Permalink
Loading example data from the wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmodrak committed Jan 9, 2017
1 parent 66f66e2 commit b3d636f
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ID_REF 0 5 10 15 20 25 30 40 50 60 70 80 90 100
sigA 65.02848915 126.4129103 4272.900479 5841.001338 3827.004813 4214.074196 3655.872395 3023.491903 2252.013874 771.2207189 1624.747711 1463.289999 2063.674901 1638.318343
sigB 61.94860972 37.89669158 668.1369332 862.2724645 701.8407961 1585.805369 2365.615687 3475.488365 11206.12601 3856.295791 3227.049517 2245.778613 2055.110141 1884.544308
dnaA 141.1416529 599.6596128 14776.3262 10631.07598 9554.734037 4408.279551 3439.540195 4630.653203 2886.288907 6463.05252 6051.176708 5845.051415 3942.786839 4463.624652
glnR 102.1821935 982.2864582 4617.832088 5992.73972 5341.391812 6472.018427 6774.975434 2661.456 3676.201168 2281.868597 3877.739034 4261.069892 3850.953533 2900.327297
tnrA 39.89123822 77.17170097 412.7144097 335.2282683 522.7582084 452.8847029 289.6165025 470.4833963 213.4863472 400.3172573 441.7235684 374.0273609 398.1035704 320.6820963
bmrR 76.79816847 49.45347518 357.1781456 286.0255073 385.0761604 302.9634616 187.1433534 398.1035704 276.0909905 232.3249038 155.9565138 124.4998333 154.9866347 190.282622
ctsR 77.54705027 382.9467541 2772.554299 1288.074211 827.1470363 933.8195615 922.8804737 1986.481992 2904.350793 2065.105828 1555.32461 1150.463901 1326.124031 1375.747508
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cz.cas.mbu.cygenexpi.internal.tasks;

import java.io.File;
import java.io.InputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

import org.cytoscape.event.CyEventHelper;
import org.cytoscape.io.read.CySessionReader;
import org.cytoscape.io.read.CySessionReaderManager;
import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.session.CySession;
import org.cytoscape.session.CySessionManager;
import org.cytoscape.session.events.SessionAboutToBeLoadedEvent;
import org.cytoscape.session.events.SessionLoadCancelledEvent;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;

public class LoadExampleDataTask extends AbstractTask {
@Tunable(description="<html>Current session (all networks and tables) will be lost.<br />Do you want to continue?</html>",
params="ForceSetDirectly=true;ForceSetTitle=Open Session")
public boolean approve;

private final CyServiceRegistrar registrar;

public LoadExampleDataTask(CyServiceRegistrar registrar) {
super();
this.registrar = registrar;
}

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
if(approve)
{
CyEventHelper eventHelper = registrar.getService(CyEventHelper.class);
eventHelper.fireEvent(new SessionAboutToBeLoadedEvent(this));
try {
InputStream is = getClass().getResourceAsStream("/cz/cas/mbu/genexpi/example1_ds.cys");
File tempFile = File.createTempFile("cygenexpi_example", ".cys");
tempFile.deleteOnExit();
Files.copy(is, tempFile.toPath(),StandardCopyOption.REPLACE_EXISTING);

CySessionReader reader = registrar.getService(CySessionReaderManager.class).getReader(tempFile.toURI(), tempFile.getName());

if (reader == null)
{
throw new NullPointerException("Failed to find appropriate reader for example data.");
}
reader.run(taskMonitor);

final CySession newSession = reader.getSession();

if (newSession == null)
throw new NullPointerException("Example session could not be read.");

CySessionManager sessionMgr = registrar.getService(CySessionManager.class);
sessionMgr.setCurrentSession(newSession, "CyGenexpi example");

}
catch(Exception ex)
{
eventHelper.fireEvent(new SessionLoadCancelledEvent(this));
throw ex;
}
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void run(TaskMonitor taskMonitor) throws Exception {
data.selectedNetwork = registrar.getService(CyApplicationManager.class).getCurrentNetwork();

WizardPanel<GNWizardData> panel = new WizardPanel<>(registrar, InferenceWizard.getSteps(), InferenceWizard.TITLE, data);
data.wizardPanel = panel;
registrar.registerService(panel, CytoPanelComponent.class, new Properties());

UIUtils.ensurePanelVisible(registrar, panel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class GNWizardData {
@RememberValue(type=Type.NEVER)
public CyNetwork selectedNetwork;

@RememberValue(type=Type.NEVER)
public WizardPanel<GNWizardData> wizardPanel;

public String expressionMappingColumn = "";

@RememberValueRecursive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import cz.cas.mbu.cydataseries.TimeSeries;
import cz.cas.mbu.cygenexpi.PredictionService;
import cz.cas.mbu.cygenexpi.internal.tasks.CheckConfigurationTask;
import cz.cas.mbu.cygenexpi.internal.tasks.LoadExampleDataTask;

import com.jgoodies.forms.layout.FormSpecs;
import javax.swing.JLabel;
Expand Down Expand Up @@ -103,6 +104,12 @@ public SelectTimeSeriesStep() {
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,}));

JLabel lblDescription = new JLabel("<html>First we need a time series for the expression data. The time series needs to be mapped to nodes in the network.\r\n</html>");
Expand Down Expand Up @@ -154,6 +161,16 @@ public SelectTimeSeriesStep() {
btnSmoothTimeSeries = new JButton("Smooth a Time Series");
add(btnSmoothTimeSeries, "2, 28, 3, 1");
btnSmoothTimeSeries.addActionListener(evt -> smoothTimeSeries());

JSeparator separator_3 = new JSeparator();
add(separator_3, "2, 30, 3, 1");

JLabel lblAlternativelyYouCan = new JLabel("Alternatively you can load example data directly:");
add(lblAlternativelyYouCan, "2, 32, 3, 1");

JButton btnLoadExampleData = new JButton("Load example data");
add(btnLoadExampleData, "2, 34, 3, 1");
btnLoadExampleData.addActionListener(evt -> loadExampleData());

}

Expand Down Expand Up @@ -293,6 +310,27 @@ private void smoothTimeSeries()
registrar.getService(DialogTaskManager.class).execute(smoothTaskIterator);
}

private void loadExampleData()
{
registrar.getService(DialogTaskManager.class).execute(new TaskIterator(
new LoadExampleDataTask(registrar)
, new AbstractTask(){

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
SwingUtilities.invokeLater(() -> {
CyNetwork exampleNetwork = registrar.getService(CyNetworkManager.class).getNetworkSet().iterator().next();
data.selectedNetwork = exampleNetwork;
data.expressionMappingColumn = "Expression_smooth";
refreshUI();
data.wizardPanel.nextStep();
});
}

}
));

}


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ public void run(TaskMonitor taskMonitor) throws Exception {
}
}

protected void previousStep()
public void previousStep()
{
if(shownStepIndex > 0)
{
setShownStepIndex(shownStepIndex - 1, false);
}
}

protected void nextStep()
public void nextStep()
{
registrar.getService(RememberValueService.class).saveProperties(data);

Expand Down
Binary file not shown.

0 comments on commit b3d636f

Please sign in to comment.