use of net.sf.mzmine.modules.rawdatamethods.rawdataimport.RawDataImportModule in project mzmine2 by mzmine.
the class MzTabImportTask method importRawDataFiles.
private SortedMap<Integer, RawDataFile> importRawDataFiles(MZTabFile mzTabFile) throws Exception {
SortedMap<Integer, MsRun> msrun = mzTabFile.getMetadata().getMsRunMap();
SortedMap<Integer, RawDataFile> rawDataFiles = new TreeMap<>();
// If we are importing files, let's run RawDataImportModule
if (importRawFiles) {
List<File> filesToImport = new ArrayList<>();
for (Entry<Integer, MsRun> entry : msrun.entrySet()) {
File fileToImport = new File(entry.getValue().getLocation().getPath());
if (fileToImport.exists() && fileToImport.canRead())
filesToImport.add(fileToImport);
else {
// Check if the raw file exists in the same folder as the mzTab file
File checkFile = new File(inputFile.getParentFile(), fileToImport.getName());
if (checkFile.exists() && checkFile.canRead())
filesToImport.add(checkFile);
else {
// Append .gz & check again if file exists as a workaround to .gz not getting preserved
// when .mzML.gz importing
checkFile = new File(inputFile.getParentFile(), fileToImport.getName() + ".gz");
if (checkFile.exists() && checkFile.canRead())
filesToImport.add(checkFile);
else {
// One more level of checking, appending .zip & checking as a workaround
checkFile = new File(inputFile.getParentFile(), fileToImport.getName() + ".zip");
if (checkFile.exists() && checkFile.canRead())
filesToImport.add(checkFile);
}
}
}
}
RawDataImportModule RDI = MZmineCore.getModuleInstance(RawDataImportModule.class);
ParameterSet rdiParameters = RDI.getParameterSetClass().newInstance();
rdiParameters.getParameter(RawDataImportParameters.fileNames).setValue(filesToImport.toArray(new File[0]));
synchronized (underlyingTasks) {
RDI.runModule(project, rdiParameters, underlyingTasks);
}
if (underlyingTasks.size() > 0) {
MZmineCore.getTaskController().addTasks(underlyingTasks.toArray(new Task[0]));
}
// Wait until all raw data file imports have completed
while (true) {
if (isCanceled())
return null;
boolean tasksFinished = true;
for (Task task : underlyingTasks) {
if ((task.getStatus() == TaskStatus.WAITING) || (task.getStatus() == TaskStatus.PROCESSING))
tasksFinished = false;
}
if (tasksFinished)
break;
Thread.sleep(1000);
}
/*
* // Sort raw data files based on order in mzTab file MainWindow mainWindow = (MainWindow)
* MZmineCore.getDesktop(); ProjectTree rawDataTree = mainWindow.getMainPanel()
* .getRawDataTree(); final RawDataTreeModel treeModel = ((MZmineProjectImpl)
* project).getRawDataTreeModel(); final DefaultMutableTreeNode rootNode =
* treeModel.getRoot(); int[] selectedRows = new int[rootNode.getChildCount()]; for (int i =
* 1; i < rootNode.getChildCount() + 1; i++) { selectedRows[i - 1] = i; } final
* ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
* for (int row : selectedRows) { TreePath path = rawDataTree.getPathForRow(row);
* DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path
* .getLastPathComponent(); selectedNodes.add(selectedNode); }
*
* // Reorder the nodes in the tree model based on order in mzTab // file int fileCounter = 0;
* for (Entry<Integer, MsRun> entry : msrun.entrySet()) { fileCounter++; File f = new
* File(entry.getValue().getLocation().getPath()); for (DefaultMutableTreeNode node :
* selectedNodes) { if (node.toString().equals(f.getName())) {
* treeModel.removeNodeFromParent(node); treeModel.insertNodeInto(node, rootNode, fileCounter
* - 1); } } }
*/
} else {
finishedPercentage = 0.5;
}
// Find a matching RawDataFile for each MsRun entry
for (Entry<Integer, MsRun> entry : msrun.entrySet()) {
String rawFileName = new File(entry.getValue().getLocation().getPath()).getName();
RawDataFile rawDataFile = null;
// Check if we already have a RawDataFile of that name
for (RawDataFile f : project.getDataFiles()) {
if (f.getName().equals(rawFileName)) {
rawDataFile = f;
break;
}
}
// If no data file of that name exists, create a dummy one
if (rawDataFile == null) {
RawDataFileWriter writer = MZmineCore.createNewFile(rawFileName);
rawDataFile = writer.finishWriting();
project.addFile(rawDataFile);
}
// Save a reference to the new raw data file
rawDataFiles.put(entry.getKey(), rawDataFile);
}
return rawDataFiles;
}
Aggregations