Ejemplo n.º 1
0
    def top_level(self, request, api_name=None):
        """
        A view that returns a serialized list of all DAS_sources in registers.
        """
        sources = self._registry

        if request.GET:
            form = DASSourcesForm(request.GET)
            if form.is_valid():
                version = form.cleaned_data['version']
                capability = form.cleaned_data['capability']
                authority = form.cleaned_data['authority']
                stype = form.cleaned_data['type']
                organism = form.cleaned_data['organism']
            else:
                # :TODO raise exception
                pass

            sources = dict((key, value) for key, value in sources.items() if \
                       value._meta.version == int(version))
        else:
            pass

        if api_name is None:
            api_name = self.api_name

        #desired_format = determine_format(request, serializer)
        desired_format = 'application/xml'
        options = {}
        response = HttpResponse(
            content=top_level_serializer(sources),
            content_type=build_content_type(desired_format))
        response = add_das_headers(response, self.version)
        return response
Ejemplo n.º 2
0
    def top_level(self, request, api_name=None):
        """
        A view that returns a serialized list of all DAS_sources in registers.
        """
        sources = self._registry

        if request.GET:
            form = DASSourcesForm(request.GET)
            if form.is_valid():
                version = form.cleaned_data['version']
                capability = form.cleaned_data['capability']
                authority = form.cleaned_data['authority']
                stype = form.cleaned_data['type']
                organism = form.cleaned_data['organism']
            else: 
                # :TODO raise exception
                pass

            sources = dict((key, value) for key, value in sources.items() if \
                       value._meta.version == int(version))
        else: pass

        if api_name is None:
            api_name = self.api_name

        #desired_format = determine_format(request, serializer)
        desired_format = 'application/xml'
        options = {}
        response = HttpResponse(content = top_level_serializer(sources),
                     content_type=build_content_type(desired_format))
        response = add_das_headers(response, self.version)
        return response
Ejemplo n.º 3
0
    def get_features(self, request, **kwargs):
        """ Returns a DAS GFF xml.  

        Calls ''obj_get'' to fetch only the objects requested.  This method
        only responds to HTTP GET.  

        Similar to obj_get_list in ModelResource with modifications.  Need to
        make this a factory so that specific fields and be mapped to the
        segment and start end.  
        """
        
        if hasattr(request, 'GET'):
            reference, start, stop = parse_das_segment(request)
        query_seg = {'id': reference, 'start':start, 'stop':stop}
        
        query_method = getattr(self, "%s_query" % self._meta.filetype,  None)
        if query_method:
            hits = query_method(**query_seg)
        else:
            raise NotImplementedError("No query function implemented for\
                    filetype %s" % self._meta.filetyp)
        
        #:TODO implement json return as well.        
        try:
            content = feature_serializer(request, hits, format_json = getattr(self._meta , 'json'), **query_seg) 
        except:
            content = feature_serializer(request, hits, **query_seg) 
        response = HttpResponse(content = content,
                content_type = 'application/xml')
        response = add_das_headers(response)
        return response
Ejemplo n.º 4
0
 def get_types(self, request, **kwargs):
     registry = {getattr(self._meta , 'resource_name'): self}
     content = serializers.type_serializer(request)
     response = HttpResponse(
             content = content,
             content_type = 'application/xml')
     response = add_das_headers(response)
     return response
Ejemplo n.º 5
0
    def get_features(self, request, **kwargs):
        """ Returns a DAS GFF xml.  

        Calls ''obj_get'' to fetch only the objects requested.  This method
        only responds to HTTP GET.  

        Similar to obj_get_list in ModelResource with modifications.  Need to
        make this a factory so that specific fields and be mapped to the
        segment and start end.  
        """
        if hasattr(request, 'GET'):
            reference, start, stop = parse_das_segment(request)
        query_seg = {'id': reference, 'start':start, 'stop':stop}
        # Attempts to be smart about field mapping
        # :TODO implement this
        if 'chrom' in self.fields:
            pass
        # :TODO Need to implement type, category, feature_id and maxbins
        # :TODO Check if model has a Kent bin.  Also benchmark using this overa
        # standard index.
        # :TODO make reference more general
        try:
            reference = int(reference)
        except ValueError:
            # For when the query is 'chr1'
            reference = reference
        self.is_authenticated(request)

        # Check if there is a binning scheme.  Assume it follows the
        # UCSC binning scheme.
        
        try:
            if start:
                base_object_list = self.get_object_list(request).filter(
                        Q(start__range=(start,stop)) |\
                        Q(end__range=(start,stop)), 
                        chrom__exact = reference)
            else:
                base_object_list = self.get_object_list(request).filter(
                        chrom__exact = reference)
            # :TODO authorization check
        except ValueError:
            raise ValueError('Invalid Request')
        # Do I need to convert to a bundle, or too much.  
        '''
        bundles = [self.build_bundle(obj=obj, request=request) for obj in\
                base_object_list]
        to_be_serialized = [self.full_dehydrate(bundle) for bundle in bundles]
        '''
        try:
            content = feature_serializer(request, base_object_list, format_json = getattr(self._meta , 'json'), **query_seg)
        except:
            content = feature_serializer(request, base_object_list, **query_seg)
        response = HttpResponse(content = content,
                content_type = 'application/xml')
        response = add_das_headers(response)
        return response
Ejemplo n.º 6
0
 def get_list(self, request, **kwargs):
     """ Replaces the standard resource response with the sources one.
     """
     # :TODO modify top_level_serializer or pass a list with self as
     # argument?
     registry = {getattr(self._meta, "resource_name"): self}
     content = serializers.top_level_serializer(registry)
     response = HttpResponse(content=content, content_type="application/xml")
     response = add_das_headers(response)
     return response
Ejemplo n.º 7
0
 def get_list(self, request, **kwargs):
     """ Replaces the standard resource response with the sources one.
     """
     # :TODO modify top_level_serializer or pass a list with self as
     # argument?
     registry = {getattr(self._meta , 'resource_name'): self}
     content = serializers.top_level_serializer(registry)
     response = HttpResponse(
         content = content,
         content_type = 'application/xml')
     response = add_das_headers(response)
     return response
Ejemplo n.º 8
0
    def get_features(self, request, **kwargs):
        """ Returns a DAS GFF xml.

        Calls ''obj_get'' to fetch only the objects requested.  This method
        only responds to HTTP GET.

        Similar to obj_get_list in ModelResource with modifications.  Need to
        make this a factory so that specific fields and be mapped to the
        segment and start end.
        """
        if hasattr(request, 'GET'):
            reference, start, stop = parse_das_segment(request)
        query_seg = {'id': reference, 'start':start, 'stop':stop}
        if 'chrom' in self.fields:
            pass
        try:
            reference = int(reference)
        except ValueError:
            reference = reference
        self.is_authenticated(request)
        # :TODO put this throught the regular filter
        try:
            if start:
                base_object_list = self.get_object_list(request).filter(
                        Q(start__range=(start, stop)) |\
                        Q(end__range=(start, stop)),
                        chrom__exact = reference)
            else:
                base_object_list = self.get_object_list(request).filter(
                        chrom__exact = reference)
            # :TODO authorization check
        except ValueError:
            raise ValueError('Invalid Request')
        bundles = [self.build_bundle(obj=obj, request=request) for obj in\
                base_object_list]
        to_be_serialized = [self.full_dehydrate(bundle) for bundle in bundles]
        # passing reqeust into options is, maybe I should pass in the whole
        # request? 
        options = {'query': query_seg, 
                'method': self._meta.method, 
                'request_string': request.META['QUERY_STRING'],
                'request_path': request.path,
        }
        content = self.serialize(request, to_be_serialized, 'xml',
                options=options)
        response = HttpResponse(content = content,
                content_type = 'application/xml')
        response = add_das_headers(response)
        return response
Ejemplo n.º 9
0
    def get_features(self, request, **kwargs):
        """ Returns a DAS GFF xml.

        Calls ''obj_get'' to fetch only the objects requested.  This method
        only responds to HTTP GET.

        Similar to obj_get_list in ModelResource with modifications.  Need to
        make this a factory so that specific fields can be mapped to the
        segment and start end.
        """

        if hasattr(request, "GET"):
            reference, start, stop = parse_das_segment(request)
        query_seg = {"id": self._meta.ref_prefix + reference, "start": start, "stop": stop}

        query_method = getattr(self, "%s_query" % self._meta.filetype, None)
        if query_method:
            hits = query_method(**query_seg)
        else:
            raise NotImplementedError(
                "No query function implemented for\
                    filetype %s"
                % self._meta.filetype
            )
        options = {
            "query": query_seg,
            "method": self._meta.method,
            "request_string": request.META["QUERY_STRING"],
            "request_path": request.path,
        }
        """
        to_be_serialized = [self.build_bundle(data = i.__dict__,
            request=request) for i in hits]
    
        content = feature_serializer(request, hits, **query_seg) 
        """
        to_be_serialized = []
        for i in hits:
            to_be_serialized.append(Bundle(data=i.__dict__, request=request))
        # self.full_dehydrate(hits)
        content = self.serialize(request, to_be_serialized, "xml", options=options)
        response = HttpResponse(content=content, content_type="application/xml")
        response = add_das_headers(response)
        return response
Ejemplo n.º 10
0
 def get_stylesheet(self, request, **kwargs):
     registry = {getattr(self._meta, "resource_name"): self}
     content = serializers.bam_stylesheet(request)
     response = HttpResponse(content=content, content_type="application/xml")
     response = add_das_headers(response)
     return response