ExitCodes main_(int, const char**) { //------------------------------------------------------------- // parsing parameters //------------------------------------------------------------- String in = getStringOption_("in"); String csv = getStringOption_("out_csv"); String target_qp = getStringOption_("qp"); String target_run = getStringOption_("name"); String target_file = getStringOption_("run"); //------------------------------------------------------------- // reading input //------------------------------------------------------------ if (target_file != "") { target_run = QFileInfo(QString::fromStdString(target_file)).baseName(); } QcMLFile qcmlfile; qcmlfile.load(in); if (target_run == "") { //~ check if only one run in file std::vector<String> nas; qcmlfile.getRunNames(nas); if (nas.size() == 1) { target_run = nas.front(); } else { cerr << "Error: You have to give at least one of the following parameter (in ascending precedence): name, run. Aborting!" << endl; return ILLEGAL_PARAMETERS; } } String csv_str = ""; if (target_qp == "set id") { if (qcmlfile.existsSet(target_run,true)) { csv_str = qcmlfile.exportIDstats(target_run); } else { cerr << "Error: You have to specify a existing set for this qp. " << target_run << " seems not to exist. Aborting!" << endl; return ILLEGAL_PARAMETERS; } } else { //TODO warn when target_run is empty or not present in qcml csv_str = qcmlfile.exportAttachment(target_run, target_qp); } ofstream fout(csv.c_str()); fout << csv_str << endl; fout.close(); //~ qcmlfile.store(out); return EXECUTION_OK; //~ TODO export table containing all given qp }
ExitCodes main_(int, const char**) { //------------------------------------------------------------- // parsing parameters //------------------------------------------------------------- String in = getStringOption_("in"); String out = getStringOption_("out"); String mappi = getStringOption_("mapping"); String tab = getStringOption_("table"); ControlledVocabulary cv; cv.loadFromOBO("PSI-MS", File::find("/CV/psi-ms.obo")); cv.loadFromOBO("QC", File::find("/CV/qc-cv.obo")); //------------------------------------------------------------- // reading input //------------------------------------------------------------ QcMLFile qcmlfile; if (in != "") { qcmlfile.load(in); } if (mappi != "" && tab != "") { CsvFile csv_file(tab); CsvFile map_file(mappi); if (map_file.size()<2) //assumed that first row is the header of table and second row is the according qc { cerr << "Error: You have to give a mapping of your table (first row is the header of table and second row is the according qc). Aborting!" << endl; return ILLEGAL_PARAMETERS; } StringList header,according; map_file.getRow(0, header); map_file.getRow(1, according); if (header.size() != according.size()) { cerr << "Error: You have to give a mapping of your table (first row is the header of table and second row is the according qc). Aborting!" << endl; return ILLEGAL_PARAMETERS; } //~ std::map<String,String> mapping; //~ std::transform( header.begin(), header.end(), according.begin(), std::inserter(mapping, mapping.end() ), std::make_pair<String,String> ); int runset_col = -1; for (Size i = 0; i < according.size(); ++i) { if (!cv.exists(according[i])) { try { const ControlledVocabulary::CVTerm& term = cv.getTermByName(according[i]); header[i] = term.name; according[i] = term.id; } catch (...) { cerr << "Error: You have to specify a correct cv with accession or name in col "<< String(i) <<". Aborting!" << endl; //~ cerr << "Header was: "<< header[i] << " , according value was: " << according[i] << endl; return ILLEGAL_PARAMETERS; } } else { const ControlledVocabulary::CVTerm& term = cv.getTerm(according[i]); header[i] = term.name; } if (header[i] == "raw data file") //TODO add set name as possibility! { runset_col = i; } } if (runset_col < 0) { cerr << "Error: You have to give a mapping of your table - rows to runs/sets. Aborting!" << endl; return ILLEGAL_PARAMETERS; } if (csv_file.size()>1) { StringList li; for (Size i = 1; i < csv_file.size(); ++i) { StringList li; csv_file.getRow(i, li); if (li.size() < according.size()) { cerr << "Error: You have to give a correct mapping of your table - row " << String(i+1) <<" is too short. Aborting!" << endl; return ILLEGAL_PARAMETERS; } std::vector< QcMLFile::QualityParameter > qps; String id; bool set = false; for (Size j = 0; j < li.size(); ++j) { if (j==runset_col) { if (qcmlfile.existsRun(li[j])) //TODO this only works for real run IDs { id = li[j]; } else if (qcmlfile.existsSet(li[j])) //TODO this only works for real set IDs { id = li[j]; set = true; } else { id = li[j]; qcmlfile.registerRun(id,id); //TODO warn that if this was supposed to be a set - now it is not! } } QcMLFile::QualityParameter def; def.name = header[j]; ///< Name def.id = String(UniqueIdGenerator::getUniqueId()); def.cvRef = "QC"; ///< cv reference ('full name') def.cvAcc = according[j]; def.value = li[j]; qps.push_back(def); } if (id!="") { for (std::vector<QcMLFile::QualityParameter>::const_iterator qit = qps.begin(); qit != qps.end(); ++qit) { if (!set) { qcmlfile.addRunQualityParameter(id, *qit); } else { qcmlfile.addSetQualityParameter(id, *qit); } } } } } } qcmlfile.store(out); return EXECUTION_OK; }