Example #1
0
def site_upload(request):
    
    # 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)

    selection_type = 'segments'
    selection_subtype = 'site_residue'

    if request.FILES == {}:
        return render(request, 'common/selection_lists_sitesearch.html', '')

    #Overwriting the existing selection
    selection.clear(selection_type)

    print(type(request.FILES['xml_file'].file))

    wb=load_workbook(filename=request.FILES['xml_file'].file)
    ws=wb.active


    for row in ws.rows:
        if len(row) < 5:
            continue
        group_id = int(row[0].value)
        min_match = int(row[1].value)
        try:
            position = ResidueGenericNumberEquivalent.objects.get(label=row[2].value, scheme__slug=row[3].value)
        except e:
            print(e)
            continue
        feature = row[4].value

        # update the selected group
        selection.active_site_residue_group = group_id
        print(selection.site_residue_groups)
        if not selection.site_residue_groups:
            selection.site_residue_groups = [[]]
        selection.site_residue_groups[selection.active_site_residue_group - 1].append(1)
        if len(selection.site_residue_groups) < group_id:
            for x in group_id - len(selection.site_residue_groups):
                selection.site_residue_groups.append([])
        selection.site_residue_groups[group_id - 1][0] = min_match
        selection_object = SelectionItem(selection_subtype, position)
        selection_object.properties['feature'] = feature
        selection_object.properties['site_residue_group'] = selection.active_site_residue_group
        selection_object.properties['amino_acids'] = ','.join(definitions.AMINO_ACID_GROUPS[feature])
        selection.add(selection_type, selection_subtype, selection_object)

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

    # add simple selection to session
    request.session['selection'] = simple_selection
    
    return render(request, 'common/selection_lists_sitesearch.html', selection.dict(selection_type))
Example #2
0
def SelectionAnnotation(request):
    """Updates the selected level of annotation"""
    protein_source = request.GET['protein_source']
    
    if protein_source == 'All':
        pss = ProteinSource.objects.all()
    else:
        pss = ProteinSource.objects.filter(name=protein_source)

    # 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)

    # reset the annotation selection
    selection.clear('annotation')

    # add the selected items to the selection
    for ps in pss:
        selection_object = SelectionItem('annotation', ps)
        selection.add('annotation', 'annotation', selection_object)

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

    # add simple selection to session
    request.session['selection'] = simple_selection
    return render(request, 'common/selection_filters_annotation.html', selection.dict('annotation'))
Example #3
0
def SelectionAnnotation(request):
    """Updates the selected level of annotation"""
    protein_source = request.GET['protein_source']
    
    if protein_source == 'All':
        pss = ProteinSource.objects.all()
    else:
        pss = ProteinSource.objects.filter(name=protein_source)

    # 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)

    # reset the annotation selection
    selection.clear('annotation')

    # add the selected items to the selection
    for ps in pss:
        selection_object = SelectionItem('annotation', ps)
        selection.add('annotation', 'annotation', selection_object)

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

    # add simple selection to session
    request.session['selection'] = simple_selection
    return render(request, 'common/selection_filters_annotation.html', selection.dict('annotation'))
Example #4
0
def ResiduesUpload(request):
    """Receives a file containing generic residue positions along with numbering scheme and adds those to the selection."""

    # 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)

    selection_type = 'segments'
    if request.FILES == {}:
        return render(request, 'common/selection_lists.html', '')

    #Overwriting the existing selection
    selection.clear(selection_type)

    #The excel file
    o = []
    workbook = xlrd.open_workbook(
        file_contents=request.FILES['xml_file'].read())
    worksheets = workbook.sheet_names()
    for worksheet_name in worksheets:
        worksheet = workbook.sheet_by_name(worksheet_name)
        for row in worksheet.get_rows():
            if len(row) < 2:
                continue
            try:
                if row[0].value == 'residue':
                    position = ResidueGenericNumberEquivalent.objects.get(
                        label=row[2].value, scheme__slug=row[1].value)
                    o.append(position)
                elif row[0].value == 'helix':
                    o.append(ProteinSegment.objects.get(slug=row[2].value))
            except Exception as msg:
                print(msg)
                continue
    for obj in o:
        # add the selected item to the selection
        if obj.__class__.__name__ == 'ResidueGenericNumberEquivalent':
            selection_subtype = 'residue'
        else:
            selection_subtype = 'helix'
        selection_object = SelectionItem(selection_subtype, obj)
        selection.add(selection_type, selection_subtype, selection_object)

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

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

    return render(request, 'common/selection_lists.html',
                  selection.dict(selection_type))
Example #5
0
def SelectionGproteinPredefined(request):
    """Updates the selected g proteins to predefined sets (Gi/Go and all)"""
    g_protein = request.GET['g_protein']
    preferred = request.GET['preferred']

    # 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)

    all_gprots = ProteinGProtein.objects.all()
    gprots = False
    if g_protein == 'All':
        gprots = []
    if g_protein != 'All' and g_protein:
        gprots = ProteinGProtein.objects.filter(name=g_protein)

    if gprots != False:
        # reset the g proteins selection
        if preferred == 'true':
            selection.clear('pref_g_proteins')
        else:
            selection.clear('g_proteins')

        # add the selected items to the selection
        for gprot in gprots:
            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':
        return render(request, 'common/selection_filters_pref_gproteins.html',
                      context)
    else:
        return render(request, 'common/selection_filters_gproteins.html',
                      context)
Example #6
0
def ResiduesUpload(request):
    """Receives a file containing generic residue positions along with numbering scheme and adds those to the selection."""

    # 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)

    selection_type = 'segments'
    if request.FILES == {}:
        return render(request, 'common/selection_lists.html', '')

    #Overwriting the existing selection
    selection.clear(selection_type)

    #The excel file
    o = []
    workbook = xlrd.open_workbook(file_contents=request.FILES['xml_file'].read())
    worksheets = workbook.sheet_names()
    for worksheet_name in worksheets:
        worksheet = workbook.sheet_by_name(worksheet_name)
        for row in worksheet.get_rows():
            if len(row) < 2:
                continue
            try:
                if row[0].value == 'residue':
                    position = ResidueGenericNumberEquivalent.objects.get(label=row[2].value, scheme__slug=row[1].value)
                    o.append(position)
                elif row[0].value == 'helix':
                    o.append(ProteinSegment.objects.get(slug=row[2].value))
            except Exception as msg:
                print(msg)
                continue
    for obj in o:
        # add the selected item to the selection
        if obj.__class__.__name__ == 'ResidueGenericNumberEquivalent':
            selection_subtype = 'residue'
        else: 
            selection_subtype = 'helix'
        selection_object = SelectionItem(selection_subtype, obj)
        selection.add(selection_type, selection_subtype, selection_object)

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

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

    return render(request, 'common/selection_lists.html', selection.dict(selection_type))
Example #7
0
def SelectionGproteinPredefined(request):
    """Updates the selected g proteins to predefined sets (Gi/Go and all)"""
    g_protein = request.GET['g_protein']
    preferred = request.GET['preferred']

    # 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)
    
    all_gprots = ProteinGProtein.objects.all()
    gprots = False
    if g_protein == 'All':
        gprots = []
    if g_protein != 'All' and g_protein:
        gprots = ProteinGProtein.objects.filter(name=g_protein)

    if gprots != False:
        # reset the g proteins selection
        if preferred == 'true':
            selection.clear('pref_g_proteins')
        else:
            selection.clear('g_proteins')

        # add the selected items to the selection
        for gprot in gprots:
            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':
        return render(request, 'common/selection_filters_pref_gproteins.html', context)
    else:
        return render(request, 'common/selection_filters_gproteins.html', context)
Example #8
0
def preserve_targets(request):

    request.session['targets_pos'] = deepcopy(request.session.get('selection', False))
    # 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)
        selection.clear('targets')
        # export simple selection that can be serialized
        simple_selection = selection.exporter()
        # add simple selection to session
        request.session['selection'] = simple_selection

    return redirect('/seqsign/negativegroupselection',)
Example #9
0
def preserve_targets(request):

    request.session['targets_pos'] = deepcopy(request.session.get('selection', False))
    # 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)
        selection.clear('targets')
        # export simple selection that can be serialized
        simple_selection = selection.exporter()
        # add simple selection to session
        request.session['selection'] = simple_selection

    return redirect('/seqsign/negativegroupselection',)
Example #10
0
def SelectionSchemesPredefined(request):
    """Updates the selected numbering_schemes to predefined sets (GPCRdb and All)"""
    numbering_schemes = request.GET['numbering_schemes']

    # 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)

    all_gns = ResidueNumberingScheme.objects.exclude(
        slug=settings.DEFAULT_NUMBERING_SCHEME)
    gns = False
    if numbering_schemes == 'All':
        print(len(selection.numbering_schemes), all_gns.count())
        if len(selection.numbering_schemes) == all_gns.count():
            gns = []
        else:
            gns = all_gns

    # reset the species selection
    selection.clear('numbering_schemes')

    # add the selected items to the selection
    for gn in gns:
        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'] = all_gns

    return render(request, 'common/selection_filters_numbering_schemes.html',
                  context)
Example #11
0
def signature_selection(request):
    # create full selection and import simple selection (if it exists)
    simple_selection = request.session.get('selection', False)
    selection_pos = Selection()
    selection_pos.importer(deepcopy(simple_selection))
    selection_pos.clear('targets')

    selection_neg = Selection()
    selection_neg.importer(deepcopy(simple_selection))
    selection_neg.clear('targets')

    if 'group1' in request.POST and 'group2' in request.POST:
        up_names = request.POST['group1'].split('\r')
        for up_name in up_names:
            try:
                selection_object = SelectionItem(
                    'protein',
                    Protein.objects.get(entry_name=up_name.strip().lower()))
                selection_pos.add('targets', 'protein', selection_object)
            except:
                continue

        down_names = request.POST['group2'].split('\r')
        for down_name in down_names:
            try:
                selection_object = SelectionItem(
                    'protein',
                    Protein.objects.get(entry_name=down_name.strip().lower()))
                selection_neg.add('targets', 'protein', selection_object)
            except:
                continue

        # Set both the positive and negative target selections
        request.session['targets_pos'] = selection_pos.exporter()

        request.session['selection'] = selection_neg.exporter()

        return JsonResponse({"response": "ok"})
    else:
        return JsonResponse({"response": "error"})
Example #12
0
def SelectionSchemesPredefined(request):
    """Updates the selected numbering_schemes to predefined sets (GPCRdb and All)"""
    numbering_schemes = request.GET['numbering_schemes']

    # 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)
    
    all_gns = ResidueNumberingScheme.objects.exclude(slug=settings.DEFAULT_NUMBERING_SCHEME)
    gns = False
    if numbering_schemes == 'All':
        print(len(selection.numbering_schemes), all_gns.count())
        if len(selection.numbering_schemes) == all_gns.count():
            gns = []
        else:
            gns = all_gns
    
    # reset the species selection
    selection.clear('numbering_schemes')

    # add the selected items to the selection
    for gn in gns:
        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'] = all_gns
    
    return render(request, 'common/selection_filters_numbering_schemes.html', context)
Example #13
0
    def get_context_data (self, **kwargs):

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

        # get selection from session and add to context
        # get simple selection from session
        simple_selection = self.request.session.get('selection', False)

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

        #Clearing selections for fresh run
        if 'clear' in self.kwargs.keys():
            selection.clear('reference')
            selection.clear('targets')
            selection.clear('segments')
            if 'alt_files' in self.request.session.keys():
                del self.request.session['alt_files']
            if 'ref_file' in self.request.session.keys():
                del self.request.session['ref_file']
        context['selection'] = {}
        for selection_box, include in self.selection_boxes.items():
            if include:
                context['selection'][selection_box] = selection.dict(selection_box)['selection'][selection_box]

        # get attributes of this class and add them to the context
        context['form_code'] = str(self.form_code)
        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 context
Example #14
0
def SelectionSpeciesPredefined(request):
    """Updates the selected species to predefined sets (Human and all)"""
    species = request.GET['species']

    # 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)
    
    all_sps = Species.objects.all()
    sps = False
    if species == 'All':
        sps = []
    if species != 'All' and species:
        sps = Species.objects.filter(common_name=species)

    if sps != False:
        # reset the species selection
        selection.clear('species')

        # add the selected items to the selection
        for sp in sps:
            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'] = all_sps
    
    return render(request, 'common/selection_filters_species.html', context)
Example #15
0
def ClearSelection(request):
    """Clears all selected items of the selected type from the session"""
    selection_type = request.GET['selection_type']
    
    # 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.clear(selection_type)

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

    # add simple selection to session
    request.session['selection'] = simple_selection
    
    return render(request, 'common/selection_lists.html', selection.dict(selection_type))
Example #16
0
def SelectionSpeciesPredefined(request):
    """Updates the selected species to predefined sets (Human and all)"""
    species = request.GET['species']

    # 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)
    
    all_sps = Species.objects.all()
    sps = False
    if species == 'All':
        sps = []
    if species != 'All' and species:
        sps = Species.objects.filter(common_name=species)

    if sps != False:
        # reset the species selection
        selection.clear('species')

        # add the selected items to the selection
        for sp in sps:
            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'] = all_sps
    
    return render(request, 'common/selection_filters_species.html', context)
Example #17
0
def ClearSelection(request):
    """Clears all selected items of the selected type from the session"""
    selection_type = request.GET['selection_type']
    
    # 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.clear(selection_type)

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

    # add simple selection to session
    request.session['selection'] = simple_selection
    
    return render(request, 'common/selection_lists.html', selection.dict(selection_type))
Example #18
0
def site_upload(request):
    
    # 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)

    selection_type = 'segments'
    selection_subtype = 'site_residue'

    if request.FILES == {}:
        return render(request, 'common/selection_lists_sitesearch.html', '')

    #Overwriting the existing selection
    selection.clear(selection_type)

    workbook = xlrd.open_workbook(file_contents=request.FILES['xml_file'].read())
    worksheets = workbook.sheet_names()
    for worksheet_name in worksheets:
        worksheet = workbook.sheet_by_name(worksheet_name)
        for row in worksheet.get_rows():

    #for row in ws.rows:
            if len(row) < 5:
                continue
            group_id = int(row[0].value)
            min_match = int(row[1].value)
            try:
                position = ResidueGenericNumberEquivalent.objects.get(label=row[2].value, scheme__slug=row[3].value)
            except e:
                print(e)
                continue
            feature = row[4].value

            # update the selected group
            if not selection.active_site_residue_group:
                selection.active_site_residue_group = group_id
            if not selection.site_residue_groups:
                selection.site_residue_groups = [[]]
            if len(selection.site_residue_groups) < group_id:
                for x in group_id - len(selection.site_residue_groups):
                    selection.site_residue_groups[x].append([])
#            selection.site_residue_groups[group_id - 1].append(1)
            properties = {}
            properties['feature'] = feature
            properties['site_residue_group'] = selection.active_site_residue_group
            properties['amino_acids'] = ','.join(definitions.AMINO_ACID_GROUPS[feature]) if feature != 'custom' else row[5].value
            selection_object = SelectionItem(selection_subtype, position, properties)
            selection.add(selection_type, selection_subtype, selection_object)
            selection.site_residue_groups[group_id - 1][0] = min_match
    # export simple selection that can be serialized
    simple_selection = selection.exporter()
    # add simple selection to session
    request.session['selection'] = simple_selection

    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)

    return render(request, 'common/selection_lists_sitesearch.html', context)
Example #19
0
def site_upload(request):

    # 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)

    selection_type = 'segments'
    selection_subtype = 'site_residue'

    if request.FILES == {}:
        return render(request, 'common/selection_lists_sitesearch.html', '')

    #Overwriting the existing selection
    selection.clear(selection_type)

    workbook = xlrd.open_workbook(
        file_contents=request.FILES['xml_file'].read())
    worksheets = workbook.sheet_names()
    for worksheet_name in worksheets:
        worksheet = workbook.sheet_by_name(worksheet_name)
        for row in worksheet.get_rows():

            #for row in ws.rows:
            if len(row) < 5:
                continue
            group_id = int(row[0].value)
            min_match = int(row[1].value)
            try:
                position = ResidueGenericNumberEquivalent.objects.get(
                    label=row[2].value, scheme__slug=row[3].value)
            except e:
                print(e)
                continue
            feature = row[4].value

            # update the selected group
            if not selection.active_site_residue_group:
                selection.active_site_residue_group = group_id
            if not selection.site_residue_groups:
                selection.site_residue_groups = [[]]
            if len(selection.site_residue_groups) < group_id:
                for x in group_id - len(selection.site_residue_groups):
                    selection.site_residue_groups[x].append([])


#            selection.site_residue_groups[group_id - 1].append(1)
            properties = {}
            properties['feature'] = feature
            properties[
                'site_residue_group'] = selection.active_site_residue_group
            properties['amino_acids'] = ','.join(
                definitions.AMINO_ACID_GROUPS[feature]
            ) if feature != 'custom' else row[5].value
            selection_object = SelectionItem(selection_subtype, position,
                                             properties)
            selection.add(selection_type, selection_subtype, selection_object)
            selection.site_residue_groups[group_id - 1][0] = min_match
    # export simple selection that can be serialized
    simple_selection = selection.exporter()
    # add simple selection to session
    request.session['selection'] = simple_selection

    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)

    return render(request, 'common/selection_lists_sitesearch.html', context)