-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisValidity.py
54 lines (40 loc) · 1.29 KB
/
isValidity.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
48
49
50
51
52
def runValidity():
nameFASTA = []
def readFASTA(fileName):
with open(fileName, 'r') as file:
v = []
genome = ''
for line in file:
if line[0] != '>':
genome += line.strip()
else:
nameFASTA.append(line.replace('\n', ''))
v.append(genome)
genome = ''
v.append(genome)
del v[0]
return v
def fetchX():
import os
this_folder = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(this_folder,'sample.txt')
X = readFASTA(filename)
return X
def isValid(x):
for base in x:
if not base in {'A' ,'C' ,'D' ,'E' ,'F' ,'G' ,'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'}:
return 'Invalid'
return 'Valid'
X_newbie = []
Y_newbie = []
X = fetchX()
Verdict = []
for x in X:
x = x.upper().replace(' ', '')
if isValid(x) == 'Invalid' or len(x)<16:
Verdict.append('Invalid FASTA')
else:
Verdict.append('Valid FASTA')
X_newbie.append(x)
Y_newbie.append(-100)
return X_newbie, Y_newbie, nameFASTA, Verdict