use of net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.param.LibraryMetaDataParameters in project mzmine2 by mzmine.
the class GnpsJsonGenerator method generateJSON.
/**
* Whole JSON entry
*
* @param param
* @param dps
* @return
*/
public static String generateJSON(LibrarySubmitIonParameters param, DataPoint[] dps) {
LibraryMetaDataParameters meta = (LibraryMetaDataParameters) param.getParameter(LibrarySubmitIonParameters.META_PARAM).getValue();
boolean exportRT = meta.getParameter(LibraryMetaDataParameters.EXPORT_RT).getValue();
JsonObjectBuilder json = Json.createObjectBuilder();
// tag spectrum from mzmine2
json.add(DBEntryField.SOFTWARE.getGnpsJsonID(), "mzmine2");
// ion specific
Double precursorMZ = param.getParameter(LibrarySubmitIonParameters.MZ).getValue();
if (precursorMZ != null)
json.add(DBEntryField.MZ.getGnpsJsonID(), precursorMZ);
Integer charge = param.getParameter(LibrarySubmitIonParameters.CHARGE).getValue();
if (charge != null)
json.add(DBEntryField.CHARGE.getGnpsJsonID(), charge);
String adduct = param.getParameter(LibrarySubmitIonParameters.ADDUCT).getValue();
if (adduct != null && !adduct.trim().isEmpty())
json.add(DBEntryField.ION_TYPE.getGnpsJsonID(), adduct);
if (exportRT) {
Double rt = meta.getParameter(LibraryMetaDataParameters.EXPORT_RT).getEmbeddedParameter().getValue();
if (rt != null)
json.add(DBEntryField.RT.getGnpsJsonID(), rt);
}
// add data points array
json.add("peaks", genJSONData(dps));
// add meta data
for (Parameter<?> p : meta.getParameters()) {
if (!p.getName().equals(LibraryMetaDataParameters.EXPORT_RT.getName())) {
String key = p.getName();
Object value = p.getValue();
if (value instanceof Double) {
if (Double.compare(0d, (Double) value) == 0)
json.add(key, 0);
else
json.add(key, (Double) value);
} else if (value instanceof Float) {
if (Float.compare(0f, (Float) value) == 0)
json.add(key, 0);
else
json.add(key, (Float) value);
} else if (value instanceof Integer)
json.add(key, (Integer) value);
else {
if (value == null || (value instanceof String && ((String) value).isEmpty()))
value = "N/A";
json.add(key, value.toString());
}
}
}
// return Json.createObjectBuilder().add("spectrum", json.build()).build().toString();
return json.build().toString();
}
use of net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.param.LibraryMetaDataParameters in project mzmine2 by mzmine.
the class MSPEntryGenerator method createMSPEntry.
/**
* Creates a simple MSP nist format DB entry
*
* @param param
* @param dps
* @return
*/
public static String createMSPEntry(LibrarySubmitIonParameters param, DataPoint[] dps) {
LibraryMetaDataParameters meta = (LibraryMetaDataParameters) param.getParameter(LibrarySubmitIonParameters.META_PARAM).getValue();
boolean exportRT = meta.getParameter(LibraryMetaDataParameters.EXPORT_RT).getValue();
String ionMode = meta.getParameter(LibraryMetaDataParameters.IONMODE).getValue().equals(Polarity.Positive) ? "P" : "N";
String def = ": ";
String br = "\n";
StringBuilder s = new StringBuilder();
// tag spectrum from mzmine2
// ion specific
s.append(DBEntryField.NAME.getNistMspID() + def + meta.getParameter(LibraryMetaDataParameters.COMPOUND_NAME).getValue() + br);
s.append(DBEntryField.INCHIKEY.getNistMspID() + def + meta.getParameter(LibraryMetaDataParameters.INCHI_AUX).getValue() + br);
s.append(DBEntryField.MS_LEVEL.getNistMspID() + def + "MS" + meta.getParameter(LibraryMetaDataParameters.MS_LEVEL).getValue() + br);
s.append(DBEntryField.INSTRUMENT_TYPE.getNistMspID() + def + meta.getParameter(LibraryMetaDataParameters.INSTRUMENT).getValue() + br);
s.append(DBEntryField.INSTRUMENT.getNistMspID() + def + meta.getParameter(LibraryMetaDataParameters.INSTRUMENT_NAME).getValue() + br);
s.append(DBEntryField.ION_MODE.getNistMspID() + def + ionMode + br);
s.append(DBEntryField.COLLISION_ENERGY.getNistMspID() + def + meta.getParameter(LibraryMetaDataParameters.FRAGMENTATION_METHOD).getValue() + br);
s.append(DBEntryField.FORMULA.getNistMspID() + def + meta.getParameter(LibraryMetaDataParameters.FORMULA).getValue() + br);
Double exact = meta.getParameter(LibraryMetaDataParameters.EXACT_MASS).getValue();
if (exact != null)
s.append(DBEntryField.EXACT_MASS.getNistMspID() + def + exact + br);
Double precursorMZ = param.getParameter(LibrarySubmitIonParameters.MZ).getValue();
if (precursorMZ != null)
s.append(DBEntryField.MZ.getNistMspID() + def + param.getParameter(LibrarySubmitIonParameters.MZ).getValue() + br);
String adduct = param.getParameter(LibrarySubmitIonParameters.ADDUCT).getValue();
if (adduct != null && !adduct.trim().isEmpty())
s.append(DBEntryField.ION_TYPE.getNistMspID() + def + param.getParameter(LibrarySubmitIonParameters.ADDUCT).getValue() + br);
if (exportRT) {
Double rt = meta.getParameter(LibraryMetaDataParameters.EXPORT_RT).getEmbeddedParameter().getValue();
if (rt != null)
s.append(DBEntryField.RT.getNistMspID() + def + rt + br);
}
// num peaks and data
s.append(DBEntryField.NUM_PEAKS.getNistMspID() + def + dps.length + br);
NumberFormat mzForm = new DecimalFormat("0.######");
for (DataPoint dp : dps) {
s.append(mzForm.format(dp.getMZ()) + " " + dp.getIntensity() + br);
}
s.append(br);
return s.toString();
}
Aggregations