title: How to isolate a subnetwork from a graph, including nodes and edges up to depth n?
body: <p>I'm trying to write a script which will let me mangle (edit, cut, change) some big network files from a command line interface. One of the things I'm trying to do is isolate a subnetwork from a larger network based on searching for matches in node labels. </p>
  
  <p>So basically I'd have a networkx graph with maybe 7000 nodes and corresponding edges with various labels. Then I'd match a string, eg "Smith" to the nodes. I'd get a match of maybe 30 nodes (label:"John Smith", label:"Peter Smith", etc). I'd then like to make a new networkx network containing those 30 nodes, and the edges they have, and the nodes those edges connect to, up to a depth of n, or optionally until all the nodes and edges are found. </p>
  
  <p>My current code is rubbish, so maybe I'll try to write some pseudocode:</p>
  
  <pre><code>for node in networkx_network: 
      if searched_string in node:
          new_network.add(node.subnetwork(depth=n))
  </code></pre>
  
  <p>I've spent days googling for a solution, and maybe subgraph, or neighbors, or connected_components is the right thing to do, but I can't wrap my head around how to do it.</p>