-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGC.py
42 lines (31 loc) · 1.11 KB
/
GC.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
# count the GC content in a fasta file
from Bio import SeqIO
import argparse
# get all fasta files created and read it as a dictionary list
import os
files = {}
for filename in os.listdir():
if os.path.isfile(filename) \
and filename.startswith("Rosalind") \
and not filename in files:
with open(filename, "r") as file:
files[filename] = file.read().rstrip("\n")
#remove the first line of each DNA file and print it
sequences = {}
for filename, text in files.items():
text = text.split("\n",1)[1]
sequences[filename] = text
GC = {} # create an empty dictionary to store GC values
#create a new dictionary with the proportions for each GC
for filename,text in sequences.items():
total = int(len(text))
c = text.count("C")
g = text.count("G")
gc_total = c + g
gc_content = gc_total/total
GC[filename] = round(gc_content*100,6)
#get larger value of GC content
max_value = max(GC.values()) # maximum value
max_keys = [k for k, v in GC.items() if v == max_value] # getting all keys containing the `maximum`
print(GC)
print(*max_keys,'\n', max_value) # print answer