use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class ClusteringTask method run.
@Override
public void run() {
status = TaskStatus.PROCESSING;
logger.info("Clustering");
double[][] rawData;
if (typeOfData == ClusteringDataType.VARIABLES) {
rawData = createMatrix(false);
dataset = createVariableWekaDataset(rawData);
} else {
rawData = createMatrix(true);
dataset = createSampleWekaDataset(rawData);
}
// Run the clustering algorithm
ClusteringAlgorithm clusteringAlgorithm = clusteringStep.getModule();
ParameterSet clusteringParameters = clusteringStep.getParameterSet();
ClusteringResult result = clusteringAlgorithm.performClustering(dataset, clusteringParameters);
String cluster = "";
if (clusteringAlgorithm.getName().toString().equals("Hierarchical clusterer")) {
progress = 0;
// Getting the result of the clustering in Newick format
cluster = result.getHiearchicalCluster();
// Getting the number of clusters counting the number of times the
// word "cluster" is in the result
Pattern p = Pattern.compile("Cluster", Pattern.LITERAL | Pattern.CASE_INSENSITIVE);
int numberOfClusters = p.split(cluster, -1).length - 1;
if (numberOfClusters == 0) {
numberOfClusters = 1;
}
// Visualization window for each cluster
for (int i = 0; i < numberOfClusters; i++) {
String c = null;
String clusterNumber = "Cluster " + i;
if (cluster.indexOf(clusterNumber) > 0) {
int nextNumber = i + 1;
String clusterNumber2 = "Cluster " + nextNumber;
if (cluster.indexOf(clusterNumber2) < 0) {
c = cluster.substring(cluster.indexOf(clusterNumber) + clusterNumber.length(), cluster.length());
} else {
c = cluster.substring(cluster.indexOf(clusterNumber) + clusterNumber.length(), cluster.indexOf(clusterNumber2));
}
} else {
c = cluster;
}
JFrame visualizationWindow = new JFrame(clusterNumber);
visualizationWindow.setSize(600, 500);
visualizationWindow.setLayout(new BorderLayout());
HierarchyVisualizer visualizer = new HierarchyVisualizer(c);
visualizationWindow.add(visualizer, BorderLayout.CENTER);
visualizer.fitToScreen();
// Text field with the clustering result in Newick format
JTextField data = new JTextField(c);
visualizationWindow.add(data, BorderLayout.SOUTH);
visualizationWindow.setVisible(true);
visualizationWindow.pack();
visualizationWindow.setVisible(true);
}
progress = 100;
} else {
List<Integer> clusteringResult = result.getClusters();
// Report window
Desktop desktop = MZmineCore.getDesktop();
if (typeOfData == ClusteringDataType.SAMPLES) {
String[] sampleNames = new String[selectedRawDataFiles.length];
for (int i = 0; i < selectedRawDataFiles.length; i++) {
sampleNames[i] = selectedRawDataFiles[i].getName();
}
ClusteringReportWindow reportWindow = new ClusteringReportWindow(sampleNames, clusteringResult.toArray(new Integer[0]), "Clustering Report");
reportWindow.setVisible(true);
} else {
String[] variableNames = new String[selectedRows.length];
for (int i = 0; i < selectedRows.length; i++) {
variableNames[i] = selectedRows[i].getID() + " - " + selectedRows[i].getAverageMZ() + " - " + selectedRows[i].getAverageRT();
if (selectedRows[i].getPeakIdentities() != null && selectedRows[i].getPeakIdentities().length > 0) {
variableNames[i] += " - " + selectedRows[i].getPeakIdentities()[0].getName();
}
}
ClusteringReportWindow reportWindow = new ClusteringReportWindow(variableNames, clusteringResult.toArray(new Integer[0]), "Clustering Report");
reportWindow.setVisible(true);
}
// Visualization
if (typeOfData == ClusteringDataType.VARIABLES) {
for (int ind = 0; ind < selectedRows.length; ind++) {
groupsForSelectedVariables[ind] = clusteringResult.get(ind);
}
} else {
for (int ind = 0; ind < selectedRawDataFiles.length; ind++) {
groupsForSelectedRawDataFiles[ind] = clusteringResult.get(ind);
}
}
this.finalNumberOfGroups = result.getNumberOfGroups();
parameterValuesForGroups = new Object[finalNumberOfGroups];
for (int i = 0; i < finalNumberOfGroups; i++) {
parameterValuesForGroups[i] = "Group " + i;
}
int numComponents = xAxisDimension;
if (yAxisDimension > numComponents) {
numComponents = yAxisDimension;
}
if (result.getVisualizationType() == VisualizationType.PCA) {
// Scale data and do PCA
Preprocess.scaleToUnityVariance(rawData);
PCA pcaProj = new PCA(rawData, numComponents);
projectionStatus = pcaProj.getProjectionStatus();
double[][] pcaResult = pcaProj.getState();
if (status == TaskStatus.CANCELED) {
return;
}
component1Coords = pcaResult[xAxisDimension - 1];
component2Coords = pcaResult[yAxisDimension - 1];
} else if (result.getVisualizationType() == VisualizationType.SAMMONS) {
// Scale data and do Sammon's mapping
Preprocess.scaleToUnityVariance(rawData);
Sammons sammonsProj = new Sammons(rawData);
projectionStatus = sammonsProj.getProjectionStatus();
sammonsProj.iterate(100);
double[][] sammonsResult = sammonsProj.getState();
if (status == TaskStatus.CANCELED) {
return;
}
component1Coords = sammonsResult[xAxisDimension - 1];
component2Coords = sammonsResult[yAxisDimension - 1];
}
ProjectionPlotWindow newFrame = new ProjectionPlotWindow(desktop.getSelectedPeakLists()[0], this, parameters);
newFrame.setVisible(true);
}
status = TaskStatus.FINISHED;
logger.info("Finished computing Clustering visualization.");
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class BatchQueue method clone.
@Override
public BatchQueue clone() {
// Clone the parameters.
final BatchQueue clonedQueue = new BatchQueue();
for (final MZmineProcessingStep<MZmineProcessingModule> step : this) {
final ParameterSet parameters = step.getParameterSet();
final MZmineProcessingStepImpl<MZmineProcessingModule> stepCopy = new MZmineProcessingStepImpl<MZmineProcessingModule>(step.getModule(), parameters.cloneParameterSet());
clonedQueue.add(stepCopy);
}
return clonedQueue;
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class BatchQueue method saveToXml.
/**
* Serialize to XML.
*
* @param xmlElement the XML element to append to.
*/
public void saveToXml(final Element xmlElement) {
final Document document = xmlElement.getOwnerDocument();
// Process each step.
for (final MZmineProcessingStep<?> step : this) {
// Append a new batch step element.
final Element stepElement = document.createElement(BATCH_STEP_ELEMENT);
stepElement.setAttribute(METHOD_ELEMENT, step.getModule().getClass().getName());
xmlElement.appendChild(stepElement);
// Save parameters.
final ParameterSet parameters = step.getParameterSet();
if (parameters != null) {
parameters.saveValuesToXML(stepElement);
}
}
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class BatchModeModule method runBatch.
public static ExitCode runBatch(@Nonnull MZmineProject project, File batchFile) {
logger.info("Running batch from file " + batchFile);
try {
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document parsedBatchXML = docBuilder.parse(batchFile);
BatchQueue newQueue = BatchQueue.loadFromXml(parsedBatchXML.getDocumentElement());
ParameterSet parameters = new BatchModeParameters();
parameters.getParameter(BatchModeParameters.batchQueue).setValue(newQueue);
Task batchTask = new BatchTask(project, parameters);
batchTask.run();
if (batchTask.getStatus() == TaskStatus.FINISHED)
return ExitCode.OK;
else
return ExitCode.ERROR;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Error while running batch", e);
e.printStackTrace();
return ExitCode.ERROR;
}
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class MZmineCore method main.
/**
* Main method
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
// In the beginning, set the default locale to English, to avoid
// problems with conversion of numbers etc. (e.g. decimal separator may
// be . or , depending on the locale)
Locale.setDefault(new Locale("en", "US"));
logger.info("Starting MZmine " + getMZmineVersion());
// Remove old temporary files, if we find any
TmpFileCleanup.removeOldTemporaryFiles();
logger.fine("Loading core classes..");
// create instance of configuration
configuration = new MZmineConfigurationImpl();
// create instances of core modules
projectManager = new ProjectManagerImpl();
taskController = new TaskControllerImpl();
logger.fine("Initializing core classes..");
projectManager.initModule();
taskController.initModule();
logger.fine("Loading modules");
for (Class<?> moduleClass : MZmineModulesList.MODULES) {
try {
logger.finest("Loading module " + moduleClass.getName());
// Create instance and init module
MZmineModule moduleInstance = (MZmineModule) moduleClass.newInstance();
// Add to the module list
initializedModules.put(moduleClass, moduleInstance);
// Create an instance of parameter set
Class<? extends ParameterSet> parameterSetClass = moduleInstance.getParameterSetClass();
ParameterSet parameterSetInstance = parameterSetClass.newInstance();
// Add the parameter set to the configuration
configuration.setModuleParameters((Class<MZmineModule>) moduleClass, parameterSetInstance);
} catch (Throwable e) {
logger.log(Level.SEVERE, "Could not load module " + moduleClass, e);
e.printStackTrace();
continue;
}
}
// If we have no arguments, run in GUI mode, otherwise run in batch mode
if (args.length == 0) {
// Create the Swing GUI in the event-dispatching thread, as is
// generally recommended
Runnable desktopInit = new Runnable() {
@Override
public void run() {
logger.fine("Initializing GUI");
MainWindow mainWindow = new MainWindow();
desktop = mainWindow;
mainWindow.initModule();
// Activate project - bind it to the desktop's project tree
MZmineProjectImpl currentProject = (MZmineProjectImpl) projectManager.getCurrentProject();
currentProject.activateProject();
// add desktop menu icon
for (Class<?> moduleClass : MZmineModulesList.MODULES) {
MZmineModule module = initializedModules.get(moduleClass);
if (module instanceof MZmineRunnableModule) {
mainWindow.getMainMenu().addMenuItemForModule((MZmineRunnableModule) module);
}
}
}
};
try {
SwingUtilities.invokeAndWait(desktopInit);
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not initialize GUI", e);
e.printStackTrace();
System.exit(1);
}
} else {
desktop = new HeadLessDesktop();
}
// load configuration
if (MZmineConfiguration.CONFIG_FILE.exists() && MZmineConfiguration.CONFIG_FILE.canRead()) {
try {
configuration.loadConfiguration(MZmineConfiguration.CONFIG_FILE);
} catch (Exception e) {
e.printStackTrace();
}
}
// if we have GUI, show it now
if (desktop.getMainWindow() != null && !(desktop instanceof HeadLessDesktop)) {
// update the size and position of the main window
ParameterSet paramSet = configuration.getPreferences();
WindowSettingsParameter settings = paramSet.getParameter(MZminePreferences.windowSetttings);
settings.applySettingsToWindow(desktop.getMainWindow());
// add last project menu items
if (desktop instanceof MainWindow) {
((MainWindow) desktop).createLastUsedProjectsMenu(configuration.getLastProjects());
// listen for changes
configuration.getLastProjectsParameter().addFileListChangedListener(list -> {
// new list of last used projects
Desktop desk = getDesktop();
if (desk instanceof MainWindow) {
((MainWindow) desk).createLastUsedProjectsMenu(list);
}
});
}
// show the GUI
logger.info("Showing main window");
desktop.getMainWindow().setVisible(true);
// show the welcome message
desktop.setStatusBarText("Welcome to MZmine 2!");
// Check for updated version
NewVersionCheck NVC = new NewVersionCheck(CheckType.DESKTOP);
Thread nvcThread = new Thread(NVC);
nvcThread.setPriority(Thread.MIN_PRIORITY);
nvcThread.start();
// Tracker
GoogleAnalyticsTracker GAT = new GoogleAnalyticsTracker("MZmine Loaded (GUI mode)", "/JAVA/Main/GUI");
Thread gatThread = new Thread(GAT);
gatThread.setPriority(Thread.MIN_PRIORITY);
gatThread.start();
// register shutdown hook only if we have GUI - we don't want to
// save configuration on exit if we only run a batch
ShutDownHook shutDownHook = new ShutDownHook();
Runtime.getRuntime().addShutdownHook(shutDownHook);
}
// mode
if (args.length > 0 && desktop instanceof HeadLessDesktop) {
// Tracker
GoogleAnalyticsTracker GAT = new GoogleAnalyticsTracker("MZmine Loaded (Headless mode)", "/JAVA/Main/GUI");
Thread gatThread = new Thread(GAT);
gatThread.setPriority(Thread.MIN_PRIORITY);
gatThread.start();
File batchFile = new File(args[0]);
if ((!batchFile.exists()) || (!batchFile.canRead())) {
logger.severe("Cannot read batch file " + batchFile);
System.exit(1);
}
ExitCode exitCode = BatchModeModule.runBatch(projectManager.getCurrentProject(), batchFile);
if (exitCode == ExitCode.OK)
System.exit(0);
else
System.exit(1);
}
}
Aggregations