Commit 41e9453b authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

do not use extanded from doi API which is unstable

parent ecd25b67
Pipeline #54370 failed with stages
in 4 minutes and 57 seconds
import logging
from drf_yasg.utils import swagger_auto_schema
from marshmallow.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.status import HTTP_422_UNPROCESSABLE_ENTITY
from requests.models import HTTPError
from metagenedb.apps.catalog.models import Source
from metagenedb.apps.catalog.serializers import SourceSerializer
......@@ -11,6 +14,9 @@ from metagenedb.common.utils.external_api.doi_api import GetDOIExternalInfo
from .base import BulkViewSet
logger = logging.getLogger(__name__)
class SourceViewSet(BulkViewSet):
queryset = Source.objects.all()
serializer_class = SourceSerializer
......@@ -32,6 +38,8 @@ class SourceViewSet(BulkViewSet):
except NotImplementedError as not_implemented_error:
logger.warning("Could not found API for the source, returning item from the DB. Error: %s" %
not_implemented_error)
except HTTPError:
logger.warning("Could not get info from external API source, returning default response.")
return db_data
@swagger_auto_schema(
......
......@@ -17,7 +17,5 @@
</div>
<!-- Simple information -->
<SimpleListing v-else :listData="sourceDetails" :color="color"/>
<!-- Expandable details (pathways, diseases, references...) -->
<SimpleExpand :expandData="sourceExpandDetails" :color="color"/>
</v-card>
</v-flex>
\ No newline at end of file
......@@ -18,8 +18,7 @@ export default {
data() {
return {
sourceDetails: [],
sourceExpandDetails: [],
keggReferences: [],
referenceExpandDetails: [],
requestDone: false,
};
},
......@@ -36,7 +35,6 @@ export default {
})
.then((response) => {
this.buildsourceDetails(response);
this.buildSourceExpandDetails(response);
})
.catch((error) => {
console.log(error);
......@@ -54,139 +52,12 @@ export default {
url_label: "Visit website",
},
{
title: 'Reference',
title: 'Reference - DOI',
content: response.data.doi,
url: `https://doi.org/${response.data.doi}`,
url_label: "Open reference",
},
];
},
buildSourceExpandDetails(response) {
this.keggExpandDetails = [
this.buildEcNumbers(response),
this.buildPathways(response),
this.buildDiseases(response),
this.buildModules(response),
this.buildReferences(response),
];
},
buildEcNumbers(response) {
var ec_numbers = {
title: 'EC numbers',
icon: 'fas fa-exchange-alt',
content: [],
};
if(response.data.ec_numbers) {
Object.entries(response.data.ec_numbers).forEach(([key, value]) => {
var link_id = value.split('.-')[0]
ec_numbers.content.push(
{
id: value,
url: `https://www.ebi.ac.uk/intenz/query?cmd=SearchEC&ec=${link_id}`,
url_label: "Open in IntEnz",
},
);
});
}
return ec_numbers;
},
buildPathways(response) {
var pathways = {
title: 'Pathways',
icon: 'fas fa-bezier-curve',
content: [],
};
if(response.data.pathways) {
Object.entries(response.data.pathways).forEach(([key, value]) => {
pathways.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/kegg-bin/show_pathway?${key}+${this.sourceId}`,
url_label: "Open in KEGG",
fetch: true,
},
);
});
}
return pathways;
},
buildModules(response) {
var modules = {
title: 'Modules',
icon: 'fas fa-bezier-curve',
content: [],
};
if(response.data.modules) {
Object.entries(response.data.modules).forEach(([key, value]) => {
modules.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/kegg-bin/show_module?${key}+${this.sourceId}`,
url_label: "Open in KEGG"
},
);
});
}
return modules;
},
buildDiseases(response) {
var diseases = {
title: 'Diseases',
icon: 'fas fa-laptop-medical',
content: [],
};
if(response.data.diseases) {
Object.entries(response.data.diseases).forEach(([key, value]) => {
diseases.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/dbget-bin/www_bget?ds:${key}`,
},
);
});
}
return diseases;
},
buildReferences(response) {
var references = {
title: 'References',
icon: 'fas fa-book-open',
content: [],
};
if (response.data.references) {
for (let i = 0; i < response.data.references.length; i++) {
var url = null
if (response.data.references[i].doi){
var url = `https://doi.org/${response.data.references[i].doi}`;
var url_label = "Open in doi.org";
}
else if (response.data.references[i].pubmed_id) {
var url = `https://www.ncbi.nlm.nih.gov/pubmed/${response.data.references[i].pubmed_id}`;
var url_label = "Open in Pubmed";
}
if (url) {
references.content.push(
{
id: response.data.references[i].title,
name: `${response.data.references[i].authors[0]} et al. ${response.data.references[i].journal}`,
url: url,
url_label: url_label,
},
);
}
else {
references.content.push(
{
id: response.data.references[i].title,
name: `${response.data.references[i].authors[0]} et al. ${response.data.references[i].journal}`,
},
);
}
};
}
return references;
},
},
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment