<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_filtered_graph(self, relations=None, prefix=None):
 """ Returns a networkx graph for the whole ontology, for a subset of relations Only implemented for eager methods. Implementation notes: currently this is not cached Arguments --------- - relations : list list of object property IDs, e.g. subClassOf, BFO:0000050. If empty, uses all. - prefix : String if specified, create a subgraph using only classes with this prefix, e.g. ENVO, PATO, GO Return ------ nx.MultiDiGraph A networkx MultiDiGraph object representing the filtered ontology """


        # trigger synonym cache
        self.all_synonyms()
        self.all_obsoletes()

        # default method - wrap get_graph
        srcg = self.get_graph()
        if prefix is not None:
            srcg = srcg.subgraph([n for n in srcg.nodes() if n.startswith(prefix+":")])
        if relations is None:
            logger.info("No filtering on "+str(self))
            return srcg
        logger.info("Filtering {} for {}".format(self, relations))
        g = nx.MultiDiGraph()

        # TODO: copy full metadata
        logger.info("copying nodes")
        for (n,d) in srcg.nodes(data=True):
            g.add_node(n, **d)

        logger.info("copying edges")
        num_edges = 0
        for (x,y,d) in srcg.edges(data=True):
            if d['pred'] in relations:
                num_edges += 1
                g.add_edge(x,y,**d)
        logger.info("Filtered edges: {}".format(num_edges))
        return g