aboutsummaryrefslogtreecommitdiffstats
path: root/cgi-bin/classifier.py
blob: ec2b634a57067288714f1ec14394b8376987dea6 (plain)
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
#!/usr/bin/python

#import packages to be used
from sklearn.svm import SVC
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.preprocessing import StandardScaler
from sklearn.externals import joblib
import cgi, cgitb

cgitb.enable()
form=cgi.FieldStorage()
if form.getvalue('fasta'):
	alignment = form.getvalue('fasta')
	alignment=[alignment]
	name=form.getvalue('seqname')
	size=len(alignment[0])
else:
	alignment = ["MPSKKSGPQPHKRWVFTLNNPSEEEKNKIRELPISLFDYFVCGEEGLEEGRTAHLQGFANFAKKQTFNKVKWYFGARCHIEKAKGTDQQNKEYCSKEGHILIECGAPRNQGKRSDLSTAYFDYQQSGPPGMVLLNCCPSCRSSLSEDYYFAILEDCWRTINGGTRRPI"]
	name='demo'
	size=len(alignment[0])
	
html = open("./www.html/CRESSresults.html")
page=html.read()


AAs=['a','c','d','e','f','g','h','i','k','l','m','n','p','q','r','s','t','v','w','y']
clf=joblib.load("./cgi-bin/SVM_linear_aa_clf.pkl")
StSc=joblib.load("./cgi-bin/UniqRepsGemys_6089_StSCALER.pkl")
cv=CountVectorizer(analyzer='char',ngram_range=(1,1),vocabulary=AAs)


#initialize text data vectorizer

dataVect=cv.transform(alignment)
 	
#Scale the data to the training set
X=StSc.transform(dataVect.astype("float64"))

#make predictions for the original dataset
results=",".join([name,clf.predict(X)[0]])
results=",".join([results,str(size)])
#for i in results:
	#print(i[0],"\t",i[1])

output = page.format(prediction=results)
"""f=open('test.html','w')
f.write(output)
f.close()"""
print (output)	

	
quit()