Skip to content

Commit

Permalink
Add rnacentral_id and description
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosribas committed Jul 11, 2024
1 parent 15cda33 commit fdcd5f9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions rnacentral/apiv1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,4 +963,6 @@ def get_ensembl_assembly(self, obj):
class Md5Serializer(serializers.Serializer):
"""Serializer class to fetch sequence using md5"""

rnacentral_id = serializers.CharField(source="id")
description = serializers.CharField()
sequence = serializers.CharField(source="get_sequence")
12 changes: 6 additions & 6 deletions rnacentral/apiv1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@
cache_page(CACHE_TIMEOUT)(views.LncrnaTargetsView.as_view()),
name="rna-lncrna-targets",
),
# fetch sequence using md5
url(
r"md5/(?P<md5>.*?)/?$",
cache_page(CACHE_TIMEOUT)(views.Md5SequenceView.as_view({"get": "retrieve"})),
name="md5-sequence",
),
# Information about the qc status for a given sequence
url(
r"^rna/(?P<pk>URS[0-9A-Fa-f]{10})/qc-status/(?P<taxid>\d+)/?$",
Expand Down Expand Up @@ -202,6 +196,12 @@
{},
name="litsumm-specific-id",
),
# fetch sequence using md5
url(
r"md5/(?P<md5>.*?)/?$",
cache_page(CACHE_TIMEOUT)(views.Md5SequenceView.as_view()),
name="md5-sequence",
),
]

urlpatterns = format_suffix_patterns(
Expand Down
19 changes: 15 additions & 4 deletions rnacentral/apiv1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,20 @@ def get_queryset(self):
return queryset


class Md5SequenceView(ReadOnlyModelViewSet):
class Md5SequenceView(APIView):
"""API endpoint to fetch sequence using md5 field"""

queryset = Rna.objects.all()
serializer_class = Md5Serializer
lookup_field = "md5"
permission_classes = (AllowAny,)

def get(self, request, md5):
try:
rna = Rna.objects.get(md5=md5)
except Rna.DoesNotExist:
raise Http404

precomputed = RnaPrecomputed.objects.filter(upi=rna, taxid__isnull=True).first()
if not precomputed:
raise Http404

serializer = Md5Serializer(precomputed)
return Response(serializer.data)

0 comments on commit fdcd5f9

Please sign in to comment.