Search in sources :

Example 1 with MZTabFileParser

use of uk.ac.ebi.pride.jmztab.utils.MZTabFileParser 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)

Aggregations

OutputStream (java.io.OutputStream)1 PeakList (net.sf.mzmine.datamodel.PeakList)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)1 MZTabFile (uk.ac.ebi.pride.jmztab.model.MZTabFile)1 MZTabFileParser (uk.ac.ebi.pride.jmztab.utils.MZTabFileParser)1