-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCcalc.py
More file actions
42 lines (29 loc) · 804 Bytes
/
GCcalc.py
File metadata and controls
42 lines (29 loc) · 804 Bytes
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
#!/usr/bin/env python3
from Bio import SeqIO
import sys
#DNA GC content calculator
def countItems(Item,Seq):
ItemCount=Seq.count(Item)
return(ItemCount)
def GC(DNAseq):
GC_count=0
SeqLength=len(DNAseq)
for Base in ('A','G','T','C', 'S', 'N'):
#Count the number of times the base occurs
NumBase=countItems(Base, DNAseq)
if Base == "G" or Base == "C" or Base == "S":
GC_count+=NumBase
#End of for Base in loop.
return(GC_count/SeqLength*100)
def main():
InFile=sys.argv[1]
try:
IN=open(InFile, 'r')
except IOError:
print ("Can't open file: %s." %(InFile))
for Record in SeqIO.parse(IN, "fasta") :
DNAseq=Record.seq
MyGC=GC(DNAseq)
print ("GC content of %s is %.2f" %(Record.id, MyGC))
if __name__ == "__main__":
main()