From 0cb64ab86e56b6da3c0b2f1c2eb3ac69cbadba37 Mon Sep 17 00:00:00 2001 From: wingedRuslan Date: Tue, 2 Apr 2019 23:12:45 +0300 Subject: [PATCH 1/7] Try to link to autodoc content in the introduction.rst --- docs/source/introduction.rst | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index bbf861e..4e61e72 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -20,10 +20,19 @@ 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. + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`scripts#submodules` + +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 `_. + From 86ff8d66ad118df2d55c0c2b9eaf5b8e87e1de33 Mon Sep 17 00:00:00 2001 From: wingedRuslan Date: Mon, 8 Apr 2019 00:15:54 +0300 Subject: [PATCH 2/7] Add documentation to the introduction page --- docs/source/introduction.rst | 16 +++++++++++----- docs/source/scona.rst | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index 4e61e72..0343397 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -23,13 +23,19 @@ If you want to edit scona it's recommended that you pass the ``-e`` flag to ``pi Getting Started --------------- -We have automatically generated docstring documentation and here's how to navigate to it. +We have automatically generated `docstring `_ documentation and here's how to navigate to it. -* :ref:`genindex` -* :ref:`modindex` -* :ref:`scripts#submodules` +See all docs organized in the alphabetical order: + * :ref:`genindex` -Alongside this documentation scona has some jupyter notebook `tutorials `_. +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 ------------ 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 ----------- From 1500c32a8745de446e8c420e122f481e7ff928b2 Mon Sep 17 00:00:00 2001 From: wingedRuslan Date: Tue, 2 Apr 2019 23:12:45 +0300 Subject: [PATCH 3/7] Add documentation to the introduction page, ready for PR --- docs/source/introduction.rst | 21 ++++++++++++++++++--- docs/source/scona.rst | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) 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 ----------- From 9d083dce1a902c4a81e8ad77d612c6e4c6a01f71 Mon Sep 17 00:00:00 2001 From: wingedRuslan Date: Wed, 10 Apr 2019 01:51:52 +0300 Subject: [PATCH 4/7] Update view_corr_mat in visualisation commands to accept corr_mat as DataFrame object and PathToFile --- scona/scripts/visualisation_commands.py | 33 ++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/scona/scripts/visualisation_commands.py b/scona/scripts/visualisation_commands.py index 86bd5ef..1130456 100644 --- a/scona/scripts/visualisation_commands.py +++ b/scona/scripts/visualisation_commands.py @@ -54,15 +54,32 @@ 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:`pandas.DataFrame` or :class:`str` + corr_mat could be a DataFrame object to represent a correlation matrix + or a string object - Path to the File, containing the 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'. + + Returns + ------- + The visualization of the correlation matrix is saved in the file. - # Read in the data - M = np.loadtxt(corr_mat_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 +87,14 @@ 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 + else: + print("Please provide correlation matrix as pandas.DataFrame object or as a path to the file containing the matrix") + return + if cost: thr = np.percentile(M.reshape(-1), 100-cost) M[M Date: Tue, 16 Apr 2019 16:16:09 +0300 Subject: [PATCH 5/7] Add support of numpy.array as an input for view_corr_mat and add raising a TypeError if unsupported type provided --- scona/scripts/visualisation_commands.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scona/scripts/visualisation_commands.py b/scona/scripts/visualisation_commands.py index 1130456..912c0d9 100644 --- a/scona/scripts/visualisation_commands.py +++ b/scona/scripts/visualisation_commands.py @@ -64,9 +64,10 @@ def view_corr_mat(corr_mat, Parameters ---------- - corr_mat : :class:`pandas.DataFrame` or :class:`str` + corr_mat : :class:`pandas.DataFrame` or :class:`str` or :class:`numpy.array` corr_mat could be a DataFrame object to represent a correlation matrix or a string object - Path to the File, containing the 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. @@ -91,9 +92,10 @@ def view_corr_mat(corr_mat, 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: - print("Please provide correlation matrix as pandas.DataFrame object or as a path to the file containing the matrix") - return + raise TypeError("corr_mat argument must be a 1)pandas.DataFrame object or 2) numpy.array or 3)a path to the file containing the matrix") if cost: thr = np.percentile(M.reshape(-1), 100-cost) From d9ed917b9b261270318f109e19c23c73b99ae098 Mon Sep 17 00:00:00 2001 From: wingedRuslan Date: Tue, 16 Apr 2019 19:26:49 +0300 Subject: [PATCH 6/7] Check that corr_mat is n x n matrix, otherwise raise Error --- scona/scripts/visualisation_commands.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scona/scripts/visualisation_commands.py b/scona/scripts/visualisation_commands.py index 912c0d9..d3d9b2d 100644 --- a/scona/scripts/visualisation_commands.py +++ b/scona/scripts/visualisation_commands.py @@ -97,6 +97,9 @@ def view_corr_mat(corr_mat, else: raise TypeError("corr_mat argument must be a 1)pandas.DataFrame object or 2) numpy.array or 3)a path to the file containing the matrix") + 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 Date: Thu, 18 Apr 2019 11:36:27 +0300 Subject: [PATCH 7/7] Explain corr_mat argument to view_corr_mat() more precisely --- scona/scripts/visualisation_commands.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scona/scripts/visualisation_commands.py b/scona/scripts/visualisation_commands.py index d3d9b2d..6e9af67 100644 --- a/scona/scripts/visualisation_commands.py +++ b/scona/scripts/visualisation_commands.py @@ -64,10 +64,14 @@ def view_corr_mat(corr_mat, Parameters ---------- - corr_mat : :class:`pandas.DataFrame` or :class:`str` or :class:`numpy.array` - corr_mat could be a DataFrame object to represent a correlation matrix - or a string object - Path to the File, containing the matrix. - or a numpy.array representing a correlation matrix + 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. @@ -95,7 +99,7 @@ def view_corr_mat(corr_mat, 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 a 1)pandas.DataFrame object or 2) numpy.array or 3)a path to the file containing the matrix") + 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")