/*------------------------------------------------------------------------ * object to WKT */ bool ogc_method :: to_wkt_projection( char buffer[], int options, size_t buflen) const { OGC_UTF8_NAME buf_name; OGC_TBUF buf_hdr; OGC_TBUF buf_id; int opts = (options | OGC_WKT_OPT_INTERNAL); size_t len = 0; bool rc = true; const char * opn = "["; const char * cls = "]"; const char * kwd = obj_kwd(); if ( (options & OGC_WKT_OPT_PARENS) != 0 ) { opn = "("; cls = ")"; } if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 ) opts |= OGC_WKT_OPT_NO_IDS; if ( buffer == OGC_NULL ) return false; *buffer = 0; if ( (opts & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) kwd = alt_kwd(); ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX); sprintf(buf_hdr, "%s%s\"%s\"", kwd, opn, buf_name); OGC_CPY_TO_BUF( buf_hdr ); if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 ) { for (int i = 0; i < id_count(); i++) { rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX); OGC_ADD_TO_BUF( buf_id ); if ( (opts & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) break; } } OGC_CPY_TO_BUF( cls ); if ( (options & OGC_WKT_OPT_INTERNAL) == 0 && (options & OGC_WKT_OPT_EXPAND) != 0 ) { rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen); } return rc; }
bool ogc_cs :: to_wkt( char buffer[], int options, size_t buflen) const { OGC_TBUF buf_hdr; OGC_TBUF buf_id; OGC_NBUF buf_dimension; const char * cs_type; int opts = (options | OGC_WKT_OPT_INTERNAL); size_t len = 0; bool rc = true; const char * opn = "["; const char * cls = "]"; const char * kwd = obj_kwd(); if ( (options & OGC_WKT_OPT_PARENS) != 0 ) { opn = "("; cls = ")"; } if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 ) opts |= OGC_WKT_OPT_NO_IDS; if ( buffer == OGC_NULL ) return false; *buffer = 0; if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) return true; cs_type = ogc_utils :: cs_type_to_kwd(_cs_type); ogc_string :: itoa(_dimension, buf_dimension); sprintf(buf_hdr, "%s%s\"%s\",%s", kwd, opn, cs_type, buf_dimension); OGC_CPY_TO_BUF( buf_hdr ); if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 ) { for (int i = 0; i < id_count(); i++) { rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX); OGC_ADD_TO_BUF( buf_id ); if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) break; } } OGC_CPY_TO_BUF( cls ); if ( (options & OGC_WKT_OPT_INTERNAL) == 0 && (options & OGC_WKT_OPT_EXPAND) != 0 ) { rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen); } return rc; }
bool ogc_geog3d_crs :: to_wkt( char buffer[], int options, size_t buflen) const { OGC_UTF8_NAME buf_name; OGC_TBUF buf_hdr; OGC_TBUF buf_datum; OGC_TBUF buf_primem; OGC_TBUF buf_cs; OGC_TBUF buf_axis_1; OGC_TBUF buf_axis_2; OGC_TBUF buf_axis_3; OGC_TBUF buf_unit; OGC_TBUF buf_extent; OGC_TBUF buf_id; OGC_TBUF buf_remark; int opts = (options | OGC_WKT_OPT_INTERNAL); size_t len = 0; bool rc = true; const char * opn = "["; const char * cls = "]"; const char * kwd = obj_kwd(); if ( (options & OGC_WKT_OPT_PARENS) != 0 ) { opn = "("; cls = ")"; } if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 ) opts |= OGC_WKT_OPT_NO_IDS; if ( buffer == OGC_NULL ) return false; *buffer = 0; if ( (opts & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) return true; rc &= ogc_geodetic_datum :: to_wkt(_datum, buf_datum, opts, OGC_TBUF_MAX); rc &= ogc_primem :: to_wkt(_primem, buf_primem, opts, OGC_TBUF_MAX); rc &= ogc_cs :: to_wkt(_cs, buf_cs, opts, OGC_TBUF_MAX); rc &= ogc_axis :: to_wkt(_axis_1, buf_axis_1, opts, OGC_TBUF_MAX); rc &= ogc_axis :: to_wkt(_axis_2, buf_axis_2, opts, OGC_TBUF_MAX); rc &= ogc_axis :: to_wkt(_axis_3, buf_axis_3, opts, OGC_TBUF_MAX); rc &= ogc_unit :: to_wkt(_unit, buf_unit, opts, OGC_TBUF_MAX); rc &= ogc_remark :: to_wkt(_remark, buf_remark, opts, OGC_TBUF_MAX); ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX); sprintf(buf_hdr, "%s%s\"%s\"", kwd, opn, buf_name); OGC_CPY_TO_BUF( buf_hdr ); OGC_ADD_TO_BUF( buf_datum ); OGC_ADD_TO_BUF( buf_primem ); OGC_ADD_TO_BUF( buf_cs ); OGC_ADD_TO_BUF( buf_axis_1 ); OGC_ADD_TO_BUF( buf_axis_2 ); OGC_ADD_TO_BUF( buf_axis_3 ); OGC_ADD_TO_BUF( buf_unit ); if ( _extents != OGC_NULL && (options & OGC_WKT_OPT_OLD_SYNTAX) == 0 ) { for (int i = 0; i < extent_count(); i++) { rc &= ogc_extent :: to_wkt(extent(i), buf_extent, opts, OGC_TBUF_MAX); OGC_ADD_TO_BUF( buf_extent ); } } if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 ) { for (int i = 0; i < id_count(); i++) { rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX); OGC_ADD_TO_BUF( buf_id ); } } OGC_ADD_TO_BUF( buf_remark ); OGC_CPY_TO_BUF( cls ); if ( (options & OGC_WKT_OPT_INTERNAL) == 0 && (options & OGC_WKT_OPT_EXPAND) != 0 ) { rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen); } return rc; }
bool ogc_unit :: to_wkt( char buffer[], int options, size_t buflen) const { OGC_UTF8_NAME buf_name; OGC_TBUF buf_hdr; OGC_TBUF buf_id; OGC_NBUF buf_factor; int opts = (options | OGC_WKT_OPT_INTERNAL); size_t len = 0; bool rc = true; const char * opn = "["; const char * cls = "]"; const char * kwd = obj_kwd(); if ( (options & OGC_WKT_OPT_PARENS) != 0 ) { opn = "("; cls = ")"; } if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 ) opts |= OGC_WKT_OPT_NO_IDS; if ( buffer == OGC_NULL ) return false; *buffer = 0; if ( !is_visible() ) return true; ogc_string :: dtoa(_factor, buf_factor); if ( (options & OGC_WKT_OPT_OLD_SYNTAX) == 0 ) { switch (_unit_type) { case OGC_UNIT_TYPE_ANGLE: kwd = ogc_angunit ::obj_kwd(); break; case OGC_UNIT_TYPE_LENGTH: kwd = ogc_lenunit ::obj_kwd(); break; case OGC_UNIT_TYPE_PARAM: kwd = ogc_paramunit::obj_kwd(); break; case OGC_UNIT_TYPE_SCALE: kwd = ogc_scaleunit::obj_kwd(); break; case OGC_UNIT_TYPE_TIME: kwd = ogc_timeunit ::obj_kwd(); break; default: break; } } ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX); sprintf(buf_hdr, "%s%s\"%s\",%s", kwd, opn, buf_name, buf_factor); OGC_CPY_TO_BUF( buf_hdr ); if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 ) { for (int i = 0; i < id_count(); i++) { rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX); OGC_ADD_TO_BUF( buf_id ); if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) break; } } OGC_CPY_TO_BUF( cls ); if ( (options & OGC_WKT_OPT_INTERNAL) == 0 && (options & OGC_WKT_OPT_EXPAND) != 0 ) { rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen); } return rc; }
void PepNovoOutfile::load( const std::string & result_filename, vector<PeptideIdentification> & peptide_identifications, ProteinIdentification & protein_identification, const double & score_threshold, const IndexPosMappingType & index_to_precursor, const map<String, String> & pnovo_modkey_to_mod_id ) { // generally used variables StringList substrings; map<String, Int> columns; PeptideHit peptide_hit; String line, score_type = "PepNovo", version = "unknown", identifier, filename, sequence, sequence_with_mods; DateTime datetime = DateTime::now(); // there's no date given from PepNovo protein_identification.setDateTime(datetime); peptide_identifications.clear(); PeptideIdentification peptide_identification; protein_identification = ProteinIdentification(); // open the result ifstream result_file(result_filename.c_str()); if (!result_file) { throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, result_filename); } Size line_number(0); // used to report in which line an error occurred Size id_count(0); // number of IDs seen (not necessarily the ones finally returned) getSearchEngineAndVersion(result_filename, protein_identification); //if information could not be retrieved from the outfile use defaults if (protein_identification.getSearchEngineVersion().empty()) { protein_identification.setSearchEngine("PepNovo"); protein_identification.setSearchEngineVersion(version); } identifier = protein_identification.getSearchEngine() + "_" + datetime.getDate(); protein_identification.setIdentifier(identifier); map<String, String> mod_mask_map; const vector<String> & mods = protein_identification.getSearchParameters().variable_modifications; for (vector<String>::const_iterator mod_it = mods.begin(); mod_it != mods.end(); ++mod_it) { if (mod_it->empty()) continue; //cout<<*mod_it<<endl; if (pnovo_modkey_to_mod_id.find(*mod_it) != pnovo_modkey_to_mod_id.end()) { //cout<<keys_to_id.find(*mod_it)->second<<endl; ResidueModification tmp_mod = ModificationsDB::getInstance()->getModification(pnovo_modkey_to_mod_id.find(*mod_it)->second); if (mod_it->prefix(1) == "^" || mod_it->prefix(1) == "$") { mod_mask_map[*mod_it] = "(" + tmp_mod.getId() + ")"; } else { mod_mask_map[*mod_it] = String(tmp_mod.getOrigin()) + "(" + tmp_mod.getId() + ")"; } } else { if (mod_it->prefix(1) != "^" && mod_it->prefix(1) != "$") { mod_mask_map[*mod_it] = mod_it->prefix(1) + "[" + mod_it->substr(1) + "]"; //cout<<mod_mask_map[*mod_it]<<endl; } else { mod_mask_map[*mod_it] = "[" + *mod_it + "]"; //cout<<mod_mask_map[*mod_it]<<endl; } } } Size index; while (getline(result_file, line)) { if (!line.empty() && (line[line.length() - 1] < 33)) line.resize(line.length() - 1); // remove weird EOL character line.trim(); ++line_number; if (line.hasPrefix(">> ")) // >> 1 /home/shared/pepnovo/4611_raw_ms2_picked.mzXML.1001.2.dta { ++id_count; if (!peptide_identification.empty() && !peptide_identification.getHits().empty()) { peptide_identifications.push_back(peptide_identification); } line.split(' ', substrings); //String index = File::basename(line.substr(line.find(' ', strlen(">> ")) + 1)); if (substrings.size() < 3) { throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Not enough columns (spectrum Id) in file in line " + String(line_number) + String(" (should be 2 or more)!"), result_filename); } try { index = substrings[2].trim().toInt(); } catch (...) { throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Expected an index number in line " + String(line_number) + String(" at position 2 (line was: '" + line + "')!"), result_filename); } //cout<<"INDEX: "<<index<<endl; peptide_identification = PeptideIdentification(); bool success = false; if (index_to_precursor.size()>0) { if (index_to_precursor.find(index) != index_to_precursor.end()) { peptide_identification.setRT(index_to_precursor.find(index)->second.first); peptide_identification.setMZ(index_to_precursor.find(index)->second.second); success = true; } else throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Index '" + String(index) + String("' in line '" + line + "' not found in index table (line was: '" + line + "')!"), result_filename); } if (!success) { // try to reconstruct from title entry (usually sensible when MGF is supplied to PepNovo) try { if (substrings.size() >= 4) { StringList parts = ListUtils::create<String>(substrings[3], '_'); if (parts.size() >= 2) { peptide_identification.setRT(parts[1].toDouble()); peptide_identification.setMZ(parts[0].toDouble()); success = true; } } } catch (...) { } if (!success) throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Precursor could not be reconstructed from title '" + substrings[3] + String("' in line '" + line + "' (line was: '" + line + "')!"), result_filename); } peptide_identification.setSignificanceThreshold(score_threshold); peptide_identification.setScoreType(score_type); peptide_identification.setIdentifier(identifier); } else if (line.hasPrefix("#Index")) // #Index Prob Score N-mass C-Mass [M+H] Charge Sequence { if (columns.empty()) // map the column names to their column number { line.split('\t', substrings); for (vector<String>::const_iterator s_i = substrings.begin(); s_i != substrings.end(); ++s_i) { if ((*s_i) == "#Index") columns["Index"] = s_i - substrings.begin(); else if ((*s_i) == "RnkScr") columns["RnkScr"] = s_i - substrings.begin(); else if ((*s_i) == "PnvScr") columns["PnvScr"] = s_i - substrings.begin(); else if ((*s_i) == "N-Gap") columns["N-Gap"] = s_i - substrings.begin(); else if ((*s_i) == "C-Gap") columns["C-Gap"] = s_i - substrings.begin(); else if ((*s_i) == "[M+H]") columns["[M+H]"] = s_i - substrings.begin(); else if ((*s_i) == "Charge") columns["Charge"] = s_i - substrings.begin(); else if ((*s_i) == "Sequence") columns["Sequence"] = s_i - substrings.begin(); } if (columns.size() != 8) { result_file.close(); result_file.clear(); throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Not enough columns in file in line " + String(line_number) + String(" (should be 8)!"), result_filename); } } while (getline(result_file, line)) { ++line_number; if (!line.empty() && (line[line.length() - 1] < 33)) line.resize(line.length() - 1); line.trim(); if (line.empty()) break; line.split('\t', substrings); if (!substrings.empty()) { if (substrings.size() != 8) { result_file.close(); result_file.clear(); throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Not enough columns in file in line " + String(line_number) + String(" (should be 8)!"), result_filename); } if (substrings[columns["RnkScr"]].toFloat() >= score_threshold) { peptide_hit = PeptideHit(); peptide_hit.setCharge(substrings[columns["Charge"]].toInt()); peptide_hit.setRank(substrings[columns["Index"]].toInt() + 1); peptide_hit.setScore(substrings[columns["RnkScr"]].toFloat()); peptide_hit.setMetaValue("PnvScr", substrings[columns["PnvScr"]].toFloat()); peptide_hit.setMetaValue("N-Gap", substrings[columns["N-Gap"]].toFloat()); peptide_hit.setMetaValue("C-Gap", substrings[columns["C-Gap"]].toFloat()); peptide_hit.setMetaValue("MZ", substrings[columns["[M+H]"]].toFloat()); sequence = substrings[columns["Sequence"]]; for (map<String, String>::iterator mask_it = mod_mask_map.begin(); mask_it != mod_mask_map.end(); ++mask_it) { if (mask_it->first.hasPrefix("^") && sequence.hasSubstring(mask_it->first)) { sequence.substitute(mask_it->first, ""); sequence = mask_it->second + sequence; } //cout<<mask_it->first<<" "<<mask_it->second<<endl; sequence.substitute(mask_it->first, mask_it->second); } peptide_hit.setSequence(AASequence::fromString(sequence)); peptide_identification.insertHit(peptide_hit); } } } } } if (!peptide_identifications.empty() || !peptide_identification.getHits().empty()) { peptide_identifications.push_back(peptide_identification); } result_file.close(); result_file.clear(); LOG_INFO << "Parsed " << id_count << " ids, retained " << peptide_identifications.size() << "." << std::endl; }
bool ogc_ellipsoid :: to_wkt( char buffer[], int options, size_t buflen) const { OGC_UTF8_NAME buf_name; OGC_TBUF buf_hdr; OGC_TBUF buf_lenunit; OGC_TBUF buf_id; OGC_NBUF buf_sm_axis; OGC_NBUF buf_flattening; int opts = (options | OGC_WKT_OPT_INTERNAL); size_t len = 0; bool rc = true; const char * opn = "["; const char * cls = "]"; const char * kwd = obj_kwd(); if ( (options & OGC_WKT_OPT_PARENS) != 0 ) { opn = "("; cls = ")"; } if ( (opts & OGC_WKT_OPT_TOP_ID_ONLY) != 0 ) opts |= OGC_WKT_OPT_NO_IDS; if ( buffer == OGC_NULL ) return false; *buffer = 0; if ( !is_visible() ) return true; if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) kwd = alt_kwd(); double flattening = _flattening; if ( flattening != 0.0 ) flattening = (1.0 / flattening); ogc_string :: dtoa(_semi_major_axis, buf_sm_axis); ogc_string :: dtoa( flattening, buf_flattening); if ( (options & OGC_WKT_OPT_OLD_SYNTAX) == 0 ) rc &= ogc_lenunit :: to_wkt(_lenunit, buf_lenunit, opts, OGC_TBUF_MAX); else *buf_lenunit = 0; ogc_string::escape_str(buf_name, _name, OGC_UTF8_NAME_MAX); sprintf(buf_hdr, "%s%s\"%s\",%s,%s", kwd, opn, buf_name, buf_sm_axis, buf_flattening); OGC_CPY_TO_BUF( buf_hdr ); OGC_ADD_TO_BUF( buf_lenunit ); if ( _ids != OGC_NULL && (options & OGC_WKT_OPT_NO_IDS) == 0 ) { for (int i = 0; i < id_count(); i++) { rc &= ogc_id :: to_wkt(id(i), buf_id, opts, OGC_TBUF_MAX); OGC_ADD_TO_BUF( buf_id ); if ( (options & OGC_WKT_OPT_OLD_SYNTAX) != 0 ) break; } } OGC_CPY_TO_BUF( cls ); if ( (options & OGC_WKT_OPT_INTERNAL) == 0 && (options & OGC_WKT_OPT_EXPAND) != 0 ) { rc &= ogc_utils :: expand_wkt(buffer, buffer, "", options, buflen); } return rc; }