예제 #1
0
def phenotype_detail(request, q, format=None):
    """
    Detailed information about the phenotype
    ---
    parameters:
        - name: q
          description: the id or doi of the phenotype
          required: true
          type: string
          paramType: path

    serializer: PhenotypeListSerializer
    omit_serializer: false

    produces:
        - text/csv
        - application/json

    """
    doi = _is_doi(DOI_PATTERN_PHENOTYPE, q)

    try:
        id = doi if doi else int(q)
        phenotype = Phenotype.objects.published().get(pk=id)
    except:
        return HttpResponse(status=404)

    if request.method == "GET":
        serializer = PhenotypeListSerializer(phenotype, many=False)
        return Response(serializer.data)
예제 #2
0
def study_all_pheno(request, q=None, format=None):
    """
    List all phenotypes for a study
    ---

    serializer: PhenotypeListSerializer
    omit_serializer: false

    produces:
        - text/csv
        - application/json
    """
    doi = _is_doi(DOI_PATTERN_STUDY, q)
    try:
        id = doi if doi else int(q)
        study = Study.objects.published().get(pk=id)
    except:
        return HttpResponse(status=404)

    if request.method == "GET":
        serializer = PhenotypeListSerializer(
            study.phenotype_set.all().annotate(
                num_values=Count('phenotypevalue')),
            many=True)
        return Response(serializer.data)
예제 #3
0
def _create_phenotypes_files(studies, folder):
    renderer = PhenotypeListRenderer()
    for study in studies:
        serializer = PhenotypeListSerializer(study.phenotype_set.all(),
                                             many=True)
        content = renderer.render(serializer.data)
        study_filename = os.path.join(folder, str(study.id),
                                      'study_%s_phenotypes.csv' % study.id)
        with open(study_filename, 'w') as f:
            f.write(content)
    pass
예제 #4
0
def phenotype_list(request, format=None):
    """
    List all available phenotypes
    ---
    serializer: PhenotypeListSerializer
    omit_serializer: false

    produces:
        - text/csv
        - application/json
    """
    phenotypes = Phenotype.objects.published().all()

    if request.method == "GET":
        serializer = PhenotypeListSerializer(phenotypes, many=True)
        return Response(serializer.data)
예제 #5
0
def search(request, query_term=None, format=None):
    """
    Search for a phenotype or study
    ---
    parameters:
        - name: query_term
          description: the search term
          required: true
          type: string
          paramType: path

    serializer: PhenotypeListSerializer
    omit_serializer: false

    produces:
        - text/csv
        - application/json
    """
    if request.method == "GET":
        if query_term == None:
            studies = Study.objects.published().all()
            phenotypes = Phenotype.objects.published().all()
            accessions = Accession.objects.all()
            ontologies = OntologyTerm.objects.all()
        else:
            studies = Study.objects.published().filter(
                name__icontains=query_term)
            phenotypes = Phenotype.objects.published().filter(
                Q(name__icontains=query_term)
                | Q(to_term__id__icontains=query_term)
                | Q(to_term__name__icontains=query_term))
            accessions = Accession.objects.filter(
                Q(id__icontains=query_term) | Q(name__icontains=query_term))
            ontologies = OntologyTerm.objects.filter(
                name__icontains=query_term)

        study_serializer = StudyListSerializer(studies, many=True)
        phenotype_serializer = PhenotypeListSerializer(phenotypes, many=True)
        accession_serializer = AccessionListSerializer(accessions, many=True)
        ontology_serializer = OntologyTermListSerializer(ontologies, many=True)
        return Response({
            'phenotype_search_results': phenotype_serializer.data,
            'study_search_results': study_serializer.data,
            'accession_search_results': accession_serializer.data,
            'ontology_search_results': ontology_serializer.data
        })
예제 #6
0
def accession_phenotypes(request, pk, format=None):
    """
    List all phenotypes for an accession
    ---

    serializer: PhenotypeListSerializer
    omit_serializer: false

    produces:
        - text/csv
        - application/json
    """
    phenotypes = Phenotype.objects.published().filter(
        phenotypevalue__obs_unit__accession_id=pk)

    if request.method == "GET":
        serializer = PhenotypeListSerializer(phenotypes, many=True)
        return Response(serializer.data)
예제 #7
0
def phenotype_similar_list(request, q, format=None):
    """
    List all available phenotypes matching phenotype q's trait ontology
    ---
    serializer: PhenotypeListSerializer
    omit_serializer: false

    produces:
        - text/csv
        - application/json
    """
    doi = _is_doi(DOI_PATTERN_PHENOTYPE, q)
    try:
        id = doi if doi else int(q)
        phenotype = Phenotype.objects.published().get(pk=id)
    except:
        return HttpResponse(status=404)
    to_term = phenotype.to_term.id
    phenotypes = Phenotype.objects.published().filter(to_term__id=to_term)

    if request.method == "GET":
        serializer = PhenotypeListSerializer(phenotypes, many=True)
        return Response(serializer.data)