CachedmzML cacheFile(std::string & tmp_filename, PeakMap& exp) { NEW_TMP_FILE(tmp_filename); // Load experiment MzMLFile().load(OPENMS_GET_TEST_DATA_PATH("MzMLFile_1.mzML"), exp); TEST_EQUAL(exp.getNrSpectra() > 0, true) TEST_EQUAL(exp.getNrChromatograms() > 0, true) // Cache the experiment to a temporary file CachedmzML cache; cache.writeMemdump(exp, tmp_filename); // Create the index from the given file cache.createMemdumpIndex(tmp_filename); return cache; }
ExitCodes main_(int , const char**) { String in = getStringOption_("in"); String out_meta = getStringOption_("out"); String in_cached = in + ".cached"; String out_cached = out_meta + ".cached"; bool convert_back = getFlag_("convert_back"); if (!convert_back) { MapType exp; CachedmzML cacher; MzMLFile f; cacher.setLogType(log_type_); f.setLogType(log_type_); f.load(in,exp); cacher.writeMemdump(exp, out_cached); DataProcessing dp; std::set<DataProcessing::ProcessingAction> actions; actions.insert(DataProcessing::FORMAT_CONVERSION); dp.setProcessingActions(actions); dp.setMetaValue("cached_data", "true"); for (Size i=0; i<exp.size(); ++i) { exp[i].getDataProcessing().push_back(dp); } std::vector<MSChromatogram<ChromatogramPeak> > chromatograms = exp.getChromatograms(); for (Size i=0; i<chromatograms.size(); ++i) { chromatograms[i].getDataProcessing().push_back(dp); } exp.setChromatograms(chromatograms); cacher.writeMetadata(exp, out_meta); } else { MzMLFile f; MapType meta_exp; CachedmzML cacher; MapType exp_reading; cacher.setLogType(log_type_); f.setLogType(log_type_); f.load(in,meta_exp); cacher.readMemdump(exp_reading, in_cached); std::cout << " read back, got " << exp_reading.size() << " spectra " << exp_reading.getChromatograms().size() << " chromats " << std::endl; { for (Size i=0; i<meta_exp.size(); ++i) { for (Size j = 0; j < meta_exp[i].getDataProcessing().size(); j++) { DataProcessing& dp = meta_exp[i].getDataProcessing()[j]; if (dp.metaValueExists("cached_data")) { dp.removeMetaValue("cached_data"); } } } std::vector<MSChromatogram<ChromatogramPeak> > chromatograms = meta_exp.getChromatograms(); for (Size i=0; i<chromatograms.size(); ++i) { for (Size j = 0; j < chromatograms[i].getDataProcessing().size(); j++) { DataProcessing& dp = chromatograms[i].getDataProcessing()[j]; if (dp.metaValueExists("cached_data")) { dp.removeMetaValue("cached_data"); } } } } if (meta_exp.size() != exp_reading.size()) { std::cerr << " Both experiments need to have the same size!"; } for (Size i=0; i<exp_reading.size(); ++i) { for (Size j = 0; j < exp_reading[i].size(); j++) { meta_exp[i].push_back(exp_reading[i][j]); } } std::vector<MSChromatogram<ChromatogramPeak> > chromatograms = exp_reading.getChromatograms(); std::vector<MSChromatogram<ChromatogramPeak> > old_chromatograms = meta_exp.getChromatograms(); for (Size i=0; i<chromatograms.size(); ++i) { for (Size j = 0; j < chromatograms[i].size(); j++) { old_chromatograms[i].push_back(chromatograms[i][j]); } } meta_exp.setChromatograms(old_chromatograms); f.store(out_meta,meta_exp); } return EXECUTION_OK; }
ExitCodes main_(int , const char**) { String out_meta = getStringOption_("out"); String out_cached = out_meta + ".cached"; bool convert_back = getFlag_("convert_back"); FileHandler fh; //input file type String in = getStringOption_("in"); String in_cached = in + ".cached"; FileTypes::Type in_type = FileTypes::nameToType(getStringOption_("in_type")); if (in_type == FileTypes::UNKNOWN) { in_type = fh.getType(in); writeDebug_(String("Input file type: ") + FileTypes::typeToName(in_type), 2); } if (in_type == FileTypes::UNKNOWN) { writeLog_("Error: Could not determine input file type!"); return PARSE_ERROR; } //output file names and types String out = getStringOption_("out"); FileTypes::Type out_type = FileTypes::nameToType(getStringOption_("out_type")); if (out_type == FileTypes::UNKNOWN) { out_type = fh.getTypeByFileName(out); } if (out_type == FileTypes::UNKNOWN) { writeLog_("Error: Could not determine output file type!"); return PARSE_ERROR; } if (in_type == FileTypes::SQMASS && out_type == FileTypes::MZML) { MapType exp; SqMassFile sqfile; MzMLFile f; sqfile.load(in, exp); f.store(out, exp); return EXECUTION_OK; } else if (in_type == FileTypes::MZML && out_type == FileTypes::SQMASS) { MzMLFile f; SqMassFile sqfile; MapType exp; f.load(in, exp); sqfile.store(out, exp); return EXECUTION_OK; } if (!convert_back) { MapType exp; CachedmzML cacher; MzMLFile f; cacher.setLogType(log_type_); f.setLogType(log_type_); f.load(in,exp); cacher.writeMemdump(exp, out_cached); cacher.writeMetadata(exp, out_meta, true); } else { MzMLFile f; MapType meta_exp; CachedmzML cacher; MapType exp_reading; cacher.setLogType(log_type_); f.setLogType(log_type_); f.load(in,meta_exp); cacher.readMemdump(exp_reading, in_cached); std::cout << " read back, got " << exp_reading.size() << " spectra " << exp_reading.getChromatograms().size() << " chromats " << std::endl; { for (Size i=0; i<meta_exp.size(); ++i) { for (Size j = 0; j < meta_exp[i].getDataProcessing().size(); j++) { if (meta_exp[i].getDataProcessing()[j]->metaValueExists("cached_data")) { meta_exp[i].getDataProcessing()[j]->removeMetaValue("cached_data"); } } } for (Size i=0; i < meta_exp.getNrChromatograms(); ++i) { for (Size j = 0; j < meta_exp.getChromatogram(i).getDataProcessing().size(); j++) { if (meta_exp.getChromatogram(i).getDataProcessing()[j]->metaValueExists("cached_data")) { meta_exp.getChromatogram(i).getDataProcessing()[j]->removeMetaValue("cached_data"); } } } } if (meta_exp.size() != exp_reading.size()) { std::cerr << " Both experiments need to have the same size!"; } for (Size i=0; i<exp_reading.size(); ++i) { for (Size j = 0; j < exp_reading[i].size(); j++) { meta_exp[i].push_back(exp_reading[i][j]); } } std::vector<MSChromatogram<ChromatogramPeak> > chromatograms = exp_reading.getChromatograms(); std::vector<MSChromatogram<ChromatogramPeak> > old_chromatograms = meta_exp.getChromatograms(); for (Size i=0; i<chromatograms.size(); ++i) { for (Size j = 0; j < chromatograms[i].size(); j++) { old_chromatograms[i].push_back(chromatograms[i][j]); } } meta_exp.setChromatograms(old_chromatograms); f.store(out_meta,meta_exp); } return EXECUTION_OK; }