Exemplo n.º 1
0
    def get(self, request, rid, rtype_src, rtype_dst):
        resource_class = {
            Resource.RESOURCE_TYPES.STRUCTURE: Structure,
            Resource.RESOURCE_TYPES.ASSEMBLY: Assembly,
            Resource.RESOURCE_TYPES.SAMPLE: Sample,
            Resource.RESOURCE_TYPES.EXPRESSION: Expression,
            Resource.RESOURCE_TYPES.PUBLICATION: Publication,
            Resource.RESOURCE_TYPES.TOOL: Tool,
            Resource.RESOURCE_TYPES.READS: ReadsArchive,
            Resource.RESOURCE_TYPES.ORGANIZATION: Organization,
            Resource.RESOURCE_TYPES.PERSON: Person,
        }
        level = int(self.request.GET.get("level", "1"))

        neighborhood_ids = GraphRepo.get_neighborhood_ids(rid,
                                                          rtype_src,
                                                          rtype_dst,
                                                          level=1)
        if level > 1:
            neighborhood_ids += GraphRepo.get_neighborhood_ids(rid,
                                                               rtype_src,
                                                               rtype_dst,
                                                               level=level)

        obj = resource_class[Resource.name2code[
            rtype_src.upper()]].objects.get(id=rid)

        repo = resource_class[Resource.name2code[rtype_dst.upper()]]

        return render(
            request, self.template_name, {
                "rtype_dst": rtype_dst,
                "obj": obj,
                "results": repo.objects.filter(id__in=neighborhood_ids)
            })
Exemplo n.º 2
0
def publication(request, pk):

    publication = Publication.objects.prefetch_related(
        "targets__target", "affiliations__author",
        "affiliations__organizations").get(id=pk)
    orgs = publication.affiliation_names()
    org_map = {}
    authors = []
    for aff in publication.affiliations.all():
        author = aff.author
        author.affs = " ".join([
            "(" + str(orgs.index(org.name) + 1) + ")"
            for org in aff.organizations.all()
        ])
        if author not in authors:
            authors.append(author)
        for org in aff.organizations.all():
            org_map[org.name] = org

    graph, related_resources = GraphRepo.get_neighborhood(pk,
                                                          "Publication",
                                                          level=1)

    return render(
        request, 'resources/publication.html', {
            "graph": graph,
            "related_resources": related_resources,
            "pk": pk,
            "rtype_src": "Publication",
            "level": 1,
            "publication": publication,
            "authors": authors,
            "org_map": org_map,
            "sidebarleft": 1
        })
Exemplo n.º 3
0
def reads(request, pk):
    sra = ReadsArchive.objects.prefetch_related("external_ids").get(id=pk)

    graph, related_resources = GraphRepo.get_neighborhood(pk, "Reads", level=1)

    external_ids = [
        x.identifier for x in sra.external_ids.all() if x.type == "accession"
    ]

    external_url = ""
    if external_ids:
        external_url = ("https://www.ncbi.nlm.nih.gov/" +
                        NCBISearch.rtype2ncbb[ReadsArchive.TYPE] + "/" +
                        external_ids[0] + "[accn]")

    collaboration = request.user.get_collaboration(
        sra) if request.user.is_authenticated else None
    params = {
        "readsarchive": sra,
        "sidebarleft": 1,
        "level": 1,
        "external_url": external_url,
        "graph": graph,
        "related_resources": related_resources,
        "pk": pk,
        "rtype_src": "Reads",
        "collaboration": collaboration
    }
    return render(request, 'resources/readsarchive.html', params)
Exemplo n.º 4
0
def bioproject(request, pk):
    bioproject = BioProject.objects.get(id=pk)

    graph, related_resources = GraphRepo.get_neighborhood(
        bioproject.id, "BioProject", 1)

    external_ids = [
        x.identifier for x in bioproject.external_ids.all()
        if x.type == "accession"
    ]
    external_url = ""
    if external_ids:
        external_url = ("https://www.ncbi.nlm.nih.gov/" +
                        NCBISearch.rtype2ncbb[BioProject.TYPE] + "/" +
                        external_ids[0])
    collaboration = request.user.get_collaboration(
        bioproject) if request.user.is_authenticated else None
    params = {
        "external_url": external_url,
        "bioproject": bioproject,
        "graph": graph,
        "related_resources": related_resources,
        "sidebarleft": 1,
        "collaboration": collaboration
    }
    return render(request, 'resources/bioproject.html', params)
Exemplo n.º 5
0
def organization(request, pk):
    org = Organization.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk, "Organization",level=2)

    return render(request, 'resources/organization.html',
                  {"graph": graph, "related_resources": related_resources, "pk": pk,
                   "rtype_src":"Organization","organization": org, "sidebarleft": 1, })
Exemplo n.º 6
0
def expression(request, pk):
    expression = Expression.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk,
                                                          "Expression",
                                                          level=2)

    external_ids = [
        x.identifier for x in expression.external_ids.all()
        if x.type == "accession"
    ]
    external_url = ""
    if external_ids:
        external_url = ("https://www.ncbi.nlm.nih.gov/" +
                        NCBISearch.rtype2ncbb[Expression.TYPE] + "/" +
                        external_ids[0])

    collaboration = request.user.get_collaboration(
        expression) if request.user.is_authenticated else None
    params = {
        "expression": expression,
        "sidebarleft": 1,
        "external_url": external_url,
        "collaboration": collaboration,
        "graph": graph,
        "related_resources": related_resources,
        "pk": pk,
        "rtype_src": "Expression"
    }

    return render(request, 'resources/expression.html', params)
Exemplo n.º 7
0
def structure(request, pk):
    pdb = Structure.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk,
                                                          "Structure",
                                                          level=1)
    external_url = "https://www.rcsb.org/structure/" + pdb.name

    loaded = True
    job = LoadPDBJob.objects.filter(pdb=pdb.name)
    if job.exists():
        job = job.order_by("-id")[0]
        if job.status != Job.STATUS.FINISHED:
            loaded = False

    collaboration = request.user.get_collaboration(
        pdb) if request.user.is_authenticated else None
    params = {
        "external_url": external_url,
        "loaded": loaded,
        "collaboration": collaboration,
        "graph": graph,
        "related_resources": related_resources,
        "pk": pk,
        "rtype_src": "Structure",
        "pdb": pdb,
        "sidebarleft": 1,
        "level": 1
    }
    return render(request, 'resources/structure.html', params)
Exemplo n.º 8
0
def barcode(request, pk):
    barcode = Barcode.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk, "Barcode",level=1)
    external_url ="http://www.boldsystems.org/index.php/Public_RecordView?processid=" + barcode.name
    return render(request, 'resources/barcode.html', { "external_url":external_url,
        "graph": graph, "related_resources": related_resources, "pk": pk, "rtype_src": "Barcode",
        "barcode": barcode,     "sidebarleft": 1, })
Exemplo n.º 9
0
def person(request, pk):
    person = Person.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk, "Person")
    return render(
        request, 'resources/person.html', {
            "pk": person.id,
            "related_resources": related_resources,
            "person": person,
            "graph": graph,
            "sidebarleft": 1,
        })
Exemplo n.º 10
0
def tool(request, pk):
    relate_with = None
    if "relate_with" in request.session:
        relate_with = Resource.objects.get(id=int(request.session["relate_with"]))

    tool = Tool.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk, "Tool", level=1)
    collaboration = request.user.get_collaboration(tool)   if request.user.is_authenticated else None

    params = {"external_url": tool.url, "collaboration": collaboration,
              "graph": graph, "related_resources": related_resources, "pk": pk,
              "rtype_src": "Tool",
              "tool": tool, "sidebarleft": 1, "relate_with": relate_with}
    return render(request, 'resources/tool.html', params)
Exemplo n.º 11
0
def sample_view(request, pk):
    sample = Sample.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk,
                                                          "Sample",
                                                          level=2)

    return render(
        request, 'resources/sample.html', {
            "graph": graph,
            "related_resources": related_resources,
            "pk": pk,
            "rtype_src": "Sample",
            "sample": sample,
            "sidebarleft": 1,
            "level": 1
        })
Exemplo n.º 12
0
def UserResourcesView(request, username=""):
    person = request.user.person
    collaborations = None
    graph = None
    if person:
        collaborations = set(
            Collaboration.objects.prefetch_related("resource").filter(
                person=person))
        for c in collaborations:
            c.resource.tname = Resource.RESOURCE_TYPES[c.resource.type]
        if person:
            graph, _ = GraphRepo.get_neighborhood(person.id, "Person", 1)
        else:
            graph = {}
    return render(
        request, 'user/user_resources.html', {
            "user": request.user,
            "person": person,
            "collaborations": collaborations,
            "graph": graph
        })
Exemplo n.º 13
0
def assembly_view(request, pk):
    assembly = Assembly.objects.get(id=pk)
    graph, related_resources = GraphRepo.get_neighborhood(pk,
                                                          "Assembly",
                                                          level=1)

    job = LoadGenomeJob.objects.filter(assembly=assembly)

    contigs = None
    lengths = None
    qsbdb = Biodatabase.objects.filter(name=assembly.name)

    loaded = bool(qsbdb.count())
    processing = False
    if job.exists():
        processing = True
        job = job.order_by("-id")[0]
        if job.status != Job.STATUS.FINISHED:
            loaded = False

    external_ids = [
        x.identifier for x in assembly.external_ids.all()
        if x.type == "accession"
    ]
    external_url = ""
    if external_ids:
        external_url = ("https://www.ncbi.nlm.nih.gov/" +
                        NCBISearch.rtype2ncbb[Assembly.TYPE] + "/" +
                        external_ids[0])

    page = None
    if qsbdb.count():
        bdb = qsbdb.get()
        beqs = bdb.entries.all()

        lengths = {}
        # for x in be.entries.all():
        # SELECT s.bioentry_id, s.version , s.length , s.alphabet
        seqs = Biosequence.objects.prefetch_related("bioentry").raw("""
            SELECT s.bioentry_id, s.length
            FROM biosequence s,bioentry b WHERE b.biodatabase_id = %i AND  b.bioentry_id = s.bioentry_id ;
            """ % (bdb.biodatabase_id))
        for seq in seqs:
            lengths[seq.bioentry.accession] = seq.length
        # assembly.assembly_type = str(Assembly.ASSEMBLY_TYPES[assembly.assembly_type])
        # assembly.level = str(Assembly.ASSEMBLY_LEVEL[assembly.level])

        page = Page.from_request(request, count=beqs.count())

        contigs = beqs[page.offset():page.end()]

    collaboration = request.user.get_collaboration(
        assembly) if request.user.is_authenticated else None

    can_upload = not loaded and collaboration and not external_ids and not bool(
        qsbdb.count())

    params = {
        "query": "",
        "page_obj": page,
        "collaboration": collaboration,
        "can_upload": can_upload,
        "lengths": lengths,
        "external_url": external_url,
        "loaded": loaded,
        "level": {k: str(v)
                  for k, v in Assembly.ASSEMBLY_LEVEL},
        "object": assembly,
        "graph": graph,
        "atypes": {k: str(v)
                   for k, v in Assembly.ASSEMBLY_TYPES},
        "related_resources": related_resources,
        "contigs": contigs,
        "sidebarleft": {},
        "processing": processing
    }

    return render(request, 'resources/assembly_detail.html', params)