src/pybel/manager/query_manager.py
def query_edges(
        self,
        bel: Optional[str] = None,
        source_function: Optional[str] = None,
        source: Union[None, str, Node] = None,
        target_function: Optional[str] = None,
        target: Union[None, str, Node] = None,
        relation: Optional[str] = None,
    ):
        """Return a query over the edges in the database.

        Usually this means that you should call ``list()`` or ``.all()`` on this result.

        :param bel: BEL statement that represents the desired edge.
        :param source_function: Filter source nodes with the given BEL function
        :param source: BEL term of source node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
        :param target_function: Filter target nodes with the given BEL function
        :param target: BEL term of target node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
        :param relation: The relation that should be present between source and target node.
        """
        if bel:
            return self.search_edges_with_bel(bel)

        query = self.session.query(Edge)

        if relation:
            query = query.filter(Edge.relation.like(relation))

        if source_function:
            source_node_table = aliased(Node)
            query = query \
                .join(source_node_table, Edge.source_id == source_node_table.id) \
                .filter(source_node_table.type == source_function)

        if target_function:
            target_node_table = aliased(Node)
            query = query \
                .join(target_node_table, Edge.target_id == target_node_table.id) \
                .filter(target_node_table.type == target_function)

        if source:
            if isinstance(source, str):
                source = self.query_nodes(bel=source)
                if source.count() == 0:
                    return []
                source = source.first()  # FIXME what if this matches multiple?
                query = query.filter(Edge.source == source)
            elif isinstance(source, Node):
                query = query.filter(Edge.source == source)
            else:
                raise TypeError('Invalid type of {}: {}'.format(source, source.__class__.__name__))

        if target:
            if isinstance(target, str):
                targets = self.query_nodes(bel=target).all()
                target = targets[0]  # FIXME what if this matches multiple?
                query = query.filter(Edge.target == target)
            elif isinstance(target, Node):
                query = query.filter(Edge.target == target)
            else:
                raise TypeError('Invalid type of {}: {}'.format(target, target.__class__.__name__))

        return query
Return a query over the edges in the database.

        Usually this means that you should call ``list()`` or ``.all()`` on this result.

        :param bel: BEL statement that represents the desired edge.
        :param source_function: Filter source nodes with the given BEL function
        :param source: BEL term of source node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
        :param target_function: Filter target nodes with the given BEL function
        :param target: BEL term of target node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
        :param relation: The relation that should be present between source and target node.
        
Return a query over the edges in the database.
Return a query over the edges in the database .
def query_edges(
        self,
        bel: Optional[str] = None,
        source_function: Optional[str] = None,
        source: Union[None, str, Node] = None,
        target_function: Optional[str] = None,
        target: Union[None, str, Node] = None,
        relation: Optional[str] = None,
    ):
        if bel:
            return self.search_edges_with_bel(bel)
        query = self.session.query(Edge)
        if relation:
            query = query.filter(Edge.relation.like(relation))
        if source_function:
            source_node_table = aliased(Node)
            query = query \
                .join(source_node_table, Edge.source_id == source_node_table.id) \
                .filter(source_node_table.type == source_function)
        if target_function:
            target_node_table = aliased(Node)
            query = query \
                .join(target_node_table, Edge.target_id == target_node_table.id) \
                .filter(target_node_table.type == target_function)
        if source:
            if isinstance(source, str):
                source = self.query_nodes(bel=source)
                if source.count() == 0:
                    return []
                source = source.first()  
                query = query.filter(Edge.source == source)
            elif isinstance(source, Node):
                query = query.filter(Edge.source == source)
            else:
                raise TypeError('Invalid type of {}: {}'.format(source, source.__class__.__name__))
        if target:
            if isinstance(target, str):
                targets = self.query_nodes(bel=target).all()
                target = targets[0]  
                query = query.filter(Edge.target == target)
            elif isinstance(target, Node):
                query = query.filter(Edge.target == target)
            else:
                raise TypeError('Invalid type of {}: {}'.format(target, target.__class__.__name__))
        return query
def query_edges ( self , bel : Optional [ str ] = None , source_function : Optional [ str ] = None , source : Union [ None , str , Node ] = None , target_function : Optional [ str ] = None , target : Union [ None , str , Node ] = None , relation : Optional [ str ] = None , ) : if bel : return self . search_edges_with_bel ( bel ) query = self . session . query ( Edge ) if relation : query = query . filter ( Edge . relation . like ( relation ) ) if source_function : source_node_table = aliased ( Node ) query = query . join ( source_node_table , Edge . source_id == source_node_table . id ) . filter ( source_node_table . type == source_function ) if target_function : target_node_table = aliased ( Node ) query = query . join ( target_node_table , Edge . target_id == target_node_table . id ) . filter ( target_node_table . type == target_function ) if source : if isinstance ( source , str ) : source = self . query_nodes ( bel = source ) if source . count ( ) == 0 : return [ ] source = source . first ( ) query = query . filter ( Edge . source == source ) elif isinstance ( source , Node ) : query = query . filter ( Edge . source == source ) else : raise TypeError ( 'Invalid type of {}: {}' . format ( source , source . __class__ . __name__ ) ) if target : if isinstance ( target , str ) : targets = self . query_nodes ( bel = target ) . all ( ) target = targets [ 0 ] query = query . filter ( Edge . target == target ) elif isinstance ( target , Node ) : query = query . filter ( Edge . target == target ) else : raise TypeError ( 'Invalid type of {}: {}' . format ( target , target . __class__ . __name__ ) ) return query
Return a query over the edges in the database.
Return a query over the edges in the database .
"""Return a query over the edges in the database.

        Usually this means that you should call ``list()`` or ``.all()`` on this result.

        :param bel: BEL statement that represents the desired edge.
        :param source_function: Filter source nodes with the given BEL function
        :param source: BEL term of source node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
        :param target_function: Filter target nodes with the given BEL function
        :param target: BEL term of target node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
        :param relation: The relation that should be present between source and target node.
        """ # FIXME what if this matches multiple? # FIXME what if this matches multiple?
self
bel
Optional[str]
BEL statement that represents the desired edge.
BEL statement that represents the desired edge .
source_function
Optional[str]
Filter source nodes with the given BEL function
Filter source nodes with the given BEL function
source
Union[None, str, Node]
BEL term of source node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
BEL term of source node e . g . ` ` p ( HGNC : APP ) ` ` or : class : ` Node ` object .
target_function
Optional[str]
Filter target nodes with the given BEL function
Filter target nodes with the given BEL function
target
Union[None, str, Node]
BEL term of target node e.g. ``p(HGNC:APP)`` or :class:`Node` object.
BEL term of target node e . g . ` ` p ( HGNC : APP ) ` ` or : class : ` Node ` object .
relation
Optional[str]
The relation that should be present between source and target node.
The relation that should be present between source and target node .