def analysis_results(request, pk): analysis = Analysis.objects.filter(is_active=True, pk=pk).first() if not analysis: return api.json(404, detail='Analysis not found') if not analysis.success: return api.json(404, detail='Analysis failed or not finished yet') return HttpResponse(frame_dumps(analysis.results_df()), content_type='application/json')
def upload_to_zenodo(request, snap_id): snap = get_object_or_404(Snapshot, pk=snap_id) # Minimum length for title and description on zenodo is 3 if len(snap.title) < 3: return api.json(400, detail='Need title of length 3 or more') description = snap.description if len( snap.description) >= 3 else 'no description' # Create deposition meta = { 'title': snap.title, 'description': description, 'upload_type': 'dataset', 'creators': [{ 'name': '%s, %s' % (request.user.last_name, request.user.first_name) }], } res = request.zenodo.post('https://zenodo.org/api/deposit/depositions', json={'metadata': meta}) res.raise_for_status() snap.zenodo = deposit = res.json() snap.save() # Upload files for file in snap.files: name = re.sub(r'\W+', '-', snap.title).strip('-').lower() or 'file' filename = '%s.%s' % (name, file['format']) data = {'filename': filename} files = {'file': file.open()} res = request.zenodo.post(deposit['links']['files'], data=data, files=files) res.raise_for_status() # Rename file, see Zenodo bug https://github.com/zenodo/zenodo/issues/940 file_desc = res.json() if file_desc['filename'] != filename: res = request.zenodo.put(file_desc['links']['self'], json={'filename': filename}) res.raise_for_status() # Publish res = request.zenodo.post(deposit['links']['publish']) res.raise_for_status() # Update info res = request.zenodo.get(deposit['links']['self']) res.raise_for_status() snap.zenodo = deposit = res.json() snap.save() return api.json(deposit)
def platform_probes(request, gpl_name): if not Platform.objects.filter(gpl_name=gpl_name).exists(): return api.json(404, detail='Platform not found') qs = PlatformProbe.objects.filter(platform__gpl_name=gpl_name) probes_df = qs.to_dataframe( fieldnames=['probe', 'mygene_sym', 'mygene_entrez']) return HttpResponse(frame_dumps(probes_df), content_type='application/json')
def series_samples(request, gse_name): series = Series.objects.get(gse_name=gse_name) samples = api.queryset(series.samples.exclude(deleted='T')).values( 'gsm_name', 'attrs', gse_name='series__gse_name', gpl_name='platform__gpl_name') # Filter by platform if request.GET.get('gpl_name'): samples = samples.filter( platform__gpl_name=request.GET.get('gpl_name')) return api.json(samples)
def annotate(request, data): canonical = SeriesAnnotation.objects.filter( series=data['series'], tag=data['tag'], platform=data['platform']).first() data['tag_id'] = data.pop('tag').id data['series_id'] = data.pop('series').id data['user_id'] = request.user.id data['from_api'] = True try: if canonical: save_validation(canonical.id, data) else: save_annotation(data) except AnnotationError as e: return api.json(409, detail=str(e)) return HttpResponse(status=204)
def platform_detail(request, gpl_name): return api.json(api.get_or_404(platforms_qs, gpl_name=gpl_name))
def platforms(request): return api.json(api.paginate(request, platforms_qs, per_page=PER_PAGE))
def series_detail(request, gse_name): return api.json(api.get_or_404(series_qs, gse_name=gse_name))
def series(request): return api.json(api.paginate(request, series_qs, per_page=PER_PAGE))
def tag_detail(request, pk): return api.json(api.get_or_404(tags_qs, pk=pk))
def analysis_detail(request, pk): return api.json(api.get_or_404(analysis_qs, pk=pk))
def annotation_samples(request, pk): if not annotations_qs.filter(pk=pk).exists(): return api.json(404, detail='Annotation not found') samples = api.queryset(SampleAnnotation).filter(series_annotation=pk) \ .values_list('sample__gsm_name', 'annotation') return api.json(dict(samples))
def annotation_detail(request, pk): return api.json(api.get_or_404(annotations_qs, pk=pk))
def annotations(request): return api.json(api.paginate(request, annotations_qs, per_page=PER_PAGE))
def analysis_create(request, analysis): analysis.created_by_id = analysis.modified_by_id = request.user.id analysis.save() analysis_task.delay(analysis.pk) return api.json(201, created=analysis.pk)
def analysis_list(request): return api.json(api.paginate(request, analysis_qs, per_page=PER_PAGE))
def tags(request): return api.json(tags_qs)