Esempio n. 1
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
Esempio n. 2
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
Esempio 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}
        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
Esempio n. 4
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