-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoldmanEncoding.py
72 lines (61 loc) · 2.41 KB
/
GoldmanEncoding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
##########################################################################################
Improvised Version: DNA Cloud 3.14
Developers: Mihir Gohel, Natvar Prajapati, Shashank Upadhyay, Shivam Madlani, Vandan Bhuva
Mentor: Prof. Manish K Gupta
Website: www.guptalab.org/dnacloud
This file implements Goldman Encoding.
##########################################################################################
Author: Aayush Kapadia,Suparshva Mehta
Project: DNA Cloud 3
Graduate Mentor: Dixita Limbachya
Mentor: Prof. Manish K Gupta
Website: www.guptalab.org/dnacloud
##########################################################################################
"""
import huffman
import ChunkManager1
import ExtraModules
import io
import os
# Binary files to DNA String Convertor
# Input : fileName and fileID to be used
# Output : file converted to it's DNA string. To be later converted into chunks to get 4 fold redundancy
# Limitation: 3GB is the limitation
def file2DNA(fileName, fileId, signalStatus):
totalLen = 0
myFile = io.open(fileName, "rb")
outFile = io.open(fileName+'.dnac', "w")
outFile.write(" \n") # writing a blank line in .dnac file so that .seek() function does not over-write the DNA string while writing number of chunks
chunkManager = ChunkManager1.ChunkManager(outFile, fileId)
prevBase = 'A'
countOfBytes = 0
while True:
byte = myFile.read(1)
countOfBytes = countOfBytes + 1
global percentageCompleted
global fileLength
percentageCompleted = (countOfBytes*1.00/fileLength)*100
if countOfBytes % 1000 == 0:
signalStatus.emit(str(int(percentageCompleted)))
if (not byte):
break
tritString = str(huffman.encode(byte))
totalLen = totalLen + len(tritString)
dnaString = ExtraModules.encodeSTR(tritString, prevBase)
prevBase = dnaString[-1]
chunkManager.addString(dnaString)
S2 = ExtraModules.intToBase3(totalLen, 20)
currLen = 20 + totalLen
lenOfS3 = 25 - (currLen % 25)
S3 = '0'*lenOfS3
dnaString1 = ExtraModules.encodeSTR(S3+S2, prevBase)
chunkManager.addString(dnaString1)
chunkManager.close()
signalStatus.emit('100')
def encodeFile(str1, signalStatus):
global fileLength
fileLength = os.path.getsize(str1)
file2DNA(str1, '10', signalStatus)
fileLength = 0
percentageCompleted = 0