Skip to content

Commit 53336c4

Browse files
committed
Update for MSc course
1 parent 7ec6636 commit 53336c4

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

Files/dna.fa

Whitespace-only changes.

Intro-to-Python/pythonscripts.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
def get_genes(infile,outfile):
2+
"""
3+
Function to extract a list of genes and write to file
4+
"""
5+
gene_list = []
6+
with open(infile) as gene:
7+
tag = False
8+
for line in gene:
9+
if line.startswith('name'):
10+
tag = True
11+
pass
12+
if tag:
13+
items = line.split()
14+
if len(items) > 0:
15+
gene_list.append(items[0])
16+
gene_list = gene_list[1:-7]
17+
with open(outfile, 'w') as outfile:
18+
for i in gene_list:
19+
outfile.write(i+'\n')
20+
21+
22+
def dnatest(dnaseq):
23+
testdna =[]
24+
dna = dnaseq.upper()
25+
for i in dna:
26+
result = str(i) in ['T', 'A', 'G', 'C']
27+
testdna.append(result)
28+
if testdna.count(False) > 0:
29+
return False
30+
else:
31+
return True
32+
33+
def dnaTest(x):
34+
dnaset = set("AGCT")
35+
y = set(x.upper()).union(dnaset) == dnaset
36+
return y
37+
38+
def percentGC(dna):
39+
'''calculates the percentage GC content, given a DNA sequence'''
40+
if dnacheck(dna):
41+
dna_len= len(dna)
42+
gs = dna.count('G')
43+
cs = dna.count('C')
44+
45+
return (gs+cs)/dna_len*100
46+
47+
#print("The sequence input is not a valid DNA")
48+
49+
def dnacheck(dna):
50+
counter = 0
51+
check = True
52+
valid_dna = 'ACGT'
53+
for i in dna.upper():
54+
counter += 1
55+
if i in valid_dna:
56+
pass
57+
else:
58+
check = False
59+
print("There is an invalid base '%s' at position %d"
60+
% (i,counter))
61+
return check
62+
63+
dna = 'ACZGTCYTTgZCABG'
64+
dnacheck(dna)
65+
dnaseq ='acgtaaqat'
66+
dnatest(dnaseq)

0 commit comments

Comments
 (0)