Commit a63ba85a authored by Mathieu Giraud's avatar Mathieu Giraud

core/tools.{h,cpp}: nuc_to_AA

Finally Vidjil learns the genetic code.
parent cde2c1df
......@@ -136,6 +136,26 @@ int dna_to_int(const string &word, int size) {
return index_word;
}
string nuc_to_aa(const string &word) {
string aa;
int index_word = 0;
int i = 0;
for (; i < word.length() ; i++) {
index_word = (index_word << 2) | nuc_to_int(word[i]);
if (i % 3 == 2) {
aa += GENETIC_CODE[index_word];
index_word = 0 ;
}
}
if (i % 3)
aa += GENETIC_CODE_OUT_OF_FRAME ;
return aa;
}
Sequence create_sequence(string label_full, string label, string sequence, string quality) {
Sequence seq;
seq.label_full = label_full;
......
......@@ -126,6 +126,19 @@ inline int nuc_to_int(char nuc) {
*/
int dna_to_int(const string &, int size);
#define GENETIC_CODE \
"KNKN" "TTTT" "RSRS" "IIMI" \
"QHQH" "PPPP" "RRRR" "LLLL" \
"EDED" "AAAA" "GGGG" "VVVV" \
"*Y*Y" "SSSS" "*CWC" "LFLF"
#define GENETIC_CODE_OUT_OF_FRAME '#'
/**
* Convert nucleotides to amino acids
*/
string nuc_to_aa(const string &nuc);
string extract_from_label(string str, int field, string separator);
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment