|
| 1 | +import json |
| 2 | +import requests |
| 3 | + |
1 | 4 | from drf_spectacular.types import OpenApiTypes
|
2 | 5 | from drf_spectacular.utils import extend_schema_field
|
3 | 6 | from rest_framework import serializers
|
@@ -43,6 +46,9 @@ class XrefSerializer(serializers.Serializer):
|
43 | 46 | mirbase_precursor = serializers.SerializerMethodField(
|
44 | 47 | method_name="get_mirbase_precursor"
|
45 | 48 | )
|
| 49 | + quickgo_hits = serializers.SerializerMethodField( |
| 50 | + method_name="get_quickgo_hits" |
| 51 | + ) |
46 | 52 | refseq_mirna_mature_products = serializers.SerializerMethodField(
|
47 | 53 | method_name="get_refseq_mirna_mature_products"
|
48 | 54 | )
|
@@ -116,6 +122,22 @@ def get_mirbase_precursor(self, obj):
|
116 | 122 |
|
117 | 123 | return get_related_sequence(obj.accession_id, "precursor")
|
118 | 124 |
|
| 125 | + def get_quickgo_hits(self, obj): |
| 126 | + """Return the number of annotations in QuickGO""" |
| 127 | + if obj.accession.database == "PSICQUIC": |
| 128 | + urs_taxid = obj.upi.upi + "_" + str(obj.taxid) |
| 129 | + try: |
| 130 | + response = requests.get( |
| 131 | + f"https://www.ebi.ac.uk/QuickGO/services/annotation/stats?geneProductId={urs_taxid}" |
| 132 | + ) |
| 133 | + data = json.loads(response.text) |
| 134 | + hits = data["results"][0]["totalHits"] |
| 135 | + except Exception: |
| 136 | + hits = None |
| 137 | + else: |
| 138 | + hits = None |
| 139 | + return hits |
| 140 | + |
119 | 141 | def get_refseq_mirna_mature_products(self, obj):
|
120 | 142 | if obj.db_id != 9: # 9 = REFSEQ
|
121 | 143 | return None
|
|
0 commit comments