-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNAcalc2.py
executable file
·47 lines (34 loc) · 1.05 KB
/
DNAcalc2.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
#!/usr/bin/env python3
import argparse
from Bio import SeqIO
#DNA GC content calculator
#Handle command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("-i", help="Input file")
args = parser.parse_args()
#Put the -i argument in InFile
InFile = args.i
#Open the InFile
try:
IN=open(InFile, 'r')
except IOError:
print ("Can't open file: %s." %(InFile))
#Old code for reading file one line at a time.
#for Line in IN:
# Line=Line.strip('\n')
#New code to use BioPython to read a fasta file
for Record in SeqIO.parse(IN, "fasta") :
DNAseq=Record.seq
GC_count=0
#Get Length of sequence
SeqLength=len(DNAseq)
#Go through each base
for Base in ('A','G','T','C', 'S', 'N'):
#Count the number of times the base occurs
NumBase=DNAseq.count(Base)
#print("Percent %s: %.2f" %(Base,NumBase/SeqLength*100))
if Base == "G" or Base == "C" or Base == "S":
GC_count+=NumBase
#End of for Base in loop.
print ("GC content of %s is %.2f" %(Record.id, GC_count/SeqLength*100))
#End for Record in loop.