Ejemplo n.º 1
0
def SelectionGproteinToggle(request):
    """Updates the selected g proteins arbitrary selections"""
    g_protein_id = request.GET['g_protein_id']
    preferred = request.GET['preferred']

    all_gprots = ProteinGProtein.objects.all()
    gprots = ProteinGProtein.objects.filter(pk=g_protein_id)
    print("'{}'".format(ProteinGProtein.objects.get(pk=g_protein_id).name))

    # get simple selection from session
    simple_selection = request.session.get('selection', False)

    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # add the selected items to the selection
    for gprot in gprots:
        if preferred == 'true':
            exists = selection.remove('pref_g_proteins', 'g_protein',
                                      g_protein_id)
        else:
            exists = selection.remove('g_proteins', 'g_protein', g_protein_id)
        if not exists:
            selection_object = SelectionItem('g_protein', gprot)
            if preferred == 'true':
                selection.add('pref_g_proteins', 'g_protein', selection_object)
            else:
                selection.add('g_proteins', 'g_protein', selection_object)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # add all species objects to context (for comparison to selected species)
    if preferred == 'true':
        context = selection.dict('pref_g_proteins')
    else:
        context = selection.dict('g_proteins')

    context['gprots'] = ProteinGProtein.objects.all()

    if preferred == 'true':
        print(request.session['selection'])
        return render(request,
                      'common/selection_filters_pref_gproteins_selector.html',
                      context)
    else:
        return render(request,
                      'common/selection_filters_gproteins_selector.html',
                      context)
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):

        context = super(PDBClean, self).get_context_data(**kwargs)

        self.posted = True
        pref = True
        water = False
        hets = False
        
        if 'pref_chain' not in request.POST.keys():
            pref = False
        if 'water' in request.POST.keys():
            water = True
        if 'hets' in request.POST.keys():
            hets = True

        # get simple selection from session
        simple_selection = request.session.get('selection', False)
        selection = Selection()
        if simple_selection:
            selection.importer(simple_selection)
        out_stream = BytesIO()
        io = PDBIO()
        zipf = zipfile.ZipFile(out_stream, 'w', zipfile.ZIP_DEFLATED)
        if selection.targets != []:
            for selected_struct in [x for x in selection.targets if x.type == 'structure']:
                struct_name = '{}_{}.pdb'.format(selected_struct.item.protein_conformation.protein.parent.entry_name, selected_struct.item.pdb_code.index)
                if hets:
                    lig_names = [x.pdb_reference for x in StructureLigandInteraction.objects.filter(structure=selected_struct.item, annotated=True)]
                else:
                    lig_names = None
                gn_assigner = GenericNumbering(structure=PDBParser(QUIET=True).get_structure(struct_name, StringIO(selected_struct.item.get_cleaned_pdb(pref, water, lig_names)))[0])
                tmp = StringIO()
                io.set_structure(gn_assigner.assign_generic_numbers())
                request.session['substructure_mapping'] = gn_assigner.get_substructure_mapping_dict()
                io.save(tmp)
                zipf.writestr(struct_name, tmp.getvalue())
                del gn_assigner, tmp
            for struct in selection.targets:
                selection.remove('targets', 'structure', struct.item.id)
            # export simple selection that can be serialized
            simple_selection = selection.exporter()

            request.session['selection'] = simple_selection
            request.session['cleaned_structures'] = out_stream

        attributes = inspect.getmembers(self, lambda a:not(inspect.isroutine(a)))
        for a in attributes:
            if not(a[0].startswith('__') and a[0].endswith('__')):
                context[a[0]] = a[1]
        return render(request, self.template_name, context)
Ejemplo n.º 3
0
def SelectionGproteinToggle(request):
    """Updates the selected g proteins arbitrary selections"""
    g_protein_id = request.GET['g_protein_id']
    preferred = request.GET['preferred']

    all_gprots = ProteinGProtein.objects.all()
    gprots = ProteinGProtein.objects.filter(pk=g_protein_id)
    print("'{}'".format(ProteinGProtein.objects.get(pk=g_protein_id).name))

    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # add the selected items to the selection
    for gprot in gprots:
        if preferred == 'true':
            exists = selection.remove('pref_g_proteins', 'g_protein', g_protein_id)
        else:
            exists = selection.remove('g_proteins', 'g_protein', g_protein_id)
        if not exists:
            selection_object = SelectionItem('g_protein', gprot)
            if preferred == 'true':
                selection.add('pref_g_proteins', 'g_protein', selection_object)
            else:
                selection.add('g_proteins', 'g_protein', selection_object)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # add all species objects to context (for comparison to selected species)
    if preferred == 'true':
        context = selection.dict('pref_g_proteins')
    else:
        context = selection.dict('g_proteins')

    context['gprots'] = ProteinGProtein.objects.all()
    
    if preferred == 'true':
        print(request.session['selection'])
        return render(request, 'common/selection_filters_pref_gproteins_selector.html', context)
    else:
        return render(request, 'common/selection_filters_gproteins_selector.html', context)
Ejemplo n.º 4
0
def SelectionSchemesToggle(request):
    """Updates the selected numbering schemes arbitrary selections"""
    numbering_scheme_id = request.GET['numbering_scheme_id']
    gns = ResidueNumberingScheme.objects.filter(pk=numbering_scheme_id)

    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # add the selected items to the selection
    for gn in gns:
        exists = selection.remove('numbering_schemes', 'numbering_schemes', numbering_scheme_id)
        if not exists:
            selection_object = SelectionItem('numbering_schemes', gn)
            selection.add('numbering_schemes', 'numbering_schemes', selection_object)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # add all species objects to context (for comparison to selected species)
    context = selection.dict('numbering_schemes')
    context['gns'] = ResidueNumberingScheme.objects.exclude(slug=settings.DEFAULT_NUMBERING_SCHEME)
    
    return render(request, 'common/selection_filters_numbering_schemes.html', context)
Ejemplo n.º 5
0
def SelectionSpeciesToggle(request):
    """Updates the selected species arbitrary selections"""
    species_id = request.GET['species_id']

    all_sps = Species.objects.all()
    sps = Species.objects.filter(pk=species_id)

    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # add the selected items to the selection
    for sp in sps:
        exists = selection.remove('species', 'species', species_id)
        if not exists:
            selection_object = SelectionItem('species', sp)
            selection.add('species', 'species', selection_object)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # add all species objects to context (for comparison to selected species)
    context = selection.dict('species')
    context['sps'] = Species.objects.all()
    
    return render(request, 'common/selection_filters_species_selector.html', context)
Ejemplo n.º 6
0
def SelectionSchemesToggle(request):
    """Updates the selected numbering schemes arbitrary selections"""
    numbering_scheme_id = request.GET['numbering_scheme_id']
    gns = ResidueNumberingScheme.objects.filter(pk=numbering_scheme_id)

    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # add the selected items to the selection
    for gn in gns:
        exists = selection.remove('numbering_schemes', 'numbering_schemes', numbering_scheme_id)
        if not exists:
            selection_object = SelectionItem('numbering_schemes', gn)
            selection.add('numbering_schemes', 'numbering_schemes', selection_object)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # add all species objects to context (for comparison to selected species)
    context = selection.dict('numbering_schemes')
    context['gns'] = ResidueNumberingScheme.objects.exclude(slug=settings.DEFAULT_NUMBERING_SCHEME)
    
    return render(request, 'common/selection_filters_numbering_schemes.html', context)
Ejemplo n.º 7
0
def SelectionSpeciesToggle(request):
    """Updates the selected species arbitrary selections"""
    species_id = request.GET['species_id']

    all_sps = Species.objects.all()
    sps = Species.objects.filter(pk=species_id)

    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # add the selected items to the selection
    for sp in sps:
        exists = selection.remove('species', 'species', species_id)
        if not exists:
            selection_object = SelectionItem('species', sp)
            selection.add('species', 'species', selection_object)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # add all species objects to context (for comparison to selected species)
    context = selection.dict('species')
    context['sps'] = Species.objects.all()
    
    return render(request, 'common/selection_filters_species_selector.html', context)
Ejemplo n.º 8
0
def RemoveResidueGroup(request):
    """Receives a selection request, removes a residue group, and returns the updated selection"""
    selection_type = request.GET['selection_type']
    group_id = int(request.GET['group_id'])

    # get simple selection from session
    simple_selection = request.session.get('selection', False)

    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # find all positions in the group and delete them
    for position in selection.segments:
        if position.type == 'site_residue':
            if position.properties['site_residue_group'] == group_id:
                selection.remove(selection_type, position.type,
                                 position.item.id)
            else:
                if position.properties['site_residue_group'] > group_id:
                    position.properties['site_residue_group'] -= 1

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # context
    context = selection.dict(selection_type)

    # amino acid groups
    amino_acid_groups = {
        'amino_acid_groups': definitions.AMINO_ACID_GROUPS,
        'amino_acid_group_names': definitions.AMINO_ACID_GROUP_NAMES
    }
    context.update(amino_acid_groups)

    # template to load
    template = 'common/selection_lists_sitesearch.html'

    return render(request, template, context)
Ejemplo n.º 9
0
def ConvertStructuresToProteins(request):
    "For alignment from structure browser"

    simple_selection = request.session.get('selection', False)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)
    if selection.targets != []:
        for struct in selection.targets:
            prot = struct.item.protein_conformation.protein.parent
            selection.remove('targets', 'structure', struct.item.id)
            selection.add('targets', 'protein', SelectionItem('protein', prot))
    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    return HttpResponseRedirect('/alignment/segmentselection')
Ejemplo n.º 10
0
def RemoveResidueGroup(request):
    """Receives a selection request, removes a residue group, and returns the updated selection"""
    selection_type = request.GET['selection_type']
    group_id = int(request.GET['group_id'])
    
    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # find all positions in the group and delete them
    for position in selection.segments:
        if position.type == 'site_residue':
            if position.properties['site_residue_group'] == group_id:
                selection.remove(selection_type, position.type, position.item.id)
            else:
                if position.properties['site_residue_group'] > group_id:
                    position.properties['site_residue_group'] -= 1

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # context
    context = selection.dict(selection_type)
    
    # amino acid groups
    amino_acid_groups = {
        'amino_acid_groups': definitions.AMINO_ACID_GROUPS,
        'amino_acid_group_names': definitions.AMINO_ACID_GROUP_NAMES }
    context.update(amino_acid_groups)

    # template to load
    template = 'common/selection_lists_sitesearch.html'

    return render(request, template, context)
Ejemplo n.º 11
0
def RemoveFromSelection(request):
    """Removes one selected item from the session"""
    selection_type = request.GET['selection_type']
    selection_subtype = request.GET['selection_subtype']
    selection_id = request.GET['selection_id']

    # get simple selection from session
    simple_selection = request.session.get('selection', False)

    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # remove the selected item to the selection
    selection.remove(selection_type, selection_subtype, selection_id)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # context
    context = selection.dict(selection_type)

    # template to load
    if selection_subtype == 'site_residue':
        template = 'common/selection_lists_sitesearch.html'
        amino_acid_groups = {
            'amino_acid_groups': definitions.AMINO_ACID_GROUPS,
            'amino_acid_group_names': definitions.AMINO_ACID_GROUP_NAMES
        }
        context.update(amino_acid_groups)
    else:
        template = 'common/selection_lists.html'

    return render(request, template, context)
Ejemplo n.º 12
0
def RemoveFromSelection(request):
    """Removes one selected item from the session"""
    selection_type = request.GET['selection_type']
    selection_subtype = request.GET['selection_subtype']
    selection_id = request.GET['selection_id']
    
    # get simple selection from session
    simple_selection = request.session.get('selection', False)
    
    # create full selection and import simple selection (if it exists)
    selection = Selection()
    if simple_selection:
        selection.importer(simple_selection)

    # remove the selected item to the selection
    selection.remove(selection_type, selection_subtype, selection_id)

    # export simple selection that can be serialized
    simple_selection = selection.exporter()

    # add simple selection to session
    request.session['selection'] = simple_selection

    # context 
    context = selection.dict(selection_type)
    
    # template to load
    if selection_subtype == 'site_residue':
        template = 'common/selection_lists_sitesearch.html'
        amino_acid_groups = {
            'amino_acid_groups': definitions.AMINO_ACID_GROUPS,
            'amino_acid_group_names': definitions.AMINO_ACID_GROUP_NAMES }
        context.update(amino_acid_groups)
    else:
        template = 'common/selection_lists.html'

    return render(request, template, context)