forked from CBIIT/ldsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (58 loc) · 2.19 KB
/
app.py
File metadata and controls
67 lines (58 loc) · 2.19 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
from flask import Flask, jsonify,request
import subprocess
import os,glob
app = Flask(__name__)
def run_ldsc_command(pop, genome_build, filename,ldwindow,windUnit):
fileDir = f"/data/tmp/uploads"
print(filename)
ldwindow_value = 1 # Example value, replace with actual value
# Check if ldwindow is an integer greater than 0, if not set it to 1
try:
ldwindow_value = int(ldwindow)
if ldwindow_value <= 0:
ldwindow_value = 1
except ValueError:
ldwindow_value = 1
windFlag = '--ld-wind-cm'
if windUnit == 'cm':
windFlag = "--ld-wind-cm"
elif windUnit == 'kb':
windFlag = "--ld-wind-kb"
if filename:
file_parts = filename.split('.')
file_chromo = None
for part in file_parts:
if part.isdigit() and 1 <= int(part) <= 22:
file_chromo = part
break
if file_chromo:
# Find the file in the directory
pattern = os.path.join(fileDir, f"{filename}.*")
for file_path in glob.glob(pattern):
extension = file_path.split('.')[-1]
new_filename = f"{file_chromo}.{extension}"
new_file_path = os.path.join(fileDir, new_filename)
os.rename(file_path, new_file_path)
try:
# Run the command
# 'cd 1kg_eur && python ../ldsc.py --bfile 22 --l2 --ld-wind-cm 1 --out 22'
command = f"cd {fileDir} && python /app/ldsc.py --bfile {file_chromo} --l2 {windFlag} {ldwindow_value} --out {file_chromo}"
result = subprocess.run(
['bash', '-c', command],
check=True,
capture_output=True,
text=True
)
return result.stdout
except subprocess.CalledProcessError as e:
return f"An error occurred: {e.stderr}"
@app.route('/ldscore')
def ldscore():
pop = request.args.get('pop')
genome_build = request.args.get('genome_build')
filename = request.args.get('filename')
print(f"pop: {pop}, genome_build: {genome_build}, filename: {filename}")
output = run_ldsc_command(pop, genome_build, filename)
return jsonify({"output": output})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)