Diagnostic

pygna.diagnostic.plot_degree(degree_object: networkx.classes.graph.Graph, output_file: str)[source]

Diagnosis tool for the degree object. It takes a graph and plot its statistics

Parameters:
  • degree_object – the graph to plot
  • output_file – the path to save the file

Example

>>> graph = nx.complete_graph(100)
>>> plot_degree(nx.degree(graph), "graph_degree")
pygna.diagnostic.plot_connected_components(c_components: networkx.algorithms.components.connected.connected_components, output_file: str) → None[source]

Diagnosis tool for the connected components object. Creates the histogram of the components length, to analyse the relationship between the lcc and the other c_components, and prints some overall stats about the connected components

Parameters:
  • c_components – the list of the connected components
  • output_file – the path to save the file

Example

>>> from pygna import diagnostic
>>> import pygna.reading_class as rc
>>> network = rc.ReadTsv("network_file.tsv").get_network()
>>> geneset = rc.ReadGmt("geneset_input_file.gmt").get_geneset("brca")
>>> c_components_figure_file = "components_plot.pdf"
>>> for setname, item in geneset.items():
...     graph = nx.subgraph(network, item)
...     diagnostic.plot_connected_components(nx.connected_components(graph), c_components_figure_file)
pygna.diagnostic.plot_diffusion_matrix(nodes: list, matrix: numpy.ndarray, filename: str, show_labels: bool = False) → None[source]

Diagnosis tool for a diffusion matrix. It shows the weighted adjacency matrix that is the output of a build process

Parameters:
  • nodes – the network nodes
  • matrix – the diffusion matrix
  • filename – the path to save the file
  • show_labels – if labels should be plotted

Example

>>> nodes = ["A", "B", "C"]
>>> matrix = np.random.rand(3,2)
>>> plot_diffusion_matrix(nodes, matrix, "diff_matrix.pdf")
pygna.diagnostic.plot_null_distribution(null_distribution: list, observed: list, output_file: str, setname: str, alternative: str = 'greater') → None[source]

Saves the density plot of the null distribution and pinpoints the observed value. Please refer to the CLI for the usage of this function

Parameters:
  • null_distribution – the list with the values from the null distribution
  • observed – list of the observed genes
  • output_file – the path to save the file
  • setname – the name of the gene set
  • alternative – use “greater” if you want to take the genes with greater than the observed value

Example

>>> from pygna import diagnostic
>>> import pygna.statistical_test as st
>>> import pygna.reading_class as rc
>>> network = rc.ReadTsv("network_file.tsv").get_network()
>>> st_test = st.StatisticalTest(st.geneset_total_degree_statistic, network)
>>> geneset = rc.ReadGmt("geneset_file.gmt").get_geneset("brca")
>>> for setname, item in geneset.items():
...     observed, pvalue, null_d, n_mapped, n_geneset = st_test.empirical_pvalue(item, max_iter=500, alternative="greater", cores=10)
...     diagnostic.plot_null_distribution(null_d, observed, "./results/" + setname +'_total_degree_null_distribution.pdf', setname=setname)