-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtraModules.py
66 lines (59 loc) · 1.78 KB
/
ExtraModules.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
#global variables
diffEncDict = {'A' : ['C','G','T'] ,'C' : ['G','T','A'] ,'G' : ['T','A','C'] ,'T':['A','C','G'] }
complementDictionary = {'A':'T','T':'A','C':'G','G':'C'}
# Uses differential encoding
# Input : base 3 number
# Output A,T,C,G
def diffEncode(prevBase,currTrit):
global diffEncDict
currBase = diffEncDict[prevBase][int(currTrit)]
return currBase
# differentialy encode whole string
# Input : trit string
# Output : Corresponding DNA Sequence
def encodeSTR(string1,prevBase):
finalDNAString = []
for trit in string1:
currBase = diffEncode(prevBase,trit)
finalDNAString.append(currBase)
prevBase = currBase
return ''.join(finalDNAString)
# converts decimal to base 3 string
# Input: A decimal that is base 10 number
# Output: Base 3 Numerical String of length equal to lengthOfOut
def intToBase3(num,lengthOfOut):
output = ''
for i in range(1,lengthOfOut+1):
output = str((num%3)) + output
num = num/3
return output
# Converts base 3 number to decimal number
def base3ToInt(tritString):
num = 0
for trit in tritString:
num = (num*3) + int(trit)
return num
# Converts base b number to decimal number
def base256ToInt(byteList):
num = 0
mul1 = 1
for byte in byteList:
num = num + byte*mul1
mul1=mul1*256
return num
# Reverse complements the DNA Chunk
def reverseComplement(dnaStr):
global complementDictionary
outputStr = []
i = len(dnaStr) - 1
while i>=0 :
outputStr.append(complementDictionary[dnaStr[i]])
i = i - 1
return ''.join(outputStr)
# converts DNA string to trits using differential decoding
def getTrits(dnaStr,prevBase):
output = []
for base in dnaStr:
output.append(str(diffEncDict[prevBase].index(base)))
prevBase = base
return ''.join(output)