Created
July 29, 2017 00:43
-
-
Save odeblic/ea4571afb68a1eb851cebf519f63d930 to your computer and use it in GitHub Desktop.
DNA encoding and decoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct Wheel | |
{ | |
wheel(char initial_escape_symbol) : escape_id(0), left_id(1), right_id(2), switch_id(3) { while(symbols[escape_id] != esc) rotate(); } | |
void rotate() { escape_id++; left_id++; right_id++; switch_id++; } | |
char getEscapeSymbol() { return symbols[escape_id]; } | |
char getLeftSymbol() { return symbols[left_id]; } | |
char getRightSymbol() { return symbols[right_id]; } | |
char getSwitchSymbol() { return symbols[switch_id]; } | |
const char symbols[4] = "TAGA"; | |
char escape_id:2; | |
char left_id:2; | |
char right_id:2; | |
char switch_id:2; | |
}; | |
void multiplex(const std::string input, std::string& output, char marker, Wheel& wheel) | |
{ | |
int symbol_count = 0; | |
int switching_count = 0; | |
for(auto c : input) | |
{ | |
if(c == escape_symbol) | |
{ | |
output.append(1, c); | |
output.append(1, c); | |
switching++; | |
} | |
else | |
{ | |
output.append(1, c); | |
} | |
if(swiching > symbol_count+++5) | |
{ | |
wheel.rotate(); | |
} | |
} | |
} | |
std::string demultiplex(std::string input, Wheel& wheel) | |
{ | |
} | |
int main() | |
{ | |
std::string input = "ATATGCGCTCTATAGATCTGTATCGACTAGCGATCGCTAGCTAGCAAGCTATCGCTCGCGATAGTCGTAATGCAAGGCATCTCAGAGATATCGCG"; | |
std::string output; | |
int marker = 1; | |
Wheel wheel('T'); | |
multiplex("CATGCTAGTAGTCGC", output, 1, wheel); | |
multiplex("TCTCGATAATAACTGATAC", output, 2, wheel); | |
multiplex("AGTCTTGAC", output, 1, wheel); | |
multiplex("GATCGGTCTAGAAATCG", output, 2, wheel); | |
std::cout << "input:\t" << input << std::endl; | |
std::cout << "output:\t" << output << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment