コード例 #1
0
ファイル: views.py プロジェクト: dsalvanha/network_portal
def search(request):
    if request.GET.has_key('q'):
        try:
            q = request.GET['q']
            results = s.search(q)
            gene_ids= []
            for result in results:
                if result['doc_type'] == 'GENE':
                    gene_ids.append(result['id'])

            gene_objs = Gene.objects.filter(pk__in=gene_ids)
            species_genes = {}
            species_names = {}
            genes = []
            for gene_obj in gene_objs:
                species_names[gene_obj.species.id] = gene_obj.species.name
                bicluster_ids = [b.id for b in gene_obj.bicluster_set.all()]
                regulates = Bicluster.objects.filter(influences__name__contains=gene_obj.name)
                _, influence_biclusters = get_influence_biclusters(gene_obj)

                if not species_genes.has_key(gene_obj.species.id):
                    species_genes[gene_obj.species.id] = []
                genes = species_genes[gene_obj.species.id]

                genes.append(GeneResultEntry(gene_obj.id, gene_obj.name,
                                             gene_obj.species.id,
                                             gene_obj.description,
                                             bicluster_ids,
                                             influence_biclusters,
                                             regulates))
        except Exception as e:
            error_message = str(e)
    return render_to_response('search.html', locals())
コード例 #2
0
def search(request):
    if request.GET.has_key('q'):
        try:
            q = request.GET['q']
            results = s.search(q)
            gene_ids = []
            for result in results:
                if result['doc_type'] == 'GENE':
                    gene_ids.append(result['id'])

            gene_objs = Gene.objects.filter(pk__in=gene_ids)
            species_genes = {}
            species_names = {}
            genes = []
            for gene_obj in gene_objs:
                species_names[gene_obj.species.id] = gene_obj.species.name
                bicluster_ids = [b.id for b in gene_obj.bicluster_set.all()]
                regulates = Bicluster.objects.filter(
                    influences__name__contains=gene_obj.name)
                _, influence_biclusters = get_influence_biclusters(gene_obj)

                if not species_genes.has_key(gene_obj.species.id):
                    species_genes[gene_obj.species.id] = []
                genes = species_genes[gene_obj.species.id]

                genes.append(
                    GeneResultEntry(gene_obj.id, gene_obj.name,
                                    gene_obj.species.id, gene_obj.description,
                                    bicluster_ids, influence_biclusters,
                                    regulates))
        except Exception as e:
            error_message = str(e)
    return render_to_response('search.html', locals())
コード例 #3
0
def gene(request, gene=None, network_id=None):
    if request.GET.has_key("view"):
        view = request.GET["view"]
    else:
        view = ""

    if gene:
        try:
            gene_id = int(gene)
            gene = Gene.objects.get(id=gene_id)
        except ValueError:
            gene = find_gene_by_name(gene)
    elif request.GET.has_key("id"):
        gene_id = request.GET["id"]
        gene = Gene.objects.get(id=gene_id)
    else:
        gene_count = Gene.objects.count()
        species_count = Species.objects.count()
        return render_to_response("genes_empty.html", locals())

    # TODO: need to figure out how to handle cases where there's more than one network
    if network_id:
        network_id = int(network_id)
    elif gene.species.network_set.count() > 0:
        network = gene.species.network_set.all()[0]
        network_id = network.id
    else:
        network_id = None
    member_biclusters, influence_biclusters = get_influence_biclusters(gene)

    # set species for use in template
    species = gene.species

    # get neighbor genes
    neighbor_genes = gene.neighbor_genes(network_id)

    # compile functions into groups by functional system
    systems = []
    for key, functions in gene.functions_by_type().items():
        system = {}
        system["name"] = functional_systems[key].display_name
        system["functions"] = [
            '(<a href="%s">%s</a>) %s' % (function.link_to_term(), function.native_id, function.name)
            for function in functions
        ]
        systems.append(system)

    # if the gene is a transcription factor, how many biclusters does it regulate?
    count_regulated_biclusters = gene.count_regulated_biclusters(network_id)
    # regulated_biclusters = Bicluster.objects.distinct().filter(influences__name__contains=gene.name)
    regulated_biclusters = gene.regulated_biclusters(network_id)

    bicluster_pssms = {}
    preview_motifs = []
    all_motifs = []
    for mbicl in member_biclusters:
        motifs = mbicl.motif_set.all()
        all_motifs.extend(motifs)
        pssms = __make_pssms(motifs)
        preview_added = False
        for motif_id, pssm in pssms.items():
            bicluster_pssms[motif_id] = pssm
            if not preview_added:
                preview_motifs.append(motif_id)
                preview_added = True
    motifs = all_motifs  # used in template
    preview_motifs = preview_motifs[:2]  # restrict to 2 motifs on the front tab to improve load time

    if request.GET.has_key("format"):
        format = request.GET["format"]
        if format == "html":
            return render_to_response("gene_snippet.html", locals())

    return render_to_response("gene.html", locals())
コード例 #4
0
def gene(request, gene=None, network_id=None):
    if request.GET.has_key('view'):
        view = request.GET['view']
    else:
        view = ""

    if gene:
        try:
            gene_id = int(gene)
            gene = Gene.objects.get(id=gene_id)
        except ValueError:
            gene = find_gene_by_name(gene)
    elif request.GET.has_key('id'):
        gene_id = request.GET['id']
        gene = Gene.objects.get(id=gene_id)
    else:
        gene_count = Gene.objects.count()
        species_count = Species.objects.count()
        return render_to_response('genes_empty.html', locals())

    # TODO: need to figure out how to handle cases where there's more than one network
    if network_id:
        network_id = int(network_id)
    elif gene.species.network_set.count() > 0:
        network = gene.species.network_set.all()[0]
        network_id = network.id
    else:
        network_id = None
    member_biclusters, influence_biclusters = get_influence_biclusters(gene)

    # set species for use in template
    species = gene.species

    # get neighbor genes
    neighbor_genes = gene.neighbor_genes(network_id)

    # compile functions into groups by functional system
    systems = []
    for key, functions in gene.functions_by_type().items():
        system = {}
        system['name'] = functional_systems[key].display_name
        system['functions'] = [ "(<a href=\"%s\">%s</a>) %s" % (function.link_to_term(), function.native_id, function.name,) \
                                for function in functions ]
        systems.append(system)

    # if the gene is a transcription factor, how many biclusters does it regulate?
    count_regulated_biclusters = gene.count_regulated_biclusters(network_id)
    #regulated_biclusters = Bicluster.objects.distinct().filter(influences__name__contains=gene.name)
    regulated_biclusters = gene.regulated_biclusters(network_id)

    bicluster_pssms = {}
    preview_motifs = []
    all_motifs = []
    for mbicl in member_biclusters:
        motifs = mbicl.motif_set.all()
        all_motifs.extend(motifs)
        pssms = __make_pssms(motifs)
        preview_added = False
        for motif_id, pssm in pssms.items():
            bicluster_pssms[motif_id] = pssm
            if not preview_added:
                preview_motifs.append(motif_id)
                preview_added = True
    motifs = all_motifs  # used in template
    preview_motifs = preview_motifs[:
                                    2]  # restrict to 2 motifs on the front tab to improve load time

    if request.GET.has_key('format'):
        format = request.GET['format']
        if format == 'html':
            return render_to_response('gene_snippet.html', locals())

    return render_to_response('gene.html', locals())