def SelectResidueGroup(request): """Receives a selection request, updates the active 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) # update the selected group selection.active_site_residue_group = group_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) # 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)
def SelectResidueGroup(request): """Receives a selection request, updates the active 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) # update the selected group selection.active_site_residue_group = group_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) # 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)
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))
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)
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)