%% Plot Subgraph of Animal Sounds
% Create a digraph object that represents the AudioSet ontology.

ygraph = yamnetGraph;

%
% Use dfsearch to perform a depth-first graph search to identify all audio classes under the class Animal.

animalNodes = dfsearch(ygraph,"Animal");

%
% Use subgraph to create a new digraph object that only includes the identified audio classes. Plot the resulting directed edges graph.

animalGraph = subgraph(ygraph,animalNodes);

p = plot(animalGraph);

p.NodeFontSize = 12;
graphFigure = gcf;
old = graphFigure.Position;
set(graphFigure,'position',[old(1),old(2),old(3)*3,old(4)*3])

%
% Use predecessors to determine all predecessors to the Growling sound. Highlight the predecessors on the plot.

preIDs = predecessors(animalGraph,"Growling")

%
% Use highlight to highlight the Growling node and the predecessors on the plot.

highlight(p,"Growling",'NodeColor','g','MarkerSize',8)
highlight(p,preIDs,'NodeColor','r','MarkerSize',8)

% Copyright 2020 The MathWorks, Inc.