Search in sources :

Example 91 with PeakList

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;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) PeakList(net.sf.mzmine.datamodel.PeakList) Nonnull(javax.annotation.Nonnull)

Example 92 with PeakList

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;
    }
}
Also used : MZTabFile(uk.ac.ebi.pride.jmztab.model.MZTabFile) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) OutputStream(java.io.OutputStream) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) MZTabFileParser(uk.ac.ebi.pride.jmztab.utils.MZTabFileParser)

Example 93 with PeakList

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);
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) PeakList(net.sf.mzmine.datamodel.PeakList) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 94 with PeakList

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);
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) PeakList(net.sf.mzmine.datamodel.PeakList) File(java.io.File) IOException(java.io.IOException)

Example 95 with PeakList

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);
}
Also used : FileWriter(java.io.FileWriter) PeakList(net.sf.mzmine.datamodel.PeakList) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File) IOException(java.io.IOException)

Aggregations

PeakList (net.sf.mzmine.datamodel.PeakList)120 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)41 Nonnull (javax.annotation.Nonnull)40 Task (net.sf.mzmine.taskcontrol.Task)37 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)36 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)26 Feature (net.sf.mzmine.datamodel.Feature)19 ArrayList (java.util.ArrayList)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)11 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)10 File (java.io.File)9 FileWriter (java.io.FileWriter)8 ParameterSet (net.sf.mzmine.parameters.ParameterSet)8 IOException (java.io.IOException)7 DataPoint (net.sf.mzmine.datamodel.DataPoint)7 Vector (java.util.Vector)6 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)6