use of net.sf.mzmine.project.impl.StorableMassList in project mzmine2 by mzmine.
the class RawDataFileSaveHandler method fillScanElement.
/**
* Create the part of the XML document related to the scans
*
* @param scan
* @param element
*/
private void fillScanElement(Scan scan, TransformerHandler hd) throws SAXException, IOException {
// <SCAN_ID>
AttributesImpl atts = new AttributesImpl();
hd.startElement("", "", RawDataElementName.SCAN_ID.getElementName(), atts);
hd.characters(String.valueOf(scan.getScanNumber()).toCharArray(), 0, String.valueOf(scan.getScanNumber()).length());
hd.endElement("", "", RawDataElementName.SCAN_ID.getElementName());
// <MS_LEVEL>
hd.startElement("", "", RawDataElementName.MS_LEVEL.getElementName(), atts);
hd.characters(String.valueOf(scan.getMSLevel()).toCharArray(), 0, String.valueOf(scan.getMSLevel()).length());
hd.endElement("", "", RawDataElementName.MS_LEVEL.getElementName());
if (scan.getMSLevel() >= 2) {
// <PRECURSOR_MZ>
hd.startElement("", "", RawDataElementName.PRECURSOR_MZ.getElementName(), atts);
hd.characters(String.valueOf(scan.getPrecursorMZ()).toCharArray(), 0, String.valueOf(scan.getPrecursorMZ()).length());
hd.endElement("", "", RawDataElementName.PRECURSOR_MZ.getElementName());
// <PRECURSOR_CHARGE>
hd.startElement("", "", RawDataElementName.PRECURSOR_CHARGE.getElementName(), atts);
hd.characters(String.valueOf(scan.getPrecursorCharge()).toCharArray(), 0, String.valueOf(scan.getPrecursorCharge()).length());
hd.endElement("", "", RawDataElementName.PRECURSOR_CHARGE.getElementName());
}
// <RETENTION_TIME>
hd.startElement("", "", RawDataElementName.RETENTION_TIME.getElementName(), atts);
// In the project file, retention time is represented in seconds, for
// historical reasons
double rt = scan.getRetentionTime() * 60d;
hd.characters(String.valueOf(rt).toCharArray(), 0, String.valueOf(rt).length());
hd.endElement("", "", RawDataElementName.RETENTION_TIME.getElementName());
// <CENTROIDED>
hd.startElement("", "", RawDataElementName.CENTROIDED.getElementName(), atts);
hd.characters(String.valueOf(scan.getSpectrumType()).toCharArray(), 0, String.valueOf(scan.getSpectrumType()).length());
hd.endElement("", "", RawDataElementName.CENTROIDED.getElementName());
// <QUANTITY_DATAPOINTS>
hd.startElement("", "", RawDataElementName.QUANTITY_DATAPOINTS.getElementName(), atts);
hd.characters(String.valueOf((scan.getNumberOfDataPoints())).toCharArray(), 0, String.valueOf((scan.getNumberOfDataPoints())).length());
hd.endElement("", "", RawDataElementName.QUANTITY_DATAPOINTS.getElementName());
// <FRAGMENT_SCAN>
if (scan.getFragmentScanNumbers() != null) {
int[] fragmentScans = scan.getFragmentScanNumbers();
atts.addAttribute("", "", RawDataElementName.QUANTITY.getElementName(), "CDATA", String.valueOf(fragmentScans.length));
hd.startElement("", "", RawDataElementName.QUANTITY_FRAGMENT_SCAN.getElementName(), atts);
atts.clear();
for (int i : fragmentScans) {
hd.startElement("", "", RawDataElementName.FRAGMENT_SCAN.getElementName(), atts);
hd.characters(String.valueOf(i).toCharArray(), 0, String.valueOf(i).length());
hd.endElement("", "", RawDataElementName.FRAGMENT_SCAN.getElementName());
}
hd.endElement("", "", RawDataElementName.QUANTITY_FRAGMENT_SCAN.getElementName());
}
// <MASS_LIST>
MassList[] massLists = scan.getMassLists();
for (MassList massList : massLists) {
StorableMassList stMassList = (StorableMassList) massList;
atts.addAttribute("", "", RawDataElementName.NAME.getElementName(), "CDATA", stMassList.getName());
atts.addAttribute("", "", RawDataElementName.STORAGE_ID.getElementName(), "CDATA", String.valueOf(stMassList.getStorageID()));
hd.startElement("", "", RawDataElementName.MASS_LIST.getElementName(), atts);
atts.clear();
hd.endElement("", "", RawDataElementName.MASS_LIST.getElementName());
}
// <POLARITY>
hd.startElement("", "", RawDataElementName.POLARITY.getElementName(), atts);
String pol = scan.getPolarity().toString();
hd.characters(pol.toCharArray(), 0, pol.length());
hd.endElement("", "", RawDataElementName.POLARITY.getElementName());
// <SCAN_DESCRIPTION>
hd.startElement("", "", RawDataElementName.SCAN_DESCRIPTION.getElementName(), atts);
String scanDesc = scan.getScanDefinition();
hd.characters(scanDesc.toCharArray(), 0, scanDesc.length());
hd.endElement("", "", RawDataElementName.SCAN_DESCRIPTION.getElementName());
// <SCAN_MZ_RANGE>
hd.startElement("", "", RawDataElementName.SCAN_MZ_RANGE.getElementName(), atts);
Range<Double> mzRange = scan.getScanningMZRange();
String mzRangeStr = mzRange.lowerEndpoint() + "-" + mzRange.upperEndpoint();
hd.characters(mzRangeStr.toCharArray(), 0, mzRangeStr.length());
hd.endElement("", "", RawDataElementName.SCAN_MZ_RANGE.getElementName());
}
use of net.sf.mzmine.project.impl.StorableMassList 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;
}
use of net.sf.mzmine.project.impl.StorableMassList in project mzmine2 by mzmine.
the class RawDataFileOpenHandler_2_5 method endElement.
/**
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
* java.lang.String)
*/
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
if (canceled)
throw new SAXException("Parsing canceled");
// <NAME>
if (qName.equals(RawDataElementName_2_5.NAME.getElementName())) {
// Adds the scan file and the name to the new raw data file
String name = getTextOfElement();
logger.info("Loading raw data file: " + name);
newRawDataFile.setName(name);
}
if (qName.equals(RawDataElementName_2_5.QUANTITY_SCAN.getElementName())) {
// number of scans - actually not used for anything
Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.SCAN_ID.getElementName())) {
scanNumber = Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.STORED_DATA.getElementName())) {
long offset = Long.parseLong(getTextOfElement());
dataPointsOffsets.put(storedDataID, offset);
dataPointsLengths.put(storedDataID, storedDataNumDP);
}
if (qName.equals(RawDataElementName_2_5.MS_LEVEL.getElementName())) {
msLevel = Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.PARENT_SCAN.getElementName())) {
Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.POLARITY.getElementName())) {
String txt = getTextOfElement();
try {
polarity = PolarityType.valueOf(txt);
} catch (Exception e) {
polarity = PolarityType.fromSingleChar(txt);
}
}
if (qName.equals(RawDataElementName_2_5.SCAN_DESCRIPTION.getElementName())) {
scanDescription = getTextOfElement();
}
if (qName.equals(RawDataElementName_2_5.SCAN_MZ_RANGE.getElementName())) {
final String text = getTextOfElement();
scanMZRange = RangeUtils.parseRange(text);
}
if (qName.equals(RawDataElementName_2_5.PRECURSOR_CHARGE.getElementName())) {
precursorCharge = Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.PRECURSOR_MZ.getElementName())) {
precursorMZ = Double.parseDouble(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.RETENTION_TIME.getElementName())) {
// Before MZmine 2.6 retention time was saved in seconds, but now we
// use minutes, so we need to divide by 60
retentionTime = Double.parseDouble(getTextOfElement()) / 60d;
}
if (qName.equals(RawDataElementName_2_5.QUANTITY_DATAPOINTS.getElementName())) {
dataPointsNumber = Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.FRAGMENT_SCAN.getElementName())) {
fragmentScan[fragmentCount++] = Integer.parseInt(getTextOfElement());
}
if (qName.equals(RawDataElementName_2_5.SCAN.getElementName())) {
StorableScan storableScan = new StorableScan(newRawDataFile, currentStorageID, dataPointsNumber, scanNumber, msLevel, retentionTime, precursorMZ, precursorCharge, fragmentScan, null, polarity, scanDescription, scanMZRange);
try {
newRawDataFile.addScan(storableScan);
} catch (IOException e) {
throw new SAXException(e);
}
for (StorableMassList newML : massLists) {
newML.setScan(storableScan);
storableScan.addMassList(newML);
}
// Cleanup
massLists.clear();
currentStorageID = -1;
dataPointsNumber = -1;
scanNumber = -1;
msLevel = -1;
retentionTime = -1;
precursorMZ = -1;
precursorCharge = -1;
fragmentScan = null;
polarity = PolarityType.UNKNOWN;
scanDescription = "";
scanMZRange = null;
}
}
use of net.sf.mzmine.project.impl.StorableMassList in project mzmine2 by mzmine.
the class RawDataFileOpenHandler_2_5 method startElement.
/**
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
* java.lang.String, org.xml.sax.Attributes)
*/
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException {
if (canceled)
throw new SAXException("Parsing canceled");
// This will remove any remaining characters from previous elements
getTextOfElement();
if (qName.equals(RawDataElementName_2_5.QUANTITY_FRAGMENT_SCAN.getElementName())) {
numberOfFragments = Integer.parseInt(attrs.getValue(RawDataElementName_2_5.QUANTITY.getElementName()));
if (numberOfFragments > 0) {
fragmentScan = new int[numberOfFragments];
fragmentCount = 0;
}
}
if (qName.equals(RawDataElementName_2_5.SCAN.getElementName())) {
currentStorageID = Integer.parseInt(attrs.getValue(RawDataElementName_2_5.STORAGE_ID.getElementName()));
}
if (qName.equals(RawDataElementName_2_5.STORED_DATA.getElementName())) {
storedDataID = Integer.parseInt(attrs.getValue(RawDataElementName_2_5.STORAGE_ID.getElementName()));
storedDataNumDP = Integer.parseInt(attrs.getValue(RawDataElementName_2_5.QUANTITY_DATAPOINTS.getElementName()));
}
if (qName.equals(RawDataElementName_2_5.MASS_LIST.getElementName())) {
String name = attrs.getValue(RawDataElementName_2_5.NAME.getElementName());
int storageID = Integer.parseInt(attrs.getValue(RawDataElementName_2_5.STORAGE_ID.getElementName()));
StorableMassList newML = new StorableMassList(newRawDataFile, storageID, name, null);
massLists.add(newML);
}
}
Aggregations