Skip to content
Permalink
Browse files

Add rest endpoint to query rnaseq values by gene_id

Add an endpoint that takes a study_id and an gene_id and retrieves
the rnaseq values. This fixes #40.
Use sentry only for production.
  • Loading branch information...
timeu committed Oct 28, 2019
1 parent 8b9a0c5 commit 099bfead748ecced0be943721a222db1aeed4c6e
@@ -11,13 +11,6 @@
"""

import os
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
dsn="https://9a156862319542a88f13172b04a338cb@sentry.io/1798770",
integrations=[DjangoIntegration()]
)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__+ "/../")))
@@ -4,6 +4,13 @@
# Load defaults in order to then add/override with dev-only settings
from defaults import *
import os
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
dsn="https://9a156862319542a88f13172b04a338cb@sentry.io/1798770",
integrations=[DjangoIntegration()]
)

DATACITE_REST_URL='https://mds.datacite.org/'

@@ -155,6 +155,8 @@ def d(request, *args, **kwargs):
url(r'rest/terms/(?P<term_id>%s)/$' % ONTOLOGY_REGEX, rest.ontology_tree_data,name='ontology_tree_children'),
#url(r'rest/ontology/(?P<pk>%s)/(?P<term_id>%s)' % ID_REGEX )

url(r'^rest/rnaseq/(?P<study_id>%s)/(?P<gene_id>%s)/values/$' % (ID_REGEX, rest.GENEID_REGEX), rest.rnaseq_value_by_gene_id),

url(r'^rest/rnaseq/(?P<q>%s)/values/$' % REGEX_PHENOTYPE, rest.rnaseq_value),

]
@@ -41,6 +41,8 @@

DOI_PATTERN_STUDY = re.compile(DOI_REGEX_STUDY)
DOI_PATTERN_PHENOTYPE = re.compile(DOI_REGEX_PHENOTYPE)
GENEID_REGEX = r"AT[1-5|M|C]G[\d]*(\.[\d]){0,1}"
GENEID_PATTERN = re.compile(GENEID_REGEX)

'''
Search Endpoint
@@ -216,6 +218,47 @@ def phenotype_value(request,q,format=None):
value_serializer = PhenotypeValueSerializer(pheno_acc_infos,many=True)
return Response(value_serializer.data)

'''
Get all rnaseq values
'''
@api_view(['GET'])
@permission_classes((IsAuthenticatedOrReadOnly,))
@renderer_classes((PhenotypeValueRenderer,JSONRenderer,PLINKRenderer,))
def rnaseq_value_by_gene_id(request,study_id,gene_id,format=None):
"""
List of the rnaseq values
---
parameters:
- name: study_id
description: the id of the study
required: true
type: int
paramType: path
- name: gene_id
description: the gene_id for the rnaseq values
required: true
type: string
paramType: path
serializer: PhenotypeValueSerializer
omit_serializer: false
produces:
- text/csv
- application/json
"""
study_id = int(study_id)
gene_id = _is_geneid(gene_id)
try:
rnaseq = RNASeq.objects.filter(study__id=study_id,name=gene_id).first()
except:
return HttpResponse(status=404)

if request.method == "GET":
pheno_acc_infos = rnaseq.rnaseqvalue_set.prefetch_related('obs_unit__accession')
value_serializer = PhenotypeValueSerializer(pheno_acc_infos,many=True)
return Response(value_serializer.data)

'''
Get all rnaseq values
'''
@@ -763,6 +806,13 @@ def _is_doi(pattern, term):
return int(term.split(":")[1])
return None

def _is_geneid(term):
gene_id = GENEID_PATTERN.match(term)
if gene_id:
# can't use REGEX capture groups because "("" causes problems in Swagger
return gene_id.group()
return None

def generate_database_dump():
"""
Generate an archive of the full database

0 comments on commit 099bfea

Please sign in to comment.
You can’t perform that action at this time.