From d766ec6c864ac4ebf5aa4a2147f96188ab2a291e Mon Sep 17 00:00:00 2001 From: Alessio Giacomel Date: Tue, 14 Sep 2021 18:24:01 +0200 Subject: [PATCH] commit for pypi upload: v1.0.0 --- MANIFEST.in | 2 +- docs/chapters/01_getting_started.rst | 2 ++ docs/chapters/03_installation.rst | 4 ++-- docs/chapters/04_usage.rst | 18 ++++++++++++++++++ docs/chapters/07_faq.rst | 6 +++--- imaging_transcriptomics/__init__.py | 2 +- .../atlas-desikankilliany_1mm_MNI152.nii.gz | Bin .../data}/atlas_regions_info.csv | 0 .../data}/fsa5_lh_aparc.annot | Bin .../data}/fsa5_rh_aparc.annot | Bin .../data}/gene_expression_data.csv | 0 .../data}/gene_expression_labels.txt | 0 imaging_transcriptomics/inputs.py | 6 +++--- imaging_transcriptomics/transcriptomics.py | 4 ++-- requirements.txt | 1 + setup.py | 4 ++-- 16 files changed, 35 insertions(+), 14 deletions(-) rename {data => imaging_transcriptomics/data}/atlas-desikankilliany_1mm_MNI152.nii.gz (100%) rename {data => imaging_transcriptomics/data}/atlas_regions_info.csv (100%) rename {data => imaging_transcriptomics/data}/fsa5_lh_aparc.annot (100%) rename {data => imaging_transcriptomics/data}/fsa5_rh_aparc.annot (100%) rename {data => imaging_transcriptomics/data}/gene_expression_data.csv (100%) rename {data => imaging_transcriptomics/data}/gene_expression_labels.txt (100%) diff --git a/MANIFEST.in b/MANIFEST.in index 0b5c670..0d6bce0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include data/* +include imaging_transcriptomics/data/* include requirements.txt include ./**/*.yaml diff --git a/docs/chapters/01_getting_started.rst b/docs/chapters/01_getting_started.rst index 9896d3f..3668254 100644 --- a/docs/chapters/01_getting_started.rst +++ b/docs/chapters/01_getting_started.rst @@ -18,3 +18,5 @@ components independently and cumulatively, that can be used to tune consequent a For more information on the use have a look at the :ref:`usage ` page. You can also have a deeper look at the :ref:`methods ` and on :ref:`what to do with the results from the script `. + +For more advanced use, or to integrate it in your python workflow, you can use the :ref:`python module `. diff --git a/docs/chapters/03_installation.rst b/docs/chapters/03_installation.rst index 2b10780..1886d6c 100644 --- a/docs/chapters/03_installation.rst +++ b/docs/chapters/03_installation.rst @@ -13,7 +13,7 @@ To install the ``imaging-transcriptomics`` Python package you must first of all .. note:: - All following steps assume that, if you have created a dedicated environment, this is currently active. If you are unsure you can check with ``which python`` from your terminal or activate your environment via the `` source activate`` (for conda managed environments) or ``source venv/bin/activate`` (for venv managed environments). + All following steps assume that, if you have created a dedicated environment, this is currently active. If you are unsure you can check with ``which python`` from your terminal or activate your environment via the ``source activate`` (for conda managed environments) or ``source venv/bin/activate`` (for venv managed environments). Before installing the ``imaging-transcriptomics`` package we need to install a package that is not available through PyPi but from GitHub only. This package is `pypls `_ and is used in the script to perform all PLS regressions. @@ -27,7 +27,7 @@ This will install install the GitHub repository directly using pip and it will m .. warning:: - Do not install ``pyls`` directly from ``pip`` with the command ``pip install pyls`` as this is a completely different package! + Do not install pyls directly from pip with the command ``pip install pyls`` as this is a completely different package! Once this package is installed you can install the ``imaging-transcriptomics`` package by running: diff --git a/docs/chapters/04_usage.rst b/docs/chapters/04_usage.rst index e332589..bd2eb14 100644 --- a/docs/chapters/04_usage.rst +++ b/docs/chapters/04_usage.rst @@ -39,6 +39,7 @@ Optional additional parameters that can be provided are: ``--suppress`` Sets the logging level to warning and will display only eventual warning messages. +.. _library: ======================= Usage as python library @@ -51,4 +52,21 @@ To the library can be imported by running: import imaging_transcriptomics as imt +Once imported the package will contain the core ``ImagingTranscriptomics`` class, along with other useful functions. +ImagingTranscriptomics Class +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``ImagingTranscriptomics`` class is the core class of the entire package and allows you to run the entire analysis on your data. +To start using the class the first step is to initialise it. A way to do this is: + +.. code:: python + + my_analysis = imt.ImagingTranscriptomics(my_data, n_components=1) + +The ``my_data`` is an array that contains the data you want to analyse (e.g., the average values from the scan). This vector has to have some characteristics, mainly: +* it has to be a ``numpy.array`` with length 41, which corresponds to the number of regions in the left hemisphere of the Desikan-Killiany atlas. +* it has to contain the values you want to analyse but not the ``zscore`` of the values as this is computed automatically during the initialisation. + +When initialising the class one might choose to initialise it using the ``n_components`` or the ``var`` attribute which represent the number of components to use for the regression or the variance to extract respectively. +After setting one, and only one, of the values are set, one can estiamte the other by running the ``my_analysis.pls_all_components()`` method which will compute the PLS regression with 15 components and estimate the variance explained by the user defined diff --git a/docs/chapters/07_faq.rst b/docs/chapters/07_faq.rst index 0a02e6a..17793d0 100644 --- a/docs/chapters/07_faq.rst +++ b/docs/chapters/07_faq.rst @@ -1,8 +1,8 @@ .. _faq: -========================== -Frequently asked questions -========================== +=== +FAQ +=== diff --git a/imaging_transcriptomics/__init__.py b/imaging_transcriptomics/__init__.py index f40a251..e290e2f 100644 --- a/imaging_transcriptomics/__init__.py +++ b/imaging_transcriptomics/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.0.6" +__version__ = "1.0.0" from . import errors from . import bootstrap diff --git a/data/atlas-desikankilliany_1mm_MNI152.nii.gz b/imaging_transcriptomics/data/atlas-desikankilliany_1mm_MNI152.nii.gz similarity index 100% rename from data/atlas-desikankilliany_1mm_MNI152.nii.gz rename to imaging_transcriptomics/data/atlas-desikankilliany_1mm_MNI152.nii.gz diff --git a/data/atlas_regions_info.csv b/imaging_transcriptomics/data/atlas_regions_info.csv similarity index 100% rename from data/atlas_regions_info.csv rename to imaging_transcriptomics/data/atlas_regions_info.csv diff --git a/data/fsa5_lh_aparc.annot b/imaging_transcriptomics/data/fsa5_lh_aparc.annot similarity index 100% rename from data/fsa5_lh_aparc.annot rename to imaging_transcriptomics/data/fsa5_lh_aparc.annot diff --git a/data/fsa5_rh_aparc.annot b/imaging_transcriptomics/data/fsa5_rh_aparc.annot similarity index 100% rename from data/fsa5_rh_aparc.annot rename to imaging_transcriptomics/data/fsa5_rh_aparc.annot diff --git a/data/gene_expression_data.csv b/imaging_transcriptomics/data/gene_expression_data.csv similarity index 100% rename from data/gene_expression_data.csv rename to imaging_transcriptomics/data/gene_expression_data.csv diff --git a/data/gene_expression_labels.txt b/imaging_transcriptomics/data/gene_expression_labels.txt similarity index 100% rename from data/gene_expression_labels.txt rename to imaging_transcriptomics/data/gene_expression_labels.txt diff --git a/imaging_transcriptomics/inputs.py b/imaging_transcriptomics/inputs.py index b4303f8..f81f2ca 100644 --- a/imaging_transcriptomics/inputs.py +++ b/imaging_transcriptomics/inputs.py @@ -53,7 +53,7 @@ def extract_average(imaging_matrix): """ n_regions = 41 logger.debug("Extracting average from scan.") - atlas_data = nib.load(Path(__file__).resolve().parent.parent / "data" / + atlas_data = nib.load(Path(__file__).resolve().parent / "data" / "atlas-desikankilliany_1mm_MNI152.nii.gz").get_fdata() data = np.zeros(n_regions) for i in range(1, n_regions + 1): @@ -89,7 +89,7 @@ def load_gene_expression(): :return: numpy array with the gene expression data. """ logger.debug("Loading gene_expression data.") - expression_file_path = Path(__file__).resolve().parent.parent / "data" / "gene_expression_data.csv" + expression_file_path = Path(__file__).resolve().parent / "data" / "gene_expression_data.csv" expression_data = pd.read_csv(expression_file_path, sep=',') my_data_x = expression_data.iloc[0:41, 2:].to_numpy() return zscore(my_data_x, ddof=1) @@ -102,5 +102,5 @@ def load_gene_labels(): :return: numpy array with the labels of the genes. """ logger.debug("Loading gene labels.") - genes_labels_path = Path(__file__).resolve().parent.parent / "data" / "gene_expression_labels.txt" + genes_labels_path = Path(__file__).resolve().parent / "data" / "gene_expression_labels.txt" return pd.read_fwf(genes_labels_path, header=None).to_numpy() diff --git a/imaging_transcriptomics/transcriptomics.py b/imaging_transcriptomics/transcriptomics.py index 9e31b09..3ac23e0 100644 --- a/imaging_transcriptomics/transcriptomics.py +++ b/imaging_transcriptomics/transcriptomics.py @@ -132,8 +132,8 @@ def permute_data(self, iterations=1_000): self.permuted[34:, :] = sub_permuted # Cortical # Annotation file for the Desikan-Killiany atlas in fs5 - annot_lh = Path(__file__).resolve().parent.parent / "data/fsa5_lh_aparc.annot" - annot_rh = Path(__file__).resolve().parent.parent / "data/fsa5_rh_aparc.annot" + annot_lh = Path(__file__).resolve().parent / "data/fsa5_lh_aparc.annot" + annot_rh = Path(__file__).resolve().parent / "data/fsa5_rh_aparc.annot" # Get the parcel centroids of the Desikan-Killiany atlas parcel_centroids, parcel_hemi = freesurfer.find_parcel_centroids( lhannot=annot_lh, diff --git a/requirements.txt b/requirements.txt index fa3b645..ea713b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ scikit-learn>=0.24.2 joblib>=1.0.1 pyyaml>=5.4.1 netneurotools>=0.1.0 +fpdf2>=2.0.0 diff --git a/setup.py b/setup.py index a386e8e..8d18e73 100644 --- a/setup.py +++ b/setup.py @@ -55,8 +55,8 @@ def get_requirements(): ], keywords="Image analysis, Neuroimaging, Imaging Transcriptomics, Medical Imaging, Research, Multimodal Imaging", install_requires=get_requirements(), - packages=find_packages(), + packages=["imaging_transcriptomics"], include_package_data=True, - package_data={"": ["*.yaml"]}, + package_data={"imaging_transcriptomics": ["*.yaml", "*.nii.gz", "*.csv", "*.txt", "*.annot"]}, scripts=glob("script/imagingtranscriptomics") )