use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class FragmentSearchModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(FragmentSearchParameters.peakLists).getValue().getMatchingPeakLists();
for (PeakList peakList : peakLists) {
Task newTask = new FragmentSearchTask(parameters, peakList);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class MzTabImportTask method run.
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
try {
// Prevent MZTabFileParser from writing to console
OutputStream logStream = ByteStreams.nullOutputStream();
// Load mzTab file
MZTabFileParser mzTabFileParser = new MZTabFileParser(inputFile, logStream);
if (!mzTabFileParser.getErrorList().getErrorList().isEmpty()) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Error processing " + inputFile + ":\n" + mzTabFileParser.getErrorList().toString());
return;
}
MZTabFile mzTabFile = mzTabFileParser.getMZTabFile();
// Let's say the initial parsing took 10% of the time
finishedPercentage = 0.1;
// Import raw data files
SortedMap<Integer, RawDataFile> rawDataFiles = importRawDataFiles(mzTabFile);
// Check if not canceled
if (isCanceled())
return;
// Create a new feature list
String peakListName = inputFile.getName().replace(".mzTab", "");
RawDataFile[] rawDataArray = rawDataFiles.values().toArray(new RawDataFile[0]);
PeakList newPeakList = new SimplePeakList(peakListName, rawDataArray);
// Check if not canceled
if (isCanceled())
return;
// Import variables
importVariables(mzTabFile, rawDataFiles);
// Check if not canceled
if (isCanceled())
return;
// import small molecules (=feature list rows)
importSmallMolecules(newPeakList, mzTabFile, rawDataFiles);
// Check if not canceled
if (isCanceled())
return;
// Add the new feature list to the project
project.addPeakList(newPeakList);
// Finish
setStatus(TaskStatus.FINISHED);
finishedPercentage = 1.0;
} catch (Exception e) {
e.printStackTrace();
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not import data from " + inputFile + ": " + e.getMessage());
return;
}
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class SiriusExportTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
// Shall export several files?
boolean substitute = fileName.getPath().contains(plNamePattern);
for (PeakList l : peakLists) {
this.totalRows += l.getNumberOfRows();
prefillStatistics(l.getRows());
}
// Process feature lists
for (PeakList peakList : peakLists) {
// Filename
File curFile = fileName;
if (substitute) {
// Cleanup from illegal filename characters
String cleanPlName = peakList.getName().replaceAll("[^a-zA-Z0-9.-]", "_");
// Substitute
String newFilename = fileName.getPath().replaceAll(Pattern.quote(plNamePattern), cleanPlName);
curFile = new File(newFilename);
}
// Open file
try (final BufferedWriter bw = new BufferedWriter(new FileWriter(curFile))) {
exportPeakList(peakList, bw);
} catch (IOException e) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not open file " + curFile + " for writing.");
}
// treat one feature list only
if (!substitute)
break;
}
if (getStatus() == TaskStatus.PROCESSING)
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class GnpsFbmnMgfExportTask method run.
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
// Shall export several files?
boolean substitute = fileName.getPath().contains(plNamePattern);
// Process feature lists
for (PeakList peakList : peakLists) {
currentIndex++;
// Filename
File curFile = fileName;
if (substitute) {
// Cleanup from illegal filename characters
String cleanPlName = peakList.getName().replaceAll("[^a-zA-Z0-9.-]", "_");
// Substitute
String newFilename = fileName.getPath().replaceAll(Pattern.quote(plNamePattern), cleanPlName);
curFile = new File(newFilename);
}
curFile = FileAndPathUtil.getRealFilePath(curFile, "mgf");
// Open file
FileWriter writer;
try {
writer = new FileWriter(curFile);
} catch (Exception e) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not open file " + curFile + " for writing.");
return;
}
try {
export(peakList, writer, curFile);
} catch (IOException e) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Error while writing into file " + curFile + ": " + e.getMessage());
return;
}
// Cancel?
if (isCanceled()) {
return;
}
// Close file
try {
writer.close();
} catch (Exception e) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not close file " + curFile);
return;
}
// treat one feature list only
if (!substitute)
break;
}
if (getStatus() == TaskStatus.PROCESSING)
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class MetaboAnalystExportTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
// Shall export several files?
boolean substitute = fileName.getPath().contains(plNamePattern);
// Total number of rows
for (PeakList peakList : peakLists) {
totalRows += peakList.getNumberOfRows();
}
// Process feature lists
for (PeakList peakList : peakLists) {
// Filename
File curFile = fileName;
if (substitute) {
// Cleanup from illegal filename characters
String cleanPlName = peakList.getName().replaceAll("[^a-zA-Z0-9.-]", "_");
// Substitute
String newFilename = fileName.getPath().replaceAll(Pattern.quote(plNamePattern), cleanPlName);
curFile = new File(newFilename);
}
// Check the feature list for MetaboAnalyst requirements
boolean checkResult = checkPeakList(peakList);
if (checkResult == false) {
MZmineCore.getDesktop().displayErrorMessage(null, "Feature list " + peakList.getName() + " does not conform to MetaboAnalyst requirement: at least 3 samples (raw data files) in each group");
}
try {
// Open file
FileWriter writer = new FileWriter(curFile);
// Get number of rows
totalRows = peakList.getNumberOfRows();
exportPeakList(peakList, writer);
// Close file
writer.close();
} catch (Exception e) {
e.printStackTrace();
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not export feature list to file " + curFile + ": " + e.getMessage());
return;
}
}
if (getStatus() == TaskStatus.PROCESSING)
setStatus(TaskStatus.FINISHED);
}
Aggregations