Beispiel #1
0
    def get_similar_disease(self, disease, **kwargs):
        """
        Return targets sharing a similar patter nof association to diseases
        Accepts any string as `disease` parameter and fires a search if nothing is retireved on a first attempt

        Args:
            disease (str): a disease identifier or a string to search for a disease mapping
        Keyword Args:
            **kwargs: are passed as parameters to the /private/relation/disease method of the REST API
        Returns:
            IterableResult: Result of the query
        """
        if not isinstance(disease, str):
            raise AttributeError('disease must be of type str')
        result = IterableResult(self.conn)
        result(self._relation_disease_endpoint+'/'+disease, **kwargs)
        if not result:
            search_result = next(self.search(disease, size=1, filter='disease'))
            if not search_result:
                raise AttributeError('cannot find an disease id for disease {}'.format(disease))
            disease_id = search_result['id']
            logger.debug('{} resolved to id {}'.format(disease, disease_id))
            result = IterableResult(self.conn)
            result(self._relation_disease_endpoint + '/' + disease_id, **kwargs)
        return result
Beispiel #2
0
    def get_similar_target(self, target, **kwargs):
        """
        Return targets sharing a similar patter nof association to diseases
        Accepts any string as `target` parameter and fires a search if it is not an Ensembl Gene identifier

        Args:
            target (str): an Ensembl Gene identifier or a string to search for a gene mapping
        Keyword Args:
            **kwargs: are passed as parameters to the /private/relation/target method of the REST API
        Returns:
            IterableResult: Result of the query
        """
        if not isinstance(target, str):
            raise AttributeError('target must be of type str')
        if not target.startswith('ENSG'):
            search_result = next(self.search(target, size=1, filter='target'))
            if not search_result:
                raise AttributeError('cannot find an ensembl gene id for target {}'.format(target))
            target_id = search_result['id']
            logger.debug('{} resolved to id {}'.format(target, target_id))
        else:
            target_id = target

        result = IterableResult(self.conn)
        result(self._relation_target_endpoint+'/'+target_id, **kwargs)
        return result
Beispiel #3
0
    def get_metrics(self, **kwargs):
        """
        Returns metrics about the data served by the REST API

        Returns:
            IterableResult: Result of the query
        """
        result = IterableResult(self.conn)
        result(self._metrics_endpoint)
        return result
Beispiel #4
0
    def get_stats(self):
        """
        Returns statistics about the data served by the REST API

        Returns:
            IterableResult: Result of the query
        """
        result = IterableResult(self.conn)
        result(self._stats_endpoint)
        return result
Beispiel #5
0
    def filter_associations(self,**kwargs):
        """
        Retrieve a set of associations by applying a set of filters

        Keyword Args:
            **kwargs: are passed as parameters to the /public/association/filterby method of the REST API

        Returns:
            IterableResult: Result of the query
        """
        result = IterableResult(self.conn)
        result(self._filter_associations_endpoint, **kwargs)
        return result
Beispiel #6
0
    def get_disease(self, disease_id, **kwargs):
        """
        Retrieve a specific disease object from the REST API provided its ID

        Args:
            evidence_id: OT disease ID (EFO, Orphanet, ...)
        Keyword Args:
            **kwargs: are passed as other parameters to the /private/disease method of the REST API

        Returns:
             IterableResult: Result of the query
        """
        result = IterableResult(self.conn)
        result(self._get_disease + '/' + disease_id, **kwargs)
        return result
Beispiel #7
0
    def get_target(self, target_id, **kwargs):
        """
        Retrieve a specific target object from the REST API provided its ID

        Args:
            target_id: Ensembl ID
        Keyword Args:
            **kwargs: are passed as other parameters to the /private/target method of the REST API

        Returns:
             IterableResult: Result of the query
        """
        result = IterableResult(self.conn)
        result(self._get_target + '/' + target_id, **kwargs)
        return result
Beispiel #8
0
    def get_association(self,association_id, **kwargs):
        """
        Retrieve a specific Association object from the REST API provided its ID

        Args:
            association_id (str): Association ID
        Keyword Args:
            **kwargs: are passed as other parameters to the /public/association method of the REST API

        Returns:
             IterableResult: Result of the query
        """
        kwargs['id']= association_id
        result = IterableResult(self.conn)
        result(self._get_associations_endpoint, **kwargs)
        return result
Beispiel #9
0
    def get_evidence(self, evidence_id, **kwargs):
        """
        Retrieve a specific Evidence object from the REST API provided its ID

        Args:
            evidence_id:
        Keyword Args:
            **kwargs: are passed as other parameters to the /public/evidence method of the REST API

        Returns:
             IterableResult: Result of the query
        """
        kwargs['id']= evidence_id
        result = IterableResult(self.conn)
        result(self._get_evidence_endpoint, **kwargs)
        return result
Beispiel #10
0
    def search(self, query,**kwargs):
        """
        Search a string and return a list of objects form the search method of the REST API.
        E.g. A returned object could be a target or a disease

        Args:
            query (str): string to search for
        Keyword Args:
            **kwargs: are passed as other parameters to the /public/search method of the REST API

        Returns:
            IterableResult: Result of the query
        """
        kwargs['q']=query
        result = IterableResult(self.conn)
        result(self._search_endpoint,**kwargs)
        return result