forked from SBNoor/fNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.py
177 lines (144 loc) · 4.65 KB
/
tool.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created by Bakhtawar Noor and Judit Kisistók
Aarhus University, 2018
"""
import argparse
import ThreeStateGenerator as tsg
import parse
import os
from sklearn.utils import class_weight
from keras.models import Sequential
from keras.layers import Dense, Flatten
import numpy as np
import matplotlib.pyplot as plt
from keras import regularizers
import math
from sklearn.model_selection import KFold
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split, GridSearchCV
from keras import regularizers
from keras.layers import Dropout
from numpy import array
from sklearn.metrics import confusion_matrix
import jnn
import os
import jsnn
import parse
import mnn
import snn
def check(content):
flag = 0
for i in range(len(content)):
if content[i][0] == '>':
flag += 1
return flag
def main():
file_name = []
file = []
flag = 0
parser = argparse.ArgumentParser()
#group = parser.add_mutually_exclusive_group()
parser.add_argument('file', type=argparse.FileType('r'))
#parser.add_argument('file_msa', type=argparse.FileType('r'))
parser.add_argument('--jNN','-j',help='Runs simple NN')
parser.add_argument('--msa','-js',help = "Runs NN based on majority vote")
parser.add_argument('--mNN','-m',help = "Runs cascaded NN")
parser.add_argument('--sNN','-s',help = "Runs convolutional NN")
parser.add_argument("--output", "-o", help="Output the result to a file", action="store_true")
args = parser.parse_args()
if args.file:
with args.file as f:
content = f.readlines()
flag = check(content)
if flag == 1:
a = ''
for line in content[1:]:
line = line.strip('\n')
a += line
file.append(a)
file_name.append(content[0])
print(file)
elif flag > 1:
file = parse.parse_msa_file(content)
print(file)
else:
pssm = parse.reading_pssm_files(content)
if args.jNN:
cm = jnn.jNN(file)
c = cm.replace(" ", "C")
if args.output:
f = open("prediction.txt","a")
f.write(">" + file_name[0]+ '\n')
f.write(str(c) + '\n')
f.close()
else:
print("Prediction : ")
print((c))
elif args.msa:
cm = jsnn.jNN_msa(file)
c = cm.replace(" ","C")
if args.output:
f = open("Prediction.txt","a")
f.write(">prediction")
f.write(str(c) + '\n')
f.close()
else:
print("Prediction : ")
print(c)
elif args.mNN:
cm = mnn.mNN(file)
c = cm.replace(" ","C")
if args.output:
f = open("Prediction.txt","a")
f.write(">prediction")
f.write(str(c) + '\n')
f.close()
else:
print("Prediction : ")
print(c)
elif args.sNN:
cm = snn.sNN(pssm)
c = cm.replace(" ","C")
if args.output:
f = open("Prediction.txt","a")
f.write(">prediction")
f.write(str(c) + '\n')
f.close()
else:
print("Prediction : ")
print(c)
else:
if flag == 1:
cm = jnn.jNN(file)
c = cm.replace(" ", "C")
if args.output:
f = open("prediction.txt","a")
f.write(">" + file_name[0]+ '\n')
f.write(str(c) + '\n')
f.close()
else:
print("Prediction : ")
print((c))
elif flag > 1:
cm = jsnn.jNN_msa(file)
c = cm.replace(" ","C")
if args.output:
f = open("Prediction.txt","a")
f.write(">prediction")
f.write(str(c) + '\n')
f.close()
else:
print("Prediction : ")
print(c)
if __name__ == '__main__':
print('\n')
print('\n')
print("##############################################################")
print("3-state protein secondary structure prediction tool.")
print("##############################################################")
print('\n')
print('\n')
main()