import igraph
import numpy
import pandas
import matplotlib.pyplot

"""
Explanation: Class Session 17 - Date Hubs and Party Hubs
Comparing the histograms of local clustering coefficients of date hubs and party hubs
In this class, we will analyze the protein-protein interaction network for two classes of yeast proteins, "date hubs" and "party hubs" as defined by Han et al. in their 2004 study of protein-interaction networks and gene expression (Han et al., Nature, v430, p88, 2004). The authors of that study claimed that there is no difference in the local clustering density, between "date hubs" and "party hubs".  We will put this to the test. We for each of the "date hub" and "party hub" proteins, we will compute its local clustering coefficient (Ci) in the protein-protein interaction network.  We will then histogram the Ci values for the two sets of hubs, so that we can compare the distributions of local clustering coefficients for "date hubs" and "party hubs". We will use a statistical test (Kolmogorov-Smirnov) to compare the two distributions of Ci values.
To get started, we load the modules that we will require:
End of explanation
"""


hub_data = 

"""
Explanation: Next, we'll load the file of hub types shared/han_hub_data.txt (which is a two-column TSV file in which the first column is the protein name and the second column contains the string date or party for each row; the first row of the file contains the column headers), using our old friend pandas.read_csv. This file has a header so pass header=0 to read_csv.
End of explanation
"""


edge_data = 

"""
Explanation: Let's take a peek at the structure of the hub_data data frame, using head and shape.  Here's what it should look like:
Next, let's load the file of yeat protein-protein interaction network edges shared/han_network_edges.txt (which is a two-column file, with first column is the first protein in the interacting pair, and the second column is the second protein in the interacting pair).This file has a header so pass header=0 to read_csv.
End of explanation
"""


ppi_graph = 

"""
Explanation: Let's take a peek at the data frame edge_df, using head and shape:
make an undirected igraph Graph from the edgelist data; show summary data on the graph as a sanity-check
It will be convenient to let igraph compute the local clustering coefficients.  So, we'll want to make an undirected igraph igraph.Graph object from the edgelist data, using our old friend igraph.Graph.TupleList:
End of explanation
"""


graph_vertices = 

graph_vertices[0:10]

[graph_vertices[i] for i in range(0,10)]

"""
Explanation: As always, we'll use igraph.Graph.summary to sanity check the Graph object:
Generate a list of the names of the proteins in the order of the proteins' corresponding vertices in the igraph Graph object
End of explanation
"""


graph_vertices_df = 
graph_vertices_df.columns = ["Protein"]
graph_vertices_df["order"]=graph_vertices_df.index

"""
Explanation: Make a dataframe containing the protein names (as column "Protein") and the vertex IDs (as column "order"):
End of explanation
"""


graph_vertices_df_merged = ## fill in the merge call here
graph_vertices_df_merged = graph_vertices_df_merged.sort_values("order")

"""
Explanation: Let's take a peek at this data frame:
Let's use the pandas.DataFrame.merge method on the graph_vertices_df object to pull in the hub type (date or party) for vertices that are hubs, by passing hub_data to merge.  Don't forget to specify how='outer' and on="Protein":
End of explanation
"""


vertex_types_np = 

"""
Explanation: Having merged the hub type information into graph_vertices_df, let's take a peek at it using head and shape:
Let's pull out the HubType column as a numpy array, using column indexing (["HubType"]) and then values.tolist():
End of explanation
"""


vertex_types_np

"""
Explanation: Let's take a peek at this numpy.array that we have just created:
End of explanation
"""


date_hub_inds = 
party_hub_inds = 

"""
Explanation: Use numpy.where in order to find the index numbers of the proteins that are "date hubs" and that are "party hubs":
End of explanation
"""


ci_values = 
ci_values_np =

"""
Explanation: Use the igraph.Graph.transitivity_local_undirected function in igraph to compute the local clustering coefficients for every vertex in the graph. Make a numpy.array from the resulting list of Ci values:
End of explanation
"""


ci_values_np

"""
Explanation: Let's take a peek at the ci_values_np array that you have just created.  What are the nan values, and what do they signify?  Is this normal?
End of explanation
"""


ci_values_date_hubs = 
ci_values_party_hubs = 

"""
Explanation: Make a numpy.array of the Ci values of the date hubs (ci_values_date_hubs) and the Ci values of the party hubs (ci_values_party_hubs)
End of explanation
"""


matplotlib.pyplot.hist(ci_values_date_hubs, normed=1, alpha=0.5, label="date")
matplotlib.pyplot.hist(ci_values_party_hubs, normed=1, alpha=0.5, label="party")
matplotlib.pyplot.legend(loc="upper center")
matplotlib.pyplot.xlabel("Ci")
matplotlib.pyplot.ylabel("frequency")
matplotlib.pyplot.show()

"""
Explanation: Plot the histograms of the local clustering coefficients of the "date hubs" and the "party hubs".
End of explanation
"""


