def tree(request, id, file, template='tree.html'): """Displays treenode results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "placementInfo") ready, redirect = taskReady(sym_task.celeryUID) if ready: counts, headers = treeCsv(os.path.join(output, file, "treenodeCladeDist.tsv")) if counts != None: paginator = Paginator(counts, 50) page = request.GET.get('page') try: counts = paginator.page(page) except PageNotAnInteger: counts = paginator.page(1) except EmptyPage: counts = paginator.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID])) context = { 'counts': counts, 'headers': headers, 'id': id, 'file': file, } return render(request, template, context)
def perfect(request, id, template='subtypes.html'): """Displays subtypes results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "blastResults") ready, redirect = taskReady(sym_task.celeryUID) if ready: counts, headers = csv2list(os.path.join(output, "PERFECT_subtypes_count.tsv")) elif redirect: return redirect else: return HttpResponseRedirect(reverse("index", args=[sym_task.UID])) context = { 'title': "Perfect Subtypes", 'counts': counts, 'headers': headers, 'id': id, } return render(request, template, context)
def perfect(request, id, template='subtypes.html'): """Displays subtypes results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "blastResults") ready, redirect = taskReady(sym_task.celeryUID) if ready: counts, headers = csv2list( os.path.join(output, "PERFECT_subtypes_count.tsv")) elif redirect: return redirect else: return HttpResponseRedirect(reverse("index", args=[sym_task.UID])) context = { 'title': "Perfect Subtypes", 'counts': counts, 'headers': headers, 'id': id, } return render(request, template, context)
def chart(request, id, site): """Displays pie chart""" detailed_counts = None try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput") ready, redirect = taskReady(sym_task.celeryUID) if ready: detailed_counts = searchTable( os.path.join(output, 'DETAILED_counts.tsv'), site) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID])) return render_to_response( 'chart.html', RequestContext(request, { 'id': id, 'site': site, 'detailed_counts': detailed_counts }))
def unique(request, id, template='subtypes.html'): """Displays subtypes results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "blastResults") ready, redirect = taskReady(sym_task) if ready: counts, headers = csv2list(os.path.join(output, "UNIQUE_subtypes_count.tsv")) #shortnew_counts, shortnew_headers = csv2list(os.path.join(output, "SHORTNEW_subtypes_count.tsv")) #perfect_counts, perfect_headers = csv2list(os.path.join(output, "PERFECT_subtypes_count.tsv")) elif redirect: return redirect else: return HttpResponseRedirect(reverse("index", args=[sym_task.UID])) context = { #'shortnew_counts': shortnew_counts, #'shortnew_headers': shortnew_headers, #'unique_counts': unique_counts, #'unique_headers': unique_headers, #'perfect_counts': perfect_counts, #'perfect_headers': perfect_headers, 'counts': counts, 'headers': headers, 'title': "Unique Subtypes", 'id': id, } return render(request, template, context)
def clades(request, id, template='clades.html'): """Displays clade results.""" dirs = all_counts = detailed_counts = all_headers = detailed_headers = None try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "hmmer_parsedOutput") ready, redirect = taskReady(sym_task) if ready: with open(os.path.join(output, "ALL_counts.tsv")) as tsv: # order is maintained and we don't really reorder, so why use zip and dict? all_headers = [ l for l in tsv.next().strip().split() ] all_counts = [ row.strip().split() for row in tsv ] with open(os.path.join(output, "DETAILED_counts.tsv")) as tsv: # remove the sample detailed_headers = tsv.next().strip().split()[1:] detailed_counts = [ zip(detailed_headers, row.strip().split()[1:]) for row in tsv ] paginator1 = Paginator(all_counts, 50) paginator2 = Paginator(detailed_counts, 50) page = request.GET.get('page') try: all_counts = paginator1.page(page) detailed_counts = paginator2.page(page) except PageNotAnInteger: all_counts = paginator1.page(1) detailed_counts = paginator2.page(1) except EmptyPage: all_counts_counts = paginator1.page(paginator.num_pages) detailed_counts = paginator2.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("index", args=[sym_task.UID])) context = { 'id': id, 'title': "Clades", 'dirs': dirs, 'all_headers': all_headers, 'all_counts': all_counts, 'detailed_counts': detailed_counts, #'detailed_headers': detailed_headers, } return render(request, template, context)
def multiplesResolved(request, id, file, template='multiples.html'): """Displays resolved multiples results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) resolved = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "resolveMultiples", "correctedMultiplesHits", "resolved") ready, redirect = taskReady(sym_task.celeryUID) if ready: resolved_counts, resolved_headers, resolved_breakdown, resolved_subtypes = multiplesCsv( os.path.join(resolved, file)) if resolved_counts != None and resolved_subtypes != None and resolved_breakdown != None: paginator1 = Paginator(resolved_counts, 5) paginator2 = Paginator(resolved_breakdown, 5) paginator3 = Paginator(resolved_subtypes, 5) page = request.GET.get('page') try: counts = paginator1.page(page) breakdown = paginator2.page(page) subtypes = paginator3.page(page) except PageNotAnInteger: counts = paginator1.page(1) breakdown = paginator2.page(1) subtypes = paginator3.page(1) except EmptyPage: counts = paginator1.page(paginator.num_pages) breakdown = paginator2.page(paginator.num_pages) subtypes = paginator3.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID])) context = { 'file': file, 'counts': resolved_counts, 'headers': resolved_headers, 'breakdown': resolved_breakdown, 'subtypes': resolved_subtypes, 'id': id, } return render(request, template, context)
def dlEverything(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task.celeryUID) if ready: path = os.path.join(settings.SYMTYPER_HOME, str(id), "data") return servZip(request, path) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def dlEverything(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task.celeryUID) if ready: path = os.path.join(settings.SYMTYPER_HOME, str(id), "data") return servZip(request, path) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def multiplesResolved(request, id, file, template='multiples.html'): """Displays resolved multiples results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) resolved = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "resolveMultiples", "correctedMultiplesHits", "resolved") ready, redirect = taskReady(sym_task.celeryUID) if ready: resolved_counts, resolved_headers, resolved_breakdown, resolved_subtypes = multiplesCsv(os.path.join(resolved, file)) if resolved_counts != None and resolved_subtypes != None and resolved_breakdown != None: paginator1 = Paginator(resolved_counts, 5) paginator2 = Paginator(resolved_breakdown, 5) paginator3 = Paginator(resolved_subtypes, 5) page = request.GET.get('page') try: counts = paginator1.page(page) breakdown = paginator2.page(page) subtypes = paginator3.page(page) except PageNotAnInteger: counts = paginator1.page(1) breakdown = paginator2.page(1) subtypes = paginator3.page(1) except EmptyPage: counts = paginator1.page(paginator.num_pages) breakdown = paginator2.page(paginator.num_pages) subtypes = paginator3.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID])) context = { 'file': file, 'counts': resolved_counts, 'headers': resolved_headers, 'breakdown': resolved_breakdown, 'subtypes': resolved_subtypes, 'id': id, } return render(request, template, context)
def dlDetailed(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task.celeryUID) if ready: fPath = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput","DETAILED_counts.tsv") fsize = os.stat(fPath).st_size filename = "DETAILED_counts.tsv" return servFile(request, ready, filename, fPath, fsize) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def dlShortnew(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task.celeryUID) if ready: fPath = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "blastResults","SHORTNEW_subtypes_count.tsv") fsize = os.stat(fPath).st_size filename = "SHORTNEW_subtypes__count.tsv" return servFile(request, ready, filename, fPath, fsize) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def dlBiom(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task) if ready: fPath = os.path.join(settings.SYMTYPER_HOME, str(id), "breakdown.tsv") fsize = os.stat(fPath).st_size filename = "breakdown.tsv" return servFile(request, ready, filename, fPath, fsize) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def index(request, id, template='index.html'): """Displays index page.""" done = False try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task) if ready: done = True elif redirect: return redirect else: pass #message = "pending..." if done: context = descriptiveStats(id) params = yaml.load(sym_task.params) parm = defaultdict(list) version = params.pop('version_tag',1) ordering = [p.title() for p in params.pop('order', [])] if version == 1: for k, v in params.iteritems(): section, label = k.replace('+',' ').split("_") parm[section.title()].append( (label, v,)) for k in parm: parm[k].sort(key = lambda x: x[0]) elif version == 2: for section, v in params.iteritems(): k = section.title() parm[k] = v.items() parm[k].sort(key = lambda x: x[0]) context['done'] = done context['id'] = id context['params'] = dict(parm) context['order'] = ordering else: context= { 'done': done, 'id': id } return render(request, template, context)
def dlDetailed(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task.celeryUID) if ready: fPath = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput", "DETAILED_counts.tsv") fsize = os.stat(fPath).st_size filename = "DETAILED_counts.tsv" return servFile(request, ready, filename, fPath, fsize) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def dlShortnew(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task.celeryUID) if ready: fPath = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "blastResults", "SHORTNEW_subtypes_count.tsv") fsize = os.stat(fPath).st_size filename = "SHORTNEW_subtypes__count.tsv" return servFile(request, ready, filename, fPath, fsize) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def chart(request, id, site): """Displays pie chart""" detailed_counts = None try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput") ready, redirect = taskReady(sym_task.celeryUID) if ready: detailed_counts = searchTable(os.path.join(output, 'DETAILED_counts.tsv'),site) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID])) return render_to_response('chart.html', RequestContext(request, {'id': id, 'site': site, 'detailed_counts': detailed_counts}))
def dlMultiples(request, id): try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) ready, redirect = taskReady(sym_task) if ready: fPath = os.path.join(settings.SYMTYPER_HOME, str(id), "multiples.zip") fsize = os.stat(fPath).st_size filename = settings.SYMTYPER_ZIP_FMT%(str(id), "multiples") return servFile(request, ready, filename, fPath, fsize) path = os.path.join(settings.SYMTYPER_HOME, str(id), "resolveMultiples", "correctedMultiplesHits") return servZip(request, path) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID]))
def index(request, id, template='index.html'): """Displays index page.""" done = False try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) #output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput") ready, redirect = taskReady(sym_task.celeryUID) if ready: done = True elif redirect: return redirect else: pass #message = "pending..." context = {'done': done, 'id': id} return render(request, template, context)
def index(request, id, template='index.html'): """Displays index page.""" done = False try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) #output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput") ready, redirect = taskReady(sym_task.celeryUID) if ready: done = True elif redirect: return redirect else: pass #message = "pending..." context = { 'done': done, 'id': id } return render(request, template, context)
def tree(request, id, file, template='tree.html'): """Displays treenode results.""" try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "placementInfo") ready, redirect = taskReady(sym_task.celeryUID) if ready: counts, headers = treeCsv( os.path.join(output, file, "treenodeCladeDist.tsv")) if counts != None: paginator = Paginator(counts, 50) page = request.GET.get('page') try: counts = paginator.page(page) except PageNotAnInteger: counts = paginator.page(1) except EmptyPage: counts = paginator.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("status", args=[sym_task.UID])) context = { 'counts': counts, 'headers': headers, 'id': id, 'file': file, } return render(request, template, context)
def clades(request, id, template='clades.html'): """Displays clade results.""" dirs = all_counts = detailed_counts = all_headers = detailed_headers = None try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput") ready, redirect = taskReady(sym_task.celeryUID) if ready: #dirs = [d for d in os.listdir(output) #if os.path.isdir(os.path.join(output, d))] with open(os.path.join(output, "ALL_counts.tsv")) as tsv: all_counts = [] all = [line.strip().split() for line in tsv] all_headers = all[0] for row in all[1:]: total = hit = no_hit = low = ambiguous = percentages = 0 site = row[0] for column in row[1:]: total += int(column) if total != 0: hit = round(float(row[1])/total * 100, 2) no_hit = round(float(row[2])/total * 100, 2) low = round(float(row[3])/total * 100, 2) ambiguous = round(float(row[4])/total * 100, 2) percentages = [site, hit, no_hit, low, ambiguous] all_counts.append(dict(zip(all_headers, percentages))) with open(os.path.join(output, "DETAILED_counts.tsv")) as tsv: detailed_counts = [] all = [line.strip().split() for line in tsv] detailed_headers = all[0][1:] for row in all[1:]: data = [] site = row[0] for column in row[1:]: data.append(column) detailed_counts.append(dict(zip(detailed_headers, data))) paginator1 = Paginator(all_counts, 50) paginator2 = Paginator(detailed_counts, 50) page = request.GET.get('page') try: all_counts = paginator1.page(page) detailed_counts = paginator2.page(page) except PageNotAnInteger: all_counts = paginator1.page(1) detailed_counts = paginator2.page(1) except EmptyPage: all_counts_counts = paginator1.page(paginator.num_pages) detailed_counts = paginator2.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("index", args=[sym_task.UID])) context = { 'id': id, 'title': "Clades", 'dirs': dirs, 'all_headers': all_headers, 'all_counts': all_counts, 'detailed_counts': detailed_counts, 'detailed_headers': detailed_headers, } return render(request, template, context)
def clades(request, id, template='clades.html'): """Displays clade results.""" dirs = all_counts = detailed_counts = all_headers = detailed_headers = None try: sym_task = symTyperTask.objects.get(UID=id) except ObjectDoesNotExist: return HttpResponseRedirect(reverse("form")) output = os.path.join(settings.SYMTYPER_HOME, str(id), "data", "hmmer_parsedOutput") ready, redirect = taskReady(sym_task.celeryUID) if ready: #dirs = [d for d in os.listdir(output) #if os.path.isdir(os.path.join(output, d))] with open(os.path.join(output, "ALL_counts.tsv")) as tsv: all_counts = [] all = [line.strip().split() for line in tsv] all_headers = all[0] for row in all[1:]: total = hit = no_hit = low = ambiguous = percentages = 0 site = row[0] for column in row[1:]: total += int(column) if total != 0: hit = round(float(row[1]) / total * 100, 2) no_hit = round(float(row[2]) / total * 100, 2) low = round(float(row[3]) / total * 100, 2) ambiguous = round(float(row[4]) / total * 100, 2) percentages = [site, hit, no_hit, low, ambiguous] all_counts.append(dict(zip(all_headers, percentages))) with open(os.path.join(output, "DETAILED_counts.tsv")) as tsv: detailed_counts = [] all = [line.strip().split() for line in tsv] detailed_headers = all[0][1:] for row in all[1:]: data = [] site = row[0] for column in row[1:]: data.append(column) detailed_counts.append(dict(zip(detailed_headers, data))) paginator1 = Paginator(all_counts, 50) paginator2 = Paginator(detailed_counts, 50) page = request.GET.get('page') try: all_counts = paginator1.page(page) detailed_counts = paginator2.page(page) except PageNotAnInteger: all_counts = paginator1.page(1) detailed_counts = paginator2.page(1) except EmptyPage: all_counts_counts = paginator1.page(paginator.num_pages) detailed_counts = paginator2.page(paginator.num_pages) elif redirect: return redirect else: return HttpResponseRedirect(reverse("index", args=[sym_task.UID])) context = { 'id': id, 'title': "Clades", 'dirs': dirs, 'all_headers': all_headers, 'all_counts': all_counts, 'detailed_counts': detailed_counts, 'detailed_headers': detailed_headers, } return render(request, template, context)