Esempio n. 1
0
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')
Esempio n. 2
0
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)
Esempio n. 3
0
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')
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
def platform_detail(request, gpl_name):
    return api.json(api.get_or_404(platforms_qs, gpl_name=gpl_name))
Esempio n. 7
0
def platforms(request):
    return api.json(api.paginate(request, platforms_qs, per_page=PER_PAGE))
Esempio n. 8
0
def series_detail(request, gse_name):
    return api.json(api.get_or_404(series_qs, gse_name=gse_name))
Esempio n. 9
0
def series(request):
    return api.json(api.paginate(request, series_qs, per_page=PER_PAGE))
Esempio n. 10
0
def tag_detail(request, pk):
    return api.json(api.get_or_404(tags_qs, pk=pk))
Esempio n. 11
0
def analysis_detail(request, pk):
    return api.json(api.get_or_404(analysis_qs, pk=pk))
Esempio n. 12
0
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))
Esempio n. 13
0
def annotation_detail(request, pk):
    return api.json(api.get_or_404(annotations_qs, pk=pk))
Esempio n. 14
0
def annotations(request):
    return api.json(api.paginate(request, annotations_qs, per_page=PER_PAGE))
Esempio n. 15
0
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)
Esempio n. 16
0
def analysis_list(request):
    return api.json(api.paginate(request, analysis_qs, per_page=PER_PAGE))
Esempio n. 17
0
def tags(request):
    return api.json(tags_qs)