-
Notifications
You must be signed in to change notification settings - Fork 2
/
basePairComposition.py
52 lines (41 loc) · 1.19 KB
/
basePairComposition.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
##################################
# #
# Last modified 05/25/2011 #
# #
# Georgi Marinov #
# #
##################################
import sys
import string
def main(argv):
if len(argv) < 2:
print 'usage: python %s inputfastafilename outfilename' % argv[0]
sys.exit(1)
fastafilename = argv[1]
outfilename = argv[2]
outfile = open(outfilename, 'w')
A=0.0
C=0.0
T=0.0
G=0.0
listoflines = open(fastafilename)
for line in listoflines:
if line.startswith('>'):
continue
sequence=line.strip()
sequence=sequence.upper()
A+=sequence.count('A')
C+=sequence.count('C')
T+=sequence.count('T')
G+=sequence.count('G')
outline='A' + '\t' + str(A/(A+C+T+G))+'\n'
outfile.write(outline)
outline='C' + '\t' + str(C/(A+C+T+G))+'\n'
outfile.write(outline)
outline='T' + '\t' + str(T/(A+C+T+G))+'\n'
outfile.write(outline)
outline='G' + '\t' + str(G/(A+C+T+G))+'\n'
outfile.write(outline)
outfile.close()
if __name__ == '__main__':
main(sys.argv)