1. Definitions & basic recap
Hi! I'm Eric, and I'm a computational biological engineer, and I'll be your instructor for this course!
2. Network/Graph
To get started, let's start by recapping some definitions. Recall that a network, which is also known as a graph, is comprised of two sets: a set of nodes, and a set of edges. We often draw graphs as “circles joined by lines”, where the circles represent some real-world entity, such as individuals in a social network, and the lines denote some relationship between the entities, such as being connected as friends in the social network. A graph can be directed or undirected. Previously, we saw some examples of undirected graphs, such as Facebook - if I request to connect with another person on Facebook, once the other person accepts the Friend Request, we immediately connect, and no direction is implied, thus it is an “Undirected” graph. On the other hand, if we look at the Twitter network, I may choose to Follow another user, but that user may not necessarily follow me back. In this way, the Twitter social network is a “Directed” network. In Python, there is a package called NetworkX, which contains a library of classes and functions for the creation, analysis, and manipulation of graphs. In the previous course, we showed you some of the basics of the NetworkX API, and applied those functions to case studies.
3. Basic NetworkX API
Let’s take a quick look at the basics of the API to refresh your memory. As always, we must first import NetworkX into our Python session. Suppose we had a graph G that already exists in memory. If I want to know how many nodes exist in that graph, I can call on G’s method “dot nodes”, which will return a list of every node in the graph. The analogous method dot edges also exists. Because both equals dot nodes and dot edges return a list, it is thus possible to get the
4. Basic NetworkX API
length of each of those elements. len G dot nodes gives us the number of nodes in the graph, and len G dot edges gives us the number of edges in the graph. Using these two lines of code, we can start describing a graph's basic statistic If you remember, there were multiple types of graphs, and we can check the type of the graph by doing type(G), which in this case is a regular Graph object. Other graph types include DiGraph, MultiGraph, and MultiDiGraph. Previously,
5. Network visualization
you also learned about the nxviz package, which is a package I wrote for that provides a simple API for the the visualization of large complex networks in a rational fashion."Rational” visualizations prioritize the nodes’ placement. This allows us to create beautiful visualizations such as the matrix plot,
6. Network visualization
the arc plot,
7. Network visualization
the circos plot and
8. Network visualization
the HivePlot. We will be using the circos plot the most in this course, as I personally think it has the best combination of aesthetics and functionality.
9. Basic nxviz API
To use the circos plot, you must first import nxviz and matplotlib's pyplot as plt. Then, you can instantiate a new plot object, passing in the graph G. After that, you will have to call the dot draw method of the plot object. Finally, call the plt dot show function to get the plot to be drawn to screen, yielding beautiful network diagrams like the ones below.
10. Let's practice!
Once you're done with the coming warm-up exercises, we will come back to explore a new topic, bipartite graphs. Have fun with the exercises!