| 19 | using namespace std; |
| 20 | |
| 21 | void CsiFingerIdMzTabWriter::read(const std::vector<String>& sirius_output_paths, |
| 22 | const String& original_input_mzml, |
| 23 | const Size& top_n_hits, |
| 24 | MzTab& result) |
| 25 | { |
| 26 | |
| 27 | CsiFingerIdMzTabWriter::CsiAdapterRun csi_result; |
| 28 | |
| 29 | for (const auto& it : sirius_output_paths) |
| 30 | { |
| 31 | // extract mz, rt of the precursor and the nativeID of the corresponding MS2 spectra in the spectrum.ms file |
| 32 | SiriusMzTabWriter::SiriusSpectrumMSInfo info = SiriusMzTabWriter::extractSpectrumMSInfo(it); |
| 33 | |
| 34 | const std::string pathtocsicsv = it + "/structure_candidates.tsv"; |
| 35 | |
| 36 | ifstream file(pathtocsicsv); |
| 37 | |
| 38 | if (file) |
| 39 | { |
| 40 | CsvFile compounds(pathtocsicsv, '\t'); |
| 41 | const UInt rowcount = compounds.rowCount(); |
| 42 | |
| 43 | if (rowcount > 1) |
| 44 | { |
| 45 | // correction if the rowcount is smaller than the number of hits used as parameter |
| 46 | // rowcount-1 because the csv header will be skipped in the loop later on. |
| 47 | int header = 1; |
| 48 | const UInt top_n_hits_cor = (top_n_hits >= rowcount) ? rowcount-header : top_n_hits; |
| 49 | |
| 50 | // fill identification structure containing all candidate hits for a single spectrum |
| 51 | CsiFingerIdMzTabWriter::CsiAdapterIdentification csi_id{}; |
| 52 | |
| 53 | // extract scan_index from path |
| 54 | OpenMS::String str = File::path(pathtocsicsv); |
| 55 | int scan_index = SiriusMzTabWriter::extractScanIndex(str); |
| 56 | |
| 57 | // extract scan_number from string |
| 58 | int scan_number = SiriusMzTabWriter::extractScanNumber(str); |
| 59 | |
| 60 | // extract feature_id from string |
| 61 | String feature_id = SiriusMzTabWriter::extractFeatureId(str); |
| 62 | |
| 63 | // extract column name and index from header |
| 64 | std::map< std::string, Size > columnname_to_columnindex = SiriusMzTabWriter::extract_columnname_to_columnindex(compounds); |
| 65 | |
| 66 | // j = 1 because of .csv file format (header) |
| 67 | for (Size j = 1; j <= top_n_hits_cor; ++j) |
| 68 | { |
| 69 | StringList sl; |
| 70 | compounds.getRow(j, sl); |
| 71 | CsiFingerIdMzTabWriter::CsiAdapterHit csi_hit; |
| 72 | csi_hit.inchikey2D = sl[columnname_to_columnindex.at("InChIkey2D")]; |
| 73 | csi_hit.inchi = sl[columnname_to_columnindex.at("InChI")]; |
| 74 | csi_hit.molecular_formula = sl[columnname_to_columnindex.at("molecularFormula")]; |
| 75 | csi_hit.rank = sl[columnname_to_columnindex.at("rank")].toInt(); |
| 76 | csi_hit.formula_rank = sl[columnname_to_columnindex.at("formulaRank")].toInt(); |
| 77 | csi_hit.adduct = sl[columnname_to_columnindex.at("adduct")]; |
| 78 | csi_hit.score = sl[columnname_to_columnindex.at("CSI:FingerIDScore")].toDouble(); |
nothing calls this directly
no test coverage detected