Skip to content

Instantly share code, notes, and snippets.

@nrshrivatsan
Created August 20, 2015 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrshrivatsan/cd74afb8e47d891be9a5 to your computer and use it in GitHub Desktop.
Save nrshrivatsan/cd74afb8e47d891be9a5 to your computer and use it in GitHub Desktop.
A simple binary compression algorithm for ATGC sequence using python
"""
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