Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…code into update-gunicorn
  • Loading branch information
carlosribas committed Dec 11, 2024
2 parents f60d63d + 6b09607 commit 413768d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 4 deletions.
12 changes: 11 additions & 1 deletion rnacentral/apiv1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404
from django_filters import rest_framework as filters
from drf_spectacular.utils import extend_schema
from portal.config.expert_databases import expert_dbs
from portal.models import (
Accession,
Expand Down Expand Up @@ -109,6 +110,7 @@ def get_database(region):
return providing_databases


@extend_schema(exclude=True)
class GenomeAnnotations(APIView):
"""
Ensembl-like genome coordinates endpoint.
Expand Down Expand Up @@ -182,6 +184,7 @@ def get(self, request, species, chromosome, start, end, format=None):
return Response(features)


@extend_schema(exclude=True)
class APIRoot(APIView):
"""
This is the root of the RNAcentral API Version 1.
Expand Down Expand Up @@ -457,6 +460,7 @@ def get_queryset(self):
return Rna.objects.get(upi=upi).get_xrefs(taxid=taxid)


@extend_schema(exclude=True)
class SecondaryStructureSpeciesSpecificList(generics.ListAPIView):
"""
List of secondary structures for a particular RNA sequence in a specific species.
Expand Down Expand Up @@ -630,7 +634,12 @@ class CitationsView(generics.ListAPIView):

def get_queryset(self):
pk = self.kwargs["pk"]
return Accession.objects.select_related().get(pk=pk).refs.all()
try:
citations = Accession.objects.select_related().get(pk=pk).refs.all()
except Accession.DoesNotExist:
citations = Accession.objects.none()

return citations


class RnaPublicationsView(generics.ListAPIView):
Expand Down Expand Up @@ -691,6 +700,7 @@ def _normalize_expert_db_label(expert_db_label):
# return Database.objects.get(expert_db_name).references


@extend_schema(exclude=True)
class ExpertDatabasesStatsViewSet(RetrieveModelMixin, ListModelMixin, GenericViewSet):
"""
API endpoint with statistics of databases, comprising RNAcentral.
Expand Down
5 changes: 3 additions & 2 deletions rnacentral/portal/templates/portal/docs/sab.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[RNAcentral](/) and [Rfam](https://rfam.org) share a Scientific Advisory Board (SAB)
which includes six RNA biologists covering a wide range of expertise from wet lab to computational research.

- [Yann Ponty](http://www.lix.polytechnique.fr/~ponty/) CNRS École Politechnique, France
- [Lovorka Stojic](https://www.bartscancer.london/staff/dr-lovorka-stojic/) Barts Centre CRUK, UK
- [Alain Laederach](https://ribosnitch.bio.unc.edu/) UNC Chapel Hill, USA
- [Madeline Sherlock](https://profiles.ucdenver.edu/display/20414874) New York Structural Biology Center, USA
Expand All @@ -26,4 +25,6 @@ The SAB oversees the progress of the project during annual meetings.
- [Mihaela Zavolan](https://www.biozentrum.unibas.ch/research/researchgroups/overview/unit/zavolan/research-group-mihaela-zavolan/) (University of Basel) *SAB member between 2016-2020*
- [Eric Westhof](http://www-ibmc.u-strasbg.fr/upr9002/westhof/index.html) University of Strasbourg *SAB member between 2015-2021*
- [Michelle Meyer](https://bioinformatics.bc.edu/meyerlab/) Boston College *SAB member between 2016-2021*
- [Manja Marz](http://www.rna.uni-jena.de/members/manja-marz/) Friedrich Schiller University Jena, Germany
- [Manja Marz](http://www.rna.uni-jena.de/members/manja-marz/) Friedrich Schiller University Jena, Germany *SAB member between 2017-2022*
- [Yiliang Ding](https://www.jic.ac.uk/people/yilliang-ding/) John Innes Centre, UK *SAB member between 2021-2023*
- [Yann Ponty](http://www.lix.polytechnique.fr/~ponty/) CNRS École Politechnique, France *SAB member between 2019-2024*
1 change: 1 addition & 0 deletions rnacentral/portal/templates/portal/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<ul class="dropdown-menu">
<li><a href="{% url 'api-v1-root' %}">Browsable API</a></li>
<li><a href="{% url 'api-docs' %}">API Documentation</a></li>
<li><a href="{% url 'swagger-ui' %}" target="_blank">OpenAPI Schema</a></li>
</ul>
</li>

Expand Down
2 changes: 1 addition & 1 deletion rnacentral/portal/templates/portal/r2dt.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1><i class="fa fa-search"></i> R2DT</h1>
</p>
<r2dt-web
examples='[
{"description": "3SKZ_B", "sequence": "GGCCUUAUACAGGGUAGCAUAAUGGGCUACUGACCCCGCCUUCAAACCUAUUUGGAGACUAUAAGGUC\n.((((((((A..((((((.....BB))))))(.....a)(((((((bb..)))))))..))))))))."},
{"description": "3SKZ_B", "descriptionNote": "Dot-bracket notation", "sequence": "GGCCUUAUACAGGGUAGCAUAAUGGGCUACUGACCCCGCCUUCAAACCUAUUUGGAGACUAUAAGGUC\n.((((((((A..((((((.....BB))))))(.....a)(((((((bb..)))))))..))))))))."},
{"description": "MT-RNR1", "sequence": "AAUAGGUUUGGUCCUAGCCUUUCUAUUAGCUCUUAGUAAGAUUACACAUGCAAGCAUCCCCGUUCCAGUGAGUUCACCCUCUAAAUCACCACGAUCAAAAGGAACAAGCAUCAAGCACGCAGCAAUGCAGCUCAAAACGCUUAGCCUAGCCACACCCCCACGGGAAACAGCAGUGAUUAACCUUUAGCAAUAAACGAAAGUUUAACUAAGCUAUACUAACCCCAGGGUUGGUCAAUUUCGUGCCAGCCACCGCGGUCACACGAUUAACCCAAGUCAAUAGAAGCCGGCGUAAAGAGUGUUUUAGAUCACCCCCUCCCCAAUAAAGCUAAAACUCACCUGAGUUGUAAAAAACUCCAGUUGACACAAAAUAGACUACGAAAGUGGCUUUAACAUAUCUGAACACACAAUAGCUAAGACCCAAACUGGGAUUAGAUACCCCACUAUGCUUAGCCCUAAACCUCAACAGUUAAAUCAACAAAACUGCUCGCCAGAACACUACGAGCCACAGCUUAAAACUCAAAGGACCUGGCGGUGCUUCAUAUCCCUCUAGAGGAGCCUGUUCUGUAAUCGAUAAACCCCGAUCAACCUCACCACCUCUUGCUCAGCCUAUAUACCGCCAUCUUCAGCAAACCCUGAUGAAGGCUACAAAGUAAGCGCAAGUACCCACGUAAAGACGUUAGGUCAAGGUGUAGCCCAUGAGGUGGCAAGAAAUGGGCUACAUUUUCUACCCCAGAAAACUACGAUAGCCCUUAUGAAACUUAAGGGUCGAAGGUGGAUUUAGCAGUAAACUAAGAGUAGAGUGCUUAGUUGAACAGGGCCCUGAAGCGCGUACACACCGCCCGUCACCCUCCUCAAGUAUACUUCAAAGGACAUUUAACUAAAACCCCUACGCAUUUAUAUAGAGGAGACAAGUCGUAACAUGGUAAGUGUACUGGAAAGUGCACUUGGACGAAC"},
{"description": "SAM", "sequence": "CTCTTATCGAGAGTTGGGCGAGGGATTTGGCCTTTTGACCCCAAAAGCAACCGACCGTAATTCCATTGTGAAATGGGGCGCATTTTTTTCGCGCCGAGACGCTGGTCTCTTAAGGCACGGTGCTAATTCCATTCAGATCTGATCTGAGAGATAAGAG"},
{"description": "RNVU1-1", "sequence": "AUACUUACCUGGCAGGGGAGAUACGAUGAUCACGAAGGUGGUUUUCCCAGGGAGAGGCUUAUCCAUUGCACUCCGGAUGUGCUGACCCCUGCCGUUUCCCCAAAUGUGGGAAACUCGACUGCAUAAUUUGUGGUAGUGGGGGACUGCGUUCGCGCUGUCCUCUG"},
Expand Down
3 changes: 3 additions & 0 deletions rnacentral/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ django-cache-machine==1.1.0

# AWS SDK for Python
boto3==1.17.54

# drf-spectacular for OpenAPI schema generation
drf_spectacular
15 changes: 15 additions & 0 deletions rnacentral/rnacentral/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"rest_framework",
"compressor",
"markdown_deux",
"drf_spectacular",
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
Expand Down Expand Up @@ -246,6 +247,7 @@
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
],
"DEFAULT_AUTHENTICATION_CLASSES": [],
# API results pagination
"DEFAULT_PAGINATION_CLASS": "rnacentral.utils.pagination.Pagination",
"PAGE_SIZE": 10,
Expand All @@ -266,6 +268,19 @@
"rest_framework_yaml.renderers.YAMLRenderer",
"rest_framework.renderers.BrowsableAPIRenderer",
),
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}

SPECTACULAR_SETTINGS = {
"TITLE": "RNAcentral API",
"DESCRIPTION": "RNAcentral API provides programmatic access to RNAcentral data",
"VERSION": "1.0.0",
"SERVE_INCLUDE_SCHEMA": False,
"POSTPROCESSING_HOOKS": [
"rnacentral.utils.drf_spectacular.remove_path",
"rnacentral.utils.drf_spectacular.fix_path",
],
"SCHEMA_PATH_PREFIX": r"/api/v[0-9]",
}

# django-debug-toolbar
Expand Down
8 changes: 8 additions & 0 deletions rnacentral/rnacentral/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from django.conf.urls import include, url
from django.views.generic import TemplateView
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

urlpatterns = [
# RNAcentral portal
Expand All @@ -27,6 +28,13 @@
# new sequence search
url(r"^sequence-search/", include("sequence_search.urls")),
# Django Debug Toolbar
# OpenAPI schema
url(r"^api/schema/$", SpectacularAPIView.as_view(), name="schema"),
url(
r"^api/schema/swagger-ui/$",
SpectacularSwaggerView.as_view(url_name="schema"),
name="swagger-ui",
),
]

# robots.txt extras
Expand Down
31 changes: 31 additions & 0 deletions rnacentral/rnacentral/utils/drf_spectacular.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def remove_path(result, generator, request, public):
"""
Post-processing hook to remove /api/current/ and /sequence-search/ from the schema
"""
paths = result.get("paths", {})
excluded_prefixes = ("/api/current/", "/sequence-search/")
paths = {
key: value
for key, value in paths.items()
if not key.startswith(excluded_prefixes)
}
result["paths"] = paths
return result


def fix_path(result, generator, request, public):
"""
Post-processing hook to normalize paths in the OpenAPI schema:
- Fix RNA path patterns containing [_/] to only show /.
"""
paths = result.get("paths", {})
updated_paths = {}

for path, details in paths.items():
if "[/_]" in path:
path = path.replace("[/_]", "/")

updated_paths[path] = details

result["paths"] = updated_paths
return result

0 comments on commit 413768d

Please sign in to comment.