@brief Generates a feature quantification file required for GNPS FBMN, as defined here: https://ccms-ucsd.github.io/GNPSDocumentation/featurebasedmolecularnetworking/#feature-quantification-table */
| 20 | @brief Generates a feature quantification file required for GNPS FBMN, as defined here: https://ccms-ucsd.github.io/GNPSDocumentation/featurebasedmolecularnetworking/#feature-quantification-table |
| 21 | */ |
| 22 | void GNPSQuantificationFile::store(const ConsensusMap& consensus_map, const String& output_file) |
| 23 | { |
| 24 | // IIMN meta values will be exported, if first feature contains mv Constants::UserParam::IIMN_ROW_ID |
| 25 | bool iimn = false; |
| 26 | if (consensus_map[0].metaValueExists(Constants::UserParam::IIMN_ROW_ID)) iimn = true; |
| 27 | |
| 28 | // meta values for ion identity molecular networking |
| 29 | std::vector<String> iimn_mvs{Constants::UserParam::IIMN_ROW_ID, |
| 30 | Constants::UserParam::IIMN_BEST_ION, |
| 31 | Constants::UserParam::IIMN_ADDUCT_PARTNERS, |
| 32 | Constants::UserParam::IIMN_ANNOTATION_NETWORK_NUMBER}; |
| 33 | |
| 34 | // initialize SVOutStream with tab separation |
| 35 | std::ofstream outstr(output_file.c_str()); |
| 36 | SVOutStream out(outstr, "\t", "_", String::NONE); |
| 37 | |
| 38 | // write headers for MAP and CONSENSUS |
| 39 | out << "#MAP" << "id" << "filename" << "label" << "size" << std::endl; |
| 40 | out << "#CONSENSUS" << "rt_cf" << "mz_cf" << "intensity_cf" << "charge_cf" << "width_cf" << "quality_cf"; |
| 41 | if (iimn) |
| 42 | { |
| 43 | for (const auto& mv : iimn_mvs) out << mv; |
| 44 | } |
| 45 | for (size_t i = 0; i < consensus_map.getColumnHeaders().size(); i++) |
| 46 | { |
| 47 | out << "rt_" + String(i) << "mz_" + String(i) << "intensity_" + String(i) << "charge_" + String(i) << "width_" + String(i); |
| 48 | } |
| 49 | out << std::endl; |
| 50 | |
| 51 | // write MAP information |
| 52 | for (const auto& h: consensus_map.getColumnHeaders()) |
| 53 | { |
| 54 | out << "MAP" << h.first << h.second.filename << h.second.label << h.second.size << std::endl; |
| 55 | } |
| 56 | |
| 57 | // write ConsensusFeature information |
| 58 | for (const auto& cf: consensus_map) |
| 59 | { |
| 60 | out << "CONSENSUS" << cf.getRT() << cf.getMZ() << cf.getIntensity() << cf.getCharge() << cf.getWidth() << cf.getQuality(); |
| 61 | if (iimn) |
| 62 | { |
| 63 | for (const auto& mv : iimn_mvs) out << cf.getMetaValue(mv, ""); |
| 64 | } |
| 65 | // map index to feature handle and write feature information on correct position, if feature is missing write empty strings |
| 66 | std::unordered_map<size_t, FeatureHandle> index_to_feature; |
| 67 | for (const auto& fh: cf.getFeatures()) index_to_feature[fh.getMapIndex()] = fh; |
| 68 | for (size_t i = 0; i < consensus_map.getColumnHeaders().size(); i++) |
| 69 | { |
| 70 | if (index_to_feature.count(i)) |
| 71 | { |
| 72 | out << index_to_feature[i].getRT() << index_to_feature[i].getMZ() << index_to_feature[i].getIntensity() << index_to_feature[i].getCharge() << index_to_feature[i].getWidth(); |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | out << "" << "" << "" << "" << ""; |
| 77 | } |
| 78 | } |
| 79 | out << std::endl; |
nothing calls this directly
no test coverage detected