Skip to content
Snippets Groups Projects
Commit fce3e3a5 authored by Rachel TORCHET's avatar Rachel TORCHET
Browse files

Change ProteinForm into a ModelFormSet to vizualize multiple protein forms infos based on a PDBid

Former-commit-id: 07e75173ed345e9f263ce83b31a8570f776c4df2
parents ca4c0627 072502fd
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@ class AutoFillableModel(models.Model):
def save(self, *args, **kwargs):
if kwargs.get('autofill') is True:
self.autofill()
if 'autofill' in kwargs:
del kwargs['autofill']
super(AutoFillableModel, self).save(*args, **kwargs)
......@@ -30,7 +32,7 @@ class Bibliography(AutoFillableModel):
('PT', 'Patent'),
('DO', 'DOI ID')
)
source = models.CharField('Bibliographic type', max_length=2, choices=SOURCES)
source = models.CharField('Bibliographic type', max_length=2, choices=SOURCES, default='PM')
id_source = models.CharField('Bibliographic ID', max_length=25)
title = models.CharField('Title', max_length=300)
journal_name = models.CharField('Journal name', max_length=50, null=True)
......@@ -107,7 +109,7 @@ class Protein(AutoFillableModel):
taxonomy.taxonomy_id = info['organism']
taxonomy.save(autofill=True)
self.organism = taxonomy
#super(Protein, self).save(*args, **kwargs)
super(Protein, self).save()
for go_id in info['molecular_functions']:
try:
mol_function = MolecularFunction.objects.get(go_id=go_id)
......
......@@ -2,7 +2,10 @@ import ippidb
from django.shortcuts import render
from django.http import HttpResponseRedirect
from formtools.wizard.views import SessionWizardView,NamedUrlSessionWizardView
from .forms import IdForm, BibliographyForm, PDBForm, ProteinForm, ProteinDomainComplexTypeForm, ProteinDomainComplexForm, PpiForm, ProteinFormSet
from .models import Protein
from .ws import get_pdb_uniprot_mapping
def index(request):
return render(request, 'index.html')
......@@ -48,6 +51,19 @@ class IppiWizard(SessionWizardView):
if self.steps.current=='IdForm':
form.instance.autofill()
self.instance_dict['BibliographyForm'] = form.instance
elif self.steps.current=='PDBForm':
uniprot_ids = get_pdb_uniprot_mapping(form.cleaned_data['pdb_id'])
proteins = []
for uniprot_id in uniprot_ids:
try:
p = Protein.objects.get(uniprot_id=uniprot_id)
except Protein.DoesNotExist:
p = Protein()
p.uniprot_id = uniprot_ids[0]
p.autofill()
proteins.append(p)
#TODO replace p with proteins as the instance_dict
self.instance_dict['ProteinForm'] = p
return self.get_form_step_data(form)
def done(self, form_list, **kwargs):
......
......@@ -78,3 +78,8 @@ def get_pfam_info(pfam_acc):
domain_family = ''
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))
uniprot_ids = list(resp.json()[pdb_id]['UniProt'].keys())
return uniprot_ids
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