-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.py
51 lines (48 loc) · 1.96 KB
/
day6.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
output = []
def codons(gg,i):
global output
codonFull = []
codonInProduction = []
h = list(gg[i].replace("-","").upper())
for i in range(0,(len(h))):
if(i%3 == 2):
codonInProduction += [h[i]]
codonFull += ["".join(codonInProduction)]
codonInProduction = []
else:
codonInProduction += [h[i]]
output += ["Codons List: %s \n" % (str(codonFull))]
return codonFull
def isProtein(codonFull):
global output
if(codonFull[0] == "ATG" and ((codonFull[len(codonFull)-1]) == "TAA" or codonFull[len(codonFull)-1] == "TAG" or codonFull[len(codonFull)-1] == "TGA")) :
output += ["Is Protein?: YES \n"]
else:
output += ["Is Protein?: NO \n"]
def dna():
#VARIABLES AND FUNCTIONS
global output
output = []
inputFile = raw_input("DISH DAT INPUT FILE BRAHHHHHHHHHHHHH! \n - VIVIAN, brothority\nInput File: ")
outputFile = raw_input("Can you please give me a location to output your results? \n Thank you! \n - David Silverman (dsilvs)\nOutput File: ")
f = open(inputFile).readlines()
#f.split("\n")
g = [item.replace("\n","") for item in f]
#print g
for i in range(0,len(g)):
if(i%2==0):
output += ["Region Name: %s \n" % (g[i])]
else:
output += ["Nucleotides: %s \n" % (g[i].replace("-","").upper())]
output += ["Nuc. Counts: %s \n" % (str([g[i].upper().count("A"),g[i].upper().count("C"),g[i].upper().count("G"),g[i].upper().count("T")]))]
totalMass = [float(g[i].upper().count("A")*135.128),float(g[i].upper().count("C")*111.103),float(g[i].upper().count("G")*151.128),float(g[i].upper().count("T")*125.107),float(g[i].count("-")*100.000)]
output += ["Total Mass%: [{0:.2f},{1:.2f},{2:.2f},{3:.2f}] of {4:.2f} \n".format((totalMass[0]/float(sum(totalMass)))*100,(totalMass[1]/float(sum(totalMass)))*100,(totalMass[2]/float(sum(totalMass)))*100,(totalMass[3]/float(sum(totalMass)))*100,float(sum(totalMass)))]
codonFull = codons(g,i)
output += ["\n"]
#ACGT
i += 1
with open(outputFile, "w'") as s:
s.writelines(output)
return output
output = g
dna()