diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index bbf861e..0343397 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -20,10 +20,25 @@ You can install scona directly from the GitHub repository:: If you want to edit scona it's recommended that you pass the ``-e`` flag to ``pip`` to install the package editably. +Getting Started +--------------- + +We have automatically generated `docstring `_ documentation and here's how to navigate to it. + +See all docs organized in the alphabetical order: + * :ref:`genindex` + +See the structure of the package: + * :ref:`modindex` + +See the submodules page: + * :ref:`ref-subpackages-label` + +| Besides, you can type any function into the **search bar** and come up with some results. +| Alongside this documentation scona has some jupyter notebook `tutorials `_. + Finding Help ------------ If you have questions or want to get in touch, you can join our `gitter lobby `_, tweet `@Whitaker_Lab `_ or email Isla at islastaden@gmail.com. -Getting Started ---------------- -Alongside this documentation scona has some jupyter notebook `tutorials `_. + diff --git a/docs/source/scona.rst b/docs/source/scona.rst index cf7d054..645ab07 100644 --- a/docs/source/scona.rst +++ b/docs/source/scona.rst @@ -1,6 +1,8 @@ scona package ============================= +.. _ref-subpackages-label: + Subpackages ----------- diff --git a/scona/scripts/visualisation_commands.py b/scona/scripts/visualisation_commands.py index 86bd5ef..6e9af67 100644 --- a/scona/scripts/visualisation_commands.py +++ b/scona/scripts/visualisation_commands.py @@ -54,15 +54,37 @@ def rescale(fname, suff='png'): # And you're done! -def view_corr_mat(corr_mat_file, +def view_corr_mat(corr_mat, output_name, cmap_name='RdBu_r', cost=None, bin=False): - ''' This is a visualisation tool for correlation matrices''' + ''' + This is a visualisation tool for correlation matrices + + Parameters + ---------- + corr_mat : :class:`str` or :class:`pandas.DataFrame` or :class:`numpy.array` + corr_mat could be: + + - a string object - Path to the File, containing the matrix; ``Note`` loading the corr_mat from file is only possible if all data values are float (or integers). Please do not include column or row labels in the file. + + - or a pandas.DataFrame object to represent a correlation matrix; + + - or a numpy.array representing a correlation matrix; + output_name : :class:`str` + the name of the file you want to save your visualization + of correlation matrix to in. + cmap_name : string or Colormap, optional + A Colormap instance or registered colormap name. + The colormap maps scalar data to colors. It is ignored for RGB(A) data. + Defaults to 'RdBu_r'. - # Read in the data - M = np.loadtxt(corr_mat_file) + Returns + ------- + The visualization of the correlation matrix is saved in the file. + + ''' # If cost is given then roughly threshold at that cost. # NOTE - this is not actually the EXACT network that you're analysing @@ -70,6 +92,18 @@ def view_corr_mat(corr_mat_file, # you a good sense of the network structure. # #GoodEnough ;) + if isinstance(corr_mat, str): + M = np.loadtxt(corr_mat) # Read in the data + elif isinstance(corr_mat, pd.DataFrame): + M = corr_mat.to_numpy() # Convert the DataFrame to a NumPy array + elif isinstance(corr_mat, np.ndarray): + M = corr_mat # support numpy array as input to the function + else: + raise TypeError("corr_mat argument must be 1) a path to the file containing the matrix or 2) pandas.DataFrame object or 3) numpy.array") + + if M.shape[0] != M.shape[1]: + raise ValueError("The correlation matrix must be n x n, where n is the number of nodes") + if cost: thr = np.percentile(M.reshape(-1), 100-cost) M[M