Files
Simple_Drawing/tools/views.py
2021-09-24 16:05:56 +08:00

69 lines
2.0 KiB
Python

import os, time
from django.http import JsonResponse
from django.shortcuts import render
from chart import tools
from Bio import SeqIO
def out_page(request, page):
return render(request, f'/tools/{page}')
def id_transform(request):
file = request.FILES.get('file', None)
to = request.POST.get("to", None)
from_ = request.POST.get("from", None)
if file is None:
return JsonResponse({})
return JsonResponse({})
def blast(request):
file1 = request.FILES.get('file1', None)
pass
def gen_to_fa(request):
file = request.FILES.get("file")
file_path, file_id = tools.path_out("chart")
tools.keep_file(file, file_path)
data = {"id": file_id}
records = SeqIO.parse(file_path, "genbank") # 读入
SeqIO.write(records, f"{file_path}.fasta", "fasta") # 写出
return JsonResponse(data)
def gff_to_gtf(request):
file = request.FILES.get("file")
file_path, file_id = tools.path_out("chart")
tools.keep_file(file, file_path)
data = {"id": file_id}
os.system(f"{tools.tools_path}/gffread {file_path} -T -o {file_path}.gtf")
return JsonResponse(data)
def gff_to_gtf(request):
file = request.FILES.get("file")
file_path, file_id = tools.path_out("chart")
tools.keep_file(file, file_path)
data = {"id": file_id}
os.system(f"{tools.tools_path}/gffread {file_path} -T -o {file_path}.gtf")
return JsonResponse(data)
def orf(request):
file = request.FILES.get("file", None)
begin = request.POST.get("begin", None)
end = request.POST.get("end", None)
Cyclotype = request.POST.get("Cyclotype", None)
Codons = request.POST.get("Codons", None)
outfmt = request.POST.get("outfmt", None)
file_path, file_id = tools.path_out("chart")
tools.keep_file(file, file_path)
data = {"id": file_id}
os.system(
f"{tools.tools_path}/ORFfinder {file_path} -b {begin} -e {end} -c {'t' if Cyclotype == 'YES' else 'f'} -g {Codons} -outfmt {outfmt} -out {file_path}.txt")
return JsonResponse(data)