Search in sources :

Example 51 with RawDataFile

use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.

the class PeakListOpenHandler_2_5 method initializePeakList.

/**
 * Initializes the feature list
 */
private void initializePeakList() {
    RawDataFile[] dataFiles = currentPeakListDataFiles.toArray(new RawDataFile[0]);
    buildingPeakList = new SimplePeakList(peakListName, dataFiles);
    for (int i = 0; i < appliedMethods.size(); i++) {
        String methodName = appliedMethods.elementAt(i);
        String methodParams = appliedMethodParameters.elementAt(i);
        PeakListAppliedMethod pam = new SimplePeakListAppliedMethod(methodName, methodParams);
        buildingPeakList.addDescriptionOfAppliedTask(pam);
    }
    buildingPeakList.setDateCreated(dateCreated);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 52 with RawDataFile

use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.

the class PeakListOpenHandler_2_5 method readPeakList.

/**
 * Load the feature list from the zip file reading the XML feature list file
 */
@Override
public PeakList readPeakList(InputStream peakListStream) throws IOException, ParserConfigurationException, SAXException {
    totalRows = 0;
    parsedRows = 0;
    charBuffer = new StringBuffer();
    appliedMethods = new Vector<String>();
    appliedMethodParameters = new Vector<String>();
    currentPeakListDataFiles = new Vector<RawDataFile>();
    currentIsotopes = new Vector<DataPoint>();
    currentAllMS2FragmentScans = new Vector<Integer>();
    buildingPeakList = null;
    // Parse the XML file
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse(peakListStream, this);
    // If there were no rows in the peaklist, it is still not initialized
    if (buildingPeakList == null) {
        initializePeakList();
    }
    return buildingPeakList;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 53 with RawDataFile

use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.

the class RawDataFileOpenHandler_2_5 method readRawDataFile.

/**
 * Extract the scan file and copies it into the temporary folder. Create a new raw data file using
 * the information from the XML raw data description file
 *
 * @param Name raw data file name
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public RawDataFile readRawDataFile(InputStream is, File scansFile) throws IOException, ParserConfigurationException, SAXException {
    charBuffer = new StringBuffer();
    massLists = new ArrayList<StorableMassList>();
    newRawDataFile = (RawDataFileImpl) MZmineCore.createNewFile(null);
    newRawDataFile.openDataPointsFile(scansFile);
    dataPointsOffsets = newRawDataFile.getDataPointsOffsets();
    dataPointsLengths = newRawDataFile.getDataPointsLengths();
    // Reads the XML file (raw data description)
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse(is, this);
    // Adds the raw data file to MZmine
    RawDataFile rawDataFile = newRawDataFile.finishWriting();
    return rawDataFile;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SAXParser(javax.xml.parsers.SAXParser) StorableMassList(net.sf.mzmine.project.impl.StorableMassList) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 54 with RawDataFile

use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_5 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@SuppressWarnings("unchecked")
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <OPTION>
    if (qName.equals(UserParameterElementName_2_5.OPTION.getElementName())) {
        String optionValue = getTextOfElement();
        currentOptions.add(optionValue);
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_5.VALUE.getElementName())) {
        RawDataFile currentDataFile = dataFilesIDMap.get(currentDataFileID);
        String valueString = getTextOfElement();
        Object value;
        if (currentParameter instanceof DoubleParameter) {
            value = new Double(valueString);
        } else
            value = valueString;
        currentValues.put(currentDataFile, value);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_5.PARAMETER.getElementName())) {
        if (currentParameter instanceof ComboParameter) {
            String[] newChoices = currentOptions.toArray(new String[0]);
            ((ComboParameter<String>) currentParameter).setChoices(newChoices);
        }
        newProject.addParameter(currentParameter);
        for (RawDataFile dataFile : currentValues.keySet()) {
            Object value = currentValues.get(dataFile);
            newProject.setParameterValue(currentParameter, dataFile, value);
        }
        parsedParams++;
    }
}
Also used : DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 55 with RawDataFile

use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.

the class PeakListSaveHandler method savePeakList.

/**
 * Create an XML document with the feature list information an save it into the project zip file
 *
 * @param peakList
 * @param peakListSavedName name of the feature list
 * @throws java.io.IOException
 */
public void savePeakList(PeakList peakList) throws IOException, TransformerConfigurationException, SAXException {
    numberOfRows = peakList.getNumberOfRows();
    finishedRows = 0;
    StreamResult streamResult = new StreamResult(finalStream);
    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler hd = tf.newTransformerHandler();
    Transformer serializer = hd.getTransformer();
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    hd.setResult(streamResult);
    hd.startDocument();
    AttributesImpl atts = new AttributesImpl();
    hd.startElement("", "", PeakListElementName.PEAKLIST.getElementName(), atts);
    atts.clear();
    // <NAME>
    hd.startElement("", "", PeakListElementName.PEAKLIST_NAME.getElementName(), atts);
    hd.characters(peakList.getName().toCharArray(), 0, peakList.getName().length());
    hd.endElement("", "", PeakListElementName.PEAKLIST_NAME.getElementName());
    // <PEAKLIST_DATE>
    String dateText = "";
    if (((SimplePeakList) peakList).getDateCreated() == null) {
        dateText = ((SimplePeakList) peakList).getDateCreated();
    } else {
        Date date = new Date();
        dateText = dateFormat.format(date);
    }
    hd.startElement("", "", PeakListElementName.PEAKLIST_DATE.getElementName(), atts);
    hd.characters(dateText.toCharArray(), 0, dateText.length());
    hd.endElement("", "", PeakListElementName.PEAKLIST_DATE.getElementName());
    // <QUANTITY>
    hd.startElement("", "", PeakListElementName.QUANTITY.getElementName(), atts);
    hd.characters(String.valueOf(numberOfRows).toCharArray(), 0, String.valueOf(numberOfRows).length());
    hd.endElement("", "", PeakListElementName.QUANTITY.getElementName());
    // <PROCESS>
    PeakListAppliedMethod[] processes = peakList.getAppliedMethods();
    for (PeakListAppliedMethod proc : processes) {
        hd.startElement("", "", PeakListElementName.METHOD.getElementName(), atts);
        hd.startElement("", "", PeakListElementName.METHOD_NAME.getElementName(), atts);
        String methodName = proc.getDescription();
        hd.characters(methodName.toCharArray(), 0, methodName.length());
        hd.endElement("", "", PeakListElementName.METHOD_NAME.getElementName());
        hd.startElement("", "", PeakListElementName.METHOD_PARAMETERS.getElementName(), atts);
        String methodParameters = proc.getParameters();
        hd.characters(methodParameters.toCharArray(), 0, methodParameters.length());
        hd.endElement("", "", PeakListElementName.METHOD_PARAMETERS.getElementName());
        hd.endElement("", "", PeakListElementName.METHOD.getElementName());
    }
    atts.clear();
    // <RAWFILE>
    RawDataFile[] dataFiles = peakList.getRawDataFiles();
    for (int i = 0; i < dataFiles.length; i++) {
        String ID = dataFilesIDMap.get(dataFiles[i]);
        hd.startElement("", "", PeakListElementName.RAWFILE.getElementName(), atts);
        char[] idChars = ID.toCharArray();
        hd.characters(idChars, 0, idChars.length);
        hd.endElement("", "", PeakListElementName.RAWFILE.getElementName());
    }
    // <ROW>
    PeakListRow row;
    for (int i = 0; i < numberOfRows; i++) {
        if (canceled)
            return;
        atts.clear();
        row = peakList.getRow(i);
        atts.addAttribute("", "", PeakListElementName.ID.getElementName(), "CDATA", String.valueOf(row.getID()));
        if (row.getComment() != null) {
            atts.addAttribute("", "", PeakListElementName.COMMENT.getElementName(), "CDATA", row.getComment());
        }
        hd.startElement("", "", PeakListElementName.ROW.getElementName(), atts);
        fillRowElement(row, hd);
        hd.endElement("", "", PeakListElementName.ROW.getElementName());
        finishedRows++;
    }
    hd.endElement("", "", PeakListElementName.PEAKLIST.getElementName());
    hd.endDocument();
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) Date(java.util.Date) DataPoint(net.sf.mzmine.datamodel.DataPoint) AttributesImpl(org.xml.sax.helpers.AttributesImpl) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile)

Aggregations

RawDataFile (net.sf.mzmine.datamodel.RawDataFile)185 Feature (net.sf.mzmine.datamodel.Feature)59 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)52 DataPoint (net.sf.mzmine.datamodel.DataPoint)51 Scan (net.sf.mzmine.datamodel.Scan)40 ArrayList (java.util.ArrayList)33 PeakList (net.sf.mzmine.datamodel.PeakList)33 Nonnull (javax.annotation.Nonnull)24 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)24 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)24 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)22 Task (net.sf.mzmine.taskcontrol.Task)20 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)19 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)17 IOException (java.io.IOException)14 ParameterSet (net.sf.mzmine.parameters.ParameterSet)14 File (java.io.File)13 MassList (net.sf.mzmine.datamodel.MassList)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)13 TreeMap (java.util.TreeMap)10