Commit c5fb2869 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

autopep8 code


Former-commit-id: e4a2b89495247a4954b8046c445d85df5888f0b5
parent a0c493d7
......@@ -2,44 +2,56 @@ from django.contrib import admin
from .models import *
from django.apps import apps
@admin.register(Bibliography)
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)
class ProteinAdmin(admin.ModelAdmin):
list_display = ('uniprot_id', 'recommended_name_long')
@admin.register(Taxonomy)
class TaxonomyAdmin(admin.ModelAdmin):
list_display = ('taxonomy_id', 'name')
@admin.register(Domain)
class DomainAdmin(admin.ModelAdmin):
list_display = ('pfam_acc', 'pfam_id', 'pfam_description', 'domain_family')
@admin.register(ProteinDomainBoundComplex)
class ProteinDomainBoundComplexAdmin(admin.ModelAdmin):
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)
class ProteinDomainPartnerComplexAdmin(admin.ModelAdmin):
list_display = ('protein', 'domain', 'ppc_copy_nb')
list_display_links = ('protein', 'domain', 'ppc_copy_nb')
@admin.register(Symmetry)
class Symmetry(admin.ModelAdmin):
list_display = ('code', 'description')
@admin.register(MDDRCompoundImport)
class MDDRCompoundImport(admin.ModelAdmin):
list_display = ('mddr_name', 'dvpmt_phase', 'canonical_smile')
@admin.register(Compound)
class Compound(admin.ModelAdmin):
list_display = ('iupac_name', 'common_name', 'canonical_smile')
@admin.register(TestActivityDescription)
class TextActivityDescription(admin.ModelAdmin):
list_display = ('test_name', 'test_type', 'test_modulation_type')
......@@ -57,5 +69,3 @@ admin.site.site_title = admin.site.site_header
admin.site.index_header = 'iPPI-DB administration'
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.db import models
from django.core.exceptions import ValidationError
......@@ -7,84 +7,102 @@ from django.core.validators import RegexValidator
from .models import Bibliography, Protein, ProteinDomainComplex, Ppi, PpiComplex
from .ws import pdb_entry_exists
class IdForm(ModelForm):
class Meta:
model = Bibliography
fields = ['source','id_source']
fields = ['source', 'id_source']
widgets = {
'source' : forms.RadioSelect,
'source': forms.RadioSelect,
'id_source': forms.TextInput(attrs={'placeholder': 'ID'}),
}
class BibliographyForm(ModelForm):
class Meta:
model = Bibliography
exclude = ['authors_list', 'biblio_year']
widgets = {
'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'}),
'journal_name': forms.TextInput(attrs={'readonly':'readonly', 'class':'readonly'}),
'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'}),
'journal_name': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
}
def validate_pdb_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):
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'),
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'),
validate_pdb_exists
])
])
PDBFormSet = formset_factory(PDBForm)
formset=PDBFormSet()
formset = PDBFormSet()
class ProteinForm(ModelForm):
class Meta:
model = Protein
exclude = ['recommended_name_long', 'short_name']
widgets = {
'uniprot_id' : forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}),
'gene_name' : forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}),
'entry_name' : forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}),
'organism': forms.TextInput(attrs={'readonly':'readonly','class':'readonly'}),
class Meta:
model = Protein
exclude = ['recommended_name_long', 'short_name']
widgets = {
'uniprot_id': forms.TextInput(attrs={'readonly': 'readonly', 'class': 'readonly'}),
'gene_name': 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 = (
('Hetero2merAB','Inhib_Hetero 2-mer AB'),
('Homo2merA2','Inhib_Homo 2-mer A2'),
('custom', 'Inhib_Custom your own'),
('Hetero2merAB','Stab_Hetero 2-mer AB'),
('Homo2merA2','Stab_Homo 2-mer A2'),
('HomoLike2mer','Stab_Homo-Like 2-mer A2'),
('Homo3merA3','Stab_Homo 3-mer A3'),
('Homo3merA2','Stab_Homo 3-mer A3 inhibited A2-dimer'),
('Homo4merA4','Stab_Homo 4-mer A4'),
('RingHomo3mer','Stab_Ring-Like 3-mer A3'),
('RingHomo5mer','Stab_Ring-Like 5-mer A5'),
('custom', 'Stab_Custom your own'),
)
('Hetero2merAB', 'Inhib_Hetero 2-mer AB'),
('Homo2merA2', 'Inhib_Homo 2-mer A2'),
('custom', 'Inhib_Custom your own'),
('Hetero2merAB', 'Stab_Hetero 2-mer AB'),
('Homo2merA2', 'Stab_Homo 2-mer A2'),
('HomoLike2mer', 'Stab_Homo-Like 2-mer A2'),
('Homo3merA3', 'Stab_Homo 3-mer A3'),
('Homo3merA2', 'Stab_Homo 3-mer A3 inhibited A2-dimer'),
('Homo4merA4', 'Stab_Homo 4-mer A4'),
('RingHomo3mer', 'Stab_Ring-Like 3-mer A3'),
('RingHomo5mer', 'Stab_Ring-Like 5-mer A5'),
('custom', 'Stab_Custom your own'),
)
class ProteinDomainComplexTypeForm(forms.Form):
complexType = forms.ChoiceField(
widget=forms.RadioSelect,
choices=TYPE_CHOICES,
)
)
class ProteinDomainComplexForm(ModelForm):
class Meta:
model = ProteinDomainComplex
fields = ['protein', 'domain', 'ppc_copy_nb']
class Meta:
model = ProteinDomainComplex
fields = ['protein', 'domain', 'ppc_copy_nb']
class PpiForm(ModelForm):
class Meta:
model = Ppi
fields = ['pdb_id', 'symmetry']
class Meta:
model = Ppi
fields = ['pdb_id', 'symmetry']
class PpiComplexForm(ModelForm):
class Meta:
model = PpiComplex
fields = ['complex', 'cc_nb']
class Meta:
model = PpiComplex
fields = ['complex', 'cc_nb']
......@@ -2,14 +2,17 @@ from bioblend.galaxy import GalaxyInstance
from bioblend.galaxy.tools.inputs import inputs
workflow_id = 'dad6103ff71ca4fe'
galaxy_url = 'https://galaxy-dev.web.pasteur.fr'
galaxy_url = 'https://galaxy-dev.web.pasteur.fr'
api_key = '21c2ce387688b1a785040762f7c9c331'
def run_workflow_and_get_results(input_file):
gi = GalaxyInstance(galaxy_url, key=api_key)
gi.verify = False
history_id = gi.histories.create_history("ippidb_history")['id']
dataset_id = gi.tools.upload_file(input_file, history_id)['outputs'][0]['id']
inputs = {'0':{'id':dataset_id, 'src': 'hda' }}
workflow_run = gi.workflows.invoke_workflow(workflow_id, inputs=inputs, history_id=history_id)
print(workflow_run)
dataset_id = gi.tools.upload_file(
input_file, history_id)['outputs'][0]['id']
inputs = {'0': {'id': dataset_id, 'src': 'hda'}}
workflow_run = gi.workflows.invoke_workflow(
workflow_id, inputs=inputs, history_id=history_id)
print(workflow_run)
This diff is collapsed.
from django.conf.urls import include,url
from django.conf.urls import include, url
from . import views
from ippidb.forms import IdForm, BibliographyForm,PDBForm,ProteinDomainComplexTypeForm,ProteinDomainComplexForm,PpiForm
from ippidb.views import IppiWizard,FORMS
from ippidb.forms import IdForm, BibliographyForm, PDBForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm
from ippidb.views import IppiWizard, FORMS
ippidb_wizard = IppiWizard.as_view(FORMS,
url_name='ippidb_step')
url_name='ippidb_step')
urlpatterns = [
......@@ -12,14 +12,17 @@ urlpatterns = [
url(r'^about$', views.about, name='about'),
url(r'^about/general/$', views.general, name='general'),
url(r'^about/pharmacology/$', views.pharmacology, name='pharmacology'),
url(r'^about/physicochemistry/$', views.physicochemistry, name='physicochemistry'),
url(r'^about/drug-candidate/$', views.drugCandidate, name='drug-candidate'),
url(r'^about/physicochemistry/$',
views.physicochemistry, name='physicochemistry'),
url(r'^about/drug-candidate/$',
views.drugCandidate, name='drug-candidate'),
url(r'^query$', views.query, name='query'),
url(r'^query/pharma/$', views.pharma, name='pharma'),
url(r'^query/chemical/$', views.chemical, name='chemical'),
url(r'^tutorials$', views.tutorials, name='tutorials'),
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$', views.adminSession, name='admin-session'),
url(r'^admin-session/add/(?P<step>.+)/$',
ippidb_wizard, name='ippidb_step'),
url(r'^admin-session/add/$', ippidb_wizard, name='ippidb'),
]
......
......@@ -2,50 +2,62 @@ import ippidb
from django.shortcuts import render
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 .models import Protein, Bibliography
from .ws import get_pdb_uniprot_mapping
def index(request):
return render(request, 'index.html')
def about(request):
return render(request, 'about.html')
def general(request):
return render(request, 'general.html')
def pharmacology(request):
return render(request, 'pharmacology.html')
def physicochemistry(request):
return render(request, 'physicochemistry.html')
def drugCandidate(request):
return render(request, 'drug-candidate.html')
def query(request):
return render(request, 'query.html')
def pharma(request):
return render(request, 'pharma.html')
def chemical(request):
return render(request, 'chemical.html')
def tutorials(request):
return render(request, 'tutorials.html')
def adminSession(request):
return render(request, 'admin-session.html')
FORMS = [("IdForm", ippidb.forms.IdForm),
("BibliographyForm", ippidb.forms.BibliographyForm),
("PDBForm", ippidb.forms.PDBFormSet),
("ProteinForm",ippidb.forms.ProteinFormSet),
("ProteinDomainComplexTypeForm", ippidb.forms.ProteinDomainComplexTypeForm),
("ProteinForm", ippidb.forms.ProteinFormSet),
("ProteinDomainComplexTypeForm",
ippidb.forms.ProteinDomainComplexTypeForm),
("ProteinDomainComplexForm", ippidb.forms.ProteinDomainComplexForm),
("PpiForm", ippidb.forms.PpiForm)]
......@@ -53,19 +65,21 @@ TEMPLATES = {"IdForm": "IdForm.html",
"BibliographyForm": "BibliographyForm.html",
"PDBForm": "PDBForm.html",
"ProteinForm": "ProteinForm.html",
"ProteinDomainComplexTypeForm":"ProteinDomainComplexTypeForm.html",
"ProteinDomainComplexTypeForm": "ProteinDomainComplexTypeForm.html",
"ProteinDomainComplexForm": "ProteinDomainComplexForm.html",
"PpiForm": "PpiForm.html"}
class IppiWizard(NamedUrlSessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
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')
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')
return Protein.objects.filter(id__in=pks)
......@@ -76,12 +90,12 @@ class IppiWizard(NamedUrlSessionWizardView):
when appropriate
"""
data = super(IppiWizard, self).process_step(form).copy()
if self.steps.current=='IdForm':
if self.steps.current == 'IdForm':
form.instance.autofill()
if self.steps.current in ['IdForm', 'Bibliography']:
form.instance.save()
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]
uniprot_ids = []
protein_ids = []
......@@ -103,4 +117,3 @@ class IppiWizard(NamedUrlSessionWizardView):
return render(self.request, '/admin-session/add.html', {
'form_data': [form.cleaned_data for form in form_list],
})
......@@ -3,12 +3,15 @@ from bioservices.uniprot import UniProt
import xml.etree.ElementTree as ET
import requests
def get_pubmed_info(pmid):
eu = EUtils()
r = eu.EFetch('pubmed', pmid, retmode='dict', rettype='abstract')
article = r['PubmedArticleSet']['PubmedArticle']['MedlineCitation']['Article']
article = r['PubmedArticleSet'][
'PubmedArticle']['MedlineCitation']['Article']
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)
journal_name = article['Journal']['Title']
biblio_date = article['Journal']['JournalIssue']['PubDate']
......@@ -16,60 +19,76 @@ def get_pubmed_info(pmid):
biblio_year = biblio_date['Year']
else:
biblio_year = biblio_date['MedlineDate'][0:3]
return {'title':title,
'journal_name':journal_name,
'biblio_year':biblio_year,
return {'title': title,
'journal_name': journal_name,
'biblio_year': biblio_year,
'authors_list': authors}
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()
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):
exchange_doc = exchange_doc[0]
title = [el['$'] for el in exchange_doc['bibliographic-data']['invention-title'] if el['@lang']=='en']
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]
title = [el['$']
for el in exchange_doc['bibliographic-data']['invention-title'] if el['@lang'] == 'en']
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,
'journal_name': None,
'biblio_year': biblio_year,
'authors_list': authors}
def get_uniprot_info(uniprot_id):
uniprot_client = UniProt()
ns = {'u':'http://uniprot.org/uniprot'}
ns = {'u': 'http://uniprot.org/uniprot'}
resp = uniprot_client.retrieve(uniprot_id)
recommended_name = resp.root.findall('u:entry/u:protein/u:recommendedName/u:fullName', 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
recommended_name = resp.root.findall(
'u:entry/u:protein/u:recommendedName/u:fullName', 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
go_els = resp.root.findall('u:entry/u:dbReference[@type="GO"]', ns)
molecular_functions = []
for go_el in go_els:
term_property_value = go_el.findall('u:property[@type="term"]', ns)[0].attrib['value']
if term_property_value[0:2]=='F:':
molecular_functions.append('GO_'+go_el.attrib['id'][3:])
term_property_value = go_el.findall(
'u:property[@type="term"]', ns)[0].attrib['value']
if term_property_value[0:2] == 'F:':
molecular_functions.append('GO_' + go_el.attrib['id'][3:])
return {'recommended_name': recommended_name,
'organism': int(organism),
'gene': gene,
'entry_name': entry_name,
'molecular_functions': molecular_functions
}
}
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()
label = data['label']
return {'label': label}
def get_taxonomy_info(taxonomy_id):
eu = EUtils()
r = eu.EFetch('taxonomy', taxonomy_id, retmode='dict')
scientific_name = r['TaxaSet']['Taxon']['ScientificName']
return {'scientific_name': scientific_name}
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)
ns = {'pfam': 'http://pfam.xfam.org/'}
entry = root.findall('pfam:entry', ns)[0]
......@@ -79,14 +98,18 @@ def get_pfam_info(pfam_acc):
return {'id': pfam_id,
'description': description}
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())
return uniprot_ids
def pdb_entry_exists(pdb_id):
""" 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
if not(resp.ok):
return False
......
Supports Markdown
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