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);
}
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;
}
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;
}
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++;
}
}
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();
}
Aggregations