Skip to content

Instantly share code, notes, and snippets.

@odeblic
Created July 29, 2017 00:43
Show Gist options
  • Save odeblic/ea4571afb68a1eb851cebf519f63d930 to your computer and use it in GitHub Desktop.
Save odeblic/ea4571afb68a1eb851cebf519f63d930 to your computer and use it in GitHub Desktop.
DNA encoding and decoding
#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