Created
August 20, 2015 23:00
-
-
Save nrshrivatsan/cd74afb8e47d891be9a5 to your computer and use it in GitHub Desktop.
A simple binary compression algorithm for ATGC sequence using python
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
""" | |
Name: Shrivats | |
Bit Compression of ATGC | |
""" | |
bit_seq = 0 | |
input_seq = 'ATGC' | |
input_seq+='GTAC' | |
# input sequence | |
def binary(input): | |
print '{0:08b}'.format(x) | |
x=0 | |
counter = 0 | |
binaryRep = [] | |
for code in input_seq: | |
print code | |
if 'A' is code: | |
x|=0 | |
elif 'T' is code: | |
x|=1 | |
elif 'G' is code: | |
x|=2 | |
elif 'C' is code: | |
x|=3 | |
counter+=1 | |
if counter < 4: | |
x = x << 2 | |
elif counter == 4: | |
binary(x) | |
binaryRep.append(x) | |
counter =0 | |
x = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment