Gemmi C++ API
Loading...
Searching...
No Matches
seqtools.hpp
Go to the documentation of this file.
1// Copyright Global Phasing Ltd.
2//
3// Functions for working with sequences (other than alignment).
4
5#ifndef GEMMI_SEQTOOLS_HPP_
6#define GEMMI_SEQTOOLS_HPP_
7
8#include "resinfo.hpp" // for find_tabulated_residue
9#include "metadata.hpp" // for Entity::first_mon, PolymerType
10
11namespace gemmi {
12
13constexpr double h2o_weight() { return 2 * 1.00794 + 15.9994; }
14
15inline double calculate_sequence_weight(const std::vector<std::string>& seq,
16 double unknown=100.) {
17 double weight = 0.;
18 for (const std::string& item : seq) {
20 if (idx == 361)
21 weight += unknown;
22 else
23 weight += get_residue_info(idx).weight;
24 //ResidueInfo res_info = find_tabulated_residue(Entity::first_mon(item));
25 //weight += res_info.found() ? res_info.weight : unknown;
26 }
27 return weight - (seq.size() - 1) * h2o_weight();
28}
29
30inline std::string one_letter_code(const std::vector<std::string>& seq) {
31 std::string r;
32 for (const std::string& item : seq)
33 r += find_tabulated_residue(Entity::first_mon(item)).fasta_code();
34 return r;
35}
36
40inline std::string pdbx_one_letter_code(const std::vector<std::string>& seq,
41 ResidueKind kind) {
42 std::string r;
43 for (const std::string& item : seq) {
44 std::string code = Entity::first_mon(item);
46 if (ri.is_standard() && ri.kind == kind)
47 r += ri.one_letter_code;
48 else
49 cat_to(r, '(', code, ')');
50 }
51 return r;
52}
53
57 return ResidueKind::AA;
59 return ResidueKind::DNA;
61 return ResidueKind::RNA;
63 fail("sequence_kind(): unknown polymer type");
64 return ResidueKind::AA;
65}
66
67} // namespace gemmi
68#endif
Metadata from coordinate files.
ResidueKind sequence_kind(PolymerType ptype)
used with expand_one_letter_sequence()
Definition seqtools.hpp:55
std::string pdbx_one_letter_code(const std::vector< std::string > &seq, ResidueKind kind)
Returns the format used in _entity_poly.pdbx_seq_one_letter_code, in which non-standard amino acids/n...
Definition seqtools.hpp:40
bool is_polypeptide(PolymerType pt)
Definition metadata.hpp:231
GEMMI_DLL ResidueInfo & find_tabulated_residue(const std::string &name)
std::string one_letter_code(const std::vector< std::string > &seq)
Definition seqtools.hpp:30
GEMMI_DLL size_t find_tabulated_residue_idx(const std::string &name)
double calculate_sequence_weight(const std::vector< std::string > &seq, double unknown=100.)
Definition seqtools.hpp:15
void cat_to(std::string &)
Definition util.hpp:26
constexpr double h2o_weight()
Definition seqtools.hpp:13
GEMMI_DLL ResidueInfo & get_residue_info(size_t idx)
void fail(const std::string &msg)
Definition fail.hpp:59
ResidueKind
Definition resinfo.hpp:26
List of common residues with basic data.
static std::string first_mon(const std::string &mon_list)
Definition metadata.hpp:264