-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculateGenomeGCcontent.py
46 lines (37 loc) · 1.1 KB
/
calculateGenomeGCcontent.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
##################################
# #
# Last modified 6/9/2009 #
# #
# Georgi Marinov #
# #
##################################
import sys
import os
import string
def main(argv):
if len(argv) < 3:
print 'usage: python %s genome_directory outfilename' % argv[0]
sys.exit(1)
directory = argv[1]
outfilename = argv[2]
outfile = open(outfilename, 'w')
files = os.listdir(directory)
for filename in files:
length=0.0
GC=0.0
file=open(direcotry+'/'+filename)
listlines=file.readlines()
for line in listlines:
line=string.upper(line.strip())
length=length+len(line)
G=line.split('G')
C=line.split('C')
GC=GC+len(G)-1+len(C)-1
print 'chromosomelength= ', length
k=GC/length
print 'GC%= ', k
outline=filename+': GC%= '+str(k) + '\n'
outfile.write('outline')
outfile.close()
if __name__ == '__main__':
main(sys.argv)