当前位置: 首页>>代码示例>>Python>>正文


Python Selection.add方法代码示例

本文整理汇总了Python中common.selection.Selection.add方法的典型用法代码示例。如果您正苦于以下问题:Python Selection.add方法的具体用法?Python Selection.add怎么用?Python Selection.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.selection.Selection的用法示例。


在下文中一共展示了Selection.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SelectionSchemesToggle

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:33,代码来源:views.py

示例2: SelectionSpeciesToggle

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:35,代码来源:views.py

示例3: SelectionAnnotation

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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'))
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:33,代码来源:views.py

示例4: SelectAlignableSegments

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
def SelectAlignableSegments(request):
    """Adds all alignable segments to the selection"""
    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)

    # get all segments
        # get all segments
    if "protein_type" in request.GET:
        gsegments = definitions.G_PROTEIN_SEGMENTS

        preserved = Case(*[When(slug=pk, then=pos) for pos, pk in enumerate(gsegments['Structured'])])
        segments = ProteinSegment.objects.filter(slug__in = gsegments['Structured'], partial=False).order_by(preserved)
    else:
        segments = ProteinSegment.objects.filter(partial=False, slug__startswith='TM')

    for segment in segments:
        selection_object = SelectionItem(segment.category, segment)
        # add the selected item to the selection
        selection.add(selection_type, segment.category, 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))
开发者ID:protwis,项目名称:protwis,代码行数:36,代码来源:views.py

示例5: SelectAlignableSegments

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
def SelectAlignableSegments(request):
    """Adds all alignable segments to the selection"""
    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)

    # get all segments
    segments = ProteinSegment.objects.filter(partial=False, slug__startswith='TM')
    for segment in segments:
        selection_object = SelectionItem(segment.category, segment)
        # add the selected item to the selection
        selection.add(selection_type, segment.category, 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))
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:28,代码来源:views.py

示例6: site_upload

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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))
开发者ID:MeeMaster,项目名称:protwis,代码行数:62,代码来源:views.py

示例7: SelectionGproteinPredefined

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:54,代码来源:views.py

示例8: ResiduesUpload

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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))
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:54,代码来源:views.py

示例9: UpdateSiteResidueFeatures

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
def UpdateSiteResidueFeatures(request):
    """Updates the selected features of a site residue"""
    selection_type = request.GET['selection_type']
    selection_subtype = request.GET['selection_subtype']
    selection_id = request.GET['selection_id']
    
    o = []
    if selection_type == 'reference' or selection_type == 'targets':
        if selection_subtype == 'protein':
            o.append(Protein.objects.get(pk=selection_id))
        elif selection_subtype == 'protein_set':
            selection_subtype = 'protein'
            pset = ProteinSet.objects.get(pk=selection_id)
            for protein in pset.proteins.all():
                o.append(protein)
        elif selection_subtype == 'family':
            o.append(ProteinFamily.objects.get(pk=selection_id))
        elif selection_subtype == 'set':
            o.append(ProteinSet.objects.get(pk=selection_id))
        elif selection_subtype == 'structure':
            o.append(Protein.objects.get(entry_name=selection_id.lower()))
    elif selection_type == 'segments':
        if selection_subtype == 'residue':
            o.append(ResidueGenericNumberEquivalent.objects.get(pk=selection_id))
        elif selection_subtype == 'residue_with_properties': # used in site search
            o.append(ResidueGenericNumberEquivalent.objects.get(pk=selection_id))
        else:
            o.append(ProteinSegment.objects.get(pk=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)

    for obj in o:
        # add the selected item to the selection
        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))
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:51,代码来源:views.py

示例10: SelectionGproteinToggle

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:51,代码来源:views.py

示例11: ConvertStructuresToProteins

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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')
开发者ID:akumar03,项目名称:protwis,代码行数:21,代码来源:views.py

示例12: SelectionSchemesPredefined

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:42,代码来源:views.py

示例13: ReadTargetInput

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
def ReadTargetInput(request):
    """Receives the data from the input form nd adds the listed targets 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 = 'targets'
    selection_subtype = 'protein'

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

    o = []
    up_names = request.POST['input-targets'].split('\r')
    for up_name in up_names:
        try:
            o.append(Protein.objects.get(entry_name=up_name.strip()))
        except:
            continue

    for obj in o:
        # add the selected item to the selection
        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

    # context 
    context = selection.dict(selection_type)

    return render(request, 'common/selection_lists.html', context)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:42,代码来源:views.py

示例14: SelectionSpeciesPredefined

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:AnnaTsolakou,项目名称:protwis,代码行数:41,代码来源:views.py

示例15: site_upload

# 需要导入模块: from common.selection import Selection [as 别名]
# 或者: from common.selection.Selection import add [as 别名]
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)
开发者ID:pszgaspar,项目名称:protwis,代码行数:68,代码来源:views.py


注:本文中的common.selection.Selection.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。