-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·154 lines (120 loc) · 5.81 KB
/
main.py
File metadata and controls
executable file
·154 lines (120 loc) · 5.81 KB
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
from flask import Flask, render_template, request, jsonify
from dataset import *
from thym import *
from thca import *
from lihc import *
import json
import subprocess as sp
# ***** SETTINGS *****
if not os.path.isdir('datasetTCGA'):
os.makedirs('datasetTCGA')
def emptyCache():
# svuoto la cartella tempAnalysis
filelist = [f for f in os.listdir('static/tempAnalysis')]
for f in filelist:
os.remove(os.path.join('static/tempAnalysis', f))
if not os.path.isdir('static/tempAnalysis'):
os.makedirs('static/tempAnalysis')
else:
emptyCache()
app = Flask(__name__)
# ***** INDEX *****
@app.route('/')
def index():
return render_template('index.html')
# ***** BIOMARKERS *****
@app.route('/biomarkers')
def biomarkers():
#emptyCache()
return render_template('biomarkers.html')
# ***** MITHrIL *****
@app.route('/MITHrIL')
def mithril():
return render_template('MITHrIL.html')
# ***** DOWNLOADER *****
@app.route('/downloader', methods=['POST'])
def process():
typeTumor = request.form['typeTumor']
biocli = request.form['biocli']
rnaseq = request.form['rnaseq']
mirnaseq = request.form['mirnaseq']
if typeTumor and biocli and rnaseq and mirnaseq:
mess = downloadData(typeTumor, biocli, rnaseq, mirnaseq)
return jsonify({'status': 1, 'type': 'success', 'mess': ''})
return jsonify({'status': 0, 'type': 'error', 'mess': 'Missing data!'})
# ***** ANALYSIS BIOMARKERS *****
@app.route('/analysisBiomarkers', methods=['POST'])
def process2():
nameTumor = request.form['tumor']
idxAnalysis = request.form['idxAnalysis']
file_miRNA = request.form['file_miRNA']
file_RNA = request.form['file_RNA']
pvalue = request.form['pvalue']
foldchange = request.form['foldchange']
contrasts = request.form['contrasts']
geneSelected = request.form['geneSelected']
if nameTumor and idxAnalysis and file_miRNA and file_RNA and pvalue and foldchange and contrasts:
if nameTumor == 'THYM':
htmlListGenes, htmlAllGenes, nGenes, emptyDF = analysisTHYM(idxAnalysis, file_miRNA, file_RNA, pvalue, foldchange, contrasts, geneSelected)
elif nameTumor == 'THCA':
htmlListGenes, htmlAllGenes, nGenes, emptyDF = analysisTHCA(idxAnalysis, file_miRNA, file_RNA, pvalue, foldchange, contrasts, geneSelected)
elif nameTumor == 'LIHC':
htmlListGenes, htmlAllGenes, nGenes, emptyDF = analysisLIHC(idxAnalysis, file_miRNA, file_RNA, pvalue, foldchange, contrasts, geneSelected)
return jsonify({'status': 1, 'type': 'success', 'listGene': htmlListGenes, 'AllListGene': htmlAllGenes, 'nGenes': nGenes, 'emptyDF': emptyDF})
return jsonify({'status': 0, 'type': 'error', 'mess': 'Missing data!'})
# ***** ANALYSIS MITHRIL *****
@app.route('/analysisMithril', methods=['POST'])
def process3():
pathtempAnalysis = 'static/tempAnalysis/'
inputFileName = request.form['fileName']
outPertubationsName = pathtempAnalysis + request.form['outPertubationsName']
outMainFile = pathtempAnalysis + request.form['outMainFile']
rootDir = os.getcwd() + os.sep
jsonHTML1 = []
jsonHTML2 = []
if inputFileName:
if os.path.exists(pathtempAnalysis + inputFileName):
try:
sp.call(['java', '-jar', rootDir + 'library/java/MITHrIL2.jar', 'merged-mithril', '-verbose', '-i',
pathtempAnalysis + inputFileName, '-o', outMainFile, '-p', outPertubationsName])
with open(rootDir + outMainFile, "r") as f:
next(f)
for rows in f:
row = rows.split("\t")
jsonTMP = {}
jsonTMP['PathwayId'] = row[0]
jsonTMP['PathwayName'] = row[1]
jsonTMP['RawAccumulator'] = row[2]
jsonTMP['ImpactFactor'] = row[3]
jsonTMP['probability_pi'] = row[4]
jsonTMP['total_perturbation'] = row[5]
jsonTMP['corrected_accumulator'] = row[6]
jsonTMP['pValue'] = row[7]
jsonTMP['adjusted_pValue'] = row[8]
jsonHTML1.append(jsonTMP)
with open(pathtempAnalysis + 'mithril_output.json', 'w') as outfile:
json.dump(jsonHTML1, outfile)
with open(rootDir + outPertubationsName, "r") as f:
next(f)
for rows in f:
row = rows.split("\t")
jsonTMP2 = {}
jsonTMP2['PathwayId'] = row[0]
jsonTMP2['PathwayName'] = row[1]
jsonTMP2['GeneId'] = row[2]
jsonTMP2['GeneName'] = row[3]
jsonTMP2['perturbation'] = row[4]
jsonTMP2['accumulator'] = row[5]
jsonTMP2['pValue'] = row[6]
jsonHTML2.append(jsonTMP2)
with open(pathtempAnalysis + 'mithril_pertubation.json', 'w') as outfile:
json.dump(jsonHTML2, outfile)
return jsonify({'status': 1, 'type': 'success', 'mess': 'I file output di <b>MITHrIL</b>, sono stati generati con successo!'})
except:
return jsonify({'status': 0, 'type': 'error', 'mess': 'Si è verificato un problema durante l\'esecuzione del jar'})
else:
return jsonify({'status': 0, 'type': 'error', 'mess': 'Il file di input non è stato trovato, potrebbe non essere stato generato!'})
else:
return jsonify({'status': 0, 'type': 'error', 'mess': 'Si è verificato un problema durante l\'esecuzione!'})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=2892, debug=True)