Skip to content
Snippets Groups Projects
Commit c5fb2869 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

autopep8 code

Former-commit-id: e4a2b89495247a4954b8046c445d85df5888f0b5
parent a0c493d7
No related branches found
No related tags found
No related merge requests found
...@@ -2,44 +2,56 @@ from django.contrib import admin ...@@ -2,44 +2,56 @@ from django.contrib import admin
from .models import * from .models import *
from django.apps import apps from django.apps import apps
@admin.register(Bibliography) @admin.register(Bibliography)
class BibliographyAdmin(admin.ModelAdmin): class BibliographyAdmin(admin.ModelAdmin):
list_display = ('authors_list', 'title', 'journal_name', 'biblio_year', 'id_source') list_display = ('authors_list', 'title',
'journal_name', 'biblio_year', 'id_source')
@admin.register(Protein) @admin.register(Protein)
class ProteinAdmin(admin.ModelAdmin): class ProteinAdmin(admin.ModelAdmin):
list_display = ('uniprot_id', 'recommended_name_long') list_display = ('uniprot_id', 'recommended_name_long')
@admin.register(Taxonomy) @admin.register(Taxonomy)
class TaxonomyAdmin(admin.ModelAdmin): class TaxonomyAdmin(admin.ModelAdmin):
list_display = ('taxonomy_id', 'name') list_display = ('taxonomy_id', 'name')
@admin.register(Domain) @admin.register(Domain)
class DomainAdmin(admin.ModelAdmin): class DomainAdmin(admin.ModelAdmin):
list_display = ('pfam_acc', 'pfam_id', 'pfam_description', 'domain_family') list_display = ('pfam_acc', 'pfam_id', 'pfam_description', 'domain_family')
@admin.register(ProteinDomainBoundComplex) @admin.register(ProteinDomainBoundComplex)
class ProteinDomainBoundComplexAdmin(admin.ModelAdmin): class ProteinDomainBoundComplexAdmin(admin.ModelAdmin):
list_display = ('protein', 'domain', 'ppc_copy_nb', 'ppp_copy_nb_per_p') list_display = ('protein', 'domain', 'ppc_copy_nb', 'ppp_copy_nb_per_p')
list_display_links = ('protein', 'domain', 'ppc_copy_nb', 'ppp_copy_nb_per_p') list_display_links = (
'protein', 'domain', 'ppc_copy_nb', 'ppp_copy_nb_per_p')
@admin.register(ProteinDomainPartnerComplex) @admin.register(ProteinDomainPartnerComplex)
class ProteinDomainPartnerComplexAdmin(admin.ModelAdmin): class ProteinDomainPartnerComplexAdmin(admin.ModelAdmin):
list_display = ('protein', 'domain', 'ppc_copy_nb') list_display = ('protein', 'domain', 'ppc_copy_nb')
list_display_links = ('protein', 'domain', 'ppc_copy_nb') list_display_links = ('protein', 'domain', 'ppc_copy_nb')
@admin.register(Symmetry) @admin.register(Symmetry)
class Symmetry(admin.ModelAdmin): class Symmetry(admin.ModelAdmin):
list_display = ('code', 'description') list_display = ('code', 'description')
@admin.register(MDDRCompoundImport) @admin.register(MDDRCompoundImport)
class MDDRCompoundImport(admin.ModelAdmin): class MDDRCompoundImport(admin.ModelAdmin):
list_display = ('mddr_name', 'dvpmt_phase', 'canonical_smile') list_display = ('mddr_name', 'dvpmt_phase', 'canonical_smile')
@admin.register(Compound) @admin.register(Compound)
class Compound(admin.ModelAdmin): class Compound(admin.ModelAdmin):
list_display = ('iupac_name', 'common_name', 'canonical_smile') list_display = ('iupac_name', 'common_name', 'canonical_smile')
@admin.register(TestActivityDescription) @admin.register(TestActivityDescription)
class TextActivityDescription(admin.ModelAdmin): class TextActivityDescription(admin.ModelAdmin):
list_display = ('test_name', 'test_type', 'test_modulation_type') list_display = ('test_name', 'test_type', 'test_modulation_type')
...@@ -57,5 +69,3 @@ admin.site.site_title = admin.site.site_header ...@@ -57,5 +69,3 @@ admin.site.site_title = admin.site.site_header
admin.site.index_header = 'iPPI-DB administration' admin.site.index_header = 'iPPI-DB administration'
admin.site.index_title = admin.site.index_header admin.site.index_title = admin.site.index_header
from django.forms import ModelForm,modelformset_factory,formset_factory from django.forms import ModelForm, modelformset_factory, formset_factory
from django import forms from django import forms
from django.db import models from django.db import models
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -7,84 +7,102 @@ from django.core.validators import RegexValidator ...@@ -7,84 +7,102 @@ from django.core.validators import RegexValidator
from .models import Bibliography, Protein, ProteinDomainComplex, Ppi, PpiComplex from .models import Bibliography, Protein, ProteinDomainComplex, Ppi, PpiComplex
from .ws import pdb_entry_exists from .ws import pdb_entry_exists
class IdForm(ModelForm): class IdForm(ModelForm):
class Meta: class Meta:
model = Bibliography model = Bibliography
fields = ['source','id_source'] fields = ['source', 'id_source']
widgets = { widgets = {
'source' : forms.RadioSelect, 'source': forms.RadioSelect,
'id_source': forms.TextInput(attrs={'placeholder': 'ID'}), 'id_source': forms.TextInput(attrs={'placeholder': 'ID'}),
} }
class BibliographyForm(ModelForm): class BibliographyForm(ModelForm):
class Meta: class Meta:
model = Bibliography model = Bibliography
exclude = ['authors_list', 'biblio_year'] exclude = ['authors_list', 'biblio_year']
widgets = { widgets = {
'source': forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}), 'source': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'id_source': forms.TextInput(attrs={'readonly':'readonly', 'class':'readonly'}), 'id_source': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'title': forms.TextInput(attrs={'readonly':'readonly', 'class':'readonly'}), 'title': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'journal_name': forms.TextInput(attrs={'readonly':'readonly', 'class':'readonly'}), 'journal_name': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
} }
def validate_pdb_exists(value): def validate_pdb_exists(value):
if not(pdb_entry_exists(value)): if not(pdb_entry_exists(value)):
raise ValidationError('PDB entry not found: %(value)s', params={'value': value}, code='invalid') raise ValidationError(
'PDB entry not found: %(value)s', params={'value': value}, code='invalid')
class PDBForm(forms.Form): class PDBForm(forms.Form):
pdb_id = forms.CharField(label="PDB ID",max_length=4, widget=forms.TextInput(attrs={'placeholder': 'e.g 4HHB', 'required':'required'}), required=True, validators=[ pdb_id = forms.CharField(label="PDB ID", max_length=4, widget=forms.TextInput(attrs={'placeholder': 'e.g 4HHB', 'required': 'required'}), required=True, validators=[
RegexValidator('^[0-9][a-zA-Z0-9]{3}$', message='PDB ID must be 1 numeric + 3 alphanumeric characters'), RegexValidator(
'^[0-9][a-zA-Z0-9]{3}$', message='PDB ID must be 1 numeric + 3 alphanumeric characters'),
validate_pdb_exists validate_pdb_exists
]) ])
PDBFormSet = formset_factory(PDBForm) PDBFormSet = formset_factory(PDBForm)
formset=PDBFormSet() formset = PDBFormSet()
class ProteinForm(ModelForm): class ProteinForm(ModelForm):
class Meta:
model = Protein class Meta:
exclude = ['recommended_name_long', 'short_name'] model = Protein
widgets = { exclude = ['recommended_name_long', 'short_name']
'uniprot_id' : forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}), widgets = {
'gene_name' : forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}), 'uniprot_id': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'entry_name' : forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}), 'gene_name': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'organism': forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}), 'entry_name': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'organism': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
} }
ProteinFormSet = modelformset_factory(Protein, exclude=('recommended_name_long', 'short_name'), extra=0) ProteinFormSet = modelformset_factory(
Protein, exclude=('recommended_name_long', 'short_name'), extra=0)
TYPE_CHOICES = ( TYPE_CHOICES = (
('Hetero2merAB','Inhib_Hetero 2-mer AB'), ('Hetero2merAB', 'Inhib_Hetero 2-mer AB'),
('Homo2merA2','Inhib_Homo 2-mer A2'), ('Homo2merA2', 'Inhib_Homo 2-mer A2'),
('custom', 'Inhib_Custom your own'), ('custom', 'Inhib_Custom your own'),
('Hetero2merAB','Stab_Hetero 2-mer AB'), ('Hetero2merAB', 'Stab_Hetero 2-mer AB'),
('Homo2merA2','Stab_Homo 2-mer A2'), ('Homo2merA2', 'Stab_Homo 2-mer A2'),
('HomoLike2mer','Stab_Homo-Like 2-mer A2'), ('HomoLike2mer', 'Stab_Homo-Like 2-mer A2'),
('Homo3merA3','Stab_Homo 3-mer A3'), ('Homo3merA3', 'Stab_Homo 3-mer A3'),
('Homo3merA2','Stab_Homo 3-mer A3 inhibited A2-dimer'), ('Homo3merA2', 'Stab_Homo 3-mer A3 inhibited A2-dimer'),
('Homo4merA4','Stab_Homo 4-mer A4'), ('Homo4merA4', 'Stab_Homo 4-mer A4'),
('RingHomo3mer','Stab_Ring-Like 3-mer A3'), ('RingHomo3mer', 'Stab_Ring-Like 3-mer A3'),
('RingHomo5mer','Stab_Ring-Like 5-mer A5'), ('RingHomo5mer', 'Stab_Ring-Like 5-mer A5'),
('custom', 'Stab_Custom your own'), ('custom', 'Stab_Custom your own'),
) )
class ProteinDomainComplexTypeForm(forms.Form): class ProteinDomainComplexTypeForm(forms.Form):
complexType = forms.ChoiceField( complexType = forms.ChoiceField(
widget=forms.RadioSelect, widget=forms.RadioSelect,
choices=TYPE_CHOICES, choices=TYPE_CHOICES,
) )
class ProteinDomainComplexForm(ModelForm): class ProteinDomainComplexForm(ModelForm):
class Meta:
model = ProteinDomainComplex class Meta:
fields = ['protein', 'domain', 'ppc_copy_nb'] model = ProteinDomainComplex
fields = ['protein', 'domain', 'ppc_copy_nb']
class PpiForm(ModelForm): class PpiForm(ModelForm):
class Meta:
model = Ppi class Meta:
fields = ['pdb_id', 'symmetry'] model = Ppi
fields = ['pdb_id', 'symmetry']
class PpiComplexForm(ModelForm): class PpiComplexForm(ModelForm):
class Meta:
model = PpiComplex class Meta:
fields = ['complex', 'cc_nb'] model = PpiComplex
fields = ['complex', 'cc_nb']
...@@ -2,14 +2,17 @@ from bioblend.galaxy import GalaxyInstance ...@@ -2,14 +2,17 @@ from bioblend.galaxy import GalaxyInstance
from bioblend.galaxy.tools.inputs import inputs from bioblend.galaxy.tools.inputs import inputs
workflow_id = 'dad6103ff71ca4fe' workflow_id = 'dad6103ff71ca4fe'
galaxy_url = 'https://galaxy-dev.web.pasteur.fr' galaxy_url = 'https://galaxy-dev.web.pasteur.fr'
api_key = '21c2ce387688b1a785040762f7c9c331' api_key = '21c2ce387688b1a785040762f7c9c331'
def run_workflow_and_get_results(input_file): def run_workflow_and_get_results(input_file):
gi = GalaxyInstance(galaxy_url, key=api_key) gi = GalaxyInstance(galaxy_url, key=api_key)
gi.verify = False gi.verify = False
history_id = gi.histories.create_history("ippidb_history")['id'] history_id = gi.histories.create_history("ippidb_history")['id']
dataset_id = gi.tools.upload_file(input_file, history_id)['outputs'][0]['id'] dataset_id = gi.tools.upload_file(
inputs = {'0':{'id':dataset_id, 'src': 'hda' }} input_file, history_id)['outputs'][0]['id']
workflow_run = gi.workflows.invoke_workflow(workflow_id, inputs=inputs, history_id=history_id) inputs = {'0': {'id': dataset_id, 'src': 'hda'}}
print(workflow_run) workflow_run = gi.workflows.invoke_workflow(
workflow_id, inputs=inputs, history_id=history_id)
print(workflow_run)
This diff is collapsed.
This diff is collapsed.
from django.conf.urls import include,url from django.conf.urls import include, url
from . import views from . import views
from ippidb.forms import IdForm, BibliographyForm,PDBForm,ProteinDomainComplexTypeForm,ProteinDomainComplexForm,PpiForm from ippidb.forms import IdForm, BibliographyForm, PDBForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm
from ippidb.views import IppiWizard,FORMS from ippidb.views import IppiWizard, FORMS
ippidb_wizard = IppiWizard.as_view(FORMS, ippidb_wizard = IppiWizard.as_view(FORMS,
url_name='ippidb_step') url_name='ippidb_step')
urlpatterns = [ urlpatterns = [
...@@ -12,14 +12,17 @@ urlpatterns = [ ...@@ -12,14 +12,17 @@ urlpatterns = [
url(r'^about$', views.about, name='about'), url(r'^about$', views.about, name='about'),
url(r'^about/general/$', views.general, name='general'), url(r'^about/general/$', views.general, name='general'),
url(r'^about/pharmacology/$', views.pharmacology, name='pharmacology'), url(r'^about/pharmacology/$', views.pharmacology, name='pharmacology'),
url(r'^about/physicochemistry/$', views.physicochemistry, name='physicochemistry'), url(r'^about/physicochemistry/$',
url(r'^about/drug-candidate/$', views.drugCandidate, name='drug-candidate'), views.physicochemistry, name='physicochemistry'),
url(r'^about/drug-candidate/$',
views.drugCandidate, name='drug-candidate'),
url(r'^query$', views.query, name='query'), url(r'^query$', views.query, name='query'),
url(r'^query/pharma/$', views.pharma, name='pharma'), url(r'^query/pharma/$', views.pharma, name='pharma'),
url(r'^query/chemical/$', views.chemical, name='chemical'), url(r'^query/chemical/$', views.chemical, name='chemical'),
url(r'^tutorials$', views.tutorials, name='tutorials'), url(r'^tutorials$', views.tutorials, name='tutorials'),
url(r'^admin-session$', views.adminSession, name='admin-session'), url(r'^admin-session$', views.adminSession, name='admin-session'),
url(r'^admin-session/add/(?P<step>.+)/$', ippidb_wizard, name='ippidb_step'), url(r'^admin-session/add/(?P<step>.+)/$',
ippidb_wizard, name='ippidb_step'),
url(r'^admin-session/add/$', ippidb_wizard, name='ippidb'), url(r'^admin-session/add/$', ippidb_wizard, name='ippidb'),
] ]
......
...@@ -2,50 +2,62 @@ import ippidb ...@@ -2,50 +2,62 @@ import ippidb
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from formtools.wizard.views import SessionWizardView,NamedUrlSessionWizardView from formtools.wizard.views import SessionWizardView, NamedUrlSessionWizardView
from .forms import IdForm, BibliographyForm, PDBForm, ProteinForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm, ProteinFormSet, PDBFormSet from .forms import IdForm, BibliographyForm, PDBForm, ProteinForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm, ProteinFormSet, PDBFormSet
from .models import Protein, Bibliography from .models import Protein, Bibliography
from .ws import get_pdb_uniprot_mapping from .ws import get_pdb_uniprot_mapping
def index(request): def index(request):
return render(request, 'index.html') return render(request, 'index.html')
def about(request): def about(request):
return render(request, 'about.html') return render(request, 'about.html')
def general(request): def general(request):
return render(request, 'general.html') return render(request, 'general.html')
def pharmacology(request): def pharmacology(request):
return render(request, 'pharmacology.html') return render(request, 'pharmacology.html')
def physicochemistry(request): def physicochemistry(request):
return render(request, 'physicochemistry.html') return render(request, 'physicochemistry.html')
def drugCandidate(request): def drugCandidate(request):
return render(request, 'drug-candidate.html') return render(request, 'drug-candidate.html')
def query(request): def query(request):
return render(request, 'query.html') return render(request, 'query.html')
def pharma(request): def pharma(request):
return render(request, 'pharma.html') return render(request, 'pharma.html')
def chemical(request): def chemical(request):
return render(request, 'chemical.html') return render(request, 'chemical.html')
def tutorials(request): def tutorials(request):
return render(request, 'tutorials.html') return render(request, 'tutorials.html')
def adminSession(request): def adminSession(request):
return render(request, 'admin-session.html') return render(request, 'admin-session.html')
FORMS = [("IdForm", ippidb.forms.IdForm), FORMS = [("IdForm", ippidb.forms.IdForm),
("BibliographyForm", ippidb.forms.BibliographyForm), ("BibliographyForm", ippidb.forms.BibliographyForm),
("PDBForm", ippidb.forms.PDBFormSet), ("PDBForm", ippidb.forms.PDBFormSet),
("ProteinForm",ippidb.forms.ProteinFormSet), ("ProteinForm", ippidb.forms.ProteinFormSet),
("ProteinDomainComplexTypeForm", ippidb.forms.ProteinDomainComplexTypeForm), ("ProteinDomainComplexTypeForm",
ippidb.forms.ProteinDomainComplexTypeForm),
("ProteinDomainComplexForm", ippidb.forms.ProteinDomainComplexForm), ("ProteinDomainComplexForm", ippidb.forms.ProteinDomainComplexForm),
("PpiForm", ippidb.forms.PpiForm)] ("PpiForm", ippidb.forms.PpiForm)]
...@@ -53,19 +65,21 @@ TEMPLATES = {"IdForm": "IdForm.html", ...@@ -53,19 +65,21 @@ TEMPLATES = {"IdForm": "IdForm.html",
"BibliographyForm": "BibliographyForm.html", "BibliographyForm": "BibliographyForm.html",
"PDBForm": "PDBForm.html", "PDBForm": "PDBForm.html",
"ProteinForm": "ProteinForm.html", "ProteinForm": "ProteinForm.html",
"ProteinDomainComplexTypeForm":"ProteinDomainComplexTypeForm.html", "ProteinDomainComplexTypeForm": "ProteinDomainComplexTypeForm.html",
"ProteinDomainComplexForm": "ProteinDomainComplexForm.html", "ProteinDomainComplexForm": "ProteinDomainComplexForm.html",
"PpiForm": "PpiForm.html"} "PpiForm": "PpiForm.html"}
class IppiWizard(NamedUrlSessionWizardView): class IppiWizard(NamedUrlSessionWizardView):
def get_template_names(self): def get_template_names(self):
return [TEMPLATES[self.steps.current]] return [TEMPLATES[self.steps.current]]
def get_form_instance(self, step): def get_form_instance(self, step):
if self.steps.current=='BibliographyForm': if self.steps.current == 'BibliographyForm':
pk = self.storage.get_step_data('IdForm').get('pk') pk = self.storage.get_step_data('IdForm').get('pk')
return Bibliography.objects.get(pk=pk) return Bibliography.objects.get(pk=pk)
if self.steps.current=='ProteinForm': if self.steps.current == 'ProteinForm':
pks = self.storage.get_step_data('PDBForm').get('pks') pks = self.storage.get_step_data('PDBForm').get('pks')
return Protein.objects.filter(id__in=pks) return Protein.objects.filter(id__in=pks)
...@@ -76,12 +90,12 @@ class IppiWizard(NamedUrlSessionWizardView): ...@@ -76,12 +90,12 @@ class IppiWizard(NamedUrlSessionWizardView):
when appropriate when appropriate
""" """
data = super(IppiWizard, self).process_step(form).copy() data = super(IppiWizard, self).process_step(form).copy()
if self.steps.current=='IdForm': if self.steps.current == 'IdForm':
form.instance.autofill() form.instance.autofill()
if self.steps.current in ['IdForm', 'Bibliography']: if self.steps.current in ['IdForm', 'Bibliography']:
form.instance.save() form.instance.save()
data['pk'] = form.instance.id data['pk'] = form.instance.id
if self.steps.current=='PDBForm': if self.steps.current == 'PDBForm':
pdb_ids = [form['pdb_id'] for form in form.cleaned_data] pdb_ids = [form['pdb_id'] for form in form.cleaned_data]
uniprot_ids = [] uniprot_ids = []
protein_ids = [] protein_ids = []
...@@ -103,4 +117,3 @@ class IppiWizard(NamedUrlSessionWizardView): ...@@ -103,4 +117,3 @@ class IppiWizard(NamedUrlSessionWizardView):
return render(self.request, '/admin-session/add.html', { return render(self.request, '/admin-session/add.html', {
'form_data': [form.cleaned_data for form in form_list], 'form_data': [form.cleaned_data for form in form_list],
}) })
...@@ -3,12 +3,15 @@ from bioservices.uniprot import UniProt ...@@ -3,12 +3,15 @@ from bioservices.uniprot import UniProt
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import requests import requests
def get_pubmed_info(pmid): def get_pubmed_info(pmid):
eu = EUtils() eu = EUtils()
r = eu.EFetch('pubmed', pmid, retmode='dict', rettype='abstract') r = eu.EFetch('pubmed', pmid, retmode='dict', rettype='abstract')
article = r['PubmedArticleSet']['PubmedArticle']['MedlineCitation']['Article'] article = r['PubmedArticleSet'][
'PubmedArticle']['MedlineCitation']['Article']
title = article['ArticleTitle'] title = article['ArticleTitle']
authors_list = [a['LastName']+ ' ' + a['Initials'] for a in article['AuthorList']['Author']] authors_list = [a['LastName'] + ' ' + a['Initials']
for a in article['AuthorList']['Author']]
authors = ', '.join(authors_list) authors = ', '.join(authors_list)
journal_name = article['Journal']['Title'] journal_name = article['Journal']['Title']
biblio_date = article['Journal']['JournalIssue']['PubDate'] biblio_date = article['Journal']['JournalIssue']['PubDate']
...@@ -16,60 +19,76 @@ def get_pubmed_info(pmid): ...@@ -16,60 +19,76 @@ def get_pubmed_info(pmid):
biblio_year = biblio_date['Year'] biblio_year = biblio_date['Year']
else: else:
biblio_year = biblio_date['MedlineDate'][0:3] biblio_year = biblio_date['MedlineDate'][0:3]
return {'title':title, return {'title': title,
'journal_name':journal_name, 'journal_name': journal_name,
'biblio_year':biblio_year, 'biblio_year': biblio_year,
'authors_list': authors} 'authors_list': authors}
def get_epo_info(patent_number): def get_epo_info(patent_number):
resp = requests.get('http://ops.epo.org/3.1/rest-services/published-data/publication/docdb/{}/biblio.json'.format(patent_number)) resp = requests.get(
'http://ops.epo.org/3.1/rest-services/published-data/publication/docdb/{}/biblio.json'.format(patent_number))
data = resp.json() data = resp.json()
exchange_doc = data['ops:world-patent-data']['exchange-documents']['exchange-document'] exchange_doc = data['ops:world-patent-data'][
'exchange-documents']['exchange-document']
if isinstance(exchange_doc, list): if isinstance(exchange_doc, list):
exchange_doc = exchange_doc[0] exchange_doc = exchange_doc[0]
title = [el['$'] for el in exchange_doc['bibliographic-data']['invention-title'] if el['@lang']=='en'] title = [el['$']
authors = [i['inventor-name']['name']['$'] for i in exchange_doc['bibliographic-data']['parties']['inventors']['inventor'] if i['@data-format']=='original'] for el in exchange_doc['bibliographic-data']['invention-title'] if el['@lang'] == 'en']
biblio_year = [el['date']['$'][:4] for el in exchange_doc['bibliographic-data']['publication-reference']['document-id'] if el['@document-id-type']=='epodoc'][0] authors = [i['inventor-name']['name']['$']
for i in exchange_doc['bibliographic-data']['parties']['inventors']['inventor'] if i['@data-format'] == 'original']
biblio_year = [el['date']['$'][:4]
for el in exchange_doc['bibliographic-data']['publication-reference']['document-id'] if el['@document-id-type'] == 'epodoc'][0]
return {'title': title, return {'title': title,
'journal_name': None, 'journal_name': None,
'biblio_year': biblio_year, 'biblio_year': biblio_year,
'authors_list': authors} 'authors_list': authors}
def get_uniprot_info(uniprot_id): def get_uniprot_info(uniprot_id):
uniprot_client = UniProt() uniprot_client = UniProt()
ns = {'u':'http://uniprot.org/uniprot'} ns = {'u': 'http://uniprot.org/uniprot'}
resp = uniprot_client.retrieve(uniprot_id) resp = uniprot_client.retrieve(uniprot_id)
recommended_name = resp.root.findall('u:entry/u:protein/u:recommendedName/u:fullName', ns)[0].text recommended_name = resp.root.findall(
organism = resp.root.findall('u:entry/u:organism/u:dbReference[@type="NCBI Taxonomy"]', ns)[0].attrib['id'] 'u:entry/u:protein/u:recommendedName/u:fullName', ns)[0].text
gene = resp.root.findall('u:entry/u:gene/u:name[@type="primary"]', ns)[0].text organism = resp.root.findall(
'u:entry/u:organism/u:dbReference[@type="NCBI Taxonomy"]', ns)[0].attrib['id']
gene = resp.root.findall(
'u:entry/u:gene/u:name[@type="primary"]', ns)[0].text
entry_name = resp.root.findall('u:entry/u:name', ns)[0].text entry_name = resp.root.findall('u:entry/u:name', ns)[0].text
go_els = resp.root.findall('u:entry/u:dbReference[@type="GO"]', ns) go_els = resp.root.findall('u:entry/u:dbReference[@type="GO"]', ns)
molecular_functions = [] molecular_functions = []
for go_el in go_els: for go_el in go_els:
term_property_value = go_el.findall('u:property[@type="term"]', ns)[0].attrib['value'] term_property_value = go_el.findall(
if term_property_value[0:2]=='F:': 'u:property[@type="term"]', ns)[0].attrib['value']
molecular_functions.append('GO_'+go_el.attrib['id'][3:]) if term_property_value[0:2] == 'F:':
molecular_functions.append('GO_' + go_el.attrib['id'][3:])
return {'recommended_name': recommended_name, return {'recommended_name': recommended_name,
'organism': int(organism), 'organism': int(organism),
'gene': gene, 'gene': gene,
'entry_name': entry_name, 'entry_name': entry_name,
'molecular_functions': molecular_functions 'molecular_functions': molecular_functions
} }
def get_go_info(go_id): def get_go_info(go_id):
resp = requests.get('https://www.ebi.ac.uk/ols/api/ontologies/go/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252F{}'.format(go_id)) resp = requests.get(
'https://www.ebi.ac.uk/ols/api/ontologies/go/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252F{}'.format(go_id))
data = resp.json() data = resp.json()
label = data['label'] label = data['label']
return {'label': label} return {'label': label}
def get_taxonomy_info(taxonomy_id): def get_taxonomy_info(taxonomy_id):
eu = EUtils() eu = EUtils()
r = eu.EFetch('taxonomy', taxonomy_id, retmode='dict') r = eu.EFetch('taxonomy', taxonomy_id, retmode='dict')
scientific_name = r['TaxaSet']['Taxon']['ScientificName'] scientific_name = r['TaxaSet']['Taxon']['ScientificName']
return {'scientific_name': scientific_name} return {'scientific_name': scientific_name}
def get_pfam_info(pfam_acc): def get_pfam_info(pfam_acc):
resp = requests.get('http://pfam.xfam.org/family/{}?output=xml'.format(pfam_acc)) resp = requests.get(
'http://pfam.xfam.org/family/{}?output=xml'.format(pfam_acc))
root = ET.fromstring(resp.text) root = ET.fromstring(resp.text)
ns = {'pfam': 'http://pfam.xfam.org/'} ns = {'pfam': 'http://pfam.xfam.org/'}
entry = root.findall('pfam:entry', ns)[0] entry = root.findall('pfam:entry', ns)[0]
...@@ -79,14 +98,18 @@ def get_pfam_info(pfam_acc): ...@@ -79,14 +98,18 @@ def get_pfam_info(pfam_acc):
return {'id': pfam_id, return {'id': pfam_id,
'description': description} 'description': description}
def get_pdb_uniprot_mapping(pdb_id): def get_pdb_uniprot_mapping(pdb_id):
resp = requests.get('https://www.ebi.ac.uk/pdbe/api/mappings/uniprot/{}'.format(pdb_id.lower())) resp = requests.get(
'https://www.ebi.ac.uk/pdbe/api/mappings/uniprot/{}'.format(pdb_id.lower()))
uniprot_ids = list(resp.json()[pdb_id]['UniProt'].keys()) uniprot_ids = list(resp.json()[pdb_id]['UniProt'].keys())
return uniprot_ids return uniprot_ids
def pdb_entry_exists(pdb_id): def pdb_entry_exists(pdb_id):
""" test if a PDB entry exists using EBI web services """ """ test if a PDB entry exists using EBI web services """
resp = requests.get('https://www.ebi.ac.uk/pdbe/api/pdb/entry/summary/{}'.format(pdb_id.lower())) resp = requests.get(
'https://www.ebi.ac.uk/pdbe/api/pdb/entry/summary/{}'.format(pdb_id.lower()))
# EBI sends back either a 404 or an empty json if the PDB does not exist # EBI sends back either a 404 or an empty json if the PDB does not exist
if not(resp.ok): if not(resp.ok):
return False return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment